1- import useAnnotationStore from "@/hooks/annotation-store/use-annotation-store"
21import { useExportCapability } from "@embedpdf/plugin-export/react"
3- import { useZoom } from "@embedpdf/plugin-zoom/react"
2+ import { useZoomCapability } from "@embedpdf/plugin-zoom/react"
43import {
54 Download ,
65 Highlighter ,
@@ -11,22 +10,17 @@ import {
1110 ZoomIn ,
1211 ZoomOut ,
1312} from "lucide-react"
13+ import usePluginStore from "../plugin-store/hooks/use-plugin-store"
1414
1515const Toolbar = ( ) => {
16- const { provides : exportApi } = useExportCapability ( )
17- const { provides : zoom } = useZoom ( )
16+ const { provides : exportCapability } = useExportCapability ( )
17+ const { provides : zoomCapability } = useZoomCapability ( )
1818
19- const {
20- capability : annotationApi ,
21- activeToolId,
22- selectedUid,
23- canUndo,
24- canRedo,
25- } = useAnnotationStore ( )
19+ const { annoCapability, annoState } = usePluginStore ( )
2620
2721 const handleDelete = ( ) => {
28- if ( selectedUid ) {
29- annotationApi ?. deleteAnnotation ( selectedUid )
22+ if ( annoState ?. selectedUid ) {
23+ annoCapability ?. deleteAnnotation ( annoState . selectedUid )
3024 }
3125 }
3226
@@ -41,10 +35,12 @@ const Toolbar = () => {
4135 < button
4236 key = { tool . id }
4337 onClick = { ( ) => {
44- annotationApi ?. activateTool ( tool . id === activeToolId ? null : tool . id )
38+ annoCapability ?. activateTool ( tool . id === annoState ?. activeToolId ? null : tool . id )
4539 } }
4640 className = { `rounded-md px-3 py-1 text-sm font-medium transition-colors ${
47- tool . id === activeToolId ? "bg-blue-500 text-white" : "bg-gray-100 hover:bg-gray-200"
41+ tool . id === annoState ?. activeToolId
42+ ? "bg-blue-500 text-white"
43+ : "bg-gray-100 hover:bg-gray-200"
4844 } `}
4945 title = { tool . id }
5046 >
@@ -55,16 +51,16 @@ const Toolbar = () => {
5551 < div className = "h-6 w-px bg-gray-200" />
5652
5753 < button
58- onClick = { ( ) => zoom ?. zoomOut ( ) }
59- disabled = { ! zoom }
54+ onClick = { ( ) => zoomCapability ?. zoomOut ( ) }
55+ disabled = { ! zoomCapability }
6056 className = "rounded-md bg-gray-500 px-3 py-1 text-sm font-medium text-white transition-colors hover:bg-gray-600 disabled:cursor-not-allowed disabled:bg-gray-300"
6157 title = "Zoom out"
6258 >
6359 < ZoomOut size = { 18 } />
6460 </ button >
6561 < button
66- onClick = { ( ) => zoom ?. zoomIn ( ) }
67- disabled = { ! zoom }
62+ onClick = { ( ) => zoomCapability ?. zoomIn ( ) }
63+ disabled = { ! zoomCapability }
6864 className = "rounded-md bg-gray-500 px-3 py-1 text-sm font-medium text-white transition-colors hover:bg-gray-600 disabled:cursor-not-allowed disabled:bg-gray-300"
6965 title = "Zoom in"
7066 >
@@ -74,16 +70,16 @@ const Toolbar = () => {
7470 < div className = "h-6 w-px bg-gray-200" />
7571
7672 < button
77- onClick = { ( ) => annotationApi ?. undo ( ) }
78- disabled = { ! canUndo }
73+ onClick = { ( ) => annoCapability ?. undo ( ) }
74+ disabled = { ! annoState ?. canUndo }
7975 className = "rounded-md bg-gray-100 px-3 py-1 text-sm font-medium transition-colors hover:bg-gray-200 disabled:cursor-not-allowed disabled:opacity-50"
8076 title = "Undo"
8177 >
8278 < Undo2 size = { 18 } />
8379 </ button >
8480 < button
85- onClick = { ( ) => annotationApi ?. redo ( ) }
86- disabled = { ! canRedo }
81+ onClick = { ( ) => annoCapability ?. redo ( ) }
82+ disabled = { ! annoState ?. canRedo }
8783 className = "rounded-md bg-gray-100 px-3 py-1 text-sm font-medium transition-colors hover:bg-gray-200 disabled:cursor-not-allowed disabled:opacity-50"
8884 title = "Redo"
8985 >
@@ -93,23 +89,23 @@ const Toolbar = () => {
9389 < div className = "h-6 w-px bg-gray-200" />
9490
9591 < button
96- onClick = { ( ) => annotationApi ?. exportAnnotationsToJSON ?.( ) }
92+ onClick = { ( ) => annoCapability ?. exportAnnotationsToJSON ?.( ) }
9793 className = "rounded-md bg-blue-500 px-3 py-1 text-sm font-medium text-white transition-colors hover:bg-blue-600"
9894 title = "Export Annotations to JSON"
9995 >
10096 Export JSON
10197 </ button >
10298 < button
103- onClick = { ( ) => exportApi ?. download ( ) }
104- disabled = { ! exportApi }
99+ onClick = { ( ) => exportCapability ?. download ( ) }
100+ disabled = { ! exportCapability }
105101 className = "rounded-md bg-green-500 px-3 py-1 text-sm font-medium text-white transition-colors hover:bg-green-600 disabled:cursor-not-allowed disabled:bg-green-300"
106102 title = "Download Annotated PDF"
107103 >
108104 < Download size = { 18 } />
109105 </ button >
110106 < button
111107 onClick = { handleDelete }
112- disabled = { ! selectedUid }
108+ disabled = { ! annoState ?. selectedUid }
113109 className = "rounded-md bg-red-500 px-3 py-1 text-sm font-medium text-white transition-colors hover:bg-red-600 disabled:cursor-not-allowed disabled:bg-red-300"
114110 title = "Delete Selected Annotation"
115111 >
0 commit comments