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,77 +1,83 @@
|
||||
import { useCallback, useEffect, useRef, useState } from 'react'
|
||||
import { loadSvg } from '@/anatomy/svgLoader'
|
||||
import {
|
||||
getBoneIdFromEvent,
|
||||
getAnnotatedElement,
|
||||
} from '@/anatomy/svgConvention'
|
||||
import type { BoneState } from '@/anatomy/types'
|
||||
import { useCallback, useEffect, useRef } from 'react'
|
||||
import { buildViewSvg, type ViewStates } from '@/anatomy/drawing'
|
||||
import type { SheetIndex } from '@/services/sheetIndex'
|
||||
import { useLocaleStore } from '@/state/localeStore'
|
||||
import { pickLocaleLabel } from '@/i18n/pickLocaleLabel'
|
||||
|
||||
export interface AnatomyCanvasProps {
|
||||
src: string
|
||||
boneStates: Map<string, BoneState>
|
||||
onZoneClick: (boneId: string) => void
|
||||
index: SheetIndex
|
||||
viewId: string
|
||||
states: ViewStates
|
||||
onZoneClick: (annotationId: string, viewId: string) => void
|
||||
className?: string
|
||||
}
|
||||
|
||||
const ANNOTATED = '[data-anno-id]'
|
||||
|
||||
function annotatedTarget(event: Event): Element | null {
|
||||
const target = event.target
|
||||
return target instanceof Element ? target.closest(ANNOTATED) : null
|
||||
}
|
||||
|
||||
/**
|
||||
* One view of the sheet: the drawing plus the annotation layer generated
|
||||
* from the document, rebuilt when the view changes and restyled in place
|
||||
* when the selection changes. Clicks are delegated on `data-anno-id`.
|
||||
*/
|
||||
export default function AnatomyCanvas({
|
||||
src,
|
||||
boneStates,
|
||||
index,
|
||||
viewId,
|
||||
states,
|
||||
onZoneClick,
|
||||
className = '',
|
||||
}: AnatomyCanvasProps) {
|
||||
const wrapperRef = useRef<HTMLDivElement | null>(null)
|
||||
const svgRef = useRef<HTMLDivElement | null>(null)
|
||||
const tooltipRef = useRef<HTMLDivElement | null>(null)
|
||||
const [loadedSrc, setLoadedSrc] = useState<string | null>(null)
|
||||
const locale = useLocaleStore((s) => s.locale)
|
||||
|
||||
useEffect(() => {
|
||||
let cancelled = false
|
||||
const c = svgRef.current
|
||||
if (!c) return
|
||||
c.replaceChildren()
|
||||
setLoadedSrc(null)
|
||||
loadSvg(src).then((root) => {
|
||||
if (cancelled || !c) return
|
||||
c.appendChild(root)
|
||||
setLoadedSrc(src)
|
||||
})
|
||||
return () => { cancelled = true }
|
||||
}, [src])
|
||||
const host = svgRef.current
|
||||
if (!host) return
|
||||
host.replaceChildren(buildViewSvg(index, viewId, states))
|
||||
// States are applied by the effect below; the build only needs the view.
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [index, viewId])
|
||||
|
||||
useEffect(() => {
|
||||
const c = svgRef.current
|
||||
if (!c) return
|
||||
const onClick = (e: Event) => {
|
||||
const id = getBoneIdFromEvent(e)
|
||||
if (id) onZoneClick(id)
|
||||
}
|
||||
c.addEventListener('click', onClick)
|
||||
return () => c.removeEventListener('click', onClick)
|
||||
}, [onZoneClick])
|
||||
|
||||
useEffect(() => {
|
||||
const c = svgRef.current
|
||||
if (!c || loadedSrc !== src) return
|
||||
const all = c.querySelectorAll<Element>('[data-anno-id]')
|
||||
all.forEach((el) => {
|
||||
const id = el.getAttribute('data-anno-id') as string
|
||||
const state = boneStates.get(id)
|
||||
if (state && state !== 'default') el.setAttribute('data-state', state)
|
||||
const host = svgRef.current
|
||||
if (!host) return
|
||||
host.querySelectorAll<Element>(ANNOTATED).forEach((el) => {
|
||||
const state = states.get(el.getAttribute('data-anno-id') ?? '')
|
||||
if (state) el.setAttribute('data-state', state)
|
||||
else el.removeAttribute('data-state')
|
||||
})
|
||||
}, [boneStates, loadedSrc, src])
|
||||
}, [states, index, viewId])
|
||||
|
||||
useEffect(() => {
|
||||
const host = svgRef.current
|
||||
if (!host) return
|
||||
const onClick = (e: Event) => {
|
||||
const id = annotatedTarget(e)?.getAttribute('data-anno-id')
|
||||
if (id) onZoneClick(id, viewId)
|
||||
}
|
||||
host.addEventListener('click', onClick)
|
||||
return () => host.removeEventListener('click', onClick)
|
||||
}, [onZoneClick, viewId])
|
||||
|
||||
const showTooltip = useCallback(
|
||||
(el: Element, x: number, y: number) => {
|
||||
const tip = tooltipRef.current
|
||||
if (!tip) return
|
||||
const fr = el.getAttribute('data-anno-name-fr') ?? ''
|
||||
const en = el.getAttribute('data-anno-name-en') ?? ''
|
||||
const label = pickLocaleLabel(fr, en, locale)
|
||||
if (!label) { tip.style.opacity = '0'; return }
|
||||
const label = pickLocaleLabel(
|
||||
el.getAttribute('data-anno-name-fr') ?? '',
|
||||
el.getAttribute('data-anno-name-en') ?? '',
|
||||
locale,
|
||||
)
|
||||
if (!label) {
|
||||
tip.style.opacity = '0'
|
||||
return
|
||||
}
|
||||
tip.textContent = label
|
||||
tip.style.opacity = '1'
|
||||
tip.style.left = `${x + 12}px`
|
||||
@@ -80,46 +86,40 @@ export default function AnatomyCanvas({
|
||||
[locale],
|
||||
)
|
||||
|
||||
const hideTooltip = useCallback(() => {
|
||||
const tip = tooltipRef.current
|
||||
if (tip) tip.style.opacity = '0'
|
||||
}, [])
|
||||
|
||||
useEffect(() => {
|
||||
const c = svgRef.current
|
||||
if (!c || loadedSrc !== src) return
|
||||
const host = svgRef.current
|
||||
if (!host) return
|
||||
const hide = () => {
|
||||
if (tooltipRef.current) tooltipRef.current.style.opacity = '0'
|
||||
}
|
||||
const onMove = (e: MouseEvent) => {
|
||||
const el = getAnnotatedElement(e)
|
||||
if (el && !el.hasAttribute('data-anno-opens-detail')) {
|
||||
const w = wrapperRef.current
|
||||
if (!w) return
|
||||
const rect = w.getBoundingClientRect()
|
||||
showTooltip(el, e.clientX - rect.left, e.clientY - rect.top)
|
||||
} else {
|
||||
hideTooltip()
|
||||
}
|
||||
const el = annotatedTarget(e)
|
||||
const wrapper = wrapperRef.current
|
||||
if (!el || !wrapper || el.hasAttribute('data-anno-opens-view'))
|
||||
return hide()
|
||||
const rect = wrapper.getBoundingClientRect()
|
||||
showTooltip(el, e.clientX - rect.left, e.clientY - rect.top)
|
||||
}
|
||||
const onLeave = () => hideTooltip()
|
||||
c.addEventListener('mousemove', onMove)
|
||||
c.addEventListener('mouseleave', onLeave)
|
||||
host.addEventListener('mousemove', onMove)
|
||||
host.addEventListener('mouseleave', hide)
|
||||
return () => {
|
||||
c.removeEventListener('mousemove', onMove)
|
||||
c.removeEventListener('mouseleave', onLeave)
|
||||
host.removeEventListener('mousemove', onMove)
|
||||
host.removeEventListener('mouseleave', hide)
|
||||
}
|
||||
}, [loadedSrc, src, showTooltip, hideTooltip])
|
||||
}, [showTooltip])
|
||||
|
||||
return (
|
||||
<div
|
||||
data-testid="anatomy-canvas"
|
||||
data-view-id={viewId}
|
||||
ref={wrapperRef}
|
||||
className={`svg-canvas relative w-full h-full ${className}`}
|
||||
>
|
||||
<div ref={svgRef} className="w-full h-full [&>svg]:max-w-full [&>svg]:max-h-full [&>svg]:mx-auto" />
|
||||
<div
|
||||
ref={tooltipRef}
|
||||
className="zone-tooltip"
|
||||
style={{ opacity: 0 }}
|
||||
ref={svgRef}
|
||||
className="w-full h-full [&>svg]:max-w-full [&>svg]:max-h-full [&>svg]:mx-auto"
|
||||
/>
|
||||
<div ref={tooltipRef} className="zone-tooltip" style={{ opacity: 0 }} />
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -1,25 +1,27 @@
|
||||
import Dialog from '@/components/ui/Dialog'
|
||||
import AnatomyCanvas from './AnatomyCanvas'
|
||||
import type { BoneState } from '@/anatomy/types'
|
||||
import type { ViewStates } from '@/anatomy/drawing'
|
||||
import type { SheetIndex } from '@/services/sheetIndex'
|
||||
import { useT } from '@/i18n/useT'
|
||||
|
||||
export interface DetailModalProps {
|
||||
open: boolean
|
||||
onClose: () => void
|
||||
detailSrc: string
|
||||
detailId: string
|
||||
index: SheetIndex
|
||||
viewId: string
|
||||
title: string
|
||||
boneStates: Map<string, BoneState>
|
||||
onZoneClick: (boneId: string, detailId: string) => void
|
||||
states: ViewStates
|
||||
onZoneClick: (annotationId: string, viewId: string) => void
|
||||
}
|
||||
|
||||
/** A detail view of the sheet (a crop or its own drawing) in a dialog. */
|
||||
export default function DetailModal({
|
||||
open,
|
||||
onClose,
|
||||
detailSrc,
|
||||
detailId,
|
||||
index,
|
||||
viewId,
|
||||
title,
|
||||
boneStates,
|
||||
states,
|
||||
onZoneClick,
|
||||
}: DetailModalProps) {
|
||||
const t = useT()
|
||||
@@ -27,9 +29,10 @@ export default function DetailModal({
|
||||
<Dialog open={open} onClose={onClose} title={title} size="xl">
|
||||
<div className="aspect-[4/3] w-full">
|
||||
<AnatomyCanvas
|
||||
src={detailSrc}
|
||||
boneStates={boneStates}
|
||||
onZoneClick={(id) => onZoneClick(id, detailId)}
|
||||
index={index}
|
||||
viewId={viewId}
|
||||
states={states}
|
||||
onZoneClick={onZoneClick}
|
||||
/>
|
||||
</div>
|
||||
<p className="mt-4 text-sm text-[var(--color-ink-muted)]">
|
||||
|
||||
Reference in new issue
Block a user