MCPcopy Create free account
hub / github.com/pacexy/flow / Annotation

Function Annotation

apps/reader/src/components/Annotation.tsx:110–145  ·  view source on GitHub ↗
({ tab, annotation })

Source from the content-addressed store, hash-verified

108 annotation: IAnnotation
109}
110const 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
147interface AnnotationsProps {
148 tab: BookTab

Callers

nothing calls this directly

Calls 3

setClickedAnnotationFunction · 0.85
setAnnotationRangeMethod · 0.80
removeMethod · 0.45

Tested by

no test coverage detected