From 93ee735e435de5949a0eec54c07537c4de2eedf4 Mon Sep 17 00:00:00 2001
From: bobzel <zzzman@gmail.com>
Date: Tue, 7 Jan 2025 01:24:55 -0500
Subject: fixed pdfs/marqueeAnnotator so that you can add rectangle
 annotations.

---
 src/client/views/nodes/PDFBox.tsx | 34 ++++++++++++++++------------------
 1 file changed, 16 insertions(+), 18 deletions(-)

(limited to 'src/client/views/nodes/PDFBox.tsx')

diff --git a/src/client/views/nodes/PDFBox.tsx b/src/client/views/nodes/PDFBox.tsx
index 1de4d2512..06b75e243 100644
--- a/src/client/views/nodes/PDFBox.tsx
+++ b/src/client/views/nodes/PDFBox.tsx
@@ -1,5 +1,5 @@
 import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
-import { action, computed, IReactionDisposer, makeObservable, observable, reaction, runInAction } from 'mobx';
+import { action, computed, IReactionDisposer, makeObservable, observable, reaction } from 'mobx';
 import { observer } from 'mobx-react';
 import * as Pdfjs from 'pdfjs-dist';
 import 'pdfjs-dist/web/pdf_viewer.css';
@@ -40,8 +40,11 @@ export class PDFBox extends ViewBoxAnnotatableComponent<FieldViewProps>() {
     public static LayoutString(fieldKey: string) {
         return FieldView.LayoutString(PDFBox, fieldKey);
     }
+    static pdfcache = new Map<string, Pdfjs.PDFDocumentProxy>();
+    static pdfpromise = new Map<string, Promise<Pdfjs.PDFDocumentProxy>>();
     public static openSidebarWidth = 250;
     public static sidebarResizerWidth = 5;
+
     private _searchString: string = '';
     private _initialScrollTarget: Opt<Doc>;
     private _pdfViewer: PDFViewer | undefined;
@@ -63,11 +66,8 @@ export class PDFBox extends ViewBoxAnnotatableComponent<FieldViewProps>() {
         const nh = Doc.NativeHeight(this.Document, this.dataDoc) || 1200;
         !this.Document._layout_fitWidth && (this.Document._height = NumCast(this.Document._width) * (nh / nw));
         if (this.pdfUrl) {
-            if (PDFBox.pdfcache.get(this.pdfUrl.url.href))
-                runInAction(() => {
-                    this._pdf = PDFBox.pdfcache.get(this.pdfUrl!.url.href);
-                });
-            else if (PDFBox.pdfpromise.get(this.pdfUrl.url.href))
+            this._pdf = PDFBox.pdfcache.get(this.pdfUrl.url.href);
+            !this._pdf &&
                 PDFBox.pdfpromise.get(this.pdfUrl.url.href)?.then(
                     action(pdf => {
                         this._pdf = pdf;
@@ -265,12 +265,12 @@ export class PDFBox extends ViewBoxAnnotatableComponent<FieldViewProps>() {
     };
 
     @action
-    loaded = (nw: number, nh: number, np: number) => {
-        this.dataDoc[this._props.fieldKey + '_numPages'] = np;
-        Doc.SetNativeWidth(this.dataDoc, Math.max(Doc.NativeWidth(this.dataDoc), nw));
-        Doc.SetNativeHeight(this.dataDoc, nh);
+    loaded = (p: { width: number; height: number }, pages: number) => {
+        this.dataDoc[this._props.fieldKey + '_numPages'] = pages;
+        Doc.SetNativeWidth(this.dataDoc, Math.max(Doc.NativeWidth(this.dataDoc), p.width));
+        Doc.SetNativeHeight(this.dataDoc, p.height);
         this.layoutDoc._height = NumCast(this.layoutDoc._width) / (Doc.NativeAspect(this.dataDoc) || 1);
-        !this.Document._layout_fitWidth && (this.Document._height = NumCast(this.Document._width) * (nh / nw));
+        !this.Document._layout_fitWidth && (this.Document._height = NumCast(this.Document._width) * (p.height / p.width));
     };
 
     override search = action((searchString: string, bwd?: boolean, clear: boolean = false) => {
@@ -596,13 +596,11 @@ export class PDFBox extends ViewBoxAnnotatableComponent<FieldViewProps>() {
                 }}>
                 <div className="pdfBox-background" onPointerDown={e => this.sidebarBtnDown(e, false)} />
                 <div
+                    className="pdfBox-container"
                     style={{
                         width: `calc(${100 / viewScale}% - ${(this.sidebarWidth() / viewScale) * (this._previewWidth ? viewScale : 1)}px)`,
                         height: `${100 / viewScale}%`,
                         transform: `scale(${viewScale})`,
-                        position: 'absolute',
-                        transformOrigin: 'top left',
-                        top: 0,
                     }}>
                     <PDFViewer
                         {...this._props}
@@ -615,7 +613,7 @@ export class PDFBox extends ViewBoxAnnotatableComponent<FieldViewProps>() {
                         focus={this.focus}
                         url={this.pdfUrl!.url.pathname}
                         anchorMenuClick={this.anchorMenuClick}
-                        loaded={!Doc.NativeAspect(this.dataDoc) ? this.loaded : undefined}
+                        loaded={Doc.NativeAspect(this.dataDoc) ? emptyFunction : this.loaded}
                         setPdfViewer={this.setPdfViewer}
                         addDocument={this.addDocument}
                         moveDocument={this.moveDocument}
@@ -624,14 +622,14 @@ export class PDFBox extends ViewBoxAnnotatableComponent<FieldViewProps>() {
                         crop={this.crop}
                     />
                 </div>
-                <div style={{ position: 'absolute', height: '100%', right: 0, top: 0, width: `calc(100 * ${this.sidebarWidth() / this._props.PanelWidth()}%` }}>{this.sidebarCollection}</div>
+                <div className="pdfBox-sidebarContainer" style={{ width: `calc(100 * ${this.sidebarWidth() / this._props.PanelWidth()}%` }}>
+                    {this.sidebarCollection}
+                </div>
                 {this.settingsPanel()}
             </div>
         );
     }
 
-    static pdfcache = new Map<string, Pdfjs.PDFDocumentProxy>();
-    static pdfpromise = new Map<string, Promise<Pdfjs.PDFDocumentProxy>>();
     render() {
         TraceMobx();
         const pdfView = !this._pdf ? null : this.renderPdfView;
-- 
cgit v1.2.3-70-g09d2

