@@ -5,10 +5,10 @@ import {
5
5
MainLayoutState ,
6
6
RegionAllowedActions ,
7
7
} from "../MainLayout/types.ts" ;
8
- import { ComponentType , FunctionComponent , useEffect , useReducer } from "react" ;
8
+ import { ComponentType , forwardRef , FunctionComponent , useEffect , useImperativeHandle , useReducer , useRef } from "react" ;
9
9
10
10
import type { KeypointsDefinition } from "../types/region-tools.ts" ;
11
- import MainLayout from "../MainLayout/index.tsx" ;
11
+ import MainLayout , { MainLayoutRef } from "../MainLayout/index.tsx" ;
12
12
import SettingsProvider from "../SettingsProvider/index.tsx" ;
13
13
import combineReducers from "./reducers/combine-reducers.ts" ;
14
14
import generalReducer from "./reducers/general-reducer.ts" ;
@@ -54,7 +54,11 @@ export type AnnotatorProps = {
54
54
onPrevImage ?: ( state : MainLayoutState ) => void ;
55
55
} ;
56
56
57
- export const Annotator = ( {
57
+ export interface AnnotatorRef {
58
+ clickHeaderButton : ( name : string ) => void ;
59
+ }
60
+
61
+ export const Annotator = forwardRef < AnnotatorRef , AnnotatorProps > ( ( {
58
62
images,
59
63
allowedArea,
60
64
selectedImage = images && images . length > 0 ? 0 : undefined ,
@@ -98,14 +102,23 @@ export const Annotator = ({
98
102
hideFullScreen,
99
103
hideSave,
100
104
allowComments,
101
- } : AnnotatorProps ) => {
105
+ } , ref ) => {
102
106
if ( typeof selectedImage === "string" ) {
103
107
selectedImage = ( images || [ ] ) . findIndex (
104
108
( img ) => img . name === selectedImage
105
109
) ;
106
110
107
111
if ( selectedImage === - 1 ) selectedImage = undefined ;
108
112
}
113
+
114
+ const mainLayoutRef = useRef < MainLayoutRef > ( null ) ;
115
+
116
+ useImperativeHandle ( ref , ( ) => ( {
117
+ clickHeaderButton ( name : string ) {
118
+ mainLayoutRef . current ?. clickHeaderButton ( name ) ;
119
+ } ,
120
+ } ) ) ;
121
+
109
122
const combinedReducers = combineReducers ( imageReducer , generalReducer ) as (
110
123
state : MainLayoutState ,
111
124
action : Action
@@ -186,6 +199,7 @@ export const Annotator = ({
186
199
return (
187
200
< SettingsProvider >
188
201
< MainLayout
202
+ ref = { mainLayoutRef }
189
203
RegionEditLabel = { RegionEditLabel }
190
204
alwaysShowNextButton = { Boolean ( onNextImage ) }
191
205
alwaysShowPrevButton = { Boolean ( onPrevImage ) }
@@ -203,6 +217,6 @@ export const Annotator = ({
203
217
/>
204
218
</ SettingsProvider >
205
219
) ;
206
- } ;
220
+ } ) ;
207
221
208
222
export default Annotator ;
0 commit comments