From f82458be8bc8beaab387cc2813b7b18c9b3caac2 Mon Sep 17 00:00:00 2001 From: Sam Wilkins Date: Sun, 22 Sep 2019 17:16:18 -0400 Subject: initial commit post master merge --- src/client/views/pdf/Annotation.tsx | 10 ++-- src/client/views/pdf/PDFAnnotationLayer.scss | 6 -- src/client/views/pdf/PDFAnnotationLayer.tsx | 21 ------- src/client/views/pdf/PDFViewer.tsx | 89 ++++++++++++++-------------- src/client/views/pdf/Page.scss | 5 ++ src/client/views/pdf/Page.tsx | 2 +- 6 files changed, 56 insertions(+), 77 deletions(-) delete mode 100644 src/client/views/pdf/PDFAnnotationLayer.scss delete mode 100644 src/client/views/pdf/PDFAnnotationLayer.tsx (limited to 'src/client/views/pdf') diff --git a/src/client/views/pdf/Annotation.tsx b/src/client/views/pdf/Annotation.tsx index eeb2531a2..a9fa883c8 100644 --- a/src/client/views/pdf/Annotation.tsx +++ b/src/client/views/pdf/Annotation.tsx @@ -1,20 +1,18 @@ import React = require("react"); import { action, IReactionDisposer, observable, reaction, runInAction } from "mobx"; import { observer } from "mobx-react"; -import { Doc, DocListCast, HeightSym, WidthSym } from "../../../new_fields/Doc"; +import { Doc, DocListCast, HeightSym, WidthSym, Opt } from "../../../new_fields/Doc"; import { Id } from "../../../new_fields/FieldSymbols"; import { List } from "../../../new_fields/List"; import { Cast, FieldValue, NumCast, StrCast } from "../../../new_fields/Types"; import { DocumentManager } from "../../util/DocumentManager"; import PDFMenu from "./PDFMenu"; import "./Annotation.scss"; -import { scale } from "./PDFViewer"; -import { PresBox } from "../nodes/PresBox"; interface IAnnotationProps { anno: Doc; fieldExtensionDoc: Doc; - addDocTab: (document: Doc, dataDoc: Doc | undefined, where: string) => void; + addDocTab: (document: Doc, dataDoc: Opt, where: string) => boolean; pinToPres: (document: Doc) => void; } @@ -31,7 +29,7 @@ interface IRegionAnnotationProps { width: number; height: number; fieldExtensionDoc: Doc; - addDocTab: (document: Doc, dataDoc: Doc | undefined, where: string) => void; + addDocTab: (document: Doc, dataDoc: Doc | undefined, where: string) => boolean; pinToPres: (document: Doc) => void; document: Doc; } @@ -58,7 +56,7 @@ class RegionAnnotation extends React.Component { runInAction(() => this._brushed = brushed); } } - ) + ); } componentWillUnmount() { diff --git a/src/client/views/pdf/PDFAnnotationLayer.scss b/src/client/views/pdf/PDFAnnotationLayer.scss deleted file mode 100644 index 733533007..000000000 --- a/src/client/views/pdf/PDFAnnotationLayer.scss +++ /dev/null @@ -1,6 +0,0 @@ -.pdfAnnotationLayer-cont { - width:100%; - height:100%; - position:relative; - top:-200%; -} \ No newline at end of file diff --git a/src/client/views/pdf/PDFAnnotationLayer.tsx b/src/client/views/pdf/PDFAnnotationLayer.tsx deleted file mode 100644 index 4f267a5c0..000000000 --- a/src/client/views/pdf/PDFAnnotationLayer.tsx +++ /dev/null @@ -1,21 +0,0 @@ -import React = require("react"); -import { observer } from "mobx-react"; -import "./PDFAnnotationLayer.scss"; - -interface IAnnotationProps { - -} - -@observer -export class PDFAnnotationLayer extends React.Component { - onPointerDown = (e: React.PointerEvent) => { - if (e.ctrlKey) { - console.log("annotating"); - e.stopPropagation(); - } - } - - render() { - return
; - } -} \ No newline at end of file diff --git a/src/client/views/pdf/PDFViewer.tsx b/src/client/views/pdf/PDFViewer.tsx index 7bc1d3507..b82c3bb32 100644 --- a/src/client/views/pdf/PDFViewer.tsx +++ b/src/client/views/pdf/PDFViewer.tsx @@ -1,5 +1,5 @@ import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; -import { action, computed, IReactionDisposer, observable, reaction, runInAction } from "mobx"; +import { action, computed, IReactionDisposer, observable, reaction, runInAction, trace } from "mobx"; import { observer } from "mobx-react"; import * as Pdfjs from "pdfjs-dist"; import "pdfjs-dist/web/pdf_viewer.css"; @@ -19,6 +19,7 @@ import Annotation from "./Annotation"; import Page from "./Page"; import "./PDFViewer.scss"; import React = require("react"); +import requestPromise = require("request-promise"); const PDFJSViewer = require("pdfjs-dist/web/pdf_viewer"); export const scale = 2; @@ -35,7 +36,8 @@ interface IViewerProps { scrollTo: (y: number) => void; active: () => boolean; setPanY?: (n: number) => void; - addDocTab: (document: Doc, dataDoc: Doc | undefined, where: string) => void; + GoToPage?: (n: number) => void; + addDocTab: (document: Doc, dataDoc: Doc | undefined, where: string) => boolean; pinToPres: (document: Doc) => void; addDocument?: (doc: Doc, allowDuplicates?: boolean) => boolean; } @@ -61,7 +63,7 @@ export class PDFViewer extends React.Component { private _filterReactionDisposer?: IReactionDisposer; private _viewer: React.RefObject = React.createRef(); private _mainCont: React.RefObject = React.createRef(); - private _pdfViewer: any; + public _pdfViewer: any; private _pdfFindController: any; private _searchString: string = ""; private _selectionText: string = ""; @@ -77,18 +79,12 @@ export class PDFViewer extends React.Component { } @computed get allAnnotations() { - let annotations = DocListCast(this.props.fieldExtensionDoc.annotations); - return annotations.filter(anno => { - let run = this._script.run({ this: anno }); - return run.success ? run.result : true; - }) + return DocListCast(this.props.fieldExtensionDoc.annotations).filter( + anno => this._script.run({ this: anno }, console.log, true).result); } @computed get nonDocAnnotations() { - return this._annotations.filter(anno => { - let run = this._script.run({ this: anno }); - return run.success ? run.result : true; - }); + return this._annotations.filter(anno => this._script.run({ this: anno }, console.log, true).result); } componentDidUpdate = (prevProps: IViewerProps) => this.panY !== prevProps.panY && this.renderPages(); @@ -114,10 +110,7 @@ export class PDFViewer extends React.Component { if (this._script.originalScript !== oldScript) { this.Index = -1; } - annos.forEach(d => { - let run = this._script.run(d); - d.opacity = !run.success || run.result ? 1 : 0; - }); + annos.forEach(d => d.opacity = this._script.run({ this: d }, console.log, 1).result ? 1 : 0); }), { fireImmediately: true } ); @@ -372,7 +365,7 @@ export class PDFViewer extends React.Component { @action search = (searchString: string) => { if (this._pdfViewer._pageViewsReady) { - this._pdfFindController.executeCommand('find', { + this._pdfFindController.executeCommand('findagain', { caseSensitive: false, findPrevious: undefined, highlightAll: true, @@ -381,13 +374,15 @@ export class PDFViewer extends React.Component { }); } else if (this._mainCont.current) { - let executeFind = () => this._pdfFindController.executeCommand('find', { - caseSensitive: false, - findPrevious: undefined, - highlightAll: true, - phraseSearch: true, - query: searchString - }); + let executeFind = () => { + this._pdfFindController.executeCommand('find', { + caseSensitive: false, + findPrevious: undefined, + highlightAll: true, + phraseSearch: true, + query: searchString + }); + }; this._mainCont.current.addEventListener("pagesloaded", executeFind); this._mainCont.current.addEventListener("pagerendered", executeFind); } @@ -400,14 +395,14 @@ export class PDFViewer extends React.Component { this._searching = !this._searching; if (this._searching) { - if (!this._pdfFindController && this._mainCont.current && this._viewer.current) { - let simpleLinkService = new SimpleLinkService(); + if (!this._pdfFindController && this._mainCont.current && this._viewer.current && !this._pdfViewer) { + let simpleLinkService = new SimpleLinkService(this); this._pdfViewer = new PDFJSViewer.PDFViewer({ container: this._mainCont.current, viewer: this._viewer.current, linkService: simpleLinkService }); - simpleLinkService.setPdf(this.props.pdf); + simpleLinkService.setPDFJSview(this._pdfViewer); this._mainCont.current.addEventListener("pagesinit", () => this._pdfViewer.currentScaleValue = 1); this._mainCont.current.addEventListener("pagerendered", () => console.log("rendered")); this._pdfViewer.setDocument(this.props.pdf); @@ -415,21 +410,16 @@ export class PDFViewer extends React.Component { this._pdfViewer.findController = this._pdfFindController; } } - else { - this._pdfFindController = null; - if (this._viewer.current) { - let cns = this._viewer.current.childNodes; - for (let i = cns.length - 1; i >= 0; i--) { - cns.item(i).remove(); - } - } - } + } + @computed get visibleElementWrapper() { + trace(); + return this._visibleElements; } render() { return (
- {this._visibleElements} + {this.visibleElementWrapper}
@@ -467,9 +457,13 @@ export class PDFViewer extends React.Component { export enum AnnotationTypes { Region } class SimpleLinkService { - externalLinkTarget: any = null; - externalLinkRel: any = null; - pdf: any = null; + _viewer: PDFViewer; + _pdfjsView: any; + + constructor(viewer: PDFViewer) { + this._viewer = viewer; + } + setPDFJSview(v: any) { this._pdfjsView = v; } navigateTo() { } @@ -479,15 +473,24 @@ class SimpleLinkService { setHash() { } + isPageVisible(page: number) { return true; } + executeNamedAction() { } cachePageRef() { } - get pagesCount() { return this.pdf ? this.pdf.numPages : 0; } + get pagesCount() { return this._viewer._pdfViewer.pagesCount; } - get page() { return 0; } + get page() { return NumCast(this._viewer.props.Document.curPage); } + set page(p: number) { + this._pdfjsView._ensurePdfPageLoaded(this._pdfjsView._pages[p - 1]).then(() => { + this._pdfjsView.renderingQueue.renderView(this._pdfjsView._pages[p - 1]); + if (this._viewer.props.GoToPage) { + this._viewer.props.GoToPage(p); + } + }); + } - setPdf(pdf: any) { this.pdf = pdf; } get rotation() { return 0; } set rotation(value: any) { } diff --git a/src/client/views/pdf/Page.scss b/src/client/views/pdf/Page.scss index af1628a6f..d8034b4b4 100644 --- a/src/client/views/pdf/Page.scss +++ b/src/client/views/pdf/Page.scss @@ -1,4 +1,9 @@ +.pdfViewer-text { + .page { + position: relative; + } +} .pdfPage-cont { position: relative; diff --git a/src/client/views/pdf/Page.tsx b/src/client/views/pdf/Page.tsx index 856e883e7..533247170 100644 --- a/src/client/views/pdf/Page.tsx +++ b/src/client/views/pdf/Page.tsx @@ -137,7 +137,7 @@ export default class Page extends React.Component { view.nativeWidth = this.props.Document.nativeWidth; view.startY = marquee.top + this.props.getScrollFromPage(this.props.page); view.width = this.props.Document[WidthSym](); - DragManager.StartDocumentDrag([], new DragManager.DocumentDragData([view], [undefined]), 0, 0); + DragManager.StartDocumentDrag([], new DragManager.DocumentDragData([view]), 0, 0); } @action -- cgit v1.2.3-70-g09d2