Socket
Socket
Sign inDemoInstall

react-input-mask

Package Overview
Dependencies
3
Maintainers
1
Versions
90
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 2.0.0-beta.1 to 2.0.0-beta.2

330

dist/react-input-mask.js

@@ -11,17 +11,2 @@ (function (global, factory) {

function _defineProperty(obj, key, value) {
if (key in obj) {
Object.defineProperty(obj, key, {
value: value,
enumerable: true,
configurable: true,
writable: true
});
} else {
obj[key] = value;
}
return obj;
}
function _extends() {

@@ -45,21 +30,2 @@ _extends = Object.assign || function (target) {

function _objectSpread(target) {
for (var i = 1; i < arguments.length; i++) {
var source = arguments[i] != null ? arguments[i] : {};
var ownKeys = Object.keys(source);
if (typeof Object.getOwnPropertySymbols === 'function') {
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) {
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
}));
}
ownKeys.forEach(function (key) {
_defineProperty(target, key, source[key]);
});
}
return target;
}
function _inheritsLoose(subClass, superClass) {

@@ -162,3 +128,3 @@ _defaults2(subClass.prototype, superClass && superClass.prototype);

prefix: null,
lastEditablePos: null,
lastEditablePosition: null,
permanents: []

@@ -172,3 +138,3 @@ };

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

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

} else {
lastEditablePos = str.length + 1;
lastEditablePosition = str.length + 1;
}

@@ -198,3 +164,3 @@

mask: str,
lastEditablePos: lastEditablePos,
lastEditablePosition: lastEditablePosition,
permanents: permanents

