@@ -65,7 +65,7 @@ function start ({ rect, startOffset, state, interaction, pageCoords }: ModifierA
65
65
state . offset = offset
66
66
}
67
67
68
- function set ( { coords, interaction, state } : ModifierArg < RestrictState > ) {
68
+ function set ( { coords, interaction, state, edges } : ModifierArg < RestrictState > ) {
69
69
const { options, offset } = state
70
70
71
71
const restriction = getRestrictionRect ( options . restriction , interaction , coords )
@@ -74,8 +74,43 @@ function set ({ coords, interaction, state }: ModifierArg<RestrictState>) {
74
74
75
75
const rect = rectUtils . xywhToTlbr ( restriction )
76
76
77
- coords . x = Math . max ( Math . min ( rect . right - offset . right , coords . x ) , rect . left + offset . left )
78
- coords . y = Math . max ( Math . min ( rect . bottom - offset . bottom , coords . y ) , rect . top + offset . top )
77
+ // Configure coords X
78
+ switch ( true ) {
79
+ // Drag
80
+ case edges . left && edges . right :
81
+ coords . x = Math . max ( Math . min ( rect . right - offset . right , coords . x ) , rect . left + offset . left )
82
+ break
83
+ // Resize
84
+ case edges . left :
85
+ coords . x = Math . max ( rect . left + offset . left , coords . x )
86
+ break
87
+ case edges . right :
88
+ coords . x = Math . min ( rect . right - offset . right , coords . x )
89
+ break
90
+ // Other
91
+ default :
92
+ coords . x = Math . max ( Math . min ( rect . right - offset . right , coords . x ) , rect . left + offset . left )
93
+ break
94
+ }
95
+
96
+ // Configure coords Y
97
+ switch ( true ) {
98
+ // Drag
99
+ case edges . top && edges . bottom :
100
+ coords . y = Math . max ( Math . min ( rect . bottom - offset . bottom , coords . y ) , rect . top + offset . top )
101
+ break
102
+ // Resize
103
+ case edges . top :
104
+ coords . y = Math . max ( rect . top + offset . top , coords . y )
105
+ break
106
+ case edges . bottom :
107
+ coords . y = Math . min ( rect . bottom - offset . bottom , coords . y )
108
+ break
109
+ // Other
110
+ default :
111
+ coords . y = Math . max ( Math . min ( rect . bottom - offset . bottom , coords . y ) , rect . top + offset . top )
112
+ break
113
+ }
79
114
}
80
115
81
116
export function getRestrictionRect (
0 commit comments