Socket
Socket
Sign inDemoInstall

react-input-mask

Package Overview
Dependencies
Maintainers
1
Versions
90
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-input-mask - npm Package Compare versions

Comparing version 1.2.1 to 1.2.2

3

dist/react-input-mask.js

@@ -499,3 +499,4 @@ (function (global, factory) {

formatChars = _props.formatChars,
props = _objectWithoutProperties(_props, ["mask", "alwaysShowMask", "maskChar", "formatChars"]);
inputRef = _props.inputRef,
props = _objectWithoutProperties(_props, ["mask", "alwaysShowMask", "maskChar", "formatChars", "inputRef"]);

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

@@ -130,3 +130,4 @@ function _instanceof(left, right) { if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) { return right[Symbol.hasInstance](left); } else { return left instanceof right; } }

formatChars = _props.formatChars,
props = _objectWithoutProperties(_props, ["mask", "alwaysShowMask", "maskChar", "formatChars"]);
inputRef = _props.inputRef,
props = _objectWithoutProperties(_props, ["mask", "alwaysShowMask", "maskChar", "formatChars", "inputRef"]);

@@ -133,0 +134,0 @@ if (this.maskOptions.mask) {

@@ -140,3 +140,4 @@ "use strict";

formatChars = _props.formatChars,
props = _objectWithoutProperties(_props, ["mask", "alwaysShowMask", "maskChar", "formatChars"]);
inputRef = _props.inputRef,
props = _objectWithoutProperties(_props, ["mask", "alwaysShowMask", "maskChar", "formatChars", "inputRef"]);

@@ -143,0 +144,0 @@ if (this.maskOptions.mask) {

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