Socket
Socket
Sign inDemoInstall

react-input-mask

Package Overview
Dependencies
Maintainers
1
Versions
90
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-input-mask - npm Package Compare versions

Comparing version 1.0.7 to 1.1.0

965

dist/react-input-mask.js

@@ -9,2 +9,74 @@ (function (global, factory) {

function _typeof(obj) {
if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") {
_typeof = function (obj) {
return typeof obj;
};
} else {
_typeof = function (obj) {
return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
};
}
return _typeof(obj);
}
function _extends() {
_extends = Object.assign || function (target) {
for (var i = 1; i < arguments.length; i++) {
var source = arguments[i];
for (var key in source) {
if (Object.prototype.hasOwnProperty.call(source, key)) {
target[key] = source[key];
}
}
}
return target;
};
return _extends.apply(this, arguments);
}
function _inheritsLoose(subClass, superClass) {
subClass.prototype = Object.create(superClass.prototype);
subClass.prototype.constructor = subClass;
subClass.__proto__ = superClass;
}
function _instanceof(left, right) {
if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
return right[Symbol.hasInstance](left);
} else {
return left instanceof right;
}
}
function _objectWithoutProperties(source, excluded) {
if (source == null) return {};
var target = {};
var sourceKeys = Object.keys(source);
var key, i;
for (i = 0; i < sourceKeys.length; i++) {
key = sourceKeys[i];
if (excluded.indexOf(key) >= 0) continue;
target[key] = source[key];
}
if (Object.getOwnPropertySymbols) {
var sourceSymbolKeys = Object.getOwnPropertySymbols(source);
for (i = 0; i < sourceSymbolKeys.length; i++) {
key = sourceSymbolKeys[i];
if (excluded.indexOf(key) >= 0) continue;
if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
target[key] = source[key];
}
}
return target;
}
var defaultCharsRules = {

@@ -15,3 +87,2 @@ '9': '[0-9]',

};
var defaultMaskChar = '_';

@@ -23,2 +94,3 @@

}
if (charsRules == null) {

@@ -38,2 +110,3 @@ charsRules = defaultCharsRules;

}
var str = '';

@@ -44,3 +117,2 @@ var prefix = '';

