@equinor/roma-ui 0.2.2 → 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.
Files changed (3) hide show
  1. package/number.js +1 -1
  2. package/number.mjs +98 -98
  3. package/package.json +1 -1
package/number.js CHANGED
@@ -1 +1 @@
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 c=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 b=u.useContext(be),f=u.useMemo(()=>i?Array.isArray(i)?i.flatMap(s=>G(b[s])):G(b[i]):[],[b,i]),[h,g]=u.useState(b),[p,$]=u.useState(!1);b!==h&&(g(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:c||D||V||a||O,displayValidation:o==="native"?c||D||x:c||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),$(!0)},commitValidation(){o==="native"&&S(!0),$(!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 c=new Intl.NumberFormat(r,{...t,minimumSignificantDigits:1,maximumSignificantDigits:21,roundingIncrement:1,roundingPriority:"auto",roundingMode:"halfExpand"}),V=c.formatToParts(-10000.111),b=c.formatToParts(10000.111),f=De.map(s=>c.formatToParts(s));var h;let g=(h=(n=V.find(s=>s.type==="minusSign"))===null||n===void 0?void 0:n.value)!==null&&h!==void 0?h:"-",p=(a=b.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:g,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:c,isDisabled:V,isReadOnly:b}=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,h]=pe.$458b0a5536c1a7cf$export$40bfa8c7b0832715(a,isNaN(l)?NaN:l,o),[g,p]=u.useState(()=>isNaN(f)?"":new Z(c,n).format(f)),$=u.useMemo(()=>new re(c,n),[c,n]),D=u.useMemo(()=>$.getNumberingSystem(g),[$,g]),w=u.useMemo(()=>new Z(c,{...n,numberingSystem:D}),[c,n,D]),x=u.useMemo(()=>w.resolvedOptions(),[w]),y=u.useCallback(m=>isNaN(m)||m===null?"":w.format(m),[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(c),[s,E]=u.useState(n);(!Object.is(f,P)||c!==F||n!==s)&&(p(y(f)),S(f),I(c),E(n));let N=u.useMemo(()=>$.parse(g),[$,g]),ae=()=>{if(!g.length){h(NaN),p(a===void 0?"":y(f));return}if(isNaN(N)){p(y(f));return}let m;i===void 0||isNaN(i)?m=L(N,e,t):m=M(N,e,t,i),m=$.parse(y(m)),h(m),p(y(a===void 0?m:f))},B=(m,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 m==="+"&&C>R||m==="-"&&C<R?C:M(_(m,R,d),e,t,d)}},ne=()=>{let m=B("+",e);m===f&&p(y(m)),h(m),v.commitValidation()},se=()=>{let m=B("-",t);m===f&&p(y(m)),h(m),v.commitValidation()},le=()=>{t!=null&&(h(M(t,e,t,d)),v.commitValidation())},oe=()=>{e!=null&&(h(e),v.commitValidation())},ue=u.useMemo(()=>!V&&!b&&(isNaN(N)||t===void 0||isNaN(t)||M(N,e,t,d)>N||_("+",N,d)<=t),[V,b,e,t,d,N]),me=u.useMemo(()=>!V&&!b&&(isNaN(N)||e===void 0||isNaN(e)||M(N,e,t,d)<N||_("-",N,d)>=e),[V,b,e,t,d,N]);return{...v,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:h,setInputValue:p,inputValue:g,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,c=Math.pow(10,Math.max(l,o));e=Math.round(e*c),t=Math.round(t*c),i=r==="+"?e+t:e-t,i/=c}return i}const Pe=u.forwardRef(({placeholder:r,variant:e,disabled:t,type:i,readOnly:n,leftAdornments:a,rightAdornments:l,leftAdornmentsProps:o,rightAdornmentsProps:c,leftAdornmentsWidth:V,rightAdornmentsWidth:b,className:f,style:h,label:g,value:p,locale:$,...D},w)=>{$=$??"nb-NO";const x=xe({...D,label:g??"number-field",value:p,onChange:d=>{D.onChange&&D.onChange(d)},locale:$}),y=u.useRef(null),{inputProps:v}=de.useNumberField({...D,isReadOnly:n,isDisabled:t,label:g??"number-field",value:p},x,y);return ce.jsx(fe.Input,{placeholder:r,variant:e,type:i,leftAdornments:a,rightAdornments:l,leftAdornmentsProps:o,rightAdornmentsProps:c,leftAdornmentsWidth:V,rightAdornmentsWidth:b,className:f,style:h,"data-testid":`number-field-${g}`,...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:w,"aria-label":g})});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 Z, useEffect as he, useCallback as ge, forwardRef as $e } from "react";
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 m = e !== void 0 ? {
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 p = pe(Ve), d = w(() => i ? Array.isArray(i) ? i.flatMap((s) => B(p[s])) : B(p[i]) : [], [
73
- p,
72
+ let b = pe(Ve), d = w(() => i ? Array.isArray(i) ? i.flatMap((s) => Z(b[s])) : Z(b[i]) : [], [
73
+ b,
74
74
  i
75
- ]), [b, h] = M(p), [f, g] = M(!1);
76
- p !== b && (h(p), g(!1));
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 = Z(T), [x, $] = M(T), y = Z(T), c = () => {
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, y.current) || (y.current = s, $(s));
84
+ _(s, p.current) || (p.current = s, y(s));
85
85
  }, [P, V] = M(!1);
86
- return he(c), {
87
- realtimeValidation: m || S || N || a || T,
88
- displayValidation: o === "native" ? m || S || x : m || S || N || a || x,
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) ? $(s) : D.current = s;
90
+ o === "aria" && !_(x, s) ? y(s) : D.current = s;
91
91
  },
92
92
  resetValidation() {
93
93
  let s = T;
94
- _(s, y.current) || (y.current = s, $(s)), o === "native" && V(!1), g(!0);
94
+ _(s, p.current) || (p.current = s, y(s)), o === "native" && V(!1), $(!0);
95
95
  },
96
96
  commitValidation() {
97
- o === "native" && V(!0), g(!0);
97
+ o === "native" && V(!0), $(!0);
98
98
  }
99
99
  };
