feat(editor): collapsible reference tiles in the Références tab

Board 23 / 24 / 27 tiles: closed (citation on two lines, type, « Citée
{n} fois » / « Non citée »), open (Type, DOI, URL as safe links, the
citers with « famille » badge and « Aller à »), edit (« Terminer » with a
leave guard re-committing every changed field; a refusal keeps edit
and focuses the field). A cited reference shows the deletion hint, an
uncited one keeps « Supprimer ». Read-only keeps DOI, URL, « Aller à ».
« Terminer » keeps focus in the field on press, so a refusal message
can no longer move the button under the pointer.

Gates: typecheck, lint, test:run (app 1419), build, e2e:ui 251;
e2e:shell 16 specs on db:sandbox (editor-equine never listed): 111
passed / 99 skipped / 3 failed in the new editor-references.spec (two
test bugs, one app bug), fixed and rerun: 5 passed / 4 skipped; full-row
guard: no pre-existing row changed in any table.

## R-24 (removed or rewritten assertions)
| file | old | new |
|---|---|---|
| editor-citations.test.ts | `citationCounts` counts 2/1/0, memoised, empty | `citersOf`: ordered citers (Cat, Node), family flag, trail from zone, key, memoised, empty |
| editor-references-tab.test.tsx | cards say « citée N fois » (ref-a 1, ref-c 0) | « Citée 2 fois » (fixture gains a node citing ref-a), « Citée 1 fois », « Non citée » |
| same | ids `#tab-reference-ref-a-citation` exist when closed | header id `#tab-reference-0-ref-a-header`; field ids only inside an open edit tile |
| same | ↑/↓ on every card | in open tiles only, absent under a search |
| same | Ctrl+Z on an always-visible field | open tile, Modifier, then same assertion on `#tab-reference-0-ref-a-citation` |
| same | « Aller à » focuses the card (`listitem` count 3, focus key) | tile opened (aria-expanded true), header focused, 3 tiles |
| same | add: `getByText('Nouvelle source')` | tile header named « Nouvelle source » |
| same | read-only: no Supprimer / add | same after opening every tile |
| editor-tabs-lists.test.tsx | edit on blur and arrows on always-open cards | open tile, Modifier, blur applies, Terminer, Monter on opened tile |
| same | cited reference deletion refused in a dialog listing citers | REMOVED: no Supprimer on a cited tile (hint asserted, citer listed); uncited delete kept. The dialog's blocked path stays covered by `DeleteDialog`'s own tests |
| same | read-only: no button at all | read-only: facts shown, no Modifier / Supprimer / Citation textbox (header buttons exist now) |
| editor-keep-alive.test.tsx:~330 | tab-click commit of `#tab-reference-ref-1-citation` | opens tile + Modifier first, id `#tab-reference-0-ref-1-citation` |
| editor-keep-alive.test.tsx:~350,367 | `#panel-reference-ref-1-citation` | `#panel-reference-0-ref-1-citation` |
| editor-references-panel.test.tsx | « citée 2 fois / 1 fois » | « Citée 2 fois / 1 fois » |
| same | `#panel-reference-ref-a-citation`; no `#tab-reference-ref-a-citation` | `#panel-reference-0-ref-a-citation`; no `[id^="tab-reference-"]` while the tab tiles are closed |
| same | ids unique, tab and panel field ids present | tab tile opened in edit first; `tab-reference-0-ref-a-citation` and `panel-reference-0-ref-a-citation` unique |
| e2e editor-structures.spec.ts:~88-110 | citation inputs count 3/1/2, « citée 0 fois » x2, « citée 1 fois », move via row buttons | tile headers count, « Non citée » x2, « Citée 1 fois », tile opened before Monter/Supprimer, `tiles.nth(1)` contains the moved text (saved-list assertion unchanged) |