var lastEditablePos = null;
mask.split('').forEach(function (character) {

@@ -52,2 +124,3 @@ if (!isPermanent && character === '\\') {

permanents.push(str.length);
if (str.length === permanents.length - 1) {

@@ -59,2 +132,3 @@ prefix += character;

}
str += character;

@@ -64,3 +138,2 @@ isPermanent = false;

});
return {

@@ -83,3 +156,2 @@ maskChar: maskChar,

}
function isWindowsPhoneBrowser() {

@@ -91,3 +163,2 @@ var windows = new RegExp('windows', 'i');

}
function isAndroidFirefox() {

@@ -104,3 +175,2 @@ var windows = new RegExp('windows', 'i');

}
function isAllowedChar(maskOptions, pos, character) {

@@ -110,3 +180,2 @@ var mask = maskOptions.mask,

if (!character) {

@@ -122,6 +191,4 @@ return false;

var charRule = charsRules[ruleChar];
return new RegExp(charRule).test(character);
}
function isEmpty(maskOptions, value) {

@@ -132,3 +199,2 @@ return value.split('').every(function (character, i) {

}
function getFilledLength(maskOptions, value) {

@@ -138,3 +204,2 @@ var maskChar = maskOptions.maskChar,

if (!maskChar) {

@@ -144,2 +209,3 @@ while (value.length > prefix.length && isPermanentChar(maskOptions, value.length - 1)) {

}
return value.length;

@@ -149,5 +215,7 @@ }

var filledLength = prefix.length;
for (var i = value.length; i >= prefix.length; i--) {
var character = value[i];
var isEnteredCharacter = !isPermanentChar(maskOptions, i) && isAllowedChar(maskOptions, i, character);
if (isEnteredCharacter) {

@@ -161,7 +229,5 @@ filledLength = i + 1;

}
function isFilled(maskOptions, value) {
return getFilledLength(maskOptions, value) === maskOptions.mask.length;
}
function formatValue(maskOptions, value) {

@@ -172,3 +238,2 @@ var maskChar = maskOptions.maskChar,

if (!maskChar) {

@@ -200,3 +265,2 @@ value = insertString(maskOptions, '', value, 0);

}
function clearRange(maskOptions, value, start, len) {

@@ -207,3 +271,2 @@ var end = start + len;

prefix = maskOptions.prefix;
var arrayValue = value.split('');

@@ -215,3 +278,2 @@

value = arrayValue.join('');
return formatValue(maskOptions, value);

@@ -224,9 +286,10 @@ }

}
if (isPermanentChar(maskOptions, i)) {
return mask[i];
}
return maskChar;
}).join('');
}
function insertString(maskOptions, value, insertStr, insertPos) {

@@ -236,3 +299,2 @@ var mask = maskOptions.mask,

prefix = maskOptions.prefix;
var arrayInsertStr = insertStr.split('');

@@ -244,2 +306,3 @@ var isInputFilled = isFilled(maskOptions, value);

};
var isUsableCharacter = function isUsableCharacter(character, pos) {

@@ -263,5 +326,4 @@ return !maskChar || !isPermanentChar(maskOptions, pos) || character !== maskChar;

insertPos++;
insertPos++; // stop iteration if maximum value length reached
// stop iteration if maximum value length reached
if (insertPos >= mask.length) {

@@ -273,2 +335,3 @@ return false;

var isAllowed = isAllowedChar(maskOptions, insertPos, insertCharacter) || insertCharacter === maskChar;
if (!isAllowed) {

@@ -289,15 +352,11 @@ return true;

insertPos++;
insertPos++; // stop iteration if maximum value length reached
// stop iteration if maximum value length reached
return insertPos < mask.length;
});
return value;
}
function getInsertStringLength(maskOptions, value, insertStr, insertPos) {
var mask = maskOptions.mask,
maskChar = maskOptions.maskChar;
var arrayInsertStr = insertStr.split('');

@@ -312,5 +371,4 @@ var initialInsertPos = insertPos;

while (!isUsablePosition(insertPos, insertCharacter)) {
insertPos++;
insertPos++; // stop iteration if maximum value length reached
// stop iteration if maximum value length reached
if (insertPos >= mask.length) {

@@ -325,8 +383,7 @@ return false;

insertPos++;
}
} // stop iteration if maximum value length reached
// stop iteration if maximum value length reached
return insertPos < mask.length;
});
return insertPos - initialInsertPos;

@@ -336,29 +393,19 @@ }

var defer = function (fn) {
var defer = window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || function () {
return setTimeout(fn, 0);
};
var defer = window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || function () {
return setTimeout(fn, 0);
};
return defer(fn);
return defer(fn);
};
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
// https://github.com/sanniassin/react-input-mask
var InputElement = function (_React$Component) {
_inherits(InputElement, _React$Component);
var InputElement =
/*#__PURE__*/
function (_React$Component) {
_inheritsLoose(InputElement, _React$Component);
function InputElement(props) {
_classCallCheck(this, InputElement);
var _this;
var _this = _possibleConstructorReturn(this, (InputElement.__proto__ || Object.getPrototypeOf(InputElement)).call(this, props));
_this = _React$Component.call(this, props) || this;

@@ -373,4 +420,2 @@ _initialiseProps.call(_this);

alwaysShowMask = props.alwaysShowMask;
_this.hasValue = value != null;

@@ -382,2 +427,3 @@ _this.maskOptions = parseMask(mask, maskChar, formatChars);

}
if (value == null) {

@@ -397,54 +443,48 @@ value = defaultValue;

return InputElement;
}(React.Component);
var _proto = InputElement.prototype;
var _initialiseProps = function _initialiseProps() {
var _this2 = this;
_proto.componentDidMount = function componentDidMount() {
this.isAndroidBrowser = isAndroidBrowser();
this.isWindowsPhoneBrowser = isWindowsPhoneBrowser();
this.isAndroidFirefox = isAndroidFirefox();
this.lastCursorPos = null;
this.focused = false;
this.componentDidMount = function () {
_this2.isAndroidBrowser = isAndroidBrowser();
_this2.isWindowsPhoneBrowser = isWindowsPhoneBrowser();
_this2.isAndroidFirefox = isAndroidFirefox();
if (_this2.maskOptions.mask && _this2.getInputValue() !== _this2.value) {
_this2.setInputValue(_this2.value);
if (this.maskOptions.mask && this.getInputValue() !== this.value) {
this.setInputValue(this.value);
}
};
this.componentWillReceiveProps = function (nextProps) {
var oldMaskOptions = _this2.maskOptions;
_proto.componentWillReceiveProps = function componentWillReceiveProps(nextProps) {
var oldMaskOptions = this.maskOptions;
this.hasValue = nextProps.value != null;
this.maskOptions = parseMask(nextProps.mask, nextProps.maskChar, nextProps.formatChars);
_this2.hasValue = nextProps.value != null;
_this2.maskOptions = parseMask(nextProps.mask, nextProps.maskChar, nextProps.formatChars);
if (!_this2.maskOptions.mask) {
_this2.backspaceOrDeleteRemoval = null;
_this2.lastCursorPos = null;
if (!this.maskOptions.mask) {
this.backspaceOrDeleteRemoval = null;
this.lastCursorPos = null;
return;
}
var isMaskChanged = _this2.maskOptions.mask && _this2.maskOptions.mask !== oldMaskOptions.mask;
var showEmpty = nextProps.alwaysShowMask || _this2.isFocused();
var newValue = _this2.hasValue ? _this2.getStringValue(nextProps.value) : _this2.value;
var isMaskChanged = this.maskOptions.mask && this.maskOptions.mask !== oldMaskOptions.mask;
var showEmpty = nextProps.alwaysShowMask || this.isFocused();
var newValue = this.hasValue ? this.getStringValue(nextProps.value) : this.value;
if (!oldMaskOptions.mask && !_this2.hasValue) {
newValue = _this2.getInputDOMNode().value;
if (!oldMaskOptions.mask && !this.hasValue) {
newValue = this.getInputDOMNode().value;
}
if (isMaskChanged || _this2.maskOptions.mask && (newValue || showEmpty)) {
newValue = formatValue(_this2.maskOptions, newValue);
if (isMaskChanged || this.maskOptions.mask && (newValue || showEmpty)) {
newValue = formatValue(this.maskOptions, newValue);
if (isMaskChanged) {
var pos = _this2.lastCursorPos;
var filledLen = getFilledLength(_this2.maskOptions, newValue);
var pos = this.lastCursorPos;
var filledLen = getFilledLength(this.maskOptions, newValue);
if (pos === null || filledLen < pos) {
if (isFilled(_this2.maskOptions, newValue)) {
if (isFilled(this.maskOptions, newValue)) {
pos = filledLen;
} else {
pos = _this2.getRightEditablePos(filledLen);
pos = this.getRightEditablePos(filledLen);
}
_this2.setCursorPos(pos);
this.setCursorPos(pos);
}

@@ -454,405 +494,566 @@ }

if (_this2.maskOptions.mask && isEmpty(_this2.maskOptions, newValue) && !showEmpty && (!_this2.hasValue || !nextProps.value)) {
if (this.maskOptions.mask && isEmpty(this.maskOptions, newValue) && !showEmpty && (!this.hasValue || !nextProps.value)) {
newValue = '';
}
_this2.value = newValue;
this.value = newValue;
};
this.componentDidUpdate = function () {
if (_this2.maskOptions.mask && _this2.getInputValue() !== _this2.value) {
_this2.setInputValue(_this2.value);
_proto.componentDidUpdate = function componentDidUpdate() {
if (this.maskOptions.mask && this.getInputValue() !== this.value) {
this.setInputValue(this.value);
}
};
this.isDOMElement = function (element) {
return (typeof HTMLElement === 'undefined' ? 'undefined' : _typeof(HTMLElement)) === 'object' ? element instanceof HTMLElement // DOM2
: element.nodeType === 1 && typeof element.nodeName === 'string';
};
_proto.render = function render() {
var _this2 = this;
this.getInputDOMNode = function () {
var input = _this2.input;
if (!input) {
return null;
}
var _props = this.props,
mask = _props.mask,
alwaysShowMask = _props.alwaysShowMask,
maskChar = _props.maskChar,
formatChars = _props.formatChars,
props = _objectWithoutProperties(_props, ["mask", "alwaysShowMask", "maskChar", "formatChars"]);
if (_this2.isDOMElement(input)) {
return input;
if (this.maskOptions.mask) {
if (!props.disabled && !props.readOnly) {
var handlersKeys = ['onChange', 'onKeyDown', 'onPaste', 'onMouseDown'];
handlersKeys.forEach(function (key) {
props[key] = _this2[key];
});
}
if (props.value != null) {
props.value = this.value;
}
}
// React 0.13
return React.findDOMNode(input);
return React.createElement("input", _extends({
ref: function ref(_ref) {
return _this2.input = _ref;
}
}, props, {
onFocus: this.onFocus,
onBlur: this.onBlur
}));
};
this.getInputValue = function () {
var input = _this2.getInputDOMNode();
if (!input) {
return null;
return InputElement;
}(React.Component);
var _initialiseProps = function _initialiseProps() {
var _this3 = this;
Object.defineProperty(this, "lastCursorPos", {
configurable: true,
enumerable: true,
writable: true,
value: null
});
Object.defineProperty(this, "focused", {
configurable: true,
enumerable: true,
writable: true,
value: false
});
Object.defineProperty(this, "isDOMElement", {
configurable: true,
enumerable: true,
writable: true,
value: function value(element) {
return (typeof HTMLElement === "undefined" ? "undefined" : _typeof(HTMLElement)) === 'object' ? _instanceof(element, HTMLElement) // DOM2
: element.nodeType === 1 && typeof element.nodeName === 'string';
}
});
Object.defineProperty(this, "getInputDOMNode", {
configurable: true,
enumerable: true,
writable: true,
value: function value() {
var input = _this3.input;
return input.value;
};
if (!input) {
return null;
}
this.setInputValue = function (value) {
var input = _this2.getInputDOMNode();
if (!input) {
return;
if (_this3.isDOMElement(input)) {
return input;
} // React 0.13
return React.findDOMNode(input);
}
});
Object.defineProperty(this, "getInputValue", {
configurable: true,
enumerable: true,
writable: true,
value: function value() {
var input = _this3.getInputDOMNode();
_this2.value = value;
input.value = value;
};
if (!input) {
return null;
}
this.getLeftEditablePos = function (pos) {
for (var i = pos; i >= 0; --i) {
if (!isPermanentChar(_this2.maskOptions, i)) {
return i;
}
return input.value;
}
return null;
};
});
Object.defineProperty(this, "setInputValue", {
configurable: true,
enumerable: true,
writable: true,
value: function value(_value) {
var input = _this3.getInputDOMNode();
this.getRightEditablePos = function (pos) {
var mask = _this2.maskOptions.mask;
if (!input) {
return;
}
for (var i = pos; i < mask.length; ++i) {
if (!isPermanentChar(_this2.maskOptions, i)) {
return i;
_this3.value = _value;
input.value = _value;
}
});
Object.defineProperty(this, "getLeftEditablePos", {
configurable: true,
enumerable: true,
writable: true,
value: function value(pos) {
for (var i = pos; i >= 0; --i) {
if (!isPermanentChar(_this3.maskOptions, i)) {
return i;
}
}
}
return null;
};
this.setCursorToEnd = function () {
var filledLen = getFilledLength(_this2.maskOptions, _this2.value);
var pos = _this2.getRightEditablePos(filledLen);
if (pos !== null) {
_this2.setCursorPos(pos);
return null;
}
};
});
Object.defineProperty(this, "getRightEditablePos", {
configurable: true,
enumerable: true,
writable: true,
value: function value(pos) {
var mask = _this3.maskOptions.mask;
this.setSelection = function (start) {
var len = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
for (var i = pos; i < mask.length; ++i) {
if (!isPermanentChar(_this3.maskOptions, i)) {
return i;
}
}
var input = _this2.getInputDOMNode();
if (!input) {
return;
return null;
}
});
Object.defineProperty(this, "setCursorToEnd", {
configurable: true,
enumerable: true,
writable: true,
value: function value() {
var filledLen = getFilledLength(_this3.maskOptions, _this3.value);
var end = start + len;
if ('selectionStart' in input && 'selectionEnd' in input) {
input.selectionStart = start;
input.selectionEnd = end;
} else {
var range = input.createTextRange();
range.collapse(true);
range.moveStart('character', start);
range.moveEnd('character', end - start);
range.select();
}
};
var pos = _this3.getRightEditablePos(filledLen);
this.getSelection = function () {
var input = _this2.getInputDOMNode();
var start = 0;
var end = 0;
if ('selectionStart' in input && 'selectionEnd' in input) {
start = input.selectionStart;
end = input.selectionEnd;
} else {
var range = document.selection.createRange();
if (range.parentElement() === input) {
start = -range.moveStart('character', -input.value.length);
end = -range.moveEnd('character', -input.value.length);
if (pos !== null) {
_this3.setCursorPos(pos);
}
}
});
Object.defineProperty(this, "setSelection", {
configurable: true,
enumerable: true,
writable: true,
value: function value(start, len) {
if (len === void 0) {
len = 0;
}
return {
start: start,
end: end,
length: end - start
};
};
var input = _this3.getInputDOMNode();
this.getCursorPos = function () {
return _this2.getSelection().start;
};
if (!input) {
return;
}
this.setCursorPos = function (pos) {
_this2.setSelection(pos, 0);
var end = start + len;
defer(function () {
_this2.setSelection(pos, 0);
});
if ('selectionStart' in input && 'selectionEnd' in input) {
input.selectionStart = start;
input.selectionEnd = end;
} else {
var range = input.createTextRange();
range.collapse(true);
range.moveStart('character', start);
range.moveEnd('character', end - start);
range.select();
}
}
});
Object.defineProperty(this, "getSelection", {
configurable: true,
enumerable: true,
writable: true,
value: function value() {
var input = _this3.getInputDOMNode();
_this2.lastCursorPos = pos;
};
var start = 0;
var end = 0;
this.isFocused = function () {
return _this2.focused;
};
if ('selectionStart' in input && 'selectionEnd' in input) {
start = input.selectionStart;
end = input.selectionEnd;
} else {
var range = document.selection.createRange();
this.getStringValue = function (value) {
return !value && value !== 0 ? '' : value + '';
};
if (range.parentElement() === input) {
start = -range.moveStart('character', -input.value.length);
end = -range.moveEnd('character', -input.value.length);
}
}
this.onKeyDown = function (event) {
_this2.backspaceOrDeleteRemoval = null;
return {
start: start,
end: end,
length: end - start
};
}
});
Object.defineProperty(this, "getCursorPos", {
configurable: true,
enumerable: true,
writable: true,
value: function value() {
return _this3.getSelection().start;
}
});
Object.defineProperty(this, "setCursorPos", {
configurable: true,
enumerable: true,
writable: true,
value: function value(pos) {
_this3.setSelection(pos, 0);
if (typeof _this2.props.onKeyDown === 'function') {
_this2.props.onKeyDown(event);
defer(function () {
_this3.setSelection(pos, 0);
});
_this3.lastCursorPos = pos;
}
});
Object.defineProperty(this, "isFocused", {
configurable: true,
enumerable: true,
writable: true,
value: function value() {
return _this3.focused;
}
});
Object.defineProperty(this, "getStringValue", {
configurable: true,
enumerable: true,
writable: true,
value: function value(_value2) {
return !_value2 && _value2 !== 0 ? '' : _value2 + '';
}
});
Object.defineProperty(this, "onKeyDown", {
configurable: true,
enumerable: true,
writable: true,
value: function value(event) {
_this3.backspaceOrDeleteRemoval = null;
var key = event.key,
ctrlKey = event.ctrlKey,
metaKey = event.metaKey,
defaultPrevented = event.defaultPrevented;
if (typeof _this3.props.onKeyDown === 'function') {
_this3.props.onKeyDown(event);
}
if (ctrlKey || metaKey || defaultPrevented) {
return;
}
var key = event.key,
ctrlKey = event.ctrlKey,
metaKey = event.metaKey,
defaultPrevented = event.defaultPrevented;
if (key === 'Backspace' || key === 'Delete') {
var selection = _this2.getSelection();
var canRemove = key === 'Backspace' && selection.end > 0 || key === 'Delete' && _this2.value.length > selection.start;
if (!canRemove) {
if (ctrlKey || metaKey || defaultPrevented) {
return;
}
_this2.backspaceOrDeleteRemoval = {
key: key,
selection: _this2.getSelection()
};
if (key === 'Backspace' || key === 'Delete') {
var selection = _this3.getSelection();
var canRemove = key === 'Backspace' && selection.end > 0 || key === 'Delete' && _this3.value.length > selection.start;
if (!canRemove) {
return;
}
_this3.backspaceOrDeleteRemoval = {
key: key,
selection: _this3.getSelection()
};
}
}
};
});
Object.defineProperty(this, "onChange", {
configurable: true,
enumerable: true,
writable: true,
value: function value(event) {
var beforePasteState = _this3.beforePasteState;
var _this3$maskOptions = _this3.maskOptions,
mask = _this3$maskOptions.mask,
maskChar = _this3$maskOptions.maskChar,
lastEditablePos = _this3$maskOptions.lastEditablePos,
prefix = _this3$maskOptions.prefix;
this.onChange = function (event) {
var paste = _this2.paste;
var _maskOptions = _this2.maskOptions,
mask = _maskOptions.mask,
maskChar = _maskOptions.maskChar,
lastEditablePos = _maskOptions.lastEditablePos,
prefix = _maskOptions.prefix;
var value = _this3.getInputValue();
var oldValue = _this3.value;
var value = _this2.getInputValue();
var oldValue = _this2.value;
if (beforePasteState) {
_this3.beforePasteState = null;
if (paste) {
_this2.paste = null;
_this2.pasteText(paste.value, value, paste.selection, event);
return;
}
_this3.pasteText(beforePasteState.value, value, beforePasteState.selection, event);
var selection = _this2.getSelection();
var cursorPos = selection.end;
var maskLen = mask.length;
var valueLen = value.length;
var oldValueLen = oldValue.length;
return;
}
var clearedValue;
var enteredString;
var selection = _this3.getSelection();
if (_this2.backspaceOrDeleteRemoval) {
var deleteFromRight = _this2.backspaceOrDeleteRemoval.key === 'Delete';
value = _this2.value;
selection = _this2.backspaceOrDeleteRemoval.selection;
cursorPos = selection.start;
var cursorPos = selection.end;
var maskLen = mask.length;
var valueLen = value.length;
var oldValueLen = oldValue.length;
var clearedValue;
var enteredString;
_this2.backspaceOrDeleteRemoval = null;
if (_this3.backspaceOrDeleteRemoval) {
var deleteFromRight = _this3.backspaceOrDeleteRemoval.key === 'Delete';
value = _this3.value;
selection = _this3.backspaceOrDeleteRemoval.selection;
cursorPos = selection.start;
_this3.backspaceOrDeleteRemoval = null;
if (selection.length) {
value = clearRange(_this2.maskOptions, value, selection.start, selection.length);
} else if (selection.start < prefix.length || !deleteFromRight && selection.start === prefix.length) {
cursorPos = prefix.length;
} else {
var editablePos = deleteFromRight ? _this2.getRightEditablePos(cursorPos) : _this2.getLeftEditablePos(cursorPos - 1);
if (selection.length) {
value = clearRange(_this3.maskOptions, value, selection.start, selection.length);
} else if (selection.start < prefix.length || !deleteFromRight && selection.start === prefix.length) {
cursorPos = prefix.length;
} else {
var editablePos = deleteFromRight ? _this3.getRightEditablePos(cursorPos) : _this3.getLeftEditablePos(cursorPos - 1);
if (editablePos !== null) {
value = clearRange(_this2.maskOptions, value, editablePos, 1);
cursorPos = editablePos;
if (editablePos !== null) {
value = clearRange(_this3.maskOptions, value, editablePos, 1);
cursorPos = editablePos;
}
}
}
} else if (valueLen > oldValueLen) {
var enteredStringLen = valueLen - oldValueLen;
var startPos = selection.end - enteredStringLen;
enteredString = value.substr(startPos, enteredStringLen);
} else if (valueLen > oldValueLen) {
var enteredStringLen = valueLen - oldValueLen;
var startPos = selection.end - enteredStringLen;
enteredString = value.substr(startPos, enteredStringLen);
if (startPos < lastEditablePos && (enteredStringLen !== 1 || enteredString !== mask[startPos])) {
cursorPos = _this2.getRightEditablePos(startPos);
} else {
cursorPos = startPos;
}
if (startPos < lastEditablePos && (enteredStringLen !== 1 || enteredString !== mask[startPos])) {
cursorPos = _this3.getRightEditablePos(startPos);
} else {
cursorPos = startPos;
}
value = value.substr(0, startPos) + value.substr(startPos + enteredStringLen);
value = value.substr(0, startPos) + value.substr(startPos + enteredStringLen);
clearedValue = clearRange(_this3.maskOptions, value, startPos, maskLen - startPos);
clearedValue = insertString(_this3.maskOptions, clearedValue, enteredString, cursorPos);
value = insertString(_this3.maskOptions, oldValue, enteredString, cursorPos);
clearedValue = clearRange(_this2.maskOptions, value, startPos, maskLen - startPos);
clearedValue = insertString(_this2.maskOptions, clearedValue, enteredString, cursorPos);
if (enteredStringLen !== 1 || cursorPos >= prefix.length && cursorPos < lastEditablePos) {
cursorPos = Math.max(getFilledLength(_this3.maskOptions, clearedValue), cursorPos);
value = insertString(_this2.maskOptions, oldValue, enteredString, cursorPos);
if (cursorPos < lastEditablePos) {
cursorPos = _this3.getRightEditablePos(cursorPos);
}
} else if (cursorPos < lastEditablePos) {
cursorPos++;
}
} else if (valueLen < oldValueLen) {
var removedLen = maskLen - valueLen;
enteredString = value.substr(0, selection.end);
var clearOnly = enteredString === oldValue.substr(0, selection.end);
clearedValue = clearRange(_this3.maskOptions, oldValue, selection.end, removedLen);
if (enteredStringLen !== 1 || cursorPos >= prefix.length && cursorPos < lastEditablePos) {
cursorPos = Math.max(getFilledLength(_this2.maskOptions, clearedValue), cursorPos);
if (cursorPos < lastEditablePos) {
cursorPos = _this2.getRightEditablePos(cursorPos);
if (maskChar) {
value = insertString(_this3.maskOptions, clearedValue, enteredString, 0);
}
} else if (cursorPos < lastEditablePos) {
cursorPos++;
}
} else if (valueLen < oldValueLen) {
var removedLen = maskLen - valueLen;
enteredString = value.substr(0, selection.end);
var clearOnly = enteredString === oldValue.substr(0, selection.end);
clearedValue = clearRange(_this2.maskOptions, oldValue, selection.end, removedLen);
clearedValue = clearRange(_this3.maskOptions, clearedValue, selection.end, maskLen - selection.end);
clearedValue = insertString(_this3.maskOptions, clearedValue, enteredString, 0);
if (maskChar) {
value = insertString(_this2.maskOptions, clearedValue, enteredString, 0);
}
if (!clearOnly) {
cursorPos = Math.max(getFilledLength(_this3.maskOptions, clearedValue), cursorPos);
clearedValue = clearRange(_this2.maskOptions, clearedValue, selection.end, maskLen - selection.end);
clearedValue = insertString(_this2.maskOptions, clearedValue, enteredString, 0);
if (!clearOnly) {
cursorPos = Math.max(getFilledLength(_this2.maskOptions, clearedValue), cursorPos);
if (cursorPos < lastEditablePos) {
cursorPos = _this2.getRightEditablePos(cursorPos);
if (cursorPos < lastEditablePos) {
cursorPos = _this3.getRightEditablePos(cursorPos);
}
} else if (cursorPos < prefix.length) {
cursorPos = prefix.length;
}
} else if (cursorPos < prefix.length) {
cursorPos = prefix.length;
}
}
value = formatValue(_this2.maskOptions, value);
_this2.setInputValue(value);
value = formatValue(_this3.maskOptions, value);
if (typeof _this2.props.onChange === 'function') {
_this2.props.onChange(event);
}
_this3.setInputValue(value);
if (_this2.isWindowsPhoneBrowser) {
defer(function () {
_this2.setSelection(cursorPos, 0);
});
} else {
_this2.setCursorPos(cursorPos);
if (typeof _this3.props.onChange === 'function') {
_this3.props.onChange(event);
}
if (_this3.isWindowsPhoneBrowser) {
defer(function () {
_this3.setSelection(cursorPos, 0);
});
} else {
_this3.setCursorPos(cursorPos);
}
}
};
});
Object.defineProperty(this, "onFocus", {
configurable: true,
enumerable: true,
writable: true,
value: function value(event) {
_this3.focused = true;
this.onFocus = function (event) {
_this2.focused = true;
if (_this3.maskOptions.mask) {
if (!_this3.value) {
var prefix = _this3.maskOptions.prefix;
var value = formatValue(_this3.maskOptions, prefix);
var inputValue = formatValue(_this3.maskOptions, value); // do not use this.getInputValue and this.setInputValue as this.input
// can be undefined at this moment if autoFocus attribute is set
if (_this2.maskOptions.mask) {
if (!_this2.value) {
var prefix = _this2.maskOptions.prefix;
var value = formatValue(_this2.maskOptions, prefix);
var inputValue = formatValue(_this2.maskOptions, value);
var isInputValueChanged = inputValue !== event.target.value;
// do not use this.getInputValue and this.setInputValue as this.input
// can be undefined at this moment if autoFocus attribute is set
var isInputValueChanged = inputValue !== event.target.value;
if (isInputValueChanged) {
event.target.value = inputValue;
}
if (isInputValueChanged) {
event.target.value = inputValue;
}
_this3.value = inputValue;
_this2.value = inputValue;
if (isInputValueChanged && typeof _this3.props.onChange === 'function') {
_this3.props.onChange(event);
}
if (isInputValueChanged && typeof _this2.props.onChange === 'function') {
_this2.props.onChange(event);
_this3.setCursorToEnd();
} else if (getFilledLength(_this3.maskOptions, _this3.value) < _this3.maskOptions.mask.length) {
_this3.setCursorToEnd();
}
}
_this2.setCursorToEnd();
} else if (getFilledLength(_this2.maskOptions, _this2.value) < _this2.maskOptions.mask.length) {
_this2.setCursorToEnd();
if (typeof _this3.props.onFocus === 'function') {
_this3.props.onFocus(event);
}
}
});
Object.defineProperty(this, "onBlur", {
configurable: true,
enumerable: true,
writable: true,
value: function value(event) {
_this3.focused = false;
if (typeof _this2.props.onFocus === 'function') {
_this2.props.onFocus(event);
}
};
if (_this3.maskOptions.mask && !_this3.props.alwaysShowMask && isEmpty(_this3.maskOptions, _this3.value)) {
var inputValue = '';
this.onBlur = function (event) {
_this2.focused = false;
var isInputValueChanged = inputValue !== _this3.getInputValue();
if (_this2.maskOptions.mask && !_this2.props.alwaysShowMask && isEmpty(_this2.maskOptions, _this2.value)) {
var inputValue = '';
var isInputValueChanged = inputValue !== _this2.getInputValue();
if (isInputValueChanged) {
_this3.setInputValue(inputValue);
}
if (isInputValueChanged) {
_this2.setInputValue(inputValue);
if (isInputValueChanged && typeof _this3.props.onChange === 'function') {
_this3.props.onChange(event);
}
}
if (isInputValueChanged && typeof _this2.props.onChange === 'function') {
_this2.props.onChange(event);
if (typeof _this3.props.onBlur === 'function') {
_this3.props.onBlur(event);
}
}
});
Object.defineProperty(this, "onMouseDown", {
configurable: true,
enumerable: true,
writable: true,
value: function value(event) {
// tiny unintentional mouse movements can break cursor
// position on focus, so we have to restore it in that case
//
// https://github.com/sanniassin/react-input-mask/issues/108
if (!_this3.focused && document.addEventListener) {
_this3.mouseDownX = event.clientX;
_this3.mouseDownY = event.clientY;
_this3.mouseDownTime = new Date().getTime();
if (typeof _this2.props.onBlur === 'function') {
_this2.props.onBlur(event);
}
};
var mouseUpHandler = function mouseUpHandler(mouseUpEvent) {
document.removeEventListener('mouseup', mouseUpHandler);
this.onPaste = function (event) {
if (typeof _this2.props.onPaste === 'function') {
_this2.props.onPaste(event);
}
if (!_this3.focused) {
return;
}
if (_this2.isAndroidBrowser && !event.defaultPrevented) {
_this2.paste = {
value: _this2.getInputValue(),
selection: _this2.getSelection()
};
_this2.setInputValue('');
}
};
var deltaX = Math.abs(mouseUpEvent.clientX - _this3.mouseDownX);
var deltaY = Math.abs(mouseUpEvent.clientY - _this3.mouseDownY);
var axisDelta = Math.max(deltaX, deltaY);
this.pasteText = function (value, text, selection, event) {
var cursorPos = selection.start;
if (selection.length) {
value = clearRange(_this2.maskOptions, value, cursorPos, selection.length);
var timeDelta = new Date().getTime() - _this3.mouseDownTime;
if (axisDelta <= 10 && timeDelta <= 200 || axisDelta <= 5 && timeDelta <= 300) {
_this3.setCursorToEnd();
}
};
document.addEventListener('mouseup', mouseUpHandler);
}
if (typeof _this3.props.onMouseDown === 'function') {
_this3.props.onMouseDown(event);
}
}
var textLen = getInsertStringLength(_this2.maskOptions, value, text, cursorPos);
value = insertString(_this2.maskOptions, value, text, cursorPos);
cursorPos += textLen;
cursorPos = _this2.getRightEditablePos(cursorPos) || cursorPos;
});
Object.defineProperty(this, "onPaste", {
configurable: true,
enumerable: true,
writable: true,
value: function value(event) {
if (typeof _this3.props.onPaste === 'function') {
_this3.props.onPaste(event);
} // we need raw pasted text, but event.clipboardData
// may not work in Android browser, so we clean input
// to get raw text in onChange handler
if (value !== _this2.getInputValue()) {
_this2.setInputValue(value);
if (event && typeof _this2.props.onChange === 'function') {
_this2.props.onChange(event);
if (!event.defaultPrevented) {
_this3.beforePasteState = {
value: _this3.getInputValue(),
selection: _this3.getSelection()
};
_this3.setInputValue('');
}
}
});
Object.defineProperty(this, "pasteText", {
configurable: true,
enumerable: true,
writable: true,
value: function value(_value3, text, selection, event) {
var cursorPos = selection.start;
_this2.setCursorPos(cursorPos);
};
if (selection.length) {
_value3 = clearRange(_this3.maskOptions, _value3, cursorPos, selection.length);
}
this.render = function () {
var _props = _this2.props,
mask = _props.mask,
alwaysShowMask = _props.alwaysShowMask,
maskChar = _props.maskChar,
formatChars = _props.formatChars,
props = _objectWithoutProperties(_props, ['mask', 'alwaysShowMask', 'maskChar', 'formatChars']);
var textLen = getInsertStringLength(_this3.maskOptions, _value3, text, cursorPos);
_value3 = insertString(_this3.maskOptions, _value3, text, cursorPos);
cursorPos += textLen;
cursorPos = _this3.getRightEditablePos(cursorPos) || cursorPos;
if (_this2.maskOptions.mask) {
if (!props.disabled && !props.readOnly) {
var handlersKeys = ['onChange', 'onKeyDown', 'onPaste'];
handlersKeys.forEach(function (key) {
props[key] = _this2[key];
});
_this3.setInputValue(_value3);
if (event && typeof _this3.props.onChange === 'function') {
_this3.props.onChange(event);
}
if (props.value != null) {
props.value = _this2.value;
}
_this3.setCursorPos(cursorPos);
}
return React.createElement('input', _extends({ ref: function ref(_ref) {
return _this2.input = _ref;
} }, props, { onFocus: _this2.onFocus, onBlur: _this2.onBlur }));
};
});
};

@@ -859,0 +1060,0 @@

@@ -1,1 +0,1 @@

!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t(require("react")):"function"==typeof define&&define.amd?define(["react"],t):e.ReactInputMask=t(e.React)}(this,function(e){"use strict";function t(){var e=new RegExp("windows","i"),t=new RegExp("firefox","i"),n=new RegExp("android","i"),s=navigator.userAgent;return!e.test(s)&&!t.test(s)&&n.test(s)}function n(){var e=new RegExp("windows","i"),t=new RegExp("phone","i"),n=navigator.userAgent;return e.test(n)&&t.test(n)}function s(){var e=new RegExp("windows","i"),t=new RegExp("firefox","i"),n=new RegExp("android","i"),s=navigator.userAgent;return!e.test(s)&&t.test(s)&&n.test(s)}function o(e,t){return-1!==e.permanents.indexOf(t)}function a(e,t,n){var s=e.mask,a=e.charsRules;if(!n)return!1;if(o(e,t))return s[t]===n;var r=a[s[t]];return new RegExp(r).test(n)}function r(e,t){return t.split("").every(function(t,n){return o(e,n)||!a(e,n,t)})}function i(e,t){var n=e.maskChar,s=e.prefix;if(!n){for(;t.length>s.length&&o(e,t.length-1);)t=t.slice(0,t.length-1);return t.length}for(var r=s.length,i=t.length;i>=s.length;i--){var u=t[i];if(!o(e,i)&&a(e,i,u)){r=i+1;break}}return r}function u(e,t){return i(e,t)===e.mask.length}function l(e,t){var n=e.maskChar,s=e.mask,a=e.prefix;if(!n)return t=c(e,"",t,0),(t=t.slice(0,i(e,t))).length<a.length&&(t=a),t;if(t)return c(e,l(e,""),t,0);for(var r=0;r<s.length;r++)o(e,r)?t+=s[r]:t+=n;return t}function p(e,t,n,s){var a=n+s,r=e.maskChar,i=e.mask,u=e.prefix,p=t.split("");return r?p.map(function(t,s){return s<n||s>=a?t:o(e,s)?i[s]:r}).join(""):(n=Math.max(u.length,n),p.splice(n,a-n),t=p.join(""),l(e,t))}function c(e,t,n,s){var r=e.mask,i=e.maskChar,p=e.prefix,c=n.split(""),f=u(e,t),h=function(t,n){return!o(e,t)||n===r[t]},m=function(t,n){return!i||!o(e,n)||t!==i};return!i&&s>t.length&&(t+=r.slice(t.length,s)),c.every(function(n){for(;!h(s,n);){if(s>=t.length&&(t+=r[s]),!m(n,s))return!0;if(++s>=r.length)return!1}return!a(e,s,n)&&n!==i||(s<t.length?i||f||s<p.length?t=t.slice(0,s)+n+t.slice(s+1):(t=t.slice(0,s)+n+t.slice(s),t=l(e,t)):i||(t+=n),++s<r.length)}),t}function f(e,t,n,s){var r=e.mask,i=e.maskChar,u=n.split(""),l=s,p=function(t,n){return!o(e,t)||n===r[t]};return u.every(function(t){for(;!p(s,t);)if(++s>=r.length)return!1;return(a(e,s,t)||t===i)&&s++,s<r.length}),s-l}function h(e,t){var n={};for(var s in e)t.indexOf(s)>=0||Object.prototype.hasOwnProperty.call(e,s)&&(n[s]=e[s]);return n}function m(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function g(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function k(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}e=e&&e.hasOwnProperty("default")?e["default"]:e;var v={9:"[0-9]",a:"[A-Za-z]","*":"[A-Za-z0-9]"},d=function(e,t,n){if(t===undefined&&(t="_"),null==n&&(n=v),!e||"string"!=typeof e)return{maskChar:t,charsRules:n,mask:null,prefix:null,lastEditablePos:null,permanents:[]};var s="",o="",a=[],r=!1,i=null;return e.split("").forEach(function(e){r||"\\"!==e?(r||!n[e]?(a.push(s.length),s.length===a.length-1&&(o+=e)):i=s.length+1,s+=e,r=!1):r=!0}),{maskChar:t,charsRules:n,prefix:o,mask:s,lastEditablePos:i,permanents:a}},O=function(e){return(window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||function(){return setTimeout(e,0)})(e)},y=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var s in n)Object.prototype.hasOwnProperty.call(n,s)&&(e[s]=n[s])}return e},w="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},b=function(t){function n(e){m(this,n);var t=g(this,(n.__proto__||Object.getPrototypeOf(n)).call(this,e));E.call(t);var s=e.mask,o=e.maskChar,a=e.formatChars,r=e.defaultValue,i=e.value,u=e.alwaysShowMask;return t.hasValue=null!=i,t.maskOptions=d(s,o,a),null==r&&(r=""),null==i&&(i=r),i=t.getStringValue(i),t.maskOptions.mask&&(u||i)&&(i=l(t.maskOptions,i)),t.value=i,t}return k(n,e.Component),n}(),E=function(){var a=this;this.lastCursorPos=null,this.focused=!1,this.componentDidMount=function(){a.isAndroidBrowser=t(),a.isWindowsPhoneBrowser=n(),a.isAndroidFirefox=s(),a.maskOptions.mask&&a.getInputValue()!==a.value&&a.setInputValue(a.value)},this.componentWillReceiveProps=function(e){var t=a.maskOptions;if(a.hasValue=null!=e.value,a.maskOptions=d(e.mask,e.maskChar,e.formatChars),!a.maskOptions.mask)return a.backspaceOrDeleteRemoval=null,void(a.lastCursorPos=null);var n=a.maskOptions.mask&&a.maskOptions.mask!==t.mask,s=e.alwaysShowMask||a.isFocused(),o=a.hasValue?a.getStringValue(e.value):a.value;if(t.mask||a.hasValue||(o=a.getInputDOMNode().value),(n||a.maskOptions.mask&&(o||s))&&(o=l(a.maskOptions,o),n)){var p=a.lastCursorPos,c=i(a.maskOptions,o);(null===p||c<p)&&(p=u(a.maskOptions,o)?c:a.getRightEditablePos(c),a.setCursorPos(p))}!a.maskOptions.mask||!r(a.maskOptions,o)||s||a.hasValue&&e.value||(o=""),a.value=o},this.componentDidUpdate=function(){a.maskOptions.mask&&a.getInputValue()!==a.value&&a.setInputValue(a.value)},this.isDOMElement=function(e){return"object"===("undefined"==typeof HTMLElement?"undefined":w(HTMLElement))?e instanceof HTMLElement:1===e.nodeType&&"string"==typeof e.nodeName},this.getInputDOMNode=function(){var t=a.input;return t?a.isDOMElement(t)?t:e.findDOMNode(t):null},this.getInputValue=function(){var e=a.getInputDOMNode();return e?e.value:null},this.setInputValue=function(e){var t=a.getInputDOMNode();t&&(a.value=e,t.value=e)},this.getLeftEditablePos=function(e){for(var t=e;t>=0;--t)if(!o(a.maskOptions,t))return t;return null},this.getRightEditablePos=function(e){for(var t=a.maskOptions.mask,n=e;n<t.length;++n)if(!o(a.maskOptions,n))return n;return null},this.setCursorToEnd=function(){var e=i(a.maskOptions,a.value),t=a.getRightEditablePos(e);null!==t&&a.setCursorPos(t)},this.setSelection=function(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:0,n=a.getInputDOMNode();if(n){var s=e+t;if("selectionStart"in n&&"selectionEnd"in n)n.selectionStart=e,n.selectionEnd=s;else{var o=n.createTextRange();o.collapse(!0),o.moveStart("character",e),o.moveEnd("character",s-e),o.select()}}},this.getSelection=function(){var e=a.getInputDOMNode(),t=0,n=0;if("selectionStart"in e&&"selectionEnd"in e)t=e.selectionStart,n=e.selectionEnd;else{var s=document.selection.createRange();s.parentElement()===e&&(t=-s.moveStart("character",-e.value.length),n=-s.moveEnd("character",-e.value.length))}return{start:t,end:n,length:n-t}},this.getCursorPos=function(){return a.getSelection().start},this.setCursorPos=function(e){a.setSelection(e,0),O(function(){a.setSelection(e,0)}),a.lastCursorPos=e},this.isFocused=function(){return a.focused},this.getStringValue=function(e){return e||0===e?e+"":""},this.onKeyDown=function(e){a.backspaceOrDeleteRemoval=null,"function"==typeof a.props.onKeyDown&&a.props.onKeyDown(e);var t=e.key,n=e.ctrlKey,s=e.metaKey,o=e.defaultPrevented;if(!(n||s||o||"Backspace"!==t&&"Delete"!==t)){var r=a.getSelection();if(!("Backspace"===t&&r.end>0||"Delete"===t&&a.value.length>r.start))return;a.backspaceOrDeleteRemoval={key:t,selection:a.getSelection()}}},this.onChange=function(e){var t=a.paste,n=a.maskOptions,s=n.mask,o=n.maskChar,r=n.lastEditablePos,u=n.prefix,f=a.getInputValue(),h=a.value;if(t)return a.paste=null,void a.pasteText(t.value,f,t.selection,e);var m,g,k=a.getSelection(),v=k.end,d=s.length,y=f.length,w=h.length;if(a.backspaceOrDeleteRemoval){var b="Delete"===a.backspaceOrDeleteRemoval.key;if(f=a.value,k=a.backspaceOrDeleteRemoval.selection,v=k.start,a.backspaceOrDeleteRemoval=null,k.length)f=p(a.maskOptions,f,k.start,k.length);else if(k.start<u.length||!b&&k.start===u.length)v=u.length;else{var E=b?a.getRightEditablePos(v):a.getLeftEditablePos(v-1);null!==E&&(f=p(a.maskOptions,f,E,1),v=E)}}else if(y>w){var C=y-w,P=k.end-C;g=f.substr(P,C),v=P<r&&(1!==C||g!==s[P])?a.getRightEditablePos(P):P,f=f.substr(0,P)+f.substr(P+C),m=p(a.maskOptions,f,P,d-P),m=c(a.maskOptions,m,g,v),f=c(a.maskOptions,h,g,v),1!==C||v>=u.length&&v<r?(v=Math.max(i(a.maskOptions,m),v))<r&&(v=a.getRightEditablePos(v)):v<r&&v++}else if(y<w){var R=d-y,x=(g=f.substr(0,k.end))===h.substr(0,k.end);m=p(a.maskOptions,h,k.end,R),o&&(f=c(a.maskOptions,m,g,0)),m=p(a.maskOptions,m,k.end,d-k.end),m=c(a.maskOptions,m,g,0),x?v<u.length&&(v=u.length):(v=Math.max(i(a.maskOptions,m),v))<r&&(v=a.getRightEditablePos(v))}f=l(a.maskOptions,f),a.setInputValue(f),"function"==typeof a.props.onChange&&a.props.onChange(e),a.isWindowsPhoneBrowser?O(function(){a.setSelection(v,0)}):a.setCursorPos(v)},this.onFocus=function(e){if(a.focused=!0,a.maskOptions.mask)if(a.value)i(a.maskOptions,a.value)<a.maskOptions.mask.length&&a.setCursorToEnd();else{var t=a.maskOptions.prefix,n=l(a.maskOptions,t),s=l(a.maskOptions,n),o=s!==e.target.value;o&&(e.target.value=s),a.value=s,o&&"function"==typeof a.props.onChange&&a.props.onChange(e),a.setCursorToEnd()}"function"==typeof a.props.onFocus&&a.props.onFocus(e)},this.onBlur=function(e){if(a.focused=!1,a.maskOptions.mask&&!a.props.alwaysShowMask&&r(a.maskOptions,a.value)){var t=""!==a.getInputValue();t&&a.setInputValue(""),t&&"function"==typeof a.props.onChange&&a.props.onChange(e)}"function"==typeof a.props.onBlur&&a.props.onBlur(e)},this.onPaste=function(e){"function"==typeof a.props.onPaste&&a.props.onPaste(e),a.isAndroidBrowser&&!e.defaultPrevented&&(a.paste={value:a.getInputValue(),selection:a.getSelection()},a.setInputValue(""))},this.pasteText=function(e,t,n,s){var o=n.start;n.length&&(e=p(a.maskOptions,e,o,n.length));var r=f(a.maskOptions,0,t,o);e=c(a.maskOptions,e,t,o),o+=r,o=a.getRightEditablePos(o)||o,e!==a.getInputValue()&&(a.setInputValue(e),s&&"function"==typeof a.props.onChange&&a.props.onChange(s)),a.setCursorPos(o)},this.render=function(){var t=a.props,n=(t.mask,t.alwaysShowMask,t.maskChar,t.formatChars,h(t,["mask","alwaysShowMask","maskChar","formatChars"]));return a.maskOptions.mask&&(n.disabled||n.readOnly||["onChange","onKeyDown","onPaste"].forEach(function(e){n[e]=a[e]}),null!=n.value&&(n.value=a.value)),e.createElement("input",y({ref:function(e){return a.input=e}},n,{onFocus:a.onFocus,onBlur:a.onBlur}))}};return b});
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t(require("react")):"function"==typeof define&&define.amd?define(["react"],t):e.ReactInputMask=t(e.React)}(this,function(e){"use strict";function t(e){return(t="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function n(){return(n=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e}).apply(this,arguments)}function r(e,t){return-1!==e.permanents.indexOf(t)}function a(e,t,n){var a=e.mask,o=e.charsRules;if(!n)return!1;if(r(e,t))return a[t]===n;var s=o[a[t]];return new RegExp(s).test(n)}function o(e,t){return t.split("").every(function(t,n){return r(e,n)||!a(e,n,t)})}function s(e,t){var n=e.maskChar,o=e.prefix;if(!n){for(;t.length>o.length&&r(e,t.length-1);)t=t.slice(0,t.length-1);return t.length}for(var s=o.length,i=t.length;i>=o.length;i--){var u=t[i];if(!r(e,i)&&a(e,i,u)){s=i+1;break}}return s}function i(e,t){return s(e,t)===e.mask.length}function u(e,t){var n=e.maskChar,a=e.mask,o=e.prefix;if(!n)return t=c(e,"",t,0),(t=t.slice(0,s(e,t))).length<o.length&&(t=o),t;if(t){return c(e,u(e,""),t,0)}for(var i=0;i<a.length;i++)r(e,i)?t+=a[i]:t+=n;return t}function l(e,t,n,a){var o=n+a,s=e.maskChar,i=e.mask,l=e.prefix,c=t.split("");return s?c.map(function(t,a){return a<n||a>=o?t:r(e,a)?i[a]:s}).join(""):(n=Math.max(l.length,n),c.splice(n,o-n),t=c.join(""),u(e,t))}function c(e,t,n,o){var s=e.mask,l=e.maskChar,c=e.prefix,f=n.split(""),p=i(e,t),h=function(t,n){return!r(e,t)||n===s[t]},m=function(t,n){return!l||!r(e,n)||t!==l};return!l&&o>t.length&&(t+=s.slice(t.length,o)),f.every(function(n){for(;!h(o,n);){if(o>=t.length&&(t+=s[o]),!m(n,o))return!0;if(++o>=s.length)return!1}return!a(e,o,n)&&n!==l||(o<t.length?l||p||o<c.length?t=t.slice(0,o)+n+t.slice(o+1):(t=t.slice(0,o)+n+t.slice(o),t=u(e,t)):l||(t+=n),++o<s.length)}),t}var f={9:"[0-9]",a:"[A-Za-z]","*":"[A-Za-z0-9]"},p=function(e,t,n){if(t===undefined&&(t="_"),null==n&&(n=f),!e||"string"!=typeof e)return{maskChar:t,charsRules:n,mask:null,prefix:null,lastEditablePos:null,permanents:[]};var r="",a="",o=[],s=!1,i=null;return e.split("").forEach(function(e){s||"\\"!==e?(s||!n[e]?(o.push(r.length),r.length===o.length-1&&(a+=e)):i=r.length+1,r+=e,s=!1):s=!0}),{maskChar:t,charsRules:n,prefix:a,mask:r,lastEditablePos:i,permanents:o}},h=function(e){return(window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||function(){return setTimeout(e,0)})(e)},m=function(t){function r(e){var n;n=t.call(this,e)||this,g.call(n);var r=e.mask,a=e.maskChar,o=e.formatChars,s=e.defaultValue,i=e.value,l=e.alwaysShowMask;return n.hasValue=null!=i,n.maskOptions=p(r,a,o),null==s&&(s=""),null==i&&(i=s),i=n.getStringValue(i),n.maskOptions.mask&&(l||i)&&(i=u(n.maskOptions,i)),n.value=i,n}!function(e,t){e.prototype=Object.create(t.prototype),e.prototype.constructor=e,e.__proto__=t}(r,t);var a=r.prototype;return a.componentDidMount=function(){this.isAndroidBrowser=function(){var e=new RegExp("windows","i"),t=new RegExp("firefox","i"),n=new RegExp("android","i"),r=navigator.userAgent;return!e.test(r)&&!t.test(r)&&n.test(r)}(),this.isWindowsPhoneBrowser=function(){var e=new RegExp("windows","i"),t=new RegExp("phone","i"),n=navigator.userAgent;return e.test(n)&&t.test(n)}(),this.isAndroidFirefox=function(){var e=new RegExp("windows","i"),t=new RegExp("firefox","i"),n=new RegExp("android","i"),r=navigator.userAgent;return!e.test(r)&&t.test(r)&&n.test(r)}(),this.maskOptions.mask&&this.getInputValue()!==this.value&&this.setInputValue(this.value)},a.componentWillReceiveProps=function(e){var t=this.maskOptions;if(this.hasValue=null!=e.value,this.maskOptions=p(e.mask,e.maskChar,e.formatChars),!this.maskOptions.mask)return this.backspaceOrDeleteRemoval=null,void(this.lastCursorPos=null);var n=this.maskOptions.mask&&this.maskOptions.mask!==t.mask,r=e.alwaysShowMask||this.isFocused(),a=this.hasValue?this.getStringValue(e.value):this.value;if(t.mask||this.hasValue||(a=this.getInputDOMNode().value),(n||this.maskOptions.mask&&(a||r))&&(a=u(this.maskOptions,a),n)){var l=this.lastCursorPos,c=s(this.maskOptions,a);(null===l||c<l)&&(l=i(this.maskOptions,a)?c:this.getRightEditablePos(c),this.setCursorPos(l))}!this.maskOptions.mask||!o(this.maskOptions,a)||r||this.hasValue&&e.value||(a=""),this.value=a},a.componentDidUpdate=function(){this.maskOptions.mask&&this.getInputValue()!==this.value&&this.setInputValue(this.value)},a.render=function(){var t=this,r=this.props,a=(r.mask,r.alwaysShowMask,r.maskChar,r.formatChars,function(e,t){if(null==e)return{};var n,r,a={},o=Object.keys(e);for(r=0;r<o.length;r++)n=o[r],t.indexOf(n)>=0||(a[n]=e[n]);if(Object.getOwnPropertySymbols){var s=Object.getOwnPropertySymbols(e);for(r=0;r<s.length;r++)n=s[r],t.indexOf(n)>=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(a[n]=e[n])}return a}(r,["mask","alwaysShowMask","maskChar","formatChars"]));if(this.maskOptions.mask){if(!a.disabled&&!a.readOnly){["onChange","onKeyDown","onPaste","onMouseDown"].forEach(function(e){a[e]=t[e]})}null!=a.value&&(a.value=this.value)}return e.createElement("input",n({ref:function(e){return t.input=e}},a,{onFocus:this.onFocus,onBlur:this.onBlur}))},r}((e=e&&e.hasOwnProperty("default")?e["default"]:e).Component),g=function(){var n=this;Object.defineProperty(this,"lastCursorPos",{configurable:!0,enumerable:!0,writable:!0,value:null}),Object.defineProperty(this,"focused",{configurable:!0,enumerable:!0,writable:!0,value:!1}),Object.defineProperty(this,"isDOMElement",{configurable:!0,enumerable:!0,writable:!0,value:function(e){return"object"===("undefined"==typeof HTMLElement?"undefined":t(HTMLElement))?function(e,t){return null!=t&&"undefined"!=typeof Symbol&&t[Symbol.hasInstance]?t[Symbol.hasInstance](e):e instanceof t}(e,HTMLElement):1===e.nodeType&&"string"==typeof e.nodeName}}),Object.defineProperty(this,"getInputDOMNode",{configurable:!0,enumerable:!0,writable:!0,value:function(){var t=n.input;return t?n.isDOMElement(t)?t:e.findDOMNode(t):null}}),Object.defineProperty(this,"getInputValue",{configurable:!0,enumerable:!0,writable:!0,value:function(){var e=n.getInputDOMNode();return e?e.value:null}}),Object.defineProperty(this,"setInputValue",{configurable:!0,enumerable:!0,writable:!0,value:function(e){var t=n.getInputDOMNode();t&&(n.value=e,t.value=e)}}),Object.defineProperty(this,"getLeftEditablePos",{configurable:!0,enumerable:!0,writable:!0,value:function(e){for(var t=e;t>=0;--t)if(!r(n.maskOptions,t))return t;return null}}),Object.defineProperty(this,"getRightEditablePos",{configurable:!0,enumerable:!0,writable:!0,value:function(e){for(var t=n.maskOptions.mask,a=e;a<t.length;++a)if(!r(n.maskOptions,a))return a;return null}}),Object.defineProperty(this,"setCursorToEnd",{configurable:!0,enumerable:!0,writable:!0,value:function(){var e=s(n.maskOptions,n.value),t=n.getRightEditablePos(e);null!==t&&n.setCursorPos(t)}}),Object.defineProperty(this,"setSelection",{configurable:!0,enumerable:!0,writable:!0,value:function(e,t){void 0===t&&(t=0);var r=n.getInputDOMNode();if(r){var a=e+t;if("selectionStart"in r&&"selectionEnd"in r)r.selectionStart=e,r.selectionEnd=a;else{var o=r.createTextRange();o.collapse(!0),o.moveStart("character",e),o.moveEnd("character",a-e),o.select()}}}}),Object.defineProperty(this,"getSelection",{configurable:!0,enumerable:!0,writable:!0,value:function(){var e=n.getInputDOMNode(),t=0,r=0;if("selectionStart"in e&&"selectionEnd"in e)t=e.selectionStart,r=e.selectionEnd;else{var a=document.selection.createRange();a.parentElement()===e&&(t=-a.moveStart("character",-e.value.length),r=-a.moveEnd("character",-e.value.length))}return{start:t,end:r,length:r-t}}}),Object.defineProperty(this,"getCursorPos",{configurable:!0,enumerable:!0,writable:!0,value:function(){return n.getSelection().start}}),Object.defineProperty(this,"setCursorPos",{configurable:!0,enumerable:!0,writable:!0,value:function(e){n.setSelection(e,0),h(function(){n.setSelection(e,0)}),n.lastCursorPos=e}}),Object.defineProperty(this,"isFocused",{configurable:!0,enumerable:!0,writable:!0,value:function(){return n.focused}}),Object.defineProperty(this,"getStringValue",{configurable:!0,enumerable:!0,writable:!0,value:function(e){return e||0===e?e+"":""}}),Object.defineProperty(this,"onKeyDown",{configurable:!0,enumerable:!0,writable:!0,value:function(e){n.backspaceOrDeleteRemoval=null,"function"==typeof n.props.onKeyDown&&n.props.onKeyDown(e);var t=e.key,r=e.ctrlKey,a=e.metaKey,o=e.defaultPrevented;if(!(r||a||o||"Backspace"!==t&&"Delete"!==t)){var s=n.getSelection();if(!("Backspace"===t&&s.end>0||"Delete"===t&&n.value.length>s.start))return;n.backspaceOrDeleteRemoval={key:t,selection:n.getSelection()}}}}),Object.defineProperty(this,"onChange",{configurable:!0,enumerable:!0,writable:!0,value:function(e){var t=n.beforePasteState,r=n.maskOptions,a=r.mask,o=r.maskChar,i=r.lastEditablePos,f=r.prefix,p=n.getInputValue(),m=n.value;if(t)return n.beforePasteState=null,void n.pasteText(t.value,p,t.selection,e);var g,b,v=n.getSelection(),d=v.end,k=a.length,O=p.length,y=m.length;if(n.backspaceOrDeleteRemoval){var w="Delete"===n.backspaceOrDeleteRemoval.key;if(p=n.value,v=n.backspaceOrDeleteRemoval.selection,d=v.start,n.backspaceOrDeleteRemoval=null,v.length)p=l(n.maskOptions,p,v.start,v.length);else if(v.start<f.length||!w&&v.start===f.length)d=f.length;else{var P=w?n.getRightEditablePos(d):n.getLeftEditablePos(d-1);null!==P&&(p=l(n.maskOptions,p,P,1),d=P)}}else if(O>y){var E=O-y,C=v.end-E;b=p.substr(C,E),d=C<i&&(1!==E||b!==a[C])?n.getRightEditablePos(C):C,p=p.substr(0,C)+p.substr(C+E),g=l(n.maskOptions,p,C,k-C),g=c(n.maskOptions,g,b,d),p=c(n.maskOptions,m,b,d),1!==E||d>=f.length&&d<i?(d=Math.max(s(n.maskOptions,g),d))<i&&(d=n.getRightEditablePos(d)):d<i&&d++}else if(O<y){var D=k-O,S=(b=p.substr(0,v.end))===m.substr(0,v.end);g=l(n.maskOptions,m,v.end,D),o&&(p=c(n.maskOptions,g,b,0)),g=l(n.maskOptions,g,v.end,k-v.end),g=c(n.maskOptions,g,b,0),S?d<f.length&&(d=f.length):(d=Math.max(s(n.maskOptions,g),d))<i&&(d=n.getRightEditablePos(d))}p=u(n.maskOptions,p),n.setInputValue(p),"function"==typeof n.props.onChange&&n.props.onChange(e),n.isWindowsPhoneBrowser?h(function(){n.setSelection(d,0)}):n.setCursorPos(d)}}),Object.defineProperty(this,"onFocus",{configurable:!0,enumerable:!0,writable:!0,value:function(e){if(n.focused=!0,n.maskOptions.mask)if(n.value)s(n.maskOptions,n.value)<n.maskOptions.mask.length&&n.setCursorToEnd();else{var t=n.maskOptions.prefix,r=u(n.maskOptions,t),a=u(n.maskOptions,r),o=a!==e.target.value;o&&(e.target.value=a),n.value=a,o&&"function"==typeof n.props.onChange&&n.props.onChange(e),n.setCursorToEnd()}"function"==typeof n.props.onFocus&&n.props.onFocus(e)}}),Object.defineProperty(this,"onBlur",{configurable:!0,enumerable:!0,writable:!0,value:function(e){if(n.focused=!1,n.maskOptions.mask&&!n.props.alwaysShowMask&&o(n.maskOptions,n.value)){var t=""!==n.getInputValue();t&&n.setInputValue(""),t&&"function"==typeof n.props.onChange&&n.props.onChange(e)}"function"==typeof n.props.onBlur&&n.props.onBlur(e)}}),Object.defineProperty(this,"onMouseDown",{configurable:!0,enumerable:!0,writable:!0,value:function(e){if(!n.focused&&document.addEventListener){n.mouseDownX=e.clientX,n.mouseDownY=e.clientY,n.mouseDownTime=(new Date).getTime();document.addEventListener("mouseup",function t(e){if(document.removeEventListener("mouseup",t),n.focused){var r=Math.abs(e.clientX-n.mouseDownX),a=Math.abs(e.clientY-n.mouseDownY),o=Math.max(r,a),s=(new Date).getTime()-n.mouseDownTime;(o<=10&&s<=200||o<=5&&s<=300)&&n.setCursorToEnd()}})}"function"==typeof n.props.onMouseDown&&n.props.onMouseDown(e)}}),Object.defineProperty(this,"onPaste",{configurable:!0,enumerable:!0,writable:!0,value:function(e){"function"==typeof n.props.onPaste&&n.props.onPaste(e),e.defaultPrevented||(n.beforePasteState={value:n.getInputValue(),selection:n.getSelection()},n.setInputValue(""))}}),Object.defineProperty(this,"pasteText",{configurable:!0,enumerable:!0,writable:!0,value:function(e,t,o,s){var i=o.start;o.length&&(e=l(n.maskOptions,e,i,o.length));var u=function(e,t,n,o){var s=e.mask,i=e.maskChar,u=n.split(""),l=o,c=function(t,n){return!r(e,t)||n===s[t]};return u.every(function(t){for(;!c(o,t);)if(++o>=s.length)return!1;return(a(e,o,t)||t===i)&&o++,o<s.length}),o-l}(n.maskOptions,0,t,i);e=c(n.maskOptions,e,t,i),i+=u,i=n.getRightEditablePos(i)||i,n.setInputValue(e),s&&"function"==typeof n.props.onChange&&n.props.onChange(s),n.setCursorPos(i)}})};return m});

@@ -6,3 +6,2 @@ export var defaultCharsRules = {

};
export var defaultMaskChar = '_';

@@ -1,16 +0,13 @@

var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
function _instanceof(left, right) { if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) { return right[Symbol.hasInstance](left); } else { return left instanceof right; } }
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; }
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; subClass.__proto__ = superClass; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
// https://github.com/sanniassin/react-input-mask
import React from 'react';
import parseMask from './utils/parseMask';

@@ -21,9 +18,11 @@ import { isAndroidBrowser, isWindowsPhoneBrowser, isAndroidFirefox } from './utils/environment';

var InputElement = function (_React$Component) {
_inherits(InputElement, _React$Component);
var InputElement =
/*#__PURE__*/
function (_React$Component) {
_inheritsLoose(InputElement, _React$Component);
function InputElement(props) {
_classCallCheck(this, InputElement);
var _this;
var _this = _possibleConstructorReturn(this, (InputElement.__proto__ || Object.getPrototypeOf(InputElement)).call(this, props));
_this = _React$Component.call(this, props) || this;

@@ -38,4 +37,2 @@ _initialiseProps.call(_this);

alwaysShowMask = props.alwaysShowMask;
_this.hasValue = value != null;

@@ -47,2 +44,3 @@ _this.maskOptions = parseMask(mask, maskChar, formatChars);

}
if (value == null) {

@@ -62,54 +60,48 @@ value = defaultValue;

return InputElement;
}(React.Component);
var _proto = InputElement.prototype;
var _initialiseProps = function _initialiseProps() {
var _this2 = this;
_proto.componentDidMount = function componentDidMount() {
this.isAndroidBrowser = isAndroidBrowser();
this.isWindowsPhoneBrowser = isWindowsPhoneBrowser();
this.isAndroidFirefox = isAndroidFirefox();
this.lastCursorPos = null;
this.focused = false;
this.componentDidMount = function () {
_this2.isAndroidBrowser = isAndroidBrowser();
_this2.isWindowsPhoneBrowser = isWindowsPhoneBrowser();
_this2.isAndroidFirefox = isAndroidFirefox();
if (_this2.maskOptions.mask && _this2.getInputValue() !== _this2.value) {
_this2.setInputValue(_this2.value);
if (this.maskOptions.mask && this.getInputValue() !== this.value) {
this.setInputValue(this.value);
}
};
this.componentWillReceiveProps = function (nextProps) {
var oldMaskOptions = _this2.maskOptions;
_proto.componentWillReceiveProps = function componentWillReceiveProps(nextProps) {
var oldMaskOptions = this.maskOptions;
this.hasValue = nextProps.value != null;
this.maskOptions = parseMask(nextProps.mask, nextProps.maskChar, nextProps.formatChars);
_this2.hasValue = nextProps.value != null;
_this2.maskOptions = parseMask(nextProps.mask, nextProps.maskChar, nextProps.formatChars);
if (!_this2.maskOptions.mask) {
_this2.backspaceOrDeleteRemoval = null;
_this2.lastCursorPos = null;
if (!this.maskOptions.mask) {
this.backspaceOrDeleteRemoval = null;
this.lastCursorPos = null;
return;
}
var isMaskChanged = _this2.maskOptions.mask && _this2.maskOptions.mask !== oldMaskOptions.mask;
var showEmpty = nextProps.alwaysShowMask || _this2.isFocused();
var newValue = _this2.hasValue ? _this2.getStringValue(nextProps.value) : _this2.value;
var isMaskChanged = this.maskOptions.mask && this.maskOptions.mask !== oldMaskOptions.mask;
var showEmpty = nextProps.alwaysShowMask || this.isFocused();
var newValue = this.hasValue ? this.getStringValue(nextProps.value) : this.value;
if (!oldMaskOptions.mask && !_this2.hasValue) {
newValue = _this2.getInputDOMNode().value;
if (!oldMaskOptions.mask && !this.hasValue) {
newValue = this.getInputDOMNode().value;
}
if (isMaskChanged || _this2.maskOptions.mask && (newValue || showEmpty)) {
newValue = formatValue(_this2.maskOptions, newValue);
if (isMaskChanged || this.maskOptions.mask && (newValue || showEmpty)) {
newValue = formatValue(this.maskOptions, newValue);
if (isMaskChanged) {
var pos = _this2.lastCursorPos;
var filledLen = getFilledLength(_this2.maskOptions, newValue);
var pos = this.lastCursorPos;
var filledLen = getFilledLength(this.maskOptions, newValue);
if (pos === null || filledLen < pos) {
if (isFilled(_this2.maskOptions, newValue)) {
if (isFilled(this.maskOptions, newValue)) {
pos = filledLen;
} else {
pos = _this2.getRightEditablePos(filledLen);
pos = this.getRightEditablePos(filledLen);
}
_this2.setCursorPos(pos);
this.setCursorPos(pos);
}

@@ -119,407 +111,568 @@ }

if (_this2.maskOptions.mask && isEmpty(_this2.maskOptions, newValue) && !showEmpty && (!_this2.hasValue || !nextProps.value)) {
if (this.maskOptions.mask && isEmpty(this.maskOptions, newValue) && !showEmpty && (!this.hasValue || !nextProps.value)) {
newValue = '';
}
_this2.value = newValue;
this.value = newValue;
};
this.componentDidUpdate = function () {
if (_this2.maskOptions.mask && _this2.getInputValue() !== _this2.value) {
_this2.setInputValue(_this2.value);
_proto.componentDidUpdate = function componentDidUpdate() {
if (this.maskOptions.mask && this.getInputValue() !== this.value) {
this.setInputValue(this.value);
}
};
this.isDOMElement = function (element) {
return (typeof HTMLElement === 'undefined' ? 'undefined' : _typeof(HTMLElement)) === 'object' ? element instanceof HTMLElement // DOM2
: element.nodeType === 1 && typeof element.nodeName === 'string';
};
_proto.render = function render() {
var _this2 = this;
this.getInputDOMNode = function () {
var input = _this2.input;
if (!input) {
return null;
}
var _props = this.props,
mask = _props.mask,
alwaysShowMask = _props.alwaysShowMask,
maskChar = _props.maskChar,
formatChars = _props.formatChars,
props = _objectWithoutProperties(_props, ["mask", "alwaysShowMask", "maskChar", "formatChars"]);
if (_this2.isDOMElement(input)) {
return input;
if (this.maskOptions.mask) {
if (!props.disabled && !props.readOnly) {
var handlersKeys = ['onChange', 'onKeyDown', 'onPaste', 'onMouseDown'];
handlersKeys.forEach(function (key) {
props[key] = _this2[key];
});
}
if (props.value != null) {
props.value = this.value;
}
}
// React 0.13
return React.findDOMNode(input);
return React.createElement("input", _extends({
ref: function ref(_ref) {
return _this2.input = _ref;
}
}, props, {
onFocus: this.onFocus,
onBlur: this.onBlur
}));
};
this.getInputValue = function () {
var input = _this2.getInputDOMNode();
if (!input) {
return null;
return InputElement;
}(React.Component);
var _initialiseProps = function _initialiseProps() {
var _this3 = this;
Object.defineProperty(this, "lastCursorPos", {
configurable: true,
enumerable: true,
writable: true,
value: null
});
Object.defineProperty(this, "focused", {
configurable: true,
enumerable: true,
writable: true,
value: false
});
Object.defineProperty(this, "isDOMElement", {
configurable: true,
enumerable: true,
writable: true,
value: function value(element) {
return (typeof HTMLElement === "undefined" ? "undefined" : _typeof(HTMLElement)) === 'object' ? _instanceof(element, HTMLElement) // DOM2
: element.nodeType === 1 && typeof element.nodeName === 'string';
}
});
Object.defineProperty(this, "getInputDOMNode", {
configurable: true,
enumerable: true,
writable: true,
value: function value() {
var input = _this3.input;
return input.value;
};
if (!input) {
return null;
}
this.setInputValue = function (value) {
var input = _this2.getInputDOMNode();
if (!input) {
return;
if (_this3.isDOMElement(input)) {
return input;
} // React 0.13
return React.findDOMNode(input);
}
});
Object.defineProperty(this, "getInputValue", {
configurable: true,
enumerable: true,
writable: true,
value: function value() {
var input = _this3.getInputDOMNode();
_this2.value = value;
input.value = value;
};
if (!input) {
return null;
}
this.getLeftEditablePos = function (pos) {
for (var i = pos; i >= 0; --i) {
if (!isPermanentChar(_this2.maskOptions, i)) {
return i;
}
return input.value;
}
return null;
};
});
Object.defineProperty(this, "setInputValue", {
configurable: true,
enumerable: true,
writable: true,
value: function value(_value) {
var input = _this3.getInputDOMNode();
this.getRightEditablePos = function (pos) {
var mask = _this2.maskOptions.mask;
if (!input) {
return;
}
for (var i = pos; i < mask.length; ++i) {
if (!isPermanentChar(_this2.maskOptions, i)) {
return i;
_this3.value = _value;
input.value = _value;
}
});
Object.defineProperty(this, "getLeftEditablePos", {
configurable: true,
enumerable: true,
writable: true,
value: function value(pos) {
for (var i = pos; i >= 0; --i) {
if (!isPermanentChar(_this3.maskOptions, i)) {
return i;
}
}
}
return null;
};
this.setCursorToEnd = function () {
var filledLen = getFilledLength(_this2.maskOptions, _this2.value);
var pos = _this2.getRightEditablePos(filledLen);
if (pos !== null) {
_this2.setCursorPos(pos);
return null;
}
};
});
Object.defineProperty(this, "getRightEditablePos", {
configurable: true,
enumerable: true,
writable: true,
value: function value(pos) {
var mask = _this3.maskOptions.mask;
this.setSelection = function (start) {
var len = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
for (var i = pos; i < mask.length; ++i) {
if (!isPermanentChar(_this3.maskOptions, i)) {
return i;
}
}
var input = _this2.getInputDOMNode();
if (!input) {
return;
return null;
}
});
Object.defineProperty(this, "setCursorToEnd", {
configurable: true,
enumerable: true,
writable: true,
value: function value() {
var filledLen = getFilledLength(_this3.maskOptions, _this3.value);
var end = start + len;
if ('selectionStart' in input && 'selectionEnd' in input) {
input.selectionStart = start;
input.selectionEnd = end;
} else {
var range = input.createTextRange();
range.collapse(true);
range.moveStart('character', start);
range.moveEnd('character', end - start);
range.select();
}
};
var pos = _this3.getRightEditablePos(filledLen);
this.getSelection = function () {
var input = _this2.getInputDOMNode();
var start = 0;
var end = 0;
if ('selectionStart' in input && 'selectionEnd' in input) {
start = input.selectionStart;
end = input.selectionEnd;
} else {
var range = document.selection.createRange();
if (range.parentElement() === input) {
start = -range.moveStart('character', -input.value.length);
end = -range.moveEnd('character', -input.value.length);
if (pos !== null) {
_this3.setCursorPos(pos);
}
}
});
Object.defineProperty(this, "setSelection", {
configurable: true,
enumerable: true,
writable: true,
value: function value(start, len) {
if (len === void 0) {
len = 0;
}
return {
start: start,
end: end,
length: end - start
};
};
var input = _this3.getInputDOMNode();
this.getCursorPos = function () {
return _this2.getSelection().start;
};
if (!input) {
return;
}
this.setCursorPos = function (pos) {
_this2.setSelection(pos, 0);
var end = start + len;
defer(function () {
_this2.setSelection(pos, 0);
});
if ('selectionStart' in input && 'selectionEnd' in input) {
input.selectionStart = start;
input.selectionEnd = end;
} else {
var range = input.createTextRange();
range.collapse(true);
range.moveStart('character', start);
range.moveEnd('character', end - start);
range.select();
}
}
});
Object.defineProperty(this, "getSelection", {
configurable: true,
enumerable: true,
writable: true,
value: function value() {
var input = _this3.getInputDOMNode();
_this2.lastCursorPos = pos;
};
var start = 0;
var end = 0;
this.isFocused = function () {
return _this2.focused;
};
if ('selectionStart' in input && 'selectionEnd' in input) {
start = input.selectionStart;
end = input.selectionEnd;
} else {
var range = document.selection.createRange();
this.getStringValue = function (value) {
return !value && value !== 0 ? '' : value + '';
};
if (range.parentElement() === input) {
start = -range.moveStart('character', -input.value.length);
end = -range.moveEnd('character', -input.value.length);
}
}
this.onKeyDown = function (event) {
_this2.backspaceOrDeleteRemoval = null;
return {
start: start,
end: end,
length: end - start
};
}
});
Object.defineProperty(this, "getCursorPos", {
configurable: true,
enumerable: true,
writable: true,
value: function value() {
return _this3.getSelection().start;
}
});
Object.defineProperty(this, "setCursorPos", {
configurable: true,
enumerable: true,
writable: true,
value: function value(pos) {
_this3.setSelection(pos, 0);
if (typeof _this2.props.onKeyDown === 'function') {
_this2.props.onKeyDown(event);
defer(function () {
_this3.setSelection(pos, 0);
});
_this3.lastCursorPos = pos;
}
});
Object.defineProperty(this, "isFocused", {
configurable: true,
enumerable: true,
writable: true,
value: function value() {
return _this3.focused;
}
});
Object.defineProperty(this, "getStringValue", {
configurable: true,
enumerable: true,
writable: true,
value: function value(_value2) {
return !_value2 && _value2 !== 0 ? '' : _value2 + '';
}
});
Object.defineProperty(this, "onKeyDown", {
configurable: true,
enumerable: true,
writable: true,
value: function value(event) {
_this3.backspaceOrDeleteRemoval = null;
var key = event.key,
ctrlKey = event.ctrlKey,
metaKey = event.metaKey,
defaultPrevented = event.defaultPrevented;
if (typeof _this3.props.onKeyDown === 'function') {
_this3.props.onKeyDown(event);
}
if (ctrlKey || metaKey || defaultPrevented) {
return;
}
var key = event.key,
ctrlKey = event.ctrlKey,
metaKey = event.metaKey,
defaultPrevented = event.defaultPrevented;
if (key === 'Backspace' || key === 'Delete') {
var selection = _this2.getSelection();
var canRemove = key === 'Backspace' && selection.end > 0 || key === 'Delete' && _this2.value.length > selection.start;
if (!canRemove) {
if (ctrlKey || metaKey || defaultPrevented) {
return;
}
_this2.backspaceOrDeleteRemoval = {
key: key,
selection: _this2.getSelection()
};
if (key === 'Backspace' || key === 'Delete') {
var selection = _this3.getSelection();
var canRemove = key === 'Backspace' && selection.end > 0 || key === 'Delete' && _this3.value.length > selection.start;
if (!canRemove) {
return;
}
_this3.backspaceOrDeleteRemoval = {
key: key,
selection: _this3.getSelection()
};
}
}
};
});
Object.defineProperty(this, "onChange", {
configurable: true,
enumerable: true,
writable: true,
value: function value(event) {
var beforePasteState = _this3.beforePasteState;
var _this3$maskOptions = _this3.maskOptions,
mask = _this3$maskOptions.mask,
maskChar = _this3$maskOptions.maskChar,
lastEditablePos = _this3$maskOptions.lastEditablePos,
prefix = _this3$maskOptions.prefix;
this.onChange = function (event) {
var paste = _this2.paste;
var _maskOptions = _this2.maskOptions,
mask = _maskOptions.mask,
maskChar = _maskOptions.maskChar,
lastEditablePos = _maskOptions.lastEditablePos,
prefix = _maskOptions.prefix;
var value = _this3.getInputValue();
var oldValue = _this3.value;
var value = _this2.getInputValue();
var oldValue = _this2.value;
if (beforePasteState) {
_this3.beforePasteState = null;
if (paste) {
_this2.paste = null;
_this2.pasteText(paste.value, value, paste.selection, event);
return;
}
_this3.pasteText(beforePasteState.value, value, beforePasteState.selection, event);
var selection = _this2.getSelection();
var cursorPos = selection.end;
var maskLen = mask.length;
var valueLen = value.length;
var oldValueLen = oldValue.length;
return;
}
var clearedValue;
var enteredString;
var selection = _this3.getSelection();
if (_this2.backspaceOrDeleteRemoval) {
var deleteFromRight = _this2.backspaceOrDeleteRemoval.key === 'Delete';
value = _this2.value;
selection = _this2.backspaceOrDeleteRemoval.selection;
cursorPos = selection.start;
var cursorPos = selection.end;
var maskLen = mask.length;
var valueLen = value.length;
var oldValueLen = oldValue.length;
var clearedValue;
var enteredString;
_this2.backspaceOrDeleteRemoval = null;
if (_this3.backspaceOrDeleteRemoval) {
var deleteFromRight = _this3.backspaceOrDeleteRemoval.key === 'Delete';
value = _this3.value;
selection = _this3.backspaceOrDeleteRemoval.selection;
cursorPos = selection.start;
_this3.backspaceOrDeleteRemoval = null;
if (selection.length) {
value = clearRange(_this2.maskOptions, value, selection.start, selection.length);
} else if (selection.start < prefix.length || !deleteFromRight && selection.start === prefix.length) {
cursorPos = prefix.length;
} else {
var editablePos = deleteFromRight ? _this2.getRightEditablePos(cursorPos) : _this2.getLeftEditablePos(cursorPos - 1);
if (selection.length) {
value = clearRange(_this3.maskOptions, value, selection.start, selection.length);
} else if (selection.start < prefix.length || !deleteFromRight && selection.start === prefix.length) {
cursorPos = prefix.length;
} else {
var editablePos = deleteFromRight ? _this3.getRightEditablePos(cursorPos) : _this3.getLeftEditablePos(cursorPos - 1);
if (editablePos !== null) {
value = clearRange(_this2.maskOptions, value, editablePos, 1);
cursorPos = editablePos;
if (editablePos !== null) {
value = clearRange(_this3.maskOptions, value, editablePos, 1);
cursorPos = editablePos;
}
}
}
} else if (valueLen > oldValueLen) {
var enteredStringLen = valueLen - oldValueLen;
var startPos = selection.end - enteredStringLen;
enteredString = value.substr(startPos, enteredStringLen);
} else if (valueLen > oldValueLen) {
var enteredStringLen = valueLen - oldValueLen;
var startPos = selection.end - enteredStringLen;
enteredString = value.substr(startPos, enteredStringLen);
if (startPos < lastEditablePos && (enteredStringLen !== 1 || enteredString !== mask[startPos])) {
cursorPos = _this2.getRightEditablePos(startPos);
} else {
cursorPos = startPos;
}
if (startPos < lastEditablePos && (enteredStringLen !== 1 || enteredString !== mask[startPos])) {
cursorPos = _this3.getRightEditablePos(startPos);
} else {
cursorPos = startPos;
}
value = value.substr(0, startPos) + value.substr(startPos + enteredStringLen);
value = value.substr(0, startPos) + value.substr(startPos + enteredStringLen);
clearedValue = clearRange(_this3.maskOptions, value, startPos, maskLen - startPos);
clearedValue = insertString(_this3.maskOptions, clearedValue, enteredString, cursorPos);
value = insertString(_this3.maskOptions, oldValue, enteredString, cursorPos);
clearedValue = clearRange(_this2.maskOptions, value, startPos, maskLen - startPos);
clearedValue = insertString(_this2.maskOptions, clearedValue, enteredString, cursorPos);
if (enteredStringLen !== 1 || cursorPos >= prefix.length && cursorPos < lastEditablePos) {
cursorPos = Math.max(getFilledLength(_this3.maskOptions, clearedValue), cursorPos);
value = insertString(_this2.maskOptions, oldValue, enteredString, cursorPos);
if (cursorPos < lastEditablePos) {
cursorPos = _this3.getRightEditablePos(cursorPos);
}
} else if (cursorPos < lastEditablePos) {
cursorPos++;
}
} else if (valueLen < oldValueLen) {
var removedLen = maskLen - valueLen;
enteredString = value.substr(0, selection.end);
var clearOnly = enteredString === oldValue.substr(0, selection.end);
clearedValue = clearRange(_this3.maskOptions, oldValue, selection.end, removedLen);
if (enteredStringLen !== 1 || cursorPos >= prefix.length && cursorPos < lastEditablePos) {
cursorPos = Math.max(getFilledLength(_this2.maskOptions, clearedValue), cursorPos);
if (cursorPos < lastEditablePos) {
cursorPos = _this2.getRightEditablePos(cursorPos);
if (maskChar) {
value = insertString(_this3.maskOptions, clearedValue, enteredString, 0);
}
} else if (cursorPos < lastEditablePos) {
cursorPos++;
}
} else if (valueLen < oldValueLen) {
var removedLen = maskLen - valueLen;
enteredString = value.substr(0, selection.end);
var clearOnly = enteredString === oldValue.substr(0, selection.end);
clearedValue = clearRange(_this2.maskOptions, oldValue, selection.end, removedLen);
clearedValue = clearRange(_this3.maskOptions, clearedValue, selection.end, maskLen - selection.end);
clearedValue = insertString(_this3.maskOptions, clearedValue, enteredString, 0);
if (maskChar) {
value = insertString(_this2.maskOptions, clearedValue, enteredString, 0);
}
if (!clearOnly) {
cursorPos = Math.max(getFilledLength(_this3.maskOptions, clearedValue), cursorPos);
clearedValue = clearRange(_this2.maskOptions, clearedValue, selection.end, maskLen - selection.end);
clearedValue = insertString(_this2.maskOptions, clearedValue, enteredString, 0);
if (!clearOnly) {
cursorPos = Math.max(getFilledLength(_this2.maskOptions, clearedValue), cursorPos);
if (cursorPos < lastEditablePos) {
cursorPos = _this2.getRightEditablePos(cursorPos);
if (cursorPos < lastEditablePos) {
cursorPos = _this3.getRightEditablePos(cursorPos);
}
} else if (cursorPos < prefix.length) {
cursorPos = prefix.length;
}
} else if (cursorPos < prefix.length) {
cursorPos = prefix.length;
}
}
value = formatValue(_this2.maskOptions, value);
_this2.setInputValue(value);
value = formatValue(_this3.maskOptions, value);
if (typeof _this2.props.onChange === 'function') {
_this2.props.onChange(event);
}
_this3.setInputValue(value);
if (_this2.isWindowsPhoneBrowser) {
defer(function () {
_this2.setSelection(cursorPos, 0);
});
} else {
_this2.setCursorPos(cursorPos);
if (typeof _this3.props.onChange === 'function') {
_this3.props.onChange(event);
}
if (_this3.isWindowsPhoneBrowser) {
defer(function () {
_this3.setSelection(cursorPos, 0);
});
} else {
_this3.setCursorPos(cursorPos);
}
}
};
});
Object.defineProperty(this, "onFocus", {
configurable: true,
enumerable: true,
writable: true,
value: function value(event) {
_this3.focused = true;
this.onFocus = function (event) {
_this2.focused = true;
if (_this3.maskOptions.mask) {
if (!_this3.value) {
var prefix = _this3.maskOptions.prefix;
var value = formatValue(_this3.maskOptions, prefix);
var inputValue = formatValue(_this3.maskOptions, value); // do not use this.getInputValue and this.setInputValue as this.input
// can be undefined at this moment if autoFocus attribute is set
if (_this2.maskOptions.mask) {
if (!_this2.value) {
var prefix = _this2.maskOptions.prefix;
var value = formatValue(_this2.maskOptions, prefix);
var inputValue = formatValue(_this2.maskOptions, value);
var isInputValueChanged = inputValue !== event.target.value;
// do not use this.getInputValue and this.setInputValue as this.input
// can be undefined at this moment if autoFocus attribute is set
var isInputValueChanged = inputValue !== event.target.value;
if (isInputValueChanged) {
event.target.value = inputValue;
}
if (isInputValueChanged) {
event.target.value = inputValue;
}
_this3.value = inputValue;
_this2.value = inputValue;
if (isInputValueChanged && typeof _this3.props.onChange === 'function') {
_this3.props.onChange(event);
}
if (isInputValueChanged && typeof _this2.props.onChange === 'function') {
_this2.props.onChange(event);
_this3.setCursorToEnd();
} else if (getFilledLength(_this3.maskOptions, _this3.value) < _this3.maskOptions.mask.length) {
_this3.setCursorToEnd();
}
}
_this2.setCursorToEnd();
} else if (getFilledLength(_this2.maskOptions, _this2.value) < _this2.maskOptions.mask.length) {
_this2.setCursorToEnd();
if (typeof _this3.props.onFocus === 'function') {
_this3.props.onFocus(event);
}
}
});
Object.defineProperty(this, "onBlur", {
configurable: true,
enumerable: true,
writable: true,
value: function value(event) {
_this3.focused = false;
if (typeof _this2.props.onFocus === 'function') {
_this2.props.onFocus(event);
}
};
if (_this3.maskOptions.mask && !_this3.props.alwaysShowMask && isEmpty(_this3.maskOptions, _this3.value)) {
var inputValue = '';
this.onBlur = function (event) {
_this2.focused = false;
var isInputValueChanged = inputValue !== _this3.getInputValue();
if (_this2.maskOptions.mask && !_this2.props.alwaysShowMask && isEmpty(_this2.maskOptions, _this2.value)) {
var inputValue = '';
var isInputValueChanged = inputValue !== _this2.getInputValue();
if (isInputValueChanged) {
_this3.setInputValue(inputValue);
}
if (isInputValueChanged) {
_this2.setInputValue(inputValue);
if (isInputValueChanged && typeof _this3.props.onChange === 'function') {
_this3.props.onChange(event);
}
}
if (isInputValueChanged && typeof _this2.props.onChange === 'function') {
_this2.props.onChange(event);
if (typeof _this3.props.onBlur === 'function') {
_this3.props.onBlur(event);
}
}
});
Object.defineProperty(this, "onMouseDown", {
configurable: true,
enumerable: true,
writable: true,
value: function value(event) {
// tiny unintentional mouse movements can break cursor
// position on focus, so we have to restore it in that case
//
// https://github.com/sanniassin/react-input-mask/issues/108
if (!_this3.focused && document.addEventListener) {
_this3.mouseDownX = event.clientX;
_this3.mouseDownY = event.clientY;
_this3.mouseDownTime = new Date().getTime();
if (typeof _this2.props.onBlur === 'function') {
_this2.props.onBlur(event);
}
};
var mouseUpHandler = function mouseUpHandler(mouseUpEvent) {
document.removeEventListener('mouseup', mouseUpHandler);
this.onPaste = function (event) {
if (typeof _this2.props.onPaste === 'function') {
_this2.props.onPaste(event);
}
if (!_this3.focused) {
return;
}
if (_this2.isAndroidBrowser && !event.defaultPrevented) {
_this2.paste = {
value: _this2.getInputValue(),
selection: _this2.getSelection()
};
_this2.setInputValue('');
}
};
var deltaX = Math.abs(mouseUpEvent.clientX - _this3.mouseDownX);
var deltaY = Math.abs(mouseUpEvent.clientY - _this3.mouseDownY);
var axisDelta = Math.max(deltaX, deltaY);
this.pasteText = function (value, text, selection, event) {
var cursorPos = selection.start;
if (selection.length) {
value = clearRange(_this2.maskOptions, value, cursorPos, selection.length);
var timeDelta = new Date().getTime() - _this3.mouseDownTime;
if (axisDelta <= 10 && timeDelta <= 200 || axisDelta <= 5 && timeDelta <= 300) {
_this3.setCursorToEnd();
}
};
document.addEventListener('mouseup', mouseUpHandler);
}
if (typeof _this3.props.onMouseDown === 'function') {
_this3.props.onMouseDown(event);
}
}
var textLen = getInsertStringLength(_this2.maskOptions, value, text, cursorPos);
value = insertString(_this2.maskOptions, value, text, cursorPos);
cursorPos += textLen;
cursorPos = _this2.getRightEditablePos(cursorPos) || cursorPos;
});
Object.defineProperty(this, "onPaste", {
configurable: true,
enumerable: true,
writable: true,
value: function value(event) {
if (typeof _this3.props.onPaste === 'function') {
_this3.props.onPaste(event);
} // we need raw pasted text, but event.clipboardData
// may not work in Android browser, so we clean input
// to get raw text in onChange handler
if (value !== _this2.getInputValue()) {
_this2.setInputValue(value);
if (event && typeof _this2.props.onChange === 'function') {
_this2.props.onChange(event);
if (!event.defaultPrevented) {
_this3.beforePasteState = {
value: _this3.getInputValue(),
selection: _this3.getSelection()
};
_this3.setInputValue('');
}
}
});
Object.defineProperty(this, "pasteText", {
configurable: true,
enumerable: true,
writable: true,
value: function value(_value3, text, selection, event) {
var cursorPos = selection.start;
_this2.setCursorPos(cursorPos);
};
if (selection.length) {
_value3 = clearRange(_this3.maskOptions, _value3, cursorPos, selection.length);
}
this.render = function () {
var _props = _this2.props,
mask = _props.mask,
alwaysShowMask = _props.alwaysShowMask,
maskChar = _props.maskChar,
formatChars = _props.formatChars,
props = _objectWithoutProperties(_props, ['mask', 'alwaysShowMask', 'maskChar', 'formatChars']);
var textLen = getInsertStringLength(_this3.maskOptions, _value3, text, cursorPos);
_value3 = insertString(_this3.maskOptions, _value3, text, cursorPos);
cursorPos += textLen;
cursorPos = _this3.getRightEditablePos(cursorPos) || cursorPos;
if (_this2.maskOptions.mask) {
if (!props.disabled && !props.readOnly) {
var handlersKeys = ['onChange', 'onKeyDown', 'onPaste'];
handlersKeys.forEach(function (key) {
props[key] = _this2[key];
});
_this3.setInputValue(_value3);
if (event && typeof _this3.props.onChange === 'function') {
_this3.props.onChange(event);
}
if (props.value != null) {
props.value = _this2.value;
}
_this3.setCursorPos(cursorPos);
}
return React.createElement('input', _extends({ ref: function ref(_ref) {
return _this2.input = _ref;
} }, props, { onFocus: _this2.onFocus, onBlur: _this2.onBlur }));
};
});
};
export default InputElement;
export default function (fn) {
var defer = window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || function () {
return setTimeout(fn, 0);
};
var defer = window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || function () {
return setTimeout(fn, 0);
};
return defer(fn);
return defer(fn);
}

@@ -8,3 +8,2 @@ export function isAndroidBrowser() {

}
export function isWindowsPhoneBrowser() {

@@ -16,3 +15,2 @@ var windows = new RegExp('windows', 'i');

}
export function isAndroidFirefox() {

@@ -25,3 +23,2 @@ var windows = new RegExp('windows', 'i');

}
export function isIOS() {

@@ -28,0 +25,0 @@ var windows = new RegExp('windows', 'i');

import { defaultCharsRules, defaultMaskChar } from '../constants';
export default function (mask, maskChar, charsRules) {

@@ -7,2 +6,3 @@ if (maskChar === undefined) {

}
if (charsRules == null) {

@@ -22,2 +22,3 @@ charsRules = defaultCharsRules;

}
var str = '';

@@ -28,3 +29,2 @@ var prefix = '';

var lastEditablePos = null;
mask.split('').forEach(function (character) {

@@ -36,2 +36,3 @@ if (!isPermanent && character === '\\') {

permanents.push(str.length);
if (str.length === permanents.length - 1) {

@@ -43,2 +44,3 @@ prefix += character;

}
str += character;

@@ -48,3 +50,2 @@ isPermanent = false;

});
return {

@@ -51,0 +52,0 @@ maskChar: maskChar,

export function isPermanentChar(maskOptions, pos) {
return maskOptions.permanents.indexOf(pos) !== -1;
}
export function isAllowedChar(maskOptions, pos, character) {

@@ -9,3 +8,2 @@ var mask = maskOptions.mask,

if (!character) {

@@ -21,6 +19,4 @@ return false;

var charRule = charsRules[ruleChar];
return new RegExp(charRule).test(character);
}
export function isEmpty(maskOptions, value) {

@@ -31,3 +27,2 @@ return value.split('').every(function (character, i) {

}
export function getFilledLength(maskOptions, value) {

@@ -37,3 +32,2 @@ var maskChar = maskOptions.maskChar,

if (!maskChar) {

@@ -43,2 +37,3 @@ while (value.length > prefix.length && isPermanentChar(maskOptions, value.length - 1)) {

}
return value.length;

@@ -48,5 +43,7 @@ }

var filledLength = prefix.length;
for (var i = value.length; i >= prefix.length; i--) {
var character = value[i];
var isEnteredCharacter = !isPermanentChar(maskOptions, i) && isAllowedChar(maskOptions, i, character);
if (isEnteredCharacter) {

@@ -60,7 +57,5 @@ filledLength = i + 1;

}
export function isFilled(maskOptions, value) {
return getFilledLength(maskOptions, value) === maskOptions.mask.length;
}
export function formatValue(maskOptions, value) {

@@ -71,3 +66,2 @@ var maskChar = maskOptions.maskChar,

if (!maskChar) {

@@ -99,3 +93,2 @@ value = insertString(maskOptions, '', value, 0);

}
export function clearRange(maskOptions, value, start, len) {

@@ -106,3 +99,2 @@ var end = start + len;

prefix = maskOptions.prefix;
var arrayValue = value.split('');

@@ -114,3 +106,2 @@

value = arrayValue.join('');
return formatValue(maskOptions, value);

@@ -123,9 +114,10 @@ }

}
if (isPermanentChar(maskOptions, i)) {
return mask[i];
}
return maskChar;
}).join('');
}
export function insertString(maskOptions, value, insertStr, insertPos) {

@@ -135,3 +127,2 @@ var mask = maskOptions.mask,

prefix = maskOptions.prefix;
var arrayInsertStr = insertStr.split('');

@@ -143,2 +134,3 @@ var isInputFilled = isFilled(maskOptions, value);

};
var isUsableCharacter = function isUsableCharacter(character, pos) {

@@ -162,5 +154,4 @@ return !maskChar || !isPermanentChar(maskOptions, pos) || character !== maskChar;

insertPos++;
insertPos++; // stop iteration if maximum value length reached
// stop iteration if maximum value length reached
if (insertPos >= mask.length) {

@@ -172,2 +163,3 @@ return false;

var isAllowed = isAllowedChar(maskOptions, insertPos, insertCharacter) || insertCharacter === maskChar;
if (!isAllowed) {

@@ -188,15 +180,11 @@ return true;

insertPos++;
insertPos++; // stop iteration if maximum value length reached
// stop iteration if maximum value length reached
return insertPos < mask.length;
});
return value;
}
export function getInsertStringLength(maskOptions, value, insertStr, insertPos) {
var mask = maskOptions.mask,
maskChar = maskOptions.maskChar;
var arrayInsertStr = insertStr.split('');

@@ -211,5 +199,4 @@ var initialInsertPos = insertPos;

while (!isUsablePosition(insertPos, insertCharacter)) {
insertPos++;
insertPos++; // stop iteration if maximum value length reached
// stop iteration if maximum value length reached
if (insertPos >= mask.length) {

@@ -224,9 +211,8 @@ return false;

insertPos++;
}
} // stop iteration if maximum value length reached
// stop iteration if maximum value length reached
return insertPos < mask.length;
});
return insertPos - initialInsertPos;
}

@@ -1,7 +0,6 @@

'use strict';
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
var defaultCharsRules = exports.defaultCharsRules = {
exports.__esModule = true;
exports.defaultMaskChar = exports.defaultCharsRules = void 0;
var defaultCharsRules = {
'9': '[0-9]',

@@ -11,3 +10,4 @@ 'a': '[A-Za-z]',

};
var defaultMaskChar = exports.defaultMaskChar = '_';
exports.defaultCharsRules = defaultCharsRules;
var defaultMaskChar = '_';
exports.defaultMaskChar = defaultMaskChar;

@@ -1,45 +0,37 @@

'use strict';
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.__esModule = true;
exports.default = void 0;
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
var _react = _interopRequireDefault(require("react"));
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
var _parseMask = _interopRequireDefault(require("./utils/parseMask"));
var _react = require('react');
var _environment = require("./utils/environment");
var _react2 = _interopRequireDefault(_react);
var _string = require("./utils/string");
var _parseMask = require('./utils/parseMask');
var _defer = _interopRequireDefault(require("./utils/defer"));
var _parseMask2 = _interopRequireDefault(_parseMask);
var _environment = require('./utils/environment');
var _string = require('./utils/string');
var _defer = require('./utils/defer');
var _defer2 = _interopRequireDefault(_defer);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; }
function _instanceof(left, right) { if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) { return right[Symbol.hasInstance](left); } else { return left instanceof right; } }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } // https://github.com/sanniassin/react-input-mask
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; subClass.__proto__ = superClass; }
var InputElement = function (_React$Component) {
_inherits(InputElement, _React$Component);
var InputElement =
/*#__PURE__*/
function (_React$Component) {
_inheritsLoose(InputElement, _React$Component);
function InputElement(props) {
_classCallCheck(this, InputElement);
var _this;
var _this = _possibleConstructorReturn(this, (InputElement.__proto__ || Object.getPrototypeOf(InputElement)).call(this, props));
_this = _React$Component.call(this, props) || this;

@@ -54,6 +46,4 @@ _initialiseProps.call(_this);

alwaysShowMask = props.alwaysShowMask;
_this.hasValue = value != null;
_this.maskOptions = (0, _parseMask2.default)(mask, maskChar, formatChars);
_this.maskOptions = (0, _parseMask.default)(mask, maskChar, formatChars);

@@ -63,2 +53,3 @@ if (defaultValue == null) {

}
if (value == null) {

@@ -78,54 +69,48 @@ value = defaultValue;

return InputElement;
}(_react2.default.Component);
var _proto = InputElement.prototype;
var _initialiseProps = function _initialiseProps() {
var _this2 = this;
_proto.componentDidMount = function componentDidMount() {
this.isAndroidBrowser = (0, _environment.isAndroidBrowser)();
this.isWindowsPhoneBrowser = (0, _environment.isWindowsPhoneBrowser)();
this.isAndroidFirefox = (0, _environment.isAndroidFirefox)();
this.lastCursorPos = null;
this.focused = false;
this.componentDidMount = function () {
_this2.isAndroidBrowser = (0, _environment.isAndroidBrowser)();
_this2.isWindowsPhoneBrowser = (0, _environment.isWindowsPhoneBrowser)();
_this2.isAndroidFirefox = (0, _environment.isAndroidFirefox)();
if (_this2.maskOptions.mask && _this2.getInputValue() !== _this2.value) {
_this2.setInputValue(_this2.value);
if (this.maskOptions.mask && this.getInputValue() !== this.value) {
this.setInputValue(this.value);
}
};
this.componentWillReceiveProps = function (nextProps) {
var oldMaskOptions = _this2.maskOptions;
_proto.componentWillReceiveProps = function componentWillReceiveProps(nextProps) {
var oldMaskOptions = this.maskOptions;
this.hasValue = nextProps.value != null;
this.maskOptions = (0, _parseMask.default)(nextProps.mask, nextProps.maskChar, nextProps.formatChars);
_this2.hasValue = nextProps.value != null;
_this2.maskOptions = (0, _parseMask2.default)(nextProps.mask, nextProps.maskChar, nextProps.formatChars);
if (!_this2.maskOptions.mask) {
_this2.backspaceOrDeleteRemoval = null;
_this2.lastCursorPos = null;
if (!this.maskOptions.mask) {
this.backspaceOrDeleteRemoval = null;
this.lastCursorPos = null;
return;
}
var isMaskChanged = _this2.maskOptions.mask && _this2.maskOptions.mask !== oldMaskOptions.mask;
var showEmpty = nextProps.alwaysShowMask || _this2.isFocused();
var newValue = _this2.hasValue ? _this2.getStringValue(nextProps.value) : _this2.value;
var isMaskChanged = this.maskOptions.mask && this.maskOptions.mask !== oldMaskOptions.mask;
var showEmpty = nextProps.alwaysShowMask || this.isFocused();
var newValue = this.hasValue ? this.getStringValue(nextProps.value) : this.value;
if (!oldMaskOptions.mask && !_this2.hasValue) {
newValue = _this2.getInputDOMNode().value;
if (!oldMaskOptions.mask && !this.hasValue) {
newValue = this.getInputDOMNode().value;
}
if (isMaskChanged || _this2.maskOptions.mask && (newValue || showEmpty)) {
newValue = (0, _string.formatValue)(_this2.maskOptions, newValue);
if (isMaskChanged || this.maskOptions.mask && (newValue || showEmpty)) {
newValue = (0, _string.formatValue)(this.maskOptions, newValue);
if (isMaskChanged) {
var pos = _this2.lastCursorPos;
var filledLen = (0, _string.getFilledLength)(_this2.maskOptions, newValue);
var pos = this.lastCursorPos;
var filledLen = (0, _string.getFilledLength)(this.maskOptions, newValue);
if (pos === null || filledLen < pos) {
if ((0, _string.isFilled)(_this2.maskOptions, newValue)) {
if ((0, _string.isFilled)(this.maskOptions, newValue)) {
pos = filledLen;
} else {
pos = _this2.getRightEditablePos(filledLen);
pos = this.getRightEditablePos(filledLen);
}
_this2.setCursorPos(pos);
this.setCursorPos(pos);
}

@@ -135,408 +120,570 @@ }

if (_this2.maskOptions.mask && (0, _string.isEmpty)(_this2.maskOptions, newValue) && !showEmpty && (!_this2.hasValue || !nextProps.value)) {
if (this.maskOptions.mask && (0, _string.isEmpty)(this.maskOptions, newValue) && !showEmpty && (!this.hasValue || !nextProps.value)) {
newValue = '';
}
_this2.value = newValue;
this.value = newValue;
};
this.componentDidUpdate = function () {
if (_this2.maskOptions.mask && _this2.getInputValue() !== _this2.value) {
_this2.setInputValue(_this2.value);
_proto.componentDidUpdate = function componentDidUpdate() {
if (this.maskOptions.mask && this.getInputValue() !== this.value) {
this.setInputValue(this.value);
}
};
this.isDOMElement = function (element) {
return (typeof HTMLElement === 'undefined' ? 'undefined' : _typeof(HTMLElement)) === 'object' ? element instanceof HTMLElement // DOM2
: element.nodeType === 1 && typeof element.nodeName === 'string';
};
_proto.render = function render() {
var _this2 = this;
this.getInputDOMNode = function () {
var input = _this2.input;
if (!input) {
return null;
}
var _props = this.props,
mask = _props.mask,
alwaysShowMask = _props.alwaysShowMask,
maskChar = _props.maskChar,
formatChars = _props.formatChars,
props = _objectWithoutProperties(_props, ["mask", "alwaysShowMask", "maskChar", "formatChars"]);
if (_this2.isDOMElement(input)) {
return input;
if (this.maskOptions.mask) {
if (!props.disabled && !props.readOnly) {
var handlersKeys = ['onChange', 'onKeyDown', 'onPaste', 'onMouseDown'];
handlersKeys.forEach(function (key) {
props[key] = _this2[key];
});
}
if (props.value != null) {
props.value = this.value;
}
}
// React 0.13
return _react2.default.findDOMNode(input);
return _react.default.createElement("input", _extends({
ref: function ref(_ref) {
return _this2.input = _ref;
}
}, props, {
onFocus: this.onFocus,
onBlur: this.onBlur
}));
};
this.getInputValue = function () {
var input = _this2.getInputDOMNode();
if (!input) {
return null;
return InputElement;
}(_react.default.Component);
var _initialiseProps = function _initialiseProps() {
var _this3 = this;
Object.defineProperty(this, "lastCursorPos", {
configurable: true,
enumerable: true,
writable: true,
value: null
});
Object.defineProperty(this, "focused", {
configurable: true,
enumerable: true,
writable: true,
value: false
});
Object.defineProperty(this, "isDOMElement", {
configurable: true,
enumerable: true,
writable: true,
value: function value(element) {
return (typeof HTMLElement === "undefined" ? "undefined" : _typeof(HTMLElement)) === 'object' ? _instanceof(element, HTMLElement) // DOM2
: element.nodeType === 1 && typeof element.nodeName === 'string';
}
});
Object.defineProperty(this, "getInputDOMNode", {
configurable: true,
enumerable: true,
writable: true,
value: function value() {
var input = _this3.input;
return input.value;
};
if (!input) {
return null;
}
this.setInputValue = function (value) {
var input = _this2.getInputDOMNode();
if (!input) {
return;
if (_this3.isDOMElement(input)) {
return input;
} // React 0.13
return _react.default.findDOMNode(input);
}
});
Object.defineProperty(this, "getInputValue", {
configurable: true,
enumerable: true,
writable: true,
value: function value() {
var input = _this3.getInputDOMNode();
_this2.value = value;
input.value = value;
};
if (!input) {
return null;
}
this.getLeftEditablePos = function (pos) {
for (var i = pos; i >= 0; --i) {
if (!(0, _string.isPermanentChar)(_this2.maskOptions, i)) {
return i;
}
return input.value;
}
return null;
};
});
Object.defineProperty(this, "setInputValue", {
configurable: true,
enumerable: true,
writable: true,
value: function value(_value) {
var input = _this3.getInputDOMNode();
this.getRightEditablePos = function (pos) {
var mask = _this2.maskOptions.mask;
if (!input) {
return;
}
for (var i = pos; i < mask.length; ++i) {
if (!(0, _string.isPermanentChar)(_this2.maskOptions, i)) {
return i;
_this3.value = _value;
input.value = _value;
}
});
Object.defineProperty(this, "getLeftEditablePos", {
configurable: true,
enumerable: true,
writable: true,
value: function value(pos) {
for (var i = pos; i >= 0; --i) {
if (!(0, _string.isPermanentChar)(_this3.maskOptions, i)) {
return i;
}
}
}
return null;
};
this.setCursorToEnd = function () {
var filledLen = (0, _string.getFilledLength)(_this2.maskOptions, _this2.value);
var pos = _this2.getRightEditablePos(filledLen);
if (pos !== null) {
_this2.setCursorPos(pos);
return null;
}
};
});
Object.defineProperty(this, "getRightEditablePos", {
configurable: true,
enumerable: true,
writable: true,
value: function value(pos) {
var mask = _this3.maskOptions.mask;
this.setSelection = function (start) {
var len = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
for (var i = pos; i < mask.length; ++i) {
if (!(0, _string.isPermanentChar)(_this3.maskOptions, i)) {
return i;
}
}
var input = _this2.getInputDOMNode();
if (!input) {
return;
return null;
}
});
Object.defineProperty(this, "setCursorToEnd", {
configurable: true,
enumerable: true,
writable: true,
value: function value() {
var filledLen = (0, _string.getFilledLength)(_this3.maskOptions, _this3.value);
var end = start + len;
if ('selectionStart' in input && 'selectionEnd' in input) {
input.selectionStart = start;
input.selectionEnd = end;
} else {
var range = input.createTextRange();
range.collapse(true);
range.moveStart('character', start);
range.moveEnd('character', end - start);
range.select();
}
};
var pos = _this3.getRightEditablePos(filledLen);
this.getSelection = function () {
var input = _this2.getInputDOMNode();
var start = 0;
var end = 0;
if ('selectionStart' in input && 'selectionEnd' in input) {
start = input.selectionStart;
end = input.selectionEnd;
} else {
var range = document.selection.createRange();
if (range.parentElement() === input) {
start = -range.moveStart('character', -input.value.length);
end = -range.moveEnd('character', -input.value.length);
if (pos !== null) {
_this3.setCursorPos(pos);
}
}
});
Object.defineProperty(this, "setSelection", {
configurable: true,
enumerable: true,
writable: true,
value: function value(start, len) {
if (len === void 0) {
len = 0;
}
return {
start: start,
end: end,
length: end - start
};
};
var input = _this3.getInputDOMNode();
this.getCursorPos = function () {
return _this2.getSelection().start;
};
if (!input) {
return;
}
this.setCursorPos = function (pos) {
_this2.setSelection(pos, 0);
var end = start + len;
(0, _defer2.default)(function () {
_this2.setSelection(pos, 0);
});
if ('selectionStart' in input && 'selectionEnd' in input) {
input.selectionStart = start;
input.selectionEnd = end;
} else {
var range = input.createTextRange();
range.collapse(true);
range.moveStart('character', start);
range.moveEnd('character', end - start);
range.select();
}
}
});
Object.defineProperty(this, "getSelection", {
configurable: true,
enumerable: true,
writable: true,
value: function value() {
var input = _this3.getInputDOMNode();
_this2.lastCursorPos = pos;
};
var start = 0;
var end = 0;
this.isFocused = function () {
return _this2.focused;
};
if ('selectionStart' in input && 'selectionEnd' in input) {
start = input.selectionStart;
end = input.selectionEnd;
} else {
var range = document.selection.createRange();
this.getStringValue = function (value) {
return !value && value !== 0 ? '' : value + '';
};
if (range.parentElement() === input) {
start = -range.moveStart('character', -input.value.length);
end = -range.moveEnd('character', -input.value.length);
}
}
this.onKeyDown = function (event) {
_this2.backspaceOrDeleteRemoval = null;
return {
start: start,
end: end,
length: end - start
};
}
});
Object.defineProperty(this, "getCursorPos", {
configurable: true,
enumerable: true,
writable: true,
value: function value() {
return _this3.getSelection().start;
}
});
Object.defineProperty(this, "setCursorPos", {
configurable: true,
enumerable: true,
writable: true,
value: function value(pos) {
_this3.setSelection(pos, 0);
if (typeof _this2.props.onKeyDown === 'function') {
_this2.props.onKeyDown(event);
(0, _defer.default)(function () {
_this3.setSelection(pos, 0);
});
_this3.lastCursorPos = pos;
}
});
Object.defineProperty(this, "isFocused", {
configurable: true,
enumerable: true,
writable: true,
value: function value() {
return _this3.focused;
}
});
Object.defineProperty(this, "getStringValue", {
configurable: true,
enumerable: true,
writable: true,
value: function value(_value2) {
return !_value2 && _value2 !== 0 ? '' : _value2 + '';
}
});
Object.defineProperty(this, "onKeyDown", {
configurable: true,
enumerable: true,
writable: true,
value: function value(event) {
_this3.backspaceOrDeleteRemoval = null;
var key = event.key,
ctrlKey = event.ctrlKey,
metaKey = event.metaKey,
defaultPrevented = event.defaultPrevented;
if (typeof _this3.props.onKeyDown === 'function') {
_this3.props.onKeyDown(event);
}
if (ctrlKey || metaKey || defaultPrevented) {
return;
}
var key = event.key,
ctrlKey = event.ctrlKey,
metaKey = event.metaKey,
defaultPrevented = event.defaultPrevented;
if (key === 'Backspace' || key === 'Delete') {
var selection = _this2.getSelection();
var canRemove = key === 'Backspace' && selection.end > 0 || key === 'Delete' && _this2.value.length > selection.start;
if (!canRemove) {
if (ctrlKey || metaKey || defaultPrevented) {
return;
}
_this2.backspaceOrDeleteRemoval = {
key: key,
selection: _this2.getSelection()
};
if (key === 'Backspace' || key === 'Delete') {
var selection = _this3.getSelection();
var canRemove = key === 'Backspace' && selection.end > 0 || key === 'Delete' && _this3.value.length > selection.start;
if (!canRemove) {
return;
}
_this3.backspaceOrDeleteRemoval = {
key: key,
selection: _this3.getSelection()
};
}
}
};
});
Object.defineProperty(this, "onChange", {
configurable: true,
enumerable: true,
writable: true,
value: function value(event) {
var beforePasteState = _this3.beforePasteState;
var _this3$maskOptions = _this3.maskOptions,
mask = _this3$maskOptions.mask,
maskChar = _this3$maskOptions.maskChar,
lastEditablePos = _this3$maskOptions.lastEditablePos,
prefix = _this3$maskOptions.prefix;
this.onChange = function (event) {
var paste = _this2.paste;
var _maskOptions = _this2.maskOptions,
mask = _maskOptions.mask,
maskChar = _maskOptions.maskChar,
lastEditablePos = _maskOptions.lastEditablePos,
prefix = _maskOptions.prefix;
var value = _this3.getInputValue();
var oldValue = _this3.value;
var value = _this2.getInputValue();
var oldValue = _this2.value;
if (beforePasteState) {
_this3.beforePasteState = null;
if (paste) {
_this2.paste = null;
_this2.pasteText(paste.value, value, paste.selection, event);
return;
}
_this3.pasteText(beforePasteState.value, value, beforePasteState.selection, event);
var selection = _this2.getSelection();
var cursorPos = selection.end;
var maskLen = mask.length;
var valueLen = value.length;
var oldValueLen = oldValue.length;
return;
}
var clearedValue;
var enteredString;
var selection = _this3.getSelection();
if (_this2.backspaceOrDeleteRemoval) {
var deleteFromRight = _this2.backspaceOrDeleteRemoval.key === 'Delete';
value = _this2.value;
selection = _this2.backspaceOrDeleteRemoval.selection;
cursorPos = selection.start;
var cursorPos = selection.end;
var maskLen = mask.length;
var valueLen = value.length;
var oldValueLen = oldValue.length;
var clearedValue;
var enteredString;
_this2.backspaceOrDeleteRemoval = null;
if (_this3.backspaceOrDeleteRemoval) {
var deleteFromRight = _this3.backspaceOrDeleteRemoval.key === 'Delete';
value = _this3.value;
selection = _this3.backspaceOrDeleteRemoval.selection;
cursorPos = selection.start;
_this3.backspaceOrDeleteRemoval = null;
if (selection.length) {
value = (0, _string.clearRange)(_this2.maskOptions, value, selection.start, selection.length);
} else if (selection.start < prefix.length || !deleteFromRight && selection.start === prefix.length) {
cursorPos = prefix.length;
} else {
var editablePos = deleteFromRight ? _this2.getRightEditablePos(cursorPos) : _this2.getLeftEditablePos(cursorPos - 1);
if (selection.length) {
value = (0, _string.clearRange)(_this3.maskOptions, value, selection.start, selection.length);
} else if (selection.start < prefix.length || !deleteFromRight && selection.start === prefix.length) {
cursorPos = prefix.length;
} else {
var editablePos = deleteFromRight ? _this3.getRightEditablePos(cursorPos) : _this3.getLeftEditablePos(cursorPos - 1);
if (editablePos !== null) {
value = (0, _string.clearRange)(_this2.maskOptions, value, editablePos, 1);
cursorPos = editablePos;
if (editablePos !== null) {
value = (0, _string.clearRange)(_this3.maskOptions, value, editablePos, 1);
cursorPos = editablePos;
}
}
}
} else if (valueLen > oldValueLen) {
var enteredStringLen = valueLen - oldValueLen;
var startPos = selection.end - enteredStringLen;
enteredString = value.substr(startPos, enteredStringLen);
} else if (valueLen > oldValueLen) {
var enteredStringLen = valueLen - oldValueLen;
var startPos = selection.end - enteredStringLen;
enteredString = value.substr(startPos, enteredStringLen);
if (startPos < lastEditablePos && (enteredStringLen !== 1 || enteredString !== mask[startPos])) {
cursorPos = _this2.getRightEditablePos(startPos);
} else {
cursorPos = startPos;
}
if (startPos < lastEditablePos && (enteredStringLen !== 1 || enteredString !== mask[startPos])) {
cursorPos = _this3.getRightEditablePos(startPos);
} else {
cursorPos = startPos;
}
value = value.substr(0, startPos) + value.substr(startPos + enteredStringLen);
value = value.substr(0, startPos) + value.substr(startPos + enteredStringLen);
clearedValue = (0, _string.clearRange)(_this3.maskOptions, value, startPos, maskLen - startPos);
clearedValue = (0, _string.insertString)(_this3.maskOptions, clearedValue, enteredString, cursorPos);
value = (0, _string.insertString)(_this3.maskOptions, oldValue, enteredString, cursorPos);
clearedValue = (0, _string.clearRange)(_this2.maskOptions, value, startPos, maskLen - startPos);
clearedValue = (0, _string.insertString)(_this2.maskOptions, clearedValue, enteredString, cursorPos);
if (enteredStringLen !== 1 || cursorPos >= prefix.length && cursorPos < lastEditablePos) {
cursorPos = Math.max((0, _string.getFilledLength)(_this3.maskOptions, clearedValue), cursorPos);
value = (0, _string.insertString)(_this2.maskOptions, oldValue, enteredString, cursorPos);
if (cursorPos < lastEditablePos) {
cursorPos = _this3.getRightEditablePos(cursorPos);
}
} else if (cursorPos < lastEditablePos) {
cursorPos++;
}
} else if (valueLen < oldValueLen) {
var removedLen = maskLen - valueLen;
enteredString = value.substr(0, selection.end);
var clearOnly = enteredString === oldValue.substr(0, selection.end);
clearedValue = (0, _string.clearRange)(_this3.maskOptions, oldValue, selection.end, removedLen);
if (enteredStringLen !== 1 || cursorPos >= prefix.length && cursorPos < lastEditablePos) {
cursorPos = Math.max((0, _string.getFilledLength)(_this2.maskOptions, clearedValue), cursorPos);
if (cursorPos < lastEditablePos) {
cursorPos = _this2.getRightEditablePos(cursorPos);
if (maskChar) {
value = (0, _string.insertString)(_this3.maskOptions, clearedValue, enteredString, 0);
}
} else if (cursorPos < lastEditablePos) {
cursorPos++;
}
} else if (valueLen < oldValueLen) {
var removedLen = maskLen - valueLen;
enteredString = value.substr(0, selection.end);
var clearOnly = enteredString === oldValue.substr(0, selection.end);
clearedValue = (0, _string.clearRange)(_this2.maskOptions, oldValue, selection.end, removedLen);
clearedValue = (0, _string.clearRange)(_this3.maskOptions, clearedValue, selection.end, maskLen - selection.end);
clearedValue = (0, _string.insertString)(_this3.maskOptions, clearedValue, enteredString, 0);
if (maskChar) {
value = (0, _string.insertString)(_this2.maskOptions, clearedValue, enteredString, 0);
}
if (!clearOnly) {
cursorPos = Math.max((0, _string.getFilledLength)(_this3.maskOptions, clearedValue), cursorPos);
clearedValue = (0, _string.clearRange)(_this2.maskOptions, clearedValue, selection.end, maskLen - selection.end);
clearedValue = (0, _string.insertString)(_this2.maskOptions, clearedValue, enteredString, 0);
if (!clearOnly) {
cursorPos = Math.max((0, _string.getFilledLength)(_this2.maskOptions, clearedValue), cursorPos);
if (cursorPos < lastEditablePos) {
cursorPos = _this2.getRightEditablePos(cursorPos);
if (cursorPos < lastEditablePos) {
cursorPos = _this3.getRightEditablePos(cursorPos);
}
} else if (cursorPos < prefix.length) {
cursorPos = prefix.length;
}
} else if (cursorPos < prefix.length) {
cursorPos = prefix.length;
}
}
value = (0, _string.formatValue)(_this2.maskOptions, value);
_this2.setInputValue(value);
value = (0, _string.formatValue)(_this3.maskOptions, value);
if (typeof _this2.props.onChange === 'function') {
_this2.props.onChange(event);
}
_this3.setInputValue(value);
if (_this2.isWindowsPhoneBrowser) {
(0, _defer2.default)(function () {
_this2.setSelection(cursorPos, 0);
});
} else {
_this2.setCursorPos(cursorPos);
if (typeof _this3.props.onChange === 'function') {
_this3.props.onChange(event);
}
if (_this3.isWindowsPhoneBrowser) {
(0, _defer.default)(function () {
_this3.setSelection(cursorPos, 0);
});
} else {
_this3.setCursorPos(cursorPos);
}
}
};
});
Object.defineProperty(this, "onFocus", {
configurable: true,
enumerable: true,
writable: true,
value: function value(event) {
_this3.focused = true;
this.onFocus = function (event) {
_this2.focused = true;
if (_this3.maskOptions.mask) {
if (!_this3.value) {
var prefix = _this3.maskOptions.prefix;
var value = (0, _string.formatValue)(_this3.maskOptions, prefix);
var inputValue = (0, _string.formatValue)(_this3.maskOptions, value); // do not use this.getInputValue and this.setInputValue as this.input
// can be undefined at this moment if autoFocus attribute is set
if (_this2.maskOptions.mask) {
if (!_this2.value) {
var prefix = _this2.maskOptions.prefix;
var value = (0, _string.formatValue)(_this2.maskOptions, prefix);
var inputValue = (0, _string.formatValue)(_this2.maskOptions, value);
var isInputValueChanged = inputValue !== event.target.value;
// do not use this.getInputValue and this.setInputValue as this.input
// can be undefined at this moment if autoFocus attribute is set
var isInputValueChanged = inputValue !== event.target.value;
if (isInputValueChanged) {
event.target.value = inputValue;
}
if (isInputValueChanged) {
event.target.value = inputValue;
}
_this3.value = inputValue;
_this2.value = inputValue;
if (isInputValueChanged && typeof _this3.props.onChange === 'function') {
_this3.props.onChange(event);
}
if (isInputValueChanged && typeof _this2.props.onChange === 'function') {
_this2.props.onChange(event);
_this3.setCursorToEnd();
} else if ((0, _string.getFilledLength)(_this3.maskOptions, _this3.value) < _this3.maskOptions.mask.length) {
_this3.setCursorToEnd();
}
}
_this2.setCursorToEnd();
} else if ((0, _string.getFilledLength)(_this2.maskOptions, _this2.value) < _this2.maskOptions.mask.length) {
_this2.setCursorToEnd();
if (typeof _this3.props.onFocus === 'function') {
_this3.props.onFocus(event);
}
}
});
Object.defineProperty(this, "onBlur", {
configurable: true,
enumerable: true,
writable: true,
value: function value(event) {
_this3.focused = false;
if (typeof _this2.props.onFocus === 'function') {
_this2.props.onFocus(event);
}
};
if (_this3.maskOptions.mask && !_this3.props.alwaysShowMask && (0, _string.isEmpty)(_this3.maskOptions, _this3.value)) {
var inputValue = '';
this.onBlur = function (event) {
_this2.focused = false;
var isInputValueChanged = inputValue !== _this3.getInputValue();
if (_this2.maskOptions.mask && !_this2.props.alwaysShowMask && (0, _string.isEmpty)(_this2.maskOptions, _this2.value)) {
var inputValue = '';
var isInputValueChanged = inputValue !== _this2.getInputValue();
if (isInputValueChanged) {
_this3.setInputValue(inputValue);
}
if (isInputValueChanged) {
_this2.setInputValue(inputValue);
if (isInputValueChanged && typeof _this3.props.onChange === 'function') {
_this3.props.onChange(event);
}
}
if (isInputValueChanged && typeof _this2.props.onChange === 'function') {
_this2.props.onChange(event);
if (typeof _this3.props.onBlur === 'function') {
_this3.props.onBlur(event);
}
}
});
Object.defineProperty(this, "onMouseDown", {
configurable: true,
enumerable: true,
writable: true,
value: function value(event) {
// tiny unintentional mouse movements can break cursor
// position on focus, so we have to restore it in that case
//
// https://github.com/sanniassin/react-input-mask/issues/108
if (!_this3.focused && document.addEventListener) {
_this3.mouseDownX = event.clientX;
_this3.mouseDownY = event.clientY;
_this3.mouseDownTime = new Date().getTime();
if (typeof _this2.props.onBlur === 'function') {
_this2.props.onBlur(event);
}
};
var mouseUpHandler = function mouseUpHandler(mouseUpEvent) {
document.removeEventListener('mouseup', mouseUpHandler);
this.onPaste = function (event) {
if (typeof _this2.props.onPaste === 'function') {
_this2.props.onPaste(event);
}
if (!_this3.focused) {
return;
}
if (_this2.isAndroidBrowser && !event.defaultPrevented) {
_this2.paste = {
value: _this2.getInputValue(),
selection: _this2.getSelection()
};
_this2.setInputValue('');
}
};
var deltaX = Math.abs(mouseUpEvent.clientX - _this3.mouseDownX);
var deltaY = Math.abs(mouseUpEvent.clientY - _this3.mouseDownY);
var axisDelta = Math.max(deltaX, deltaY);
this.pasteText = function (value, text, selection, event) {
var cursorPos = selection.start;
if (selection.length) {
value = (0, _string.clearRange)(_this2.maskOptions, value, cursorPos, selection.length);
var timeDelta = new Date().getTime() - _this3.mouseDownTime;
if (axisDelta <= 10 && timeDelta <= 200 || axisDelta <= 5 && timeDelta <= 300) {
_this3.setCursorToEnd();
}
};
document.addEventListener('mouseup', mouseUpHandler);
}
if (typeof _this3.props.onMouseDown === 'function') {
_this3.props.onMouseDown(event);
}
}
var textLen = (0, _string.getInsertStringLength)(_this2.maskOptions, value, text, cursorPos);
value = (0, _string.insertString)(_this2.maskOptions, value, text, cursorPos);
cursorPos += textLen;
cursorPos = _this2.getRightEditablePos(cursorPos) || cursorPos;
});
Object.defineProperty(this, "onPaste", {
configurable: true,
enumerable: true,
writable: true,
value: function value(event) {
if (typeof _this3.props.onPaste === 'function') {
_this3.props.onPaste(event);
} // we need raw pasted text, but event.clipboardData
// may not work in Android browser, so we clean input
// to get raw text in onChange handler
if (value !== _this2.getInputValue()) {
_this2.setInputValue(value);
if (event && typeof _this2.props.onChange === 'function') {
_this2.props.onChange(event);
if (!event.defaultPrevented) {
_this3.beforePasteState = {
value: _this3.getInputValue(),
selection: _this3.getSelection()
};
_this3.setInputValue('');
}
}
});
Object.defineProperty(this, "pasteText", {
configurable: true,
enumerable: true,
writable: true,
value: function value(_value3, text, selection, event) {
var cursorPos = selection.start;
_this2.setCursorPos(cursorPos);
};
if (selection.length) {
_value3 = (0, _string.clearRange)(_this3.maskOptions, _value3, cursorPos, selection.length);
}
this.render = function () {
var _props = _this2.props,
mask = _props.mask,
alwaysShowMask = _props.alwaysShowMask,
maskChar = _props.maskChar,
formatChars = _props.formatChars,
props = _objectWithoutProperties(_props, ['mask', 'alwaysShowMask', 'maskChar', 'formatChars']);
var textLen = (0, _string.getInsertStringLength)(_this3.maskOptions, _value3, text, cursorPos);
_value3 = (0, _string.insertString)(_this3.maskOptions, _value3, text, cursorPos);
cursorPos += textLen;
cursorPos = _this3.getRightEditablePos(cursorPos) || cursorPos;
if (_this2.maskOptions.mask) {
if (!props.disabled && !props.readOnly) {
var handlersKeys = ['onChange', 'onKeyDown', 'onPaste'];
handlersKeys.forEach(function (key) {
props[key] = _this2[key];
});
_this3.setInputValue(_value3);
if (event && typeof _this3.props.onChange === 'function') {
_this3.props.onChange(event);
}
if (props.value != null) {
props.value = _this2.value;
}
_this3.setCursorPos(cursorPos);
}
return _react2.default.createElement('input', _extends({ ref: function ref(_ref) {
return _this2.input = _ref;
} }, props, { onFocus: _this2.onFocus, onBlur: _this2.onBlur }));
};
});
};
exports.default = InputElement;
module.exports = exports['default'];
var _default = InputElement;
exports.default = _default;
module.exports = exports["default"];
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.__esModule = true;
exports.default = _default;
exports.default = function (fn) {
var defer = window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || function () {
return setTimeout(fn, 0);
};
function _default(fn) {
var defer = window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || function () {
return setTimeout(fn, 0);
};
return defer(fn);
};
return defer(fn);
}
module.exports = exports["default"];

@@ -1,6 +0,4 @@

'use strict';
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.__esModule = true;
exports.isAndroidBrowser = isAndroidBrowser;

@@ -10,2 +8,3 @@ exports.isWindowsPhoneBrowser = isWindowsPhoneBrowser;

exports.isIOS = isIOS;
function isAndroidBrowser() {

@@ -12,0 +11,0 @@ var windows = new RegExp('windows', 'i');

@@ -1,11 +0,13 @@

'use strict';
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.__esModule = true;
exports.default = _default;
exports.default = function (mask, maskChar, charsRules) {
var _constants = require("../constants");
function _default(mask, maskChar, charsRules) {
if (maskChar === undefined) {
maskChar = _constants.defaultMaskChar;
}
if (charsRules == null) {

@@ -25,2 +27,3 @@ charsRules = _constants.defaultCharsRules;

}
var str = '';

@@ -31,3 +34,2 @@ var prefix = '';

var lastEditablePos = null;
mask.split('').forEach(function (character) {

@@ -39,2 +41,3 @@ if (!isPermanent && character === '\\') {

permanents.push(str.length);
if (str.length === permanents.length - 1) {

@@ -46,2 +49,3 @@ prefix += character;

}
str += character;

@@ -51,3 +55,2 @@ isPermanent = false;

});
return {

@@ -61,6 +64,4 @@ maskChar: maskChar,

};
};
}
var _constants = require('../constants');
module.exports = exports['default'];
module.exports = exports["default"];

@@ -1,6 +0,4 @@

'use strict';
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.__esModule = true;
exports.isPermanentChar = isPermanentChar;

@@ -15,2 +13,3 @@ exports.isAllowedChar = isAllowedChar;

exports.getInsertStringLength = getInsertStringLength;
function isPermanentChar(maskOptions, pos) {

@@ -24,3 +23,2 @@ return maskOptions.permanents.indexOf(pos) !== -1;

if (!character) {

@@ -36,3 +34,2 @@ return false;

var charRule = charsRules[ruleChar];
return new RegExp(charRule).test(character);

@@ -51,3 +48,2 @@ }

if (!maskChar) {

@@ -57,2 +53,3 @@ while (value.length > prefix.length && isPermanentChar(maskOptions, value.length - 1)) {

}
return value.length;

@@ -62,5 +59,7 @@ }

var filledLength = prefix.length;
for (var i = value.length; i >= prefix.length; i--) {
var character = value[i];
var isEnteredCharacter = !isPermanentChar(maskOptions, i) && isAllowedChar(maskOptions, i, character);
if (isEnteredCharacter) {

@@ -84,3 +83,2 @@ filledLength = i + 1;

if (!maskChar) {

@@ -118,3 +116,2 @@ value = insertString(maskOptions, '', value, 0);

prefix = maskOptions.prefix;
var arrayValue = value.split('');

@@ -126,3 +123,2 @@

value = arrayValue.join('');
return formatValue(maskOptions, value);

@@ -135,5 +131,7 @@ }

}
if (isPermanentChar(maskOptions, i)) {
return mask[i];
}
return maskChar;

@@ -147,3 +145,2 @@ }).join('');

prefix = maskOptions.prefix;
var arrayInsertStr = insertStr.split('');

@@ -155,2 +152,3 @@ var isInputFilled = isFilled(maskOptions, value);

};
var isUsableCharacter = function isUsableCharacter(character, pos) {

@@ -174,5 +172,4 @@ return !maskChar || !isPermanentChar(maskOptions, pos) || character !== maskChar;

insertPos++;
insertPos++; // stop iteration if maximum value length reached
// stop iteration if maximum value length reached
if (insertPos >= mask.length) {

@@ -184,2 +181,3 @@ return false;

var isAllowed = isAllowedChar(maskOptions, insertPos, insertCharacter) || insertCharacter === maskChar;
if (!isAllowed) {

@@ -200,8 +198,6 @@ return true;

insertPos++;
insertPos++; // stop iteration if maximum value length reached
// stop iteration if maximum value length reached
return insertPos < mask.length;
});
return value;

@@ -213,3 +209,2 @@ }

maskChar = maskOptions.maskChar;
var arrayInsertStr = insertStr.split('');

@@ -224,5 +219,4 @@ var initialInsertPos = insertPos;

while (!isUsablePosition(insertPos, insertCharacter)) {
insertPos++;
insertPos++; // stop iteration if maximum value length reached
// stop iteration if maximum value length reached
if (insertPos >= mask.length) {

@@ -237,9 +231,8 @@ return false;

insertPos++;
}
} // stop iteration if maximum value length reached
// stop iteration if maximum value length reached
return insertPos < mask.length;
});
return insertPos - initialInsertPos;
}
{
"name": "react-input-mask",
"description": "Masked input component for React",
"version": "1.0.7",
"version": "1.1.0",
"homepage": "https://github.com/sanniassin/react-input-mask",

@@ -19,40 +19,38 @@ "license": "MIT",

"devDependencies": {
"babel-cli": "^6.24.1",
"@babel/cli": "^7.0.0-beta.34",
"@babel/core": "^7.0.0-beta.34",
"@babel/polyfill": "^7.0.0-beta.34",
"@babel/preset-es2015": "^7.0.0-beta.34",
"@babel/preset-react": "^7.0.0-beta.34",
"@babel/preset-stage-2": "^7.0.0-beta.34",
"@babel/register": "^7.0.0-beta.34",
"babel-eslint": "^7.2.3",
"babel-loader": "^7.1.1",
"babel-loader": "^8.0.0-beta.0",
"babel-plugin-add-module-exports": "^0.2.1",
"babel-plugin-transform-es3-member-expression-literals": "^6.22.0",
"babel-plugin-transform-es3-property-literals": "^6.22.0",
"babel-polyfill": "^6.23.0",
"babel-preset-es2015": "^6.24.1",
"babel-preset-react": "^6.24.1",
"babel-preset-stage-2": "^6.24.1",
"babelify": "^7.3.0",
"browserify": "^14.3.0",
"chai": "^4.1.0",
"chai": "^4.1.2",
"console-polyfill": "^0.3.0",
"cross-env": "^5.0.1",
"cross-env": "^5.1.1",
"es3ify-loader": "^0.2.0",
"eslint": "^3.19.0",
"eslint-config-airbnb": "^15.0.2",
"eslint-plugin-import": "^2.7.0",
"eslint-config-airbnb": "^15.1.0",
"eslint-plugin-import": "^2.8.0",
"eslint-plugin-jsx-a11y": "^5.1.1",
"eslint-plugin-react": "^7.1.0",
"html-webpack-plugin": "^2.29.0",
"karma": "^1.6.0",
"karma-browserify": "^5.0.5",
"eslint-plugin-react": "^7.5.1",
"html-webpack-plugin": "^2.30.1",
"karma": "^1.7.1",
"karma-browserstack-launcher": "^1.3.0",
"karma-chrome-launcher": "^2.2.0",
"karma-mocha": "^1.3.0",
"karma-phantomjs-launcher": "^1.0.0",
"mocha": "^3.4.2",
"phantomjs-prebuilt": "^2.1.7",
"react": "^15.6.1",
"react-dom": "^15.6.1",
"rollup": "^0.45.2",
"rollup-plugin-babel": "^2.7.1",
"karma-webpack": "^2.0.6",
"mocha": "^4.0.1",
"puppeteer": "^0.13.0",
"react": "^16.2.0",
"react-dom": "^16.2.0",
"rollup": "^0.52.1",
"rollup-plugin-babel": "^4.0.0-beta.0",
"rollup-plugin-node-resolve": "^3.0.0",
"rollup-plugin-replace": "^1.1.1",
"rollup-plugin-replace": "^2.0.0",
"rollup-plugin-uglify": "^2.0.1",
"watchify": "^3.9.0",
"webpack": "^3.2.0",
"webpack-dev-server": "^2.5.1"
"webpack": "^3.10.0",
"webpack-dev-server": "^2.9.7"
},

@@ -70,3 +68,3 @@ "main": "lib/index.js",

"build": "npm run build:commonjs && npm run build:es && npm run build:umd && npm run build:umd:min",
"build:commonjs": "cross-env BABEL_ENV=commonjs babel src --out-dir lib --plugins=add-module-exports",
"build:commonjs": "cross-env BABEL_ENV=commonjs babel src --out-dir lib",
"build:es": "cross-env BABEL_ENV=es babel src --out-dir es",

@@ -79,5 +77,5 @@ "build:umd": "cross-env BABEL_ENV=es NODE_ENV=development rollup -c -i src/index.js -o dist/react-input-mask.js",

"test": "npm run build && npm run test:input && npm run test:server-render && npm run test:build",
"test:input": "cross-env BABEL_ENV=commonjs karma start",
"test:server-render": "cross-env BABEL_ENV=commonjs mocha --compilers js:babel-core/register ./tests/server-render",
"test:build": "cross-env BABEL_ENV=commonjs mocha --compilers js:babel-core/register ./tests/build"
"test:input": "cross-env BABEL_ENV=tests karma start",
"test:server-render": "cross-env BABEL_ENV=tests mocha --require @babel/register ./tests/server-render",
"test:build": "cross-env BABEL_ENV=tests mocha --require @babel/register ./tests/build"
},

@@ -87,3 +85,4 @@ "repository": {

"url": "https://github.com/sanniassin/react-input-mask.git"
}
},
"dependencies": {}
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc