????

Your IP : 216.73.216.152


Current Path : C:/inetpub/vhost/bcvt.kontum.gov.vn/admin/assets/
Upload File :
Current File : C:/inetpub/vhost/bcvt.kontum.gov.vn/admin/assets/number-format-b7a5df47.js

import{P as f,R as B,j as D}from"./vendor-4ed091cd.js";function m(){}function j(){return!0}function y(r){return!!(r||"").match(/\d/)}function I(r){return r.replace(/[-[\]/{}()*+?.\\^$|]/g,"\\$&")}function $(r){switch(r){case"lakh":return/(\d+?)(?=(\d\d)+(\d)(?!\d))(\.\d+)?/g;case"wan":return/(\d)(?=(\d{4})+(?!\d))/g;case"thousand":default:return/(\d)(?=(\d{3})+(?!\d))/g}}function k(r,t,e){const n=$(e);let o=r.search(/[1-9]/);return o=o===-1?r.length:o,r.substring(0,o)+r.substring(o,r.length).replace(n,"$1"+t)}function R(r,t=!0){const e=r[0]==="-",n=e&&t;r=r.replace("-","");const o=r.split("."),s=o[0],i=o[1]||"";return{beforeDecimal:s,afterDecimal:i,hasNagation:e,addNegation:n}}function M(r){if(!r)return r;const t=r[0]==="-";t&&(r=r.substring(1,r.length));const e=r.split("."),n=e[0].replace(/^0+/,"")||"0",o=e[1]||"";return`${t?"-":""}${n}${o?`.${o}`:""}`}function T(r,t,e){let n="";const o=e?"0":"";for(let s=0;s<=t-1;s++)n+=r[s]||o;return n}function L(r,t,e){if(["","-"].indexOf(r)!==-1)return r;const n=r.indexOf(".")!==-1&&t,{beforeDecimal:o,afterDecimal:s,hasNagation:i}=R(r),a=parseFloat(`0.${s||"0"}`).toFixed(t).split("."),u=o.split("").reverse().reduce((p,d,S)=>p.length>S?(Number(p[0])+Number(d)).toString()+p.substring(1,p.length):d+p,a[0]),c=T(a[1]||"",Math.min(t,s.length),e);return`${i?"-":""}${u}${n?".":""}${c}`}function U(r,t){const e={};return Object.keys(r).forEach(n=>{t[n]||(e[n]=r[n])}),e}function V(r,t){if(r!==null){if(r.createTextRange){const e=r.createTextRange();return e.move("character",t),e.select(),!0}return r.selectionStart||r.selectionStart===0?(r.focus(),r.setSelectionRange(t,t),!0):(r.focus(),!1)}}function K(r,t){let e=0,n=0;const o=r.length,s=t.length;for(;r[e]===t[e]&&e<o;)e++;for(;r[o-1-n]===t[s-1-n]&&s-n>e&&o-n>e;)n++;return{start:e,end:o-n}}function P(r,t,e){return Math.min(Math.max(r,t),e)}function A(r){return Math.max(r.selectionStart,r.selectionEnd)}const E={thousandSeparator:f.oneOfType([f.string,f.oneOf([!0])]),decimalSeparator:f.string,thousandsGroupStyle:f.oneOf(["thousand","lakh","wan"]),decimalScale:f.number,fixedDecimalScale:f.bool,displayType:f.oneOf(["input","text"]),prefix:f.string,suffix:f.string,format:f.oneOfType([f.string,f.func]),removeFormatting:f.func,mask:f.oneOfType([f.string,f.arrayOf(f.string)]),value:f.oneOfType([f.number,f.string]),defaultValue:f.oneOfType([f.number,f.string]),isNumericString:f.bool,customInput:f.elementType,allowNegative:f.bool,allowEmptyFormatting:f.bool,allowLeadingZeros:f.bool,onValueChange:f.func,onKeyDown:f.func,onMouseUp:f.func,onChange:f.func,onFocus:f.func,onBlur:f.func,type:f.oneOf(["text","tel","password"]),isAllowed:f.func,renderText:f.func,getInputRef:f.func},G={displayType:"input",decimalSeparator:".",thousandsGroupStyle:"thousand",fixedDecimalScale:!1,prefix:"",suffix:"",allowNegative:!0,allowEmptyFormatting:!1,allowLeadingZeros:!1,isNumericString:!1,type:"text",onValueChange:m,onChange:m,onKeyDown:m,onMouseUp:m,onFocus:m,onBlur:m,isAllowed:j,getInputRef:m};class O extends B.Component{constructor(t){super(t);const{defaultValue:e}=t;this.validateProps();const n=this.formatValueProp(e);this.state={value:n,numAsString:this.removeFormatting(n)},this.selectionBeforeInput={selectionStart:0,selectionEnd:0},this.onChange=this.onChange.bind(this),this.onKeyDown=this.onKeyDown.bind(this),this.onMouseUp=this.onMouseUp.bind(this),this.onFocus=this.onFocus.bind(this),this.onBlur=this.onBlur.bind(this)}componentDidUpdate(t){this.updateValueIfRequired(t)}updateValueIfRequired(t){const{props:e,state:n,focusedElm:o}=this,{value:s,numAsString:i=""}=n;if(t!==e){this.validateProps();const a=this.formatNumString(i),u=e.value===void 0?a:this.formatValueProp(),c=this.removeFormatting(u),l=parseFloat(c),h=parseFloat(i);((!isNaN(l)||!isNaN(h))&&l!==h||a!==s||o===null&&u!==s)&&this.updateValue({formattedValue:u,numAsString:c,input:o})}}getFloatString(t=""){const{decimalScale:e}=this.props,{decimalSeparator:n}=this.getSeparators(),o=this.getNumberRegex(!0),s=t[0]==="-";s&&(t=t.replace("-","")),n&&e===0&&(t=t.split(n)[0]),t=(t.match(o)||[]).join("").replace(n,".");const i=t.indexOf(".");return i!==-1&&(t=`${t.substring(0,i)}.${t.substring(i+1,t.length).replace(new RegExp(I(n),"g"),"")}`),s&&(t="-"+t),t}getNumberRegex(t,e){const{format:n,decimalScale:o}=this.props,{decimalSeparator:s}=this.getSeparators();return new RegExp("\\d"+(s&&o!==0&&!e&&!n?"|"+I(s):""),t?"g":void 0)}getSeparators(){const{decimalSeparator:t}=this.props;let{thousandSeparator:e}=this.props;return e===!0&&(e=","),{decimalSeparator:t,thousandSeparator:e}}getMaskAtIndex(t){const{mask:e=" "}=this.props;return typeof e=="string"?e:e[t]||" "}getValueObject(t,e){const n=parseFloat(e);return{formattedValue:t,value:e,floatValue:isNaN(n)?void 0:n}}validateProps(){const{mask:t}=this.props,{decimalSeparator:e,thousandSeparator:n}=this.getSeparators();if(e===n)throw new Error(`
          Decimal separator can't be same as thousand separator.
          thousandSeparator: ${n} (thousandSeparator = {true} is same as thousandSeparator = ",")
          decimalSeparator: ${e} (default value for decimalSeparator is .)
       `);if(t&&(t==="string"?t:t.toString()).match(/\d/g))throw new Error(`
          Mask ${t} should not contain numeric character;
        `)}setPatchedCaretPosition(t,e,n){V(t,e),setTimeout(()=>{t.value===n&&V(t,e)},0)}correctCaretPosition(t,e,n){const{prefix:o,suffix:s,format:i}=this.props;if(t==="")return 0;if(e=P(e,0,t.length),!i){const d=t[0]==="-";return P(e,o.length+(d?1:0),t.length-s.length)}if(typeof i=="function"||i[e]==="#"&&y(t[e])||i[e-1]==="#"&&y(t[e-1]))return e;const a=i.indexOf("#"),u=i.lastIndexOf("#");e=P(e,a,u+1);const c=i.substring(e,i.length).indexOf("#");let l=e;const h=e+(c===-1?0:c);for(;l>a&&(i[l]!=="#"||!y(t[l]));)l-=1;return!y(t[h])||n==="left"&&e!==a||e-l<h-e?y(t[l])?l+1:l:h}getCaretPosition(t,e,n){const{format:o}=this.props,s=this.state.value,i=this.getNumberRegex(!0),a=(t.match(i)||[]).join(""),u=(e.match(i)||[]).join("");let c,l;for(c=0,l=0;l<n;l++){const h=t[l]||"",p=e[c]||"";if(!(!h.match(i)&&h!==p)&&!(h==="0"&&p.match(i)&&p!=="0"&&a.length!==u.length)){for(;h!==e[c]&&c<e.length;)c++;c++}}return typeof o=="string"&&!s&&(c=e.length),c=this.correctCaretPosition(e,c),c}removePrefixAndSuffix(t){const{format:e,prefix:n,suffix:o}=this.props;if(!e&&t){const s=t[0]==="-";s&&(t=t.substring(1,t.length)),t=n&&t.indexOf(n)===0?t.substring(n.length,t.length):t;const i=t.lastIndexOf(o);t=o&&i!==-1&&i===t.length-o.length?t.substring(0,i):t,s&&(t="-"+t)}return t}removePatternFormatting(t){const{format:e}=this.props,n=e.split("#").filter(i=>i!=="");let o=0,s="";for(let i=0,a=n.length;i<=a;i++){const u=n[i]||"",c=i===a?t.length:t.indexOf(u,o);if(c===-1){s=t;break}else s+=t.substring(o,c),o=c+u.length}return(s.match(/\d/g)||[]).join("")}removeFormatting(t){const{format:e,removeFormatting:n}=this.props;return t&&(e?typeof e=="string"?t=this.removePatternFormatting(t):typeof n=="function"?t=n(t):t=(t.match(/\d/g)||[]).join(""):(t=this.removePrefixAndSuffix(t),t=this.getFloatString(t)),t)}formatWithPattern(t){const{format:e}=this.props;let n=0;const o=e.split("");for(let s=0,i=e.length;s<i;s++)e[s]==="#"&&(o[s]=t[n]||this.getMaskAtIndex(n),n+=1);return o.join("")}formatAsNumber(t){const{decimalScale:e,fixedDecimalScale:n,prefix:o,suffix:s,allowNegative:i,thousandsGroupStyle:a}=this.props,{thousandSeparator:u,decimalSeparator:c}=this.getSeparators(),l=t.indexOf(".")!==-1||e&&n;let{beforeDecimal:h,afterDecimal:p,addNegation:d}=R(t,i);return e!==void 0&&(p=T(p,e,n)),u&&(h=k(h,u,a)),o&&(h=o+h),s&&(p=p+s),d&&(h="-"+h),t=h+(l&&c||"")+p,t}formatNumString(t=""){const{format:e,allowEmptyFormatting:n}=this.props;let o=t;return t===""&&!n?o="":t==="-"&&!e?o="-":typeof e=="string"?o=this.formatWithPattern(o):typeof e=="function"?o=e(o):o=this.formatAsNumber(o),o}formatValueProp(t){const{format:e,decimalScale:n,fixedDecimalScale:o,allowEmptyFormatting:s}=this.props;let{value:i=t,isNumericString:a}=this.props;const u=!i&&i!==0;return u&&s&&(i=""),u&&!s?"":(typeof i=="number"&&(i=i.toString(),a=!0),i==="Infinity"&&a&&(i=""),a&&!e&&typeof n=="number"&&(i=L(i,n,o)),a?this.formatNumString(i):this.formatInput(i))}formatNegation(t=""){const{allowNegative:e}=this.props,n=new RegExp("(-)"),o=new RegExp("(-)(.)*(-)"),s=n.test(t),i=o.test(t);return t=t.replace(/-/g,""),s&&!i&&e&&(t="-"+t),t}formatInput(t=""){const{format:e}=this.props;return e||(t=this.removePrefixAndSuffix(t),t=this.formatNegation(t)),t=this.removeFormatting(t),this.formatNumString(t)}isCharacterAFormat(t,e){const{format:n,prefix:o,suffix:s,decimalScale:i,fixedDecimalScale:a}=this.props,{decimalSeparator:u}=this.getSeparators();return!!(typeof n=="string"&&n[t]!=="#"||!n&&(t<o.length||t>=e.length-s.length||i&&a&&e[t]===u))}checkIfFormatGotDeleted(t,e,n){for(let o=t;o<e;o++)if(this.isCharacterAFormat(o,n))return!0;return!1}correctInputValue(t,e,n){const{format:o,allowNegative:s,prefix:i,suffix:a}=this.props,{decimalSeparator:u}=this.getSeparators(),c=this.state.numAsString||"",{selectionStart:l,selectionEnd:h}=this.selectionBeforeInput,{start:p,end:d}=K(e,n);if(!o&&u!=="."&&p===d&&n[l]===".")return n.substr(0,l)+u+n.substr(l+1,n.length);const S=o?0:i.length,x=e.length-(o?0:a.length);if(n.length>e.length||!n.length||p===d||l===0&&h===e.length||l===S&&h===x)return n;if(this.checkIfFormatGotDeleted(p,d,e)&&(n=e),!o){const b=this.removeFormatting(n);let{beforeDecimal:w,afterDecimal:g,addNegation:N}=R(b,s);const F=t<n.indexOf(u)+1;if(b.length<c.length&&F&&w===""&&!parseFloat(g))return N?"-":""}return n}updateValue(t,e){const{formattedValue:n,input:o}=t;let{numAsString:s,caretPos:i}=t;const{onValueChange:a}=this.props,{value:u}=this.state;if(o){if(!i){const c=t.inputValue||o.value,l=A(o);i=this.getCaretPosition(c,n,l)}o.value=n,this.setPatchedCaretPosition(o,i,n)}s===void 0&&(s=this.removeFormatting(n)),n!==u&&this.setState({value:n,numAsString:s},()=>{a(this.getValueObject(n,s))})}onChange(t){t.persist();const e=t.target;let n=e.value;const{state:o,props:s}=this,{isAllowed:i}=s,a=o.value||"",u=A(e);n=this.correctInputValue(u,a,n);let c=this.formatInput(n)||"";const l=this.removeFormatting(c),h=this.getValueObject(c,l);i(h)||(c=a),this.updateValue({formattedValue:c,numAsString:l,inputValue:n,input:e},()=>{s.onChange(t)})}onBlur(t){const{props:e,state:n}=this,{format:o,onBlur:s,allowLeadingZeros:i}=e;let{numAsString:a}=n;const u=n.value;if(this.focusedElm=null,!o){i||(a=M(a));const c=this.formatNumString(a);if(c!==u){t.persist(),this.updateValue({formattedValue:c,numAsString:a},()=>{s(t)});return}}s(t)}onKeyDown(t){const e=t.target,{key:n}=t,{selectionStart:o,selectionEnd:s,value:i=""}=e;let a;const{decimalScale:u,fixedDecimalScale:c,prefix:l,suffix:h,format:p,onKeyDown:d}=this.props,S=u!==void 0&&c,x=this.getNumberRegex(!1,S),b=new RegExp("-"),w=typeof p=="string";if(this.selectionBeforeInput={selectionStart:o,selectionEnd:s},n==="ArrowLeft"||n==="Backspace"?a=o-1:n==="ArrowRight"?a=o+1:n==="Delete"&&(a=o),a===void 0||o!==s){d(t);return}let g=a;const N=w?p.indexOf("#"):l.length,F=w?p.lastIndexOf("#")+1:i.length-h.length;if(n==="ArrowLeft"||n==="ArrowRight"){const C=n==="ArrowLeft"?"left":"right";g=this.correctCaretPosition(i,a,C)}else if(n==="Delete"&&!x.test(i[a])&&!b.test(i[a]))for(;!x.test(i[g])&&g<F;)g++;else if(n==="Backspace"&&!x.test(i[a])){if(o<=N+1&&i[0]==="-"&&typeof p>"u"){const C=i.substring(1);t.persist(),this.updateValue({formattedValue:C,caretPos:g,input:e})}else if(!b.test(i[a])){for(;!x.test(i[g-1])&&g>N;)g--;g=this.correctCaretPosition(i,g,"left")}}(g!==a||a<N||a>F)&&(t.preventDefault(),this.setPatchedCaretPosition(e,g,i)),t.isUnitTestRun&&this.setPatchedCaretPosition(e,g,i),this.props.onKeyDown(t)}onMouseUp(t){const e=t.target,{selectionStart:n,selectionEnd:o,value:s=""}=e;if(n===o){const i=this.correctCaretPosition(s,n);i!==n&&this.setPatchedCaretPosition(e,i,s)}this.props.onMouseUp(t)}onFocus(t){t.persist(),this.focusedElm=t.target,setTimeout(()=>{const e=t.target,{selectionStart:n,selectionEnd:o,value:s=""}=e,i=this.correctCaretPosition(s,n);i!==n&&!(n===0&&o===s.length)&&this.setPatchedCaretPosition(e,i,s),this.props.onFocus(t)},0)}render(){const{type:t,displayType:e,customInput:n,renderText:o,getInputRef:s}=this.props,{value:i}=this.state,a=U(this.props,E),u=Object.assign({},a,{type:t,value:i,onChange:this.onChange,onKeyDown:this.onKeyDown,onMouseUp:this.onMouseUp,onFocus:this.onFocus,onBlur:this.onBlur});if(e==="text")return o?o(i)||null:D.jsx("span",{...a,ref:s,children:i});if(n){const c=n;return D.jsx(c,{...u,ref:s})}return D.jsx("input",{...u,ref:s})}}O.propTypes=E;O.defaultProps=G;const H=O;export{H as N};