@@ -15,10 +15,15 @@ const options = {
1515const PDFViewer : DocRendererElement = ( props : DocumentRendererProps ) => {
1616 const { file, setDocumentStatus, pdfjsWorkerUrl } = props ;
1717 pdfjs . GlobalWorkerOptions . workerSrc = useMemo ( ( ) => {
18- if ( pdfjsWorkerUrl ?. status === "available" && pdfjsWorkerUrl ?. value ) {
19- return pdfjsWorkerUrl . value ;
18+ if ( pdfjsWorkerUrl ?. status === "available" ) {
19+ if ( pdfjsWorkerUrl ?. value ) {
20+ return pdfjsWorkerUrl . value ;
21+ } else {
22+ return `//unpkg.com/pdfjs-dist@${ pdfjs . version } /build/pdf.worker.min.mjs` ;
23+ }
24+ } else {
25+ return "" ; // no worker;
2026 }
21- return `//unpkg.com/pdfjs-dist@${ pdfjs . version } /build/pdf.worker.min.mjs` ;
2227 } , [ pdfjsWorkerUrl ] ) ;
2328
2429 const [ numberOfPages , setNumberOfPages ] = useState < number > ( 1 ) ;
@@ -100,14 +105,20 @@ const PDFViewer: DocRendererElement = (props: DocumentRendererProps) => {
100105 </ Fragment >
101106 }
102107 >
103- < Document
104- file = { pdfUrl }
105- options = { options }
106- onLoadSuccess = { onDocumentLoadSuccess }
107- onLoadError = { ( ) => setDocumentStatus ( DocumentStatus . error ) }
108- >
109- < Page pageNumber = { currentPage } scale = { zoomLevel } />
110- </ Document >
108+ { ! ! pdfUrl && pdfjsWorkerUrl ?. status === "available" ? (
109+ < Document
110+ file = { pdfUrl }
111+ options = { options }
112+ onLoadSuccess = { onDocumentLoadSuccess }
113+ onLoadError = { ( ) => setDocumentStatus ( DocumentStatus . error ) }
114+ >
115+ < Page pageNumber = { currentPage } scale = { zoomLevel } />
116+ </ Document >
117+ ) : pdfjsWorkerUrl ?. status === "unavailable" ? (
118+ < div > { "PDF worker unavailable" } </ div >
119+ ) : (
120+ < div className = "widget-document-viewer-loading" > </ div >
121+ ) }
111122 </ BaseViewer >
112123 ) ;
113124} ;
0 commit comments