diff --git a/frontend/src/core/components/viewer/AnnotationAPIBridge.tsx b/frontend/src/core/components/viewer/AnnotationAPIBridge.tsx index 7e37b3adb..a1c2f7881 100644 --- a/frontend/src/core/components/viewer/AnnotationAPIBridge.tsx +++ b/frontend/src/core/components/viewer/AnnotationAPIBridge.tsx @@ -4,7 +4,8 @@ import { PdfAnnotationSubtype, PdfAnnotationIcon } from '@embedpdf/models'; import type { AnnotationToolId, AnnotationToolOptions, AnnotationAPI } from '@app/components/viewer/viewerTypes'; export const AnnotationAPIBridge = forwardRef(function AnnotationAPIBridge(_props, ref) { - const annotationApi = useAnnotationCapability(); + // Use the provided annotation API just like SignatureAPIBridge/HistoryAPIBridge + const { provides: annotationApi } = useAnnotationCapability(); const getIconEnum = (icon?: string): PdfAnnotationIcon => { switch (icon) { @@ -164,13 +165,16 @@ export const AnnotationAPIBridge = forwardRef(function Annotation if (!annotationApi) return; const defaults = buildAnnotationDefaults(toolId, options); - const api = annotationApi as any; - if (defaults) { - api.setToolDefaults?.(toolId, defaults); + // Reset tool first, then activate (like SignatureAPIBridge does) + annotationApi.setActiveTool(null); + annotationApi.setActiveTool(toolId === 'select' ? null : toolId); + + // Verify tool was activated before setting defaults (like SignatureAPIBridge does) + const activeTool = annotationApi.getActiveTool(); + if (activeTool && activeTool.id === toolId && defaults) { + annotationApi.setToolDefaults(toolId, defaults); } - - api.setActiveTool?.(toolId === 'select' ? null : toolId); }, [annotationApi, buildAnnotationDefaults] ); diff --git a/frontend/src/core/components/viewer/EmbedPdfViewer.tsx b/frontend/src/core/components/viewer/EmbedPdfViewer.tsx index 559da623b..db530fb45 100644 --- a/frontend/src/core/components/viewer/EmbedPdfViewer.tsx +++ b/frontend/src/core/components/viewer/EmbedPdfViewer.tsx @@ -85,8 +85,8 @@ const EmbedPdfViewerContent = ({ // Check if we're in an annotation tool const { selectedTool } = useNavigationState(); - // Tools that require the annotation layer (Sign, Add Text, Add Image) - const isInAnnotationTool = selectedTool === 'sign' || selectedTool === 'addText' || selectedTool === 'addImage'; + // Tools that require the annotation layer (Sign, Add Text, Add Image, Annotate) + const isInAnnotationTool = selectedTool === 'sign' || selectedTool === 'addText' || selectedTool === 'addImage' || selectedTool === 'annotate'; // Sync isAnnotationMode in ViewerContext with current tool useEffect(() => { diff --git a/frontend/src/core/components/viewer/LocalEmbedPDF.tsx b/frontend/src/core/components/viewer/LocalEmbedPDF.tsx index 77b447c89..0b6c5df06 100644 --- a/frontend/src/core/components/viewer/LocalEmbedPDF.tsx +++ b/frontend/src/core/components/viewer/LocalEmbedPDF.tsx @@ -60,7 +60,7 @@ interface LocalEmbedPDFProps { historyApiRef?: React.RefObject; } -export function LocalEmbedPDF({ file, url, enableAnnotations = false, showBakedAnnotations = true, onSignatureAdded, signatureApiRef, historyApiRef }: LocalEmbedPDFProps) { +export function LocalEmbedPDF({ file, url, enableAnnotations = false, showBakedAnnotations = true, onSignatureAdded, signatureApiRef, annotationApiRef, historyApiRef }: LocalEmbedPDFProps) { const { t } = useTranslation(); const [pdfUrl, setPdfUrl] = useState(null); const [, setAnnotations] = useState>([]); diff --git a/frontend/src/core/tools/Annotate.tsx b/frontend/src/core/tools/Annotate.tsx index c2ea03f37..43fed68b3 100644 --- a/frontend/src/core/tools/Annotate.tsx +++ b/frontend/src/core/tools/Annotate.tsx @@ -1,6 +1,6 @@ import { useEffect, useMemo, useState, useContext, useCallback, useRef } from 'react'; import { useTranslation } from 'react-i18next'; -import { Alert, Text, Group, ActionIcon, Stack, Divider, Slider, Box, Tooltip as MantineTooltip, Button, TextInput, Textarea, NumberInput, Tooltip } from '@mantine/core'; +import { Alert, Text, Group, ActionIcon, Stack, Divider, Slider, Box, Tooltip as MantineTooltip, Button, TextInput, Textarea, NumberInput, Tooltip, Paper } from '@mantine/core'; import { createToolFlow } from '@app/components/tools/shared/createToolFlow'; import { useNavigation } from '@app/contexts/NavigationContext'; @@ -12,6 +12,7 @@ import { ColorPicker, ColorSwatchButton } from '@app/components/annotation/share import { ImageUploader } from '@app/components/annotation/shared/ImageUploader'; import LocalIcon from '@app/components/shared/LocalIcon'; import type { AnnotationToolId } from '@app/components/viewer/viewerTypes'; +import { SuggestedToolsSection } from '@app/components/tools/shared/SuggestedToolsSection'; const Annotate = (_props: BaseToolProps) => { const { t } = useTranslation(); @@ -366,10 +367,11 @@ const Annotate = (_props: BaseToolProps) => { ); const defaultStyleControls = ( - - {activeTool === 'stamp' ? ( - <> - {t('annotation.stampSettings', 'Stamp Settings')} + + + {activeTool === 'stamp' ? ( + <> + {t('annotation.stampSettings', 'Stamp Settings')} { if (file) { @@ -575,9 +577,8 @@ const Annotate = (_props: BaseToolProps) => { )} - - )} - + + ); const selectedAnnotationControls = selectedAnn && (() => { @@ -586,7 +587,8 @@ const Annotate = (_props: BaseToolProps) => { // Type 9: Highlight, Type 10: Underline, Type 11: Squiggly, Type 12: Strikeout if ([9, 10, 11, 12].includes(type)) { return ( - + + {t('annotation.editTextMarkup', 'Edit Text Markup')} {t('annotation.color', 'Color')} @@ -614,15 +616,17 @@ const Annotate = (_props: BaseToolProps) => { }} /> - + + ); } // Type 15: Ink (pen) if (type === 15) { return ( - - {t('annotation.editInk', 'Edit Pen')} + + + {t('annotation.editInk', 'Edit Pen')} {t('annotation.color', 'Color')} { }} /> - + + ); } // Type 3: Text box if (type === 3) { return ( - - {t('annotation.editText', 'Edit Text Box')} + + + {t('annotation.editText', 'Edit Text Box')} {t('annotation.color', 'Color')} { - + + ); } // Type 4: Line if (type === 4) { return ( - - {t('annotation.editLine', 'Edit Line')} + + + {t('annotation.editLine', 'Edit Line')} {t('annotation.color', 'Color')} { }} /> - + + ); } @@ -847,8 +856,9 @@ const Annotate = (_props: BaseToolProps) => { if ([5, 6, 7].includes(type)) { const shapeName = type === 5 ? 'Square' : type === 6 ? 'Circle' : 'Polygon'; return ( - - {t(`annotation.edit${shapeName}`, `Edit ${shapeName}`)} + + + {t(`annotation.edit${shapeName}`, `Edit ${shapeName}`)} {t('annotation.strokeColor', 'Stroke Color')} @@ -932,43 +942,24 @@ const Annotate = (_props: BaseToolProps) => { } - + + ); } // Default fallback return ( - - {t('annotation.editSelected', 'Edit Annotation')} - {t('annotation.unsupportedType', 'This annotation type is not fully supported for editing.')} - + + + {t('annotation.editSelected', 'Edit Annotation')} + {t('annotation.unsupportedType', 'This annotation type is not fully supported for editing.')} + + ); })(); - const saveAndColorPicker = ( + const colorPickerComponent = ( <> - setIsColorPickerOpen(false)} @@ -1224,8 +1215,11 @@ const Annotate = (_props: BaseToolProps) => { {/* Edit Selected */} {selectedAnn && selectedAnnotationControls} - {/* Save Button */} - {saveAndColorPicker} + {/* Color Picker */} + {colorPickerComponent} + + {/* Suggested Tools */} + ), },