diff --git a/package-lock.json b/package-lock.json index f2800c77..ec5dac8c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -61,6 +61,7 @@ "react-chartjs-2": "^3.3.0", "react-dom": "^16.13.1", "react-pdf": "^7.7.3", + "react-resize-detector": "^7.1.2", "resolve": "1.15.0", "resolve-url-loader": "^5.0.0", "semver": "6.3", @@ -21747,6 +21748,18 @@ } } }, + "node_modules/react-resize-detector": { + "version": "7.1.2", + "resolved": "https://registry.npmjs.org/react-resize-detector/-/react-resize-detector-7.1.2.tgz", + "integrity": "sha512-zXnPJ2m8+6oq9Nn8zsep/orts9vQv3elrpA+R8XTcW7DVVUJ9vwDwMXaBtykAYjMnkCIaOoK9vObyR7ZgFNlOw==", + "dependencies": { + "lodash": "^4.17.21" + }, + "peerDependencies": { + "react": "^16.0.0 || ^17.0.0 || ^18.0.0", + "react-dom": "^16.0.0 || ^17.0.0 || ^18.0.0" + } + }, "node_modules/read-pkg": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/read-pkg/-/read-pkg-2.0.0.tgz", @@ -43808,6 +43821,14 @@ "warning": "^4.0.0" } }, + "react-resize-detector": { + "version": "7.1.2", + "resolved": "https://registry.npmjs.org/react-resize-detector/-/react-resize-detector-7.1.2.tgz", + "integrity": "sha512-zXnPJ2m8+6oq9Nn8zsep/orts9vQv3elrpA+R8XTcW7DVVUJ9vwDwMXaBtykAYjMnkCIaOoK9vObyR7ZgFNlOw==", + "requires": { + "lodash": "^4.17.21" + } + }, "read-pkg": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/read-pkg/-/read-pkg-2.0.0.tgz", diff --git a/package.json b/package.json index 17bb4a18..c8777bf8 100644 --- a/package.json +++ b/package.json @@ -98,6 +98,7 @@ "react-chartjs-2": "^3.3.0", "react-dom": "^16.13.1", "react-pdf": "^7.7.3", + "react-resize-detector": "^7.1.2", "resolve": "1.15.0", "resolve-url-loader": "^5.0.0", "semver": "6.3", diff --git a/src/essence/Basics/Layers_/Layers_.js b/src/essence/Basics/Layers_/Layers_.js index 4cc9e09d..380490a1 100644 --- a/src/essence/Basics/Layers_/Layers_.js +++ b/src/essence/Basics/Layers_/Layers_.js @@ -3323,37 +3323,48 @@ const L_ = { } } } - //If there isn't one, search all string valued props for image urls - else { - for (var p in props) { - if ( - typeof props[p] === 'string' && - props[p].toLowerCase().match(/\.(jpeg|jpg|gif|png|xml)$/) != - null - ) { - var url = props[p] - if (!F_.isUrlAbsolute(url)) url = L_.missionPath + url - images.push({ - url: url, - name: p, - isPanoramic: false, - isModel: false, - }) - } - if ( - typeof props[p] === 'string' && - (props[p].toLowerCase().match(/\.(obj)$/) != null || - props[p].toLowerCase().match(/\.(dae)$/) != null) - ) { - var url = props[p] - if (!F_.isUrlAbsolute(url)) url = L_.missionPath + url - images.push({ - url: url, - name: p, - isPanoramic: false, - isModel: true, - }) - } + //Now search all string valued props for image urls + + for (let p in props) { + if ( + typeof props[p] === 'string' && + props[p].toLowerCase().match(/\.(jpeg|jpg|gif|png|xml)$/) != + null + ) { + let url = props[p] + if (!F_.isUrlAbsolute(url)) url = L_.missionPath + url + images.push({ + url: url, + name: p, + isPanoramic: false, + isModel: false, + }) + } else if ( + typeof props[p] === 'string' && + props[p].toLowerCase().match(/\.(pdf)$/) != null + ) { + let url = props[p] + if (!F_.isUrlAbsolute(url)) url = L_.missionPath + url + images.push({ + url: url, + name: p, + type: 'document', + isPanoramic: false, + isModel: false, + }) + } else if ( + typeof props[p] === 'string' && + (props[p].toLowerCase().match(/\.(obj)$/) != null || + props[p].toLowerCase().match(/\.(dae)$/) != null) + ) { + let url = props[p] + if (!F_.isUrlAbsolute(url)) url = L_.missionPath + url + images.push({ + url: url, + name: p, + isPanoramic: false, + isModel: true, + }) } } diff --git a/src/essence/Basics/Viewer_/PDFViewer.js b/src/essence/Basics/Viewer_/PDFViewer.js index e5391563..b3fe5902 100644 --- a/src/essence/Basics/Viewer_/PDFViewer.js +++ b/src/essence/Basics/Viewer_/PDFViewer.js @@ -1,6 +1,8 @@ import { render } from 'react-dom' import React, { useState, useEffect } from 'react' import { Document, Page, pdfjs } from 'react-pdf' +import { useResizeDetector } from 'react-resize-detector' + import 'react-pdf/dist/Page/AnnotationLayer.css' import 'react-pdf/dist/Page/TextLayer.css' @@ -14,25 +16,30 @@ const ReactPDF = (props) => { const zoomLevels = [0.25, 0.5, 0.75, 1, 1.25, 1.5, 2, 2.5, 3, 4, 5] const [zoom, setZoom] = useState(3) - function onDocumentLoadSuccess({ numPages }: { numPages: number }): void { - setNumPages(numPages) - } + const { width, height, ref } = useResizeDetector({ + handleHeight: false, + refreshMode: 'debounce', + refreshRate: 1000, + }) useEffect(() => { setZoom(3) }, [pdfPath]) + function onDocumentLoadSuccess({ numPages }: { numPages: number }): void { + setNumPages(numPages) + } const bcr = document .getElementById('pdfViewerWrapper') .getBoundingClientRect() - const width = bcr ? bcr.width - 40 : null + const pageWidth = bcr ? bcr.width - 40 : null return ( -