2 lines
8.9 KiB
JavaScript
2 lines
8.9 KiB
JavaScript
import{x as N,y as _,j as f,S as L,z,D as fe,P as F,E as y,G as pe,I as me,J as ve,f as K}from"./ui-library-DAxvtEhC.js";import{e as S,a as s}from"./react-vendor-DnK_KZAP.js";function Re(e){const o=e+"CollectionProvider",[t,n]=N(o),[c,a]=t(o,{collectionRef:{current:null},itemMap:new Map}),l=d=>{const{scope:r,children:p}=d,v=S.useRef(null),R=S.useRef(new Map).current;return f.jsx(c,{scope:r,itemMap:R,collectionRef:v,children:p})};l.displayName=o;const m=e+"CollectionSlot",u=S.forwardRef((d,r)=>{const{scope:p,children:v}=d,R=a(m,p),g=_(r,R.collectionRef);return f.jsx(L,{ref:g,children:v})});u.displayName=m;const i=e+"CollectionItemSlot",C="data-radix-collection-item",b=S.forwardRef((d,r)=>{const{scope:p,children:v,...R}=d,g=S.useRef(null),E=_(r,g),w=a(i,p);return S.useEffect(()=>(w.itemMap.set(g,{ref:g,...R}),()=>void w.itemMap.delete(g))),f.jsx(L,{[C]:"",ref:E,children:v})});b.displayName=i;function I(d){const r=a(e+"CollectionConsumer",d);return S.useCallback(()=>{const v=r.collectionRef.current;if(!v)return[];const R=Array.from(v.querySelectorAll(`[${C}]`));return Array.from(r.itemMap.values()).sort((w,A)=>R.indexOf(w.ref.current)-R.indexOf(A.ref.current))},[r.collectionRef,r.itemMap])}return[{Provider:l,Slot:u,ItemSlot:b},I,n]}var be=s.createContext(void 0);function U(e){const o=s.useContext(be);return e||o||"ltr"}var k="rovingFocusGroup.onEntryFocus",Ie={bubbles:!1,cancelable:!0},P="RovingFocusGroup",[G,B,ge]=Re(P),[Ce,V]=N(P,[ge]),[xe,ye]=Ce(P),q=s.forwardRef((e,o)=>f.jsx(G.Provider,{scope:e.__scopeRovingFocusGroup,children:f.jsx(G.Slot,{scope:e.__scopeRovingFocusGroup,children:f.jsx(he,{...e,ref:o})})}));q.displayName=P;var he=s.forwardRef((e,o)=>{const{__scopeRovingFocusGroup:t,orientation:n,loop:c=!1,dir:a,currentTabStopId:l,defaultCurrentTabStopId:m,onCurrentTabStopIdChange:u,onEntryFocus:i,preventScrollOnEntryFocus:C=!1,...b}=e,I=s.useRef(null),d=_(o,I),r=U(a),[p=null,v]=z({prop:l,defaultProp:m,onChange:u}),[R,g]=s.useState(!1),E=fe(i),w=B(t),A=s.useRef(!1),[ae,O]=s.useState(0);return s.useEffect(()=>{const x=I.current;if(x)return x.addEventListener(k,E),()=>x.removeEventListener(k,E)},[E]),f.jsx(xe,{scope:t,orientation:n,dir:r,loop:c,currentTabStopId:p,onItemFocus:s.useCallback(x=>v(x),[v]),onItemShiftTab:s.useCallback(()=>g(!0),[]),onFocusableItemAdd:s.useCallback(()=>O(x=>x+1),[]),onFocusableItemRemove:s.useCallback(()=>O(x=>x-1),[]),children:f.jsx(F.div,{tabIndex:R||ae===0?-1:0,"data-orientation":n,...b,ref:d,style:{outline:"none",...e.style},onMouseDown:y(e.onMouseDown,()=>{A.current=!0}),onFocus:y(e.onFocus,x=>{const ie=!A.current;if(x.target===x.currentTarget&&ie&&!R){const j=new CustomEvent(k,Ie);if(x.currentTarget.dispatchEvent(j),!j.defaultPrevented){const T=w().filter(h=>h.focusable),ue=T.find(h=>h.active),de=T.find(h=>h.id===p),le=[ue,de,...T].filter(Boolean).map(h=>h.ref.current);$(le,C)}}A.current=!1}),onBlur:y(e.onBlur,()=>g(!1))})})}),H="RovingFocusGroupItem",Y=s.forwardRef((e,o)=>{const{__scopeRovingFocusGroup:t,focusable:n=!0,active:c=!1,tabStopId:a,...l}=e,m=pe(),u=a||m,i=ye(H,t),C=i.currentTabStopId===u,b=B(t),{onFocusableItemAdd:I,onFocusableItemRemove:d}=i;return s.useEffect(()=>{if(n)return I(),()=>d()},[n,I,d]),f.jsx(G.ItemSlot,{scope:t,id:u,focusable:n,active:c,children:f.jsx(F.span,{tabIndex:C?0:-1,"data-orientation":i.orientation,...l,ref:o,onMouseDown:y(e.onMouseDown,r=>{n?i.onItemFocus(u):r.preventDefault()}),onFocus:y(e.onFocus,()=>i.onItemFocus(u)),onKeyDown:y(e.onKeyDown,r=>{if(r.key==="Tab"&&r.shiftKey){i.onItemShiftTab();return}if(r.target!==r.currentTarget)return;const p=we(r,i.orientation,i.dir);if(p!==void 0){if(r.metaKey||r.ctrlKey||r.altKey||r.shiftKey)return;r.preventDefault();let R=b().filter(g=>g.focusable).map(g=>g.ref.current);if(p==="last")R.reverse();else if(p==="prev"||p==="next"){p==="prev"&&R.reverse();const g=R.indexOf(r.currentTarget);R=i.loop?Ae(R,g+1):R.slice(g+1)}setTimeout(()=>$(R))}})})})});Y.displayName=H;var Se={ArrowLeft:"prev",ArrowUp:"prev",ArrowRight:"next",ArrowDown:"next",PageUp:"first",Home:"first",PageDown:"last",End:"last"};function Ee(e,o){return o!=="rtl"?e:e==="ArrowLeft"?"ArrowRight":e==="ArrowRight"?"ArrowLeft":e}function we(e,o,t){const n=Ee(e.key,t);if(!(o==="vertical"&&["ArrowLeft","ArrowRight"].includes(n))&&!(o==="horizontal"&&["ArrowUp","ArrowDown"].includes(n)))return Se[n]}function $(e,o=!1){const t=document.activeElement;for(const n of e)if(n===t||(n.focus({preventScroll:o}),document.activeElement!==t))return}function Ae(e,o){return e.map((t,n)=>e[(o+n)%e.length])}var _e=q,Fe=Y;function Ne(e){const[o,t]=s.useState(void 0);return me(()=>{if(e){t({width:e.offsetWidth,height:e.offsetHeight});const n=new ResizeObserver(c=>{if(!Array.isArray(c)||!c.length)return;const a=c[0];let l,m;if("borderBoxSize"in a){const u=a.borderBoxSize,i=Array.isArray(u)?u[0]:u;l=i.inlineSize,m=i.blockSize}else l=e.offsetWidth,m=e.offsetHeight;t({width:l,height:m})});return n.observe(e,{box:"border-box"}),()=>n.unobserve(e)}else t(void 0)},[e]),o}function Pe(e){const o=s.useRef({value:e,previous:e});return s.useMemo(()=>(o.current.value!==e&&(o.current.previous=o.current.value,o.current.value=e),o.current.previous),[e])}var M="Radio",[Te,W]=N(M),[ke,Ge]=Te(M),J=s.forwardRef((e,o)=>{const{__scopeRadio:t,name:n,checked:c=!1,required:a,disabled:l,value:m="on",onCheck:u,form:i,...C}=e,[b,I]=s.useState(null),d=_(o,v=>I(v)),r=s.useRef(!1),p=b?i||!!b.closest("form"):!0;return f.jsxs(ke,{scope:t,checked:c,disabled:l,children:[f.jsx(F.button,{type:"button",role:"radio","aria-checked":c,"data-state":Z(c),"data-disabled":l?"":void 0,disabled:l,value:m,...C,ref:d,onClick:y(e.onClick,v=>{c||u==null||u(),p&&(r.current=v.isPropagationStopped(),r.current||v.stopPropagation())})}),p&&f.jsx(Me,{control:b,bubbles:!r.current,name:n,value:m,checked:c,required:a,disabled:l,form:i,style:{transform:"translateX(-100%)"}})]})});J.displayName=M;var X="RadioIndicator",Q=s.forwardRef((e,o)=>{const{__scopeRadio:t,forceMount:n,...c}=e,a=Ge(X,t);return f.jsx(ve,{present:n||a.checked,children:f.jsx(F.span,{"data-state":Z(a.checked),"data-disabled":a.disabled?"":void 0,...c,ref:o})})});Q.displayName=X;var Me=e=>{const{control:o,checked:t,bubbles:n=!0,...c}=e,a=s.useRef(null),l=Pe(t),m=Ne(o);return s.useEffect(()=>{const u=a.current,i=window.HTMLInputElement.prototype,b=Object.getOwnPropertyDescriptor(i,"checked").set;if(l!==t&&b){const I=new Event("click",{bubbles:n});b.call(u,t),u.dispatchEvent(I)}},[l,t,n]),f.jsx("input",{type:"radio","aria-hidden":!0,defaultChecked:t,...c,tabIndex:-1,ref:a,style:{...e.style,...m,position:"absolute",pointerEvents:"none",opacity:0,margin:0}})};function Z(e){return e?"checked":"unchecked"}var De=["ArrowUp","ArrowDown","ArrowLeft","ArrowRight"],D="RadioGroup",[Oe,Ye]=N(D,[V,W]),ee=V(),oe=W(),[je,Le]=Oe(D),te=s.forwardRef((e,o)=>{const{__scopeRadioGroup:t,name:n,defaultValue:c,value:a,required:l=!1,disabled:m=!1,orientation:u,dir:i,loop:C=!0,onValueChange:b,...I}=e,d=ee(t),r=U(i),[p,v]=z({prop:a,defaultProp:c,onChange:b});return f.jsx(je,{scope:t,name:n,required:l,disabled:m,value:p,onValueChange:v,children:f.jsx(_e,{asChild:!0,...d,orientation:u,dir:r,loop:C,children:f.jsx(F.div,{role:"radiogroup","aria-required":l,"aria-orientation":u,"data-disabled":m?"":void 0,dir:r,...I,ref:o})})})});te.displayName=D;var re="RadioGroupItem",ne=s.forwardRef((e,o)=>{const{__scopeRadioGroup:t,disabled:n,...c}=e,a=Le(re,t),l=a.disabled||n,m=ee(t),u=oe(t),i=s.useRef(null),C=_(o,i),b=a.value===c.value,I=s.useRef(!1);return s.useEffect(()=>{const d=p=>{De.includes(p.key)&&(I.current=!0)},r=()=>I.current=!1;return document.addEventListener("keydown",d),document.addEventListener("keyup",r),()=>{document.removeEventListener("keydown",d),document.removeEventListener("keyup",r)}},[]),f.jsx(Fe,{asChild:!0,...m,focusable:!l,active:b,children:f.jsx(J,{disabled:l,required:a.required,checked:b,...u,...c,name:a.name,ref:C,onCheck:()=>a.onValueChange(c.value),onKeyDown:y(d=>{d.key==="Enter"&&d.preventDefault()}),onFocus:y(c.onFocus,()=>{var d;I.current&&((d=i.current)==null||d.click())})})})});ne.displayName=re;var ze="RadioGroupIndicator",Ke=s.forwardRef((e,o)=>{const{__scopeRadioGroup:t,...n}=e,c=oe(t);return f.jsx(Q,{...c,...n,ref:o})});Ke.displayName=ze;var se=te,ce=ne;const Ue=s.forwardRef(({className:e,...o},t)=>f.jsx(se,{className:K("grid gap-2",e),...o,ref:t}));Ue.displayName=se.displayName;const Be=s.forwardRef(({className:e,...o},t)=>f.jsx(ce,{ref:t,className:K(o.checked?"border-primary after:bg-opacity-1":"border-on_surface bg-transparent after:bg-opacity-0","size-5 rounded-full border-[2px] after:size-[9px] after:bg-primary before:scale-0 hover:before:scale-100 before:size-10 before:rounded-full before:transition-all before:absolute before:-top-3 before:-left-3 before:bg-on_surface/[8%] duration-300 after:rounded-full flex relative items-center justify-center text-primary focus:outline-none focus-visible:ring-1 focus-visible:ring-ring transition-all disabled:cursor-not-allowed disabled:opacity-50",e),...o}));Be.displayName=ce.displayName;export{Ue as R,Be as a};
|