({ tab })
| 15 | tab: BookTab |
| 16 | } |
| 17 | const FindMatches: React.FC<FindMatchProps> = ({ tab }) => { |
| 18 | const setAction = useSetAction() |
| 19 | const { rendition, results, currentHref } = useSnapshot(tab) |
| 20 | |
| 21 | useEffect(() => { |
| 22 | const result = results?.find((r) => compareHref(currentHref, r.id)) |
| 23 | |
| 24 | const matches = result?.subitems |
| 25 | matches?.forEach((m) => { |
| 26 | try { |
| 27 | const h = rendition?.annotations.highlight( |
| 28 | m.cfi!, |
| 29 | undefined, |
| 30 | undefined, |
| 31 | undefined, |
| 32 | { |
| 33 | // tailwind yellow-500 |
| 34 | fill: 'rgba(234, 179, 8, 0.3)', |
| 35 | 'fill-opacity': 'unset', |
| 36 | }, |
| 37 | ) |
| 38 | |
| 39 | const g = h?.mark.element as SVGGElement |
| 40 | g?.addEventListener('click', () => { |
| 41 | setClickedAnnotation(true) |
| 42 | }) |
| 43 | } catch (error) { |
| 44 | // ignore matched text in `<title>` |
| 45 | } |
| 46 | }) |
| 47 | |
| 48 | return () => { |
| 49 | matches?.forEach((m) => { |
| 50 | rendition?.annotations.remove(m.cfi!, 'highlight') |
| 51 | }) |
| 52 | } |
| 53 | }, [currentHref, rendition?.annotations, results, setAction]) |
| 54 | |
| 55 | return null |
| 56 | } |
| 57 | |
| 58 | interface DefinitionProps { |
| 59 | tab: BookTab |
nothing calls this directly
no test coverage detected