Revize 6973d036
Přidáno uživatelem Lukáš Vlček před asi 2 roky(ů)
webapp/components/annotation/DocumentAnnotationView.tsx | ||
---|---|---|
4 | 4 |
*/ |
5 | 5 |
import { useContext } from 'react'; |
6 | 6 |
import { AnnotationContext } from '../../contexts/AnnotationContext'; |
7 |
import { Button } from 'antd'; |
|
8 |
import { DOCUMENT_INSTANCE_ID_ATTRIBUTE_NAME } from '../../constants'; |
|
7 |
import parse from 'html-react-parser'; |
|
8 |
import { |
|
9 |
DOCUMENT_INSTANCE_ID_ATTRIBUTE_NAME, |
|
10 |
DOCUMENT_OCCURRENCE_ID_ATTRIBUTE_NAME, |
|
11 |
DOCUMENT_TAG_ID_ATTRIBUTE_NAME, |
|
12 |
} from '../../constants'; |
|
9 | 13 |
|
10 | 14 |
export function DocumentAnnotationView() { |
11 |
const { annotation } = useContext(AnnotationContext); |
|
15 |
const { |
|
16 |
annotation, |
|
17 |
setSelectedInstanceId, |
|
18 |
setSelectedOccurrenceId, |
|
19 |
selectedInstanceId, |
|
20 |
selectedOccurrenceId, |
|
21 |
} = useContext(AnnotationContext); |
|
12 | 22 |
|
13 | 23 |
if (!annotation) { |
14 | 24 |
return <p>Probíhá načítání anotace ...</p>; |
15 | 25 |
} |
16 | 26 |
|
17 |
function getCss() { |
|
27 |
function detectSelectedElement(e: any) { |
|
28 |
if (!(e.target instanceof HTMLElement)) { |
|
29 |
return; |
|
30 |
} |
|
31 |
|
|
32 |
const target = e.target as HTMLElement; |
|
33 |
|
|
34 |
const id = target.getAttribute(DOCUMENT_TAG_ID_ATTRIBUTE_NAME); |
|
35 |
const idInstance = target.getAttribute(DOCUMENT_INSTANCE_ID_ATTRIBUTE_NAME); |
|
36 |
const idOccurrence = target.getAttribute(DOCUMENT_OCCURRENCE_ID_ATTRIBUTE_NAME); |
|
37 |
|
|
38 |
if (!id || !idInstance || !idOccurrence) { |
|
39 |
setSelectedInstanceId(null); |
|
40 |
setSelectedOccurrenceId(null); |
|
41 |
return; |
|
42 |
} |
|
18 | 43 |
|
44 |
setSelectedInstanceId(idInstance); |
|
45 |
setSelectedOccurrenceId(idOccurrence); |
|
46 |
} |
|
47 |
|
|
48 |
function getCss() { |
|
19 | 49 |
let css = 'span.annotation {border-bottom: 2px solid;}\n'; |
20 | 50 |
css += 'span {line-height: 30px}\n'; |
21 | 51 |
css += |
... | ... | |
27 | 57 |
css += `span[${DOCUMENT_INSTANCE_ID_ATTRIBUTE_NAME}="${info.instanceId}"] { border-color:${info.color}; padding-bottom: ${info.padding}px }\n`; |
28 | 58 |
} |
29 | 59 |
|
60 |
if (selectedInstanceId) { |
|
61 |
css += `span[${DOCUMENT_INSTANCE_ID_ATTRIBUTE_NAME}="${selectedInstanceId}"] { background-color: #FCF3CF; }\n`; |
|
62 |
} |
|
63 |
if (selectedOccurrenceId) { |
|
64 |
css += `span[${DOCUMENT_OCCURRENCE_ID_ATTRIBUTE_NAME}="${selectedOccurrenceId}"] { border-bottom: 4px dotted; }\n`; |
|
65 |
} |
|
66 |
|
|
30 | 67 |
return <style dangerouslySetInnerHTML={{ __html: css }}></style>; |
31 | 68 |
} |
32 | 69 |
|
33 | 70 |
return ( |
34 | 71 |
<div> |
35 | 72 |
{getCss()} |
36 |
<div |
|
37 |
dangerouslySetInnerHTML={{ __html: annotation.documentToRender ?? '' }}
|
|
38 |
/>
|
|
73 |
<div onClick={detectSelectedElement}>
|
|
74 |
{parse(annotation.documentToRender ?? '')}
|
|
75 |
</div>
|
|
39 | 76 |
</div> |
40 | 77 |
); |
41 | 78 |
} |
Také k dispozici: Unified diff
Selected tags highlighting
On click in the middle panel or on click on highlight buttons in the right panel