11// @flow  
2- import  React ,  {  Fragment ,  useRef ,  useState ,  useLayoutEffect  }  from  "react" 
2+ import  React ,  { 
3+  Fragment , 
4+  useRef , 
5+  useState , 
6+  useLayoutEffect , 
7+  useEffect 
8+ }  from  "react" 
39import  {  Matrix  }  from  "transformation-matrix-js" 
410import  getImageData  from  "get-image-data" 
511import  Crosshairs  from  "../Crosshairs" 
@@ -21,6 +27,7 @@ import HighlightBox from "../HighlightBox"
2127// import excludePatternSrc from "./xpattern.png" 
2228import  excludePatternSrc  from  "./xpattern.js" 
2329import  PreventScrollToParents  from  "../PreventScrollToParents" 
30+ import  useWindowSize  from  "../hooks/use-window-size.js" 
2431
2532const  useStyles  =  makeStyles ( styles ) 
2633
@@ -30,6 +37,14 @@ const boxCursorMap = [
3037 [ "sw-resize" ,  "s-resize" ,  "se-resize" ] 
3138] 
3239
40+ const  copyWithout  =  ( obj ,  ...args )  =>  { 
41+  const  newObj  =  {  ...obj  } 
42+  for  ( const  arg  of  args )  { 
43+  delete  newObj [ arg ] 
44+  } 
45+  return  newObj 
46+ } 
47+ 
3348type  Props  =  { 
3449 regions : Array < Region > , 
3550 imageSrc : string , 
@@ -106,6 +121,11 @@ export default ({
106121 const  prevMousePosition  =  useRef ( {  x : 0 ,  y : 0  } ) 
107122 const  [ mat ,  changeMat ]  =  useState ( getDefaultMat ( ) ) 
108123 const  maskImages  =  useRef ( { } ) 
124+  const  windowSize  =  useWindowSize ( ) 
125+ 
126+  useLayoutEffect ( ( )  =>  { 
127+  changeMat ( mat . clone ( ) ) 
128+  } ,  [ windowSize ] ) 
109129
110130 const  innerMousePos  =  mat . applyToPoint ( 
111131 mousePosition . current . x , 
@@ -720,7 +740,9 @@ export default ({
720740 left : 0 , 
721741 ...( displayOnTop  ? {  bottom : 0  }  : {  top : 0  } ) 
722742 } } 
723-  { ...( ! region . editingLabels  ? mouseEvents  : { } ) } 
743+  { ...( ! region . editingLabels 
744+  ? copyWithout ( mouseEvents ,  "onMouseDown" ,  "onMouseUp" ) 
745+  : { } ) } 
724746 > 
725747 < RegionLabel 
726748 allowedClasses = { regionClsList } 
0 commit comments