From be2569d8640f1693eb27f124ad3dd8062ada4837 Mon Sep 17 00:00:00 2001
From: bobzel <zzzman@gmail.com>
Date: Mon, 11 Dec 2023 00:41:05 -0500
Subject: more updates to mobx 6.  updated typescript to v5. updated pdf-dist

---
 src/client/views/pdf/PDFViewer.tsx | 32 ++++++++++++++++----------------
 1 file changed, 16 insertions(+), 16 deletions(-)

(limited to 'src/client/views/pdf/PDFViewer.tsx')

diff --git a/src/client/views/pdf/PDFViewer.tsx b/src/client/views/pdf/PDFViewer.tsx
index 62df77c0a..db815eae3 100644
--- a/src/client/views/pdf/PDFViewer.tsx
+++ b/src/client/views/pdf/PDFViewer.tsx
@@ -1,6 +1,5 @@
 import { action, computed, IReactionDisposer, makeObservable, observable, ObservableMap, reaction, runInAction } from 'mobx';
 import { observer } from 'mobx-react';
-import * as Pdfjs from 'pdfjs-dist';
 import 'pdfjs-dist/web/pdf_viewer.css';
 import { Doc, DocListCast, Opt } from '../../../fields/Doc';
 import { Height } from '../../../fields/DocSymbols';
@@ -17,20 +16,20 @@ import { CollectionFreeFormView } from '../collections/collectionFreeForm/Collec
 import { MarqueeAnnotator } from '../MarqueeAnnotator';
 import { DocFocusOptions, DocumentViewProps } from '../nodes/DocumentView';
 import { FieldViewProps } from '../nodes/FieldView';
-import { LinkDocPreview } from '../nodes/LinkDocPreview';
+import { LinkDocPreview, LinkInfo } from '../nodes/LinkDocPreview';
 import { StyleProp } from '../StyleProvider';
 import { AnchorMenu } from './AnchorMenu';
 import { Annotation } from './Annotation';
 import { GPTPopup } from './GPTPopup/GPTPopup';
 import './PDFViewer.scss';
 import * as React from 'react';
-const PDFJSViewer = require('pdfjs-dist/web/pdf_viewer');
-const pdfjsLib = require('pdfjs-dist');
+import * as Pdfjs from 'pdfjs-dist';
+import * as PDFJSViewer from 'pdfjs-dist/web/pdf_viewer.mjs';
 const _global = (window /* browser */ || global) /* node */ as any;
 
 //pdfjsLib.GlobalWorkerOptions.workerSrc = `/assets/pdf.worker.js`;
 // The workerSrc property shall be specified.
-pdfjsLib.GlobalWorkerOptions.workerSrc = 'https://unpkg.com/pdfjs-dist@2.16.105/build/pdf.worker.js';
+Pdfjs.GlobalWorkerOptions.workerSrc = 'https://unpkg.com/pdfjs-dist@4.0.269/build/pdf.worker.mjs';
 
 interface IViewerProps extends FieldViewProps {
     Document: Doc;
@@ -52,11 +51,6 @@ interface IViewerProps extends FieldViewProps {
 @observer
 export class PDFViewer extends React.Component<IViewerProps> {
     static _annotationStyle: any = addStyleSheet();
-    @observable private _pageSizes: { width: number; height: number }[] = [];
-    @observable private _savedAnnotations = new ObservableMap<number, HTMLDivElement[]>();
-    @observable private _textSelecting = true;
-    @observable private _showWaiting = true;
-    @observable private Index: number = -1;
 
     _prevProps: IViewerProps;
     @observable _props: IViewerProps;
@@ -65,6 +59,13 @@ export class PDFViewer extends React.Component<IViewerProps> {
         this._prevProps = this._props = props;
         makeObservable(this);
     }
+
+    @observable _pageSizes: { width: number; height: number }[] = [];
+    @observable _savedAnnotations = new ObservableMap<number, HTMLDivElement[]>();
+    @observable _textSelecting = true;
+    @observable _showWaiting = true;
+    @observable Index: number = -1;
+
     componentDidUpdate() {
         copyProps(this);
     }
@@ -101,7 +102,7 @@ export class PDFViewer extends React.Component<IViewerProps> {
         return this.allAnnotations.filter(a => a.text_inlineAnnotations);
     }
 
-    componentDidMount = async () => {
+    componentDidMount() {
         runInAction(() => (this._showWaiting = true));
         this.setupPdfJsViewer();
         this._mainCont.current?.addEventListener('scroll', e => ((e.target as any).scrollLeft = 0));
@@ -126,7 +127,7 @@ export class PDFViewer extends React.Component<IViewerProps> {
             page => page !== undefined && page !== this._pdfViewer?.currentPageNumber && this.gotoPage(page),
             { fireImmediately: true }
         );
-    };
+    }
 
     componentWillUnmount = () => {
         Object.values(this._disposers).forEach(disposer => disposer?.());
@@ -262,7 +263,7 @@ export class PDFViewer extends React.Component<IViewerProps> {
         }
         document.removeEventListener('copy', this.copy);
         document.addEventListener('copy', this.copy);
-        const eventBus = new PDFJSViewer.EventBus(true);
+        const eventBus = new PDFJSViewer.EventBus();
         eventBus._on('pagesinit', this.pagesinit);
         eventBus._on(
             'pagerendered',
@@ -272,10 +273,9 @@ export class PDFViewer extends React.Component<IViewerProps> {
         const pdfFindController = new PDFJSViewer.PDFFindController({ linkService: pdfLinkService, eventBus });
         this._pdfViewer = new PDFJSViewer.PDFViewer({
             container: this._mainCont.current,
-            viewer: this._viewer.current,
+            viewer: this._viewer.current || undefined,
             linkService: pdfLinkService,
             findController: pdfFindController,
-            renderer: 'canvas',
             eventBus,
         });
         pdfLinkService.setViewer(this._pdfViewer);
@@ -313,7 +313,7 @@ export class PDFViewer extends React.Component<IViewerProps> {
     onScroll = (e: React.UIEvent<HTMLElement>) => {
         if (this._mainCont.current && !this._forcedScroll) {
             this._ignoreScroll = true; // the pdf scrolled, so we need to tell the Doc to scroll but we don't want the doc to then try to set the PDF scroll pos (which would interfere with the smooth scroll animation)
-            if (!LinkDocPreview.LinkInfo) {
+            if (!LinkInfo.Instance?.LinkInfo) {
                 this._props.layoutDoc._layout_scrollTop = this._mainCont.current.scrollTop;
             }
             this._ignoreScroll = false;
-- 
cgit v1.2.3-70-g09d2

