react-input-mask
Advanced tools
Comparing version 1.1.2 to 1.2.0
@@ -230,3 +230,2 @@ (function (global, factory) { | ||
value = insertString(maskOptions, '', value, 0); | ||
value = value.slice(0, getFilledLength(maskOptions, value)); | ||
@@ -237,2 +236,6 @@ if (value.length < prefix.length) { | ||
while (value.length < mask.length && isPermanentChar(maskOptions, value.length)) { | ||
value += mask[value.length]; | ||
} | ||
return value; | ||
@@ -264,2 +267,9 @@ } | ||
if (!maskChar) { | ||
// remove any permanent chars after clear range, they will be added back by foramtValue | ||
for (var i = end; i < arrayValue.length; i++) { | ||
if (isPermanentChar(maskOptions, i)) { | ||
arrayValue[i] = ''; | ||
} | ||
} | ||
start = Math.max(prefix.length, start); | ||
@@ -449,3 +459,3 @@ arrayValue.splice(start, end - start); | ||
if (!oldMaskOptions.mask && !this.hasValue) { | ||
newValue = this.getInputDOMNode().value; | ||
newValue = this.getInputValue(); | ||
} | ||
@@ -828,2 +838,6 @@ | ||
if (editablePos !== null) { | ||
if (!maskChar) { | ||
value = value.substr(0, getFilledLength(_this3.maskOptions, value)); | ||
} | ||
value = clearRange(_this3.maskOptions, value, editablePos, 1); | ||
@@ -830,0 +844,0 @@ cursorPos = editablePos; |
@@ -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,n){if(t===undefined&&(t=m),null==n&&(n=h),!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}}function a(e,t){return-1!==e.permanents.indexOf(t)}function o(e,t,n){var r=e.mask,o=e.charsRules;if(!n)return!1;if(a(e,t))return r[t]===n;var s=o[r[t]];return new RegExp(s).test(n)}function s(e,t){return t.split("").every(function(t,n){return a(e,n)||!o(e,n,t)})}function i(e,t){var n=e.maskChar,r=e.prefix;if(!n){for(;t.length>r.length&&a(e,t.length-1);)t=t.slice(0,t.length-1);return t.length}for(var s=r.length,i=t.length;i>=r.length;i--){var u=t[i];if(!a(e,i)&&o(e,i,u)){s=i+1;break}}return s}function u(e,t){return i(e,t)===e.mask.length}function l(e,t){var n=e.maskChar,r=e.mask,o=e.prefix;if(!n)return t=f(e,"",t,0),(t=t.slice(0,i(e,t))).length<o.length&&(t=o),t;if(t){return f(e,l(e,""),t,0)}for(var s=0;s<r.length;s++)a(e,s)?t+=r[s]:t+=n;return t}function c(e,t,n,r){var o=n+r,s=e.maskChar,i=e.mask,u=e.prefix,c=t.split("");return s?c.map(function(t,r){return r<n||r>=o?t:a(e,r)?i[r]:s}).join(""):(n=Math.max(u.length,n),c.splice(n,o-n),t=c.join(""),l(e,t))}function f(e,t,n,r){var s=e.mask,i=e.maskChar,c=e.prefix,f=n.split(""),p=u(e,t),h=function(t,n){return!a(e,t)||n===s[t]},m=function(t,n){return!i||!a(e,n)||t!==i};return!i&&r>t.length&&(t+=s.slice(t.length,r)),f.every(function(n){for(;!h(r,n);){if(r>=t.length&&(t+=s[r]),!m(n,r))return!0;if(++r>=s.length)return!1}return!o(e,r,n)&&n!==i||(r<t.length?i||p||r<c.length?t=t.slice(0,r)+n+t.slice(r+1):(t=t.slice(0,r)+n+t.slice(r),t=l(e,t)):i||(t+=n),++r<s.length)}),t}function p(e){return(window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||function(){return setTimeout(e,0)})(e)}var h={9:"[0-9]",a:"[A-Za-z]","*":"[A-Za-z0-9]"},m="_",g=function(t){function a(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,o=e.maskChar,s=e.formatChars,i=e.defaultValue,u=e.value,c=e.alwaysShowMask;return n.hasValue=null!=u,n.maskOptions=r(a,o,s),null==i&&(i=""),null==u&&(u=i),u=n.getStringValue(u),n.maskOptions.mask&&(c||u)&&(u=l(n.maskOptions,u)),n.value=u,n}!function(e,t){e.prototype=Object.create(t.prototype),e.prototype.constructor=e,e.__proto__=t}(a,t);var o=a.prototype;return o.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)},o.componentWillReceiveProps=function(e){var t=this.maskOptions;if(this.hasValue=null!=e.value,this.maskOptions=r(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(),o=this.hasValue?this.getStringValue(e.value):this.value;if(t.mask||this.hasValue||(o=this.getInputDOMNode().value),(n||this.maskOptions.mask&&(o||a))&&(o=l(this.maskOptions,o),n)){var c=this.lastCursorPos,f=i(this.maskOptions,o);(null===c||f<c)&&(c=u(this.maskOptions,o)?f:this.getRightEditablePos(f),this.setCursorPos(c))}!this.maskOptions.mask||!s(this.maskOptions,o)||a||this.hasValue&&e.value||(o=""),this.value=o},o.componentDidUpdate=function(){this.maskOptions.mask&&this.getInputValue()!==this.value&&this.setInputValue(this.value)},o.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}))},a}((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))?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(!a(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,r=e;r<t.length;++r)if(!a(n.maskOptions,r))return r;return null}}),Object.defineProperty(this,"setCursorToEnd",{configurable:!0,enumerable:!0,writable:!0,value:function(){var e=i(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),p(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,s=r.lastEditablePos,u=r.prefix,h=n.getInputValue();if(t)return n.beforePasteState=null,void n.pasteText(t.value,h,t.selection,e);var m=n.value,g=n.getInputDOMNode();try{"function"==typeof g.matches&&g.matches(":-webkit-autofill")&&(m="")}catch(j){}var b,d,v=n.getSelection(),k=v.end,O=a.length,y=h.length,w=m.length;if(n.backspaceOrDeleteRemoval){var P="Delete"===n.backspaceOrDeleteRemoval.key;if(h=n.value,v=n.backspaceOrDeleteRemoval.selection,k=v.start,n.backspaceOrDeleteRemoval=null,v.length)h=c(n.maskOptions,h,v.start,v.length);else if(v.start<u.length||!P&&v.start===u.length)k=u.length;else{var E=P?n.getRightEditablePos(k):n.getLeftEditablePos(k-1);null!==E&&(h=c(n.maskOptions,h,E,1),k=E)}}else if(y>w){var C=y-w,D=v.end-C;d=h.substr(D,C),k=D<s&&(1!==C||d!==a[D])?n.getRightEditablePos(D):D,h=h.substr(0,D)+h.substr(D+C),b=c(n.maskOptions,h,D,O-D),b=f(n.maskOptions,b,d,k),h=f(n.maskOptions,m,d,k),1!==C||k>=u.length&&k<s?(k=Math.max(i(n.maskOptions,b),k))<s&&(k=n.getRightEditablePos(k)):k<s&&k++}else if(y<w){var S=O-y,R=(d=h.substr(0,v.end))===m.substr(0,v.end);b=c(n.maskOptions,m,v.end,S),o&&(h=f(n.maskOptions,b,d,0)),b=c(n.maskOptions,b,v.end,O-v.end),b=f(n.maskOptions,b,d,0),R?k<u.length&&(k=u.length):(k=Math.max(i(n.maskOptions,b),k))<s&&(k=n.getRightEditablePos(k))}h=l(n.maskOptions,h),n.setInputValue(h),"function"==typeof n.props.onChange&&n.props.onChange(e),n.isWindowsPhoneBrowser?p(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)i(n.maskOptions,n.value)<n.maskOptions.mask.length&&n.setCursorToEnd();else{var t=n.maskOptions.prefix,r=l(n.maskOptions,t),a=l(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&&s(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,r,s){var i=r.start;r.length&&(e=c(n.maskOptions,e,i,r.length));var u=function(e,t,n,r){var s=e.mask,i=e.maskChar,u=n.split(""),l=r,c=function(t,n){return!a(e,t)||n===s[t]};return u.every(function(t){for(;!c(r,t);)if(++r>=s.length)return!1;return(o(e,r,t)||t===i)&&r++,r<s.length}),r-l}(n.maskOptions,0,t,i);e=f(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 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 r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e}).apply(this,arguments)}var r={9:"[0-9]",a:"[A-Za-z]","*":"[A-Za-z0-9]"},a="_";function o(e,t,n){if(t===undefined&&(t=a),null==n&&(n=r),!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 r=e.mask,a=e.charsRules;if(!n)return!1;if(s(e,t))return r[t]===n;var o=a[r[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,r=e.prefix;if(!n){for(;t.length>r.length&&s(e,t.length-1);)t=t.slice(0,t.length-1);return t.length}for(var a=r.length,o=t.length;o>=r.length;o--){var l=t[o];if(!s(e,o)&&i(e,o,l)){a=o+1;break}}return a}function c(e,t){return u(e,t)===e.mask.length}function f(e,t){var n=e.maskChar,r=e.mask,a=e.prefix;if(!n){for((t=h(e,"",t,0)).length<a.length&&(t=a);t.length<r.length&&s(e,t.length);)t+=r[t.length];return t}if(t)return h(e,f(e,""),t,0);for(var o=0;o<r.length;o++)s(e,o)?t+=r[o]:t+=n;return t}function p(e,t,n,r){var a=n+r,o=e.maskChar,i=e.mask,l=e.prefix,u=t.split("");if(!o){for(var c=a;c<u.length;c++)s(e,c)&&(u[c]="");return n=Math.max(l.length,n),u.splice(n,a-n),t=u.join(""),f(e,t)}return u.map(function(t,r){return r<n||r>=a?t:s(e,r)?i[r]:o}).join("")}function h(e,t,n,r){var a=e.mask,o=e.maskChar,l=e.prefix,u=n.split(""),p=c(e,t),h=function(t,n){return!o||!s(e,n)||t!==o};return!o&&r>t.length&&(t+=a.slice(t.length,r)),u.every(function(n){for(;c=n,s(e,u=r)&&c!==a[u];){if(r>=t.length&&(t+=a[r]),!h(n,r))return!0;if(++r>=a.length)return!1}var u,c;return!i(e,r,n)&&n!==o||(r<t.length?o||p||r<l.length?t=t.slice(0,r)+n+t.slice(r+1):(t=t.slice(0,r)+n+t.slice(r),t=f(e,t)):o||(t+=n),++r<a.length)}),t}function m(e){return(window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||function(){return setTimeout(e,0)})(e)}var g=function(t){var r,a;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 r=e.mask,a=e.maskChar,s=e.formatChars,i=e.defaultValue,l=e.value,u=e.alwaysShowMask;return n.hasValue=null!=l,n.maskOptions=o(r,a,s),null==i&&(i=""),null==l&&(l=i),l=n.getStringValue(l),n.maskOptions.mask&&(u||l)&&(l=f(n.maskOptions,l)),n.value=l,n}a=t,(r=s).prototype=Object.create(a.prototype),r.prototype.constructor=r,r.__proto__=a;var i=s.prototype;return i.componentDidMount=function(){var e,t,n,r;this.isAndroidBrowser=(e=new RegExp("windows","i"),t=new RegExp("firefox","i"),n=new RegExp("android","i"),r=navigator.userAgent,!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)},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,r=e.alwaysShowMask||this.isFocused(),a=this.hasValue?this.getStringValue(e.value):this.value;if(t.mask||this.hasValue||(a=this.getInputValue()),(n||this.maskOptions.mask&&(a||r))&&(a=f(this.maskOptions,a),n)){var s=this.lastCursorPos,i=u(this.maskOptions,a);(null===s||i<s)&&(s=c(this.maskOptions,a)?i:this.getRightEditablePos(i),this.setCursorPos(s))}!this.maskOptions.mask||!l(this.maskOptions,a)||r||this.hasValue&&e.value||(a=""),this.value=a},i.componentDidUpdate=function(){this.maskOptions.mask&&this.getInputValue()!==this.value&&this.setInputValue(this.value)},i.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}))},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!=(r=HTMLElement)&&"undefined"!=typeof Symbol&&r[Symbol.hasInstance]?r[Symbol.hasInstance](n):n instanceof r):1===e.nodeType&&"string"==typeof e.nodeName;var n,r}}),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,r=e;r<t.length;++r)if(!s(n.maskOptions,r))return r;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 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),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,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,s=r.lastEditablePos,i=r.prefix,l=n.getInputValue();if(t)return n.beforePasteState=null,void n.pasteText(t.value,l,t.selection,e);var c=n.value,g=n.getInputDOMNode();try{"function"==typeof g.matches&&g.matches(":-webkit-autofill")&&(c="")}catch(j){}var b,v,d=n.getSelection(),k=d.end,O=a.length,y=l.length,w=c.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,D=d.end-C;v=l.substr(D,C),k=D<s&&(1!==C||v!==a[D])?n.getRightEditablePos(D):D,l=l.substr(0,D)+l.substr(D+C),b=p(n.maskOptions,l,D,O-D),b=h(n.maskOptions,b,v,k),l=h(n.maskOptions,c,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 S=O-y,R=(v=l.substr(0,d.end))===c.substr(0,d.end);b=p(n.maskOptions,c,d.end,S),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),R?k<i.length&&(k=i.length):(k=Math.max(u(n.maskOptions,b),k))<s&&(k=n.getRightEditablePos(k))}l=f(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,r=f(n.maskOptions,t),a=f(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&&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 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,r,a){var o=r.start;r.length&&(e=p(n.maskOptions,e,o,r.length));var l,u,c,f,m,g,b,v=(l=n.maskOptions,u=t,c=o,f=l.mask,m=l.maskChar,g=u.split(""),b=c,g.every(function(e){for(;n=e,s(l,t=c)&&n!==f[t];)if(++c>=f.length)return!1;var t,n;return(i(l,c,e)||e===m)&&c++,c<f.length}),c-b);e=h(n.maskOptions,e,t,o),o+=v,o=n.getRightEditablePos(o)||o,n.setInputValue(e),a&&"function"==typeof n.props.onChange&&n.props.onChange(a),n.setCursorPos(o)}})};return g}); |
@@ -87,3 +87,3 @@ function _instanceof(left, right) { if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) { return right[Symbol.hasInstance](left); } else { return left instanceof right; } } | ||
if (!oldMaskOptions.mask && !this.hasValue) { | ||
newValue = this.getInputDOMNode().value; | ||
newValue = this.getInputValue(); | ||
} | ||
@@ -466,2 +466,6 @@ | ||
if (editablePos !== null) { | ||
if (!maskChar) { | ||
value = value.substr(0, getFilledLength(_this3.maskOptions, value)); | ||
} | ||
value = clearRange(_this3.maskOptions, value, editablePos, 1); | ||
@@ -468,0 +472,0 @@ cursorPos = editablePos; |
@@ -61,3 +61,2 @@ export function isPermanentChar(maskOptions, pos) { | ||
value = insertString(maskOptions, '', value, 0); | ||
value = value.slice(0, getFilledLength(maskOptions, value)); | ||
@@ -68,2 +67,6 @@ if (value.length < prefix.length) { | ||
while (value.length < mask.length && isPermanentChar(maskOptions, value.length)) { | ||
value += mask[value.length]; | ||
} | ||
return value; | ||
@@ -95,2 +98,9 @@ } | ||
if (!maskChar) { | ||
// remove any permanent chars after clear range, they will be added back by foramtValue | ||
for (var i = end; i < arrayValue.length; i++) { | ||
if (isPermanentChar(maskOptions, i)) { | ||
arrayValue[i] = ''; | ||
} | ||
} | ||
start = Math.max(prefix.length, start); | ||
@@ -97,0 +107,0 @@ arrayValue.splice(start, end - start); |
@@ -97,3 +97,3 @@ "use strict"; | ||
if (!oldMaskOptions.mask && !this.hasValue) { | ||
newValue = this.getInputDOMNode().value; | ||
newValue = this.getInputValue(); | ||
} | ||
@@ -476,2 +476,6 @@ | ||
if (editablePos !== null) { | ||
if (!maskChar) { | ||
value = value.substr(0, (0, _string.getFilledLength)(_this3.maskOptions, value)); | ||
} | ||
value = (0, _string.clearRange)(_this3.maskOptions, value, editablePos, 1); | ||
@@ -478,0 +482,0 @@ cursorPos = editablePos; |
@@ -79,3 +79,2 @@ "use strict"; | ||
value = insertString(maskOptions, '', value, 0); | ||
value = value.slice(0, getFilledLength(maskOptions, value)); | ||
@@ -86,2 +85,6 @@ if (value.length < prefix.length) { | ||
while (value.length < mask.length && isPermanentChar(maskOptions, value.length)) { | ||
value += mask[value.length]; | ||
} | ||
return value; | ||
@@ -114,2 +117,9 @@ } | ||
if (!maskChar) { | ||
// remove any permanent chars after clear range, they will be added back by foramtValue | ||
for (var i = end; i < arrayValue.length; i++) { | ||
if (isPermanentChar(maskOptions, i)) { | ||
arrayValue[i] = ''; | ||
} | ||
} | ||
start = Math.max(prefix.length, start); | ||
@@ -116,0 +126,0 @@ arrayValue.splice(start, end - start); |
{ | ||
"name": "react-input-mask", | ||
"description": "Masked input component for React", | ||
"version": "1.1.2", | ||
"version": "1.2.0", | ||
"homepage": "https://github.com/sanniassin/react-input-mask", | ||
@@ -19,9 +19,9 @@ "license": "MIT", | ||
"devDependencies": { | ||
"@babel/cli": "^7.0.0-beta.37", | ||
"@babel/core": "^7.0.0-beta.37", | ||
"@babel/polyfill": "^7.0.0-beta.37", | ||
"@babel/preset-es2015": "^7.0.0-beta.37", | ||
"@babel/preset-react": "^7.0.0-beta.37", | ||
"@babel/preset-stage-2": "^7.0.0-beta.37", | ||
"@babel/register": "^7.0.0-beta.37", | ||
"@babel/cli": "^7.0.0-beta.39", | ||
"@babel/core": "^7.0.0-beta.39", | ||
"@babel/polyfill": "^7.0.0-beta.39", | ||
"@babel/preset-es2015": "^7.0.0-beta.39", | ||
"@babel/preset-react": "^7.0.0-beta.39", | ||
"@babel/preset-stage-2": "^7.0.0-beta.39", | ||
"@babel/register": "^7.0.0-beta.39", | ||
"babel-eslint": "^7.2.3", | ||
@@ -38,3 +38,3 @@ "babel-loader": "^8.0.0-beta.0", | ||
"eslint-plugin-jsx-a11y": "^5.1.1", | ||
"eslint-plugin-react": "^7.5.1", | ||
"eslint-plugin-react": "^7.6.1", | ||
"html-webpack-plugin": "^2.30.1", | ||
@@ -46,13 +46,13 @@ "karma": "^2.0.0", | ||
"karma-webpack": "^2.0.9", | ||
"mocha": "^4.1.0", | ||
"mocha": "^5.0.0", | ||
"puppeteer": "^1.0.0", | ||
"react": "^16.2.0", | ||
"react-dom": "^16.2.0", | ||
"rollup": "^0.54.0", | ||
"rollup-plugin-babel": "^4.0.0-beta.0", | ||
"rollup": "^0.55.3", | ||
"rollup-plugin-babel": "^4.0.0-beta.1", | ||
"rollup-plugin-node-resolve": "^3.0.2", | ||
"rollup-plugin-replace": "^2.0.0", | ||
"rollup-plugin-uglify": "^2.0.1", | ||
"rollup-plugin-uglify": "^3.0.0", | ||
"webpack": "^3.10.0", | ||
"webpack-dev-server": "^2.10.1" | ||
"webpack-dev-server": "^2.11.1" | ||
}, | ||
@@ -59,0 +59,0 @@ "main": "lib/index.js", |
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
111605
2611