|
@@ -1,5 +1,4 @@
|
|
|
import React, { useEffect, useState, useCallback } from 'react';
|
|
|
-import { v4 as uuidv4 } from 'uuid';
|
|
|
|
|
|
import Icon from '../components/Icon';
|
|
|
import Button from '../components/Button';
|
|
@@ -19,6 +18,7 @@ type Props = {
|
|
|
|
|
|
let timer: any = null;
|
|
|
let textLayer: any = null;
|
|
|
+// let currentId: string = '';
|
|
|
|
|
|
const HighlightTools: React.FC<Props> = ({
|
|
|
title,
|
|
@@ -67,8 +67,9 @@ const HighlightTools: React.FC<Props> = ({
|
|
|
'[data-id="text-layer"]'
|
|
|
) as HTMLElement;
|
|
|
}
|
|
|
-
|
|
|
if (textLayer) {
|
|
|
+ textLayer.style.zIndex = 10;
|
|
|
+
|
|
|
const newMarkup = getMarkupWithSelection({
|
|
|
...data,
|
|
|
scale,
|
|
@@ -76,15 +77,17 @@ const HighlightTools: React.FC<Props> = ({
|
|
|
});
|
|
|
|
|
|
if (newMarkup) {
|
|
|
- const id = uuidv4();
|
|
|
- newMarkup.id = id;
|
|
|
- setCurrentId(id);
|
|
|
+ setCurrentId(newMarkup.id as string);
|
|
|
addAnnots([newMarkup]);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
if (selection?.isCollapsed) {
|
|
|
+ if (textLayer) {
|
|
|
+ textLayer.style.zIndex = 0;
|
|
|
+ }
|
|
|
+
|
|
|
setCurrentId('');
|
|
|
}
|
|
|
},
|
|
@@ -107,22 +110,20 @@ const HighlightTools: React.FC<Props> = ({
|
|
|
});
|
|
|
|
|
|
if (newMarkup) {
|
|
|
- const newAnnota = annotations.reduce(
|
|
|
- (acc: AnnotationType[], cur: AnnotationType) => {
|
|
|
- if (cur.id === newMarkup.id) {
|
|
|
- acc.push(newMarkup);
|
|
|
- } else {
|
|
|
- acc.push(cur);
|
|
|
- }
|
|
|
- return acc;
|
|
|
- },
|
|
|
- []
|
|
|
- );
|
|
|
- updateAnnots(newAnnota);
|
|
|
+ const array: any = [];
|
|
|
+ annotations.forEach(ele => {
|
|
|
+ if (ele.id === currentId) {
|
|
|
+ // eslint-disable-next-line no-param-reassign
|
|
|
+ ele.obj_attr.position = newMarkup.obj_attr.position;
|
|
|
+ }
|
|
|
+ array.push(ele);
|
|
|
+ });
|
|
|
+
|
|
|
+ updateAnnots(array);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- }, [data, scale, currentId]);
|
|
|
+ }, [annotations, data, scale, currentId]);
|
|
|
|
|
|
useEffect(() => {
|
|
|
if (isActive) {
|
|
@@ -134,6 +135,8 @@ const HighlightTools: React.FC<Props> = ({
|
|
|
document.addEventListener('touchend', handleUp);
|
|
|
document.addEventListener('selectstart', handleSelectStart);
|
|
|
document.addEventListener('selectionchange', handleSelectChange);
|
|
|
+ } else if (textLayer) {
|
|
|
+ textLayer.style.zIndex = 0;
|
|
|
}
|
|
|
|
|
|
return (): void => {
|