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:
1 parent
cf9c300c80
commit
ab51ea764d
19 files changed
+891
-85
No files matched your search
@@ -11,7 +11,10 @@ import { saveFailureMessage } from '@/editor/messages'
|
||||
import type { EditorMode } from '@/editor/mode'
|
||||
import { useEditorStore } from '@/editor/state/editorStore'
|
||||
import { initialTab } from '@/editor/tabs'
|
||||
import { useEditorNavigation } from '@/editor/useEditorNavigation'
|
||||
import {
|
||||
useEditorNavigation,
|
||||
type EditorNavigation,
|
||||
} from '@/editor/useEditorNavigation'
|
||||
import type { TabTier } from '@/editor/useViewport'
|
||||
import { useT } from '@/i18n/useT'
|
||||
import ConflictDialog from './ConflictDialog'
|
||||
@@ -68,6 +71,65 @@ function EditingState({
|
||||
)
|
||||
}
|
||||
|
||||
interface PlacesProps {
|
||||
nav: EditorNavigation
|
||||
readOnly: boolean
|
||||
reloadSheet: () => void
|
||||
}
|
||||
|
||||
/**
|
||||
* Under the tab row: the tab panels and the references panel beside them. The container
|
||||
* starts after the tab row, so the panel and its scrim never cover the header or the tabs;
|
||||
* while the panel is open the tab panels are inert (the scrim sits over them).
|
||||
*/
|
||||
function Places({ nav, readOnly, reloadSheet }: PlacesProps) {
|
||||
const { state } = nav
|
||||
const open = state.references.open
|
||||
return (
|
||||
<div className={`relative ${open ? 'min-h-[calc(100dvh-3.5rem)]' : ''}`}>
|
||||
{state.referencesMounted && (
|
||||
<KeptPlace
|
||||
name="references"
|
||||
visible={open}
|
||||
className="absolute bottom-0 right-0 top-0 z-20 w-[min(27rem,100%)]"
|
||||
>
|
||||
<ReferencesPanel
|
||||
readOnly={readOnly}
|
||||
focus={ownedBy(state.focus, 'references')}
|
||||
onClose={nav.closeReferences}
|
||||
citedBy={state.references.citedBy}
|
||||
onShowAll={nav.showAllReferences}
|
||||
/>
|
||||
</KeptPlace>
|
||||
)}
|
||||
{open && (
|
||||
<div
|
||||
aria-hidden="true"
|
||||
data-testid="references-scrim"
|
||||
onClick={nav.closeReferences}
|
||||
className="absolute inset-0 z-10 bg-[rgba(31,27,22,0.25)]"
|
||||
/>
|
||||
)}
|
||||
<div inert={open}>
|
||||
<EditorTabBody
|
||||
tab={state.tab}
|
||||
visited={state.visitedTabs}
|
||||
readOnly={readOnly}
|
||||
navigate={nav.navigate}
|
||||
focus={state.focus}
|
||||
reloadSheet={reloadSheet}
|
||||
annotations={{
|
||||
section: state.section,
|
||||
visited: state.visitedSections,
|
||||
onOpenSection: nav.openSection,
|
||||
onBack: nav.backToDrawing,
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
@@ -100,29 +162,7 @@ export default function EditorWorkspace(props: Props) {
|
||||
<EditorTabs active={state.tab} tier={tier} onSelect={nav.selectTab} />
|
||||
<FocusConsumedContext value={nav.consumed}>
|
||||
<AnnounceContext value={nav.announce}>
|
||||
{state.referencesMounted && (
|
||||
<KeptPlace name="references" visible={state.references.open}>
|
||||
<ReferencesPanel
|
||||
readOnly={readOnly}
|
||||
focus={ownedBy(state.focus, 'references')}
|
||||
onClose={nav.closeReferences}
|
||||
/>
|
||||
</KeptPlace>
|
||||
)}
|
||||
<EditorTabBody
|
||||
tab={state.tab}
|
||||
visited={state.visitedTabs}
|
||||
readOnly={readOnly}
|
||||
navigate={nav.navigate}
|
||||
focus={state.focus}
|
||||
reloadSheet={reloadSheet}
|
||||
annotations={{
|
||||
section: state.section,
|
||||
visited: state.visitedSections,
|
||||
onOpenSection: nav.openSection,
|
||||
onBack: nav.backToDrawing,
|
||||
}}
|
||||
/>
|
||||
<Places nav={nav} readOnly={readOnly} reloadSheet={reloadSheet} />
|
||||
</AnnounceContext>
|
||||
</FocusConsumedContext>
|
||||
<p aria-live="polite" className="sr-only">
|
||||
|
||||
@@ -2,11 +2,13 @@ import ActionButton from '@/components/editor/fields/ActionButton'
|
||||
import ReadOnlyValue from '@/components/editor/fields/ReadOnlyValue'
|
||||
import SelectField from '@/components/editor/fields/SelectField'
|
||||
import TextField from '@/components/editor/fields/TextField'
|
||||
import Icon from '@/components/ui/Icon'
|
||||
import {
|
||||
patchElement,
|
||||
type FindingItem,
|
||||
type FindingPatch,
|
||||
} from '@/editor/findings/tree'
|
||||
import { usePlural } from '@/editor/plural'
|
||||
import { optionalText, useSheetDocument } from '@/editor/sheetDocument'
|
||||
import type { EditCommandApi } from '@/editor/useEditCommand'
|
||||
import type { Locale } from '@/i18n/types'
|
||||
@@ -16,6 +18,7 @@ interface ContentProps {
|
||||
item: FindingItem
|
||||
readOnly: boolean
|
||||
edit: EditCommandApi
|
||||
onShowReferences?: (opener: HTMLElement) => void
|
||||
}
|
||||
|
||||
/** The content of a category or a node: descriptions, vet referral, cited references. */
|
||||
@@ -120,8 +123,10 @@ function Citations({
|
||||
edit,
|
||||
ids,
|
||||
patch,
|
||||
onShowReferences,
|
||||
}: ContentProps & { ids: readonly string[]; patch: Patch }) {
|
||||
const t = useT()
|
||||
const plural = usePlural()
|
||||
const doc = useSheetDocument()
|
||||
const references = doc?.references ?? []
|
||||
const citation = (id: string) =>
|
||||
@@ -134,7 +139,19 @@ function Citations({
|
||||
]
|
||||
return (
|
||||
<div className="space-y-2">
|
||||
<p className="text-sm font-medium">{t('editor.findings.references')}</p>
|
||||
<div className="flex flex-wrap items-center justify-between gap-2">
|
||||
<p className="text-sm font-medium">{t('editor.findings.references')}</p>
|
||||
{ids.length > 0 && onShowReferences && (
|
||||
<button
|
||||
type="button"
|
||||
onClick={(event) => onShowReferences(event.currentTarget)}
|
||||
className="inline-flex min-h-11 items-center gap-1 rounded-full border border-[var(--color-border)] px-3 text-sm focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--color-accent)]"
|
||||
>
|
||||
<Icon name="book" size={16} />
|
||||
{plural('editor.findings.references_open', ids.length)}
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
{ids.length === 0 && (
|
||||
<p className="text-sm text-[var(--color-ink-muted)]">
|
||||
{t('editor.findings.references_none')}
|
||||
|
||||
@@ -14,6 +14,8 @@ export interface FindingDetailProps {
|
||||
item: FindingItem
|
||||
readOnly: boolean
|
||||
onDelete: () => void
|
||||
/** Opens the references panel filtered to this element. */
|
||||
onShowReferences?: (opener: HTMLElement) => void
|
||||
}
|
||||
|
||||
/** The selected element: its names, its review state and the actions on it. */
|
||||
@@ -21,6 +23,7 @@ export default function FindingDetail({
|
||||
item,
|
||||
readOnly,
|
||||
onDelete,
|
||||
onShowReferences,
|
||||
}: FindingDetailProps) {
|
||||
const t = useT()
|
||||
const edit = useEditCommand()
|
||||
@@ -33,7 +36,12 @@ export default function FindingDetail({
|
||||
{item.status && <StatusBadge status={item.status} />}
|
||||
</div>
|
||||
<Names item={item} readOnly={readOnly} edit={edit} />
|
||||
<FindingContent item={item} readOnly={readOnly} edit={edit} />
|
||||
<FindingContent
|
||||
item={item}
|
||||
readOnly={readOnly}
|
||||
edit={edit}
|
||||
onShowReferences={onShowReferences}
|
||||
/>
|
||||
<div className="flex flex-wrap items-center justify-end gap-1">
|
||||
<ReviewActions item={item} readOnly={readOnly} edit={edit} />
|
||||
<MoveButtons
|
||||
|
||||
@@ -46,7 +46,7 @@ export default function ReferenceForm() {
|
||||
return (
|
||||
<div className="space-y-2 rounded-lg border border-dashed border-[var(--color-border)] p-3">
|
||||
<p className="text-sm font-medium">{t('editor.reference.new')}</p>
|
||||
<div className="grid gap-3 md:grid-cols-2">
|
||||
<div className="grid gap-3">
|
||||
<SelectField
|
||||
id="reference-new-type"
|
||||
label={t('editor.reference.type')}
|
||||
|
||||
@@ -6,6 +6,7 @@ import TextField from '@/components/editor/fields/TextField'
|
||||
import { FOCUS_CLASS, focusAttrs } from '@/editor/focusRequest'
|
||||
import { isBlank, nullable } from '@/editor/sheetDocument'
|
||||
import { useEditCommand } from '@/editor/useEditCommand'
|
||||
import { usePlural } from '@/editor/plural'
|
||||
import { useT } from '@/i18n/useT'
|
||||
import { REFERENCE_TYPES } from './referenceTypes'
|
||||
|
||||
@@ -16,15 +17,23 @@ export default function ReferenceRow({
|
||||
reference,
|
||||
index,
|
||||
count,
|
||||
cited,
|
||||
movable,
|
||||
readOnly,
|
||||
onDelete,
|
||||
}: {
|
||||
reference: Reference
|
||||
/** Position in the whole bibliography, not in a filtered list. */
|
||||
index: number
|
||||
count: number
|
||||
/** How many findings cite it. */
|
||||
cited: number
|
||||
/** ↑ / ↓ only while neither the finding filter nor the search narrows the list. */
|
||||
movable: boolean
|
||||
readOnly: boolean
|
||||
onDelete: () => void
|
||||
}) {
|
||||
const plural = usePlural()
|
||||
const t = useT()
|
||||
const edit = useEditCommand()
|
||||
const key = { kind: 'reference', id: reference.id } as const
|
||||
@@ -41,7 +50,10 @@ export default function ReferenceRow({
|
||||
const prefix = `reference-${reference.id}`
|
||||
return (
|
||||
<li {...focusAttrs(key)} className={`${CARD} ${FOCUS_CLASS}`}>
|
||||
<div className="grid gap-3 md:grid-cols-2">
|
||||
<p className="text-right text-sm text-[var(--color-ink-muted)]">
|
||||
{plural('editor.references.cited', cited)}
|
||||
</p>
|
||||
<div className="grid gap-3">
|
||||
<SelectField
|
||||
id={`${prefix}-type`}
|
||||
label={t('editor.reference.type')}
|
||||
@@ -82,12 +94,16 @@ export default function ReferenceRow({
|
||||
/>
|
||||
</div>
|
||||
<div className="flex flex-wrap items-center justify-end gap-1">
|
||||
<MoveButtons
|
||||
index={index}
|
||||
count={count}
|
||||
readOnly={readOnly}
|
||||
onMove={(position) => edit.run('move', { op: 'move', key, position })}
|
||||
/>
|
||||
{movable && (
|
||||
<MoveButtons
|
||||
index={index}
|
||||
count={count}
|
||||
readOnly={readOnly}
|
||||
onMove={(position) =>
|
||||
edit.run('move', { op: 'move', key, position })
|
||||
}
|
||||
/>
|
||||
)}
|
||||
<ActionButton
|
||||
readOnly={readOnly}
|
||||
variant="danger"
|
||||
|
||||
@@ -1,4 +1,12 @@
|
||||
import { useState, type KeyboardEvent } from 'react'
|
||||
import {
|
||||
useEffect,
|
||||
useMemo,
|
||||
useRef,
|
||||
useState,
|
||||
type KeyboardEvent,
|
||||
type RefObject,
|
||||
} from 'react'
|
||||
import type { ElementKey, Reference } from '@faunosteo/core-wasm/types'
|
||||
import DeleteDialog, {
|
||||
type DeleteTarget,
|
||||
} from '@/components/editor/DeleteDialog'
|
||||
@@ -6,26 +14,217 @@ import EditOnly from '@/components/editor/EditOnly'
|
||||
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 Input from '@/components/ui/Input'
|
||||
import {
|
||||
focusRow,
|
||||
useFocusRequest,
|
||||
type FocusRequest,
|
||||
} from '@/editor/focusRequest'
|
||||
import { useSheetDocument } from '@/editor/sheetDocument'
|
||||
import type { EditorPlaceProps } from '@/editor/tabs'
|
||||
import { citationCounts } from '@/editor/references/citations'
|
||||
import {
|
||||
citedIds,
|
||||
citingFinding,
|
||||
visibleReferences,
|
||||
} from '@/editor/references/filter'
|
||||
import { useT } from '@/i18n/useT'
|
||||
import { useLocaleStore } from '@/state/localeStore'
|
||||
|
||||
interface Props extends Pick<EditorPlaceProps, 'readOnly' | 'focus'> {
|
||||
interface Props {
|
||||
readOnly: boolean
|
||||
focus?: FocusRequest
|
||||
onClose: () => void
|
||||
/** The finding the list is filtered to (opened from its detail), if any. */
|
||||
citedBy?: ElementKey | null
|
||||
/** « Tout afficher »: drops the filter. */
|
||||
onShowAll?: () => 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.
|
||||
* The workspace mounts it at the first opening and keeps it (hidden) afterwards.
|
||||
* « Aller à » a reference: the search is cleared first when it may hide the card, and the
|
||||
* card is focused after the commit that shows it (it does not exist while hidden).
|
||||
*/
|
||||
export default function ReferencesPanel({ readOnly, focus, onClose }: Props) {
|
||||
function useReferenceFocus(
|
||||
focus: FocusRequest | undefined,
|
||||
query: string,
|
||||
clearQuery: () => void,
|
||||
) {
|
||||
const [late, setLate] = useState<ElementKey | null>(null)
|
||||
useEffect(() => {
|
||||
if (late === null) return
|
||||
focusRow(late)
|
||||
setLate(null)
|
||||
}, [late])
|
||||
useFocusRequest(focus, (target) => {
|
||||
if (target.key === null) return 'none'
|
||||
if (query === '') return focusRow(target.key) ? 'found' : 'none'
|
||||
clearQuery()
|
||||
setLate(target.key)
|
||||
return 'found'
|
||||
})
|
||||
}
|
||||
|
||||
function PanelHeader({ onClose }: { onClose: () => void }) {
|
||||
const t = useT()
|
||||
useRowFocus(focus)
|
||||
return (
|
||||
<div className="flex items-center justify-between gap-2">
|
||||
<h2
|
||||
id="editor-references-title"
|
||||
tabIndex={-1}
|
||||
data-place-heading
|
||||
className="flex items-center gap-2 outline-none font-serif text-xl"
|
||||
>
|
||||
<Icon name="book" size={20} />
|
||||
{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>
|
||||
)
|
||||
}
|
||||
|
||||
/** The finding filter: « Citées par « nom » (n) » and « Tout afficher (N) ». */
|
||||
function FilterChip({
|
||||
name,
|
||||
cited,
|
||||
total,
|
||||
onShowAll,
|
||||
}: {
|
||||
name: string
|
||||
cited: number
|
||||
total: number
|
||||
onShowAll: () => void
|
||||
}) {
|
||||
const t = useT()
|
||||
const text = t('editor.references.cited_by')
|
||||
.replace('{name}', name)
|
||||
.replace('{count}', String(cited))
|
||||
return (
|
||||
<div className="flex flex-wrap items-center gap-2">
|
||||
<span
|
||||
data-testid="references-filter-chip"
|
||||
className="rounded-full border border-[var(--color-accent)] bg-[var(--color-surface-strong)] px-3 py-1 text-sm"
|
||||
>
|
||||
{text}
|
||||
</span>
|
||||
<button
|
||||
type="button"
|
||||
onClick={onShowAll}
|
||||
className="min-h-11 text-sm underline focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--color-accent)]"
|
||||
>
|
||||
{t('editor.references.show_all').replace('{count}', String(total))}
|
||||
</button>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
function SearchField({
|
||||
value,
|
||||
onChange,
|
||||
inputRef,
|
||||
}: {
|
||||
value: string
|
||||
onChange: (value: string) => void
|
||||
inputRef: RefObject<HTMLInputElement | null>
|
||||
}) {
|
||||
const t = useT()
|
||||
return (
|
||||
<Input
|
||||
ref={inputRef}
|
||||
type="search"
|
||||
aria-label={t('editor.references.search')}
|
||||
placeholder={t('editor.references.search')}
|
||||
value={value}
|
||||
onChange={(event) => onChange(event.target.value)}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
interface ListProps {
|
||||
shown: readonly Reference[]
|
||||
all: readonly Reference[]
|
||||
counts: ReadonlyMap<string, number>
|
||||
movable: boolean
|
||||
readOnly: boolean
|
||||
onDelete: (reference: Reference) => void
|
||||
}
|
||||
|
||||
function ReferenceList({ shown, all, counts, ...rest }: ListProps) {
|
||||
return (
|
||||
<ul className="space-y-3">
|
||||
{shown.map((reference) => (
|
||||
<ReferenceRow
|
||||
key={reference.id}
|
||||
reference={reference}
|
||||
index={all.indexOf(reference)}
|
||||
count={all.length}
|
||||
cited={counts.get(reference.id) ?? 0}
|
||||
movable={rest.movable}
|
||||
readOnly={rest.readOnly}
|
||||
onDelete={() => rest.onDelete(reference)}
|
||||
/>
|
||||
))}
|
||||
</ul>
|
||||
)
|
||||
}
|
||||
|
||||
/** What the list shows: the finding filter (dropped once the finding is gone) and the query. */
|
||||
function useShownReferences(
|
||||
citedBy: ElementKey | null,
|
||||
query: string,
|
||||
onShowAll: (() => void) | undefined,
|
||||
) {
|
||||
const doc = useSheetDocument()
|
||||
const finding = useMemo(
|
||||
() => (doc ? citingFinding(doc, citedBy) : null),
|
||||
[doc, citedBy],
|
||||
)
|
||||
const gone = doc !== null && citedBy !== null && finding === null
|
||||
useEffect(() => {
|
||||
if (gone) onShowAll?.()
|
||||
}, [gone, onShowAll])
|
||||
const all = doc?.references ?? []
|
||||
const cited = finding ? citedIds(finding) : null
|
||||
const shown = visibleReferences(all, cited, query)
|
||||
return { doc, finding, all, cited, shown }
|
||||
}
|
||||
|
||||
/** The empty line: no reference at all, or none that matches. */
|
||||
function EmptyLine({ total, shown }: { total: number; shown: number }) {
|
||||
const t = useT()
|
||||
if (shown > 0) return null
|
||||
const key =
|
||||
total === 0 ? 'editor.reference.empty' : 'editor.references.no_match'
|
||||
return <p className="text-sm text-[var(--color-ink-muted)]">{t(key)}</p>
|
||||
}
|
||||
|
||||
/**
|
||||
* The references side panel: the sheet's bibliography, filtered to the finding that opened
|
||||
* it or searched, each reference with how often it is cited. Not a dialog: the page stays
|
||||
* usable. The workspace mounts it at the first opening and keeps it (hidden) afterwards.
|
||||
*/
|
||||
export default function ReferencesPanel(props: Props) {
|
||||
const { readOnly, focus, onClose, citedBy = null, onShowAll } = props
|
||||
const locale = useLocaleStore((s) => s.locale)
|
||||
const searchRef = useRef<HTMLInputElement>(null)
|
||||
const [query, setQuery] = useState('')
|
||||
const [deleting, setDeleting] = useState<DeleteTarget | null>(null)
|
||||
const references = doc?.references ?? []
|
||||
useReferenceFocus(focus, query, () => setQuery(''))
|
||||
const { doc, finding, all, cited, shown } = useShownReferences(
|
||||
citedBy,
|
||||
query,
|
||||
onShowAll,
|
||||
)
|
||||
const showAll = () => {
|
||||
onShowAll?.()
|
||||
searchRef.current?.focus()
|
||||
}
|
||||
const onKeyDown = (event: KeyboardEvent) => {
|
||||
if (event.key !== 'Escape' || event.defaultPrevented) return
|
||||
event.stopPropagation()
|
||||
@@ -37,52 +236,38 @@ export default function ReferencesPanel({ readOnly, focus, onClose }: Props) {
|
||||
data-testid="editor-references-panel"
|
||||
aria-labelledby="editor-references-title"
|
||||
onKeyDown={onKeyDown}
|
||||
className="space-y-3 rounded-xl border border-[var(--color-border)] p-4"
|
||||
className="sticky top-14 h-[calc(100dvh-3.5rem)] space-y-3 overflow-y-auto border-l border-[var(--color-border)] bg-[var(--color-surface)] p-4 shadow-xl"
|
||||
>
|
||||
<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>
|
||||
<PanelHeader onClose={onClose} />
|
||||
{finding && cited && (
|
||||
<FilterChip
|
||||
name={finding.name[locale]}
|
||||
cited={cited.length}
|
||||
total={all.length}
|
||||
onShowAll={showAll}
|
||||
/>
|
||||
)}
|
||||
<ul className="space-y-3">
|
||||
{references.map((reference, index) => (
|
||||
<ReferenceRow
|
||||
key={reference.id}
|
||||
reference={reference}
|
||||
index={index}
|
||||
count={references.length}
|
||||
<SearchField value={query} onChange={setQuery} inputRef={searchRef} />
|
||||
{doc && (
|
||||
<>
|
||||
<EmptyLine total={all.length} shown={shown.length} />
|
||||
<ReferenceList
|
||||
shown={shown}
|
||||
all={all}
|
||||
counts={citationCounts(doc)}
|
||||
movable={cited === null && query.trim() === ''}
|
||||
readOnly={readOnly}
|
||||
onDelete={() =>
|
||||
onDelete={(reference) =>
|
||||
setDeleting({
|
||||
key: { kind: 'reference', id: reference.id },
|
||||
label: reference.citation,
|
||||
})
|
||||
}
|
||||
/>
|
||||
))}
|
||||
</ul>
|
||||
{doc && (
|
||||
<EditOnly readOnly={readOnly}>
|
||||
<ReferenceForm />
|
||||
</EditOnly>
|
||||
<EditOnly readOnly={readOnly}>
|
||||
<ReferenceForm />
|
||||
</EditOnly>
|
||||
</>
|
||||
)}
|
||||
<DeleteDialog target={deleting} onClose={() => setDeleting(null)} />
|
||||
</section>
|
||||
|
||||
@@ -61,7 +61,11 @@ function useFindingDeletion(
|
||||
}
|
||||
|
||||
/** Constats: the tree zones → categories → nodes, edited one command at a time. */
|
||||
export default function FindingsTab({ readOnly, focus }: EditorPlaceProps) {
|
||||
export default function FindingsTab({
|
||||
readOnly,
|
||||
focus,
|
||||
navigate,
|
||||
}: EditorPlaceProps) {
|
||||
const t = useT()
|
||||
const doc = useSheetDocument()
|
||||
const [selectedId, setSelectedId] = useState<string | null>(null)
|
||||
@@ -151,6 +155,12 @@ export default function FindingsTab({ readOnly, focus }: EditorPlaceProps) {
|
||||
item={selected}
|
||||
readOnly={readOnly}
|
||||
onDelete={() => askDelete(selected)}
|
||||
onShowReferences={(opener) =>
|
||||
navigate(
|
||||
{ place: 'references', key: null, citedBy: selected.key },
|
||||
opener,
|
||||
)
|
||||
}
|
||||
/>
|
||||
)}
|
||||
<DeleteDialog target={deleting} onClose={closeDelete} />
|
||||
|
||||
@@ -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
|
||||
}
|
||||
@@ -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),
|
||||
)
|
||||
}
|
||||
@@ -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),
|
||||
}
|
||||
}
|
||||
@@ -1227,6 +1227,14 @@ export const en: Dict = {
|
||||
'editor.annotations.show_all': 'All annotations',
|
||||
'editor.references.open': 'References',
|
||||
'editor.references.close': 'Close the references',
|
||||
'editor.references.search': 'Search a reference',
|
||||
'editor.references.cited_by': 'Cited by « {name} » ({count})',
|
||||
'editor.references.show_all': 'Show all ({count})',
|
||||
'editor.references.no_match': 'No reference matches.',
|
||||
'editor.references.cited_one': 'cited {count} time',
|
||||
'editor.references.cited_other': 'cited {count} times',
|
||||
'editor.findings.references_open_one': '{count} reference',
|
||||
'editor.findings.references_open_other': '{count} references',
|
||||
'editor.draft.loading': 'Loading the draft…',
|
||||
'editor.draft.none': 'This sheet has no draft.',
|
||||
'editor.draft.overview_link': 'View the sheet',
|
||||
|
||||
@@ -1258,6 +1258,14 @@ export const fr: Dict = {
|
||||
'editor.annotations.show_all': 'Toutes les annotations',
|
||||
'editor.references.open': 'Références',
|
||||
'editor.references.close': 'Fermer les références',
|
||||
'editor.references.search': 'Rechercher une référence',
|
||||
'editor.references.cited_by': 'Citées par « {name} » ({count})',
|
||||
'editor.references.show_all': 'Tout afficher ({count})',
|
||||
'editor.references.no_match': 'Aucune référence ne correspond.',
|
||||
'editor.references.cited_one': 'citée {count} fois',
|
||||
'editor.references.cited_other': 'citée {count} fois',
|
||||
'editor.findings.references_open_one': '{count} référence',
|
||||
'editor.findings.references_open_other': '{count} références',
|
||||
'editor.draft.loading': 'Chargement du brouillon…',
|
||||
'editor.draft.none': "Cette fiche n'a pas de brouillon.",
|
||||
'editor.draft.overview_link': 'Voir la fiche',
|
||||
|
||||
Reference in new issue
Block a user