chore(workspace): move the app to apps/app under a pnpm workspace (step 2)
144 files moved with git mv (pure renames). Root package.json delegates dev/typecheck/test:run/lint/build to the packages; Node 24 LTS and pnpm 10.13.1 pinned (.nvmrc, .node-version, engines, packageManager, root devDependency, engine-strict). Dockerfile builds @faunosteo/app on node:24-alpine and copies apps/app/dist; nginx and runtime config unchanged. CI workflow for Gitea Actions. packages/ reserved (README only). Docs synced: WORKSPACE.md, CLAUDE.md, README, DEPLOY, CHANGELOG, plan. 271/271 tests, typecheck, lint, build green from the root.
This commit is contained in:
1 parent
c8d48ab4cc
commit
8673475293
164 files changed
+348
-128
No files matched your search
@@ -0,0 +1,125 @@
|
||||
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 { useLocaleStore } from '@/state/localeStore'
|
||||
import { pickLocaleLabel } from '@/i18n/pickLocaleLabel'
|
||||
|
||||
export interface AnatomyCanvasProps {
|
||||
src: string
|
||||
boneStates: Map<string, BoneState>
|
||||
onZoneClick: (boneId: string) => void
|
||||
className?: string
|
||||
}
|
||||
|
||||
export default function AnatomyCanvas({
|
||||
src,
|
||||
boneStates,
|
||||
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])
|
||||
|
||||
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)
|
||||
else el.removeAttribute('data-state')
|
||||
})
|
||||
}, [boneStates, loadedSrc, src])
|
||||
|
||||
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 }
|
||||
tip.textContent = label
|
||||
tip.style.opacity = '1'
|
||||
tip.style.left = `${x + 12}px`
|
||||
tip.style.top = `${y - 8}px`
|
||||
},
|
||||
[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 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 onLeave = () => hideTooltip()
|
||||
c.addEventListener('mousemove', onMove)
|
||||
c.addEventListener('mouseleave', onLeave)
|
||||
return () => {
|
||||
c.removeEventListener('mousemove', onMove)
|
||||
c.removeEventListener('mouseleave', onLeave)
|
||||
}
|
||||
}, [loadedSrc, src, showTooltip, hideTooltip])
|
||||
|
||||
return (
|
||||
<div
|
||||
data-testid="anatomy-canvas"
|
||||
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 }}
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
import Dialog from '@/components/ui/Dialog'
|
||||
import AnatomyCanvas from './AnatomyCanvas'
|
||||
import type { BoneState } from '@/anatomy/types'
|
||||
import { useT } from '@/i18n/useT'
|
||||
|
||||
export interface DetailModalProps {
|
||||
open: boolean
|
||||
onClose: () => void
|
||||
detailSrc: string
|
||||
detailId: string
|
||||
title: string
|
||||
boneStates: Map<string, BoneState>
|
||||
onZoneClick: (boneId: string, detailId: string) => void
|
||||
}
|
||||
|
||||
export default function DetailModal({
|
||||
open,
|
||||
onClose,
|
||||
detailSrc,
|
||||
detailId,
|
||||
title,
|
||||
boneStates,
|
||||
onZoneClick,
|
||||
}: DetailModalProps) {
|
||||
const t = useT()
|
||||
return (
|
||||
<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)}
|
||||
/>
|
||||
</div>
|
||||
<p className="mt-4 text-sm text-[var(--color-ink-muted)]">
|
||||
{t('detail.click_to_add')}
|
||||
</p>
|
||||
</Dialog>
|
||||
)
|
||||
}
|
||||
Reference in new issue
Block a user