Socket
Socket
Sign inDemoInstall

react-input-mask

Package Overview
Dependencies
Maintainers
1
Versions
90
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-input-mask - npm Package Compare versions

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

86

dist/react-input-mask.js

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

function _defaults2(obj, defaults) { var keys = Object.getOwnPropertyNames(defaults); for (var i = 0; i < keys.length; i++) { var key = keys[i]; var value = Object.getOwnPropertyDescriptor(defaults, key); if (value && value.configurable && obj[key] === undefined) { Object.defineProperty(obj, key, value); } } return obj; }
function _defineProperty(obj, key, value) {

@@ -63,4 +65,5 @@ if (key in obj) {

function _inheritsLoose(subClass, superClass) {
subClass.prototype.__proto__ = superClass && superClass.prototype;
subClass.__proto__ = superClass;
_defaults2(subClass.prototype, superClass && superClass.prototype);
_defaults2(subClass, superClass);
}

@@ -464,4 +467,7 @@

_this = _React$Component.call(this, props) || this;
_this.focused = false;
_this.mounted = false;
_this.previousSelection = null;
_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_assertThisInitialized(_assertThisInitialized(_this)), "focused", false), "mounted", false), "previousSelection", null), "saveSelectionLoop", function () {
_this.saveSelectionLoop = function () {
if (!_this.mounted || !_this.maskOptions.mask || !_this.focused || _this.saveSelectionLoopRunning) {

@@ -478,3 +484,5 @@ return;

}, 1000 / 60);
}), "getInputDOMNode", function () {
};
_this.getInputDOMNode = function () {
var input = _this.input;

@@ -492,3 +500,5 @@

return React.findDOMNode(input);
}), "getInputValue", function () {
};
_this.getInputValue = function () {
var input = _this.getInputDOMNode();

@@ -501,3 +511,5 @@

return input.value;
}), "setInputValue", function (value) {
};
_this.setInputValue = function (value) {
var input = _this.getInputDOMNode();

@@ -511,3 +523,5 @@

input.value = value;
}), "setCursorToEnd", function () {
};
_this.setCursorToEnd = function () {
var filledLen = getFilledLength(_this.maskOptions, _this.value);

@@ -519,3 +533,5 @@ var pos = getRightEditablePos(_this.maskOptions, filledLen);

}
}), "setSelection", function (start, end) {
};
_this.setSelection = function (start, end) {
var input = _this.getInputDOMNode();

@@ -536,13 +552,23 @@

};
}), "getSelection", function () {
};
_this.getSelection = function () {
var input = _this.getInputDOMNode();
return getInputSelection(input);
}), "getCursorPos", function () {
};
_this.getCursorPos = function () {
return _this.getSelection().start;
}), "setCursorPos", function (pos) {
};
_this.setCursorPos = function (pos) {
_this.setSelection(pos, pos);
}), "isFocused", function () {
};
_this.isFocused = function () {
return _this.focused;
}), "getModifyMaskedValueConfig", function () {
};
_this.getModifyMaskedValueConfig = function () {
var _this$maskOptions = _this.maskOptions,

@@ -561,3 +587,5 @@ mask = _this$maskOptions.mask,

};
}), "isInputAutofilled", function () {
};
_this.isInputAutofilled = function () {
var input = _this.getInputDOMNode();

@@ -574,3 +602,5 @@

return isAutofilled;
}), "onChange", function (event) {
};
_this.onChange = function (event) {
var _assertThisInitialize = _assertThisInitialized(_assertThisInitialized(_this)),

@@ -705,3 +735,5 @@ beforePasteState = _assertThisInitialize.beforePasteState,

}
}), "onFocus", function (event) {
};
_this.onFocus = function (event) {
var beforeMaskedValueChange = _this.props.beforeMaskedValueChange;

@@ -713,2 +745,6 @@ var _this$maskOptions3 = _this.maskOptions,

if (!_this.input) {
_this.input = event.target;
}
if (mask) {

@@ -762,3 +798,5 @@ if (!_this.value) {

}
}), "onBlur", function (event) {
};
_this.onBlur = function (event) {
var beforeMaskedValueChange = _this.props.beforeMaskedValueChange;

@@ -797,3 +835,5 @@ var mask = _this.maskOptions.mask;

}
}), "onMouseDown", function (event) {
};
_this.onMouseDown = function (event) {
// tiny unintentional mouse movements can break cursor

@@ -832,3 +872,5 @@ // position on focus, so we have to restore it in that case

}
}), "onPaste", function (event) {
};
_this.onPaste = function (event) {
if (isFunction(_this.props.onPaste)) {

@@ -848,3 +890,5 @@ _this.props.onPaste(event);

}
}), "handleRef", function (ref) {
};
_this.handleRef = function (ref) {
_this.input = ref;

@@ -855,3 +899,3 @@

}
});
};

