Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-input-mask

Package Overview
Dependencies
Maintainers
1
Versions
90
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-input-mask - npm Package Compare versions

Comparing version 1.0.3 to 1.0.4

49

dist/react-input-mask.js

@@ -371,2 +371,3 @@ (function (global, factory) {

this.lastCursorPos = null;
this.focused = false;

@@ -557,3 +558,3 @@ this.componentDidMount = function () {

this.isFocused = function () {
return document.activeElement === _this2.getInputDOMNode();
return _this2.focused;
};

@@ -707,24 +708,28 @@

this.onFocus = function (event) {
if (!_this2.value) {
var prefix = _this2.maskOptions.prefix;
var value = formatValue(_this2.maskOptions, prefix);
var inputValue = formatValue(_this2.maskOptions, value);
_this2.focused = true;
// do not use this.getInputValue and this.setInputValue as this.input
// can be undefined at this moment if autoFocus attribute is set
var isInputValueChanged = inputValue !== event.target.value;
if (_this2.maskOptions.mask) {
if (!_this2.value) {
var prefix = _this2.maskOptions.prefix;
var value = formatValue(_this2.maskOptions, prefix);
var inputValue = formatValue(_this2.maskOptions, value);
if (isInputValueChanged) {
event.target.value = inputValue;
}
// do not use this.getInputValue and this.setInputValue as this.input
// can be undefined at this moment if autoFocus attribute is set
var isInputValueChanged = inputValue !== event.target.value;
_this2.value = inputValue;
if (isInputValueChanged) {
event.target.value = inputValue;
}
if (isInputValueChanged && typeof _this2.props.onChange === 'function') {
_this2.props.onChange(event);
_this2.value = inputValue;
if (isInputValueChanged && typeof _this2.props.onChange === 'function') {
_this2.props.onChange(event);
}
_this2.setCursorToEnd();
} else if (getFilledLength(_this2.maskOptions, _this2.value) < _this2.maskOptions.mask.length) {
_this2.setCursorToEnd();
}
_this2.setCursorToEnd();
} else if (getFilledLength(_this2.maskOptions, _this2.value) < _this2.maskOptions.mask.length) {
_this2.setCursorToEnd();
}

@@ -738,3 +743,5 @@

this.onBlur = function (event) {
if (!_this2.props.alwaysShowMask && isEmpty(_this2.maskOptions, _this2.value)) {
_this2.focused = false;
if (_this2.maskOptions.mask && !_this2.props.alwaysShowMask && isEmpty(_this2.maskOptions, _this2.value)) {
var inputValue = '';

@@ -801,3 +808,3 @@ var isInputValueChanged = inputValue !== _this2.getInputValue();

if (!props.disabled && !props.readOnly) {
var handlersKeys = ['onFocus', 'onBlur', 'onChange', 'onKeyDown', 'onPaste'];
var handlersKeys = ['onChange', 'onKeyDown', 'onPaste'];
handlersKeys.forEach(function (key) {

@@ -815,3 +822,3 @@ props[key] = _this2[key];

return _this2.input = _ref;
} }, props));
} }, props, { onFocus: _this2.onFocus, onBlur: _this2.onBlur }));
};

@@ -818,0 +825,0 @@ };

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

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

@@ -66,2 +66,3 @@ var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };

this.lastCursorPos = null;
this.focused = false;

@@ -252,3 +253,3 @@ this.componentDidMount = function () {

this.isFocused = function () {
return document.activeElement === _this2.getInputDOMNode();
return _this2.focused;
};

@@ -402,24 +403,28 @@

this.onFocus = function (event) {
if (!_this2.value) {
var prefix = _this2.maskOptions.prefix;
var value = formatValue(_this2.maskOptions, prefix);
var inputValue = formatValue(_this2.maskOptions, value);
_this2.focused = true;
// do not use this.getInputValue and this.setInputValue as this.input
// can be undefined at this moment if autoFocus attribute is set
var isInputValueChanged = inputValue !== event.target.value;
if (_this2.maskOptions.mask) {
if (!_this2.value) {
var prefix = _this2.maskOptions.prefix;
var value = formatValue(_this2.maskOptions, prefix);
var inputValue = formatValue(_this2.maskOptions, value);
if (isInputValueChanged) {
event.target.value = inputValue;
}
// do not use this.getInputValue and this.setInputValue as this.input
// can be undefined at this moment if autoFocus attribute is set
var isInputValueChanged = inputValue !== event.target.value;
_this2.value = inputValue;
if (isInputValueChanged) {
event.target.value = inputValue;
}
if (isInputValueChanged && typeof _this2.props.onChange === 'function') {
_this2.props.onChange(event);
_this2.value = inputValue;
if (isInputValueChanged && typeof _this2.props.onChange === 'function') {
_this2.props.onChange(event);
}
_this2.setCursorToEnd();
} else if (getFilledLength(_this2.maskOptions, _this2.value) < _this2.maskOptions.mask.length) {
_this2.setCursorToEnd();
}
_this2.setCursorToEnd();
} else if (getFilledLength(_this2.maskOptions, _this2.value) < _this2.maskOptions.mask.length) {
_this2.setCursorToEnd();
}

@@ -433,3 +438,5 @@

this.onBlur = function (event) {
if (!_this2.props.alwaysShowMask && isEmpty(_this2.maskOptions, _this2.value)) {
_this2.focused = false;
if (_this2.maskOptions.mask && !_this2.props.alwaysShowMask && isEmpty(_this2.maskOptions, _this2.value)) {
var inputValue = '';

@@ -496,3 +503,3 @@ var isInputValueChanged = inputValue !== _this2.getInputValue();

if (!props.disabled && !props.readOnly) {
var handlersKeys = ['onFocus', 'onBlur', 'onChange', 'onKeyDown', 'onPaste'];
var handlersKeys = ['onChange', 'onKeyDown', 'onPaste'];
handlersKeys.forEach(function (key) {

@@ -510,3 +517,3 @@ props[key] = _this2[key];

return _this2.input = _ref;
} }, props));
} }, props, { onFocus: _this2.onFocus, onBlur: _this2.onBlur }));
};

@@ -513,0 +520,0 @@ };

@@ -83,2 +83,3 @@ 'use strict';

this.lastCursorPos = null;
this.focused = false;

@@ -269,3 +270,3 @@ this.componentDidMount = function () {

this.isFocused = function () {
return document.activeElement === _this2.getInputDOMNode();
return _this2.focused;
};

@@ -419,24 +420,28 @@

this.onFocus = function (event) {
if (!_this2.value) {
var prefix = _this2.maskOptions.prefix;
var value = (0, _string.formatValue)(_this2.maskOptions, prefix);
var inputValue = (0, _string.formatValue)(_this2.maskOptions, value);
_this2.focused = true;
// do not use this.getInputValue and this.setInputValue as this.input
// can be undefined at this moment if autoFocus attribute is set
var isInputValueChanged = inputValue !== event.target.value;
if (_this2.maskOptions.mask) {
if (!_this2.value) {
var prefix = _this2.maskOptions.prefix;
var value = (0, _string.formatValue)(_this2.maskOptions, prefix);
var inputValue = (0, _string.formatValue)(_this2.maskOptions, value);
if (isInputValueChanged) {
event.target.value = inputValue;
}
// do not use this.getInputValue and this.setInputValue as this.input
// can be undefined at this moment if autoFocus attribute is set
var isInputValueChanged = inputValue !== event.target.value;
_this2.value = inputValue;
if (isInputValueChanged) {
event.target.value = inputValue;
}
if (isInputValueChanged && typeof _this2.props.onChange === 'function') {
_this2.props.onChange(event);
_this2.value = inputValue;
if (isInputValueChanged && typeof _this2.props.onChange === 'function') {
_this2.props.onChange(event);
}
_this2.setCursorToEnd();
} else if ((0, _string.getFilledLength)(_this2.maskOptions, _this2.value) < _this2.maskOptions.mask.length) {
_this2.setCursorToEnd();
}
_this2.setCursorToEnd();
} else if ((0, _string.getFilledLength)(_this2.maskOptions, _this2.value) < _this2.maskOptions.mask.length) {
_this2.setCursorToEnd();
}

@@ -450,3 +455,5 @@

this.onBlur = function (event) {
if (!_this2.props.alwaysShowMask && (0, _string.isEmpty)(_this2.maskOptions, _this2.value)) {
_this2.focused = false;
if (_this2.maskOptions.mask && !_this2.props.alwaysShowMask && (0, _string.isEmpty)(_this2.maskOptions, _this2.value)) {
var inputValue = '';

@@ -513,3 +520,3 @@ var isInputValueChanged = inputValue !== _this2.getInputValue();

if (!props.disabled && !props.readOnly) {
var handlersKeys = ['onFocus', 'onBlur', 'onChange', 'onKeyDown', 'onPaste'];
var handlersKeys = ['onChange', 'onKeyDown', 'onPaste'];
handlersKeys.forEach(function (key) {

@@ -527,3 +534,3 @@ props[key] = _this2[key];

return _this2.input = _ref;
} }, props));
} }, props, { onFocus: _this2.onFocus, onBlur: _this2.onBlur }));
};

@@ -530,0 +537,0 @@ };

{
"name": "react-input-mask",
"description": "Masked input component for React",
"version": "1.0.3",
"version": "1.0.4",
"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