dgz-ui
Version:
Custom ui library using React.js, Shadcn/ui, TailwindCSS, Typescript
2 lines (1 loc) • 5.58 kB
JavaScript
;const v=require("react"),w=require("./index-Ch6ABCiC.cjs"),D=require("./index-DcWZbXs6.cjs"),y=require("./index-t1JFNXJ1.cjs"),m=require("./jsx-runtime-DUiatUiq.cjs"),G=require("./index-C1ZpNc2P.cjs"),L=require("./index-CMmIsz5H.cjs"),J=require("./index-hwV4SK1V.cjs"),Q=require("./index-C3BrtnXJ.cjs");function W(e){const o=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const s in e)if(s!=="default"){const n=Object.getOwnPropertyDescriptor(e,s);Object.defineProperty(o,s,n.get?n:{enumerable:!0,get:()=>e[s]})}}return o.default=e,Object.freeze(o)}const a=W(v);function k(e){const o=e+"CollectionProvider",[s,n]=D.createContextScope(o),[_,I]=s(o,{collectionRef:{current:null},itemMap:new Map}),R=f=>{const{scope:t,children:u}=f,d=v.useRef(null),r=v.useRef(new Map).current;return m.jsxRuntimeExports.jsx(_,{scope:t,itemMap:r,collectionRef:d,children:u})};R.displayName=o;const x=e+"CollectionSlot",A=y.createSlot(x),p=v.forwardRef((f,t)=>{const{scope:u,children:d}=f,r=I(x,u),c=y.useComposedRefs(t,r.collectionRef);return m.jsxRuntimeExports.jsx(A,{ref:c,children:d})});p.displayName=x;const i=e+"CollectionItemSlot",C="data-radix-collection-item",S=y.createSlot(i),E=v.forwardRef((f,t)=>{const{scope:u,children:d,...r}=f,c=v.useRef(null),F=y.useComposedRefs(t,c),T=I(i,u);return v.useEffect(()=>(T.itemMap.set(c,{ref:c,...r}),()=>void T.itemMap.delete(c))),m.jsxRuntimeExports.jsx(S,{[C]:"",ref:F,children:d})});E.displayName=i;function g(f){const t=I(e+"CollectionConsumer",f);return v.useCallback(()=>{const d=t.collectionRef.current;if(!d)return[];const r=Array.from(d.querySelectorAll(`[${C}]`));return Array.from(t.itemMap.values()).sort((T,h)=>r.indexOf(T.ref.current)-r.indexOf(h.ref.current))},[t.collectionRef,t.itemMap])}return[{Provider:R,Slot:p,ItemSlot:E},g,n]}var M="rovingFocusGroup.onEntryFocus",X={bubbles:!1,cancelable:!0},j="RovingFocusGroup",[N,q,Z]=k(j),[ee,te]=D.createContextScope(j,[Z]),[oe,ne]=ee(j),K=a.forwardRef((e,o)=>m.jsxRuntimeExports.jsx(N.Provider,{scope:e.__scopeRovingFocusGroup,children:m.jsxRuntimeExports.jsx(N.Slot,{scope:e.__scopeRovingFocusGroup,children:m.jsxRuntimeExports.jsx(re,{...e,ref:o})})}));K.displayName=j;var re=a.forwardRef((e,o)=>{const{__scopeRovingFocusGroup:s,orientation:n,loop:_=!1,dir:I,currentTabStopId:R,defaultCurrentTabStopId:x,onCurrentTabStopIdChange:A,onEntryFocus:p,preventScrollOnEntryFocus:i=!1,...C}=e,S=a.useRef(null),E=y.useComposedRefs(o,S),g=Q.useDirection(I),[f,t]=G.useControllableState({prop:R,defaultProp:x??null,onChange:A,caller:j}),[u,d]=a.useState(!1),r=J.useCallbackRef(p),c=q(s),F=a.useRef(!1),[T,h]=a.useState(0);return a.useEffect(()=>{const l=S.current;if(l)return l.addEventListener(M,r),()=>l.removeEventListener(M,r)},[r]),m.jsxRuntimeExports.jsx(oe,{scope:s,orientation:n,dir:g,loop:_,currentTabStopId:f,onItemFocus:a.useCallback(l=>t(l),[t]),onItemShiftTab:a.useCallback(()=>d(!0),[]),onFocusableItemAdd:a.useCallback(()=>h(l=>l+1),[]),onFocusableItemRemove:a.useCallback(()=>h(l=>l-1),[]),children:m.jsxRuntimeExports.jsx(L.Primitive.div,{tabIndex:u||T===0?-1:0,"data-orientation":n,...C,ref:E,style:{outline:"none",...e.style},onMouseDown:w.composeEventHandlers(e.onMouseDown,()=>{F.current=!0}),onFocus:w.composeEventHandlers(e.onFocus,l=>{const B=!F.current;if(l.target===l.currentTarget&&B&&!u){const P=new CustomEvent(M,X);if(l.currentTarget.dispatchEvent(P),!P.defaultPrevented){const O=c().filter(b=>b.focusable),V=O.find(b=>b.active),Y=O.find(b=>b.id===f),z=[V,Y,...O].filter(Boolean).map(b=>b.ref.current);$(z,i)}}F.current=!1}),onBlur:w.composeEventHandlers(e.onBlur,()=>d(!1))})})}),U="RovingFocusGroupItem",H=a.forwardRef((e,o)=>{const{__scopeRovingFocusGroup:s,focusable:n=!0,active:_=!1,tabStopId:I,children:R,...x}=e,A=G.useId(),p=I||A,i=ne(U,s),C=i.currentTabStopId===p,S=q(s),{onFocusableItemAdd:E,onFocusableItemRemove:g,currentTabStopId:f}=i;return a.useEffect(()=>{if(n)return E(),()=>g()},[n,E,g]),m.jsxRuntimeExports.jsx(N.ItemSlot,{scope:s,id:p,focusable:n,active:_,children:m.jsxRuntimeExports.jsx(L.Primitive.span,{tabIndex:C?0:-1,"data-orientation":i.orientation,...x,ref:o,onMouseDown:w.composeEventHandlers(e.onMouseDown,t=>{n?i.onItemFocus(p):t.preventDefault()}),onFocus:w.composeEventHandlers(e.onFocus,()=>i.onItemFocus(p)),onKeyDown:w.composeEventHandlers(e.onKeyDown,t=>{if(t.key==="Tab"&&t.shiftKey){i.onItemShiftTab();return}if(t.target!==t.currentTarget)return;const u=ie(t,i.orientation,i.dir);if(u!==void 0){if(t.metaKey||t.ctrlKey||t.altKey||t.shiftKey)return;t.preventDefault();let r=S().filter(c=>c.focusable).map(c=>c.ref.current);if(u==="last")r.reverse();else if(u==="prev"||u==="next"){u==="prev"&&r.reverse();const c=r.indexOf(t.currentTarget);r=i.loop?ue(r,c+1):r.slice(c+1)}setTimeout(()=>$(r))}}),children:typeof R=="function"?R({isCurrentTabStop:C,hasTabStop:f!=null}):R})})});H.displayName=U;var se={ArrowLeft:"prev",ArrowUp:"prev",ArrowRight:"next",ArrowDown:"next",PageUp:"first",Home:"first",PageDown:"last",End:"last"};function ce(e,o){return o!=="rtl"?e:e==="ArrowLeft"?"ArrowRight":e==="ArrowRight"?"ArrowLeft":e}function ie(e,o,s){const n=ce(e.key,s);if(!(o==="vertical"&&["ArrowLeft","ArrowRight"].includes(n))&&!(o==="horizontal"&&["ArrowUp","ArrowDown"].includes(n)))return se[n]}function $(e,o=!1){const s=document.activeElement;for(const n of e)if(n===s||(n.focus({preventScroll:o}),document.activeElement!==s))return}function ue(e,o){return e.map((s,n)=>e[(o+n)%e.length])}var le=K,ae=H;exports.Item=ae;exports.Root=le;exports.createCollection=k;exports.createRovingFocusGroupScope=te;