#1 PDF Application on GitHub that lets you edit PDFs on any device anywhere
TypeScript dockerhacktoberfestjavapdfpdf-converterpdf-editorpdf-manipulationpdf-mergerpdf-ocrpdf-toolspdf-web-appspdfmergerself-hosted
import { Box } from "@mantine/core";
import CoreViewer from "@editor-core/components/viewer/Viewer";
import type { ViewerProps } from "@editor-core/components/viewer/Viewer";
import type { EmbedPdfViewerProps } from "@editor-core/components/viewer/EmbedPdfViewer";
import { useViewer } from "@editor/contexts/ViewerContext";
import {
POLICY_IN_FLIGHT_STATUSES,
usePolicyRuns,
type PolicyRunRecord,
} from "@editor/components/policies/policyRunStore";
import { isClassificationPolicy } from "@editor/data/classificationPolicy";
import { PolicyEnforcementOverlay } from "@editor/components/viewer/PolicyEnforcementOverlay";
type SignatureOverlayPassThrough = Pick<
EmbedPdfViewerProps,
| "signaturePreviews"
| "readOnlySignaturePreviews"
| "signaturePreviewsReadOnly"
| "signaturePlacementMode"
| "signaturePlacementData"
| "signaturePlacementType"
| "onSignaturePreviewsChange"
| "signatureOverlayApiRef"
>;
const Viewer = (props: ViewerProps & SignatureOverlayPassThrough) => {
const { activeFileId } = useViewer();
const allRuns = usePolicyRuns();
const activeFileRuns = activeFileId
? allRuns.filter(
(r: PolicyRunRecord) =>
r.fileId === activeFileId &&
// Classification runs async and must never block the viewer.
!isClassificationPolicy(r.policyKey) &&
!r.externalOutput &&
(POLICY_IN_FLIGHT_STATUSES.includes(r.status) || r.retrying === true),
)
: [];
return (
// isolation: "isolate" keeps the overlay's z-index self-contained so it
// sits above EmbedPdfViewer's internal toolbar/sidebars regardless of
// their own z-index values.
<Box
data-testid="viewer-root"
data-file-id={activeFileId ?? ""}
style={{
position: "relative",
height: "100%",
isolation: "isolate",
}}
>
<CoreViewer {...props} />
{/* key resets dismissed state when the active file changes */}
<PolicyEnforcementOverlay
key={activeFileId ?? ""}
runs={activeFileRuns}
/>
</Box>
);
};
export default Viewer;