11import keyCode from '../../_util/KeyCode'
22
3+ export function isDev ( ) {
4+ return ( process . env . NODE_ENV !== 'production' )
5+ }
6+
37export function isEventFromHandle ( e , handles ) {
4- return Object . keys ( handles )
5- . some ( key => e . target === handles [ key ] . $el )
8+ try {
9+ return Object . keys ( handles )
10+ . some ( key => e . target === handles [ key ] . $el )
11+ } catch ( error ) {
12+ return false
13+ }
614}
715
816export function isValueOutOfRange ( value , { min, max } ) {
@@ -54,7 +62,7 @@ export function getHandleCenterPosition (vertical, handle) {
5462 const coords = handle . getBoundingClientRect ( )
5563 return vertical
5664 ? coords . top + ( coords . height * 0.5 )
57- : coords . left + ( coords . width * 0.5 )
65+ : window . pageXOffset + coords . left + ( coords . width * 0.5 )
5866}
5967
6068export function ensureValueInRange ( val , { max, min } ) {
@@ -69,7 +77,7 @@ export function ensureValueInRange (val, { max, min }) {
6977
7078export function ensureValuePrecision ( val , props ) {
7179 const { step } = props
72- const closestPoint = getClosestPoint ( val , props )
80+ const closestPoint = isFinite ( getClosestPoint ( val , props ) ) ? getClosestPoint ( val , props ) : 0 ; // eslint-disable-line
7381 return step === null ? closestPoint
7482 : parseFloat ( closestPoint . toFixed ( getPrecision ( step ) ) )
7583}
@@ -79,15 +87,32 @@ export function pauseEvent (e) {
7987 e . preventDefault ( )
8088}
8189
90+ export function calculateNextValue ( func , value , props ) {
91+ const operations = {
92+ increase : ( a , b ) => a + b ,
93+ decrease : ( a , b ) => a - b ,
94+ }
95+
96+ const indexToGet = operations [ func ] ( Object . keys ( props . marks ) . indexOf ( JSON . stringify ( value ) ) , 1 )
97+ const keyToGet = Object . keys ( props . marks ) [ indexToGet ]
98+
99+ if ( props . step ) {
100+ return operations [ func ] ( value , props . step )
101+ } else if ( ! ! Object . keys ( props . marks ) . length && ! ! props . marks [ keyToGet ] ) {
102+ return props . marks [ keyToGet ]
103+ }
104+ return value
105+ }
106+
82107export function getKeyboardValueMutator ( e ) {
83108 switch ( e . keyCode ) {
84109 case keyCode . UP :
85110 case keyCode . RIGHT :
86- return ( value , props ) => value + props . step
111+ return ( value , props ) => calculateNextValue ( 'increase' , value , props )
87112
88113 case keyCode . DOWN :
89114 case keyCode . LEFT :
90- return ( value , props ) => value - props . step
115+ return ( value , props ) => calculateNextValue ( 'decrease' , value , props )
91116
92117 case keyCode . END : return ( value , props ) => props . max
93118 case keyCode . HOME : return ( value , props ) => props . min
0 commit comments