feat(app): application on the canonical sheet — report v3 store with v2 draft migration, bundled SheetProvider (SHEET_BUNDLE), annotation layer rendered from the document, zone interaction service, pickers and cards on the sheet index, PDF v3 export with v2 archive import; legacy registry, matchers, editors and assets removed
This commit is contained in:
1 parent
0a17e390cf
commit
ce2ec26112
114 files changed
+3560
-14637
No files matched your search
@@ -1,86 +1,93 @@
|
||||
import { useState } from 'react'
|
||||
import type { Vertebra, VertebralRegion } from '@faunosteo/domain'
|
||||
import Dialog from '@/components/ui/Dialog'
|
||||
import Button from '@/components/ui/Button'
|
||||
import Chip from '@/components/ui/Chip'
|
||||
import type { Vertebra, VertebralRegion } from '@/domain/schema/observation'
|
||||
import type { VertebralFormula } from '@/domain/species/types'
|
||||
import { pickLabel } from '@/services/sheetIndex'
|
||||
import { useT } from '@/i18n/useT'
|
||||
|
||||
const REGIONS: VertebralRegion[] = ['C', 'T', 'L', 'S', 'Cd']
|
||||
const REGION_KEY: Record<VertebralRegion, string> = {
|
||||
C: 'vertebra.region.C',
|
||||
T: 'vertebra.region.T',
|
||||
L: 'vertebra.region.L',
|
||||
S: 'vertebra.region.S',
|
||||
Cd: 'vertebra.region.Cd',
|
||||
}
|
||||
import { useLocaleStore } from '@/state/localeStore'
|
||||
|
||||
export interface VertebraPickerProps {
|
||||
open: boolean
|
||||
onClose: () => void
|
||||
onConfirm: (vertebrae: Vertebra[]) => void
|
||||
initial: Vertebra[]
|
||||
formula: VertebralFormula
|
||||
/** Ordered regions of the sheet (`vertebral_config.regions`). */
|
||||
regions: readonly VertebralRegion[]
|
||||
title: string
|
||||
/** Tab to open on. Takes priority so a click always lands on its own zone. */
|
||||
initialRegion?: VertebralRegion
|
||||
initialRegion?: string
|
||||
}
|
||||
|
||||
const sameVertebra = (a: Vertebra, r: string, i: number) =>
|
||||
a.region === r && a.index === i
|
||||
|
||||
/**
|
||||
* Picks vertebrae across every region of the sheet. A region shows its
|
||||
* usual count; when the sheet documents a wider range (D6), one control
|
||||
* extends the grid to the documented maximum. Nothing horse-specific here.
|
||||
*/
|
||||
export default function VertebraPicker({
|
||||
open,
|
||||
onClose,
|
||||
onConfirm,
|
||||
initial,
|
||||
formula,
|
||||
regions,
|
||||
title,
|
||||
initialRegion,
|
||||
}: VertebraPickerProps) {
|
||||
const t = useT()
|
||||
const locale = useLocaleStore((s) => s.locale)
|
||||
const [selected, setSelected] = useState<Vertebra[]>(initial)
|
||||
const [activeRegion, setActiveRegion] = useState<VertebralRegion>(
|
||||
() => initialRegion ?? initial[0]?.region ?? 'C',
|
||||
const [activeCode, setActiveCode] = useState<string>(
|
||||
() => initialRegion ?? initial[0]?.region ?? regions[0]?.code ?? '',
|
||||
)
|
||||
const [extended, setExtended] = useState<Set<string>>(() => new Set())
|
||||
|
||||
const has = (r: VertebralRegion, i: number) =>
|
||||
selected.some((v) => v.region === r && v.index === i)
|
||||
const active = regions.find((r) => r.code === activeCode) ?? regions[0]
|
||||
if (!active) return null
|
||||
const maxCount = active.count_range?.max ?? active.count
|
||||
const highestPicked = Math.max(
|
||||
0,
|
||||
...selected.filter((v) => v.region === active.code).map((v) => v.index),
|
||||
)
|
||||
const canExtend = maxCount > active.count
|
||||
const showExtended = extended.has(active.code) || highestPicked > active.count
|
||||
const count = showExtended ? maxCount : active.count
|
||||
|
||||
const toggle = (r: VertebralRegion, i: number) => {
|
||||
const has = (r: string, i: number) =>
|
||||
selected.some((v) => sameVertebra(v, r, i))
|
||||
const toggle = (r: string, i: number) =>
|
||||
setSelected((cur) =>
|
||||
has(r, i)
|
||||
? cur.filter((v) => !(v.region === r && v.index === i))
|
||||
? cur.filter((v) => !sameVertebra(v, r, i))
|
||||
: [...cur, { region: r, index: i }],
|
||||
)
|
||||
}
|
||||
|
||||
const all = (r: VertebralRegion, count: number) => {
|
||||
setSelected((cur) => {
|
||||
const rest = cur.filter((v) => v.region !== r)
|
||||
return [...rest, ...Array.from({ length: count }, (_, k) => ({ region: r, index: k + 1 }))]
|
||||
})
|
||||
}
|
||||
|
||||
const none = (r: VertebralRegion) =>
|
||||
const all = (r: string, n: number) =>
|
||||
setSelected((cur) => [
|
||||
...cur.filter((v) => v.region !== r),
|
||||
...Array.from({ length: n }, (_, k) => ({ region: r, index: k + 1 })),
|
||||
])
|
||||
const none = (r: string) =>
|
||||
setSelected((cur) => cur.filter((v) => v.region !== r))
|
||||
|
||||
const count = formula[activeRegion]
|
||||
|
||||
return (
|
||||
<Dialog open={open} onClose={onClose} title={title} size="lg">
|
||||
<div role="tablist" className="flex flex-wrap gap-2 mb-4">
|
||||
{REGIONS.map((r) => (
|
||||
{regions.map((r) => (
|
||||
<button
|
||||
key={r}
|
||||
key={r.code}
|
||||
role="tab"
|
||||
aria-selected={activeRegion === r}
|
||||
onClick={() => setActiveRegion(r)}
|
||||
aria-selected={active.code === r.code}
|
||||
onClick={() => setActiveCode(r.code)}
|
||||
className={[
|
||||
'rounded-full px-4 py-2.5 sm:py-1.5 text-sm font-medium border min-h-[2.75rem]',
|
||||
activeRegion === r
|
||||
active.code === r.code
|
||||
? 'bg-[var(--color-accent)] text-white border-[var(--color-accent)]'
|
||||
: 'bg-white text-[var(--color-ink)] border-[var(--color-border)]',
|
||||
].join(' ')}
|
||||
>
|
||||
{t(REGION_KEY[r])}
|
||||
{pickLabel(r.name, locale)}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
@@ -89,26 +96,52 @@ export default function VertebraPicker({
|
||||
{Array.from({ length: count }, (_, k) => k + 1).map((i) => (
|
||||
<Chip
|
||||
key={i}
|
||||
active={has(activeRegion, i)}
|
||||
onClick={() => toggle(activeRegion, i)}
|
||||
active={has(active.code, i)}
|
||||
onClick={() => toggle(active.code, i)}
|
||||
>
|
||||
{activeRegion}{i}
|
||||
{active.code}
|
||||
{i}
|
||||
</Chip>
|
||||
))}
|
||||
</div>
|
||||
|
||||
<div className="flex flex-wrap items-center gap-2 mb-6">
|
||||
<Button variant="ghost" size="sm" onClick={() => all(activeRegion, count)}>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
onClick={() => all(active.code, active.count)}
|
||||
>
|
||||
{t('vertebra.check_all')}
|
||||
</Button>
|
||||
<Button variant="ghost" size="sm" onClick={() => none(activeRegion)}>
|
||||
<Button variant="ghost" size="sm" onClick={() => none(active.code)}>
|
||||
{t('vertebra.uncheck_all')}
|
||||
</Button>
|
||||
{canExtend && !showExtended && (
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
onClick={() => setExtended((cur) => new Set(cur).add(active.code))}
|
||||
>
|
||||
{t('vertebra.extend_to').replace('{max}', String(maxCount))}
|
||||
</Button>
|
||||
)}
|
||||
{canExtend && showExtended && (
|
||||
<span className="text-xs text-[var(--color-ink-muted)]">
|
||||
{t('vertebra.range_note')
|
||||
.replace('{usual}', String(active.count))
|
||||
.replace('{min}', String(active.count_range?.min ?? active.count))
|
||||
.replace('{max}', String(maxCount))}
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div className="flex justify-end gap-2">
|
||||
<Button variant="ghost" onClick={onClose}>{t('common.cancel')}</Button>
|
||||
<Button onClick={() => onConfirm(selected)}>{t('common.confirm')}</Button>
|
||||
<Button variant="ghost" onClick={onClose}>
|
||||
{t('common.cancel')}
|
||||
</Button>
|
||||
<Button onClick={() => onConfirm(selected)}>
|
||||
{t('common.confirm')}
|
||||
</Button>
|
||||
</div>
|
||||
</Dialog>
|
||||
)
|
||||
|
||||
Reference in new issue
Block a user