@@ -331,3 +297,3 @@ };

}
function insertString(maskOptions, value, insertStr, insertPos) {
function insertString(maskOptions, value, insertStr, insertPosition) {
var mask = maskOptions.mask,

@@ -347,19 +313,19 @@ maskChar = maskOptions.maskChar,

if (!maskChar && insertPos > value.length) {
value += mask.slice(value.length, insertPos);
if (!maskChar && insertPosition > value.length) {
value += mask.slice(value.length, insertPosition);
}
arrayInsertStr.every(function (insertCharacter) {
while (!isUsablePosition(insertPos, insertCharacter)) {
if (insertPos >= value.length) {
value += mask[insertPos];
while (!isUsablePosition(insertPosition, insertCharacter)) {
if (insertPosition >= value.length) {
value += mask[insertPosition];
}
if (!isUsableCharacter(insertCharacter, insertPos)) {
if (!isUsableCharacter(insertCharacter, insertPosition)) {
return true;
}
insertPos++; // stop iteration if maximum value length reached
insertPosition++; // stop iteration if maximum value length reached
if (insertPos >= mask.length) {
if (insertPosition >= mask.length) {
return false;

@@ -369,3 +335,3 @@ }

var isAllowed = isAllowedChar(maskOptions, insertPos, insertCharacter) || insertCharacter === maskChar;
var isAllowed = isAllowedChar(maskOptions, insertPosition, insertCharacter) || insertCharacter === maskChar;

@@ -376,7 +342,7 @@ if (!isAllowed) {

if (insertPos < value.length) {
if (maskChar || isInputFilled || insertPos < prefix.length) {
value = value.slice(0, insertPos) + insertCharacter + value.slice(insertPos + 1);
if (insertPosition < value.length) {
if (maskChar || isInputFilled || insertPosition < prefix.length) {
value = value.slice(0, insertPosition) + insertCharacter + value.slice(insertPosition + 1);
} else {
value = value.slice(0, insertPos) + insertCharacter + value.slice(insertPos);
value = value.slice(0, insertPosition) + insertCharacter + value.slice(insertPosition);
value = formatValue(maskOptions, value);

@@ -388,13 +354,13 @@ }

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

@@ -406,6 +372,6 @@ var isUsablePosition = function isUsablePosition(pos, character) {

arrayInsertStr.every(function (insertCharacter) {
while (!isUsablePosition(insertPos, insertCharacter)) {
insertPos++; // stop iteration if maximum value length reached
while (!isUsablePosition(insertPosition, insertCharacter)) {
insertPosition++; // stop iteration if maximum value length reached
if (insertPos >= mask.length) {
if (insertPosition >= mask.length) {
return false;

@@ -415,14 +381,14 @@ }

var isAllowed = isAllowedChar(maskOptions, insertPos, insertCharacter) || insertCharacter === maskChar;
var isAllowed = isAllowedChar(maskOptions, insertPosition, insertCharacter) || insertCharacter === maskChar;
if (isAllowed) {
insertPos++;
insertPosition++;
} // stop iteration if maximum value length reached
return insertPos < mask.length;
return insertPosition < mask.length;
});
return insertPos - initialInsertPos;
return insertPosition - initialInsertPosition;
}
function getLeftEditablePos(maskOptions, pos) {
function getLeftEditablePosition(maskOptions, pos) {
for (var i = pos; i >= 0; --i) {

@@ -436,3 +402,3 @@ if (!isPermanentChar(maskOptions, i)) {

}
function getRightEditablePos(maskOptions, pos) {
function getRightEditablePosition(maskOptions, pos) {
var mask = maskOptions.mask;

@@ -460,13 +426,28 @@

function defer (fn, timeoutDelay) {
if (timeoutDelay === void 0) {
timeoutDelay = 0;
function getRequestAnimationFrame() {
return window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame;
}
function getCancelAnimationFrame() {
return window.cancelAnimationFrame || window.webkitCancelRequestAnimationFrame || window.webkitCancelAnimationFrame || window.mozCancelAnimationFrame;
}
function defer(fn) {
var deferFn;
var hasCancelAnimationFrame = !!getCancelAnimationFrame();
if (hasCancelAnimationFrame) {
deferFn = getRequestAnimationFrame();
} else {
deferFn = function deferFn() {
return setTimeout(fn, 1000 / 60);
};
}
var defer = window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || function () {
return setTimeout(fn, timeoutDelay);
};
return defer(fn);
return deferFn(fn);
}
function cancelDefer(deferId) {
var cancelFn = getCancelAnimationFrame() || clearTimeout;
cancelFn(deferId);
}

@@ -483,17 +464,23 @@ var InputElement =

_this.previousSelection = null;
_this.selectionDeferId = null;
_this.saveSelectionLoopDeferId = null;
_this.saveSelectionLoop = function () {
if (!_this.mounted || !_this.maskOptions.mask || !_this.focused || _this.saveSelectionLoopRunning) {
return;
}
_this.saveSelectionLoopRunning = true;
_this.previousSelection = _this.getSelection();
defer(function () {
_this.saveSelectionLoopRunning = false;
_this.saveSelectionLoopDeferId = defer(_this.saveSelectionLoop);
};
_this.runSaveSelectionLoop = function () {
if (_this.saveSelectionLoopDeferId === null) {
_this.saveSelectionLoop();
}, 1000 / 60);
}
};
_this.stopSaveSelectionLoop = function () {
if (_this.saveSelectionLoopDeferId !== null) {
cancelDefer(_this.saveSelectionLoopDeferId);
_this.saveSelectionLoopDeferId = null;
}
};
_this.getInputDOMNode = function () {

@@ -536,11 +523,15 @@ var input = _this.input;

_this.setCursorToEnd = function () {
var filledLen = getFilledLength(_this.maskOptions, _this.value);
var pos = getRightEditablePos(_this.maskOptions, filledLen);
var filledLength = getFilledLength(_this.maskOptions, _this.value);
var pos = getRightEditablePosition(_this.maskOptions, filledLength);
if (pos !== null) {
_this.setCursorPos(pos);
_this.setCursorPosition(pos);
}
};
_this.setSelection = function (start, end) {
_this.setSelection = function (start, end, options) {
if (options === void 0) {
options = {};
}
var input = _this.getInputDOMNode();

@@ -552,5 +543,18 @@

setInputSelection(input, start, end);
defer(function () {
var _options = options,
deferred = _options.deferred;
if (!deferred) {
setInputSelection(input, start, end);
}
if (_this.selectionDeferId !== null) {
cancelDefer(_this.selectionDeferId);
} // deferred selection update is required for pre-Lollipop Android browser,
// but for consistent behavior we do it for all browsers
_this.selectionDeferId = defer(function () {
_this.selectionDeferId = null;
setInputSelection(input, start, end);
});

@@ -570,7 +574,7 @@ _this.previousSelection = {

_this.getCursorPos = function () {
_this.getCursorPosition = function () {
return _this.getSelection().start;
};
_this.setCursorPos = function (pos) {
_this.setCursorPosition = function (pos) {
_this.setSelection(pos, pos);

@@ -622,8 +626,14 @@ };

prefix = _this$maskOptions2.prefix,
lastEditablePos = _this$maskOptions2.lastEditablePos;
lastEditablePosition = _this$maskOptions2.lastEditablePosition;
var value = _this.getInputValue();
var newValue = _this.getInputValue();
var newValue = value;
var previousValue = _this.value; // autofill replaces entire value, ignore old one
var previousValue = _this.value;
var enteredString = '';
var selection = _this.getSelection();
var cursorPosition = selection.end;
var formattedEnteredStringLength = 0;
var removedLength; // autofill replaces entire value, ignore old one
// https://github.com/sanniassin/react-input-mask/issues/113

@@ -638,20 +648,13 @@

};
}
} // set value and selection as if we haven't
// cleared input in onPaste handler
var enteredString = '';
var selection = _this.getSelection();
var cursorPos = selection.end;
selection.start = selection.end;
selection.length = 0; // set value and selection as if we haven't
// cleared input in onPaste handler
if (beforePasteState) {
previousSelection = beforePasteState.selection;
previousValue = beforePasteState.value;
cursorPos = previousSelection.start + newValue.length;
cursorPosition = previousSelection.start + newValue.length;
selection = {
start: cursorPos,
end: cursorPos,
start: cursorPosition,
end: cursorPosition,
length: 0

@@ -663,15 +666,15 @@ };

var formattedEnteredStringLen = 0;
var removedLen = previousSelection.length;
cursorPos = Math.min(previousSelection.start, selection.start);
cursorPosition = Math.min(previousSelection.start, selection.start);
if (selection.end > previousSelection.start) {
enteredString = newValue.slice(previousSelection.start, selection.end);
formattedEnteredStringLen = getInsertStringLength(_this.maskOptions, previousValue, enteredString, cursorPos);
formattedEnteredStringLength = getInsertStringLength(_this.maskOptions, previousValue, enteredString, cursorPosition);
if (!formattedEnteredStringLen) {
removedLen = 0;
if (!formattedEnteredStringLength) {
removedLength = 0;
} else {
removedLength = previousSelection.length;
}
} else if (newValue.length < previousValue.length) {
removedLen = previousValue.length - newValue.length;
removedLength = previousValue.length - newValue.length;
}

@@ -681,20 +684,20 @@

if (removedLen) {
if (removedLen === 1 && !previousSelection.length) {
if (removedLength) {
if (removedLength === 1 && !previousSelection.length) {
var deleteFromRight = previousSelection.start === selection.start;
cursorPos = deleteFromRight ? getRightEditablePos(_this.maskOptions, selection.start) : getLeftEditablePos(_this.maskOptions, selection.start);
cursorPosition = deleteFromRight ? getRightEditablePosition(_this.maskOptions, selection.start) : getLeftEditablePosition(_this.maskOptions, selection.start);
}
newValue = clearRange(_this.maskOptions, newValue, cursorPos, removedLen);
newValue = clearRange(_this.maskOptions, newValue, cursorPosition, removedLength);
}
newValue = insertString(_this.maskOptions, newValue, enteredString, cursorPos);
cursorPos = cursorPos + formattedEnteredStringLen;
newValue = insertString(_this.maskOptions, newValue, enteredString, cursorPosition);
cursorPosition = cursorPosition + formattedEnteredStringLength;
if (cursorPos >= mask.length) {
cursorPos = mask.length;
} else if (cursorPos < prefix.length && !formattedEnteredStringLen) {
cursorPos = prefix.length;
} else if (cursorPos >= prefix.length && cursorPos < lastEditablePos && formattedEnteredStringLen) {
cursorPos = getRightEditablePos(_this.maskOptions, cursorPos);
if (cursorPosition >= mask.length) {
cursorPosition = mask.length;
} else if (cursorPosition < prefix.length && !formattedEnteredStringLength) {
cursorPosition = prefix.length;
} else if (cursorPosition >= prefix.length && cursorPosition < lastEditablePosition && formattedEnteredStringLength) {
cursorPosition = getRightEditablePosition(_this.maskOptions, cursorPosition);
}

@@ -709,4 +712,4 @@

var newSelection = {
start: cursorPos,
end: cursorPos
start: cursorPosition,
end: cursorPosition
};

@@ -733,13 +736,4 @@

if (_this.isWindowsPhoneBrowser) {
defer(function () {
if (!_this.mounted || !_this.isFocused()) {
return;
}
var input = _this.getInputDOMNode();
setInputSelection(input, newSelection.start, newSelection.end);
_this.previousSelection = _objectSpread({}, newSelection, {
length: newSelection.end - newSelection.start
});
_this.setSelection(newSelection.start, newSelection.end, {
deferred: true
});

@@ -756,7 +750,6 @@ } else {

prefix = _this$maskOptions3.prefix;
_this.focused = true;
_this.focused = true; // if autoFocus is set, onFocus triggers before componentDidMount
if (!_this.input) {
_this.input = event.target;
}
_this.input = event.target;
_this.mounted = true;

@@ -767,7 +760,7 @@ if (mask) {

var newValue = formatValue(_this.maskOptions, emptyValue);
var filledLen = getFilledLength(_this.maskOptions, newValue);
var cursorPos = getRightEditablePos(_this.maskOptions, filledLen);
var filledLength = getFilledLength(_this.maskOptions, newValue);
var cursorPosition = getRightEditablePosition(_this.maskOptions, filledLength);
var newSelection = {
start: cursorPos,
end: cursorPos
start: cursorPosition,
end: cursorPosition
};

@@ -807,3 +800,3 @@

_this.saveSelectionLoop();
_this.runSaveSelectionLoop();

@@ -818,2 +811,5 @@ if (isFunction(_this.props.onFocus)) {

var mask = _this.maskOptions.mask;
_this.stopSaveSelectionLoop();
_this.previousSelection = null;

@@ -963,8 +959,10 @@ _this.focused = false;

if (!this.maskOptions.mask) {
this.backspaceOrDeleteRemoval = null;
this.stopSaveSelectionLoop();
this.previousSelection = null;
return;
} else if (!oldMaskOptions.mask && this.isFocused()) {
this.runSaveSelectionLoop();
}
var cursorPos = previousSelection ? previousSelection.start : null;
var cursorPosition = previousSelection ? previousSelection.start : null;
var isMaskChanged = this.maskOptions.mask && this.maskOptions.mask !== oldMaskOptions.mask;

@@ -980,17 +978,13 @@ var showEmpty = this.props.alwaysShowMask || this.isFocused();

newValue = formatValue(this.maskOptions, newValue);
}
if (isMaskChanged) {
var filledLen = getFilledLength(this.maskOptions, newValue);
if (isMaskChanged) {
var filledLength = getFilledLength(this.maskOptions, newValue);
if (cursorPos === null || filledLen < cursorPos) {
if (isFilled(this.maskOptions, newValue)) {
cursorPos = filledLen;
} else {
cursorPos = getRightEditablePos(this.maskOptions, filledLen);
}
if (cursorPosition === null || filledLength < cursorPosition) {
if (isFilled(this.maskOptions, newValue)) {
cursorPosition = filledLength;
} else {
cursorPosition = getRightEditablePosition(this.maskOptions, filledLength);
}
if (!oldMaskOptions.mask) {
this.saveSelectionLoop();
}
}

@@ -1004,4 +998,4 @@ }

var newSelection = {
start: cursorPos,
end: cursorPos
start: cursorPosition,
end: cursorPosition
};

@@ -1028,4 +1022,8 @@

var isSelectionChanged = !previousSelection || previousSelection.start !== newSelection.start || previousSelection.end !== newSelection.end;
var isSelectionChanged = false;
if (newSelection.start != null && newSelection.end != null) {
isSelectionChanged = !previousSelection || previousSelection.start !== newSelection.start || previousSelection.end !== newSelection.end;
}
if (isSelectionChanged) {

@@ -1038,2 +1036,8 @@ this.setSelection(newSelection.start, newSelection.end);

this.mounted = false;
if (this.selectionDeferId !== null) {
cancelDefer(this.selectionDeferId);
}
this.stopSaveSelectionLoop();
};

@@ -1040,0 +1044,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(e,t){for(var n=Object.getOwnPropertyNames(t),s=0;s<n.length;s++){var a=n[s],o=Object.getOwnPropertyDescriptor(t,a);o&&o.configurable&&e[a]===undefined&&Object.defineProperty(e,a,o)}return e}function n(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function s(){return(s=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}).apply(this,arguments)}function a(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function o(e,t,n){if("selectionStart"in e&&"selectionEnd"in e)e.selectionStart=t,e.selectionEnd=n;else{var s=e.createTextRange();s.collapse(!0),s.moveStart("character",t),s.moveEnd("character",n-t),s.select()}}var r={9:"[0-9]",a:"[A-Za-z]","*":"[A-Za-z0-9]"},i="_";function u(e,t,n){if(t===undefined&&(t=i),null==n&&(n=r),!e||"string"!=typeof e)return{maskChar:t,formatChars:n,mask:null,prefix:null,lastEditablePos:null,permanents:[]};var s="",a="",o=[],u=!1,l=null;return e.split("").forEach(function(e){u||"\\"!==e?(u||!n[e]?(o.push(s.length),s.length===o.length-1&&(a+=e)):l=s.length+1,s+=e,u=!1):u=!0}),{maskChar:t,formatChars:n,prefix:a,mask:s,lastEditablePos:l,permanents:o}}function l(e,t){return-1!==e.permanents.indexOf(t)}function p(e,t,n){var s=e.mask,a=e.formatChars;if(!n)return!1;if(l(e,t))return s[t]===n;var o=a[s[t]];return new RegExp(o).test(n)}function c(e,t){return t.split("").every(function(t,n){return l(e,n)||!p(e,n,t)})}function h(e,t){var n=e.maskChar,s=e.prefix;if(!n){for(;t.length>s.length&&l(e,t.length-1);)t=t.slice(0,t.length-1);return t.length}for(var a=s.length,o=t.length;o>=s.length;o--){var r=t[o];if(!l(e,o)&&p(e,o,r)){a=o+1;break}}return a}function f(e,t){return h(e,t)===e.mask.length}function m(e,t){var n=e.maskChar,s=e.mask,a=e.prefix;if(!n){for((t=v(e,"",t,0)).length<a.length&&(t=a);t.length<s.length&&l(e,t.length);)t+=s[t.length];return t}if(t)return v(e,m(e,""),t,0);for(var o=0;o<s.length;o++)l(e,o)?t+=s[o]:t+=n;return t}function v(e,t,n,s){var a=e.mask,o=e.maskChar,r=e.prefix,i=n.split(""),u=f(e,t),c=function(t,n){return!o||!l(e,n)||t!==o};return!o&&s>t.length&&(t+=a.slice(t.length,s)),i.every(function(n){for(;h=n,l(e,i=s)&&h!==a[i];){if(s>=t.length&&(t+=a[s]),!c(n,s))return!0;if(++s>=a.length)return!1}var i,h;return!p(e,s,n)&&n!==o||(s<t.length?o||u||s<r.length?t=t.slice(0,s)+n+t.slice(s+1):(t=t.slice(0,s)+n+t.slice(s),t=m(e,t)):o||(t+=n),++s<a.length)}),t}function g(e,t){for(var n=e.mask,s=t;s<n.length;++s)if(!l(e,s))return s;return null}function d(e){return e||0===e?e+"":""}function k(e){return"function"==typeof e}function O(e,t){return void 0===t&&(t=0),(window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||function(){return setTimeout(e,t)})(e)}return function(r){function i(t){var s;(s=r.call(this,t)||this).focused=!1,s.mounted=!1,s.previousSelection=null,s.saveSelectionLoop=function(){s.mounted&&s.maskOptions.mask&&s.focused&&!s.saveSelectionLoopRunning&&(s.saveSelectionLoopRunning=!0,s.previousSelection=s.getSelection(),O(function(){s.saveSelectionLoopRunning=!1,s.saveSelectionLoop()},1e3/60))},s.getInputDOMNode=function(){var t,n=s.input;return n?(t=n,("object"==typeof HTMLElement?t instanceof HTMLElement:1===t.nodeType&&"string"==typeof t.nodeName)?n:e.findDOMNode(n)):null},s.getInputValue=function(){var e=s.getInputDOMNode();return e?e.value:null},s.setInputValue=function(e){var t=s.getInputDOMNode();t&&(s.value=e,t.value=e)},s.setCursorToEnd=function(){var e=h(s.maskOptions,s.value),t=g(s.maskOptions,e);null!==t&&s.setCursorPos(t)},s.setSelection=function(e,t){var n=s.getInputDOMNode();n&&(o(n,e,t),O(function(){o(n,e,t)}),s.previousSelection={start:e,end:t,length:Math.abs(t-e)})},s.getSelection=function(){return function(e){var 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}}(s.getInputDOMNode())},s.getCursorPos=function(){return s.getSelection().start},s.setCursorPos=function(e){s.setSelection(e,e)},s.isFocused=function(){return s.focused},s.getModifyMaskedValueConfig=function(){var e=s.maskOptions,t=e.mask,n=e.maskChar,a=e.permanents,o=e.formatChars;return{mask:t,maskChar:n,permanents:a,alwaysShowMask:!!s.props.alwaysShowMask,formatChars:o}},s.isInputAutofilled=function(){var e=s.getInputDOMNode(),t=!1;try{k(e.matches)&&e.matches(":-webkit-autofill")&&(t=!0)}catch(n){}return t},s.onChange=function(e){var t=a(a(s)),r=t.beforePasteState,i=t.previousSelection,u=s.props.beforeMaskedValueChange,c=s.maskOptions,h=c.mask,f=c.prefix,d=c.lastEditablePos,w=s.getInputValue(),y=s.value;s.isInputAutofilled()&&(y=m(s.maskOptions,""),i={start:0,end:0,length:0});var b="",C=s.getSelection(),S=C.end;C.start=C.end,C.length=0,r&&(i=r.selection,y=r.value,C={start:S=i.start+w.length,end:S,length:0},w=y.slice(0,i.start)+w+y.slice(i.end),s.beforePasteState=null);var M=0,V=i.length;if(S=Math.min(i.start,C.start),C.end>i.start?(b=w.slice(i.start,C.end),(M=function(e,t,n,s){var a=e.mask,o=e.maskChar,r=n.split(""),i=s;return r.every(function(t){for(;r=t,l(e,n=s)&&r!==a[n];)if(++s>=a.length)return!1;var n,r;return(p(e,s,t)||t===o)&&s++,s<a.length}),s-i}(s.maskOptions,0,b,S))||(V=0)):w.length<y.length&&(V=y.length-w.length),w=y,V){if(1===V&&!i.length)S=i.start===C.start?g(s.maskOptions,C.start):function(e,t){for(var n=t;n>=0;--n)if(!l(e,n))return n;return null}(s.maskOptions,C.start);w=function(e,t,n,s){var a=n+s,o=e.maskChar,r=e.mask,i=e.prefix,u=t.split("");if(!o){for(var p=a;p<u.length;p++)l(e,p)&&(u[p]="");return n=Math.max(i.length,n),u.splice(n,a-n),t=u.join(""),m(e,t)}return u.map(function(t,s){return s<n||s>=a?t:l(e,s)?r[s]:o}).join("")}(s.maskOptions,w,S,V)}w=v(s.maskOptions,w,b,S),(S+=M)>=h.length?S=h.length:S<f.length&&!M?S=f.length:S>=f.length&&S<d&&M&&(S=g(s.maskOptions,S)),w=m(s.maskOptions,w),b||(b=null);var E={start:S,end:S};if(k(u)){var P=u({value:w,selection:E},{value:y,selection:i},b,s.getModifyMaskedValueConfig());w=P.value,E=P.selection}s.setInputValue(w),k(s.props.onChange)&&s.props.onChange(e),s.isWindowsPhoneBrowser?O(function(){s.mounted&&s.isFocused()&&(o(s.getInputDOMNode(),E.start,E.end),s.previousSelection=function(e){for(var t=1;t<arguments.length;t++){var s=null!=arguments[t]?arguments[t]:{},a=Object.keys(s);"function"==typeof Object.getOwnPropertySymbols&&(a=a.concat(Object.getOwnPropertySymbols(s).filter(function(e){return Object.getOwnPropertyDescriptor(s,e).enumerable}))),a.forEach(function(t){n(e,t,s[t])})}return e}({},E,{length:E.end-E.start}))}):s.setSelection(E.start,E.end)},s.onFocus=function(e){var t=s.props.beforeMaskedValueChange,n=s.maskOptions,a=n.mask,o=n.prefix;if(s.focused=!0,s.input||(s.input=e.target),a)if(s.value)h(s.maskOptions,s.value)<s.maskOptions.mask.length&&s.setCursorToEnd();else{var r=m(s.maskOptions,o),i=m(s.maskOptions,r),u=h(s.maskOptions,i),l=g(s.maskOptions,u),p={start:l,end:l};if(k(t)){var c=t({value:i,selection:p},{value:s.value,selection:null},null,s.getModifyMaskedValueConfig());i=c.value,p=c.selection}var f=i!==e.target.value;f&&(e.target.value=i),s.value=i,f&&k(s.props.onChange)&&s.props.onChange(e),s.setSelection(p.start,p.end)}s.saveSelectionLoop(),k(s.props.onFocus)&&s.props.onFocus(e)},s.onBlur=function(e){var t=s.props.beforeMaskedValueChange,n=s.maskOptions.mask;if(s.previousSelection=null,s.focused=!1,n&&!s.props.alwaysShowMask&&c(s.maskOptions,s.value)){var a="";if(k(t))a=t({value:a,selection:null},{value:s.value,selection:s.previousSelection},null,s.getModifyMaskedValueConfig()).value;var o=a!==s.getInputValue();o&&s.setInputValue(a),o&&k(s.props.onChange)&&s.props.onChange(e)}k(s.props.onBlur)&&s.props.onBlur(e)},s.onMouseDown=function(e){if(!s.focused&&document.addEventListener){s.mouseDownX=e.clientX,s.mouseDownY=e.clientY,s.mouseDownTime=(new Date).getTime();document.addEventListener("mouseup",function t(e){if(document.removeEventListener("mouseup",t),s.focused){var n=Math.abs(e.clientX-s.mouseDownX),a=Math.abs(e.clientY-s.mouseDownY),o=Math.max(n,a),r=(new Date).getTime()-s.mouseDownTime;(o<=10&&r<=200||o<=5&&r<=300)&&s.setCursorToEnd()}})}k(s.props.onMouseDown)&&s.props.onMouseDown(e)},s.onPaste=function(e){k(s.props.onPaste)&&s.props.onPaste(e),e.defaultPrevented||(s.beforePasteState={value:s.getInputValue(),selection:s.getSelection()},s.setInputValue(""))},s.handleRef=function(e){s.input=e,k(s.props.inputRef)&&s.props.inputRef(e)};var i=t.mask,f=t.maskChar,w=t.formatChars,y=t.defaultValue,b=t.value,C=t.alwaysShowMask;return s.hasValue=null!=b,s.maskOptions=u(i,f,w),null==y&&(y=""),null==b&&(b=y),b=d(b),s.maskOptions.mask&&(C||b)&&(b=m(s.maskOptions,b)),s.value=b,s}var w,y,b=i.prototype;return b.componentDidMount=function(){var e,t,n;this.mounted=!0,this.isWindowsPhoneBrowser=(e=new RegExp("windows","i"),t=new RegExp("phone","i"),n=navigator.userAgent,e.test(n)&&t.test(n)),this.maskOptions.mask&&this.getInputValue()!==this.value&&this.setInputValue(this.value),this.props.maxLength&&this.maskOptions.mask&&"object"==typeof console&&console.error&&console.error("react-input-mask: You shouldn't pass maxLength property to the masked input. It breaks masking and unnecessary because length is limited by the mask length.")},b.componentDidUpdate=function(){var e=this.previousSelection,t=this.props.beforeMaskedValueChange,n=this.maskOptions;if(this.hasValue=null!=this.props.value,this.maskOptions=u(this.props.mask,this.props.maskChar,this.props.formatChars),!this.maskOptions.mask)return this.backspaceOrDeleteRemoval=null,void(this.previousSelection=null);var s=e?e.start:null,a=this.maskOptions.mask&&this.maskOptions.mask!==n.mask,o=this.props.alwaysShowMask||this.isFocused(),r=this.hasValue?d(this.props.value):this.value;if(n.mask||this.hasValue||(r=this.getInputValue()),(a||this.maskOptions.mask&&(r||o))&&(r=m(this.maskOptions,r),a)){var i=h(this.maskOptions,r);(null===s||i<s)&&(s=f(this.maskOptions,r)?i:g(this.maskOptions,i)),n.mask||this.saveSelectionLoop()}!this.maskOptions.mask||!c(this.maskOptions,r)||o||this.hasValue&&this.props.value||(r="");var l={start:s,end:s};if(k(t)){var p=t({value:r,selection:l},{value:this.value,selection:this.previousSelection},null,this.getModifyMaskedValueConfig());r=p.value,l=p.selection}this.value=r,this.maskOptions.mask&&this.getInputValue()!==this.value&&(this.setInputValue(this.value),this.forceUpdate()),(!e||e.start!==l.start||e.end!==l.end)&&this.setSelection(l.start,l.end)},b.componentWillUnmount=function(){this.mounted=!1},b.render=function(){var t=this,n=this.props,a=(n.mask,n.alwaysShowMask,n.maskChar,n.formatChars,n.inputRef,n.beforeMaskedValueChange,function(e,t){if(null==e)return{};var n,s,a={},o=Object.keys(e);for(s=0;s<o.length;s++)n=o[s],t.indexOf(n)>=0||(a[n]=e[n]);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);for(s=0;s<r.length;s++)n=r[s],t.indexOf(n)>=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(a[n]=e[n])}return a}(n,["mask","alwaysShowMask","maskChar","formatChars","inputRef","beforeMaskedValueChange"]));if(this.maskOptions.mask){if(!a.disabled&&!a.readOnly){["onChange","onPaste","onMouseDown"].forEach(function(e){a[e]=t[e]})}null!=a.value&&(a.value=this.value)}return e.createElement("input",s({ref:this.handleRef},a,{onFocus:this.onFocus,onBlur:this.onBlur}))},y=r,t((w=i).prototype,y&&y.prototype),t(w,y),i}((e=e&&e.hasOwnProperty("default")?e["default"]:e).Component)});
!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,t){for(var n=Object.getOwnPropertyNames(t),o=0;o<n.length;o++){var s=n[o],a=Object.getOwnPropertyDescriptor(t,s);a&&a.configurable&&e[s]===undefined&&Object.defineProperty(e,s,a)}return e}function n(){return(n=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var o in n)Object.prototype.hasOwnProperty.call(n,o)&&(e[o]=n[o])}return e}).apply(this,arguments)}function o(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function s(e,t,n){if("selectionStart"in e&&"selectionEnd"in e)e.selectionStart=t,e.selectionEnd=n;else{var o=e.createTextRange();o.collapse(!0),o.moveStart("character",t),o.moveEnd("character",n-t),o.select()}}var a={9:"[0-9]",a:"[A-Za-z]","*":"[A-Za-z0-9]"},r="_";function i(e,t,n){if(t===undefined&&(t=r),null==n&&(n=a),!e||"string"!=typeof e)return{maskChar:t,formatChars:n,mask:null,prefix:null,lastEditablePosition:null,permanents:[]};var o="",s="",i=[],l=!1,u=null;return e.split("").forEach(function(e){l||"\\"!==e?(l||!n[e]?(i.push(o.length),o.length===i.length-1&&(s+=e)):u=o.length+1,o+=e,l=!1):l=!0}),{maskChar:t,formatChars:n,prefix:s,mask:o,lastEditablePosition:u,permanents:i}}function l(e,t){return-1!==e.permanents.indexOf(t)}function u(e,t,n){var o=e.mask,s=e.formatChars;if(!n)return!1;if(l(e,t))return o[t]===n;var a=s[o[t]];return new RegExp(a).test(n)}function p(e,t){return t.split("").every(function(t,n){return l(e,n)||!u(e,n,t)})}function c(e,t){var n=e.maskChar,o=e.prefix;if(!n){for(;t.length>o.length&&l(e,t.length-1);)t=t.slice(0,t.length-1);return t.length}for(var s=o.length,a=t.length;a>=o.length;a--){var r=t[a];if(!l(e,a)&&u(e,a,r)){s=a+1;break}}return s}function f(e,t){return c(e,t)===e.mask.length}function h(e,t){var n=e.maskChar,o=e.mask,s=e.prefix;if(!n){for((t=m(e,"",t,0)).length<s.length&&(t=s);t.length<o.length&&l(e,t.length);)t+=o[t.length];return t}if(t)return m(e,h(e,""),t,0);for(var a=0;a<o.length;a++)l(e,a)?t+=o[a]:t+=n;return t}function m(e,t,n,o){var s=e.mask,a=e.maskChar,r=e.prefix,i=n.split(""),p=f(e,t),c=function(t,n){return!a||!l(e,n)||t!==a};return!a&&o>t.length&&(t+=s.slice(t.length,o)),i.every(function(n){for(;f=n,l(e,i=o)&&f!==s[i];){if(o>=t.length&&(t+=s[o]),!c(n,o))return!0;if(++o>=s.length)return!1}var i,f;return!u(e,o,n)&&n!==a||(o<t.length?a||p||o<r.length?t=t.slice(0,o)+n+t.slice(o+1):(t=t.slice(0,o)+n+t.slice(o),t=h(e,t)):a||(t+=n),++o<s.length)}),t}function d(e,t){for(var n=e.mask,o=t;o<n.length;++o)if(!l(e,o))return o;return null}function v(e){return e||0===e?e+"":""}function g(e){return"function"==typeof e}function k(){return window.cancelAnimationFrame||window.webkitCancelRequestAnimationFrame||window.webkitCancelAnimationFrame||window.mozCancelAnimationFrame}function O(e){return(!!k()?window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame:function(){return setTimeout(e,1e3/60)})(e)}function w(e){(k()||clearTimeout)(e)}return function(a){function r(t){var n;(n=a.call(this,t)||this).focused=!1,n.mounted=!1,n.previousSelection=null,n.selectionDeferId=null,n.saveSelectionLoopDeferId=null,n.saveSelectionLoop=function(){n.previousSelection=n.getSelection(),n.saveSelectionLoopDeferId=O(n.saveSelectionLoop)},n.runSaveSelectionLoop=function(){null===n.saveSelectionLoopDeferId&&n.saveSelectionLoop()},n.stopSaveSelectionLoop=function(){null!==n.saveSelectionLoopDeferId&&(w(n.saveSelectionLoopDeferId),n.saveSelectionLoopDeferId=null)},n.getInputDOMNode=function(){var t,o=n.input;return o?(t=o,("object"==typeof HTMLElement?t instanceof HTMLElement:1===t.nodeType&&"string"==typeof t.nodeName)?o:e.findDOMNode(o)):null},n.getInputValue=function(){var e=n.getInputDOMNode();return e?e.value:null},n.setInputValue=function(e){var t=n.getInputDOMNode();t&&(n.value=e,t.value=e)},n.setCursorToEnd=function(){var e=c(n.maskOptions,n.value),t=d(n.maskOptions,e);null!==t&&n.setCursorPosition(t)},n.setSelection=function(e,t,o){void 0===o&&(o={});var a=n.getInputDOMNode();a&&(o.deferred||s(a,e,t),null!==n.selectionDeferId&&w(n.selectionDeferId),n.selectionDeferId=O(function(){n.selectionDeferId=null,s(a,e,t)}),n.previousSelection={start:e,end:t,length:Math.abs(t-e)})},n.getSelection=function(){return function(e){var t=0,n=0;if("selectionStart"in e&&"selectionEnd"in e)t=e.selectionStart,n=e.selectionEnd;else{var o=document.selection.createRange();o.parentElement()===e&&(t=-o.moveStart("character",-e.value.length),n=-o.moveEnd("character",-e.value.length))}return{start:t,end:n,length:n-t}}(n.getInputDOMNode())},n.getCursorPosition=function(){return n.getSelection().start},n.setCursorPosition=function(e){n.setSelection(e,e)},n.isFocused=function(){return n.focused},n.getModifyMaskedValueConfig=function(){var e=n.maskOptions,t=e.mask,o=e.maskChar,s=e.permanents,a=e.formatChars;return{mask:t,maskChar:o,permanents:s,alwaysShowMask:!!n.props.alwaysShowMask,formatChars:a}},n.isInputAutofilled=function(){var e=n.getInputDOMNode(),t=!1;try{g(e.matches)&&e.matches(":-webkit-autofill")&&(t=!0)}catch(o){}return t},n.onChange=function(e){var t,s=o(o(n)),a=s.beforePasteState,r=s.previousSelection,i=n.props.beforeMaskedValueChange,p=n.maskOptions,c=p.mask,f=p.prefix,v=p.lastEditablePosition,k=n.getInputValue(),O=n.value,w="",S=n.getSelection(),C=S.end,y=0;if(n.isInputAutofilled()&&(O=h(n.maskOptions,""),r={start:0,end:0,length:0}),a&&(r=a.selection,O=a.value,S={start:C=r.start+k.length,end:C,length:0},k=O.slice(0,r.start)+k+O.slice(r.end),n.beforePasteState=null),C=Math.min(r.start,S.start),S.end>r.start?(w=k.slice(r.start,S.end),t=(y=function(e,t,n,o){var s=e.mask,a=e.maskChar,r=n.split(""),i=o;return r.every(function(t){for(;r=t,l(e,n=o)&&r!==s[n];)if(++o>=s.length)return!1;var n,r;return(u(e,o,t)||t===a)&&o++,o<s.length}),o-i}(n.maskOptions,0,w,C))?r.length:0):k.length<O.length&&(t=O.length-k.length),k=O,t){if(1===t&&!r.length)C=r.start===S.start?d(n.maskOptions,S.start):function(e,t){for(var n=t;n>=0;--n)if(!l(e,n))return n;return null}(n.maskOptions,S.start);k=function(e,t,n,o){var s=n+o,a=e.maskChar,r=e.mask,i=e.prefix,u=t.split("");if(!a){for(var p=s;p<u.length;p++)l(e,p)&&(u[p]="");return n=Math.max(i.length,n),u.splice(n,s-n),t=u.join(""),h(e,t)}return u.map(function(t,o){return o<n||o>=s?t:l(e,o)?r[o]:a}).join("")}(n.maskOptions,k,C,t)}k=m(n.maskOptions,k,w,C),(C+=y)>=c.length?C=c.length:C<f.length&&!y?C=f.length:C>=f.length&&C<v&&y&&(C=d(n.maskOptions,C)),k=h(n.maskOptions,k),w||(w=null);var M={start:C,end:C};if(g(i)){var b=i({value:k,selection:M},{value:O,selection:r},w,n.getModifyMaskedValueConfig());k=b.value,M=b.selection}n.setInputValue(k),g(n.props.onChange)&&n.props.onChange(e),n.isWindowsPhoneBrowser?n.setSelection(M.start,M.end,{deferred:!0}):n.setSelection(M.start,M.end)},n.onFocus=function(e){var t=n.props.beforeMaskedValueChange,o=n.maskOptions,s=o.mask,a=o.prefix;if(n.focused=!0,n.input=e.target,n.mounted=!0,s)if(n.value)c(n.maskOptions,n.value)<n.maskOptions.mask.length&&n.setCursorToEnd();else{var r=h(n.maskOptions,a),i=h(n.maskOptions,r),l=c(n.maskOptions,i),u=d(n.maskOptions,l),p={start:u,end:u};if(g(t)){var f=t({value:i,selection:p},{value:n.value,selection:null},null,n.getModifyMaskedValueConfig());i=f.value,p=f.selection}var m=i!==e.target.value;m&&(e.target.value=i),n.value=i,m&&g(n.props.onChange)&&n.props.onChange(e),n.setSelection(p.start,p.end)}n.runSaveSelectionLoop(),g(n.props.onFocus)&&n.props.onFocus(e)},n.onBlur=function(e){var t=n.props.beforeMaskedValueChange,o=n.maskOptions.mask;if(n.stopSaveSelectionLoop(),n.previousSelection=null,n.focused=!1,o&&!n.props.alwaysShowMask&&p(n.maskOptions,n.value)){var s="";if(g(t))s=t({value:s,selection:null},{value:n.value,selection:n.previousSelection},null,n.getModifyMaskedValueConfig()).value;var a=s!==n.getInputValue();a&&n.setInputValue(s),a&&g(n.props.onChange)&&n.props.onChange(e)}g(n.props.onBlur)&&n.props.onBlur(e)},n.onMouseDown=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 o=Math.abs(e.clientX-n.mouseDownX),s=Math.abs(e.clientY-n.mouseDownY),a=Math.max(o,s),r=(new Date).getTime()-n.mouseDownTime;(a<=10&&r<=200||a<=5&&r<=300)&&n.setCursorToEnd()}})}g(n.props.onMouseDown)&&n.props.onMouseDown(e)},n.onPaste=function(e){g(n.props.onPaste)&&n.props.onPaste(e),e.defaultPrevented||(n.beforePasteState={value:n.getInputValue(),selection:n.getSelection()},n.setInputValue(""))},n.handleRef=function(e){n.input=e,g(n.props.inputRef)&&n.props.inputRef(e)};var r=t.mask,f=t.maskChar,k=t.formatChars,S=t.defaultValue,C=t.value,y=t.alwaysShowMask;return n.hasValue=null!=C,n.maskOptions=i(r,f,k),null==S&&(S=""),null==C&&(C=S),C=v(C),n.maskOptions.mask&&(y||C)&&(C=h(n.maskOptions,C)),n.value=C,n}var k,S,C=r.prototype;return C.componentDidMount=function(){var e,t,n;this.mounted=!0,this.isWindowsPhoneBrowser=(e=new RegExp("windows","i"),t=new RegExp("phone","i"),n=navigator.userAgent,e.test(n)&&t.test(n)),this.maskOptions.mask&&this.getInputValue()!==this.value&&this.setInputValue(this.value),this.props.maxLength&&this.maskOptions.mask&&"object"==typeof console&&console.error&&console.error("react-input-mask: You shouldn't pass maxLength property to the masked input. It breaks masking and unnecessary because length is limited by the mask length.")},C.componentDidUpdate=function(){var e=this.previousSelection,t=this.props.beforeMaskedValueChange,n=this.maskOptions;if(this.hasValue=null!=this.props.value,this.maskOptions=i(this.props.mask,this.props.maskChar,this.props.formatChars),!this.maskOptions.mask)return this.stopSaveSelectionLoop(),void(this.previousSelection=null);!n.mask&&this.isFocused()&&this.runSaveSelectionLoop();var o=e?e.start:null,s=this.maskOptions.mask&&this.maskOptions.mask!==n.mask,a=this.props.alwaysShowMask||this.isFocused(),r=this.hasValue?v(this.props.value):this.value;if(n.mask||this.hasValue||(r=this.getInputValue()),(s||this.maskOptions.mask&&(r||a))&&(r=h(this.maskOptions,r)),s){var l=c(this.maskOptions,r);(null===o||l<o)&&(o=f(this.maskOptions,r)?l:d(this.maskOptions,l))}!this.maskOptions.mask||!p(this.maskOptions,r)||a||this.hasValue&&this.props.value||(r="");var u={start:o,end:o};if(g(t)){var m=t({value:r,selection:u},{value:this.value,selection:this.previousSelection},null,this.getModifyMaskedValueConfig());r=m.value,u=m.selection}this.value=r,this.maskOptions.mask&&this.getInputValue()!==this.value&&(this.setInputValue(this.value),this.forceUpdate());var k=!1;null!=u.start&&null!=u.end&&(k=!e||e.start!==u.start||e.end!==u.end),k&&this.setSelection(u.start,u.end)},C.componentWillUnmount=function(){this.mounted=!1,null!==this.selectionDeferId&&w(this.selectionDeferId),this.stopSaveSelectionLoop()},C.render=function(){var t=this,o=this.props,s=(o.mask,o.alwaysShowMask,o.maskChar,o.formatChars,o.inputRef,o.beforeMaskedValueChange,function(e,t){if(null==e)return{};var n,o,s={},a=Object.keys(e);for(o=0;o<a.length;o++)n=a[o],t.indexOf(n)>=0||(s[n]=e[n]);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);for(o=0;o<r.length;o++)n=r[o],t.indexOf(n)>=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(s[n]=e[n])}return s}(o,["mask","alwaysShowMask","maskChar","formatChars","inputRef","beforeMaskedValueChange"]));if(this.maskOptions.mask){if(!s.disabled&&!s.readOnly){["onChange","onPaste","onMouseDown"].forEach(function(e){s[e]=t[e]})}null!=s.value&&(s.value=this.value)}return e.createElement("input",n({ref:this.handleRef},s,{onFocus:this.onFocus,onBlur:this.onBlur}))},S=a,t((k=r).prototype,S&&S.prototype),t(k,S),r}((e=e&&e.hasOwnProperty("default")?e["default"]:e).Component)});

@@ -9,17 +9,2 @@ 'use strict';

function _defineProperty(obj, key, value) {
if (key in obj) {
Object.defineProperty(obj, key, {
value: value,
enumerable: true,
configurable: true,
writable: true
});
} else {
obj[key] = value;
}
return obj;
}
function _extends() {

@@ -43,21 +28,2 @@ _extends = Object.assign || function (target) {

function _objectSpread(target) {
for (var i = 1; i < arguments.length; i++) {
var source = arguments[i] != null ? arguments[i] : {};
var ownKeys = Object.keys(source);
if (typeof Object.getOwnPropertySymbols === 'function') {
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) {
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
}));
}
ownKeys.forEach(function (key) {
_defineProperty(target, key, source[key]);
});
}
return target;
}
function _inheritsLoose(subClass, superClass) {

@@ -160,3 +126,3 @@ _defaults2(subClass.prototype, superClass && superClass.prototype);

prefix: null,
lastEditablePos: null,
lastEditablePosition: null,
permanents: []

@@ -170,3 +136,3 @@ };

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

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

} else {
lastEditablePos = str.length + 1;
lastEditablePosition = str.length + 1;
}

@@ -196,3 +162,3 @@

mask: str,
lastEditablePos: lastEditablePos,
lastEditablePosition: lastEditablePosition,
permanents: permanents

@@ -329,3 +295,3 @@ };

}
function insertString(maskOptions, value, insertStr, insertPos) {
function insertString(maskOptions, value, insertStr, insertPosition) {
var mask = maskOptions.mask,

@@ -345,19 +311,19 @@ maskChar = maskOptions.maskChar,

if (!maskChar && insertPos > value.length) {
value += mask.slice(value.length, insertPos);
if (!maskChar && insertPosition > value.length) {
value += mask.slice(value.length, insertPosition);
}
arrayInsertStr.every(function (insertCharacter) {
while (!isUsablePosition(insertPos, insertCharacter)) {
if (insertPos >= value.length) {
value += mask[insertPos];
while (!isUsablePosition(insertPosition, insertCharacter)) {
if (insertPosition >= value.length) {
value += mask[insertPosition];
}
if (!isUsableCharacter(insertCharacter, insertPos)) {
if (!isUsableCharacter(insertCharacter, insertPosition)) {
return true;
}
insertPos++; // stop iteration if maximum value length reached
insertPosition++; // stop iteration if maximum value length reached
if (insertPos >= mask.length) {
if (insertPosition >= mask.length) {
return false;

@@ -367,3 +333,3 @@ }

var isAllowed = isAllowedChar(maskOptions, insertPos, insertCharacter) || insertCharacter === maskChar;
var isAllowed = isAllowedChar(maskOptions, insertPosition, insertCharacter) || insertCharacter === maskChar;

@@ -374,7 +340,7 @@ if (!isAllowed) {

if (insertPos < value.length) {
if (maskChar || isInputFilled || insertPos < prefix.length) {
value = value.slice(0, insertPos) + insertCharacter + value.slice(insertPos + 1);
if (insertPosition < value.length) {
if (maskChar || isInputFilled || insertPosition < prefix.length) {
value = value.slice(0, insertPosition) + insertCharacter + value.slice(insertPosition + 1);
} else {
value = value.slice(0, insertPos) + insertCharacter + value.slice(insertPos);
value = value.slice(0, insertPosition) + insertCharacter + value.slice(insertPosition);
value = formatValue(maskOptions, value);

@@ -386,13 +352,13 @@ }

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

@@ -404,6 +370,6 @@ var isUsablePosition = function isUsablePosition(pos, character) {

arrayInsertStr.every(function (insertCharacter) {
while (!isUsablePosition(insertPos, insertCharacter)) {
insertPos++; // stop iteration if maximum value length reached
while (!isUsablePosition(insertPosition, insertCharacter)) {
insertPosition++; // stop iteration if maximum value length reached
if (insertPos >= mask.length) {
if (insertPosition >= mask.length) {
return false;

@@ -413,14 +379,14 @@ }

var isAllowed = isAllowedChar(maskOptions, insertPos, insertCharacter) || insertCharacter === maskChar;
var isAllowed = isAllowedChar(maskOptions, insertPosition, insertCharacter) || insertCharacter === maskChar;
if (isAllowed) {
insertPos++;
insertPosition++;
} // stop iteration if maximum value length reached
return insertPos < mask.length;
return insertPosition < mask.length;
});
return insertPos - initialInsertPos;
return insertPosition - initialInsertPosition;
}
function getLeftEditablePos(maskOptions, pos) {
function getLeftEditablePosition(maskOptions, pos) {
for (var i = pos; i >= 0; --i) {

@@ -434,3 +400,3 @@ if (!isPermanentChar(maskOptions, i)) {

}
function getRightEditablePos(maskOptions, pos) {
function getRightEditablePosition(maskOptions, pos) {
var mask = maskOptions.mask;

@@ -458,13 +424,28 @@

function defer (fn, timeoutDelay) {
if (timeoutDelay === void 0) {
timeoutDelay = 0;
function getRequestAnimationFrame() {
return window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame;
}
function getCancelAnimationFrame() {
return window.cancelAnimationFrame || window.webkitCancelRequestAnimationFrame || window.webkitCancelAnimationFrame || window.mozCancelAnimationFrame;
}
function defer(fn) {
var deferFn;
var hasCancelAnimationFrame = !!getCancelAnimationFrame();
if (hasCancelAnimationFrame) {
deferFn = getRequestAnimationFrame();
} else {
deferFn = function deferFn() {
return setTimeout(fn, 1000 / 60);
};
}
var defer = window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || function () {
return setTimeout(fn, timeoutDelay);
};
return defer(fn);
return deferFn(fn);
}
function cancelDefer(deferId) {
var cancelFn = getCancelAnimationFrame() || clearTimeout;
cancelFn(deferId);
}

@@ -481,17 +462,23 @@ var InputElement =

_this.previousSelection = null;
_this.selectionDeferId = null;
_this.saveSelectionLoopDeferId = null;
_this.saveSelectionLoop = function () {
if (!_this.mounted || !_this.maskOptions.mask || !_this.focused || _this.saveSelectionLoopRunning) {
return;
}
_this.saveSelectionLoopRunning = true;
_this.previousSelection = _this.getSelection();
defer(function () {
_this.saveSelectionLoopRunning = false;
_this.saveSelectionLoopDeferId = defer(_this.saveSelectionLoop);
};
_this.runSaveSelectionLoop = function () {
if (_this.saveSelectionLoopDeferId === null) {
_this.saveSelectionLoop();
}, 1000 / 60);
}
};
_this.stopSaveSelectionLoop = function () {
if (_this.saveSelectionLoopDeferId !== null) {
cancelDefer(_this.saveSelectionLoopDeferId);
_this.saveSelectionLoopDeferId = null;
}
};
_this.getInputDOMNode = function () {

@@ -534,11 +521,15 @@ var input = _this.input;

_this.setCursorToEnd = function () {
var filledLen = getFilledLength(_this.maskOptions, _this.value);
var pos = getRightEditablePos(_this.maskOptions, filledLen);
var filledLength = getFilledLength(_this.maskOptions, _this.value);
var pos = getRightEditablePosition(_this.maskOptions, filledLength);
if (pos !== null) {
_this.setCursorPos(pos);
_this.setCursorPosition(pos);
}
};
_this.setSelection = function (start, end) {
_this.setSelection = function (start, end, options) {
if (options === void 0) {
options = {};
}
var input = _this.getInputDOMNode();

@@ -550,5 +541,18 @@

setInputSelection(input, start, end);
defer(function () {
var _options = options,
deferred = _options.deferred;
if (!deferred) {
setInputSelection(input, start, end);
}
if (_this.selectionDeferId !== null) {
cancelDefer(_this.selectionDeferId);
} // deferred selection update is required for pre-Lollipop Android browser,
// but for consistent behavior we do it for all browsers
_this.selectionDeferId = defer(function () {
_this.selectionDeferId = null;
setInputSelection(input, start, end);
});

@@ -568,7 +572,7 @@ _this.previousSelection = {

_this.getCursorPos = function () {
_this.getCursorPosition = function () {
return _this.getSelection().start;
};
_this.setCursorPos = function (pos) {
_this.setCursorPosition = function (pos) {
_this.setSelection(pos, pos);

@@ -620,8 +624,14 @@ };

prefix = _this$maskOptions2.prefix,
lastEditablePos = _this$maskOptions2.lastEditablePos;
lastEditablePosition = _this$maskOptions2.lastEditablePosition;
var value = _this.getInputValue();
var newValue = _this.getInputValue();
var newValue = value;
var previousValue = _this.value; // autofill replaces entire value, ignore old one
var previousValue = _this.value;
var enteredString = '';
var selection = _this.getSelection();
var cursorPosition = selection.end;
var formattedEnteredStringLength = 0;
var removedLength; // autofill replaces entire value, ignore old one
// https://github.com/sanniassin/react-input-mask/issues/113

@@ -636,20 +646,13 @@

};
}
} // set value and selection as if we haven't
// cleared input in onPaste handler
var enteredString = '';
var selection = _this.getSelection();
var cursorPos = selection.end;
selection.start = selection.end;
selection.length = 0; // set value and selection as if we haven't
// cleared input in onPaste handler
if (beforePasteState) {
previousSelection = beforePasteState.selection;
previousValue = beforePasteState.value;
cursorPos = previousSelection.start + newValue.length;
cursorPosition = previousSelection.start + newValue.length;
selection = {
start: cursorPos,
end: cursorPos,
start: cursorPosition,
end: cursorPosition,
length: 0

@@ -661,15 +664,15 @@ };

var formattedEnteredStringLen = 0;
var removedLen = previousSelection.length;
cursorPos = Math.min(previousSelection.start, selection.start);
cursorPosition = Math.min(previousSelection.start, selection.start);
if (selection.end > previousSelection.start) {
enteredString = newValue.slice(previousSelection.start, selection.end);
formattedEnteredStringLen = getInsertStringLength(_this.maskOptions, previousValue, enteredString, cursorPos);
formattedEnteredStringLength = getInsertStringLength(_this.maskOptions, previousValue, enteredString, cursorPosition);
if (!formattedEnteredStringLen) {
removedLen = 0;
if (!formattedEnteredStringLength) {
removedLength = 0;
} else {
removedLength = previousSelection.length;
}
} else if (newValue.length < previousValue.length) {
removedLen = previousValue.length - newValue.length;
removedLength = previousValue.length - newValue.length;
}

@@ -679,20 +682,20 @@

if (removedLen) {
if (removedLen === 1 && !previousSelection.length) {
if (removedLength) {
if (removedLength === 1 && !previousSelection.length) {
var deleteFromRight = previousSelection.start === selection.start;
cursorPos = deleteFromRight ? getRightEditablePos(_this.maskOptions, selection.start) : getLeftEditablePos(_this.maskOptions, selection.start);
cursorPosition = deleteFromRight ? getRightEditablePosition(_this.maskOptions, selection.start) : getLeftEditablePosition(_this.maskOptions, selection.start);
}
newValue = clearRange(_this.maskOptions, newValue, cursorPos, removedLen);
newValue = clearRange(_this.maskOptions, newValue, cursorPosition, removedLength);
}
newValue = insertString(_this.maskOptions, newValue, enteredString, cursorPos);
cursorPos = cursorPos + formattedEnteredStringLen;
newValue = insertString(_this.maskOptions, newValue, enteredString, cursorPosition);
cursorPosition = cursorPosition + formattedEnteredStringLength;
if (cursorPos >= mask.length) {
cursorPos = mask.length;
} else if (cursorPos < prefix.length && !formattedEnteredStringLen) {
cursorPos = prefix.length;
} else if (cursorPos >= prefix.length && cursorPos < lastEditablePos && formattedEnteredStringLen) {
cursorPos = getRightEditablePos(_this.maskOptions, cursorPos);
if (cursorPosition >= mask.length) {
cursorPosition = mask.length;
} else if (cursorPosition < prefix.length && !formattedEnteredStringLength) {
cursorPosition = prefix.length;
} else if (cursorPosition >= prefix.length && cursorPosition < lastEditablePosition && formattedEnteredStringLength) {
cursorPosition = getRightEditablePosition(_this.maskOptions, cursorPosition);
}

@@ -707,4 +710,4 @@

var newSelection = {
start: cursorPos,
end: cursorPos
start: cursorPosition,
end: cursorPosition
};

@@ -731,13 +734,4 @@

if (_this.isWindowsPhoneBrowser) {
defer(function () {
if (!_this.mounted || !_this.isFocused()) {
return;
}
var input = _this.getInputDOMNode();
setInputSelection(input, newSelection.start, newSelection.end);
_this.previousSelection = _objectSpread({}, newSelection, {
length: newSelection.end - newSelection.start
});
_this.setSelection(newSelection.start, newSelection.end, {
deferred: true
});

@@ -754,7 +748,6 @@ } else {

prefix = _this$maskOptions3.prefix;
_this.focused = true;
_this.focused = true; // if autoFocus is set, onFocus triggers before componentDidMount
if (!_this.input) {
_this.input = event.target;
}
_this.input = event.target;
_this.mounted = true;

@@ -765,7 +758,7 @@ if (mask) {

var newValue = formatValue(_this.maskOptions, emptyValue);
var filledLen = getFilledLength(_this.maskOptions, newValue);
var cursorPos = getRightEditablePos(_this.maskOptions, filledLen);
var filledLength = getFilledLength(_this.maskOptions, newValue);
var cursorPosition = getRightEditablePosition(_this.maskOptions, filledLength);
var newSelection = {
start: cursorPos,
end: cursorPos
start: cursorPosition,
end: cursorPosition
};

@@ -805,3 +798,3 @@

_this.saveSelectionLoop();
_this.runSaveSelectionLoop();

@@ -816,2 +809,5 @@ if (isFunction(_this.props.onFocus)) {

var mask = _this.maskOptions.mask;
_this.stopSaveSelectionLoop();
_this.previousSelection = null;

@@ -961,8 +957,10 @@ _this.focused = false;

if (!this.maskOptions.mask) {
this.backspaceOrDeleteRemoval = null;
this.stopSaveSelectionLoop();
this.previousSelection = null;
return;
} else if (!oldMaskOptions.mask && this.isFocused()) {
this.runSaveSelectionLoop();
}
var cursorPos = previousSelection ? previousSelection.start : null;
var cursorPosition = previousSelection ? previousSelection.start : null;
var isMaskChanged = this.maskOptions.mask && this.maskOptions.mask !== oldMaskOptions.mask;

@@ -978,17 +976,13 @@ var showEmpty = this.props.alwaysShowMask || this.isFocused();

newValue = formatValue(this.maskOptions, newValue);
}
if (isMaskChanged) {
var filledLen = getFilledLength(this.maskOptions, newValue);
if (isMaskChanged) {
var filledLength = getFilledLength(this.maskOptions, newValue);
if (cursorPos === null || filledLen < cursorPos) {
if (isFilled(this.maskOptions, newValue)) {
cursorPos = filledLen;
} else {
cursorPos = getRightEditablePos(this.maskOptions, filledLen);
}
if (cursorPosition === null || filledLength < cursorPosition) {
if (isFilled(this.maskOptions, newValue)) {
cursorPosition = filledLength;
} else {
cursorPosition = getRightEditablePosition(this.maskOptions, filledLength);
}
if (!oldMaskOptions.mask) {
this.saveSelectionLoop();
}
}

@@ -1002,4 +996,4 @@ }

var newSelection = {
start: cursorPos,
end: cursorPos
start: cursorPosition,
end: cursorPosition
};

@@ -1026,4 +1020,8 @@

var isSelectionChanged = !previousSelection || previousSelection.start !== newSelection.start || previousSelection.end !== newSelection.end;
var isSelectionChanged = false;
if (newSelection.start != null && newSelection.end != null) {
isSelectionChanged = !previousSelection || previousSelection.start !== newSelection.start || previousSelection.end !== newSelection.end;
}
if (isSelectionChanged) {

@@ -1036,2 +1034,8 @@ this.setSelection(newSelection.start, newSelection.end);

this.mounted = false;
if (this.selectionDeferId !== null) {
cancelDefer(this.selectionDeferId);
}
this.stopSaveSelectionLoop();
};

@@ -1038,0 +1042,0 @@

{
"name": "react-input-mask",
"description": "Masked input component for React",
"version": "2.0.0-beta.1",
"version": "2.0.0-beta.2",
"homepage": "https://github.com/sanniassin/react-input-mask",

@@ -28,3 +28,3 @@ "license": "MIT",

"@babel/register": "^7.0.0-beta.46",
"babel-eslint": "^7.2.3",
"babel-eslint": "^8.2.3",
"babel-loader": "^8.0.0-beta.2",

@@ -35,6 +35,6 @@ "chai": "^4.1.2",

"es3ify-loader": "^0.2.0",
"eslint": "^3.19.0",
"eslint-config-airbnb": "^15.1.0",
"eslint": "^4.19.1",
"eslint-config-airbnb": "^16.1.0",
"eslint-plugin-import": "^2.11.0",
"eslint-plugin-jsx-a11y": "^5.1.1",
"eslint-plugin-jsx-a11y": "^6.0.3",
"eslint-plugin-react": "^7.7.0",

@@ -41,0 +41,0 @@ "html-webpack-plugin": "^2.30.1",

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc