@@ -14,6 +14,15 @@ import clamp from "clamp"
14
14
const getRandomId = ( ) => Math . random ( ) . toString ( ) . split ( "." ) [ 1 ]
15
15
16
16
export default ( state : MainLayoutState , action : Action ) => {
17
+ if (
18
+ state . allowedArea &&
19
+ [ "MOUSE_DOWN" , "MOUSE_UP" , "MOUSE_MOVE" ] . includes ( action . type )
20
+ ) {
21
+ const aa = state . allowedArea
22
+ action . x = clamp ( action . x , aa . x , aa . x + aa . w )
23
+ action . y = clamp ( action . y , aa . y , aa . y + aa . h )
24
+ }
25
+
17
26
if ( action . type === "ON_CLS_ADDED" && action . cls && action . cls !== "" ) {
18
27
const oldRegionClsList = state . regionClsList
19
28
const newState = {
@@ -208,12 +217,7 @@ export default (state: MainLayoutState, action: Action) => {
208
217
} )
209
218
}
210
219
case "MOUSE_MOVE ": {
211
- let { x , y } = action
212
- if ( state . allowedArea ) {
213
- const aa = state . allowedArea
214
- x = clamp ( x , aa . x , aa . x + aa . w )
215
- y = clamp ( y , aa . x , aa . x + aa . w )
216
- }
220
+ const { x , y } = action
217
221
218
222
if ( ! state . mode ) return state
219
223
if ( ! activeImage ) return state
@@ -359,13 +363,7 @@ export default (state: MainLayoutState, action: Action) => {
359
363
}
360
364
case "MOUSE_DOWN" : {
361
365
if ( ! activeImage ) return state
362
- let { x , y } = action
363
-
364
- if ( state . allowedArea ) {
365
- const aa = state . allowedArea
366
- x = clamp ( x , aa . x , aa . x + aa . w )
367
- y = clamp ( y , aa . x , aa . x + aa . w )
368
- }
366
+ const { x , y } = action
369
367
370
368
state = setIn ( state , [ "mouseDownAt" ] , { x, y } )
371
369
@@ -534,12 +532,7 @@ export default (state: MainLayoutState, action: Action) => {
534
532
return setIn ( state , [ ...pathToActiveImage , "regions" ] , regions )
535
533
}
536
534
case "MOUSE_UP ": {
537
- let { x , y } = action
538
- if ( state . allowedArea ) {
539
- const aa = state . allowedArea
540
- x = clamp ( x , aa . x , aa . x + aa . w )
541
- y = clamp ( y , aa . x , aa . x + aa . w )
542
- }
535
+ const { x , y } = action
543
536
544
537
const { mouseDownAt = { x, y } } = state
545
538
if ( ! state . mode ) return state
0 commit comments