Socket
Socket
Sign inDemoInstall

react-input-mask

Package Overview
Dependencies
7
Maintainers
1
Versions
90
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 2.0.2 to 2.0.3

31

dist/react-input-mask.js

@@ -620,8 +620,10 @@ (function (global, factory) {

if (_this.input) {
return _this.input;
var input = reactDom.findDOMNode(_assertThisInitialized(_assertThisInitialized(_this)));
var isDOMNode = typeof window !== 'undefined' && input instanceof window.HTMLElement; // workaround for react-test-renderer
// https://github.com/sanniassin/react-input-mask/issues/147
if (input && !isDOMNode) {
return null;
}
var input = reactDom.findDOMNode(_assertThisInitialized(_assertThisInitialized(_this)));
if (input.nodeName !== 'INPUT') {

@@ -840,3 +842,2 @@ input = input.querySelector('input');

_this.input = event.target;
_this.mounted = true;

@@ -865,14 +866,10 @@

newSelection = modifiedValue.selection;
} // do not use this.getInputValue and this.setInputValue as this.input
// will be undefined if it's an initial mount of input with autoFocus attribute
}
var isInputValueChanged = newValue !== _this.getInputValue();
var isInputValueChanged = newValue !== event.target.value;
if (isInputValueChanged) {
event.target.value = newValue;
_this.setInputValue(newValue);
}
_this.value = newValue;
if (isInputValueChanged && isFunction(_this.props.onChange)) {

@@ -987,4 +984,2 @@ _this.props.onChange(event);

_this.handleRef = function (ref) {
_this.input = _this.getInputDOMNode();
if (_this.props.children == null && isFunction(_this.props.inputRef)) {

@@ -1045,3 +1040,9 @@ _this.props.inputRef(ref);

_proto.componentDidMount = function componentDidMount() {
this.mounted = true;
this.mounted = true; // workaround for react-test-renderer
// https://github.com/sanniassin/react-input-mask/issues/147
if (!this.getInputDOMNode()) {
return;
}
this.isWindowsPhoneBrowser = isWindowsPhoneBrowser();

@@ -1048,0 +1049,0 @@

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

!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t(require("react"),require("react-dom")):"function"==typeof define&&define.amd?define(["react","react-dom"],t):e.ReactInputMask=t(e.React,e.ReactDOM)}(this,function(i,f){"use strict";function a(e,t){for(var n=Object.getOwnPropertyNames(t),o=0;o<n.length;o++){var a=n[o],r=Object.getOwnPropertyDescriptor(t,a);r&&r.configurable&&e[a]===undefined&&Object.defineProperty(e,a,r)}return e}function l(){return(l=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 h(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}i=i&&i.hasOwnProperty("default")?i["default"]:i;var u=function(e,t,n,o,a,r,s,i){if(!e){var l;if(t===undefined)l=new Error("Minified exception occurred; use the non-minified dev environment for the full error message and additional helpful warnings.");else{var u=[n,o,a,r,s,i],c=0;(l=new Error(t.replace(/%s/g,function(){return u[c++]}))).name="Invariant Violation"}throw l.framesToPop=1,l}};function d(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 c={9:"[0-9]",a:"[A-Za-z]","*":"[A-Za-z0-9]"},p="_";function g(e,t,n){var o="",a="",r=null,s=[];if(t===undefined&&(t=p),null==n&&(n=c),!e||"string"!=typeof e)return{maskChar:t,formatChars:n,mask:null,prefix:null,lastEditablePosition:null,permanents:[]};var i=!1;return e.split("").forEach(function(e){i||"\\"!==e?(i||!n[e]?(s.push(o.length),o.length===s.length-1&&(a+=e)):r=o.length+1,o+=e,i=!1):i=!0}),{maskChar:t,formatChars:n,prefix:a,mask:o,lastEditablePosition:r,permanents:s}}function S(e,t){return-1!==e.permanents.indexOf(t)}function C(e,t,n){var o=e.mask,a=e.formatChars;if(!n)return!1;if(S(e,t))return o[t]===n;var r=a[o[t]];return new RegExp(r).test(n)}function k(n,e){return e.split("").every(function(e,t){return S(n,t)||!C(n,t,e)})}function w(e,t){var n=e.maskChar,o=e.prefix;if(!n){for(;t.length>o.length&&S(e,t.length-1);)t=t.slice(0,t.length-1);return t.length}for(var a=o.length,r=t.length;r>=o.length;r--){var s=t[r];if(!S(e,r)&&C(e,r,s)){a=r+1;break}}return a}function O(e,t){return w(e,t)===e.mask.length}function M(e,t){var n=e.maskChar,o=e.mask,a=e.prefix;if(!n){for((t=b(e,"",t,0)).length<a.length&&(t=a);t.length<o.length&&S(e,t.length);)t+=o[t.length];return t}if(t)return b(e,M(e,""),t,0);for(var r=0;r<o.length;r++)S(e,r)?t+=o[r]:t+=n;return t}function b(r,s,e,i){var l=r.mask,u=r.maskChar,c=r.prefix,t=e.split(""),f=O(r,s);return!u&&i>s.length&&(s+=l.slice(s.length,i)),t.every(function(e){for(;a=e,S(r,o=i)&&a!==l[o];){if(i>=s.length&&(s+=l[i]),t=e,n=i,u&&S(r,n)&&t===u)return!0;if(++i>=l.length)return!1}var t,n,o,a;return!C(r,i,e)&&e!==u||(i<s.length?u||f||i<c.length?s=s.slice(0,i)+e+s.slice(i+1):(s=s.slice(0,i)+e+s.slice(i),s=M(r,s)):u||(s+=e),++i<l.length)}),s}function D(e,t){for(var n=e.mask,o=t;o<n.length;++o)if(!S(e,o))return o;return null}function I(e){return e||0===e?e+"":""}function m(e,t,n,o,a){var r,s,i,l,u,c,f,p=e.mask,h=e.prefix,d=e.lastEditablePosition,m=t,v="",g=0,k=0,w=Math.min(a.start,n.start);if(n.end>a.start?(v=m.slice(a.start,n.end),s=v,i=w,l=(r=e).mask,u=r.maskChar,c=s.split(""),f=i,c.every(function(e){for(;n=e,S(r,t=i)&&n!==l[t];)if(++i>=l.length)return!1;var t,n;return(C(r,i,e)||e===u)&&i++,i<l.length}),k=(g=i-f)?a.length:0):m.length<o.length&&(k=o.length-m.length),m=o,k){if(1===k&&!a.length)w=a.start===n.start?D(e,n.start):function(e,t){for(var n=t;0<=n;--n)if(!S(e,n))return n;return null}(e,n.start);m=function(n,e,o,t){var a=o+t,r=n.maskChar,s=n.mask,i=n.prefix,l=e.split("");if(!r){for(var u=a;u<l.length;u++)S(n,u)&&(l[u]="");return o=Math.max(i.length,o),l.splice(o,a-o),e=l.join(""),M(n,e)}return l.map(function(e,t){return t<o||a<=t?e:S(n,t)?s[t]:r}).join("")}(e,m,w,k)}return m=b(e,m,v,w),(w+=g)>=p.length?w=p.length:w<h.length&&!g?w=h.length:w>=h.length&&w<d&&g&&(w=D(e,w)),v||(v=null),{value:m=M(e,m),enteredString:v,selection:{start:w,end:w}}}function y(e){return"function"==typeof e}function t(){return window.cancelAnimationFrame||window.webkitCancelRequestAnimationFrame||window.webkitCancelAnimationFrame||window.mozCancelAnimationFrame}function v(e){return(!!t()?window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame:function(){return setTimeout(e,1e3/60)})(e)}function E(e){(t()||clearTimeout)(e)}return function(c){function e(e){var p=c.call(this,e)||this;p.focused=!1,p.mounted=!1,p.previousSelection=null,p.selectionDeferId=null,p.saveSelectionLoopDeferId=null,p.saveSelectionLoop=function(){p.previousSelection=p.getSelection(),p.saveSelectionLoopDeferId=v(p.saveSelectionLoop)},p.runSaveSelectionLoop=function(){null===p.saveSelectionLoopDeferId&&p.saveSelectionLoop()},p.stopSaveSelectionLoop=function(){null!==p.saveSelectionLoopDeferId&&(E(p.saveSelectionLoopDeferId),p.saveSelectionLoopDeferId=null,p.previousSelection=null)},p.getInputDOMNode=function(){if(!p.mounted)return null;if(p.input)return p.input;var e=f.findDOMNode(h(h(p)));if("INPUT"!==e.nodeName&&(e=e.querySelector("input")),!e)throw new Error("react-input-mask: inputComponent doesn't contain input node");return e},p.getInputValue=function(){var e=p.getInputDOMNode();return e?e.value:null},p.setInputValue=function(e){var t=p.getInputDOMNode();t&&(p.value=e,t.value=e)},p.setCursorToEnd=function(){var e=w(p.maskOptions,p.value),t=D(p.maskOptions,e);null!==t&&p.setCursorPosition(t)},p.setSelection=function(e,t,n){void 0===n&&(n={});var o=p.getInputDOMNode();o&&(n.deferred||d(o,e,t),null!==p.selectionDeferId&&E(p.selectionDeferId),p.selectionDeferId=v(function(){p.selectionDeferId=null,d(o,e,t)}),p.previousSelection={start:e,end:t,length:Math.abs(t-e)})},p.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}}(p.getInputDOMNode())},p.getCursorPosition=function(){return p.getSelection().start},p.setCursorPosition=function(e){p.setSelection(e,e)},p.isFocused=function(){return p.focused},p.getBeforeMaskedValueChangeConfig=function(){var e=p.maskOptions,t=e.mask,n=e.maskChar,o=e.permanents,a=e.formatChars;return{mask:t,maskChar:n,permanents:o,alwaysShowMask:!!p.props.alwaysShowMask,formatChars:a}},p.isInputAutofilled=function(e,t,n,o){var a=p.getInputDOMNode();try{if(a.matches(":-webkit-autofill"))return!0}catch(r){}return!p.focused||o.end<n.length&&t.end===e.length},p.onChange=function(e){var t=h(h(p)).beforePasteState,n=h(h(p)).previousSelection,o=p.props.beforeMaskedValueChange,a=p.getInputValue(),r=p.value,s=p.getSelection();p.isInputAutofilled(a,s,r,n)&&(r=M(p.maskOptions,""),n={start:0,end:0,length:0}),t&&(n=t.selection,r=t.value,s={start:n.start+a.length,end:n.start+a.length,length:0},a=r.slice(0,n.start)+a+r.slice(n.end),p.beforePasteState=null);var i=m(p.maskOptions,a,s,r,n),l=i.enteredString,u=i.selection,c=i.value;if(y(o)){var f=o({value:c,selection:u},{value:r,selection:n},l,p.getBeforeMaskedValueChangeConfig());c=f.value,u=f.selection}p.setInputValue(c),y(p.props.onChange)&&p.props.onChange(e),p.isWindowsPhoneBrowser?p.setSelection(u.start,u.end,{deferred:!0}):p.setSelection(u.start,u.end)},p.onFocus=function(e){var t=p.props.beforeMaskedValueChange,n=p.maskOptions,o=n.mask,a=n.prefix;if(p.focused=!0,p.input=e.target,p.mounted=!0,o){if(p.value)w(p.maskOptions,p.value)<p.maskOptions.mask.length&&p.setCursorToEnd();else{var r=M(p.maskOptions,a),s=M(p.maskOptions,r),i=w(p.maskOptions,s),l=D(p.maskOptions,i),u={start:l,end:l};if(y(t)){var c=t({value:s,selection:u},{value:p.value,selection:null},null,p.getBeforeMaskedValueChangeConfig());s=c.value,u=c.selection}var f=s!==e.target.value;f&&(e.target.value=s),p.value=s,f&&y(p.props.onChange)&&p.props.onChange(e),p.setSelection(u.start,u.end)}p.runSaveSelectionLoop()}y(p.props.onFocus)&&p.props.onFocus(e)},p.onBlur=function(e){var t=p.props.beforeMaskedValueChange,n=p.maskOptions.mask;if(p.stopSaveSelectionLoop(),p.focused=!1,n&&!p.props.alwaysShowMask&&k(p.maskOptions,p.value)){var o="";if(y(t))o=t({value:o,selection:null},{value:p.value,selection:p.previousSelection},null,p.getBeforeMaskedValueChangeConfig()).value;var a=o!==p.getInputValue();a&&p.setInputValue(o),a&&y(p.props.onChange)&&p.props.onChange(e)}y(p.props.onBlur)&&p.props.onBlur(e)},p.onMouseDown=function(t){if(!p.focused&&document.addEventListener){p.mouseDownX=t.clientX,p.mouseDownY=t.clientY,p.mouseDownTime=(new Date).getTime();document.addEventListener("mouseup",function e(t){if(document.removeEventListener("mouseup",e),p.focused){var n=Math.abs(t.clientX-p.mouseDownX),o=Math.abs(t.clientY-p.mouseDownY),a=Math.max(n,o),r=(new Date).getTime()-p.mouseDownTime;(a<=10&&r<=200||a<=5&&r<=300)&&p.setCursorToEnd()}})}y(p.props.onMouseDown)&&p.props.onMouseDown(t)},p.onPaste=function(e){y(p.props.onPaste)&&p.props.onPaste(e),e.defaultPrevented||(p.beforePasteState={value:p.getInputValue(),selection:p.getSelection()},p.setInputValue(""))},p.handleRef=function(e){p.input=p.getInputDOMNode(),null==p.props.children&&y(p.props.inputRef)&&p.props.inputRef(e)};var t=e.mask,n=e.maskChar,o=e.formatChars,a=e.alwaysShowMask,r=e.beforeMaskedValueChange,s=e.defaultValue,i=e.value;p.maskOptions=g(t,n,o),null==s&&(s=""),null==i&&(i=s);var l=I(i);if(p.maskOptions.mask&&(a||l)&&(l=M(p.maskOptions,l),y(r))){var u=e.value;null==e.value&&(u=s),l=r({value:l,selection:null},{value:u=I(u),selection:null},null,p.getBeforeMaskedValueChangeConfig()).value}return p.value=l,p}var t,n,o=e.prototype;return o.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)},o.componentDidUpdate=function(){var e=this.previousSelection,t=this.props,n=t.beforeMaskedValueChange,o=t.alwaysShowMask,a=t.mask,r=t.maskChar,s=t.formatChars,i=this.maskOptions,l=o||this.isFocused(),u=null!=this.props.value,c=u?I(this.props.value):this.value,f=e?e.start:null;if(this.maskOptions=g(a,r,s),this.maskOptions.mask){!i.mask&&this.isFocused()&&this.runSaveSelectionLoop();var p=this.maskOptions.mask&&this.maskOptions.mask!==i.mask;if(i.mask||u||(c=this.getInputValue()),(p||this.maskOptions.mask&&(c||l))&&(c=M(this.maskOptions,c)),p){var h=w(this.maskOptions,c);(null===f||h<f)&&(f=O(this.maskOptions,c)?h:D(this.maskOptions,h))}!this.maskOptions.mask||!k(this.maskOptions,c)||l||u&&this.props.value||(c="");var d={start:f,end:f};if(y(n)){var m=n({value:c,selection:d},{value:this.value,selection:this.previousSelection},null,this.getBeforeMaskedValueChangeConfig());c=m.value,d=m.selection}this.value=c,this.getInputValue()!==this.value?(this.setInputValue(this.value),this.forceUpdate()):p&&this.forceUpdate();var v=!1;null!=d.start&&null!=d.end&&(v=!e||e.start!==d.start||e.end!==d.end),v&&this.setSelection(d.start,d.end)}else i.mask&&(this.stopSaveSelectionLoop(),this.forceUpdate())},o.componentWillUnmount=function(){this.mounted=!1,null!==this.selectionDeferId&&E(this.selectionDeferId),this.stopSaveSelectionLoop()},o.render=function(){var t,e=this.props,n=(e.mask,e.alwaysShowMask,e.maskChar,e.formatChars,e.inputRef,e.beforeMaskedValueChange,e.children),o=function(e,t){if(null==e)return{};var n,o,a={},r=Object.keys(e);for(o=0;o<r.length;o++)n=r[o],0<=t.indexOf(n)||(a[n]=e[n]);if(Object.getOwnPropertySymbols){var s=Object.getOwnPropertySymbols(e);for(o=0;o<s.length;o++)n=s[o],0<=t.indexOf(n)||Object.prototype.propertyIsEnumerable.call(e,n)&&(a[n]=e[n])}return a}(e,["mask","alwaysShowMask","maskChar","formatChars","inputRef","beforeMaskedValueChange","children"]);if(n){y(n)||u(!1);var a=["onChange","onPaste","onMouseDown","onFocus","onBlur","value","disabled","readOnly"],r=l({},o);a.forEach(function(e){return delete r[e]}),t=n(r),a.filter(function(e){return null!=t.props[e]&&t.props[e]!==o[e]}).length&&u(!1)}else t=i.createElement("input",l({ref:this.handleRef},o));var s={onFocus:this.onFocus,onBlur:this.onBlur};return this.maskOptions.mask&&(o.disabled||o.readOnly||(s.onChange=this.onChange,s.onPaste=this.onPaste,s.onMouseDown=this.onMouseDown),null!=o.value&&(s.value=this.value)),t=i.cloneElement(t,s)},a((t=e).prototype,(n=c)&&n.prototype),a(t,n),e}(i.Component)});
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?module.exports=n(require("react"),require("react-dom")):"function"==typeof define&&define.amd?define(["react","react-dom"],n):e.ReactInputMask=n(e.React,e.ReactDOM)}(this,function(i,f){"use strict";function a(e,n){for(var t=Object.getOwnPropertyNames(n),o=0;o<t.length;o++){var a=t[o],r=Object.getOwnPropertyDescriptor(n,a);r&&r.configurable&&e[a]===undefined&&Object.defineProperty(e,a,r)}return e}function l(){return(l=Object.assign||function(e){for(var n=1;n<arguments.length;n++){var t=arguments[n];for(var o in t)Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o])}return e}).apply(this,arguments)}function h(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}i=i&&i.hasOwnProperty("default")?i["default"]:i;var u=function(e,n,t,o,a,r,s,i){if(!e){var l;if(n===undefined)l=new Error("Minified exception occurred; use the non-minified dev environment for the full error message and additional helpful warnings.");else{var u=[t,o,a,r,s,i],c=0;(l=new Error(n.replace(/%s/g,function(){return u[c++]}))).name="Invariant Violation"}throw l.framesToPop=1,l}};function d(e,n,t){if("selectionStart"in e&&"selectionEnd"in e)e.selectionStart=n,e.selectionEnd=t;else{var o=e.createTextRange();o.collapse(!0),o.moveStart("character",n),o.moveEnd("character",t-n),o.select()}}var c={9:"[0-9]",a:"[A-Za-z]","*":"[A-Za-z0-9]"},p="_";function g(e,n,t){var o="",a="",r=null,s=[];if(n===undefined&&(n=p),null==t&&(t=c),!e||"string"!=typeof e)return{maskChar:n,formatChars:t,mask:null,prefix:null,lastEditablePosition:null,permanents:[]};var i=!1;return e.split("").forEach(function(e){i||"\\"!==e?(i||!t[e]?(s.push(o.length),o.length===s.length-1&&(a+=e)):r=o.length+1,o+=e,i=!1):i=!0}),{maskChar:n,formatChars:t,prefix:a,mask:o,lastEditablePosition:r,permanents:s}}function S(e,n){return-1!==e.permanents.indexOf(n)}function C(e,n,t){var o=e.mask,a=e.formatChars;if(!t)return!1;if(S(e,n))return o[n]===t;var r=a[o[n]];return new RegExp(r).test(t)}function k(t,e){return e.split("").every(function(e,n){return S(t,n)||!C(t,n,e)})}function w(e,n){var t=e.maskChar,o=e.prefix;if(!t){for(;n.length>o.length&&S(e,n.length-1);)n=n.slice(0,n.length-1);return n.length}for(var a=o.length,r=n.length;r>=o.length;r--){var s=n[r];if(!S(e,r)&&C(e,r,s)){a=r+1;break}}return a}function O(e,n){return w(e,n)===e.mask.length}function M(e,n){var t=e.maskChar,o=e.mask,a=e.prefix;if(!t){for((n=I(e,"",n,0)).length<a.length&&(n=a);n.length<o.length&&S(e,n.length);)n+=o[n.length];return n}if(n)return I(e,M(e,""),n,0);for(var r=0;r<o.length;r++)S(e,r)?n+=o[r]:n+=t;return n}function I(r,s,e,i){var l=r.mask,u=r.maskChar,c=r.prefix,n=e.split(""),f=O(r,s);return!u&&i>s.length&&(s+=l.slice(s.length,i)),n.every(function(e){for(;a=e,S(r,o=i)&&a!==l[o];){if(i>=s.length&&(s+=l[i]),n=e,t=i,u&&S(r,t)&&n===u)return!0;if(++i>=l.length)return!1}var n,t,o,a;return!C(r,i,e)&&e!==u||(i<s.length?u||f||i<c.length?s=s.slice(0,i)+e+s.slice(i+1):(s=s.slice(0,i)+e+s.slice(i),s=M(r,s)):u||(s+=e),++i<l.length)}),s}function b(e,n){for(var t=e.mask,o=n;o<t.length;++o)if(!S(e,o))return o;return null}function D(e){return e||0===e?e+"":""}function m(e,n,t,o,a){var r,s,i,l,u,c,f,p=e.mask,h=e.prefix,d=e.lastEditablePosition,m=n,v="",g=0,k=0,w=Math.min(a.start,t.start);if(t.end>a.start?(v=m.slice(a.start,t.end),s=v,i=w,l=(r=e).mask,u=r.maskChar,c=s.split(""),f=i,c.every(function(e){for(;t=e,S(r,n=i)&&t!==l[n];)if(++i>=l.length)return!1;var n,t;return(C(r,i,e)||e===u)&&i++,i<l.length}),k=(g=i-f)?a.length:0):m.length<o.length&&(k=o.length-m.length),m=o,k){if(1===k&&!a.length)w=a.start===t.start?b(e,t.start):function(e,n){for(var t=n;0<=t;--t)if(!S(e,t))return t;return null}(e,t.start);m=function(t,e,o,n){var a=o+n,r=t.maskChar,s=t.mask,i=t.prefix,l=e.split("");if(!r){for(var u=a;u<l.length;u++)S(t,u)&&(l[u]="");return o=Math.max(i.length,o),l.splice(o,a-o),e=l.join(""),M(t,e)}return l.map(function(e,n){return n<o||a<=n?e:S(t,n)?s[n]:r}).join("")}(e,m,w,k)}return m=I(e,m,v,w),(w+=g)>=p.length?w=p.length:w<h.length&&!g?w=h.length:w>=h.length&&w<d&&g&&(w=b(e,w)),v||(v=null),{value:m=M(e,m),enteredString:v,selection:{start:w,end:w}}}function y(e){return"function"==typeof e}function n(){return window.cancelAnimationFrame||window.webkitCancelRequestAnimationFrame||window.webkitCancelAnimationFrame||window.mozCancelAnimationFrame}function v(e){return(!!n()?window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame:function(){return setTimeout(e,1e3/60)})(e)}function V(e){(n()||clearTimeout)(e)}return function(c){function e(e){var p=c.call(this,e)||this;p.focused=!1,p.mounted=!1,p.previousSelection=null,p.selectionDeferId=null,p.saveSelectionLoopDeferId=null,p.saveSelectionLoop=function(){p.previousSelection=p.getSelection(),p.saveSelectionLoopDeferId=v(p.saveSelectionLoop)},p.runSaveSelectionLoop=function(){null===p.saveSelectionLoopDeferId&&p.saveSelectionLoop()},p.stopSaveSelectionLoop=function(){null!==p.saveSelectionLoopDeferId&&(V(p.saveSelectionLoopDeferId),p.saveSelectionLoopDeferId=null,p.previousSelection=null)},p.getInputDOMNode=function(){if(!p.mounted)return null;var e=f.findDOMNode(h(h(p))),n="undefined"!=typeof window&&e instanceof window.HTMLElement;if(e&&!n)return null;if("INPUT"!==e.nodeName&&(e=e.querySelector("input")),!e)throw new Error("react-input-mask: inputComponent doesn't contain input node");return e},p.getInputValue=function(){var e=p.getInputDOMNode();return e?e.value:null},p.setInputValue=function(e){var n=p.getInputDOMNode();n&&(p.value=e,n.value=e)},p.setCursorToEnd=function(){var e=w(p.maskOptions,p.value),n=b(p.maskOptions,e);null!==n&&p.setCursorPosition(n)},p.setSelection=function(e,n,t){void 0===t&&(t={});var o=p.getInputDOMNode();o&&(t.deferred||d(o,e,n),null!==p.selectionDeferId&&V(p.selectionDeferId),p.selectionDeferId=v(function(){p.selectionDeferId=null,d(o,e,n)}),p.previousSelection={start:e,end:n,length:Math.abs(n-e)})},p.getSelection=function(){return function(e){var n=0,t=0;if("selectionStart"in e&&"selectionEnd"in e)n=e.selectionStart,t=e.selectionEnd;else{var o=document.selection.createRange();o.parentElement()===e&&(n=-o.moveStart("character",-e.value.length),t=-o.moveEnd("character",-e.value.length))}return{start:n,end:t,length:t-n}}(p.getInputDOMNode())},p.getCursorPosition=function(){return p.getSelection().start},p.setCursorPosition=function(e){p.setSelection(e,e)},p.isFocused=function(){return p.focused},p.getBeforeMaskedValueChangeConfig=function(){var e=p.maskOptions,n=e.mask,t=e.maskChar,o=e.permanents,a=e.formatChars;return{mask:n,maskChar:t,permanents:o,alwaysShowMask:!!p.props.alwaysShowMask,formatChars:a}},p.isInputAutofilled=function(e,n,t,o){var a=p.getInputDOMNode();try{if(a.matches(":-webkit-autofill"))return!0}catch(r){}return!p.focused||o.end<t.length&&n.end===e.length},p.onChange=function(e){var n=h(h(p)).beforePasteState,t=h(h(p)).previousSelection,o=p.props.beforeMaskedValueChange,a=p.getInputValue(),r=p.value,s=p.getSelection();p.isInputAutofilled(a,s,r,t)&&(r=M(p.maskOptions,""),t={start:0,end:0,length:0}),n&&(t=n.selection,r=n.value,s={start:t.start+a.length,end:t.start+a.length,length:0},a=r.slice(0,t.start)+a+r.slice(t.end),p.beforePasteState=null);var i=m(p.maskOptions,a,s,r,t),l=i.enteredString,u=i.selection,c=i.value;if(y(o)){var f=o({value:c,selection:u},{value:r,selection:t},l,p.getBeforeMaskedValueChangeConfig());c=f.value,u=f.selection}p.setInputValue(c),y(p.props.onChange)&&p.props.onChange(e),p.isWindowsPhoneBrowser?p.setSelection(u.start,u.end,{deferred:!0}):p.setSelection(u.start,u.end)},p.onFocus=function(e){var n=p.props.beforeMaskedValueChange,t=p.maskOptions,o=t.mask,a=t.prefix;if(p.focused=!0,p.mounted=!0,o){if(p.value)w(p.maskOptions,p.value)<p.maskOptions.mask.length&&p.setCursorToEnd();else{var r=M(p.maskOptions,a),s=M(p.maskOptions,r),i=w(p.maskOptions,s),l=b(p.maskOptions,i),u={start:l,end:l};if(y(n)){var c=n({value:s,selection:u},{value:p.value,selection:null},null,p.getBeforeMaskedValueChangeConfig());s=c.value,u=c.selection}var f=s!==p.getInputValue();f&&p.setInputValue(s),f&&y(p.props.onChange)&&p.props.onChange(e),p.setSelection(u.start,u.end)}p.runSaveSelectionLoop()}y(p.props.onFocus)&&p.props.onFocus(e)},p.onBlur=function(e){var n=p.props.beforeMaskedValueChange,t=p.maskOptions.mask;if(p.stopSaveSelectionLoop(),p.focused=!1,t&&!p.props.alwaysShowMask&&k(p.maskOptions,p.value)){var o="";if(y(n))o=n({value:o,selection:null},{value:p.value,selection:p.previousSelection},null,p.getBeforeMaskedValueChangeConfig()).value;var a=o!==p.getInputValue();a&&p.setInputValue(o),a&&y(p.props.onChange)&&p.props.onChange(e)}y(p.props.onBlur)&&p.props.onBlur(e)},p.onMouseDown=function(n){if(!p.focused&&document.addEventListener){p.mouseDownX=n.clientX,p.mouseDownY=n.clientY,p.mouseDownTime=(new Date).getTime();document.addEventListener("mouseup",function e(n){if(document.removeEventListener("mouseup",e),p.focused){var t=Math.abs(n.clientX-p.mouseDownX),o=Math.abs(n.clientY-p.mouseDownY),a=Math.max(t,o),r=(new Date).getTime()-p.mouseDownTime;(a<=10&&r<=200||a<=5&&r<=300)&&p.setCursorToEnd()}})}y(p.props.onMouseDown)&&p.props.onMouseDown(n)},p.onPaste=function(e){y(p.props.onPaste)&&p.props.onPaste(e),e.defaultPrevented||(p.beforePasteState={value:p.getInputValue(),selection:p.getSelection()},p.setInputValue(""))},p.handleRef=function(e){null==p.props.children&&y(p.props.inputRef)&&p.props.inputRef(e)};var n=e.mask,t=e.maskChar,o=e.formatChars,a=e.alwaysShowMask,r=e.beforeMaskedValueChange,s=e.defaultValue,i=e.value;p.maskOptions=g(n,t,o),null==s&&(s=""),null==i&&(i=s);var l=D(i);if(p.maskOptions.mask&&(a||l)&&(l=M(p.maskOptions,l),y(r))){var u=e.value;null==e.value&&(u=s),l=r({value:l,selection:null},{value:u=D(u),selection:null},null,p.getBeforeMaskedValueChangeConfig()).value}return p.value=l,p}var n,t,o=e.prototype;return o.componentDidMount=function(){var e,n,t;(this.mounted=!0,this.getInputDOMNode())&&(this.isWindowsPhoneBrowser=(e=new RegExp("windows","i"),n=new RegExp("phone","i"),t=navigator.userAgent,e.test(t)&&n.test(t)),this.maskOptions.mask&&this.getInputValue()!==this.value&&this.setInputValue(this.value))},o.componentDidUpdate=function(){var e=this.previousSelection,n=this.props,t=n.beforeMaskedValueChange,o=n.alwaysShowMask,a=n.mask,r=n.maskChar,s=n.formatChars,i=this.maskOptions,l=o||this.isFocused(),u=null!=this.props.value,c=u?D(this.props.value):this.value,f=e?e.start:null;if(this.maskOptions=g(a,r,s),this.maskOptions.mask){!i.mask&&this.isFocused()&&this.runSaveSelectionLoop();var p=this.maskOptions.mask&&this.maskOptions.mask!==i.mask;if(i.mask||u||(c=this.getInputValue()),(p||this.maskOptions.mask&&(c||l))&&(c=M(this.maskOptions,c)),p){var h=w(this.maskOptions,c);(null===f||h<f)&&(f=O(this.maskOptions,c)?h:b(this.maskOptions,h))}!this.maskOptions.mask||!k(this.maskOptions,c)||l||u&&this.props.value||(c="");var d={start:f,end:f};if(y(t)){var m=t({value:c,selection:d},{value:this.value,selection:this.previousSelection},null,this.getBeforeMaskedValueChangeConfig());c=m.value,d=m.selection}this.value=c,this.getInputValue()!==this.value?(this.setInputValue(this.value),this.forceUpdate()):p&&this.forceUpdate();var v=!1;null!=d.start&&null!=d.end&&(v=!e||e.start!==d.start||e.end!==d.end),v&&this.setSelection(d.start,d.end)}else i.mask&&(this.stopSaveSelectionLoop(),this.forceUpdate())},o.componentWillUnmount=function(){this.mounted=!1,null!==this.selectionDeferId&&V(this.selectionDeferId),this.stopSaveSelectionLoop()},o.render=function(){var n,e=this.props,t=(e.mask,e.alwaysShowMask,e.maskChar,e.formatChars,e.inputRef,e.beforeMaskedValueChange,e.children),o=function(e,n){if(null==e)return{};var t,o,a={},r=Object.keys(e);for(o=0;o<r.length;o++)t=r[o],0<=n.indexOf(t)||(a[t]=e[t]);if(Object.getOwnPropertySymbols){var s=Object.getOwnPropertySymbols(e);for(o=0;o<s.length;o++)t=s[o],0<=n.indexOf(t)||Object.prototype.propertyIsEnumerable.call(e,t)&&(a[t]=e[t])}return a}(e,["mask","alwaysShowMask","maskChar","formatChars","inputRef","beforeMaskedValueChange","children"]);if(t){y(t)||u(!1);var a=["onChange","onPaste","onMouseDown","onFocus","onBlur","value","disabled","readOnly"],r=l({},o);a.forEach(function(e){return delete r[e]}),n=t(r),a.filter(function(e){return null!=n.props[e]&&n.props[e]!==o[e]}).length&&u(!1)}else n=i.createElement("input",l({ref:this.handleRef},o));var s={onFocus:this.onFocus,onBlur:this.onBlur};return this.maskOptions.mask&&(o.disabled||o.readOnly||(s.onChange=this.onChange,s.onPaste=this.onPaste,s.onMouseDown=this.onMouseDown),null!=o.value&&(s.value=this.value)),n=i.cloneElement(n,s)},a((n=e).prototype,(t=c)&&t.prototype),a(n,t),e}(i.Component)});

