|
@@ -67,8 +67,6 @@ const HighlightTools: React.FC<Props> = ({
|
|
|
) as HTMLElement;
|
|
|
}
|
|
|
if (textLayer) {
|
|
|
- textLayer.style.zIndex = '10';
|
|
|
-
|
|
|
const newMarkup = getMarkupWithSelection({
|
|
|
...data,
|
|
|
scale,
|
|
@@ -83,10 +81,6 @@ const HighlightTools: React.FC<Props> = ({
|
|
|
}
|
|
|
}
|
|
|
if (selection?.isCollapsed) {
|
|
|
- if (textLayer) {
|
|
|
- textLayer.style.zIndex = '0';
|
|
|
- }
|
|
|
-
|
|
|
setCurrentId('');
|
|
|
}
|
|
|
},
|
|
@@ -124,29 +118,37 @@ const HighlightTools: React.FC<Props> = ({
|
|
|
}
|
|
|
}, [annotations, data, scale, currentId]);
|
|
|
|
|
|
+ const subscribeEvent = () => {
|
|
|
+ document.addEventListener('mousedown', handleDown);
|
|
|
+ document.addEventListener('mousemove', handleMove);
|
|
|
+ document.addEventListener('mouseup', handleUp);
|
|
|
+ document.addEventListener('selectstart', handleSelectStart);
|
|
|
+ document.addEventListener('touchstart', handleDown);
|
|
|
+ document.addEventListener('touchmove', handleMove);
|
|
|
+ document.addEventListener('touchend', handleUp);
|
|
|
+ document.addEventListener('selectionchange', handleSelectChange);
|
|
|
+ };
|
|
|
+
|
|
|
+ const unsubscribeEvent = () => {
|
|
|
+ document.removeEventListener('mousedown', handleDown);
|
|
|
+ document.removeEventListener('mousemove', handleMove);
|
|
|
+ document.removeEventListener('mouseup', handleUp);
|
|
|
+ document.removeEventListener('selectstart', handleSelectStart);
|
|
|
+ document.removeEventListener('touchstart', handleDown);
|
|
|
+ document.removeEventListener('touchmove', handleMove);
|
|
|
+ document.removeEventListener('touchend', handleUp);
|
|
|
+ document.removeEventListener('selectionchange', handleSelectChange);
|
|
|
+ };
|
|
|
+
|
|
|
useEffect(() => {
|
|
|
if (isActive) {
|
|
|
- document.addEventListener('mousedown', handleDown);
|
|
|
- document.addEventListener('mousemove', handleMove);
|
|
|
- document.addEventListener('mouseup', handleUp);
|
|
|
- document.addEventListener('selectstart', handleSelectStart);
|
|
|
- document.addEventListener('touchstart', handleDown);
|
|
|
- document.addEventListener('touchmove', handleMove);
|
|
|
- document.addEventListener('touchend', handleUp);
|
|
|
- document.addEventListener('selectionchange', handleSelectChange);
|
|
|
- } else if (textLayer) {
|
|
|
- textLayer.style.zIndex = '0';
|
|
|
+ subscribeEvent();
|
|
|
+ } else {
|
|
|
+ unsubscribeEvent();
|
|
|
}
|
|
|
|
|
|
return (): void => {
|
|
|
- document.removeEventListener('mousedown', handleDown);
|
|
|
- document.removeEventListener('mousemove', handleMove);
|
|
|
- document.removeEventListener('mouseup', handleUp);
|
|
|
- document.removeEventListener('selectstart', handleSelectStart);
|
|
|
- document.removeEventListener('touchstart', handleDown);
|
|
|
- document.removeEventListener('touchmove', handleMove);
|
|
|
- document.removeEventListener('touchend', handleUp);
|
|
|
- document.removeEventListener('selectionchange', handleSelectChange);
|
|
|
+ unsubscribeEvent();
|
|
|
};
|
|
|
}, [isActive, handleUp, handleSelectChange]);
|
|
|
|