## i18n (fr / en)
Changed (in place, P18): `editor.references.cited_one|other`: « citée {count} fois » -> « Citée {count} fois »; « cited {count} time(s) » -> « Cited {count} time(s) ».
Added: `editor.references.uncited` Non citée / Not cited; `citers_one|other` « Citée {count} fois, par : » / « Cited {count} time(s), by: »; `no_citers` « Aucun constat ni aucune famille ne cite cette référence. » / « No finding or family cites this reference. »; `family` famille / family; `go_to` Aller à / Go to; `edit` Modifier / Edit; `done` Terminer / Done; `edit_title` Modifier la référence / Edit the reference; `url_label` URL / URL; `none_doi` Aucun / None; `none_url` Aucune / None; `new_tab` (nouvel onglet) / (new tab) (sr-only); `delete_hint` (REVUE wording, fr and en).
Removed: none. R10 grep (src, tests, e2e incl. editor-equine) found no reader of the old lowercase wording left.
This commit is contained in:
bchanot committed 2026-11-12 20:50:25 +01:00
1 parent 4499bc740c
commit c21995b3fb
26 files changed
+1532 -155

No files matched your search

+42 -13
View File
@@ -1,25 +1,54 @@
import type { AnatomicalSheetDocument } from '@faunosteo/core-wasm/types'
import type {
AnatomicalSheetDocument,
ElementKey,
LocalizedText,
} from '@faunosteo/core-wasm/types'
import { buildItems } from '@/editor/findings/tree'
const memo = new WeakMap<AnatomicalSheetDocument, ReadonlyMap<string, number>>()
/** A family or a finding that cites a reference. */
export interface CiterItem {
key: ElementKey
name: LocalizedText
/** The zone, then the families above, outermost first; the citer itself excluded. */
trail: readonly LocalizedText[]
isFamily: boolean
}
const memo = new WeakMap<
AnatomicalSheetDocument,
ReadonlyMap<string, readonly CiterItem[]>
>()
/**
* 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.
* Who cites each reference: families and findings at any depth, in document order, one
* entry per citer however often it lists the id. A display list 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(
export function citersOf(
doc: AnatomicalSheetDocument,
): ReadonlyMap<string, number> {
): ReadonlyMap<string, readonly CiterItem[]> {
const known = memo.get(doc)
if (known) return known
const counts = new Map<string, number>()
for (const { element } of buildItems(doc)) {
const items = buildItems(doc)
const byId = new Map(items.map((item) => [item.id, item]))
const trailOf = (parentId: string | null): LocalizedText[] => {
const parent = parentId === null ? undefined : byId.get(parentId)
return parent ? [...trailOf(parent.parentId), parent.name] : []
}
const citers = new Map<string, CiterItem[]>()
for (const { element, key, name, parentId, kind } of items) {
if (element.kind === 'zone') continue
for (const id of element.value.reference_ids) {
counts.set(id, (counts.get(id) ?? 0) + 1)
const citer = {
key,
name,
trail: trailOf(parentId),
isFamily: kind === 'category',
}
for (const id of new Set(element.value.reference_ids)) {
citers.set(id, [...(citers.get(id) ?? []), citer])
}
}
memo.set(doc, counts)
return counts
memo.set(doc, citers)
return citers
}
@@ -0,0 +1,24 @@
const DOI_PREFIX = /^(?:doi:|https?:\/\/(?:dx\.)?doi\.org\/)/i
const DOI_SHAPE = /^10\.\d{4,9}\/\S+$/
/** The address as a link target, only for http and https; anything else is plain text. */
export function webHref(raw: string): string | null {
try {
const url = new URL(raw.trim())
return url.protocol === 'http:' || url.protocol === 'https:'
? url.href
: null
} catch {
return null
}
}
/**
* `https://doi.org/<doi>` for a well-formed DOI (an optional `doi:` or resolver prefix is
* stripped); null when the text is not a DOI. Encoded per segment, the `/` kept.
*/
export function doiHref(raw: string): string | null {
const doi = raw.trim().replace(DOI_PREFIX, '')
if (!DOI_SHAPE.test(doi)) return null
return `https://doi.org/${doi.split('/').map(encodeURIComponent).join('/')}`
}