11import { Children , ReactElement , ReactNode , cloneElement , useContext , useEffect } from 'react' ;
22import { AnnotoriousContext , DrawingStyle } from '@annotorious/react' ;
3- import { TextAnnotatorOptions , createTextAnnotator , TextAnnotation } from '@recogito/text-annotator' ;
4- import { RecogitoTEIAnnotator , TEIPlugin } from '@recogito/text-annotator-tei' ;
3+ import { TEIPlugin } from '@recogito/text-annotator-tei' ;
4+ import { createTextAnnotator } from '@recogito/text-annotator' ;
5+ import type { Filter , TextAnnotatorOptions , TextAnnotation } from '@recogito/text-annotator' ;
56
67import '@recogito/text-annotator/dist/text-annotator.css' ;
78
89export type TEIAnnotatorProps = TextAnnotatorOptions & {
910
1011 children ?: ReactNode | JSX . Element ;
1112
13+ filter ?: Filter ;
14+
1215 style ?: DrawingStyle | ( ( annotation : TextAnnotation ) => DrawingStyle ) ;
1316
1417}
@@ -19,17 +22,24 @@ export const TEIAnnotator = (props: TEIAnnotatorProps) => {
1922
2023 const onLoad = ( element : HTMLElement ) => {
2124 const anno = TEIPlugin ( createTextAnnotator ( element ) ) ;
22- anno . style = props . style ;
25+ anno . setStyle ( props . style ) ;
2326 setAnno ( anno ) ;
2427 }
2528
2629 useEffect ( ( ) => {
2730 if ( ! anno )
2831 return ;
2932
30- ( anno as RecogitoTEIAnnotator ) . style = props . style ;
33+ anno . setStyle ( props . style ) ;
3134 } , [ props . style ] ) ;
3235
36+ useEffect ( ( ) => {
37+ if ( ! anno )
38+ return ;
39+
40+ anno . setFilter ( props . filter ) ;
41+ } , [ props . filter ] ) ;
42+
3343 return props . children ?
3444 Children . toArray ( props . children ) . map ( child =>
3545 cloneElement ( child as ReactElement , { onLoad } ) ) : null ;
0 commit comments