katoikia-app/web-ui/web-react/node_modules/primereact/inputmask/inputmask.cjs.min.js

2 lines
12 KiB
JavaScript

"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("react"),e=require("primereact/utils"),i=require("primereact/inputtext"),n=require("primereact/tooltip");function s(t){return t&&"object"==typeof t&&"default"in t?t:{default:t}}var r=s(t);function o(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function u(t,e){for(var i=0;i<e.length;i++){var n=e[i];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}function a(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}function l(t,e){return l=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t},l(t,e)}function h(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),e&&l(t,e)}function p(t){return p="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},p(t)}function f(t,e){if(e&&("object"===p(e)||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");return a(t)}function c(t){return c=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)},c(t)}function d(t,e,i){return e in t?Object.defineProperty(t,e,{value:i,enumerable:!0,configurable:!0,writable:!0}):t[e]=i,t}function v(t,e){var i=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);e&&(n=n.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),i.push.apply(i,n)}return i}function y(t){for(var e=1;e<arguments.length;e++){var i=null!=arguments[e]?arguments[e]:{};e%2?v(Object(i),!0).forEach((function(e){d(t,e,i[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(i)):v(Object(i)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(i,e))}))}return t}function b(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}var g=function(s){h(k,t.Component);var l,p,d,v,g,m=(l=k,p=b(),function(){var t,e=c(l);if(p){var i=c(this).constructor;t=Reflect.construct(e,arguments,i)}else t=e.apply(this,arguments);return f(this,t)});function k(e){var i;return o(this,k),(i=m.call(this,e)).onFocus=i.onFocus.bind(a(i)),i.onBlur=i.onBlur.bind(a(i)),i.onKeyDown=i.onKeyDown.bind(a(i)),i.onKeyPress=i.onKeyPress.bind(a(i)),i.onInput=i.onInput.bind(a(i)),i.handleInputChange=i.handleInputChange.bind(a(i)),i.inputRef=t.createRef(i.props.inputRef),i}return d=k,(v=[{key:"caret",value:function(t,e){var i,n,s,r=this.inputRef&&this.inputRef.current;if(r&&r.offsetParent&&r===document.activeElement)return"number"!=typeof t?(r.setSelectionRange?(n=r.selectionStart,s=r.selectionEnd):document.selection&&document.selection.createRange&&(s=(n=0-(i=document.selection.createRange()).duplicate().moveStart("character",-1e5))+i.text.length),{begin:n,end:s}):(n=t,s="number"==typeof e?e:n,void(r.setSelectionRange?r.setSelectionRange(n,s):r.createTextRange&&((i=r.createTextRange()).collapse(!0),i.moveEnd("character",s),i.moveStart("character",n),i.select())))}},{key:"isCompleted",value:function(){for(var t=this.firstNonMaskPos;t<=this.lastRequiredNonMaskPos;t++)if(this.tests[t]&&this.buffer[t]===this.getPlaceholder(t))return!1;return!0}},{key:"getPlaceholder",value:function(t){return this.props.slotChar.charAt(t<this.props.slotChar.length?t:0)}},{key:"getValue",value:function(){return this.props.unmask?this.getUnmaskedValue():this.inputRef&&this.inputRef.current&&this.inputRef.current.value}},{key:"seekNext",value:function(t){for(;++t<this.len&&!this.tests[t];);return t}},{key:"seekPrev",value:function(t){for(;--t>=0&&!this.tests[t];);return t}},{key:"shiftL",value:function(t,e){var i,n;if(!(t<0)){for(i=t,n=this.seekNext(e);i<this.len;i++)if(this.tests[i]){if(!(n<this.len&&this.tests[i].test(this.buffer[n])))break;this.buffer[i]=this.buffer[n],this.buffer[n]=this.getPlaceholder(n),n=this.seekNext(n)}this.writeBuffer(),this.caret(Math.max(this.firstNonMaskPos,t))}}},{key:"shiftR",value:function(t){var e,i,n,s;for(e=t,i=this.getPlaceholder(t);e<this.len;e++)if(this.tests[e]){if(n=this.seekNext(e),s=this.buffer[e],this.buffer[e]=i,!(n<this.len&&this.tests[n].test(s)))break;i=s}}},{key:"handleAndroidInput",value:function(t){var e=this.inputRef.current.value,i=this.caret();if(this.oldVal&&this.oldVal.length&&this.oldVal.length>e.length){for(this.checkVal(!0);i.begin>0&&!this.tests[i.begin-1];)i.begin--;if(0===i.begin)for(;i.begin<this.firstNonMaskPos&&!this.tests[i.begin];)i.begin++;this.caret(i.begin,i.begin)}else{for(this.checkVal(!0);i.begin<this.len&&!this.tests[i.begin];)i.begin++;this.caret(i.begin,i.begin)}this.props.onComplete&&this.isCompleted()&&this.props.onComplete({originalEvent:t,value:this.getValue()})}},{key:"onBlur",value:function(t){if(this.focus=!1,this.checkVal(),this.updateModel(t),this.updateFilledState(),this.props.onBlur&&this.props.onBlur(t),this.inputRef.current.value!==this.focusText){var e=document.createEvent("HTMLEvents");e.initEvent("change",!0,!1),this.inputRef.current.dispatchEvent(e)}}},{key:"onKeyDown",value:function(t){if(!this.props.readOnly){var i,n,s,r=t.which||t.keyCode,o=/iphone/i.test(e.DomHandler.getUserAgent());this.oldVal=this.inputRef.current.value,8===r||46===r||o&&127===r?((s=(i=this.caret()).end)-(n=i.begin)==0&&(n=46!==r?this.seekPrev(n):s=this.seekNext(n-1),s=46===r?this.seekNext(s):s),this.clearBuffer(n,s),this.shiftL(n,s-1),this.updateModel(t),t.preventDefault()):13===r?(this.onBlur(t),this.updateModel(t)):27===r&&(this.inputRef.current.value=this.focusText,this.caret(0,this.checkVal()),this.updateModel(t),t.preventDefault())}}},{key:"onKeyPress",value:function(t){var i=this;if(!this.props.readOnly){var n,s,r,o,u=t.which||t.keyCode,a=this.caret();t.ctrlKey||t.altKey||t.metaKey||u<32||(u&&13!==u&&(a.end-a.begin!=0&&(this.clearBuffer(a.begin,a.end),this.shiftL(a.begin,a.end-1)),(n=this.seekNext(a.begin-1))<this.len&&(s=String.fromCharCode(u),this.tests[n].test(s))&&(this.shiftR(n),this.buffer[n]=s,this.writeBuffer(),r=this.seekNext(n),/android/i.test(e.DomHandler.getUserAgent())?setTimeout((function(){i.caret(r)}),0):this.caret(r),a.begin<=this.lastRequiredNonMaskPos&&(o=this.isCompleted())),t.preventDefault()),this.updateModel(t),this.props.onComplete&&o&&this.props.onComplete({originalEvent:t,value:this.getValue()}))}}},{key:"clearBuffer",value:function(t,e){var i;for(i=t;i<e&&i<this.len;i++)this.tests[i]&&(this.buffer[i]=this.getPlaceholder(i))}},{key:"writeBuffer",value:function(){this.inputRef.current.value=this.buffer.join("")}},{key:"checkVal",value:function(t){this.isValueChecked=!0;var e,i,n,s=this.inputRef.current.value,r=-1;for(e=0,n=0;e<this.len;e++)if(this.tests[e]){for(this.buffer[e]=this.getPlaceholder(e);n++<s.length;)if(i=s.charAt(n-1),this.tests[e].test(i)){this.buffer[e]=i,r=e;break}if(n>s.length){this.clearBuffer(e+1,this.len);break}}else this.buffer[e]===s.charAt(n)&&n++,e<this.partialPosition&&(r=e);return t?this.writeBuffer():r+1<this.partialPosition?this.props.autoClear||this.buffer.join("")===this.defaultBuffer?(this.inputRef.current.value&&(this.inputRef.current.value=""),this.clearBuffer(0,this.len)):this.writeBuffer():(this.writeBuffer(),this.inputRef.current.value=this.inputRef.current.value.substring(0,r+1)),this.partialPosition?e:this.firstNonMaskPos}},{key:"onFocus",value:function(t){var e,i=this;this.props.readOnly||(this.focus=!0,clearTimeout(this.caretTimeoutId),this.focusText=this.inputRef.current.value,e=this.checkVal(),this.caretTimeoutId=setTimeout((function(){i.inputRef.current===document.activeElement&&(i.writeBuffer(),e===i.props.mask.replace("?","").length?i.caret(0,e):i.caret(e),i.updateFilledState())}),10),this.props.onFocus&&this.props.onFocus(t))}},{key:"onInput",value:function(t){this.androidChrome?this.handleAndroidInput(t):this.handleInputChange(t)}},{key:"handleInputChange",value:function(t){if(!this.props.readOnly){var e=this.checkVal(!0);this.caret(e),this.updateModel(t),this.props.onComplete&&this.isCompleted()&&this.props.onComplete({originalEvent:t,value:this.getValue()})}}},{key:"getUnmaskedValue",value:function(){for(var t=[],e=0;e<this.buffer.length;e++){var i=this.buffer[e];this.tests[e]&&i!==this.getPlaceholder(e)&&t.push(i)}return t.join("")}},{key:"updateModel",value:function(t){if(this.props.onChange){var e=this.props.unmask?this.getUnmaskedValue():t&&t.target.value;this.props.onChange({originalEvent:t,value:this.defaultBuffer!==e?e:"",stopPropagation:function(){},preventDefault:function(){},target:{name:this.props.name,id:this.props.id,value:this.defaultBuffer!==e?e:""}})}}},{key:"updateFilledState",value:function(){this.inputRef&&this.inputRef.current&&this.inputRef.current.value&&this.inputRef.current.value.length>0?e.DomHandler.addClass(this.inputRef.current,"p-filled"):e.DomHandler.removeClass(this.inputRef.current,"p-filled")}},{key:"updateValue",value:function(t){var e,i=this;return this.inputRef&&this.inputRef.current&&(null==this.props.value?this.inputRef.current.value="":(this.inputRef.current.value=this.props.value,e=this.checkVal(t),setTimeout((function(){if(i.inputRef&&i.inputRef.current)return i.writeBuffer(),i.checkVal(t)}),10)),this.focusText=this.inputRef.current.value),this.updateFilledState(),e}},{key:"isValueUpdated",value:function(){return this.props.unmask?this.props.value!==this.getUnmaskedValue():this.defaultBuffer!==this.inputRef.current.value&&this.inputRef.current.value!==this.props.value}},{key:"init",value:function(){if(this.props.mask){this.tests=[],this.partialPosition=this.props.mask.length,this.len=this.props.mask.length,this.firstNonMaskPos=null,this.defs={9:"[0-9]",a:"[A-Za-z]","*":"[A-Za-z0-9]"};var t=e.DomHandler.getUserAgent();this.androidChrome=/chrome/i.test(t)&&/android/i.test(t);for(var i=this.props.mask.split(""),n=0;n<i.length;n++){var s=i[n];"?"===s?(this.len--,this.partialPosition=n):this.defs[s]?(this.tests.push(new RegExp(this.defs[s])),null===this.firstNonMaskPos&&(this.firstNonMaskPos=this.tests.length-1),n<this.partialPosition&&(this.lastRequiredNonMaskPos=this.tests.length-1)):this.tests.push(null)}this.buffer=[];for(var r=0;r<i.length;r++){var o=i[r];"?"!==o&&this.buffer.push(this.defs[o]?this.getPlaceholder(r):o)}this.defaultBuffer=this.buffer.join("")}}},{key:"updateInputRef",value:function(){var t=this.props.inputRef;t&&("function"==typeof t?t(this.inputRef.current):t.current=this.inputRef.current)}},{key:"componentDidMount",value:function(){this.updateInputRef(),this.init(),this.updateValue(),this.props.tooltip&&this.renderTooltip()}},{key:"componentDidUpdate",value:function(t){t.tooltip===this.props.tooltip&&t.tooltipOptions===this.props.tooltipOptions||(this.tooltip?this.tooltip.update(y({content:this.props.tooltip},this.props.tooltipOptions||{})):this.renderTooltip()),this.isValueUpdated()&&this.updateValue(),t.mask!==this.props.mask&&(this.init(),this.caret(this.updateValue(!0)),this.updateModel())}},{key:"componentWillUnmount",value:function(){this.tooltip&&(this.tooltip.destroy(),this.tooltip=null)}},{key:"renderTooltip",value:function(){this.tooltip=n.tip({target:this.inputRef.current,content:this.props.tooltip,options:this.props.tooltipOptions})}},{key:"render",value:function(){var t=e.classNames("p-inputmask",this.props.className);return r.default.createElement(i.InputText,{id:this.props.id,ref:this.inputRef,type:this.props.type,name:this.props.name,style:this.props.style,className:t,placeholder:this.props.placeholder,size:this.props.size,maxLength:this.props.maxLength,tabIndex:this.props.tabIndex,disabled:this.props.disabled,readOnly:this.props.readOnly,onFocus:this.onFocus,onBlur:this.onBlur,onKeyDown:this.onKeyDown,onKeyPress:this.onKeyPress,onInput:this.onInput,onPaste:this.handleInputChange,required:this.props.required,"aria-labelledby":this.props.ariaLabelledBy})}}])&&u(d.prototype,v),g&&u(d,g),Object.defineProperty(d,"prototype",{writable:!1}),k}();d(g,"defaultProps",{id:null,inputRef:null,value:null,type:"text",mask:null,slotChar:"_",autoClear:!0,unmask:!1,style:null,className:null,placeholder:null,size:null,maxLength:null,tabIndex:null,disabled:!1,readOnly:!1,name:null,required:!1,tooltip:null,tooltipOptions:null,ariaLabelledBy:null,onComplete:null,onChange:null,onFocus:null,onBlur:null}),exports.InputMask=g;