diff --git a/frontend/src/components/viewer/LocalEmbedPDF.tsx b/frontend/src/components/viewer/LocalEmbedPDF.tsx index 610bd2582..a7fe26d6e 100644 --- a/frontend/src/components/viewer/LocalEmbedPDF.tsx +++ b/frontend/src/components/viewer/LocalEmbedPDF.tsx @@ -20,11 +20,6 @@ import { RotatePluginPackage, Rotate } from '@embedpdf/plugin-rotate/react'; import { ExportPluginPackage } from '@embedpdf/plugin-export/react'; import { Rotation } from '@embedpdf/models'; -// Import annotation plugins -import { HistoryPluginPackage } from '@embedpdf/plugin-history/react'; -import { AnnotationLayer, AnnotationPluginPackage } from '@embedpdf/plugin-annotation/react'; -import { PdfAnnotationSubtype } from '@embedpdf/models'; - // Import annotation plugins import { HistoryPluginPackage } from '@embedpdf/plugin-history/react'; import { AnnotationLayer, AnnotationPluginPackage } from '@embedpdf/plugin-annotation/react'; @@ -42,23 +37,20 @@ import { ThumbnailAPIBridge } from './ThumbnailAPIBridge'; import { RotateAPIBridge } from './RotateAPIBridge'; import { SignatureAPIBridge, SignatureAPI } from './SignatureAPIBridge'; import { HistoryAPIBridge, HistoryAPI } from './HistoryAPIBridge'; -import { SignatureAPIBridge, SignatureAPI } from './SignatureAPIBridge'; -import { HistoryAPIBridge, HistoryAPI } from './HistoryAPIBridge'; import { ExportAPIBridge } from './ExportAPIBridge'; interface LocalEmbedPDFProps { file?: File | Blob; url?: string | null; - enableSignature?: boolean; + enableAnnotations?: boolean; onSignatureAdded?: (annotation: any) => void; signatureApiRef?: React.RefObject; historyApiRef?: React.RefObject; } -export function LocalEmbedPDF({ file, url, enableSignature = false, onSignatureAdded, signatureApiRef, historyApiRef }: LocalEmbedPDFProps) { +export function LocalEmbedPDF({ file, url, enableAnnotations = false, onSignatureAdded, signatureApiRef, historyApiRef }: LocalEmbedPDFProps) { const [pdfUrl, setPdfUrl] = useState(null); const [, setAnnotations] = useState>([]); - const [, setAnnotations] = useState>([]); // Convert File to URL if needed useEffect(() => { @@ -101,10 +93,10 @@ export function LocalEmbedPDF({ file, url, enableSignature = false, onSignatureA createPluginRegistration(SelectionPluginPackage), // Register history plugin for undo/redo (recommended for annotations) - ...(enableSignature ? [createPluginRegistration(HistoryPluginPackage)] : []), + ...(enableAnnotations ? [createPluginRegistration(HistoryPluginPackage)] : []), // Register annotation plugin (depends on InteractionManager, Selection, History) - ...(enableSignature ? [createPluginRegistration(AnnotationPluginPackage, { + ...(enableAnnotations ? [createPluginRegistration(AnnotationPluginPackage, { annotationAuthor: 'Digital Signature', autoCommit: true, deactivateToolAfterCreate: false, @@ -205,7 +197,7 @@ export function LocalEmbedPDF({ file, url, enableSignature = false, onSignatureA { + onInitialized={enableAnnotations ? async (registry) => { const annotationPlugin = registry.getPlugin('annotation'); if (!annotationPlugin || !annotationPlugin.provides) return; @@ -276,8 +268,8 @@ export function LocalEmbedPDF({ file, url, enableSignature = false, onSignatureA - {enableSignature && } - {enableSignature && } + {enableAnnotations && } + {enableAnnotations && } {/* Annotation layer for signatures (only when enabled) */} - {enableSignature && ( + {enableAnnotations && ( (function SignatureAPI // Use stamp tool for image/canvas signatures annotationApi.setActiveTool('stamp'); const activeTool = annotationApi.getActiveTool(); + if (activeTool && activeTool.id === 'stamp') { annotationApi.setToolDefaults('stamp', { imageSrc: signatureConfig.signatureData,