feat(pdf): R4.6 app export on the core's session: export.ts drives ExportSession (rasters one by one, warnings in the engine's order, abort on unmount), labels moved to the app, EditorRoute downloads the Blob of the parts; suites read the file's content streams (pdfRead helper), app-path bytes = R4 digests, hex strings upper-case as pdf-lib

This commit is contained in:
bchanot committed 2026-10-19 01:26:13 +02:00
1 parent 9e688b6801
commit d492bf7112
29 files changed
+507 -131

No files matched your search

+17 -6
View File
@@ -34,8 +34,10 @@ import { pickLabel } from '@/i18n/pickLocaleLabel'
import type { ViewStates } from '@/anatomy/drawing'
import { exportReportToPdf } from '@/pdf/export'
import { downloadBlob } from '@/lib/download'
import type { ExportWarning } from '@faunosteo/pdf'
import type { RebaseOutcome } from '@faunosteo/core-wasm/types'
import type {
ExportWarning,
RebaseOutcome,
} from '@faunosteo/core-wasm/types'
import { useT } from '@/i18n/useT'
import { DEFAULT_SPECIES_ID } from './NewReportRoute'
import { coreFailureMessage } from '@/core/failure'
@@ -95,6 +97,8 @@ export default function EditorRoute() {
const heldAttempt = useRef<number | null>(null)
const [disclaimer, setDisclaimer] = useState<string | null>(null)
const [exporting, setExporting] = useState(false)
// Leaving the editor mid-export cancels it: the core's session is freed, no file results.
const exportAbort = useRef<AbortController | null>(null)
const [editDraft, setEditDraft] = useState<Identity | null>(null)
// One alert per restore, even if the effect runs again before the re-render.
const rebaseAlerted = useRef(false)
@@ -103,6 +107,10 @@ export default function EditorRoute() {
window.scrollTo({ top: 0, left: 0, behavior: 'auto' })
}, [])
useEffect(() => {
return () => exportAbort.current?.abort()
}, [])
// No report in memory: restore the per-tab draft once the sheet is known.
// A draft rebased on another sheet is announced with its unresolved count,
// an unreadable one is set aside. While the core cannot run, nothing is
@@ -233,14 +241,14 @@ export default function EditorRoute() {
async function onExport(index: SheetIndex) {
if (!report) return
setExporting(true)
const abort = new AbortController()
exportAbort.current = abort
try {
const { pdf, warnings } = await exportReportToPdf(report, index, {
locale,
signal: abort.signal,
})
downloadBlob(
new Blob([pdf as BlobPart], { type: 'application/pdf' }),
`bilan-${report.animal.name}-${report.date}.pdf`,
)
downloadBlob(pdf, `bilan-${report.animal.name}-${report.date}.pdf`)
const missing = missingItemsOf(warnings)
if (missing.length) {
window.alert(
@@ -248,9 +256,12 @@ export default function EditorRoute() {
)
}
} catch (err) {
// A cancelled export (the editor left) ends silently.
if (abort.signal.aborted) return
console.error('PDF export failed', err)
window.alert(coreFailureMessage(t, 'editor.export_failed'))
} finally {
if (exportAbort.current === abort) exportAbort.current = null
setExporting(false)
}
}