2023-02-08 14:20:55 +01:00
|
|
|
import { Fragment, useState } from "react";
|
2023-01-19 19:24:01 +01:00
|
|
|
import { Document, Page } from "react-pdf/dist/esm/entry.webpack5";
|
2023-02-16 18:31:06 +01:00
|
|
|
import EditableField from "./editable-field";
|
2023-02-24 18:05:32 +01:00
|
|
|
import SignableField from "./signable-field";
|
2023-02-09 13:14:40 +01:00
|
|
|
import short from "short-uuid";
|
2023-01-19 19:24:01 +01:00
|
|
|
|
2023-01-23 16:32:06 +01:00
|
|
|
export default function PDFViewer(props) {
|
2023-01-19 19:24:01 +01:00
|
|
|
const [numPages, setNumPages] = useState(null);
|
2023-01-24 19:10:24 +01:00
|
|
|
const [loading, setLoading] = useState(true);
|
2023-02-27 18:15:10 +01:00
|
|
|
const [pageHeight, setPageHeight] = useState(0);
|
2023-02-09 15:48:26 +01:00
|
|
|
|
|
|
|
|
function onPositionChangedHandler(position, id) {
|
2023-02-13 18:04:44 +01:00
|
|
|
props.onPositionChanged(position, id);
|
2023-02-09 15:48:26 +01:00
|
|
|
}
|
2023-01-19 19:24:01 +01:00
|
|
|
|
2023-02-14 17:04:53 +01:00
|
|
|
function onDeleteHandler(id) {
|
|
|
|
|
props.onDelete(id);
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-19 19:24:01 +01:00
|
|
|
function onDocumentLoadSuccess({ numPages: nextNumPages }) {
|
|
|
|
|
setNumPages(nextNumPages);
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-19 20:11:02 +01:00
|
|
|
const options = {
|
|
|
|
|
cMapUrl: "cmaps/",
|
|
|
|
|
cMapPacked: true,
|
|
|
|
|
standardFontDataUrl: "standard_fonts/",
|
|
|
|
|
};
|
|
|
|
|
|
2023-01-19 19:24:01 +01:00
|
|
|
return (
|
|
|
|
|
<>
|
2023-02-27 18:15:10 +01:00
|
|
|
<div
|
|
|
|
|
hidden={loading}
|
|
|
|
|
onMouseUp={props.onMouseUp}
|
|
|
|
|
style={{ height: numPages * pageHeight + 1000 }}
|
|
|
|
|
>
|
2023-02-13 18:04:44 +01:00
|
|
|
<div className="max-w-xs mt-6"></div>
|
2023-01-19 20:24:49 +01:00
|
|
|
<Document
|
2023-01-23 16:32:06 +01:00
|
|
|
file={props.pdfUrl}
|
2023-01-19 20:24:49 +01:00
|
|
|
onLoadSuccess={onDocumentLoadSuccess}
|
|
|
|
|
options={options}
|
2023-02-22 17:23:51 +01:00
|
|
|
renderMode="canvas"
|
2023-02-27 18:15:10 +01:00
|
|
|
className="absolute w-auto mx-auto left-0 right-0"
|
2023-01-19 20:24:49 +01:00
|
|
|
>
|
|
|
|
|
{Array.from({ length: numPages }, (_, index) => (
|
2023-02-09 13:14:40 +01:00
|
|
|
<Fragment key={short.generate().toString()}>
|
2023-02-08 14:20:55 +01:00
|
|
|
<div
|
2023-02-22 17:23:51 +01:00
|
|
|
onMouseDown={(e) => {
|
|
|
|
|
props.onMouseDown(e, index);
|
|
|
|
|
}}
|
2023-02-22 20:09:30 +01:00
|
|
|
onMouseUp={(e) => {
|
|
|
|
|
props.onMouseUp(e, index);
|
|
|
|
|
}}
|
2023-02-09 13:14:40 +01:00
|
|
|
key={short.generate().toString()}
|
2023-02-08 14:20:55 +01:00
|
|
|
style={{
|
|
|
|
|
position: "relative",
|
2023-03-07 16:34:51 +01:00
|
|
|
...props.style,
|
2023-02-08 14:20:55 +01:00
|
|
|
}}
|
2023-02-13 18:13:04 +01:00
|
|
|
className="mx-auto w-fit"
|
2023-02-08 14:20:55 +01:00
|
|
|
>
|
2023-02-13 18:13:04 +01:00
|
|
|
<Page
|
|
|
|
|
className="mt-5"
|
|
|
|
|
key={`page_${index + 1}`}
|
|
|
|
|
pageNumber={index + 1}
|
|
|
|
|
renderAnnotationLayer={false}
|
|
|
|
|
renderTextLayer={false}
|
2023-02-27 18:15:10 +01:00
|
|
|
onLoadSuccess={(e) => {
|
|
|
|
|
if (e.height) setPageHeight(e.height);
|
2023-02-22 17:54:54 +01:00
|
|
|
setLoading(false);
|
|
|
|
|
}}
|
2023-02-13 18:13:04 +01:00
|
|
|
onRenderError={() => setLoading(false)}
|
|
|
|
|
></Page>
|
|
|
|
|
{props?.fields
|
|
|
|
|
.filter((item) => item.page === index)
|
2023-02-16 18:31:06 +01:00
|
|
|
.map((item) =>
|
|
|
|
|
props.readonly ? (
|
2023-02-24 18:05:32 +01:00
|
|
|
<SignableField
|
2023-02-16 18:31:06 +01:00
|
|
|
onClick={props.onClick}
|
|
|
|
|
key={item.id}
|
|
|
|
|
field={item}
|
|
|
|
|
className="absolute"
|
2023-02-24 16:12:56 +01:00
|
|
|
onDelete={onDeleteHandler}
|
2023-02-24 18:05:32 +01:00
|
|
|
></SignableField>
|
2023-02-16 18:31:06 +01:00
|
|
|
) : (
|
|
|
|
|
<EditableField
|
2023-03-09 14:00:54 +01:00
|
|
|
hidden={item.Signature || item.inserted}
|
2023-02-16 18:31:06 +01:00
|
|
|
key={item.id}
|
|
|
|
|
field={item}
|
|
|
|
|
className="absolute"
|
|
|
|
|
onPositionChanged={onPositionChangedHandler}
|
|
|
|
|
onDelete={onDeleteHandler}
|
|
|
|
|
></EditableField>
|
|
|
|
|
)
|
|
|
|
|
)}
|
2023-02-08 14:20:55 +01:00
|
|
|
</div>
|
|
|
|
|
</Fragment>
|
2023-01-19 20:24:49 +01:00
|
|
|
))}
|
|
|
|
|
</Document>
|
|
|
|
|
</div>
|
2023-02-13 18:14:48 +01:00
|
|
|
<div className="mx-auto mt-10 w-[600px]" hidden={!loading}>
|
2023-01-24 19:10:24 +01:00
|
|
|
<div className="ph-item">
|
|
|
|
|
<div className="ph-col-12">
|
|
|
|
|
<div className="ph-picture"></div>
|
|
|
|
|
<div className="ph-row">
|
|
|
|
|
<div className="ph-col-6 big"></div>
|
|
|
|
|
<div className="ph-col-4 empty big"></div>
|
|
|
|
|
<div className="ph-col-2 big"></div>
|
|
|
|
|
<div className="ph-col-4"></div>
|
|
|
|
|
<div className="ph-col-8 empty"></div>
|
|
|
|
|
<div className="ph-col-6"></div>
|
|
|
|
|
<div className="ph-col-6 empty"></div>
|
|
|
|
|
<div className="ph-col-12"></div>
|
|
|
|
|
</div>
|
2023-01-24 20:09:40 +01:00
|
|
|
<div className="ph-row">
|
|
|
|
|
<div className="ph-col-6 big"></div>
|
|
|
|
|
<div className="ph-col-4 empty big"></div>
|
|
|
|
|
<div className="ph-col-2 big"></div>
|
|
|
|
|
<div className="ph-col-4"></div>
|
|
|
|
|
<div className="ph-col-8 empty"></div>
|
|
|
|
|
<div className="ph-col-6"></div>
|
|
|
|
|
<div className="ph-col-6 empty"></div>
|
|
|
|
|
<div className="ph-col-12"></div>
|
|
|
|
|
</div>
|
|
|
|
|
<div className="ph-row">
|
|
|
|
|
<div className="ph-col-6 big"></div>
|
|
|
|
|
<div className="ph-col-4 empty big"></div>
|
|
|
|
|
<div className="ph-col-2 big"></div>
|
|
|
|
|
<div className="ph-col-4"></div>
|
|
|
|
|
<div className="ph-col-8 empty"></div>
|
|
|
|
|
<div className="ph-col-6"></div>
|
|
|
|
|
<div className="ph-col-6 empty"></div>
|
|
|
|
|
<div className="ph-col-12"></div>
|
|
|
|
|
</div>
|
|
|
|
|
<div className="ph-row">
|
|
|
|
|
<div className="ph-col-6 big"></div>
|
|
|
|
|
<div className="ph-col-4 empty big"></div>
|
|
|
|
|
<div className="ph-col-2 big"></div>
|
|
|
|
|
<div className="ph-col-4"></div>
|
|
|
|
|
<div className="ph-col-8 empty"></div>
|
|
|
|
|
<div className="ph-col-6"></div>
|
|
|
|
|
<div className="ph-col-6 empty"></div>
|
|
|
|
|
<div className="ph-col-12"></div>
|
|
|
|
|
</div>
|
|
|
|
|
<div className="ph-row">
|
|
|
|
|
<div className="ph-col-6 big"></div>
|
|
|
|
|
<div className="ph-col-4 empty big"></div>
|
|
|
|
|
<div className="ph-col-2 big"></div>
|
|
|
|
|
<div className="ph-col-4"></div>
|
|
|
|
|
<div className="ph-col-8 empty"></div>
|
|
|
|
|
<div className="ph-col-6"></div>
|
|
|
|
|
<div className="ph-col-6 empty"></div>
|
|
|
|
|
<div className="ph-col-12"></div>
|
|
|
|
|
</div>
|
|
|
|
|
<div className="ph-row">
|
|
|
|
|
<div className="ph-col-6 big"></div>
|
|
|
|
|
<div className="ph-col-4 empty big"></div>
|
|
|
|
|
<div className="ph-col-2 big"></div>
|
|
|
|
|
<div className="ph-col-4"></div>
|
|
|
|
|
<div className="ph-col-8 empty"></div>
|
|
|
|
|
<div className="ph-col-6"></div>
|
|
|
|
|
<div className="ph-col-6 empty"></div>
|
|
|
|
|
<div className="ph-col-12"></div>
|
|
|
|
|
</div>
|
2023-01-24 19:10:24 +01:00
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
2023-01-19 19:24:01 +01:00
|
|
|
</>
|
|
|
|
|
);
|
|
|
|
|
}
|