1import{r as a,E as G,_ as J,f as k,bf as C,e as b,n as Q,V as pt,o as ft,m as mt,ak as bt,O as V,h as B,j as d,q as ht,al as gt,$ as yt,aC as O}from"./index.RuhrnD1v.js";import{I as It}from"./InputInstructions.BuiQHvdK.js";import{W as Ct}from"./WidgetLabel.CgwydhVR.js";import{W as Tt}from"./WidgetLabelHelpIcon.BKLcvqEy.js";import{u as St}from"./useBasicWidgetState.CI9LlGGe.js";import{s as wt}from"./sprintfjs.DSsuEWyc.js";import{u as vt}from"./uniqueId.HT2UodMD.js";import{I as xt}from"./input.edoqeH9S.js";import"./styled-components.CXqQ-NdV.js";import"./FormClearHelper.DFo50Lfo.js";import"./base-input.DmvIDeb9.js";import"./constants.BZvTtNRL.js";var Y=a.forwardRef(function(t,e){var o={fill:"currentColor",xmlns:"http://www.w3.org/2000/svg"};return a.createElement(G,J({iconAttrs:o,iconVerticalAlign:"middle",iconViewBox:"0 0 8 8"},t,{ref:e}),a.createElement("path",{d:"M0 3v2h8V3H0z"}))});Y.displayName="Minus";var Z=a.forwardRef(function(t,e){var o={fill:"currentColor",xmlns:"http://www.w3.org/2000/svg"};return a.createElement(G,J({iconAttrs:o,iconVerticalAlign:"middle",iconViewBox:"0 0 8 8"},t,{ref:e}),a.createElement("path",{d:"M3 0v3H0v2h3v3h2V5h3V3H5V0H3z"}))});Z.displayName="Plus";const Dt=k("div",{target:"eaeic2i0"})(({theme:t})=>({display:"flex",flexDirection:"row",flexWrap:"nowrap",alignItems:"center",height:t.sizes.minElementHeight,borderWidth:t.sizes.borderWidth,borderStyle:"solid",borderColor:t.colors.widgetBorderColor??t.colors.secondaryBg,transitionDuration:"200ms",transitionProperty:"border",transitionTimingFunction:"cubic-bezier(0.2, 0.8, 0.4, 1)",borderRadius:t.radii.default,overflow:"hidden","&.focused":{borderColor:t.colors.primary},input:{MozAppearance:"textfield","&::-webkit-inner-spin-button, &::-webkit-outer-spin-button":{WebkitAppearance:"none",margin:t.spacing.none}}})),Vt=k("div",{target:"eaeic2i1"})({display:"flex",flexDirection:"row",alignSelf:"stretch"}),_=k("button",{target:"eaeic2i2"})(({theme:t})=>({margin:t.spacing.none,border:"none",height:t.sizes.full,display:"flex",alignItems:"center",width:t.sizes.numberInputControlsWidth,justifyContent:"center",color:t.colors.bodyText,transition:"color 300ms, backgroundColor 300ms",backgroundColor:t.colors.secondaryBg,"&:hover:enabled, &:focus:enabled":{color:t.colors.white,backgroundColor:t.colors.primary,transition:"none",outline:"none"},"&:active":{outline:"none",border:"none"},"&:disabled":{cursor:"not-allowed",color:t.colors.fadedText40}})),kt=k("div",{target:"eaeic2i3"})(({theme:t,clearable:e})=>({position:"absolute",marginRight:t.spacing.twoXS,left:0,right:`calc(${t.sizes.numberInputControlsWidth} * 2 + ${e?"1em":"0em"})`})),Nt=pt.getLogger("NumberInput");function Et(t){return b(t)||t===""?void 0:t}const tt=t=>{const e=t.toString();if(e.includes("e-")){const o=e.match(/(\d+(?:\.\d+)?)e-(\d+)/);if(o){const i=(o[1]?.split(".")[1]||"").length,r=parseInt(o[2],10);return i+r}return 0}return(e.split(".")[1]||"").length},j=({value:t,format:e,step:o,dataType:i})=>{if(b(t))return null;let r=Et(e);if(b(r)&&Q(o)&&i===C.DataType.FLOAT&&o!==0){const l=tt(o);l>0&&(r=`%0.${l}f`)}if(b(r))return t.toString();try{return wt(r,t)}catch(l){return Nt.warn(`Error in sprintf(${r}, ${t}): ${l}`),String(t)}},Rt=(t,e,o)=>b(t)?!1:t-e>=o,Wt=(t,e,o)=>b(t)?!1:t+e<=o,q=(t,e,o)=>{const i=tt(e);if(i===0)switch(o){case"add":return t+e;case"subtract":return t-e}const r=Math.pow(10,i),l=Math.round(t*r),p=Math.round(e*r);switch(o){case"add":return(l+p)/r;case"subtract":return(l-p)/r}},Ft=({step:t,dataType:e})=>t||(e===C.DataType.INT?1:.01);function X(t,e){return e.dataType===C.DataType.INT?t.getIntValue(e):t.getDoubleValue(e)}function zt(t){return t.default??null}function Bt(t){return t.value??t.default??null}function Pt(t,e,o,i){switch(t.dataType){case C.DataType.INT:e.setIntValue(t,o.value,{fromUi:o.fromUi},i);break;case C.DataType.FLOAT:e.setDoubleValue(t,o.value,{fromUi:o.fromUi},i);break;default:throw new Error("Invalid data type")}}const Lt=({disabled:t,element:e,widgetMgr:o,fragmentId:i})=>{const r=ft(),{dataType:l,formId:p,default:T,format:N,icon:E,min:g,max:y}=e,{width:P,elementRef:et}=mt(),c=a.useMemo(()=>Ft({step:e.step,dataType:e.dataType}),[e.step,e.dataType]),I=a.useCallback(n=>j({value:n,dataType:l,format:N,step:c}),[l,N,c]),[f,w]=a.useState(!1),[h,S]=a.useState(()=>{const n=X(o,e)??T??null;return j({value:n,dataType:l,format:N,step:c})}),rt=e.queryParamKey?{paramKey:e.queryParamKey,valueType:"double_value",clearable:b(e.default)}
1:void 0,[L,U]=St({getStateFromWidgetMgr:X,getDefaultStateFromProto:zt,getCurrStateFromProto:Bt,updateWidgetMgrState:Pt,element:e,widgetMgr:o,fragmentId:i,formClearBehavior:"resetValueAndRunCallback",onFormCleared:a.useCallback(()=>{const n=T??null;w(!1),S(I(n))},[T,I]),queryParamBinding:rt}),[A,H]=a.useState(!1),R=a.useRef(null),[$]=a.useState(()=>vt("number_input_")),K=bt({formId:p}),ot=K?o.allowFormEnterToSubmit(p):f,nt=A&&P>V(r.breakpoints.hideWidgetDetails);a.useEffect(()=>{f||S(I(L))},[L,f,I]);const m=a.useCallback(({value:n,fromUi:s})=>{if(Q(n)&&(g>n||n>y)){R.current?.reportValidity();return}const D=n??T??null;U({value:D,fromUi:s}),w(!1),S(I(D))},[g,y,T,I,U]),at=a.useCallback(()=>{H(!0)},[]);a.useEffect(()=>{const n=R.current;if(n){const s=D=>{D.preventDefault()};return n.addEventListener("wheel",s),()=>{n.removeEventListener("wheel",s)}}},[]);const W=b(e.default)&&!t,it=a.useCallback(n=>{const{value:s}=n.target;s===""?(w(!0),S(null)):(w(!0),S(s))},[]),u=a.useMemo(()=>{if(h===null||h==="")return null;if(e.dataType===C.DataType.INT){const s=parseInt(h,10);return isNaN(s)?null:s}const n=parseFloat(h);return isNaN(n)?null:n},[h,e.dataType]),v=Rt(u,c,g),x=Wt(u,c,y),st=a.useCallback(()=>{f&&m({value:u,fromUi:!0}),H(!1)},[f,u,m]),F=a.useCallback(()=>{if(x){const n=q(u??g,c,"add");m({value:n,fromUi:!0})}},[u,g,c,x,m]),z=a.useCallback(()=>{if(v){const n=q(u??y,c,"subtract");m({value:n,fromUi:!0})}},[u,y,c,v,m]),lt=a.useCallback(n=>{const{key:s}=n;switch(s){case"ArrowUp":n.preventDefault(),F();break;case"ArrowDown":n.preventDefault(),z();break}},[F,z]),ct=a.useCallback(n=>{n.key==="Enter"&&(f&&m({value:u,fromUi:!0}),o.allowFormEnterToSubmit(p)&&o.submitForm(p,i))},[f,u,m,o,p,i]),ut=V(r.iconSizes.lg)+2*V(r.spacing.twoXS),M=V(r.breakpoints.hideNumberInputControls),dt=E?M+ut:M;return B("div",{className:"stNumberInput","data-testid":"stNumberInput",ref:et,children:[d(Ct,{label:e.label,disabled:t,labelVisibility:ht(e.labelVisibility?.value),htmlFor:$,children:e.help&&d(Tt,{content:e.help,label:e.label})}),B(Dt,{className:A?"focused":"","data-testid":"stNumberInputContainer",children:[d(xt,{type:"number",inputRef:R,value:h??"",placeholder:e.placeholder,onBlur:st,onFocus:at,onChange:it,onKeyPress:ct,onKeyDown:lt,clearable:W,clearOnEscape:W,disabled:t,"aria-label":e.label,startEnhancer:e.icon&&d(yt,{"data-testid":"stNumberInputIcon",iconValue:e.icon,size:"lg"}),id:$,overrides:{ClearIconContainer:{style:{padding:0}},ClearIcon:{props:{overrides:{Svg:{style:{color:r.colors.grayTextColor,padding:r.spacing.threeXS,height:r.sizes.clearIconSize,width:r.sizes.clearIconSize,":hover":{fill:r.colors.bodyText}}}}}},Input:{props:{"data-testid":"stNumberInputField",step:c,min:g,max:y,type:"number",inputMode:""},style:{fontWeight:r.fontWeights.normal,lineHeight:r.lineHeights.inputWidget,paddingRight:r.spacing.sm,paddingLeft:r.spacing.md,paddingBottom:r.spacing.sm,paddingTop:r.spacing.sm,"::placeholder":{color:r.colors.fadedText60}}},InputContainer:{style:()=>({borderTopRightRadius:0,borderBottomRightRadius:0})},Root:{style:{borderTopRightRadius:0,borderBottomRightRadius:0,borderTopLeftRadius:0,borderBottomLeftRadius:0,borderLeftWidth:0,borderRightWidth:0,borderTopWidth:0,borderBottomWidth:0,paddingRight:0,paddingLeft:E?r.spacing.sm:0}},StartEnhancer:{style:{paddingLeft:0,paddingRight:0,minWidth:r.iconSizes.lg,color:gt(E)?r.colors.fadedText60:"inherit"}}}}),P>dt&&B(Vt,{children:[d(_,{"data-testid":"stNumberInputStepDown",onClick:z,disabled:!v||t,tabIndex:-1,children:d(O,{content:Y,size:"xs",color:v?"inherit":r.colors.fadedText40})}),d(_,{"data-testid":"stNumberInputStepUp",onClick:F,disabled:!x||t,tabIndex:-1,children:d(O,{content:Z,size:"xs",color:x?"inherit":r.colors.fadedText40})})]})]}),nt&&d(kt,{clearable:W,children:d(It,{dirty:f,value:h??"",inForm:K,allowEnterToSubmit:ot})})]})},Jt=a.memo(Lt);export{Jt as default};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.