1 line
4.1 KiB
JavaScript
1 line
4.1 KiB
JavaScript
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{B as t,E as n,L as r,P as i,W as a,c as o,d as s,j as c,l,r as u,x as d}from"./button-BhAQo6Sy.js";import{M as f,a as p,c as m,i as h,o as g,r as _,s as v,x as y,y as b}from"./api-Bb85n68L.js";var x=e(a(),1);function S(e){return e?.ownerDocument||document}function C(e){let t=e.activeElement;for(;t?.shadowRoot?.activeElement!=null;)t=t.shadowRoot.activeElement;return t}function w(e,t){if(!e||!t)return!1;let r=t.getRootNode?.();if(e.contains(t))return!0;if(r&&n(r)){let n=t;for(;n;){if(e===n)return!0;n=n.parentNode||n.host}}return!1}function T(e){return`composedPath`in e?e.composedPath()[0]:e.target}function E(e,t){return t<0||t>=e.length}function D(e,t){return k(e.current,{disabledIndices:t})}function O(e,t){return k(e.current,{decrement:!0,startingIndex:e.current.length,disabledIndices:t})}function k(e,{startingIndex:t=-1,decrement:n=!1,disabledIndices:r,amount:i=1}={}){let a=t;do a+=n?-i:i;while(a>=0&&a<=e.length-1&&A(e,a,r));return a}function A(e,t,n){if(typeof n==`function`?n(t):n?.includes(t)??!1)return!0;let r=e[t];return r?!M(r)||r.matches(`:disabled`)?!0:!n&&(r.hasAttribute(`disabled`)||r.getAttribute(`aria-disabled`)===`true`):!1}function j(e){return e.visibility===`hidden`||e.visibility===`collapse`}function M(e,t=e?s(e):null){return!e||!e.isConnected||!t||j(t)?!1:typeof e.checkVisibility==`function`?e.checkVisibility():t.display!==`none`&&t.display!==`contents`}var N=x.createContext(void 0);function P(){return x.useContext(N)?.direction??`ltr`}function F(e={}){let{id:n,implicit:i=!1,controlRef:a}=e,{controlId:s,registerControlId:c}=h(),u=b(n),f=i?s:void 0,p=t(()=>Symbol()),m=x.useRef(!1),g=x.useRef(n!=null),_=l(()=>{!m.current||c===r||(m.current=!1,c(p.current,void 0))});return o(()=>{if(c===r)return;let e;if(i){let t=a?.current;e=d(t)&&t.closest(`label`)!=null?n??null:f??u}else if(n!=null)g.current=!0,e=n;else if(g.current)e=u;else{_();return}if(e===void 0){_();return}m.current=!0,c(p.current,e)},[n,a,f,c,i,u,p,_]),x.useEffect(()=>_,[_]),s??u}var I=x.forwardRef(function(e,t){let{render:n,className:r,id:a,name:s,value:c,disabled:u=!1,onValueChange:d,defaultValue:b,autoFocus:w=!1,style:T,...E}=e,{state:D,name:O,disabled:k,setTouched:A,setDirty:j,validityData:M,setFocused:N,setFilled:P,validationMode:I,validation:L}=g(),{clearErrors:R}=p(),z=k||u,B=O??s,V={...D,disabled:z},{labelId:H}=h(),U=F({id:a});o(()=>{let e=c!=null;L.inputRef.current?.value||e&&c!==``?P(!0):e&&c===``&&P(!1)},[L.inputRef,P,c]);let W=x.useRef(null);o(()=>{w&&W.current===C(S(W.current))&&N(!0)},[w,N]);let[G]=m({controlled:c,default:b,name:`FieldControl`,state:`value`}),K=c!==void 0,q=K?G:void 0,J=l(()=>L.inputRef.current?.value);return _(L.inputRef,U,q,J,!z,s),i(`input`,e,{ref:[t,W],state:V,props:[{id:U,disabled:z,name:B,ref:L.inputRef,"aria-labelledby":H,autoFocus:w,...K?{value:q}:{defaultValue:b},onChange(e){let t=e.currentTarget.value;d?.(t,y(f,e.nativeEvent)),j(t!==(M.initialValue??``)),P(t!==``),e.nativeEvent.defaultPrevented||(R(B),L.change(t))},onFocus(){N(!0)},onBlur(e){A(!0),N(!1),I===`onBlur`&&L.commit(e.currentTarget.value)},onKeyDown(e){e.currentTarget.tagName===`INPUT`&&e.key===`Enter`&&(A(!0),L.commit(e.currentTarget.value))}},E,e=>L.getValidationProps(z,e)],stateAttributesMapping:v})}),L=u(),R=x.forwardRef(function(e,t){return(0,L.jsx)(I,{ref:t,...e})});function z({className:e,type:t,...n}){return(0,L.jsx)(R,{type:t,"data-slot":`input`,className:c(`h-8 w-full min-w-0 rounded-lg border border-input bg-transparent px-2.5 py-1 text-base transition-colors outline-none file:inline-flex file:h-6 file:border-0 file:bg-transparent file:text-sm file:font-medium file:text-foreground placeholder:text-muted-foreground focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/50 disabled:pointer-events-none disabled:cursor-not-allowed disabled:bg-input/50 disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-3 aria-invalid:ring-destructive/20 md:text-sm dark:bg-input/30 dark:disabled:bg-input/80 dark:aria-invalid:border-destructive/50 dark:aria-invalid:ring-destructive/40`,e),...n})}export{O as a,E as c,w as d,T as f,k as i,A as l,F as n,D as o,S as p,P as r,M as s,z as t,C as u}; |