100
100
  }
101
- function B(r) {
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 B(t);
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(), K = !1;
123
+ let z = /* @__PURE__ */ new Map(), B = !1;
124
124
  try {
125
- K = new Intl.NumberFormat("de-DE", {
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 (!K && this.options.signDisplay != null ? t = Pe(this.numberFormatter, this.options.signDisplay, e) : t = this.numberFormatter.format(e), this.options.style === "unit" && !L) {
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 !K && this.options.signDisplay != null && (e = {
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 G(this.locale, this.options, e).parse(e);
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 G(this.locale, this.options, e).isValidPartialNumber(e, t, i);
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 G(this.locale, this.options, e).options.numberingSystem;
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 G(r, e, t) {
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 m = new Intl.NumberFormat(r, {
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,20 +351,20 @@ function Re(r, e, t, i) {
351
351
  roundingIncrement: 1,
352
352
  roundingPriority: "auto",
353
353
  roundingMode: "halfExpand"
354
- }), N = m.formatToParts(-10000.111), p = m.formatToParts(10000.111), d = Ie.map((s) => m.formatToParts(s));
355
- var b;
356
- let h = (b = (n = N.find((s) => s.type === "minusSign")) === null || n === void 0 ? void 0 : n.value) !== null && b !== void 0 ? b : "-", f = (a = p.find((s) => s.type === "plusSign")) === null || a === void 0 ? void 0 : a.value;
354
+ }), N = c.formatToParts(-10000.111), b = c.formatToParts(10000.111), d = Ie.map((s) => c.formatToParts(s));
355
+ var h;
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 = "+");
358
358
  let S = (l = new Intl.NumberFormat(r, {
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)), $ = d.flatMap((s) => s.filter((E) => !ee.has(E.type)).map((E) => te(E.value))), y = [
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), c = y.length === 0 ? new RegExp("[\\p{White_Space}]", "gu") : new RegExp(`${y.join("|")}|[\\p{White_Space}]`, "gu"), P = [
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)
@@ -373,11 +373,11 @@ function Re(r, e, t, i) {
373
373
  E
374
374
  ])), I = new RegExp(`[${P.join("")}]`, "g");
375
375
  return {
376
- minusSign: h,
376
+ minusSign: g,
377
377
  plusSign: f,
378
378
  decimal: S,
379
379
  group: D,
380
- literals: c,
380
+ literals: m,
381
381
  numeral: I,
382
382
  index: (s) => String(V.get(s))
383
383
  };
@@ -389,83 +389,83 @@ function te(r) {
389
389
  return r.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
390
390
  }
391
391
  function Oe(r) {
392
- let { minValue: e, maxValue: t, step: i, formatOptions: n, value: a, defaultValue: l = NaN, onChange: o, locale: m, isDisabled: N, isReadOnly: p } = 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, b] = Ne(a, isNaN(l) ? NaN : l, o), [h, f] = M(() => isNaN(d) ? "" : new Y(m, n).format(d)), g = w(() => new ne(m, n), [
395
- m,
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(() => g.getNumberingSystem(h), [
398
- g,
399
- h
400
- ]), D = w(() => new Y(m, {
397
+ ]), S = w(() => $.getNumberingSystem(g), [
398
+ $,
399
+ g
400
+ ]), D = w(() => new Y(c, {
401
401
  ...n,
402
402
  numberingSystem: S
403
403
  }), [
404
- m,
404
+ c,
405
405
  n,
406
406
  S
407
407
  ]), x = w(() => D.resolvedOptions(), [
408
408
  D
409
- ]), $ = ge((u) => isNaN(u) || u === null ? "" : D.format(u), [
409
+ ]), y = ge((u) => isNaN(u) || u === null ? "" : D.format(u), [
410
410
  D
411
- ]), y = Se({
411
+ ]), p = Se({
412
412
  ...r,
413
413
  value: d
414
- }), c = i !== void 0 && !isNaN(i) ? i : 1;
415
- x.style === "percent" && (i === void 0 || isNaN(i)) && (c = 0.01);
416
- let [P, V] = M(d), [I, R] = M(m), [s, E] = M(n);
417
- (!Object.is(d, P) || m !== I || n !== s) && (f($(d)), V(d), R(m), E(n));
418
- let v = w(() => g.parse(h), [
419
- g,
420
- h
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
+ g
421
421
  ]), se = () => {
422
- if (!h.length) {
423
- b(NaN), f(a === void 0 ? "" : $(d));
422
+ if (!g.length) {
423
+ h(NaN), f(a === void 0 ? "" : y(d));
424
424
  return;
425
425
  }
426
426
  if (isNaN(v)) {
427
- f($(d));
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 = g.parse($(u)), b(u), f($(a === void 0 ? u : d));
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
433
  let O = v;
434
434
  if (isNaN(O)) {
435
435
  let C = isNaN(Q) ? 0 : Q;
436
- return F(C, e, t, c);
436
+ return F(C, e, t, m);
437
437
  } else {
438
- let C = F(O, e, t, c);
439
- return u === "+" && C > O || u === "-" && C < O ? C : F(U(u, O, c), e, t, c);
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($(u)), b(u), y.commitValidation();
443
+ u === d && f(y(u)), h(u), p.commitValidation();
444
444
  }, oe = () => {
445
445
  let u = k("-", t);
446
- u === d && f($(u)), b(u), y.commitValidation();
446
+ u === d && f(y(u)), h(u), p.commitValidation();
447
447
  }, ue = () => {
448
- t != null && (b(F(t, e, t, c)), y.commitValidation());
448
+ t != null && (h(F(t, e, t, m)), p.commitValidation());
449
449
  }, me = () => {
450
- e != null && (b(e), y.commitValidation());
451
- }, ce = w(() => !N && !p && (isNaN(v) || t === void 0 || isNaN(t) || F(v, e, t, c) > v || U("+", v, c) <= 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
- p,
453
+ b,
454
454
  e,
455
455
  t,
456
- c,
456
+ m,
457
457
  v
458
- ]), de = w(() => !N && !p && (isNaN(v) || e === void 0 || isNaN(e) || F(v, e, t, c) < v || U("-", v, c) >= e), [
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
- p,
460
+ b,
461
461
  e,
462
462
  t,
463
- c,
463
+ m,
464
464
  v
465
465
  ]);
466
466
  return {
467
- ...y,
468
- validate: (u) => g.isValidPartialNumber(u, e, t),
467
+ ...p,
468
+ validate: (u) => $.isValidPartialNumber(u, e, t),
469
469
  increment: le,
470
470
  incrementToMax: ue,
471
471
  decrement: oe,
@@ -475,17 +475,17 @@ function Oe(r) {
475
475
  minValue: e,
476
476
  maxValue: t,
477
477
  numberValue: v,
478
- setNumberValue: b,
478
+ setNumberValue: h,
479
479
  setInputValue: f,
480
- inputValue: h,
480
+ inputValue: g,
481
481
  commit: se
482
482
  };
483
483
  }
484
- function U(r, e, t) {
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, m = Math.pow(10, Math.max(l, o));
488
- e = Math.round(e * m), t = Math.round(t * m), i = r === "+" ? e + t : e - t, i /= m;
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,35 +499,35 @@ const _e = $e(
499
499
  leftAdornments: a,
500
500
  rightAdornments: l,
501
501
  leftAdornmentsProps: o,
502
- rightAdornmentsProps: m,
502
+ rightAdornmentsProps: c,
503
503
  leftAdornmentsWidth: N,
504
- rightAdornmentsWidth: p,
504
+ rightAdornmentsWidth: b,
505
505
  className: d,
506
- style: b,
507
- label: h,
506
+ style: h,
507
+ label: g,
508
508
  value: f,
509
- locale: g,
509
+ locale: $,
510
510
  ...S
511
511
  }, D) => {
512
- g = g ?? "nb-NO";
512
+ $ = $ ?? "nb-NO";
513
513
  const x = Oe({
514
514
  ...S,
515
- label: h ?? "number-field",
515
+ label: g ?? "number-field",
516
516
  value: f,
517
- onChange: (c) => {
518
- S.onChange && S.onChange(c);
517
+ onChange: (m) => {
518
+ S.onChange && S.onChange(m);
519
519
  },
520
- locale: g
521
- }), $ = Z(null), { inputProps: y } = ye(
520
+ locale: $
521
+ }), y = U(null), { inputProps: p } = ye(
522
522
  {
523
523
  ...S,
524
524
  isReadOnly: n,
525
525
  isDisabled: t,
526
- label: h ?? "number-field",
526
+ label: g ?? "number-field",
527
527
  value: f
528
528
  },
529
529
  x,
530
- $
530
+ y
531
531
  );
532
532
  return /* @__PURE__ */ fe(
533
533
  ve,
@@ -538,25 +538,25 @@ const _e = $e(
538
538
  leftAdornments: a,
539
539
  rightAdornments: l,
540
540
  leftAdornmentsProps: o,
541
- rightAdornmentsProps: m,
541
+ rightAdornmentsProps: c,
542
542
  leftAdornmentsWidth: N,
543
- rightAdornmentsWidth: p,
543
+ rightAdornmentsWidth: b,
544
544
  className: d,
545
- style: b,
546
- "data-testid": `number-field-${h}`,
547
- ...y,
548
- onKeyDown: (c) => {
545
+ style: h,
546
+ "data-testid": `number-field-${g}`,
547
+ ...p,
548
+ onKeyDown: (m) => {
549
549
  var P;
550
- if (c.key === ".") {
551
- c.preventDefault();
552
- const V = c.target;
550
+ if (m.key === ".") {
551
+ m.preventDefault();
552
+ const V = m.target;
553
553
  if ((P = V.value) != null && P.includes(",")) return;
554
554
  const I = V.selectionStart || 0, R = V.selectionEnd || 0;
555
555
  V.value = V.value.substring(0, I) + "," + V.value.substring(R);
556
- }
556
+ } else p.onKeyDown && p.onKeyDown(m);
557
557
  },
558
558
  ref: D,
559
- "aria-label": h
559
+ "aria-label": g
560
560
  }
561
561
  );
562
562
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@equinor/roma-ui",
3
- "version": "0.2.2",
3
+ "version": "0.2.3",
4
4
  "exports": {
5
5
  ".": {
6
6
  "import": "./index.mjs",