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

Function Definition

apps/reader/src/components/Annotation.tsx:62–104  ·  view source on GitHub ↗
({ tab, definition })

Source from the content-addressed store, hash-verified

60 definition: string
61}
62const Definition: React.FC<DefinitionProps> = ({ tab, definition }) => {
63 const setAction = useSetAction()
64 const { rendition, currentHref } = useSnapshot(tab)
65
66 useEffect(() => {
67 const result = tab.searchInSection(definition)
68 const matches = result?.subitems
69
70 matches?.forEach((m) => {
71 try {
72 const h = rendition?.annotations.highlight(
73 m.cfi!,
74 undefined,
75 undefined,
76 undefined,
77 {
78 // tailwind gray-600
79 fill: 'rgba(75, 85, 99, 0.15)',
80 'fill-opacity': 'unset',
81 },
82 )
83
84 const g = h?.mark.element as SVGGElement
85
86 // `<rect>` should be reserved to response `click`
87 g?.addEventListener('click', () => {
88 tab.setAnnotationRange(m.cfi!)
89 setClickedAnnotation(true)
90 })
91 } catch (error) {
92 // ignore matched text in `<title>`
93 }
94 })
95
96 return () => {
97 matches?.forEach((m) =>
98 rendition?.annotations.remove(m.cfi!, 'highlight'),
99 )
100 }
101 }, [currentHref, definition, rendition?.annotations, setAction, tab])
102
103 return null
104}
105
106interface AnnotationProps {
107 tab: BookTab

Callers

nothing calls this directly

Calls 7

useSetActionFunction · 0.90
setClickedAnnotationFunction · 0.85
searchInSectionMethod · 0.80
setAnnotationRangeMethod · 0.80
forEachMethod · 0.45
highlightMethod · 0.45
removeMethod · 0.45

Tested by

no test coverage detected