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