Build and Deploy Verso / deploy (push) Successful in 9m35s
- Reduce the dashboard instance-name/version font size (07 -> 06). - Enlarge the Verso logo in the loading animation (160px -> 240px). - Preserve the current RevealJS slide across recompiles: capture the deck's URL hash (same-origin) and re-append it to the iframe src so the new build reopens on the same slide instead of jumping to the start. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
73 lines
2.2 KiB
TypeScript
73 lines
2.2 KiB
TypeScript
import { lazy, memo, useCallback, useRef } from 'react'
|
|
import { useDetachCompileContext as useCompileContext } from '../../../shared/context/detach-compile-context'
|
|
|
|
const PdfJsViewer = lazy(
|
|
() => import(/* webpackChunkName: "pdf-js-viewer" */ './pdf-js-viewer')
|
|
)
|
|
|
|
function PdfViewer() {
|
|
const { pdfUrl, pdfFile, pdfViewer } = useCompileContext()
|
|
|
|
// Remember the current RevealJS slide (kept in the deck's URL hash, e.g.
|
|
// "#/3/2") so that recompiling — which swaps the iframe src for a fresh
|
|
// build — reopens the deck on the same slide instead of jumping to the
|
|
// start. Only works when the output is same-origin (the usual self-hosted
|
|
// case); cross-origin reads fail silently and we just lose the position.
|
|
const lastHashRef = useRef('')
|
|
|
|
const handlePresentationLoad = useCallback(
|
|
(event: React.SyntheticEvent<HTMLIFrameElement>) => {
|
|
const win = event.currentTarget.contentWindow
|
|
if (!win) {
|
|
return
|
|
}
|
|
try {
|
|
const capture = () => {
|
|
try {
|
|
lastHashRef.current = win.location.hash
|
|
} catch {
|
|
// cross-origin after navigation — ignore
|
|
}
|
|
}
|
|
capture()
|
|
win.addEventListener('hashchange', capture)
|
|
} catch {
|
|
// cross-origin: can't track the slide position
|
|
}
|
|
},
|
|
[]
|
|
)
|
|
|
|
if (!pdfUrl) {
|
|
return null
|
|
}
|
|
|
|
// HTML outputs (RevealJS, etc.) must always use the native iframe;
|
|
// PDF.js cannot render HTML.
|
|
if (pdfUrl.includes('output.html')) {
|
|
// Re-append the remembered slide hash so the new build opens where the
|
|
// user left off. RevealJS reads the hash on load and navigates there.
|
|
const src = `${pdfUrl}${lastHashRef.current}`
|
|
return (
|
|
<iframe
|
|
title="Presentation Preview"
|
|
src={src}
|
|
onLoad={handlePresentationLoad}
|
|
style={{ width: '100%', height: '100%', border: 'none' }}
|
|
sandbox="allow-scripts allow-same-origin allow-presentation allow-popups"
|
|
/>
|
|
)
|
|
}
|
|
|
|
switch (pdfViewer) {
|
|
case 'native':
|
|
return <iframe title="PDF Preview" src={pdfUrl} />
|
|
|
|
case 'pdfjs':
|
|
default:
|
|
return <PdfJsViewer url={pdfUrl} pdfFile={pdfFile} />
|
|
}
|
|
}
|
|
|
|
export default memo(PdfViewer)
|