({ tab, annotation })
| 108 | annotation: IAnnotation |
| 109 | } |
| 110 | const Annotation: React.FC<AnnotationProps> = ({ tab, annotation }) => { |
| 111 | const { rendition } = useSnapshot(tab) |
| 112 | |
| 113 | useEffect(() => { |
| 114 | const h = rendition?.annotations[annotation.type]( |
| 115 | annotation.cfi, |
| 116 | undefined, |
| 117 | undefined, |
| 118 | undefined, |
| 119 | { |
| 120 | fill: colorMap[annotation.color], |
| 121 | 'fill-opacity': '0.5', |
| 122 | }, |
| 123 | ) |
| 124 | |
| 125 | const g = h?.mark?.element as SVGGElement |
| 126 | |
| 127 | // `<rect>` should be reserved to response `click` |
| 128 | g?.addEventListener('click', () => { |
| 129 | tab.setAnnotationRange(annotation.cfi) |
| 130 | setClickedAnnotation(true) |
| 131 | }) |
| 132 | |
| 133 | return () => { |
| 134 | rendition?.annotations.remove(annotation.cfi, annotation.type) |
| 135 | } |
| 136 | }, [ |
| 137 | annotation.cfi, |
| 138 | annotation.color, |
| 139 | annotation.type, |
| 140 | rendition?.annotations, |
| 141 | tab, |
| 142 | ]) |
| 143 | |
| 144 | return null |
| 145 | } |
| 146 | |
| 147 | interface AnnotationsProps { |
| 148 | tab: BookTab |
nothing calls this directly
no test coverage detected