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:
bchanot committed 2026-10-10 11:36:14 +02:00
1 parent 0a17e390cf
commit ce2ec26112
114 files changed
+3560 -14637

No files matched your search

+54
View File
@@ -0,0 +1,54 @@
import { useEffect, useState } from 'react'
import { buildSheetIndex, type SheetIndex } from '@/services/sheetIndex'
import { bundledSheetProvider, type SheetProvider } from './provider'
/**
* The reference sheet of a species for the current session, loaded once
* through the provider and indexed. `none` means the build carries no sheet
* (production bundle without SHEET_BUNDLE=draft) or no sheet for the species.
*/
export type SheetState =
| { status: 'loading' }
| { status: 'none' }
| { status: 'ready'; index: SheetIndex }
let provider: SheetProvider = bundledSheetProvider
const cache = new Map<string, Promise<SheetIndex | null>>()
/** Test seam: swap the provider and forget loaded sheets. */
export function setSheetProvider(next: SheetProvider): void {
provider = next
cache.clear()
}
export function loadSheetIndex(speciesId: string): Promise<SheetIndex | null> {
let pending = cache.get(speciesId)
if (!pending) {
pending = provider
.getReferenceSheet(speciesId)
.then((sheet) => (sheet ? buildSheetIndex(sheet) : null))
cache.set(speciesId, pending)
}
return pending
}
export function useSheet(speciesId: string | undefined): SheetState {
const [state, setState] = useState<SheetState>({ status: 'loading' })
useEffect(() => {
let cancelled = false
if (!speciesId) {
setState({ status: 'none' })
return
}
setState({ status: 'loading' })
loadSheetIndex(speciesId).then((index) => {
if (cancelled) return
setState(index ? { status: 'ready', index } : { status: 'none' })
})
return () => {
cancelled = true
}
}, [speciesId])
return state
}