@@ -536,8 +536,10 @@ 'use strict';

if (_this.input) {
return _this.input;
var input = reactDom.findDOMNode(_assertThisInitialized(_assertThisInitialized(_this)));
var isDOMNode = typeof window !== 'undefined' && input instanceof window.HTMLElement; // workaround for react-test-renderer
// https://github.com/sanniassin/react-input-mask/issues/147
if (input && !isDOMNode) {
return null;
}
var input = reactDom.findDOMNode(_assertThisInitialized(_assertThisInitialized(_this)));
if (input.nodeName !== 'INPUT') {

@@ -756,3 +758,2 @@ input = input.querySelector('input');

_this.input = event.target;
_this.mounted = true;

@@ -781,14 +782,10 @@

newSelection = modifiedValue.selection;
} // do not use this.getInputValue and this.setInputValue as this.input
// will be undefined if it's an initial mount of input with autoFocus attribute
}
var isInputValueChanged = newValue !== _this.getInputValue();
var isInputValueChanged = newValue !== event.target.value;
if (isInputValueChanged) {
event.target.value = newValue;
_this.setInputValue(newValue);
}
_this.value = newValue;
if (isInputValueChanged && isFunction(_this.props.onChange)) {

@@ -903,4 +900,2 @@ _this.props.onChange(event);

_this.handleRef = function (ref) {
_this.input = _this.getInputDOMNode();
if (_this.props.children == null && isFunction(_this.props.inputRef)) {

@@ -961,3 +956,9 @@ _this.props.inputRef(ref);

_proto.componentDidMount = function componentDidMount() {
this.mounted = true;
this.mounted = true; // workaround for react-test-renderer
// https://github.com/sanniassin/react-input-mask/issues/147
if (!this.getInputDOMNode()) {
return;
}
this.isWindowsPhoneBrowser = isWindowsPhoneBrowser();

@@ -964,0 +965,0 @@

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

"use strict";function _interopDefault(e){return e&&"object"==typeof e&&"default"in e?e["default"]:e}var React=_interopDefault(require("react")),reactDom=require("react-dom");function _defaults2(e,t){for(var n=Object.getOwnPropertyNames(t),a=0;a<n.length;a++){var r=n[a],i=Object.getOwnPropertyDescriptor(t,r);i&&i.configurable&&e[r]===undefined&&Object.defineProperty(e,r,i)}return e}function _extends(){return(_extends=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var a in n)Object.prototype.hasOwnProperty.call(n,a)&&(e[a]=n[a])}return e}).apply(this,arguments)}function _inheritsLoose(e,t){_defaults2(e.prototype,t&&t.prototype),_defaults2(e,t)}function _objectWithoutProperties(e,t){if(null==e)return{};var n,a,r={},i=Object.keys(e);for(a=0;a<i.length;a++)n=i[a],0<=t.indexOf(n)||(r[n]=e[n]);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);for(a=0;a<o.length;a++)n=o[a],0<=t.indexOf(n)||Object.prototype.propertyIsEnumerable.call(e,n)&&(r[n]=e[n])}return r}function _assertThisInitialized(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}var invariant=function(e,t,n,a,r,i,o,s){if(!e){var l;if(t===undefined)l=new Error("Minified exception occurred; use the non-minified dev environment for the full error message and additional helpful warnings.");else{var u=[n,a,r,i,o,s],c=0;(l=new Error(t.replace(/%s/g,function(){return u[c++]}))).name="Invariant Violation"}throw l.framesToPop=1,l}},invariant_1=invariant;function setInputSelection(e,t,n){if("selectionStart"in e&&"selectionEnd"in e)e.selectionStart=t,e.selectionEnd=n;else{var a=e.createTextRange();a.collapse(!0),a.moveStart("character",t),a.moveEnd("character",n-t),a.select()}}function getInputSelection(e){var t=0,n=0;if("selectionStart"in e&&"selectionEnd"in e)t=e.selectionStart,n=e.selectionEnd;else{var a=document.selection.createRange();a.parentElement()===e&&(t=-a.moveStart("character",-e.value.length),n=-a.moveEnd("character",-e.value.length))}return{start:t,end:n,length:n-t}}var defaultFormatChars={9:"[0-9]",a:"[A-Za-z]","*":"[A-Za-z0-9]"},defaultMaskChar="_";function parseMask(e,t,n){var a="",r="",i=null,o=[];if(t===undefined&&(t=defaultMaskChar),null==n&&(n=defaultFormatChars),!e||"string"!=typeof e)return{maskChar:t,formatChars:n,mask:null,prefix:null,lastEditablePosition:null,permanents:[]};var s=!1;return e.split("").forEach(function(e){s||"\\"!==e?(s||!n[e]?(o.push(a.length),a.length===o.length-1&&(r+=e)):i=a.length+1,a+=e,s=!1):s=!0}),{maskChar:t,formatChars:n,prefix:r,mask:a,lastEditablePosition:i,permanents:o}}function isPermanentCharacter(e,t){return-1!==e.permanents.indexOf(t)}function isAllowedCharacter(e,t,n){var a=e.mask,r=e.formatChars;if(!n)return!1;if(isPermanentCharacter(e,t))return a[t]===n;var i=r[a[t]];return new RegExp(i).test(n)}function isEmpty(n,e){return e.split("").every(function(e,t){return isPermanentCharacter(n,t)||!isAllowedCharacter(n,t,e)})}function getFilledLength(e,t){var n=e.maskChar,a=e.prefix;if(!n){for(;t.length>a.length&&isPermanentCharacter(e,t.length-1);)t=t.slice(0,t.length-1);return t.length}for(var r=a.length,i=t.length;i>=a.length;i--){var o=t[i];if(!isPermanentCharacter(e,i)&&isAllowedCharacter(e,i,o)){r=i+1;break}}return r}function isFilled(e,t){return getFilledLength(e,t)===e.mask.length}function formatValue(e,t){var n=e.maskChar,a=e.mask,r=e.prefix;if(!n){for((t=insertString(e,"",t,0)).length<r.length&&(t=r);t.length<a.length&&isPermanentCharacter(e,t.length);)t+=a[t.length];return t}if(t)return insertString(e,formatValue(e,""),t,0);for(var i=0;i<a.length;i++)isPermanentCharacter(e,i)?t+=a[i]:t+=n;return t}function clearRange(n,e,a,t){var r=a+t,i=n.maskChar,o=n.mask,s=n.prefix,l=e.split("");if(!i){for(var u=r;u<l.length;u++)isPermanentCharacter(n,u)&&(l[u]="");return a=Math.max(s.length,a),l.splice(a,r-a),e=l.join(""),formatValue(n,e)}return l.map(function(e,t){return t<a||r<=t?e:isPermanentCharacter(n,t)?o[t]:i}).join("")}function insertString(i,o,e,s){var l=i.mask,u=i.maskChar,c=i.prefix,t=e.split(""),h=isFilled(i,o);return!u&&s>o.length&&(o+=l.slice(o.length,s)),t.every(function(e){for(;r=e,isPermanentCharacter(i,a=s)&&r!==l[a];){if(s>=o.length&&(o+=l[s]),t=e,n=s,u&&isPermanentCharacter(i,n)&&t===u)return!0;if(++s>=l.length)return!1}var t,n,a,r;return!isAllowedCharacter(i,s,e)&&e!==u||(s<o.length?u||h||s<c.length?o=o.slice(0,s)+e+o.slice(s+1):(o=o.slice(0,s)+e+o.slice(s),o=formatValue(i,o)):u||(o+=e),++s<l.length)}),o}function getInsertStringLength(a,e,t,r){var i=a.mask,o=a.maskChar,n=t.split(""),s=r;return n.every(function(e){for(;n=e,isPermanentCharacter(a,t=r)&&n!==i[t];)if(++r>=i.length)return!1;var t,n;return(isAllowedCharacter(a,r,e)||e===o)&&r++,r<i.length}),r-s}function getLeftEditablePosition(e,t){for(var n=t;0<=n;--n)if(!isPermanentCharacter(e,n))return n;return null}function getRightEditablePosition(e,t){for(var n=e.mask,a=t;a<n.length;++a)if(!isPermanentCharacter(e,a))return a;return null}function getStringValue(e){return e||0===e?e+"":""}function processChange(e,t,n,a,r){var i=e.mask,o=e.prefix,s=e.lastEditablePosition,l=t,u="",c=0,h=0,f=Math.min(r.start,n.start);if(n.end>r.start?h=(c=getInsertStringLength(e,a,u=l.slice(r.start,n.end),f))?r.length:0:l.length<a.length&&(h=a.length-l.length),l=a,h){if(1===h&&!r.length)f=r.start===n.start?getRightEditablePosition(e,n.start):getLeftEditablePosition(e,n.start);l=clearRange(e,l,f,h)}return l=insertString(e,l,u,f),(f+=c)>=i.length?f=i.length:f<o.length&&!c?f=o.length:f>=o.length&&f<s&&c&&(f=getRightEditablePosition(e,f)),u||(u=null),{value:l=formatValue(e,l),enteredString:u,selection:{start:f,end:f}}}function isWindowsPhoneBrowser(){var e=new RegExp("windows","i"),t=new RegExp("phone","i"),n=navigator.userAgent;return e.test(n)&&t.test(n)}function isFunction(e){return"function"==typeof e}function getRequestAnimationFrame(){return window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame}function getCancelAnimationFrame(){return window.cancelAnimationFrame||window.webkitCancelRequestAnimationFrame||window.webkitCancelAnimationFrame||window.mozCancelAnimationFrame}function defer(e){return(!!getCancelAnimationFrame()?getRequestAnimationFrame():function(){return setTimeout(e,1e3/60)})(e)}function cancelDefer(e){(getCancelAnimationFrame()||clearTimeout)(e)}var InputElement=function(c){function e(e){var f=c.call(this,e)||this;f.focused=!1,f.mounted=!1,f.previousSelection=null,f.selectionDeferId=null,f.saveSelectionLoopDeferId=null,f.saveSelectionLoop=function(){f.previousSelection=f.getSelection(),f.saveSelectionLoopDeferId=defer(f.saveSelectionLoop)},f.runSaveSelectionLoop=function(){null===f.saveSelectionLoopDeferId&&f.saveSelectionLoop()},f.stopSaveSelectionLoop=function(){null!==f.saveSelectionLoopDeferId&&(cancelDefer(f.saveSelectionLoopDeferId),f.saveSelectionLoopDeferId=null,f.previousSelection=null)},f.getInputDOMNode=function(){if(!f.mounted)return null;if(f.input)return f.input;var e=reactDom.findDOMNode(_assertThisInitialized(_assertThisInitialized(f)));if("INPUT"!==e.nodeName&&(e=e.querySelector("input")),!e)throw new Error("react-input-mask: inputComponent doesn't contain input node");return e},f.getInputValue=function(){var e=f.getInputDOMNode();return e?e.value:null},f.setInputValue=function(e){var t=f.getInputDOMNode();t&&(f.value=e,t.value=e)},f.setCursorToEnd=function(){var e=getFilledLength(f.maskOptions,f.value),t=getRightEditablePosition(f.maskOptions,e);null!==t&&f.setCursorPosition(t)},f.setSelection=function(e,t,n){void 0===n&&(n={});var a=f.getInputDOMNode();a&&(n.deferred||setInputSelection(a,e,t),null!==f.selectionDeferId&&cancelDefer(f.selectionDeferId),f.selectionDeferId=defer(function(){f.selectionDeferId=null,setInputSelection(a,e,t)}),f.previousSelection={start:e,end:t,length:Math.abs(t-e)})},f.getSelection=function(){return getInputSelection(f.getInputDOMNode())},f.getCursorPosition=function(){return f.getSelection().start},f.setCursorPosition=function(e){f.setSelection(e,e)},f.isFocused=function(){return f.focused},f.getBeforeMaskedValueChangeConfig=function(){var e=f.maskOptions,t=e.mask,n=e.maskChar,a=e.permanents,r=e.formatChars;return{mask:t,maskChar:n,permanents:a,alwaysShowMask:!!f.props.alwaysShowMask,formatChars:r}},f.isInputAutofilled=function(e,t,n,a){var r=f.getInputDOMNode();try{if(r.matches(":-webkit-autofill"))return!0}catch(i){}return!f.focused||a.end<n.length&&t.end===e.length},f.onChange=function(e){var t=_assertThisInitialized(_assertThisInitialized(f)).beforePasteState,n=_assertThisInitialized(_assertThisInitialized(f)).previousSelection,a=f.props.beforeMaskedValueChange,r=f.getInputValue(),i=f.value,o=f.getSelection();f.isInputAutofilled(r,o,i,n)&&(i=formatValue(f.maskOptions,""),n={start:0,end:0,length:0}),t&&(n=t.selection,i=t.value,o={start:n.start+r.length,end:n.start+r.length,length:0},r=i.slice(0,n.start)+r+i.slice(n.end),f.beforePasteState=null);var s=processChange(f.maskOptions,r,o,i,n),l=s.enteredString,u=s.selection,c=s.value;if(isFunction(a)){var h=a({value:c,selection:u},{value:i,selection:n},l,f.getBeforeMaskedValueChangeConfig());c=h.value,u=h.selection}f.setInputValue(c),isFunction(f.props.onChange)&&f.props.onChange(e),f.isWindowsPhoneBrowser?f.setSelection(u.start,u.end,{deferred:!0}):f.setSelection(u.start,u.end)},f.onFocus=function(e){var t=f.props.beforeMaskedValueChange,n=f.maskOptions,a=n.mask,r=n.prefix;if(f.focused=!0,f.input=e.target,f.mounted=!0,a){if(f.value)getFilledLength(f.maskOptions,f.value)<f.maskOptions.mask.length&&f.setCursorToEnd();else{var i=formatValue(f.maskOptions,r),o=formatValue(f.maskOptions,i),s=getFilledLength(f.maskOptions,o),l=getRightEditablePosition(f.maskOptions,s),u={start:l,end:l};if(isFunction(t)){var c=t({value:o,selection:u},{value:f.value,selection:null},null,f.getBeforeMaskedValueChangeConfig());o=c.value,u=c.selection}var h=o!==e.target.value;h&&(e.target.value=o),f.value=o,h&&isFunction(f.props.onChange)&&f.props.onChange(e),f.setSelection(u.start,u.end)}f.runSaveSelectionLoop()}isFunction(f.props.onFocus)&&f.props.onFocus(e)},f.onBlur=function(e){var t=f.props.beforeMaskedValueChange,n=f.maskOptions.mask;if(f.stopSaveSelectionLoop(),f.focused=!1,n&&!f.props.alwaysShowMask&&isEmpty(f.maskOptions,f.value)){var a="";if(isFunction(t))a=t({value:a,selection:null},{value:f.value,selection:f.previousSelection},null,f.getBeforeMaskedValueChangeConfig()).value;var r=a!==f.getInputValue();r&&f.setInputValue(a),r&&isFunction(f.props.onChange)&&f.props.onChange(e)}isFunction(f.props.onBlur)&&f.props.onBlur(e)},f.onMouseDown=function(t){if(!f.focused&&document.addEventListener){f.mouseDownX=t.clientX,f.mouseDownY=t.clientY,f.mouseDownTime=(new Date).getTime();document.addEventListener("mouseup",function e(t){if(document.removeEventListener("mouseup",e),f.focused){var n=Math.abs(t.clientX-f.mouseDownX),a=Math.abs(t.clientY-f.mouseDownY),r=Math.max(n,a),i=(new Date).getTime()-f.mouseDownTime;(r<=10&&i<=200||r<=5&&i<=300)&&f.setCursorToEnd()}})}isFunction(f.props.onMouseDown)&&f.props.onMouseDown(t)},f.onPaste=function(e){isFunction(f.props.onPaste)&&f.props.onPaste(e),e.defaultPrevented||(f.beforePasteState={value:f.getInputValue(),selection:f.getSelection()},f.setInputValue(""))},f.handleRef=function(e){f.input=f.getInputDOMNode(),null==f.props.children&&isFunction(f.props.inputRef)&&f.props.inputRef(e)};var t=e.mask,n=e.maskChar,a=e.formatChars,r=e.alwaysShowMask,i=e.beforeMaskedValueChange,o=e.defaultValue,s=e.value;f.maskOptions=parseMask(t,n,a),null==o&&(o=""),null==s&&(s=o);var l=getStringValue(s);if(f.maskOptions.mask&&(r||l)&&(l=formatValue(f.maskOptions,l),isFunction(i))){var u=e.value;null==e.value&&(u=o),l=i({value:l,selection:null},{value:u=getStringValue(u),selection:null},null,f.getBeforeMaskedValueChangeConfig()).value}return f.value=l,f}var t=e.prototype;return t.componentDidMount=function(){this.mounted=!0,this.isWindowsPhoneBrowser=isWindowsPhoneBrowser(),this.maskOptions.mask&&this.getInputValue()!==this.value&&this.setInputValue(this.value)},t.componentDidUpdate=function(){var e=this.previousSelection,t=this.props,n=t.beforeMaskedValueChange,a=t.alwaysShowMask,r=t.mask,i=t.maskChar,o=t.formatChars,s=this.maskOptions,l=a||this.isFocused(),u=null!=this.props.value,c=u?getStringValue(this.props.value):this.value,h=e?e.start:null;if(this.maskOptions=parseMask(r,i,o),this.maskOptions.mask){!s.mask&&this.isFocused()&&this.runSaveSelectionLoop();var f=this.maskOptions.mask&&this.maskOptions.mask!==s.mask;if(s.mask||u||(c=this.getInputValue()),(f||this.maskOptions.mask&&(c||l))&&(c=formatValue(this.maskOptions,c)),f){var p=getFilledLength(this.maskOptions,c);(null===h||p<h)&&(h=isFilled(this.maskOptions,c)?p:getRightEditablePosition(this.maskOptions,p))}!this.maskOptions.mask||!isEmpty(this.maskOptions,c)||l||u&&this.props.value||(c="");var m={start:h,end:h};if(isFunction(n)){var d=n({value:c,selection:m},{value:this.value,selection:this.previousSelection},null,this.getBeforeMaskedValueChangeConfig());c=d.value,m=d.selection}this.value=c,this.getInputValue()!==this.value?(this.setInputValue(this.value),this.forceUpdate()):f&&this.forceUpdate();var g=!1;null!=m.start&&null!=m.end&&(g=!e||e.start!==m.start||e.end!==m.end),g&&this.setSelection(m.start,m.end)}else s.mask&&(this.stopSaveSelectionLoop(),this.forceUpdate())},t.componentWillUnmount=function(){this.mounted=!1,null!==this.selectionDeferId&&cancelDefer(this.selectionDeferId),this.stopSaveSelectionLoop()},t.render=function(){var t,e=this.props,n=(e.mask,e.alwaysShowMask,e.maskChar,e.formatChars,e.inputRef,e.beforeMaskedValueChange,e.children),a=_objectWithoutProperties(e,["mask","alwaysShowMask","maskChar","formatChars","inputRef","beforeMaskedValueChange","children"]);if(n){isFunction(n)||invariant_1(!1);var r=["onChange","onPaste","onMouseDown","onFocus","onBlur","value","disabled","readOnly"],i=_extends({},a);r.forEach(function(e){return delete i[e]}),t=n(i),r.filter(function(e){return null!=t.props[e]&&t.props[e]!==a[e]}).length&&invariant_1(!1)}else t=React.createElement("input",_extends({ref:this.handleRef},a));var o={onFocus:this.onFocus,onBlur:this.onBlur};return this.maskOptions.mask&&(a.disabled||a.readOnly||(o.onChange=this.onChange,o.onPaste=this.onPaste,o.onMouseDown=this.onMouseDown),null!=a.value&&(o.value=this.value)),t=React.cloneElement(t,o)},_inheritsLoose(e,c),e}(React.Component);module.exports=InputElement;
"use strict";function _interopDefault(e){return e&&"object"==typeof e&&"default"in e?e["default"]:e}var React=_interopDefault(require("react")),reactDom=require("react-dom");function _defaults2(e,t){for(var n=Object.getOwnPropertyNames(t),a=0;a<n.length;a++){var i=n[a],r=Object.getOwnPropertyDescriptor(t,i);r&&r.configurable&&e[i]===undefined&&Object.defineProperty(e,i,r)}return e}function _extends(){return(_extends=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var a in n)Object.prototype.hasOwnProperty.call(n,a)&&(e[a]=n[a])}return e}).apply(this,arguments)}function _inheritsLoose(e,t){_defaults2(e.prototype,t&&t.prototype),_defaults2(e,t)}function _objectWithoutProperties(e,t){if(null==e)return{};var n,a,i={},r=Object.keys(e);for(a=0;a<r.length;a++)n=r[a],0<=t.indexOf(n)||(i[n]=e[n]);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);for(a=0;a<o.length;a++)n=o[a],0<=t.indexOf(n)||Object.prototype.propertyIsEnumerable.call(e,n)&&(i[n]=e[n])}return i}function _assertThisInitialized(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}var invariant=function(e,t,n,a,i,r,o,s){if(!e){var l;if(t===undefined)l=new Error("Minified exception occurred; use the non-minified dev environment for the full error message and additional helpful warnings.");else{var u=[n,a,i,r,o,s],c=0;(l=new Error(t.replace(/%s/g,function(){return u[c++]}))).name="Invariant Violation"}throw l.framesToPop=1,l}},invariant_1=invariant;function setInputSelection(e,t,n){if("selectionStart"in e&&"selectionEnd"in e)e.selectionStart=t,e.selectionEnd=n;else{var a=e.createTextRange();a.collapse(!0),a.moveStart("character",t),a.moveEnd("character",n-t),a.select()}}function getInputSelection(e){var t=0,n=0;if("selectionStart"in e&&"selectionEnd"in e)t=e.selectionStart,n=e.selectionEnd;else{var a=document.selection.createRange();a.parentElement()===e&&(t=-a.moveStart("character",-e.value.length),n=-a.moveEnd("character",-e.value.length))}return{start:t,end:n,length:n-t}}var defaultFormatChars={9:"[0-9]",a:"[A-Za-z]","*":"[A-Za-z0-9]"},defaultMaskChar="_";function parseMask(e,t,n){var a="",i="",r=null,o=[];if(t===undefined&&(t=defaultMaskChar),null==n&&(n=defaultFormatChars),!e||"string"!=typeof e)return{maskChar:t,formatChars:n,mask:null,prefix:null,lastEditablePosition:null,permanents:[]};var s=!1;return e.split("").forEach(function(e){s||"\\"!==e?(s||!n[e]?(o.push(a.length),a.length===o.length-1&&(i+=e)):r=a.length+1,a+=e,s=!1):s=!0}),{maskChar:t,formatChars:n,prefix:i,mask:a,lastEditablePosition:r,permanents:o}}function isPermanentCharacter(e,t){return-1!==e.permanents.indexOf(t)}function isAllowedCharacter(e,t,n){var a=e.mask,i=e.formatChars;if(!n)return!1;if(isPermanentCharacter(e,t))return a[t]===n;var r=i[a[t]];return new RegExp(r).test(n)}function isEmpty(n,e){return e.split("").every(function(e,t){return isPermanentCharacter(n,t)||!isAllowedCharacter(n,t,e)})}function getFilledLength(e,t){var n=e.maskChar,a=e.prefix;if(!n){for(;t.length>a.length&&isPermanentCharacter(e,t.length-1);)t=t.slice(0,t.length-1);return t.length}for(var i=a.length,r=t.length;r>=a.length;r--){var o=t[r];if(!isPermanentCharacter(e,r)&&isAllowedCharacter(e,r,o)){i=r+1;break}}return i}function isFilled(e,t){return getFilledLength(e,t)===e.mask.length}function formatValue(e,t){var n=e.maskChar,a=e.mask,i=e.prefix;if(!n){for((t=insertString(e,"",t,0)).length<i.length&&(t=i);t.length<a.length&&isPermanentCharacter(e,t.length);)t+=a[t.length];return t}if(t)return insertString(e,formatValue(e,""),t,0);for(var r=0;r<a.length;r++)isPermanentCharacter(e,r)?t+=a[r]:t+=n;return t}function clearRange(n,e,a,t){var i=a+t,r=n.maskChar,o=n.mask,s=n.prefix,l=e.split("");if(!r){for(var u=i;u<l.length;u++)isPermanentCharacter(n,u)&&(l[u]="");return a=Math.max(s.length,a),l.splice(a,i-a),e=l.join(""),formatValue(n,e)}return l.map(function(e,t){return t<a||i<=t?e:isPermanentCharacter(n,t)?o[t]:r}).join("")}function insertString(r,o,e,s){var l=r.mask,u=r.maskChar,c=r.prefix,t=e.split(""),h=isFilled(r,o);return!u&&s>o.length&&(o+=l.slice(o.length,s)),t.every(function(e){for(;i=e,isPermanentCharacter(r,a=s)&&i!==l[a];){if(s>=o.length&&(o+=l[s]),t=e,n=s,u&&isPermanentCharacter(r,n)&&t===u)return!0;if(++s>=l.length)return!1}var t,n,a,i;return!isAllowedCharacter(r,s,e)&&e!==u||(s<o.length?u||h||s<c.length?o=o.slice(0,s)+e+o.slice(s+1):(o=o.slice(0,s)+e+o.slice(s),o=formatValue(r,o)):u||(o+=e),++s<l.length)}),o}function getInsertStringLength(a,e,t,i){var r=a.mask,o=a.maskChar,n=t.split(""),s=i;return n.every(function(e){for(;n=e,isPermanentCharacter(a,t=i)&&n!==r[t];)if(++i>=r.length)return!1;var t,n;return(isAllowedCharacter(a,i,e)||e===o)&&i++,i<r.length}),i-s}function getLeftEditablePosition(e,t){for(var n=t;0<=n;--n)if(!isPermanentCharacter(e,n))return n;return null}function getRightEditablePosition(e,t){for(var n=e.mask,a=t;a<n.length;++a)if(!isPermanentCharacter(e,a))return a;return null}function getStringValue(e){return e||0===e?e+"":""}function processChange(e,t,n,a,i){var r=e.mask,o=e.prefix,s=e.lastEditablePosition,l=t,u="",c=0,h=0,f=Math.min(i.start,n.start);if(n.end>i.start?h=(c=getInsertStringLength(e,a,u=l.slice(i.start,n.end),f))?i.length:0:l.length<a.length&&(h=a.length-l.length),l=a,h){if(1===h&&!i.length)f=i.start===n.start?getRightEditablePosition(e,n.start):getLeftEditablePosition(e,n.start);l=clearRange(e,l,f,h)}return l=insertString(e,l,u,f),(f+=c)>=r.length?f=r.length:f<o.length&&!c?f=o.length:f>=o.length&&f<s&&c&&(f=getRightEditablePosition(e,f)),u||(u=null),{value:l=formatValue(e,l),enteredString:u,selection:{start:f,end:f}}}function isWindowsPhoneBrowser(){var e=new RegExp("windows","i"),t=new RegExp("phone","i"),n=navigator.userAgent;return e.test(n)&&t.test(n)}function isFunction(e){return"function"==typeof e}function getRequestAnimationFrame(){return window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame}function getCancelAnimationFrame(){return window.cancelAnimationFrame||window.webkitCancelRequestAnimationFrame||window.webkitCancelAnimationFrame||window.mozCancelAnimationFrame}function defer(e){return(!!getCancelAnimationFrame()?getRequestAnimationFrame():function(){return setTimeout(e,1e3/60)})(e)}function cancelDefer(e){(getCancelAnimationFrame()||clearTimeout)(e)}var InputElement=function(c){function e(e){var f=c.call(this,e)||this;f.focused=!1,f.mounted=!1,f.previousSelection=null,f.selectionDeferId=null,f.saveSelectionLoopDeferId=null,f.saveSelectionLoop=function(){f.previousSelection=f.getSelection(),f.saveSelectionLoopDeferId=defer(f.saveSelectionLoop)},f.runSaveSelectionLoop=function(){null===f.saveSelectionLoopDeferId&&f.saveSelectionLoop()},f.stopSaveSelectionLoop=function(){null!==f.saveSelectionLoopDeferId&&(cancelDefer(f.saveSelectionLoopDeferId),f.saveSelectionLoopDeferId=null,f.previousSelection=null)},f.getInputDOMNode=function(){if(!f.mounted)return null;var e=reactDom.findDOMNode(_assertThisInitialized(_assertThisInitialized(f))),t="undefined"!=typeof window&&e instanceof window.HTMLElement;if(e&&!t)return null;if("INPUT"!==e.nodeName&&(e=e.querySelector("input")),!e)throw new Error("react-input-mask: inputComponent doesn't contain input node");return e},f.getInputValue=function(){var e=f.getInputDOMNode();return e?e.value:null},f.setInputValue=function(e){var t=f.getInputDOMNode();t&&(f.value=e,t.value=e)},f.setCursorToEnd=function(){var e=getFilledLength(f.maskOptions,f.value),t=getRightEditablePosition(f.maskOptions,e);null!==t&&f.setCursorPosition(t)},f.setSelection=function(e,t,n){void 0===n&&(n={});var a=f.getInputDOMNode();a&&(n.deferred||setInputSelection(a,e,t),null!==f.selectionDeferId&&cancelDefer(f.selectionDeferId),f.selectionDeferId=defer(function(){f.selectionDeferId=null,setInputSelection(a,e,t)}),f.previousSelection={start:e,end:t,length:Math.abs(t-e)})},f.getSelection=function(){return getInputSelection(f.getInputDOMNode())},f.getCursorPosition=function(){return f.getSelection().start},f.setCursorPosition=function(e){f.setSelection(e,e)},f.isFocused=function(){return f.focused},f.getBeforeMaskedValueChangeConfig=function(){var e=f.maskOptions,t=e.mask,n=e.maskChar,a=e.permanents,i=e.formatChars;return{mask:t,maskChar:n,permanents:a,alwaysShowMask:!!f.props.alwaysShowMask,formatChars:i}},f.isInputAutofilled=function(e,t,n,a){var i=f.getInputDOMNode();try{if(i.matches(":-webkit-autofill"))return!0}catch(r){}return!f.focused||a.end<n.length&&t.end===e.length},f.onChange=function(e){var t=_assertThisInitialized(_assertThisInitialized(f)).beforePasteState,n=_assertThisInitialized(_assertThisInitialized(f)).previousSelection,a=f.props.beforeMaskedValueChange,i=f.getInputValue(),r=f.value,o=f.getSelection();f.isInputAutofilled(i,o,r,n)&&(r=formatValue(f.maskOptions,""),n={start:0,end:0,length:0}),t&&(n=t.selection,r=t.value,o={start:n.start+i.length,end:n.start+i.length,length:0},i=r.slice(0,n.start)+i+r.slice(n.end),f.beforePasteState=null);var s=processChange(f.maskOptions,i,o,r,n),l=s.enteredString,u=s.selection,c=s.value;if(isFunction(a)){var h=a({value:c,selection:u},{value:r,selection:n},l,f.getBeforeMaskedValueChangeConfig());c=h.value,u=h.selection}f.setInputValue(c),isFunction(f.props.onChange)&&f.props.onChange(e),f.isWindowsPhoneBrowser?f.setSelection(u.start,u.end,{deferred:!0}):f.setSelection(u.start,u.end)},f.onFocus=function(e){var t=f.props.beforeMaskedValueChange,n=f.maskOptions,a=n.mask,i=n.prefix;if(f.focused=!0,f.mounted=!0,a){if(f.value)getFilledLength(f.maskOptions,f.value)<f.maskOptions.mask.length&&f.setCursorToEnd();else{var r=formatValue(f.maskOptions,i),o=formatValue(f.maskOptions,r),s=getFilledLength(f.maskOptions,o),l=getRightEditablePosition(f.maskOptions,s),u={start:l,end:l};if(isFunction(t)){var c=t({value:o,selection:u},{value:f.value,selection:null},null,f.getBeforeMaskedValueChangeConfig());o=c.value,u=c.selection}var h=o!==f.getInputValue();h&&f.setInputValue(o),h&&isFunction(f.props.onChange)&&f.props.onChange(e),f.setSelection(u.start,u.end)}f.runSaveSelectionLoop()}isFunction(f.props.onFocus)&&f.props.onFocus(e)},f.onBlur=function(e){var t=f.props.beforeMaskedValueChange,n=f.maskOptions.mask;if(f.stopSaveSelectionLoop(),f.focused=!1,n&&!f.props.alwaysShowMask&&isEmpty(f.maskOptions,f.value)){var a="";if(isFunction(t))a=t({value:a,selection:null},{value:f.value,selection:f.previousSelection},null,f.getBeforeMaskedValueChangeConfig()).value;var i=a!==f.getInputValue();i&&f.setInputValue(a),i&&isFunction(f.props.onChange)&&f.props.onChange(e)}isFunction(f.props.onBlur)&&f.props.onBlur(e)},f.onMouseDown=function(t){if(!f.focused&&document.addEventListener){f.mouseDownX=t.clientX,f.mouseDownY=t.clientY,f.mouseDownTime=(new Date).getTime();document.addEventListener("mouseup",function e(t){if(document.removeEventListener("mouseup",e),f.focused){var n=Math.abs(t.clientX-f.mouseDownX),a=Math.abs(t.clientY-f.mouseDownY),i=Math.max(n,a),r=(new Date).getTime()-f.mouseDownTime;(i<=10&&r<=200||i<=5&&r<=300)&&f.setCursorToEnd()}})}isFunction(f.props.onMouseDown)&&f.props.onMouseDown(t)},f.onPaste=function(e){isFunction(f.props.onPaste)&&f.props.onPaste(e),e.defaultPrevented||(f.beforePasteState={value:f.getInputValue(),selection:f.getSelection()},f.setInputValue(""))},f.handleRef=function(e){null==f.props.children&&isFunction(f.props.inputRef)&&f.props.inputRef(e)};var t=e.mask,n=e.maskChar,a=e.formatChars,i=e.alwaysShowMask,r=e.beforeMaskedValueChange,o=e.defaultValue,s=e.value;f.maskOptions=parseMask(t,n,a),null==o&&(o=""),null==s&&(s=o);var l=getStringValue(s);if(f.maskOptions.mask&&(i||l)&&(l=formatValue(f.maskOptions,l),isFunction(r))){var u=e.value;null==e.value&&(u=o),l=r({value:l,selection:null},{value:u=getStringValue(u),selection:null},null,f.getBeforeMaskedValueChangeConfig()).value}return f.value=l,f}var t=e.prototype;return t.componentDidMount=function(){this.mounted=!0,this.getInputDOMNode()&&(this.isWindowsPhoneBrowser=isWindowsPhoneBrowser(),this.maskOptions.mask&&this.getInputValue()!==this.value&&this.setInputValue(this.value))},t.componentDidUpdate=function(){var e=this.previousSelection,t=this.props,n=t.beforeMaskedValueChange,a=t.alwaysShowMask,i=t.mask,r=t.maskChar,o=t.formatChars,s=this.maskOptions,l=a||this.isFocused(),u=null!=this.props.value,c=u?getStringValue(this.props.value):this.value,h=e?e.start:null;if(this.maskOptions=parseMask(i,r,o),this.maskOptions.mask){!s.mask&&this.isFocused()&&this.runSaveSelectionLoop();var f=this.maskOptions.mask&&this.maskOptions.mask!==s.mask;if(s.mask||u||(c=this.getInputValue()),(f||this.maskOptions.mask&&(c||l))&&(c=formatValue(this.maskOptions,c)),f){var p=getFilledLength(this.maskOptions,c);(null===h||p<h)&&(h=isFilled(this.maskOptions,c)?p:getRightEditablePosition(this.maskOptions,p))}!this.maskOptions.mask||!isEmpty(this.maskOptions,c)||l||u&&this.props.value||(c="");var d={start:h,end:h};if(isFunction(n)){var m=n({value:c,selection:d},{value:this.value,selection:this.previousSelection},null,this.getBeforeMaskedValueChangeConfig());c=m.value,d=m.selection}this.value=c,this.getInputValue()!==this.value?(this.setInputValue(this.value),this.forceUpdate()):f&&this.forceUpdate();var g=!1;null!=d.start&&null!=d.end&&(g=!e||e.start!==d.start||e.end!==d.end),g&&this.setSelection(d.start,d.end)}else s.mask&&(this.stopSaveSelectionLoop(),this.forceUpdate())},t.componentWillUnmount=function(){this.mounted=!1,null!==this.selectionDeferId&&cancelDefer(this.selectionDeferId),this.stopSaveSelectionLoop()},t.render=function(){var t,e=this.props,n=(e.mask,e.alwaysShowMask,e.maskChar,e.formatChars,e.inputRef,e.beforeMaskedValueChange,e.children),a=_objectWithoutProperties(e,["mask","alwaysShowMask","maskChar","formatChars","inputRef","beforeMaskedValueChange","children"]);if(n){isFunction(n)||invariant_1(!1);var i=["onChange","onPaste","onMouseDown","onFocus","onBlur","value","disabled","readOnly"],r=_extends({},a);i.forEach(function(e){return delete r[e]}),t=n(r),i.filter(function(e){return null!=t.props[e]&&t.props[e]!==a[e]}).length&&invariant_1(!1)}else t=React.createElement("input",_extends({ref:this.handleRef},a));var o={onFocus:this.onFocus,onBlur:this.onBlur};return this.maskOptions.mask&&(a.disabled||a.readOnly||(o.onChange=this.onChange,o.onPaste=this.onPaste,o.onMouseDown=this.onMouseDown),null!=a.value&&(o.value=this.value)),t=React.cloneElement(t,o)},_inheritsLoose(e,c),e}(React.Component);module.exports=InputElement;
{
"name": "react-input-mask",
"description": "Masked input component for React",
"version": "2.0.2",
"version": "2.0.3",
"homepage": "https://github.com/sanniassin/react-input-mask",

@@ -6,0 +6,0 @@ "license": "MIT",

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