@equinor/roma-ui 0.2.1 → 0.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/NumberField/NumberField.d.ts +3 -1
- package/number.js +1 -1
- package/number.mjs +92 -90
- package/package.json +1 -1
|
@@ -1,3 +1,5 @@
|
|
|
1
1
|
import { InputProps } from '@equinor/eds-core-react';
|
|
2
2
|
import { AriaNumberFieldProps } from '@react-types/numberfield';
|
|
3
|
-
export declare const NumberField: import('react').ForwardRefExoticComponent<InputProps & AriaNumberFieldProps &
|
|
3
|
+
export declare const NumberField: import('react').ForwardRefExoticComponent<InputProps & AriaNumberFieldProps & {
|
|
4
|
+
locale?: string;
|
|
5
|
+
} & import('react').RefAttributes<unknown>>;
|
package/number.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const me=require("react/jsx-runtime"),u=require("react"),de=require("react-aria"),fe=require("@equinor/eds-core-react"),pe=require("./useControlledState-D0L6S_5r.js");function L(r,e=-1/0,t=1/0){return Math.min(Math.max(r,e),t)}function A(r,e){let t=r,i=e.toString(),n=i.indexOf("."),a=n>=0?i.length-n:0;if(a>0){let l=Math.pow(10,a);t=Math.round(t*l)/l}return t}function M(r,e,t,i){e=Number(e),t=Number(t);let n=(r-(isNaN(e)?0:e))%i,a=A(Math.abs(n)*2>=i?r+Math.sign(n)*(i-Math.abs(n)):r-n,i);return isNaN(e)?!isNaN(t)&&a>t&&(a=Math.floor(A(t/i,i))*i):a<e?a=e:!isNaN(t)&&a>t&&(a=e+Math.floor(A((t-e)/i,i))*i),a=A(a,i),a}const ee={badInput:!1,customError:!1,patternMismatch:!1,rangeOverflow:!1,rangeUnderflow:!1,stepMismatch:!1,tooLong:!1,tooShort:!1,typeMismatch:!1,valueMissing:!1,valid:!0},te={...ee,customError:!0,valid:!1},O={isInvalid:!1,validationDetails:ee,validationErrors:[]},be=u.createContext({}),Y="__formValidationState"+Date.now();function he(r){if(r[Y]){let{realtimeValidation:e,displayValidation:t,updateValidation:i,resetValidation:n,commitValidation:a}=r[Y];return{realtimeValidation:e,displayValidation:t,updateValidation:i,resetValidation:n,commitValidation:a}}return ge(r)}function ge(r){let{isInvalid:e,validationState:t,name:i,value:n,builtinValidation:a,validate:l,validationBehavior:o="aria"}=r;t&&(e||(e=t==="invalid"));let m=e!==void 0?{isInvalid:e,validationErrors:[],validationDetails:te}:null,V=u.useMemo(()=>{if(!l||n==null)return null;let s=$e(l,n);return k(s)},[l,n]);a!=null&&a.validationDetails.valid&&(a=void 0);let h=u.useContext(be),f=u.useMemo(()=>i?Array.isArray(i)?i.flatMap(s=>G(h[s])):G(h[i]):[],[h,i]),[g,$]=u.useState(h),[p,b]=u.useState(!1);h!==g&&($(h),b(!1));let D=u.useMemo(()=>k(p?[]:f),[p,f]),w=u.useRef(O),[x,y]=u.useState(O),v=u.useRef(O),d=()=>{if(!P)return;S(!1);let s=V||a||w.current;q(s,v.current)||(v.current=s,y(s))},[P,S]=u.useState(!1);return u.useEffect(d),{realtimeValidation:m||D||V||a||O,displayValidation:o==="native"?m||D||x:m||D||V||a||x,updateValidation(s){o==="aria"&&!q(x,s)?y(s):w.current=s},resetValidation(){let s=O;q(s,v.current)||(v.current=s,y(s)),o==="native"&&S(!1),b(!0)},commitValidation(){o==="native"&&S(!0),b(!0)}}}function G(r){return r?Array.isArray(r)?r:[r]:[]}function $e(r,e){if(typeof r=="function"){let t=r(e);if(t&&typeof t!="boolean")return G(t)}return[]}function k(r){return r.length?{isInvalid:!0,validationErrors:r,validationDetails:te}:null}function q(r,e){return r===e?!0:!!r&&!!e&&r.isInvalid===e.isInvalid&&r.validationErrors.length===e.validationErrors.length&&r.validationErrors.every((t,i)=>t===e.validationErrors[i])&&Object.entries(r.validationDetails).every(([t,i])=>e.validationDetails[t]===i)}let z=new Map,U=!1;try{U=new Intl.NumberFormat("de-DE",{signDisplay:"exceptZero"}).resolvedOptions().signDisplay==="exceptZero"}catch{}let j=!1;try{j=new Intl.NumberFormat("de-DE",{style:"unit",unit:"degree"}).resolvedOptions().style==="unit"}catch{}const ie={degree:{narrow:{default:"°","ja-JP":" 度","zh-TW":"度","sl-SI":" °"}}};class Z{format(e){let t="";if(!U&&this.options.signDisplay!=null?t=ve(this.numberFormatter,this.options.signDisplay,e):t=this.numberFormatter.format(e),this.options.style==="unit"&&!j){var i;let{unit:n,unitDisplay:a="short",locale:l}=this.resolvedOptions();if(!n)return t;let o=(i=ie[n])===null||i===void 0?void 0:i[a];t+=o[l]||o.default}return t}formatToParts(e){return this.numberFormatter.formatToParts(e)}formatRange(e,t){if(typeof this.numberFormatter.formatRange=="function")return this.numberFormatter.formatRange(e,t);if(t<e)throw new RangeError("End date must be >= start date");return`${this.format(e)} – ${this.format(t)}`}formatRangeToParts(e,t){if(typeof this.numberFormatter.formatRangeToParts=="function")return this.numberFormatter.formatRangeToParts(e,t);if(t<e)throw new RangeError("End date must be >= start date");let i=this.numberFormatter.formatToParts(e),n=this.numberFormatter.formatToParts(t);return[...i.map(a=>({...a,source:"startRange"})),{type:"literal",value:" – ",source:"shared"},...n.map(a=>({...a,source:"endRange"}))]}resolvedOptions(){let e=this.numberFormatter.resolvedOptions();return!U&&this.options.signDisplay!=null&&(e={...e,signDisplay:this.options.signDisplay}),!j&&this.options.style==="unit"&&(e={...e,style:"unit",unit:this.options.unit,unitDisplay:this.options.unitDisplay}),e}constructor(e,t={}){this.numberFormatter=ye(e,t),this.options=t}}function ye(r,e={}){let{numberingSystem:t}=e;if(t&&r.includes("-nu-")&&(r.includes("-u-")||(r+="-u-"),r+=`-nu-${t}`),e.style==="unit"&&!j){var i;let{unit:l,unitDisplay:o="short"}=e;if(!l)throw new Error('unit option must be provided with style: "unit"');if(!(!((i=ie[l])===null||i===void 0)&&i[o]))throw new Error(`Unsupported unit ${l} with unitDisplay = ${o}`);e={...e,style:"decimal"}}let n=r+(e?Object.entries(e).sort((l,o)=>l[0]<o[0]?-1:1).join():"");if(z.has(n))return z.get(n);let a=new Intl.NumberFormat(r,e);return z.set(n,a),a}function ve(r,e,t){if(e==="auto")return r.format(t);if(e==="never")return r.format(Math.abs(t));{let i=!1;if(e==="always"?i=t>0||Object.is(t,0):e==="exceptZero"&&(Object.is(t,-0)||Object.is(t,0)?t=Math.abs(t):i=t>0),i){let n=r.format(-t),a=r.format(t),l=n.replace(a,"").replace(/\u200e|\u061C/,"");return[...l].length!==1&&console.warn("@react-aria/i18n polyfill for NumberFormat signDisplay: Unsupported case"),n.replace(a,"!!!").replace(l,"+").replace("!!!",a)}else return r.format(t)}}const Ne=new RegExp("^.*\\(.*\\).*$"),Ve=["latn","arab","hanidec","deva","beng"];class re{parse(e){return W(this.locale,this.options,e).parse(e)}isValidPartialNumber(e,t,i){return W(this.locale,this.options,e).isValidPartialNumber(e,t,i)}getNumberingSystem(e){return W(this.locale,this.options,e).options.numberingSystem}constructor(e,t={}){this.locale=e,this.options=t}}const Q=new Map;function W(r,e,t){let i=J(r,e);if(!r.includes("-nu-")&&!i.isValidPartialNumber(t)){for(let n of Ve)if(n!==i.options.numberingSystem){let a=J(r+(r.includes("-u-")?"-nu-":"-u-nu-")+n,e);if(a.isValidPartialNumber(t))return a}}return i}function J(r,e){let t=r+(e?Object.entries(e).sort((n,a)=>n[0]<a[0]?-1:1).join():""),i=Q.get(t);return i||(i=new Se(r,e),Q.set(t,i)),i}class Se{parse(e){let t=this.sanitize(e);if(this.symbols.group&&(t=T(t,this.symbols.group,"")),this.symbols.decimal&&(t=t.replace(this.symbols.decimal,".")),this.symbols.minusSign&&(t=t.replace(this.symbols.minusSign,"-")),t=t.replace(this.symbols.numeral,this.symbols.index),this.options.style==="percent"){let l=t.indexOf("-");t=t.replace("-",""),t=t.replace("+","");let o=t.indexOf(".");o===-1&&(o=t.length),t=t.replace(".",""),o-2===0?t=`0.${t}`:o-2===-1?t=`0.0${t}`:o-2===-2?t="0.00":t=`${t.slice(0,o-2)}.${t.slice(o-2)}`,l>-1&&(t=`-${t}`)}let i=t?+t:NaN;if(isNaN(i))return NaN;if(this.options.style==="percent"){var n,a;let l={...this.options,style:"decimal",minimumFractionDigits:Math.min(((n=this.options.minimumFractionDigits)!==null&&n!==void 0?n:0)+2,20),maximumFractionDigits:Math.min(((a=this.options.maximumFractionDigits)!==null&&a!==void 0?a:0)+2,20)};return new re(this.locale,l).parse(new Z(this.locale,l).format(i))}return this.options.currencySign==="accounting"&&Ne.test(e)&&(i=-1*i),i}sanitize(e){return e=e.replace(this.symbols.literals,""),this.symbols.minusSign&&(e=e.replace("-",this.symbols.minusSign)),this.options.numberingSystem==="arab"&&(this.symbols.decimal&&(e=e.replace(",",this.symbols.decimal),e=e.replace("،",this.symbols.decimal)),this.symbols.group&&(e=T(e,".",this.symbols.group))),this.options.locale==="fr-FR"&&this.symbols.group&&(e=T(e," ",this.symbols.group),e=T(e,/\u00A0/g,this.symbols.group)),e}isValidPartialNumber(e,t=-1/0,i=1/0){return e=this.sanitize(e),this.symbols.minusSign&&e.startsWith(this.symbols.minusSign)&&t<0?e=e.slice(this.symbols.minusSign.length):this.symbols.plusSign&&e.startsWith(this.symbols.plusSign)&&i>0&&(e=e.slice(this.symbols.plusSign.length)),this.symbols.group&&e.startsWith(this.symbols.group)||this.symbols.decimal&&e.indexOf(this.symbols.decimal)>-1&&this.options.maximumFractionDigits===0?!1:(this.symbols.group&&(e=T(e,this.symbols.group,"")),e=e.replace(this.symbols.numeral,""),this.symbols.decimal&&(e=e.replace(this.symbols.decimal,"")),e.length===0)}constructor(e,t={}){this.locale=e,t.roundingIncrement!==1&&t.roundingIncrement!=null&&(t.maximumFractionDigits==null&&t.minimumFractionDigits==null?(t.maximumFractionDigits=0,t.minimumFractionDigits=0):t.maximumFractionDigits==null?t.maximumFractionDigits=t.minimumFractionDigits:t.minimumFractionDigits==null&&(t.minimumFractionDigits=t.maximumFractionDigits)),this.formatter=new Intl.NumberFormat(e,t),this.options=this.formatter.resolvedOptions(),this.symbols=we(e,this.formatter,this.options,t);var i,n;this.options.style==="percent"&&(((i=this.options.minimumFractionDigits)!==null&&i!==void 0?i:0)>18||((n=this.options.maximumFractionDigits)!==null&&n!==void 0?n:0)>18)&&console.warn("NumberParser cannot handle percentages with greater than 18 decimal places, please reduce the number in your options.")}}const X=new Set(["decimal","fraction","integer","minusSign","plusSign","group"]),De=[0,4,2,1,11,20,3,7,100,21,.1,1.1];function we(r,e,t,i){var n,a,l,o;let m=new Intl.NumberFormat(r,{...t,minimumSignificantDigits:1,maximumSignificantDigits:21,roundingIncrement:1,roundingPriority:"auto",roundingMode:"halfExpand"}),V=m.formatToParts(-10000.111),h=m.formatToParts(10000.111),f=De.map(s=>m.formatToParts(s));var g;let $=(g=(n=V.find(s=>s.type==="minusSign"))===null||n===void 0?void 0:n.value)!==null&&g!==void 0?g:"-",p=(a=h.find(s=>s.type==="plusSign"))===null||a===void 0?void 0:a.value;!p&&((i==null?void 0:i.signDisplay)==="exceptZero"||(i==null?void 0:i.signDisplay)==="always")&&(p="+");let D=(l=new Intl.NumberFormat(r,{...t,minimumFractionDigits:2,maximumFractionDigits:2}).formatToParts(.001).find(s=>s.type==="decimal"))===null||l===void 0?void 0:l.value,w=(o=V.find(s=>s.type==="group"))===null||o===void 0?void 0:o.value,x=V.filter(s=>!X.has(s.type)).map(s=>H(s.value)),y=f.flatMap(s=>s.filter(E=>!X.has(E.type)).map(E=>H(E.value))),v=[...new Set([...x,...y])].sort((s,E)=>E.length-s.length),d=v.length===0?new RegExp("[\\p{White_Space}]","gu"):new RegExp(`${v.join("|")}|[\\p{White_Space}]`,"gu"),P=[...new Intl.NumberFormat(t.locale,{useGrouping:!1}).format(9876543210)].reverse(),S=new Map(P.map((s,E)=>[s,E])),F=new RegExp(`[${P.join("")}]`,"g");return{minusSign:$,plusSign:p,decimal:D,group:w,literals:d,numeral:F,index:s=>String(S.get(s))}}function T(r,e,t){return r.replaceAll?r.replaceAll(e,t):r.split(e).join(t)}function H(r){return r.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function xe(r){let{minValue:e,maxValue:t,step:i,formatOptions:n,value:a,defaultValue:l=NaN,onChange:o,locale:m,isDisabled:V,isReadOnly:h}=r;a===null&&(a=NaN),a!==void 0&&!isNaN(a)&&(i!==void 0&&!isNaN(i)?a=M(a,e,t,i):a=L(a,e,t)),isNaN(l)||(i!==void 0&&!isNaN(i)?l=M(l,e,t,i):l=L(l,e,t));let[f,g]=pe.$458b0a5536c1a7cf$export$40bfa8c7b0832715(a,isNaN(l)?NaN:l,o),[$,p]=u.useState(()=>isNaN(f)?"":new Z(m,n).format(f)),b=u.useMemo(()=>new re(m,n),[m,n]),D=u.useMemo(()=>b.getNumberingSystem($),[b,$]),w=u.useMemo(()=>new Z(m,{...n,numberingSystem:D}),[m,n,D]),x=u.useMemo(()=>w.resolvedOptions(),[w]),y=u.useCallback(c=>isNaN(c)||c===null?"":w.format(c),[w]),v=he({...r,value:f}),d=i!==void 0&&!isNaN(i)?i:1;x.style==="percent"&&(i===void 0||isNaN(i))&&(d=.01);let[P,S]=u.useState(f),[F,I]=u.useState(m),[s,E]=u.useState(n);(!Object.is(f,P)||m!==F||n!==s)&&(p(y(f)),S(f),I(m),E(n));let N=u.useMemo(()=>b.parse($),[b,$]),ae=()=>{if(!$.length){g(NaN),p(a===void 0?"":y(f));return}if(isNaN(N)){p(y(f));return}let c;i===void 0||isNaN(i)?c=L(N,e,t):c=M(N,e,t,i),c=b.parse(y(c)),g(c),p(y(a===void 0?c:f))},B=(c,K=0)=>{let R=N;if(isNaN(R)){let C=isNaN(K)?0:K;return M(C,e,t,d)}else{let C=M(R,e,t,d);return c==="+"&&C>R||c==="-"&&C<R?C:M(_(c,R,d),e,t,d)}},ne=()=>{let c=B("+",e);c===f&&p(y(c)),g(c),v.commitValidation()},se=()=>{let c=B("-",t);c===f&&p(y(c)),g(c),v.commitValidation()},le=()=>{t!=null&&(g(M(t,e,t,d)),v.commitValidation())},oe=()=>{e!=null&&(g(e),v.commitValidation())},ue=u.useMemo(()=>!V&&!h&&(isNaN(N)||t===void 0||isNaN(t)||M(N,e,t,d)>N||_("+",N,d)<=t),[V,h,e,t,d,N]),ce=u.useMemo(()=>!V&&!h&&(isNaN(N)||e===void 0||isNaN(e)||M(N,e,t,d)<N||_("-",N,d)>=e),[V,h,e,t,d,N]);return{...v,validate:c=>b.isValidPartialNumber(c,e,t),increment:ne,incrementToMax:le,decrement:se,decrementToMin:oe,canIncrement:ue,canDecrement:ce,minValue:e,maxValue:t,numberValue:N,setNumberValue:g,setInputValue:p,inputValue:$,commit:ae}}function _(r,e,t){let i=r==="+"?e+t:e-t;if(e%1!==0||t%1!==0){const n=e.toString().split("."),a=t.toString().split("."),l=n[1]&&n[1].length||0,o=a[1]&&a[1].length||0,m=Math.pow(10,Math.max(l,o));e=Math.round(e*m),t=Math.round(t*m),i=r==="+"?e+t:e-t,i/=m}return i}const Pe=u.forwardRef(({placeholder:r,variant:e,disabled:t,type:i,readOnly:n,leftAdornments:a,rightAdornments:l,leftAdornmentsProps:o,rightAdornmentsProps:m,leftAdornmentsWidth:V,rightAdornmentsWidth:h,className:f,style:g,label:$,value:p,...b},D)=>{const x=xe({...b,label:$,value:p,onChange:d=>{b.onChange&&b.onChange(d)},locale:"nb-NO"}),y=u.useRef(null),{inputProps:v}=de.useNumberField({...b,label:$,value:p},x,y);return me.jsx(fe.Input,{placeholder:r,variant:e,disabled:t,type:i,readOnly:n,leftAdornments:a,rightAdornments:l,leftAdornmentsProps:o,rightAdornmentsProps:m,leftAdornmentsWidth:V,rightAdornmentsWidth:h,className:f,style:g,"data-testid":`number-field-${$}`,...v,onKeyDown:d=>{var P;if(d.key==="."){d.preventDefault();const S=d.target;if((P=S.value)!=null&&P.includes(","))return;const F=S.selectionStart||0,I=S.selectionEnd||0;S.value=S.value.substring(0,F)+","+S.value.substring(I)}},ref:D,"aria-label":$})});exports.NumberField=Pe;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const ce=require("react/jsx-runtime"),u=require("react"),de=require("react-aria"),fe=require("@equinor/eds-core-react"),pe=require("./useControlledState-D0L6S_5r.js");function L(r,e=-1/0,t=1/0){return Math.min(Math.max(r,e),t)}function A(r,e){let t=r,i=e.toString(),n=i.indexOf("."),a=n>=0?i.length-n:0;if(a>0){let l=Math.pow(10,a);t=Math.round(t*l)/l}return t}function M(r,e,t,i){e=Number(e),t=Number(t);let n=(r-(isNaN(e)?0:e))%i,a=A(Math.abs(n)*2>=i?r+Math.sign(n)*(i-Math.abs(n)):r-n,i);return isNaN(e)?!isNaN(t)&&a>t&&(a=Math.floor(A(t/i,i))*i):a<e?a=e:!isNaN(t)&&a>t&&(a=e+Math.floor(A((t-e)/i,i))*i),a=A(a,i),a}const ee={badInput:!1,customError:!1,patternMismatch:!1,rangeOverflow:!1,rangeUnderflow:!1,stepMismatch:!1,tooLong:!1,tooShort:!1,typeMismatch:!1,valueMissing:!1,valid:!0},te={...ee,customError:!0,valid:!1},O={isInvalid:!1,validationDetails:ee,validationErrors:[]},be=u.createContext({}),Y="__formValidationState"+Date.now();function he(r){if(r[Y]){let{realtimeValidation:e,displayValidation:t,updateValidation:i,resetValidation:n,commitValidation:a}=r[Y];return{realtimeValidation:e,displayValidation:t,updateValidation:i,resetValidation:n,commitValidation:a}}return ge(r)}function ge(r){let{isInvalid:e,validationState:t,name:i,value:n,builtinValidation:a,validate:l,validationBehavior:o="aria"}=r;t&&(e||(e=t==="invalid"));let d=e!==void 0?{isInvalid:e,validationErrors:[],validationDetails:te}:null,V=u.useMemo(()=>{if(!l||n==null)return null;let s=ye(l,n);return k(s)},[l,n]);a!=null&&a.validationDetails.valid&&(a=void 0);let h=u.useContext(be),f=u.useMemo(()=>i?Array.isArray(i)?i.flatMap(s=>K(h[s])):K(h[i]):[],[h,i]),[g,y]=u.useState(h),[p,$]=u.useState(!1);h!==g&&(y(h),$(!1));let D=u.useMemo(()=>k(p?[]:f),[p,f]),w=u.useRef(O),[x,v]=u.useState(O),b=u.useRef(O),c=()=>{if(!P)return;S(!1);let s=V||a||w.current;q(s,b.current)||(b.current=s,v(s))},[P,S]=u.useState(!1);return u.useEffect(c),{realtimeValidation:d||D||V||a||O,displayValidation:o==="native"?d||D||x:d||D||V||a||x,updateValidation(s){o==="aria"&&!q(x,s)?v(s):w.current=s},resetValidation(){let s=O;q(s,b.current)||(b.current=s,v(s)),o==="native"&&S(!1),$(!0)},commitValidation(){o==="native"&&S(!0),$(!0)}}}function K(r){return r?Array.isArray(r)?r:[r]:[]}function ye(r,e){if(typeof r=="function"){let t=r(e);if(t&&typeof t!="boolean")return K(t)}return[]}function k(r){return r.length?{isInvalid:!0,validationErrors:r,validationDetails:te}:null}function q(r,e){return r===e?!0:!!r&&!!e&&r.isInvalid===e.isInvalid&&r.validationErrors.length===e.validationErrors.length&&r.validationErrors.every((t,i)=>t===e.validationErrors[i])&&Object.entries(r.validationDetails).every(([t,i])=>e.validationDetails[t]===i)}let z=new Map,G=!1;try{G=new Intl.NumberFormat("de-DE",{signDisplay:"exceptZero"}).resolvedOptions().signDisplay==="exceptZero"}catch{}let j=!1;try{j=new Intl.NumberFormat("de-DE",{style:"unit",unit:"degree"}).resolvedOptions().style==="unit"}catch{}const ie={degree:{narrow:{default:"°","ja-JP":" 度","zh-TW":"度","sl-SI":" °"}}};class U{format(e){let t="";if(!G&&this.options.signDisplay!=null?t=ve(this.numberFormatter,this.options.signDisplay,e):t=this.numberFormatter.format(e),this.options.style==="unit"&&!j){var i;let{unit:n,unitDisplay:a="short",locale:l}=this.resolvedOptions();if(!n)return t;let o=(i=ie[n])===null||i===void 0?void 0:i[a];t+=o[l]||o.default}return t}formatToParts(e){return this.numberFormatter.formatToParts(e)}formatRange(e,t){if(typeof this.numberFormatter.formatRange=="function")return this.numberFormatter.formatRange(e,t);if(t<e)throw new RangeError("End date must be >= start date");return`${this.format(e)} – ${this.format(t)}`}formatRangeToParts(e,t){if(typeof this.numberFormatter.formatRangeToParts=="function")return this.numberFormatter.formatRangeToParts(e,t);if(t<e)throw new RangeError("End date must be >= start date");let i=this.numberFormatter.formatToParts(e),n=this.numberFormatter.formatToParts(t);return[...i.map(a=>({...a,source:"startRange"})),{type:"literal",value:" – ",source:"shared"},...n.map(a=>({...a,source:"endRange"}))]}resolvedOptions(){let e=this.numberFormatter.resolvedOptions();return!G&&this.options.signDisplay!=null&&(e={...e,signDisplay:this.options.signDisplay}),!j&&this.options.style==="unit"&&(e={...e,style:"unit",unit:this.options.unit,unitDisplay:this.options.unitDisplay}),e}constructor(e,t={}){this.numberFormatter=$e(e,t),this.options=t}}function $e(r,e={}){let{numberingSystem:t}=e;if(t&&r.includes("-nu-")&&(r.includes("-u-")||(r+="-u-"),r+=`-nu-${t}`),e.style==="unit"&&!j){var i;let{unit:l,unitDisplay:o="short"}=e;if(!l)throw new Error('unit option must be provided with style: "unit"');if(!(!((i=ie[l])===null||i===void 0)&&i[o]))throw new Error(`Unsupported unit ${l} with unitDisplay = ${o}`);e={...e,style:"decimal"}}let n=r+(e?Object.entries(e).sort((l,o)=>l[0]<o[0]?-1:1).join():"");if(z.has(n))return z.get(n);let a=new Intl.NumberFormat(r,e);return z.set(n,a),a}function ve(r,e,t){if(e==="auto")return r.format(t);if(e==="never")return r.format(Math.abs(t));{let i=!1;if(e==="always"?i=t>0||Object.is(t,0):e==="exceptZero"&&(Object.is(t,-0)||Object.is(t,0)?t=Math.abs(t):i=t>0),i){let n=r.format(-t),a=r.format(t),l=n.replace(a,"").replace(/\u200e|\u061C/,"");return[...l].length!==1&&console.warn("@react-aria/i18n polyfill for NumberFormat signDisplay: Unsupported case"),n.replace(a,"!!!").replace(l,"+").replace("!!!",a)}else return r.format(t)}}const Ne=new RegExp("^.*\\(.*\\).*$"),Ve=["latn","arab","hanidec","deva","beng"];class re{parse(e){return W(this.locale,this.options,e).parse(e)}isValidPartialNumber(e,t,i){return W(this.locale,this.options,e).isValidPartialNumber(e,t,i)}getNumberingSystem(e){return W(this.locale,this.options,e).options.numberingSystem}constructor(e,t={}){this.locale=e,this.options=t}}const Q=new Map;function W(r,e,t){let i=J(r,e);if(!r.includes("-nu-")&&!i.isValidPartialNumber(t)){for(let n of Ve)if(n!==i.options.numberingSystem){let a=J(r+(r.includes("-u-")?"-nu-":"-u-nu-")+n,e);if(a.isValidPartialNumber(t))return a}}return i}function J(r,e){let t=r+(e?Object.entries(e).sort((n,a)=>n[0]<a[0]?-1:1).join():""),i=Q.get(t);return i||(i=new Se(r,e),Q.set(t,i)),i}class Se{parse(e){let t=this.sanitize(e);if(this.symbols.group&&(t=T(t,this.symbols.group,"")),this.symbols.decimal&&(t=t.replace(this.symbols.decimal,".")),this.symbols.minusSign&&(t=t.replace(this.symbols.minusSign,"-")),t=t.replace(this.symbols.numeral,this.symbols.index),this.options.style==="percent"){let l=t.indexOf("-");t=t.replace("-",""),t=t.replace("+","");let o=t.indexOf(".");o===-1&&(o=t.length),t=t.replace(".",""),o-2===0?t=`0.${t}`:o-2===-1?t=`0.0${t}`:o-2===-2?t="0.00":t=`${t.slice(0,o-2)}.${t.slice(o-2)}`,l>-1&&(t=`-${t}`)}let i=t?+t:NaN;if(isNaN(i))return NaN;if(this.options.style==="percent"){var n,a;let l={...this.options,style:"decimal",minimumFractionDigits:Math.min(((n=this.options.minimumFractionDigits)!==null&&n!==void 0?n:0)+2,20),maximumFractionDigits:Math.min(((a=this.options.maximumFractionDigits)!==null&&a!==void 0?a:0)+2,20)};return new re(this.locale,l).parse(new U(this.locale,l).format(i))}return this.options.currencySign==="accounting"&&Ne.test(e)&&(i=-1*i),i}sanitize(e){return e=e.replace(this.symbols.literals,""),this.symbols.minusSign&&(e=e.replace("-",this.symbols.minusSign)),this.options.numberingSystem==="arab"&&(this.symbols.decimal&&(e=e.replace(",",this.symbols.decimal),e=e.replace("،",this.symbols.decimal)),this.symbols.group&&(e=T(e,".",this.symbols.group))),this.options.locale==="fr-FR"&&this.symbols.group&&(e=T(e," ",this.symbols.group),e=T(e,/\u00A0/g,this.symbols.group)),e}isValidPartialNumber(e,t=-1/0,i=1/0){return e=this.sanitize(e),this.symbols.minusSign&&e.startsWith(this.symbols.minusSign)&&t<0?e=e.slice(this.symbols.minusSign.length):this.symbols.plusSign&&e.startsWith(this.symbols.plusSign)&&i>0&&(e=e.slice(this.symbols.plusSign.length)),this.symbols.group&&e.startsWith(this.symbols.group)||this.symbols.decimal&&e.indexOf(this.symbols.decimal)>-1&&this.options.maximumFractionDigits===0?!1:(this.symbols.group&&(e=T(e,this.symbols.group,"")),e=e.replace(this.symbols.numeral,""),this.symbols.decimal&&(e=e.replace(this.symbols.decimal,"")),e.length===0)}constructor(e,t={}){this.locale=e,t.roundingIncrement!==1&&t.roundingIncrement!=null&&(t.maximumFractionDigits==null&&t.minimumFractionDigits==null?(t.maximumFractionDigits=0,t.minimumFractionDigits=0):t.maximumFractionDigits==null?t.maximumFractionDigits=t.minimumFractionDigits:t.minimumFractionDigits==null&&(t.minimumFractionDigits=t.maximumFractionDigits)),this.formatter=new Intl.NumberFormat(e,t),this.options=this.formatter.resolvedOptions(),this.symbols=we(e,this.formatter,this.options,t);var i,n;this.options.style==="percent"&&(((i=this.options.minimumFractionDigits)!==null&&i!==void 0?i:0)>18||((n=this.options.maximumFractionDigits)!==null&&n!==void 0?n:0)>18)&&console.warn("NumberParser cannot handle percentages with greater than 18 decimal places, please reduce the number in your options.")}}const X=new Set(["decimal","fraction","integer","minusSign","plusSign","group"]),De=[0,4,2,1,11,20,3,7,100,21,.1,1.1];function we(r,e,t,i){var n,a,l,o;let d=new Intl.NumberFormat(r,{...t,minimumSignificantDigits:1,maximumSignificantDigits:21,roundingIncrement:1,roundingPriority:"auto",roundingMode:"halfExpand"}),V=d.formatToParts(-10000.111),h=d.formatToParts(10000.111),f=De.map(s=>d.formatToParts(s));var g;let y=(g=(n=V.find(s=>s.type==="minusSign"))===null||n===void 0?void 0:n.value)!==null&&g!==void 0?g:"-",p=(a=h.find(s=>s.type==="plusSign"))===null||a===void 0?void 0:a.value;!p&&((i==null?void 0:i.signDisplay)==="exceptZero"||(i==null?void 0:i.signDisplay)==="always")&&(p="+");let D=(l=new Intl.NumberFormat(r,{...t,minimumFractionDigits:2,maximumFractionDigits:2}).formatToParts(.001).find(s=>s.type==="decimal"))===null||l===void 0?void 0:l.value,w=(o=V.find(s=>s.type==="group"))===null||o===void 0?void 0:o.value,x=V.filter(s=>!X.has(s.type)).map(s=>H(s.value)),v=f.flatMap(s=>s.filter(E=>!X.has(E.type)).map(E=>H(E.value))),b=[...new Set([...x,...v])].sort((s,E)=>E.length-s.length),c=b.length===0?new RegExp("[\\p{White_Space}]","gu"):new RegExp(`${b.join("|")}|[\\p{White_Space}]`,"gu"),P=[...new Intl.NumberFormat(t.locale,{useGrouping:!1}).format(9876543210)].reverse(),S=new Map(P.map((s,E)=>[s,E])),F=new RegExp(`[${P.join("")}]`,"g");return{minusSign:y,plusSign:p,decimal:D,group:w,literals:c,numeral:F,index:s=>String(S.get(s))}}function T(r,e,t){return r.replaceAll?r.replaceAll(e,t):r.split(e).join(t)}function H(r){return r.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function xe(r){let{minValue:e,maxValue:t,step:i,formatOptions:n,value:a,defaultValue:l=NaN,onChange:o,locale:d,isDisabled:V,isReadOnly:h}=r;a===null&&(a=NaN),a!==void 0&&!isNaN(a)&&(i!==void 0&&!isNaN(i)?a=M(a,e,t,i):a=L(a,e,t)),isNaN(l)||(i!==void 0&&!isNaN(i)?l=M(l,e,t,i):l=L(l,e,t));let[f,g]=pe.$458b0a5536c1a7cf$export$40bfa8c7b0832715(a,isNaN(l)?NaN:l,o),[y,p]=u.useState(()=>isNaN(f)?"":new U(d,n).format(f)),$=u.useMemo(()=>new re(d,n),[d,n]),D=u.useMemo(()=>$.getNumberingSystem(y),[$,y]),w=u.useMemo(()=>new U(d,{...n,numberingSystem:D}),[d,n,D]),x=u.useMemo(()=>w.resolvedOptions(),[w]),v=u.useCallback(m=>isNaN(m)||m===null?"":w.format(m),[w]),b=he({...r,value:f}),c=i!==void 0&&!isNaN(i)?i:1;x.style==="percent"&&(i===void 0||isNaN(i))&&(c=.01);let[P,S]=u.useState(f),[F,I]=u.useState(d),[s,E]=u.useState(n);(!Object.is(f,P)||d!==F||n!==s)&&(p(v(f)),S(f),I(d),E(n));let N=u.useMemo(()=>$.parse(y),[$,y]),ae=()=>{if(!y.length){g(NaN),p(a===void 0?"":v(f));return}if(isNaN(N)){p(v(f));return}let m;i===void 0||isNaN(i)?m=L(N,e,t):m=M(N,e,t,i),m=$.parse(v(m)),g(m),p(v(a===void 0?m:f))},Z=(m,B=0)=>{let R=N;if(isNaN(R)){let C=isNaN(B)?0:B;return M(C,e,t,c)}else{let C=M(R,e,t,c);return m==="+"&&C>R||m==="-"&&C<R?C:M(_(m,R,c),e,t,c)}},ne=()=>{let m=Z("+",e);m===f&&p(v(m)),g(m),b.commitValidation()},se=()=>{let m=Z("-",t);m===f&&p(v(m)),g(m),b.commitValidation()},le=()=>{t!=null&&(g(M(t,e,t,c)),b.commitValidation())},oe=()=>{e!=null&&(g(e),b.commitValidation())},ue=u.useMemo(()=>!V&&!h&&(isNaN(N)||t===void 0||isNaN(t)||M(N,e,t,c)>N||_("+",N,c)<=t),[V,h,e,t,c,N]),me=u.useMemo(()=>!V&&!h&&(isNaN(N)||e===void 0||isNaN(e)||M(N,e,t,c)<N||_("-",N,c)>=e),[V,h,e,t,c,N]);return{...b,validate:m=>$.isValidPartialNumber(m,e,t),increment:ne,incrementToMax:le,decrement:se,decrementToMin:oe,canIncrement:ue,canDecrement:me,minValue:e,maxValue:t,numberValue:N,setNumberValue:g,setInputValue:p,inputValue:y,commit:ae}}function _(r,e,t){let i=r==="+"?e+t:e-t;if(e%1!==0||t%1!==0){const n=e.toString().split("."),a=t.toString().split("."),l=n[1]&&n[1].length||0,o=a[1]&&a[1].length||0,d=Math.pow(10,Math.max(l,o));e=Math.round(e*d),t=Math.round(t*d),i=r==="+"?e+t:e-t,i/=d}return i}const Pe=u.forwardRef(({placeholder:r,variant:e,disabled:t,type:i,readOnly:n,leftAdornments:a,rightAdornments:l,leftAdornmentsProps:o,rightAdornmentsProps:d,leftAdornmentsWidth:V,rightAdornmentsWidth:h,className:f,style:g,label:y,value:p,locale:$,...D},w)=>{$=$??"nb-NO";const x=xe({...D,label:y??"number-field",value:p,onChange:c=>{D.onChange&&D.onChange(c)},locale:$}),v=u.useRef(null),{inputProps:b}=de.useNumberField({...D,isReadOnly:n,isDisabled:t,label:y??"number-field",value:p},x,v);return ce.jsx(fe.Input,{placeholder:r,variant:e,type:i,leftAdornments:a,rightAdornments:l,leftAdornmentsProps:o,rightAdornmentsProps:d,leftAdornmentsWidth:V,rightAdornmentsWidth:h,className:f,style:g,"data-testid":`number-field-${y}`,...b,onKeyDown:c=>{var P;if(c.key==="."){c.preventDefault();const S=c.target;if((P=S.value)!=null&&P.includes(","))return;const F=S.selectionStart||0,I=S.selectionEnd||0;S.value=S.value.substring(0,F)+","+S.value.substring(I)}else b.onKeyDown&&b.onKeyDown(c)},ref:w,"aria-label":y})});exports.NumberField=Pe;
|
package/number.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { jsx as fe } from "react/jsx-runtime";
|
|
2
|
-
import { useMemo as w, useContext as pe, createContext as be, useState as M, useRef as
|
|
2
|
+
import { useMemo as w, useContext as pe, createContext as be, useState as M, useRef as U, useEffect as he, useCallback as ge, forwardRef as $e } from "react";
|
|
3
3
|
import { useNumberField as ye } from "react-aria";
|
|
4
4
|
import { Input as ve } from "@equinor/eds-core-react";
|
|
5
5
|
import { $ as Ne } from "./useControlledState-u436Wbp1.mjs";
|
|
@@ -56,7 +56,7 @@ function Se(r) {
|
|
|
56
56
|
function De(r) {
|
|
57
57
|
let { isInvalid: e, validationState: t, name: i, value: n, builtinValidation: a, validate: l, validationBehavior: o = "aria" } = r;
|
|
58
58
|
t && (e || (e = t === "invalid"));
|
|
59
|
-
let
|
|
59
|
+
let c = e !== void 0 ? {
|
|
60
60
|
isInvalid: e,
|
|
61
61
|
validationErrors: [],
|
|
62
62
|
validationDetails: re
|
|
@@ -69,36 +69,36 @@ function De(r) {
|
|
|
69
69
|
n
|
|
70
70
|
]);
|
|
71
71
|
a != null && a.validationDetails.valid && (a = void 0);
|
|
72
|
-
let b = pe(Ve), d = w(() => i ? Array.isArray(i) ? i.flatMap((s) =>
|
|
72
|
+
let b = pe(Ve), d = w(() => i ? Array.isArray(i) ? i.flatMap((s) => Z(b[s])) : Z(b[i]) : [], [
|
|
73
73
|
b,
|
|
74
74
|
i
|
|
75
|
-
]), [h, g] = M(b), [f,
|
|
76
|
-
b !== h && (g(b),
|
|
75
|
+
]), [h, g] = M(b), [f, $] = M(!1);
|
|
76
|
+
b !== h && (g(b), $(!1));
|
|
77
77
|
let S = w(() => J(f ? [] : d), [
|
|
78
78
|
f,
|
|
79
79
|
d
|
|
80
|
-
]), D =
|
|
80
|
+
]), D = U(T), [x, y] = M(T), p = U(T), m = () => {
|
|
81
81
|
if (!P) return;
|
|
82
82
|
V(!1);
|
|
83
83
|
let s = N || a || D.current;
|
|
84
|
-
_(s,
|
|
84
|
+
_(s, p.current) || (p.current = s, y(s));
|
|
85
85
|
}, [P, V] = M(!1);
|
|
86
|
-
return he(
|
|
87
|
-
realtimeValidation:
|
|
88
|
-
displayValidation: o === "native" ?
|
|
86
|
+
return he(m), {
|
|
87
|
+
realtimeValidation: c || S || N || a || T,
|
|
88
|
+
displayValidation: o === "native" ? c || S || x : c || S || N || a || x,
|
|
89
89
|
updateValidation(s) {
|
|
90
|
-
o === "aria" && !_(x, s) ?
|
|
90
|
+
o === "aria" && !_(x, s) ? y(s) : D.current = s;
|
|
91
91
|
},
|
|
92
92
|
resetValidation() {
|
|
93
93
|
let s = T;
|
|
94
|
-
_(s,
|
|
94
|
+
_(s, p.current) || (p.current = s, y(s)), o === "native" && V(!1), $(!0);
|
|
95
95
|
},
|
|
96
96
|
commitValidation() {
|
|
97
|
-
o === "native" && V(!0),
|
|
97
|
+
o === "native" && V(!0), $(!0);
|
|
98
98
|
}
|
|
99
99
|
};
|
|
100
100
|
}
|
|
101
|
-
function
|
|
101
|
+
function Z(r) {
|
|
102
102
|
return r ? Array.isArray(r) ? r : [
|
|
103
103
|
r
|
|
104
104
|
] : [];
|
|
@@ -106,7 +106,7 @@ function B(r) {
|
|
|
106
106
|
function we(r, e) {
|
|
107
107
|
if (typeof r == "function") {
|
|
108
108
|
let t = r(e);
|
|
109
|
-
if (t && typeof t != "boolean") return
|
|
109
|
+
if (t && typeof t != "boolean") return Z(t);
|
|
110
110
|
}
|
|
111
111
|
return [];
|
|
112
112
|
}
|
|
@@ -120,9 +120,9 @@ function J(r) {
|
|
|
120
120
|
function _(r, e) {
|
|
121
121
|
return r === e ? !0 : !!r && !!e && r.isInvalid === e.isInvalid && r.validationErrors.length === e.validationErrors.length && r.validationErrors.every((t, i) => t === e.validationErrors[i]) && Object.entries(r.validationDetails).every(([t, i]) => e.validationDetails[t] === i);
|
|
122
122
|
}
|
|
123
|
-
let z = /* @__PURE__ */ new Map(),
|
|
123
|
+
let z = /* @__PURE__ */ new Map(), B = !1;
|
|
124
124
|
try {
|
|
125
|
-
|
|
125
|
+
B = new Intl.NumberFormat("de-DE", {
|
|
126
126
|
signDisplay: "exceptZero"
|
|
127
127
|
}).resolvedOptions().signDisplay === "exceptZero";
|
|
128
128
|
} catch {
|
|
@@ -149,7 +149,7 @@ class Y {
|
|
|
149
149
|
/** Formats a number value as a string, according to the locale and options provided to the constructor. */
|
|
150
150
|
format(e) {
|
|
151
151
|
let t = "";
|
|
152
|
-
if (!
|
|
152
|
+
if (!B && this.options.signDisplay != null ? t = Pe(this.numberFormatter, this.options.signDisplay, e) : t = this.numberFormatter.format(e), this.options.style === "unit" && !L) {
|
|
153
153
|
var i;
|
|
154
154
|
let { unit: n, unitDisplay: a = "short", locale: l } = this.resolvedOptions();
|
|
155
155
|
if (!n) return t;
|
|
@@ -192,7 +192,7 @@ class Y {
|
|
|
192
192
|
/** Returns the resolved formatting options based on the values passed to the constructor. */
|
|
193
193
|
resolvedOptions() {
|
|
194
194
|
let e = this.numberFormatter.resolvedOptions();
|
|
195
|
-
return !
|
|
195
|
+
return !B && this.options.signDisplay != null && (e = {
|
|
196
196
|
...e,
|
|
197
197
|
signDisplay: this.options.signDisplay
|
|
198
198
|
}), !L && this.options.style === "unit" && (e = {
|
|
@@ -248,7 +248,7 @@ class ne {
|
|
|
248
248
|
* Parses the given string to a number. Returns NaN if a valid number could not be parsed.
|
|
249
249
|
*/
|
|
250
250
|
parse(e) {
|
|
251
|
-
return
|
|
251
|
+
return K(this.locale, this.options, e).parse(e);
|
|
252
252
|
}
|
|
253
253
|
/**
|
|
254
254
|
* Returns whether the given string could potentially be a valid number. This should be used to
|
|
@@ -256,7 +256,7 @@ class ne {
|
|
|
256
256
|
* of the minus/plus sign characters can be checked.
|
|
257
257
|
*/
|
|
258
258
|
isValidPartialNumber(e, t, i) {
|
|
259
|
-
return
|
|
259
|
+
return K(this.locale, this.options, e).isValidPartialNumber(e, t, i);
|
|
260
260
|
}
|
|
261
261
|
/**
|
|
262
262
|
* Returns a numbering system for which the given string is valid in the current locale.
|
|
@@ -264,14 +264,14 @@ class ne {
|
|
|
264
264
|
* locale is returned.
|
|
265
265
|
*/
|
|
266
266
|
getNumberingSystem(e) {
|
|
267
|
-
return
|
|
267
|
+
return K(this.locale, this.options, e).options.numberingSystem;
|
|
268
268
|
}
|
|
269
269
|
constructor(e, t = {}) {
|
|
270
270
|
this.locale = e, this.options = t;
|
|
271
271
|
}
|
|
272
272
|
}
|
|
273
273
|
const X = /* @__PURE__ */ new Map();
|
|
274
|
-
function
|
|
274
|
+
function K(r, e, t) {
|
|
275
275
|
let i = H(r, e);
|
|
276
276
|
if (!r.includes("-nu-") && !i.isValidPartialNumber(t)) {
|
|
277
277
|
for (let n of Fe) if (n !== i.options.numberingSystem) {
|
|
@@ -343,7 +343,7 @@ const ee = /* @__PURE__ */ new Set([
|
|
|
343
343
|
];
|
|
344
344
|
function Re(r, e, t, i) {
|
|
345
345
|
var n, a, l, o;
|
|
346
|
-
let
|
|
346
|
+
let c = new Intl.NumberFormat(r, {
|
|
347
347
|
...t,
|
|
348
348
|
// Resets so we get the full range of symbols
|
|
349
349
|
minimumSignificantDigits: 1,
|
|
@@ -351,7 +351,7 @@ function Re(r, e, t, i) {
|
|
|
351
351
|
roundingIncrement: 1,
|
|
352
352
|
roundingPriority: "auto",
|
|
353
353
|
roundingMode: "halfExpand"
|
|
354
|
-
}), N =
|
|
354
|
+
}), N = c.formatToParts(-10000.111), b = c.formatToParts(10000.111), d = Ie.map((s) => c.formatToParts(s));
|
|
355
355
|
var h;
|
|
356
356
|
let g = (h = (n = N.find((s) => s.type === "minusSign")) === null || n === void 0 ? void 0 : n.value) !== null && h !== void 0 ? h : "-", f = (a = b.find((s) => s.type === "plusSign")) === null || a === void 0 ? void 0 : a.value;
|
|
357
357
|
!f && ((i == null ? void 0 : i.signDisplay) === "exceptZero" || (i == null ? void 0 : i.signDisplay) === "always") && (f = "+");
|
|
@@ -359,12 +359,12 @@ function Re(r, e, t, i) {
|
|
|
359
359
|
...t,
|
|
360
360
|
minimumFractionDigits: 2,
|
|
361
361
|
maximumFractionDigits: 2
|
|
362
|
-
}).formatToParts(1e-3).find((s) => s.type === "decimal")) === null || l === void 0 ? void 0 : l.value, D = (o = N.find((s) => s.type === "group")) === null || o === void 0 ? void 0 : o.value, x = N.filter((s) => !ee.has(s.type)).map((s) => te(s.value)),
|
|
362
|
+
}).formatToParts(1e-3).find((s) => s.type === "decimal")) === null || l === void 0 ? void 0 : l.value, D = (o = N.find((s) => s.type === "group")) === null || o === void 0 ? void 0 : o.value, x = N.filter((s) => !ee.has(s.type)).map((s) => te(s.value)), y = d.flatMap((s) => s.filter((E) => !ee.has(E.type)).map((E) => te(E.value))), p = [
|
|
363
363
|
.../* @__PURE__ */ new Set([
|
|
364
364
|
...x,
|
|
365
|
-
|
|
365
|
+
...y
|
|
366
366
|
])
|
|
367
|
-
].sort((s, E) => E.length - s.length),
|
|
367
|
+
].sort((s, E) => E.length - s.length), m = p.length === 0 ? new RegExp("[\\p{White_Space}]", "gu") : new RegExp(`${p.join("|")}|[\\p{White_Space}]`, "gu"), P = [
|
|
368
368
|
...new Intl.NumberFormat(t.locale, {
|
|
369
369
|
useGrouping: !1
|
|
370
370
|
}).format(9876543210)
|
|
@@ -377,7 +377,7 @@ function Re(r, e, t, i) {
|
|
|
377
377
|
plusSign: f,
|
|
378
378
|
decimal: S,
|
|
379
379
|
group: D,
|
|
380
|
-
literals:
|
|
380
|
+
literals: m,
|
|
381
381
|
numeral: I,
|
|
382
382
|
index: (s) => String(V.get(s))
|
|
383
383
|
};
|
|
@@ -388,84 +388,84 @@ function A(r, e, t) {
|
|
|
388
388
|
function te(r) {
|
|
389
389
|
return r.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
390
390
|
}
|
|
391
|
-
function
|
|
392
|
-
let { minValue: e, maxValue: t, step: i, formatOptions: n, value: a, defaultValue: l = NaN, onChange: o, locale:
|
|
391
|
+
function Oe(r) {
|
|
392
|
+
let { minValue: e, maxValue: t, step: i, formatOptions: n, value: a, defaultValue: l = NaN, onChange: o, locale: c, isDisabled: N, isReadOnly: b } = r;
|
|
393
393
|
a === null && (a = NaN), a !== void 0 && !isNaN(a) && (i !== void 0 && !isNaN(i) ? a = F(a, e, t, i) : a = W(a, e, t)), isNaN(l) || (i !== void 0 && !isNaN(i) ? l = F(l, e, t, i) : l = W(l, e, t));
|
|
394
|
-
let [d, h] = Ne(a, isNaN(l) ? NaN : l, o), [g, f] = M(() => isNaN(d) ? "" : new Y(
|
|
395
|
-
|
|
394
|
+
let [d, h] = Ne(a, isNaN(l) ? NaN : l, o), [g, f] = M(() => isNaN(d) ? "" : new Y(c, n).format(d)), $ = w(() => new ne(c, n), [
|
|
395
|
+
c,
|
|
396
396
|
n
|
|
397
|
-
]), S = w(() =>
|
|
398
|
-
|
|
397
|
+
]), S = w(() => $.getNumberingSystem(g), [
|
|
398
|
+
$,
|
|
399
399
|
g
|
|
400
|
-
]), D = w(() => new Y(
|
|
400
|
+
]), D = w(() => new Y(c, {
|
|
401
401
|
...n,
|
|
402
402
|
numberingSystem: S
|
|
403
403
|
}), [
|
|
404
|
-
|
|
404
|
+
c,
|
|
405
405
|
n,
|
|
406
406
|
S
|
|
407
407
|
]), x = w(() => D.resolvedOptions(), [
|
|
408
408
|
D
|
|
409
|
-
]),
|
|
409
|
+
]), y = ge((u) => isNaN(u) || u === null ? "" : D.format(u), [
|
|
410
410
|
D
|
|
411
|
-
]),
|
|
411
|
+
]), p = Se({
|
|
412
412
|
...r,
|
|
413
413
|
value: d
|
|
414
|
-
}),
|
|
415
|
-
x.style === "percent" && (i === void 0 || isNaN(i)) && (
|
|
416
|
-
let [P, V] = M(d), [I, R] = M(
|
|
417
|
-
(!Object.is(d, P) ||
|
|
418
|
-
let v = w(() =>
|
|
419
|
-
|
|
414
|
+
}), m = i !== void 0 && !isNaN(i) ? i : 1;
|
|
415
|
+
x.style === "percent" && (i === void 0 || isNaN(i)) && (m = 0.01);
|
|
416
|
+
let [P, V] = M(d), [I, R] = M(c), [s, E] = M(n);
|
|
417
|
+
(!Object.is(d, P) || c !== I || n !== s) && (f(y(d)), V(d), R(c), E(n));
|
|
418
|
+
let v = w(() => $.parse(g), [
|
|
419
|
+
$,
|
|
420
420
|
g
|
|
421
421
|
]), se = () => {
|
|
422
422
|
if (!g.length) {
|
|
423
|
-
h(NaN), f(a === void 0 ? "" :
|
|
423
|
+
h(NaN), f(a === void 0 ? "" : y(d));
|
|
424
424
|
return;
|
|
425
425
|
}
|
|
426
426
|
if (isNaN(v)) {
|
|
427
|
-
f(
|
|
427
|
+
f(y(d));
|
|
428
428
|
return;
|
|
429
429
|
}
|
|
430
430
|
let u;
|
|
431
|
-
i === void 0 || isNaN(i) ? u = W(v, e, t) : u = F(v, e, t, i), u =
|
|
431
|
+
i === void 0 || isNaN(i) ? u = W(v, e, t) : u = F(v, e, t, i), u = $.parse(y(u)), h(u), f(y(a === void 0 ? u : d));
|
|
432
432
|
}, k = (u, Q = 0) => {
|
|
433
|
-
let
|
|
434
|
-
if (isNaN(
|
|
435
|
-
let
|
|
436
|
-
return F(
|
|
433
|
+
let O = v;
|
|
434
|
+
if (isNaN(O)) {
|
|
435
|
+
let C = isNaN(Q) ? 0 : Q;
|
|
436
|
+
return F(C, e, t, m);
|
|
437
437
|
} else {
|
|
438
|
-
let
|
|
439
|
-
return u === "+" &&
|
|
438
|
+
let C = F(O, e, t, m);
|
|
439
|
+
return u === "+" && C > O || u === "-" && C < O ? C : F(G(u, O, m), e, t, m);
|
|
440
440
|
}
|
|
441
441
|
}, le = () => {
|
|
442
442
|
let u = k("+", e);
|
|
443
|
-
u === d && f(
|
|
443
|
+
u === d && f(y(u)), h(u), p.commitValidation();
|
|
444
444
|
}, oe = () => {
|
|
445
445
|
let u = k("-", t);
|
|
446
|
-
u === d && f(
|
|
446
|
+
u === d && f(y(u)), h(u), p.commitValidation();
|
|
447
447
|
}, ue = () => {
|
|
448
|
-
t != null && (h(F(t, e, t,
|
|
448
|
+
t != null && (h(F(t, e, t, m)), p.commitValidation());
|
|
449
449
|
}, me = () => {
|
|
450
|
-
e != null && (h(e),
|
|
451
|
-
}, ce = w(() => !N && !b && (isNaN(v) || t === void 0 || isNaN(t) || F(v, e, t,
|
|
450
|
+
e != null && (h(e), p.commitValidation());
|
|
451
|
+
}, ce = w(() => !N && !b && (isNaN(v) || t === void 0 || isNaN(t) || F(v, e, t, m) > v || G("+", v, m) <= t), [
|
|
452
452
|
N,
|
|
453
453
|
b,
|
|
454
454
|
e,
|
|
455
455
|
t,
|
|
456
|
-
|
|
456
|
+
m,
|
|
457
457
|
v
|
|
458
|
-
]), de = w(() => !N && !b && (isNaN(v) || e === void 0 || isNaN(e) || F(v, e, t,
|
|
458
|
+
]), de = w(() => !N && !b && (isNaN(v) || e === void 0 || isNaN(e) || F(v, e, t, m) < v || G("-", v, m) >= e), [
|
|
459
459
|
N,
|
|
460
460
|
b,
|
|
461
461
|
e,
|
|
462
462
|
t,
|
|
463
|
-
|
|
463
|
+
m,
|
|
464
464
|
v
|
|
465
465
|
]);
|
|
466
466
|
return {
|
|
467
|
-
...
|
|
468
|
-
validate: (u) =>
|
|
467
|
+
...p,
|
|
468
|
+
validate: (u) => $.isValidPartialNumber(u, e, t),
|
|
469
469
|
increment: le,
|
|
470
470
|
incrementToMax: ue,
|
|
471
471
|
decrement: oe,
|
|
@@ -481,11 +481,11 @@ function Ce(r) {
|
|
|
481
481
|
commit: se
|
|
482
482
|
};
|
|
483
483
|
}
|
|
484
|
-
function
|
|
484
|
+
function G(r, e, t) {
|
|
485
485
|
let i = r === "+" ? e + t : e - t;
|
|
486
486
|
if (e % 1 !== 0 || t % 1 !== 0) {
|
|
487
|
-
const n = e.toString().split("."), a = t.toString().split("."), l = n[1] && n[1].length || 0, o = a[1] && a[1].length || 0,
|
|
488
|
-
e = Math.round(e *
|
|
487
|
+
const n = e.toString().split("."), a = t.toString().split("."), l = n[1] && n[1].length || 0, o = a[1] && a[1].length || 0, c = Math.pow(10, Math.max(l, o));
|
|
488
|
+
e = Math.round(e * c), t = Math.round(t * c), i = r === "+" ? e + t : e - t, i /= c;
|
|
489
489
|
}
|
|
490
490
|
return i;
|
|
491
491
|
}
|
|
@@ -499,61 +499,63 @@ const _e = $e(
|
|
|
499
499
|
leftAdornments: a,
|
|
500
500
|
rightAdornments: l,
|
|
501
501
|
leftAdornmentsProps: o,
|
|
502
|
-
rightAdornmentsProps:
|
|
502
|
+
rightAdornmentsProps: c,
|
|
503
503
|
leftAdornmentsWidth: N,
|
|
504
504
|
rightAdornmentsWidth: b,
|
|
505
505
|
className: d,
|
|
506
506
|
style: h,
|
|
507
507
|
label: g,
|
|
508
508
|
value: f,
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
509
|
+
locale: $,
|
|
510
|
+
...S
|
|
511
|
+
}, D) => {
|
|
512
|
+
$ = $ ?? "nb-NO";
|
|
513
|
+
const x = Oe({
|
|
514
|
+
...S,
|
|
515
|
+
label: g ?? "number-field",
|
|
514
516
|
value: f,
|
|
515
|
-
onChange: (
|
|
516
|
-
|
|
517
|
+
onChange: (m) => {
|
|
518
|
+
S.onChange && S.onChange(m);
|
|
517
519
|
},
|
|
518
|
-
locale:
|
|
519
|
-
}),
|
|
520
|
+
locale: $
|
|
521
|
+
}), y = U(null), { inputProps: p } = ye(
|
|
520
522
|
{
|
|
521
|
-
...
|
|
522
|
-
|
|
523
|
+
...S,
|
|
524
|
+
isReadOnly: n,
|
|
525
|
+
isDisabled: t,
|
|
526
|
+
label: g ?? "number-field",
|
|
523
527
|
value: f
|
|
524
528
|
},
|
|
525
529
|
x,
|
|
526
|
-
|
|
530
|
+
y
|
|
527
531
|
);
|
|
528
532
|
return /* @__PURE__ */ fe(
|
|
529
533
|
ve,
|
|
530
534
|
{
|
|
531
535
|
placeholder: r,
|
|
532
536
|
variant: e,
|
|
533
|
-
disabled: t,
|
|
534
537
|
type: i,
|
|
535
|
-
readOnly: n,
|
|
536
538
|
leftAdornments: a,
|
|
537
539
|
rightAdornments: l,
|
|
538
540
|
leftAdornmentsProps: o,
|
|
539
|
-
rightAdornmentsProps:
|
|
541
|
+
rightAdornmentsProps: c,
|
|
540
542
|
leftAdornmentsWidth: N,
|
|
541
543
|
rightAdornmentsWidth: b,
|
|
542
544
|
className: d,
|
|
543
545
|
style: h,
|
|
544
546
|
"data-testid": `number-field-${g}`,
|
|
545
|
-
...
|
|
546
|
-
onKeyDown: (
|
|
547
|
+
...p,
|
|
548
|
+
onKeyDown: (m) => {
|
|
547
549
|
var P;
|
|
548
|
-
if (
|
|
549
|
-
|
|
550
|
-
const V =
|
|
550
|
+
if (m.key === ".") {
|
|
551
|
+
m.preventDefault();
|
|
552
|
+
const V = m.target;
|
|
551
553
|
if ((P = V.value) != null && P.includes(",")) return;
|
|
552
554
|
const I = V.selectionStart || 0, R = V.selectionEnd || 0;
|
|
553
555
|
V.value = V.value.substring(0, I) + "," + V.value.substring(R);
|
|
554
|
-
}
|
|
556
|
+
} else p.onKeyDown && p.onKeyDown(m);
|
|
555
557
|
},
|
|
556
|
-
ref:
|
|
558
|
+
ref: D,
|
|
557
559
|
"aria-label": g
|
|
558
560
|
}
|
|
559
561
|
);
|