@@ -858,0 +902,0 @@ var _mask = props.mask,

@@ -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,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function n(){return(n=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 s(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function a(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 o={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=o),!e||"string"!=typeof e)return{maskChar:t,formatChars:n,mask:null,prefix:null,lastEditablePos:null,permanents:[]};var s="",a="",i=[],u=!1,l=null;return e.split("").forEach(function(e){u||"\\"!==e?(u||!n[e]?(i.push(s.length),s.length===i.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:i}}function u(e,t){return-1!==e.permanents.indexOf(t)}function l(e,t,n){var s=e.mask,a=e.formatChars;if(!n)return!1;if(u(e,t))return s[t]===n;var o=a[s[t]];return new RegExp(o).test(n)}function p(e,t){return t.split("").every(function(t,n){return u(e,n)||!l(e,n,t)})}function c(e,t){var n=e.maskChar,s=e.prefix;if(!n){for(;t.length>s.length&&u(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(!u(e,o)&&l(e,o,r)){a=o+1;break}}return a}function h(e,t){return c(e,t)===e.mask.length}function f(e,t){var n=e.maskChar,s=e.mask,a=e.prefix;if(!n){for((t=m(e,"",t,0)).length<a.length&&(t=a);t.length<s.length&&u(e,t.length);)t+=s[t.length];return t}if(t)return m(e,f(e,""),t,0);for(var o=0;o<s.length;o++)u(e,o)?t+=s[o]:t+=n;return t}function m(e,t,n,s){var a=e.mask,o=e.maskChar,r=e.prefix,i=n.split(""),p=h(e,t),c=function(t,n){return!o||!u(e,n)||t!==o};return!o&&s>t.length&&(t+=a.slice(t.length,s)),i.every(function(n){for(;h=n,u(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!l(e,s,n)&&n!==o||(s<t.length?o||p||s<r.length?t=t.slice(0,s)+n+t.slice(s+1):(t=t.slice(0,s)+n+t.slice(s),t=f(e,t)):o||(t+=n),++s<a.length)}),t}function v(e,t){for(var n=e.mask,s=t;s<n.length;++s)if(!u(e,s))return s;return null}function g(e){return e||0===e?e+"":""}function d(e){return"function"==typeof e}function k(e,t){return void 0===t&&(t=0),(window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||function(){return setTimeout(e,t)})(e)}return function(o){function r(n){var r;t(t(t(t(t(t(t(t(t(t(t(t(t(t(t(t(t(t(t(t(t(s(s(r=o.call(this,n)||this)),"focused",!1),"mounted",!1),"previousSelection",null),"saveSelectionLoop",function(){r.mounted&&r.maskOptions.mask&&r.focused&&!r.saveSelectionLoopRunning&&(r.saveSelectionLoopRunning=!0,r.previousSelection=r.getSelection(),k(function(){r.saveSelectionLoopRunning=!1,r.saveSelectionLoop()},1e3/60))}),"getInputDOMNode",function(){var t,n=r.input;return n?(t=n,("object"==typeof HTMLElement?t instanceof HTMLElement:1===t.nodeType&&"string"==typeof t.nodeName)?n:e.findDOMNode(n)):null}),"getInputValue",function(){var e=r.getInputDOMNode();return e?e.value:null}),"setInputValue",function(e){var t=r.getInputDOMNode();t&&(r.value=e,t.value=e)}),"setCursorToEnd",function(){var e=c(r.maskOptions,r.value),t=v(r.maskOptions,e);null!==t&&r.setCursorPos(t)}),"setSelection",function(e,t){var n=r.getInputDOMNode();n&&(a(n,e,t),k(function(){a(n,e,t)}),r.previousSelection={start:e,end:t,length:Math.abs(t-e)})}),"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}}(r.getInputDOMNode())}),"getCursorPos",function(){return r.getSelection().start}),"setCursorPos",function(e){r.setSelection(e,e)}),"isFocused",function(){return r.focused}),"getModifyMaskedValueConfig",function(){var e=r.maskOptions,t=e.mask,n=e.maskChar,s=e.permanents,a=e.formatChars;return{mask:t,maskChar:n,permanents:s,alwaysShowMask:!!r.props.alwaysShowMask,formatChars:a}}),"isInputAutofilled",function(){var e=r.getInputDOMNode(),t=!1;try{d(e.matches)&&e.matches(":-webkit-autofill")&&(t=!0)}catch(n){}return t}),"onChange",function(e){var n=s(s(r)),o=n.beforePasteState,i=n.previousSelection,p=r.props.beforeMaskedValueChange,c=r.maskOptions,h=c.mask,g=c.prefix,O=c.lastEditablePos,w=r.getInputValue(),y=r.value;r.isInputAutofilled()&&(y=f(r.maskOptions,""),i={start:0,end:0,length:0});var b="",C=r.getSelection(),S=C.end;C.start=C.end,C.length=0,o&&(i=o.selection,y=o.value,C={start:S=i.start+w.length,end:S,length:0},w=y.slice(0,i.start)+w+y.slice(i.end),r.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,u(e,n=s)&&r!==a[n];)if(++s>=a.length)return!1;var n,r;return(l(e,s,t)||t===o)&&s++,s<a.length}),s-i}(r.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?v(r.maskOptions,C.start):function(e,t){for(var n=t;n>=0;--n)if(!u(e,n))return n;return null}(r.maskOptions,C.start);w=function(e,t,n,s){var a=n+s,o=e.maskChar,r=e.mask,i=e.prefix,l=t.split("");if(!o){for(var p=a;p<l.length;p++)u(e,p)&&(l[p]="");return n=Math.max(i.length,n),l.splice(n,a-n),t=l.join(""),f(e,t)}return l.map(function(t,s){return s<n||s>=a?t:u(e,s)?r[s]:o}).join("")}(r.maskOptions,w,S,V)}w=m(r.maskOptions,w,b,S),(S+=M)>=h.length?S=h.length:S<g.length&&!M?S=g.length:S>=g.length&&S<O&&M&&(S=v(r.maskOptions,S)),w=f(r.maskOptions,w),b||(b=null);var E={start:S,end:S};if(d(p)){var I=p({value:w,selection:E},{value:y,selection:i},b,r.getModifyMaskedValueConfig());w=I.value,E=I.selection}r.setInputValue(w),d(r.props.onChange)&&r.props.onChange(e),r.isWindowsPhoneBrowser?k(function(){r.mounted&&r.isFocused()&&(a(r.getInputDOMNode(),E.start,E.end),r.previousSelection=function(e){for(var n=1;n<arguments.length;n++){var s=null!=arguments[n]?arguments[n]:{},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(n){t(e,n,s[n])})}return e}({},E,{length:E.end-E.start}))}):r.setSelection(E.start,E.end)}),"onFocus",function(e){var t=r.props.beforeMaskedValueChange,n=r.maskOptions,s=n.mask,a=n.prefix;if(r.focused=!0,s)if(r.value)c(r.maskOptions,r.value)<r.maskOptions.mask.length&&r.setCursorToEnd();else{var o=f(r.maskOptions,a),i=f(r.maskOptions,o),u=c(r.maskOptions,i),l=v(r.maskOptions,u),p={start:l,end:l};if(d(t)){var h=t({value:i,selection:p},{value:r.value,selection:null},null,r.getModifyMaskedValueConfig());i=h.value,p=h.selection}var m=i!==e.target.value;m&&(e.target.value=i),r.value=i,m&&d(r.props.onChange)&&r.props.onChange(e),r.setSelection(p.start,p.end)}r.saveSelectionLoop(),d(r.props.onFocus)&&r.props.onFocus(e)}),"onBlur",function(e){var t=r.props.beforeMaskedValueChange,n=r.maskOptions.mask;if(r.previousSelection=null,r.focused=!1,n&&!r.props.alwaysShowMask&&p(r.maskOptions,r.value)){var s="";if(d(t))s=t({value:s,selection:null},{value:r.value,selection:r.previousSelection},null,r.getModifyMaskedValueConfig()).value;var a=s!==r.getInputValue();a&&r.setInputValue(s),a&&d(r.props.onChange)&&r.props.onChange(e)}d(r.props.onBlur)&&r.props.onBlur(e)}),"onMouseDown",function(e){if(!r.focused&&document.addEventListener){r.mouseDownX=e.clientX,r.mouseDownY=e.clientY,r.mouseDownTime=(new Date).getTime();document.addEventListener("mouseup",function t(e){if(document.removeEventListener("mouseup",t),r.focused){var n=Math.abs(e.clientX-r.mouseDownX),s=Math.abs(e.clientY-r.mouseDownY),a=Math.max(n,s),o=(new Date).getTime()-r.mouseDownTime;(a<=10&&o<=200||a<=5&&o<=300)&&r.setCursorToEnd()}})}d(r.props.onMouseDown)&&r.props.onMouseDown(e)}),"onPaste",function(e){d(r.props.onPaste)&&r.props.onPaste(e),e.defaultPrevented||(r.beforePasteState={value:r.getInputValue(),selection:r.getSelection()},r.setInputValue(""))}),"handleRef",function(e){r.input=e,d(r.props.inputRef)&&r.props.inputRef(e)});var h=n.mask,O=n.maskChar,w=n.formatChars,y=n.defaultValue,b=n.value,C=n.alwaysShowMask;return r.hasValue=null!=b,r.maskOptions=i(h,O,w),null==y&&(y=""),null==b&&(b=y),b=g(b),r.maskOptions.mask&&(C||b)&&(b=f(r.maskOptions,b)),r.value=b,r}var O,w,y=r.prototype;return y.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.")},y.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.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?g(this.props.value):this.value;if(n.mask||this.hasValue||(r=this.getInputValue()),(a||this.maskOptions.mask&&(r||o))&&(r=f(this.maskOptions,r),a)){var u=c(this.maskOptions,r);(null===s||u<s)&&(s=h(this.maskOptions,r)?u:v(this.maskOptions,u)),n.mask||this.saveSelectionLoop()}!this.maskOptions.mask||!p(this.maskOptions,r)||o||this.hasValue&&this.props.value||(r="");var l={start:s,end:s};if(d(t)){var m=t({value:r,selection:l},{value:this.value,selection:this.previousSelection},null,this.getModifyMaskedValueConfig());r=m.value,l=m.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)},y.componentWillUnmount=function(){this.mounted=!1},y.render=function(){var t=this,s=this.props,a=(s.mask,s.alwaysShowMask,s.maskChar,s.formatChars,s.inputRef,s.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}(s,["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",n({ref:this.handleRef},a,{onFocus:this.onFocus,onBlur:this.onBlur}))},w=o,(O=r).prototype.__proto__=w&&w.prototype,O.__proto__=w,r}((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),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)});

@@ -7,2 +7,4 @@ 'use strict';

function _defaults2(obj, defaults) { var keys = Object.getOwnPropertyNames(defaults); for (var i = 0; i < keys.length; i++) { var key = keys[i]; var value = Object.getOwnPropertyDescriptor(defaults, key); if (value && value.configurable && obj[key] === undefined) { Object.defineProperty(obj, key, value); } } return obj; }
function _defineProperty(obj, key, value) {

@@ -61,4 +63,5 @@ if (key in obj) {

function _inheritsLoose(subClass, superClass) {
subClass.prototype.__proto__ = superClass && superClass.prototype;
subClass.__proto__ = superClass;
_defaults2(subClass.prototype, superClass && superClass.prototype);
_defaults2(subClass, superClass);
}

@@ -462,4 +465,7 @@

_this = _React$Component.call(this, props) || this;
_this.focused = false;
_this.mounted = false;
_this.previousSelection = null;
_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_assertThisInitialized(_assertThisInitialized(_this)), "focused", false), "mounted", false), "previousSelection", null), "saveSelectionLoop", function () {
_this.saveSelectionLoop = function () {
if (!_this.mounted || !_this.maskOptions.mask || !_this.focused || _this.saveSelectionLoopRunning) {

@@ -476,3 +482,5 @@ return;

}, 1000 / 60);
}), "getInputDOMNode", function () {
};
_this.getInputDOMNode = function () {
var input = _this.input;

@@ -490,3 +498,5 @@

return React.findDOMNode(input);
}), "getInputValue", function () {
};
_this.getInputValue = function () {
var input = _this.getInputDOMNode();

@@ -499,3 +509,5 @@

return input.value;
}), "setInputValue", function (value) {
};
_this.setInputValue = function (value) {
var input = _this.getInputDOMNode();

@@ -509,3 +521,5 @@

input.value = value;
}), "setCursorToEnd", function () {
};
_this.setCursorToEnd = function () {
var filledLen = getFilledLength(_this.maskOptions, _this.value);

@@ -517,3 +531,5 @@ var pos = getRightEditablePos(_this.maskOptions, filledLen);

}
}), "setSelection", function (start, end) {
};
_this.setSelection = function (start, end) {
var input = _this.getInputDOMNode();

@@ -534,13 +550,23 @@

};
}), "getSelection", function () {
};
_this.getSelection = function () {
var input = _this.getInputDOMNode();
return getInputSelection(input);
}), "getCursorPos", function () {
};
_this.getCursorPos = function () {
return _this.getSelection().start;
}), "setCursorPos", function (pos) {
};
_this.setCursorPos = function (pos) {
_this.setSelection(pos, pos);
}), "isFocused", function () {
};
_this.isFocused = function () {
return _this.focused;
}), "getModifyMaskedValueConfig", function () {
};
_this.getModifyMaskedValueConfig = function () {
var _this$maskOptions = _this.maskOptions,

@@ -559,3 +585,5 @@ mask = _this$maskOptions.mask,

};
}), "isInputAutofilled", function () {
};
_this.isInputAutofilled = function () {
var input = _this.getInputDOMNode();

@@ -572,3 +600,5 @@

return isAutofilled;
}), "onChange", function (event) {
};
_this.onChange = function (event) {
var _assertThisInitialize = _assertThisInitialized(_assertThisInitialized(_this)),

@@ -703,3 +733,5 @@ beforePasteState = _assertThisInitialize.beforePasteState,

}
}), "onFocus", function (event) {
};
_this.onFocus = function (event) {
var beforeMaskedValueChange = _this.props.beforeMaskedValueChange;

@@ -711,2 +743,6 @@ var _this$maskOptions3 = _this.maskOptions,

if (!_this.input) {
_this.input = event.target;
}
if (mask) {

@@ -760,3 +796,5 @@ if (!_this.value) {

}
}), "onBlur", function (event) {
};
_this.onBlur = function (event) {
var beforeMaskedValueChange = _this.props.beforeMaskedValueChange;

@@ -795,3 +833,5 @@ var mask = _this.maskOptions.mask;

}
}), "onMouseDown", function (event) {
};
_this.onMouseDown = function (event) {
// tiny unintentional mouse movements can break cursor

@@ -830,3 +870,5 @@ // position on focus, so we have to restore it in that case

}
}), "onPaste", function (event) {
};
_this.onPaste = function (event) {
if (isFunction(_this.props.onPaste)) {

@@ -846,3 +888,5 @@ _this.props.onPaste(event);

}
}), "handleRef", function (ref) {
};
_this.handleRef = function (ref) {
_this.input = ref;

@@ -853,3 +897,3 @@

}
});
};

@@ -856,0 +900,0 @@ var _mask = props.mask,

{
"name": "react-input-mask",
"description": "Masked input component for React",
"version": "2.0.0-beta.0",
"version": "2.0.0-beta.1",
"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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc