-
Notifications
You must be signed in to change notification settings - Fork 223
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of github.com:Zipstack/unstract into feat/UN-1451…
…-pdm-lock-automation
- Loading branch information
Showing
6 changed files
with
74 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
frontend/src/components/custom-tools/pdf-viewer/Highlight.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
.pdf-container { | ||
position: relative; | ||
} | ||
|
||
.highlight { | ||
position: absolute; | ||
background-color: yellow; | ||
opacity: 0.5; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,43 @@ | ||
import { useRef } from "react"; | ||
import { Viewer, Worker } from "@react-pdf-viewer/core"; | ||
import { defaultLayoutPlugin } from "@react-pdf-viewer/default-layout"; | ||
import { pageNavigationPlugin } from "@react-pdf-viewer/page-navigation"; | ||
import PropTypes from "prop-types"; | ||
import { highlightPlugin } from "@react-pdf-viewer/highlight"; | ||
import "@react-pdf-viewer/highlight/lib/styles/index.css"; | ||
import "./Highlight.css"; | ||
|
||
function PdfViewer({ fileUrl }) { | ||
let RenderHighlights; | ||
try { | ||
RenderHighlights = | ||
require("../../../plugins/pdf-highlight/RenderHighlights").RenderHighlights; | ||
} catch (err) { | ||
// Do nothing, No plugin will be loaded. | ||
} | ||
|
||
function PdfViewer({ fileUrl, highlightData }) { | ||
const newPlugin = defaultLayoutPlugin(); | ||
const pageNavigationPluginInstance = pageNavigationPlugin(); | ||
const parentRef = useRef(null); | ||
let highlightPluginInstance = ""; | ||
if (RenderHighlights && highlightData) { | ||
highlightPluginInstance = highlightPlugin({ | ||
renderHighlights: (props) => ( | ||
<RenderHighlights {...props} highlightData={highlightData} /> | ||
), | ||
}); | ||
} | ||
|
||
return ( | ||
<div className="doc-manager-body"> | ||
<div ref={parentRef} className="doc-manager-body"> | ||
<Worker workerUrl="https://unpkg.com/[email protected]/build/pdf.worker.min.js"> | ||
<Viewer | ||
fileUrl={fileUrl} | ||
plugins={[newPlugin, pageNavigationPluginInstance]} | ||
plugins={[ | ||
newPlugin, | ||
pageNavigationPluginInstance, | ||
highlightPluginInstance, | ||
]} | ||
/> | ||
</Worker> | ||
</div> | ||
|
@@ -21,6 +46,7 @@ function PdfViewer({ fileUrl }) { | |
|
||
PdfViewer.propTypes = { | ||
fileUrl: PropTypes.any, | ||
highlightData: PropTypes.array, | ||
}; | ||
|
||
export { PdfViewer }; |