react-input-mask
Advanced tools
Comparing version 0.0.7 to 0.0.8
@@ -63,11 +63,14 @@ "use strict"; | ||
}, | ||
formatValue: function formatValue(value) { | ||
formatValue: function formatValue(value, newState) { | ||
var _this2 = this; | ||
var maskChar = this.state.maskChar; | ||
var mask = this.state.mask; | ||
var _ref = newState || this.state; | ||
var maskChar = _ref.maskChar; | ||
var mask = _ref.mask; | ||
return value.split("").concat(Array.apply(null, Array(mask.length - value.length))).map(function (char, pos) { | ||
if (_this2.isAllowedChar(char, pos)) { | ||
if (_this2.isAllowedChar(char, pos, newState)) { | ||
return char; | ||
} else if (_this2.isPermanentChar(pos)) { | ||
} else if (_this2.isPermanentChar(pos, newState)) { | ||
return mask[pos]; | ||
@@ -97,5 +100,5 @@ } | ||
}, | ||
isAllowedChar: function isAllowedChar(char, pos) { | ||
var mask = this.state.mask; | ||
if (this.isPermanentChar(pos)) { | ||
isAllowedChar: function isAllowedChar(char, pos, newState) { | ||
var mask = newState ? newState.mask : this.state.mask; | ||
if (this.isPermanentChar(pos, newState)) { | ||
return mask[pos] === char; | ||
@@ -107,4 +110,5 @@ } | ||
}, | ||
isPermanentChar: function isPermanentChar(pos) { | ||
return this.state.permanents.indexOf(pos) !== -1; | ||
isPermanentChar: function isPermanentChar(pos, newState) { | ||
var permanents = newState ? newState.permanents : this.state.permanents; | ||
return permanents.indexOf(pos) !== -1; | ||
}, | ||
@@ -239,21 +243,17 @@ setCaretToEnd: function setCaretToEnd() { | ||
componentWillReceiveProps: function componentWillReceiveProps(nextProps) { | ||
var _this5 = this; | ||
var mask = this.parseMask(nextProps.mask); | ||
var maskChar = typeof this.props.maskChar === "string" ? nextProps.maskChar : this.defaultMaskChar; | ||
var state = { | ||
mask: mask.mask, | ||
permanents: mask.permanents, | ||
maskChar: typeof this.props.maskChar === "string" ? nextProps.maskChar : this.defaultMaskChar | ||
maskChar: maskChar | ||
}; | ||
this.setState(state, function () { | ||
var newValue = _this5.getStringValue(nextProps.value); | ||
if (_this5.state.mask && (newValue || _this5.isFocused())) { | ||
newValue = _this5.formatValue(newValue); | ||
} | ||
if (newValue !== _this5.state.value) { | ||
_this5.setState({ | ||
value: newValue | ||
}); | ||
} | ||
}); | ||
var newValue = this.getStringValue(nextProps.value); | ||
if (mask.mask && (newValue || this.isFocused())) { | ||
newValue = this.formatValue(newValue, state); | ||
} | ||
if (this.state.value !== newValue) { | ||
state.value = newValue; | ||
} | ||
this.setState(state); | ||
}, | ||
@@ -260,0 +260,0 @@ onKeyDown: function onKeyDown(event) { |
@@ -55,12 +55,11 @@ // https://github.com/sanniassin/react-input-mask | ||
}, | ||
formatValue: function(value) { | ||
var maskChar = this.state.maskChar; | ||
var mask = this.state.mask; | ||
formatValue: function(value, newState) { | ||
var { maskChar, mask } = newState || this.state; | ||
return value.split("") | ||
.concat(Array.apply(null, Array(mask.length - value.length))) | ||
.map((char, pos) => { | ||
if (this.isAllowedChar(char, pos)) { | ||
if (this.isAllowedChar(char, pos, newState)) { | ||
return char; | ||
} | ||
else if (this.isPermanentChar(pos)) { | ||
else if (this.isPermanentChar(pos, newState)) { | ||
return mask[pos]; | ||
@@ -91,5 +90,5 @@ } | ||
}, | ||
isAllowedChar: function(char, pos) { | ||
var mask = this.state.mask; | ||
if (this.isPermanentChar(pos)) { | ||
isAllowedChar: function(char, pos, newState) { | ||
var mask = newState ? newState.mask : this.state.mask; | ||
if (this.isPermanentChar(pos, newState)) { | ||
return mask[pos] === char; | ||
@@ -101,4 +100,5 @@ } | ||
}, | ||
isPermanentChar: function(pos) { | ||
return this.state.permanents.indexOf(pos) !== -1; | ||
isPermanentChar: function(pos, newState) { | ||
var permanents = newState ? newState.permanents : this.state.permanents; | ||
return permanents.indexOf(pos) !== -1; | ||
}, | ||
@@ -237,18 +237,16 @@ setCaretToEnd: function() { | ||
var mask = this.parseMask(nextProps.mask); | ||
var maskChar = typeof this.props.maskChar === "string" ? nextProps.maskChar : this.defaultMaskChar; | ||
var state = { | ||
mask: mask.mask, | ||
permanents: mask.permanents, | ||
maskChar: typeof this.props.maskChar === "string" ? nextProps.maskChar : this.defaultMaskChar | ||
maskChar: maskChar | ||
}; | ||
this.setState(state, () => { | ||
var newValue = this.getStringValue(nextProps.value); | ||
if (this.state.mask && (newValue || this.isFocused())) { | ||
newValue = this.formatValue(newValue); | ||
} | ||
if (newValue !== this.state.value) { | ||
this.setState({ | ||
value: newValue | ||
}); | ||
} | ||
}); | ||
var newValue = this.getStringValue(nextProps.value); | ||
if (mask.mask && (newValue || this.isFocused())) { | ||
newValue = this.formatValue(newValue, state); | ||
} | ||
if (this.state.value !== newValue) { | ||
state.value = newValue; | ||
} | ||
this.setState(state); | ||
}, | ||
@@ -255,0 +253,0 @@ onKeyDown: function(event) { |
{ | ||
"name": "react-input-mask", | ||
"description": "Masked input component for React", | ||
"version": "0.0.7", | ||
"version": "0.0.8", | ||
"homepage": "https://github.com/sanniassin/react-input-mask", | ||
@@ -6,0 +6,0 @@ "license": "MIT", |
31603
844