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
@@ -0,0 +1,83 @@
|
||||
import {
|
||||
AnatomicalSheetDocumentSchema,
|
||||
ReportMigrationMapSchema,
|
||||
type AnatomicalSheetDocument,
|
||||
type ReportMigrationMap,
|
||||
type SheetRef,
|
||||
} from '@faunosteo/domain'
|
||||
|
||||
/**
|
||||
* Where the application gets the anatomical sheet it works on. Step 5 ships
|
||||
* one implementation, the sheet bundled at build time (virtual module, see
|
||||
* vite/sheet-bundle.ts); the Supabase implementation of Step 13 sits behind
|
||||
* the same interface. A loaded sheet is immutable for the session.
|
||||
*/
|
||||
|
||||
export type SheetStatus = 'draft' | 'published'
|
||||
|
||||
/** Raw payload of the virtual module, validated here before use. */
|
||||
export interface BundledSheetData {
|
||||
status: SheetStatus
|
||||
ref: {
|
||||
sheet_id: string
|
||||
version_id: string | null
|
||||
document_sha256: string
|
||||
schema_version: number
|
||||
species_id: string
|
||||
}
|
||||
document: unknown
|
||||
migrationMap: unknown
|
||||
assets: Record<string, string>
|
||||
}
|
||||
|
||||
export interface LoadedSheet {
|
||||
status: SheetStatus
|
||||
ref: SheetRef
|
||||
speciesId: string
|
||||
document: AnatomicalSheetDocument
|
||||
/** SVG text by `svg_asset_id`. */
|
||||
assets: Readonly<Record<string, string>>
|
||||
migrationMap: ReportMigrationMap
|
||||
}
|
||||
|
||||
export interface SheetProvider {
|
||||
/** The reference sheet of a species, or null when none is available. */
|
||||
getReferenceSheet(speciesId: string): Promise<LoadedSheet | null>
|
||||
}
|
||||
|
||||
export function parseBundledSheet(data: BundledSheetData): LoadedSheet {
|
||||
const document = AnatomicalSheetDocumentSchema.parse(data.document)
|
||||
const migrationMap = ReportMigrationMapSchema.parse(data.migrationMap)
|
||||
return {
|
||||
status: data.status,
|
||||
ref: {
|
||||
sheetId: data.ref.sheet_id,
|
||||
versionId: data.ref.version_id,
|
||||
documentSha256: data.ref.document_sha256,
|
||||
},
|
||||
speciesId: data.ref.species_id,
|
||||
document,
|
||||
assets: data.assets,
|
||||
migrationMap,
|
||||
}
|
||||
}
|
||||
|
||||
let cached: Promise<LoadedSheet | null> | null = null
|
||||
|
||||
async function loadBundled(): Promise<LoadedSheet | null> {
|
||||
const mod = await import('virtual:faunosteo-sheet')
|
||||
return mod.bundledSheet ? parseBundledSheet(mod.bundledSheet) : null
|
||||
}
|
||||
|
||||
export const bundledSheetProvider: SheetProvider = {
|
||||
async getReferenceSheet(speciesId) {
|
||||
cached ??= loadBundled()
|
||||
const sheet = await cached
|
||||
return sheet && sheet.speciesId === speciesId ? sheet : null
|
||||
},
|
||||
}
|
||||
|
||||
/** Test seam: forget the memoised bundle. */
|
||||
export function resetBundledSheetCache(): void {
|
||||
cached = null
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
declare module 'virtual:faunosteo-sheet' {
|
||||
export const bundledSheet: import('./provider').BundledSheetData | null
|
||||
}
|
||||
Reference in new issue
Block a user