react-input-mask
Advanced tools
Comparing version 1.1.0 to 1.1.1
@@ -770,4 +770,2 @@ (function (global, factory) { | ||
var oldValue = _this3.value; | ||
if (beforePasteState) { | ||
@@ -781,2 +779,12 @@ _this3.beforePasteState = null; | ||
var oldValue = _this3.value; | ||
var input = _this3.getInputDOMNode(); // autofill replaces whole value, ignore old one | ||
// https://github.com/sanniassin/react-input-mask/issues/113 | ||
if (typeof input.matches === 'function' && input.matches(':-webkit-autofill')) { | ||
oldValue = ''; | ||
} | ||
var selection = _this3.getSelection(); | ||
@@ -783,0 +791,0 @@ |
@@ -1,1 +0,1 @@ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t(require("react")):"function"==typeof define&&define.amd?define(["react"],t):e.ReactInputMask=t(e.React)}(this,function(e){"use strict";function t(e){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 r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e}).apply(this,arguments)}function r(e,t){return-1!==e.permanents.indexOf(t)}function a(e,t,n){var a=e.mask,o=e.charsRules;if(!n)return!1;if(r(e,t))return a[t]===n;var s=o[a[t]];return new RegExp(s).test(n)}function o(e,t){return t.split("").every(function(t,n){return r(e,n)||!a(e,n,t)})}function s(e,t){var n=e.maskChar,o=e.prefix;if(!n){for(;t.length>o.length&&r(e,t.length-1);)t=t.slice(0,t.length-1);return t.length}for(var s=o.length,i=t.length;i>=o.length;i--){var u=t[i];if(!r(e,i)&&a(e,i,u)){s=i+1;break}}return s}function i(e,t){return s(e,t)===e.mask.length}function u(e,t){var n=e.maskChar,a=e.mask,o=e.prefix;if(!n)return t=c(e,"",t,0),(t=t.slice(0,s(e,t))).length<o.length&&(t=o),t;if(t){return c(e,u(e,""),t,0)}for(var i=0;i<a.length;i++)r(e,i)?t+=a[i]:t+=n;return t}function l(e,t,n,a){var o=n+a,s=e.maskChar,i=e.mask,l=e.prefix,c=t.split("");return s?c.map(function(t,a){return a<n||a>=o?t:r(e,a)?i[a]:s}).join(""):(n=Math.max(l.length,n),c.splice(n,o-n),t=c.join(""),u(e,t))}function c(e,t,n,o){var s=e.mask,l=e.maskChar,c=e.prefix,f=n.split(""),p=i(e,t),h=function(t,n){return!r(e,t)||n===s[t]},m=function(t,n){return!l||!r(e,n)||t!==l};return!l&&o>t.length&&(t+=s.slice(t.length,o)),f.every(function(n){for(;!h(o,n);){if(o>=t.length&&(t+=s[o]),!m(n,o))return!0;if(++o>=s.length)return!1}return!a(e,o,n)&&n!==l||(o<t.length?l||p||o<c.length?t=t.slice(0,o)+n+t.slice(o+1):(t=t.slice(0,o)+n+t.slice(o),t=u(e,t)):l||(t+=n),++o<s.length)}),t}var f={9:"[0-9]",a:"[A-Za-z]","*":"[A-Za-z0-9]"},p=function(e,t,n){if(t===undefined&&(t="_"),null==n&&(n=f),!e||"string"!=typeof e)return{maskChar:t,charsRules:n,mask:null,prefix:null,lastEditablePos:null,permanents:[]};var r="",a="",o=[],s=!1,i=null;return e.split("").forEach(function(e){s||"\\"!==e?(s||!n[e]?(o.push(r.length),r.length===o.length-1&&(a+=e)):i=r.length+1,r+=e,s=!1):s=!0}),{maskChar:t,charsRules:n,prefix:a,mask:r,lastEditablePos:i,permanents:o}},h=function(e){return(window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||function(){return setTimeout(e,0)})(e)},m=function(t){function r(e){var n;n=t.call(this,e)||this,g.call(n);var r=e.mask,a=e.maskChar,o=e.formatChars,s=e.defaultValue,i=e.value,l=e.alwaysShowMask;return n.hasValue=null!=i,n.maskOptions=p(r,a,o),null==s&&(s=""),null==i&&(i=s),i=n.getStringValue(i),n.maskOptions.mask&&(l||i)&&(i=u(n.maskOptions,i)),n.value=i,n}!function(e,t){e.prototype=Object.create(t.prototype),e.prototype.constructor=e,e.__proto__=t}(r,t);var a=r.prototype;return a.componentDidMount=function(){this.isAndroidBrowser=function(){var e=new RegExp("windows","i"),t=new RegExp("firefox","i"),n=new RegExp("android","i"),r=navigator.userAgent;return!e.test(r)&&!t.test(r)&&n.test(r)}(),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"),r=navigator.userAgent;return!e.test(r)&&t.test(r)&&n.test(r)}(),this.maskOptions.mask&&this.getInputValue()!==this.value&&this.setInputValue(this.value)},a.componentWillReceiveProps=function(e){var t=this.maskOptions;if(this.hasValue=null!=e.value,this.maskOptions=p(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,r=e.alwaysShowMask||this.isFocused(),a=this.hasValue?this.getStringValue(e.value):this.value;if(t.mask||this.hasValue||(a=this.getInputDOMNode().value),(n||this.maskOptions.mask&&(a||r))&&(a=u(this.maskOptions,a),n)){var l=this.lastCursorPos,c=s(this.maskOptions,a);(null===l||c<l)&&(l=i(this.maskOptions,a)?c:this.getRightEditablePos(c),this.setCursorPos(l))}!this.maskOptions.mask||!o(this.maskOptions,a)||r||this.hasValue&&e.value||(a=""),this.value=a},a.componentDidUpdate=function(){this.maskOptions.mask&&this.getInputValue()!==this.value&&this.setInputValue(this.value)},a.render=function(){var t=this,r=this.props,a=(r.mask,r.alwaysShowMask,r.maskChar,r.formatChars,function(e,t){if(null==e)return{};var n,r,a={},o=Object.keys(e);for(r=0;r<o.length;r++)n=o[r],t.indexOf(n)>=0||(a[n]=e[n]);if(Object.getOwnPropertySymbols){var s=Object.getOwnPropertySymbols(e);for(r=0;r<s.length;r++)n=s[r],t.indexOf(n)>=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(a[n]=e[n])}return a}(r,["mask","alwaysShowMask","maskChar","formatChars"]));if(this.maskOptions.mask){if(!a.disabled&&!a.readOnly){["onChange","onKeyDown","onPaste","onMouseDown"].forEach(function(e){a[e]=t[e]})}null!=a.value&&(a.value=this.value)}return e.createElement("input",n({ref:function(e){return t.input=e}},a,{onFocus:this.onFocus,onBlur:this.onBlur}))},r}((e=e&&e.hasOwnProperty("default")?e["default"]:e).Component),g=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))?function(e,t){return null!=t&&"undefined"!=typeof Symbol&&t[Symbol.hasInstance]?t[Symbol.hasInstance](e):e instanceof t}(e,HTMLElement):1===e.nodeType&&"string"==typeof e.nodeName}}),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(!r(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(!r(n.maskOptions,a))return a;return null}}),Object.defineProperty(this,"setCursorToEnd",{configurable:!0,enumerable:!0,writable:!0,value:function(){var e=s(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 r=n.getInputDOMNode();if(r){var a=e+t;if("selectionStart"in r&&"selectionEnd"in r)r.selectionStart=e,r.selectionEnd=a;else{var o=r.createTextRange();o.collapse(!0),o.moveStart("character",e),o.moveEnd("character",a-e),o.select()}}}}),Object.defineProperty(this,"getSelection",{configurable:!0,enumerable:!0,writable:!0,value:function(){var e=n.getInputDOMNode(),t=0,r=0;if("selectionStart"in e&&"selectionEnd"in e)t=e.selectionStart,r=e.selectionEnd;else{var a=document.selection.createRange();a.parentElement()===e&&(t=-a.moveStart("character",-e.value.length),r=-a.moveEnd("character",-e.value.length))}return{start:t,end:r,length:r-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),h(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,r=e.ctrlKey,a=e.metaKey,o=e.defaultPrevented;if(!(r||a||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,r=n.maskOptions,a=r.mask,o=r.maskChar,i=r.lastEditablePos,f=r.prefix,p=n.getInputValue(),m=n.value;if(t)return n.beforePasteState=null,void n.pasteText(t.value,p,t.selection,e);var g,b,v=n.getSelection(),d=v.end,k=a.length,O=p.length,y=m.length;if(n.backspaceOrDeleteRemoval){var w="Delete"===n.backspaceOrDeleteRemoval.key;if(p=n.value,v=n.backspaceOrDeleteRemoval.selection,d=v.start,n.backspaceOrDeleteRemoval=null,v.length)p=l(n.maskOptions,p,v.start,v.length);else if(v.start<f.length||!w&&v.start===f.length)d=f.length;else{var P=w?n.getRightEditablePos(d):n.getLeftEditablePos(d-1);null!==P&&(p=l(n.maskOptions,p,P,1),d=P)}}else if(O>y){var E=O-y,C=v.end-E;b=p.substr(C,E),d=C<i&&(1!==E||b!==a[C])?n.getRightEditablePos(C):C,p=p.substr(0,C)+p.substr(C+E),g=l(n.maskOptions,p,C,k-C),g=c(n.maskOptions,g,b,d),p=c(n.maskOptions,m,b,d),1!==E||d>=f.length&&d<i?(d=Math.max(s(n.maskOptions,g),d))<i&&(d=n.getRightEditablePos(d)):d<i&&d++}else if(O<y){var D=k-O,S=(b=p.substr(0,v.end))===m.substr(0,v.end);g=l(n.maskOptions,m,v.end,D),o&&(p=c(n.maskOptions,g,b,0)),g=l(n.maskOptions,g,v.end,k-v.end),g=c(n.maskOptions,g,b,0),S?d<f.length&&(d=f.length):(d=Math.max(s(n.maskOptions,g),d))<i&&(d=n.getRightEditablePos(d))}p=u(n.maskOptions,p),n.setInputValue(p),"function"==typeof n.props.onChange&&n.props.onChange(e),n.isWindowsPhoneBrowser?h(function(){n.setSelection(d,0)}):n.setCursorPos(d)}}),Object.defineProperty(this,"onFocus",{configurable:!0,enumerable:!0,writable:!0,value:function(e){if(n.focused=!0,n.maskOptions.mask)if(n.value)s(n.maskOptions,n.value)<n.maskOptions.mask.length&&n.setCursorToEnd();else{var t=n.maskOptions.prefix,r=u(n.maskOptions,t),a=u(n.maskOptions,r),o=a!==e.target.value;o&&(e.target.value=a),n.value=a,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&&o(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 r=Math.abs(e.clientX-n.mouseDownX),a=Math.abs(e.clientY-n.mouseDownY),o=Math.max(r,a),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,o,s){var i=o.start;o.length&&(e=l(n.maskOptions,e,i,o.length));var u=function(e,t,n,o){var s=e.mask,i=e.maskChar,u=n.split(""),l=o,c=function(t,n){return!r(e,t)||n===s[t]};return u.every(function(t){for(;!c(o,t);)if(++o>=s.length)return!1;return(a(e,o,t)||t===i)&&o++,o<s.length}),o-l}(n.maskOptions,0,t,i);e=c(n.maskOptions,e,t,i),i+=u,i=n.getRightEditablePos(i)||i,n.setInputValue(e),s&&"function"==typeof n.props.onChange&&n.props.onChange(s),n.setCursorPos(i)}})};return m}); | ||
!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 r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e}).apply(this,arguments)}function r(e,t){return-1!==e.permanents.indexOf(t)}function a(e,t,n){var a=e.mask,o=e.charsRules;if(!n)return!1;if(r(e,t))return a[t]===n;var s=o[a[t]];return new RegExp(s).test(n)}function o(e,t){return t.split("").every(function(t,n){return r(e,n)||!a(e,n,t)})}function s(e,t){var n=e.maskChar,o=e.prefix;if(!n){for(;t.length>o.length&&r(e,t.length-1);)t=t.slice(0,t.length-1);return t.length}for(var s=o.length,i=t.length;i>=o.length;i--){var u=t[i];if(!r(e,i)&&a(e,i,u)){s=i+1;break}}return s}function i(e,t){return s(e,t)===e.mask.length}function u(e,t){var n=e.maskChar,a=e.mask,o=e.prefix;if(!n)return t=c(e,"",t,0),(t=t.slice(0,s(e,t))).length<o.length&&(t=o),t;if(t){return c(e,u(e,""),t,0)}for(var i=0;i<a.length;i++)r(e,i)?t+=a[i]:t+=n;return t}function l(e,t,n,a){var o=n+a,s=e.maskChar,i=e.mask,l=e.prefix,c=t.split("");return s?c.map(function(t,a){return a<n||a>=o?t:r(e,a)?i[a]:s}).join(""):(n=Math.max(l.length,n),c.splice(n,o-n),t=c.join(""),u(e,t))}function c(e,t,n,o){var s=e.mask,l=e.maskChar,c=e.prefix,f=n.split(""),p=i(e,t),h=function(t,n){return!r(e,t)||n===s[t]},m=function(t,n){return!l||!r(e,n)||t!==l};return!l&&o>t.length&&(t+=s.slice(t.length,o)),f.every(function(n){for(;!h(o,n);){if(o>=t.length&&(t+=s[o]),!m(n,o))return!0;if(++o>=s.length)return!1}return!a(e,o,n)&&n!==l||(o<t.length?l||p||o<c.length?t=t.slice(0,o)+n+t.slice(o+1):(t=t.slice(0,o)+n+t.slice(o),t=u(e,t)):l||(t+=n),++o<s.length)}),t}var f={9:"[0-9]",a:"[A-Za-z]","*":"[A-Za-z0-9]"},p=function(e,t,n){if(t===undefined&&(t="_"),null==n&&(n=f),!e||"string"!=typeof e)return{maskChar:t,charsRules:n,mask:null,prefix:null,lastEditablePos:null,permanents:[]};var r="",a="",o=[],s=!1,i=null;return e.split("").forEach(function(e){s||"\\"!==e?(s||!n[e]?(o.push(r.length),r.length===o.length-1&&(a+=e)):i=r.length+1,r+=e,s=!1):s=!0}),{maskChar:t,charsRules:n,prefix:a,mask:r,lastEditablePos:i,permanents:o}},h=function(e){return(window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||function(){return setTimeout(e,0)})(e)},m=function(t){function r(e){var n;n=t.call(this,e)||this,g.call(n);var r=e.mask,a=e.maskChar,o=e.formatChars,s=e.defaultValue,i=e.value,l=e.alwaysShowMask;return n.hasValue=null!=i,n.maskOptions=p(r,a,o),null==s&&(s=""),null==i&&(i=s),i=n.getStringValue(i),n.maskOptions.mask&&(l||i)&&(i=u(n.maskOptions,i)),n.value=i,n}!function(e,t){e.prototype=Object.create(t.prototype),e.prototype.constructor=e,e.__proto__=t}(r,t);var a=r.prototype;return a.componentDidMount=function(){this.isAndroidBrowser=function(){var e=new RegExp("windows","i"),t=new RegExp("firefox","i"),n=new RegExp("android","i"),r=navigator.userAgent;return!e.test(r)&&!t.test(r)&&n.test(r)}(),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"),r=navigator.userAgent;return!e.test(r)&&t.test(r)&&n.test(r)}(),this.maskOptions.mask&&this.getInputValue()!==this.value&&this.setInputValue(this.value)},a.componentWillReceiveProps=function(e){var t=this.maskOptions;if(this.hasValue=null!=e.value,this.maskOptions=p(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,r=e.alwaysShowMask||this.isFocused(),a=this.hasValue?this.getStringValue(e.value):this.value;if(t.mask||this.hasValue||(a=this.getInputDOMNode().value),(n||this.maskOptions.mask&&(a||r))&&(a=u(this.maskOptions,a),n)){var l=this.lastCursorPos,c=s(this.maskOptions,a);(null===l||c<l)&&(l=i(this.maskOptions,a)?c:this.getRightEditablePos(c),this.setCursorPos(l))}!this.maskOptions.mask||!o(this.maskOptions,a)||r||this.hasValue&&e.value||(a=""),this.value=a},a.componentDidUpdate=function(){this.maskOptions.mask&&this.getInputValue()!==this.value&&this.setInputValue(this.value)},a.render=function(){var t=this,r=this.props,a=(r.mask,r.alwaysShowMask,r.maskChar,r.formatChars,function(e,t){if(null==e)return{};var n,r,a={},o=Object.keys(e);for(r=0;r<o.length;r++)n=o[r],t.indexOf(n)>=0||(a[n]=e[n]);if(Object.getOwnPropertySymbols){var s=Object.getOwnPropertySymbols(e);for(r=0;r<s.length;r++)n=s[r],t.indexOf(n)>=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(a[n]=e[n])}return a}(r,["mask","alwaysShowMask","maskChar","formatChars"]));if(this.maskOptions.mask){if(!a.disabled&&!a.readOnly){["onChange","onKeyDown","onPaste","onMouseDown"].forEach(function(e){a[e]=t[e]})}null!=a.value&&(a.value=this.value)}return e.createElement("input",n({ref:function(e){return t.input=e}},a,{onFocus:this.onFocus,onBlur:this.onBlur}))},r}((e=e&&e.hasOwnProperty("default")?e["default"]:e).Component),g=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))?function(e,t){return null!=t&&"undefined"!=typeof Symbol&&t[Symbol.hasInstance]?t[Symbol.hasInstance](e):e instanceof t}(e,HTMLElement):1===e.nodeType&&"string"==typeof e.nodeName}}),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(!r(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(!r(n.maskOptions,a))return a;return null}}),Object.defineProperty(this,"setCursorToEnd",{configurable:!0,enumerable:!0,writable:!0,value:function(){var e=s(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 r=n.getInputDOMNode();if(r){var a=e+t;if("selectionStart"in r&&"selectionEnd"in r)r.selectionStart=e,r.selectionEnd=a;else{var o=r.createTextRange();o.collapse(!0),o.moveStart("character",e),o.moveEnd("character",a-e),o.select()}}}}),Object.defineProperty(this,"getSelection",{configurable:!0,enumerable:!0,writable:!0,value:function(){var e=n.getInputDOMNode(),t=0,r=0;if("selectionStart"in e&&"selectionEnd"in e)t=e.selectionStart,r=e.selectionEnd;else{var a=document.selection.createRange();a.parentElement()===e&&(t=-a.moveStart("character",-e.value.length),r=-a.moveEnd("character",-e.value.length))}return{start:t,end:r,length:r-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),h(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,r=e.ctrlKey,a=e.metaKey,o=e.defaultPrevented;if(!(r||a||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,r=n.maskOptions,a=r.mask,o=r.maskChar,i=r.lastEditablePos,f=r.prefix,p=n.getInputValue();if(t)return n.beforePasteState=null,void n.pasteText(t.value,p,t.selection,e);var m=n.value,g=n.getInputDOMNode();"function"==typeof g.matches&&g.matches(":-webkit-autofill")&&(m="");var b,v,d=n.getSelection(),k=d.end,O=a.length,y=p.length,w=m.length;if(n.backspaceOrDeleteRemoval){var P="Delete"===n.backspaceOrDeleteRemoval.key;if(p=n.value,d=n.backspaceOrDeleteRemoval.selection,k=d.start,n.backspaceOrDeleteRemoval=null,d.length)p=l(n.maskOptions,p,d.start,d.length);else if(d.start<f.length||!P&&d.start===f.length)k=f.length;else{var E=P?n.getRightEditablePos(k):n.getLeftEditablePos(k-1);null!==E&&(p=l(n.maskOptions,p,E,1),k=E)}}else if(y>w){var C=y-w,D=d.end-C;v=p.substr(D,C),k=D<i&&(1!==C||v!==a[D])?n.getRightEditablePos(D):D,p=p.substr(0,D)+p.substr(D+C),b=l(n.maskOptions,p,D,O-D),b=c(n.maskOptions,b,v,k),p=c(n.maskOptions,m,v,k),1!==C||k>=f.length&&k<i?(k=Math.max(s(n.maskOptions,b),k))<i&&(k=n.getRightEditablePos(k)):k<i&&k++}else if(y<w){var S=O-y,R=(v=p.substr(0,d.end))===m.substr(0,d.end);b=l(n.maskOptions,m,d.end,S),o&&(p=c(n.maskOptions,b,v,0)),b=l(n.maskOptions,b,d.end,O-d.end),b=c(n.maskOptions,b,v,0),R?k<f.length&&(k=f.length):(k=Math.max(s(n.maskOptions,b),k))<i&&(k=n.getRightEditablePos(k))}p=u(n.maskOptions,p),n.setInputValue(p),"function"==typeof n.props.onChange&&n.props.onChange(e),n.isWindowsPhoneBrowser?h(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)s(n.maskOptions,n.value)<n.maskOptions.mask.length&&n.setCursorToEnd();else{var t=n.maskOptions.prefix,r=u(n.maskOptions,t),a=u(n.maskOptions,r),o=a!==e.target.value;o&&(e.target.value=a),n.value=a,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&&o(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 r=Math.abs(e.clientX-n.mouseDownX),a=Math.abs(e.clientY-n.mouseDownY),o=Math.max(r,a),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,o,s){var i=o.start;o.length&&(e=l(n.maskOptions,e,i,o.length));var u=function(e,t,n,o){var s=e.mask,i=e.maskChar,u=n.split(""),l=o,c=function(t,n){return!r(e,t)||n===s[t]};return u.every(function(t){for(;!c(o,t);)if(++o>=s.length)return!1;return(a(e,o,t)||t===i)&&o++,o<s.length}),o-l}(n.maskOptions,0,t,i);e=c(n.maskOptions,e,t,i),i+=u,i=n.getRightEditablePos(i)||i,n.setInputValue(e),s&&"function"==typeof n.props.onChange&&n.props.onChange(s),n.setCursorPos(i)}})};return m}); |
@@ -417,4 +417,2 @@ function _instanceof(left, right) { if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) { return right[Symbol.hasInstance](left); } else { return left instanceof right; } } | ||
var oldValue = _this3.value; | ||
if (beforePasteState) { | ||
@@ -428,2 +426,12 @@ _this3.beforePasteState = null; | ||
var oldValue = _this3.value; | ||
var input = _this3.getInputDOMNode(); // autofill replaces whole value, ignore old one | ||
// https://github.com/sanniassin/react-input-mask/issues/113 | ||
if (typeof input.matches === 'function' && input.matches(':-webkit-autofill')) { | ||
oldValue = ''; | ||
} | ||
var selection = _this3.getSelection(); | ||
@@ -430,0 +438,0 @@ |
@@ -427,4 +427,2 @@ "use strict"; | ||
var oldValue = _this3.value; | ||
if (beforePasteState) { | ||
@@ -438,2 +436,12 @@ _this3.beforePasteState = null; | ||
var oldValue = _this3.value; | ||
var input = _this3.getInputDOMNode(); // autofill replaces whole value, ignore old one | ||
// https://github.com/sanniassin/react-input-mask/issues/113 | ||
if (typeof input.matches === 'function' && input.matches(':-webkit-autofill')) { | ||
oldValue = ''; | ||
} | ||
var selection = _this3.getSelection(); | ||
@@ -440,0 +448,0 @@ |
{ | ||
"name": "react-input-mask", | ||
"description": "Masked input component for React", | ||
"version": "1.1.0", | ||
"version": "1.1.1", | ||
"homepage": "https://github.com/sanniassin/react-input-mask", | ||
@@ -6,0 +6,0 @@ "license": "MIT", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
109236
2557