@radix-ui/react-select 0.1.2-rc.9 → 1.0.1-rc.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,1134 @@
1
- import{RemoveScroll as e}from"react-remove-scroll";import{hideOthers as t}from"aria-hidden";import{VisuallyHidden as o}from"@radix-ui/react-visually-hidden";import{usePrevious as n}from"@radix-ui/react-use-previous";import{useLayoutEffect as r}from"@radix-ui/react-use-layout-effect";import{useControllableState as l}from"@radix-ui/react-use-controllable-state";import{useCallbackRef as c}from"@radix-ui/react-use-callback-ref";import{useDirection as a}from"@radix-ui/react-direction";import{Primitive as i}from"@radix-ui/react-primitive";import{Portal as s}from"@radix-ui/react-portal";import{useLabelContext as u}from"@radix-ui/react-label";import{useId as d}from"@radix-ui/react-id";import{FocusScope as p}from"@radix-ui/react-focus-scope";import{DismissableLayer as f}from"@radix-ui/react-dismissable-layer";import{createContextScope as m}from"@radix-ui/react-context";import{useComposedRefs as v}from"@radix-ui/react-compose-refs";import{createCollection as S}from"@radix-ui/react-collection";import{composeEventHandlers as g}from"@radix-ui/primitive";import{clamp as h}from"@radix-ui/number";import*as x from"react-dom";import*as w from"react";import b from"@babel/runtime/helpers/esm/extends";const y=[" ","Enter","ArrowUp","ArrowDown"],E=[" ","Enter"],[C,I,T]=S("Select"),[_,R]=m("Select",[T]);export{R as createSelectScope};const[D,P]=_("Select");export const Select=e=>{const{__scopeSelect:t,children:o,open:n,defaultOpen:r,onOpenChange:c,value:i,defaultValue:s,onValueChange:u,dir:p,name:f,autoComplete:m}=e,[v,S]=w.useState(null),[g,h]=w.useState(null),[x,b]=w.useState(!1),y=a(p),[E=!1,I]=l({prop:n,defaultProp:r,onChange:c}),[T="",_]=l({prop:i,defaultProp:s,onChange:u}),R=!v||Boolean(v.closest("form")),[P,L]=w.useState(null),k=w.useRef(null);/*#__PURE__*/return w.createElement(D,{scope:t,trigger:v,onTriggerChange:S,valueNode:g,onValueNodeChange:h,valueNodeHasChildren:x,onValueNodeHasChildrenChange:b,contentId:d(),value:T,onValueChange:_,open:E,onOpenChange:I,dir:y,bubbleSelect:P,triggerPointerDownPosRef:k},/*#__PURE__*/w.createElement(C.Provider,{scope:t},o),R?/*#__PURE__*/w.createElement(N,{ref:L,"aria-hidden":!0,tabIndex:-1,name:f,autoComplete:m,value:T,onChange:e=>_(e.target.value)}):null)};/*#__PURE__*/export const SelectTrigger=/*#__PURE__*/w.forwardRef(((e,t)=>{const{__scopeSelect:o,disabled:n=!1,"aria-labelledby":r,...l}=e,c=P("SelectTrigger",o),a=v(t,c.onTriggerChange),s=I(o),d=u(c.trigger),p=r||d,[f,m,S]=K((e=>{const t=s().filter((e=>!e.disabled)),o=t.find((e=>e.value===c.value)),n=F(t,e,o);void 0!==n&&c.onValueChange(n.value)})),h=()=>{n||(c.onOpenChange(!0),S())};/*#__PURE__*/return w.createElement(i.button,b({type:"button",role:"combobox","aria-controls":c.contentId,"aria-expanded":c.open,"aria-autocomplete":"none","aria-labelledby":p,dir:c.dir,disabled:n,"data-disabled":n?"":void 0},l,{ref:a,onPointerDown:g(l.onPointerDown,(e=>{e.target.releasePointerCapture(e.pointerId),0===e.button&&!1===e.ctrlKey&&(h(),c.triggerPointerDownPosRef.current={x:Math.round(e.pageX),y:Math.round(e.pageY)},e.preventDefault())})),onKeyDown:g(l.onKeyDown,(e=>{const t=""!==f.current;e.ctrlKey||e.altKey||e.metaKey||1!==e.key.length||m(e.key),t&&" "===e.key||y.includes(e.key)&&(h(),e.preventDefault())}))}))}));/*#__PURE__*/export const SelectValue=/*#__PURE__*/w.forwardRef(((e,t)=>{const{__scopeSelect:o,className:n,style:r,...l}=e,c=P("SelectValue",o),{onValueNodeHasChildrenChange:a}=c,s=void 0!==e.children,u=v(t,c.onValueNodeChange);return w.useEffect((()=>{a(s)}),[a,s]),/*#__PURE__*/w.createElement(i.span,b({},l,{ref:u,style:{pointerEvents:"none"}}))}));/*#__PURE__*/export const SelectIcon=/*#__PURE__*/w.forwardRef(((e,t)=>{const{__scopeSelect:o,children:n,...r}=e;/*#__PURE__*/return w.createElement(i.span,b({"aria-hidden":!0},r,{ref:t}),n||"▼")}));/*#__PURE__*/export const SelectContent=/*#__PURE__*/w.forwardRef(((e,t)=>{const o=P("SelectContent",e.__scopeSelect),[n,l]=w.useState();return r((()=>{l(new DocumentFragment)}),[]),o.open?/*#__PURE__*/w.createElement(V,b({},e,{ref:t})):n?/*#__PURE__*/x.createPortal(/*#__PURE__*/
2
- w.createElement(L,{scope:e.__scopeSelect},/*#__PURE__*/w.createElement(C.Slot,{scope:e.__scopeSelect},/*#__PURE__*/w.createElement("div",null,e.children))),n):null}));const[L,k]=_("SelectContent"),V=/*#__PURE__*/w.forwardRef(((o,n)=>{const{__scopeSelect:l,onCloseAutoFocus:c,...a}=o,i=P("SelectContent",l),[u,d]=w.useState(null),[m,S]=w.useState(null),[x,y]=w.useState(null),E=v(n,(e=>S(e))),[C,T]=w.useState(null),[_,R]=w.useState(null),D=I(l),[k,V]=w.useState(!1),H=w.useRef(!0),M=w.useRef(!1);w.useEffect((()=>{if(m)return t(m)}),[m]);const B=w.useCallback((e=>{const[t,...o]=D().map((e=>e.ref.current)),[n]=o.slice(-1),r=document.activeElement;for(const o of e){if(o===r)return;if(null==o||o.scrollIntoView({block:"nearest"}),o===t&&x&&(x.scrollTop=0),o===n&&x&&(x.scrollTop=x.scrollHeight),null==o||o.focus(),document.activeElement!==r)return}}),[D,x]),A=w.useCallback((()=>{if(i.trigger&&i.valueNode&&u&&m&&x&&C&&_){const e=i.trigger.getBoundingClientRect(),t=m.getBoundingClientRect(),o=i.valueNode.getBoundingClientRect(),n=_.getBoundingClientRect();if("rtl"!==i.dir){const r=n.left-t.left,l=o.left-r,c=e.left-l,a=e.width+c,i=Math.max(a,t.width),s=window.innerWidth-10,d=h(l,[10,s-i]);u.style.minWidth=a+"px",u.style.left=d+"px"}else{const r=t.right-n.right,l=window.innerWidth-o.right-r,c=window.innerWidth-e.right-l,a=e.width+c,i=Math.max(a,t.width),s=window.innerWidth-10,d=h(l,[10,s-i]);u.style.minWidth=a+"px",u.style.right=d+"px"}const r=window.innerHeight-20,l=5*C.offsetHeight,c=x.scrollHeight,a=window.getComputedStyle(m),s=parseInt(a.borderTopWidth,10),d=parseInt(a.paddingTop,10),p=parseInt(a.borderBottomWidth,10),f=s+d+c+parseInt(a.paddingBottom,10)+p,v=e.top+e.height/2-10,S=r-v,g=C.offsetHeight/2,w=s+d+(C.offsetTop+g),b=f-w;if(w<=v){u.style.bottom="0px";const e=m.clientHeight-x.offsetTop-x.offsetHeight,t=w+Math.max(S,g+e+p);u.style.height=t+"px"}else{u.style.top="0px";const e=Math.max(v,s+x.offsetTop+g)+b;u.style.height=e+"px",x.scrollTop=w-v+x.offsetTop}u.style.margin="10px 0",u.style.minHeight=l+"px",u.style.maxHeight=r+"px",V(!0),requestAnimationFrame((()=>M.current=!0))}}),[i.trigger,i.valueNode,u,m,x,C,_,i.dir]);r((()=>A()),[A]);const O=w.useCallback((()=>B([C,m])),[B,C,m]);w.useEffect((()=>{k&&O()}),[k,O]);const N=w.useCallback((e=>{e&&!0===H.current&&(A(),O(),H.current=!1)}),[A,O]),{onOpenChange:U,triggerPointerDownPosRef:W}=i;w.useEffect((()=>{if(m){let e={x:0,y:0};const t=t=>{var o,n,r,l;e={x:Math.abs(Math.round(t.pageX)-(null!==(o=null===(n=W.current)||void 0===n?void 0:n.x)&&void 0!==o?o:0)),y:Math.abs(Math.round(t.pageY)-(null!==(r=null===(l=W.current)||void 0===l?void 0:l.y)&&void 0!==r?r:0))}},o=o=>{e.x<=10&&e.y<=10?o.preventDefault():m.contains(o.target)||U(!1),document.removeEventListener("pointermove",t),W.current=null};return null!==W.current&&(document.addEventListener("pointermove",t),document.addEventListener("pointerup",o,{capture:!0,once:!0})),()=>{document.removeEventListener("pointermove",t),document.removeEventListener("pointerup",o,{capture:!0})}}}),[m,U,W]),w.useEffect((()=>{const e=()=>U(!1);return window.addEventListener("blur",e),window.addEventListener("resize",e),()=>{window.removeEventListener("blur",e),window.removeEventListener("resize",e)}}),[U]);const[z,G]=K((e=>{const t=D().filter((e=>!e.disabled)),o=t.find((e=>e.ref.current===document.activeElement)),n=F(t,e,o);n&&setTimeout((()=>n.ref.current.focus()))})),j=w.useCallback((()=>null==m?void 0:m.focus()),[m]);/*#__PURE__*/return w.createElement(L,{scope:l,contentWrapper:u,content:m,viewport:x,onViewportChange:y,selectedItem:C,onSelectedItemChange:T,selectedItemText:_,onSelectedItemTextChange:R,onScrollButtonChange:N,onItemLeave:j,isPositioned:k,shouldExpandOnScrollRef:M,searchRef:z},/*#__PURE__*/w.createElement(s,null,/*#__PURE__*/w.createElement(e,null,/*#__PURE__*/w.createElement("div",{ref:d,style:{display:"flex",flexDirection:"column",position:"fixed",zIndex:0}},/*#__PURE__*/w.createElement(p,{asChild:!0,trapped:i.open,onMountAutoFocus:e=>{e.preventDefault()},onUnmountAutoFocus:g(c,(e=>{var t;null===(t=i.trigger)||void 0===t||t.focus({preventScroll:!0}),e.preventDefault()}))},/*#__PURE__*/w.createElement(f,b({role:"listbox",id:i.contentId,"data-state":i.open?"open":"closed",dir:i.dir,onContextMenu:e=>e.preventDefault()},a,{ref:E,style:{display:"flex",flexDirection:"column",boxSizing:"border-box",maxHeight:"100%",outline:"none",...a.style},disableOutsidePointerEvents:!0,onFocusOutside:e=>e.preventDefault(),onDismiss:()=>i.onOpenChange(!1),onKeyDown:g(a.onKeyDown,(e=>{const t=e.ctrlKey||e.altKey||e.metaKey;if("Tab"===e.key&&e.preventDefault(),t||1!==e.key.length||G(e.key),["ArrowUp","ArrowDown","Home","End"].includes(e.key)){let t=D().filter((e=>!e.disabled)).map((e=>e.ref.current));if(["ArrowUp","End"].includes(e.key)&&(t=t.slice().reverse()),["ArrowUp","ArrowDown"].includes(e.key)){const o=e.target,n=t.indexOf(o);t=t.slice(n+1)}setTimeout((()=>B(t))),e.preventDefault()}}))})))))))}));export const SelectViewport=/*#__PURE__*/w.forwardRef(((e,t)=>{const{__scopeSelect:o,...n}=e,r=k("SelectViewport",o),l=v(t,r.onViewportChange),c=w.useRef(0);/*#__PURE__*/return w.createElement(w.Fragment,null,/*#__PURE__*/w.createElement("style",{dangerouslySetInnerHTML:{__html:"[data-radix-select-viewport]{scrollbar-width:none;-ms-overflow-style:none;-webkit-overflow-scrolling:touch;}[data-radix-select-viewport]::-webkit-scrollbar{display:none}"}}),/*#__PURE__*/w.createElement(C.Slot,{scope:o},/*#__PURE__*/w.createElement(i.div,b({"data-radix-select-viewport":"",role:"presentation"},n,{ref:l,style:{position:"relative",flex:1,overflow:"auto",...n.style},onScroll:g(n.onScroll,(e=>{const t=e.currentTarget,{contentWrapper:o,shouldExpandOnScrollRef:n}=r;if(n.current&&o){const e=Math.abs(c.current-t.scrollTop);if(e>0){const n=window.innerHeight-20,r=parseFloat(o.style.minHeight),l=parseFloat(o.style.height),c=Math.max(r,l);if(c<n){const r=c+e,l=Math.min(n,r),a=r-l;o.style.height=l+"px","0px"===o.style.bottom&&(t.scrollTop=a>0?a:0,o.style.justifyContent="flex-end")}}}c.current=t.scrollTop}))}))))}));/*#__PURE__*/const[H,M]=_("SelectGroup");export const SelectGroup=/*#__PURE__*/w.forwardRef(((e,t)=>{const{__scopeSelect:o,...n}=e,r=d();/*#__PURE__*/return w.createElement(H,{scope:o,id:r},/*#__PURE__*/w.createElement(i.div,b({role:"group","aria-labelledby":r},n,{ref:t})))}));/*#__PURE__*/export const SelectLabel=/*#__PURE__*/w.forwardRef(((e,t)=>{const{__scopeSelect:o,...n}=e,r=M("SelectLabel",o);/*#__PURE__*/return w.createElement(i.div,b({id:r.id},n,{ref:t}))}));/*#__PURE__*/const[B,A]=_("SelectItem");export const SelectItem=/*#__PURE__*/w.forwardRef(((e,t)=>{const{__scopeSelect:o,value:n,disabled:r=!1,textValue:l,...c}=e,a=P("SelectItem",o),s=k("SelectItem",o),u=a.value===n,[p,f]=w.useState(null!=l?l:""),[m,S]=w.useState(!1),h=v(t,u?s.onSelectedItemChange:void 0),x=d(),y=()=>{r||(a.onValueChange(n),a.onOpenChange(!1))};/*#__PURE__*/return w.createElement(B,{scope:o,value:n,textId:x,isSelected:u,onItemTextChange:w.useCallback((e=>{f((t=>{var o;return t||(null!==(o=null==e?void 0:e.textContent)&&void 0!==o?o:"").trim()}))}),[])},/*#__PURE__*/w.createElement(C.ItemSlot,{scope:o,value:n,disabled:r,textValue:p},/*#__PURE__*/w.createElement(i.div,b({role:"option","aria-labelledby":x,"aria-selected":u&&m,"data-state":u?"active":"inactive","aria-disabled":r||void 0,"data-disabled":r?"":void 0,tabIndex:r?void 0:-1},c,{ref:h,onFocus:g(c.onFocus,(()=>S(!0))),onBlur:g(c.onBlur,(()=>S(!1))),onPointerUp:g(c.onPointerUp,y),onPointerMove:g(c.onPointerMove,(e=>{r?s.onItemLeave():e.currentTarget.focus({preventScroll:!0})})),onPointerLeave:g(c.onPointerLeave,(e=>{e.currentTarget===document.activeElement&&s.onItemLeave()})),onKeyDown:g(c.onKeyDown,(e=>{""!==s.searchRef.current&&" "===e.key||(E.includes(e.key)&&y()," "===e.key&&e.preventDefault())}))}))))}));/*#__PURE__*/export const SelectItemText=/*#__PURE__*/w.forwardRef(((e,t)=>{var o;const{__scopeSelect:n,className:r,style:l,...c}=e,a=P("SelectItemText",n),s=k("SelectItemText",n),u=A("SelectItemText",n),d=w.useRef(null),p=v(t,d,u.onItemTextChange,u.isSelected?s.onSelectedItemTextChange:void 0);/*#__PURE__*/return w.createElement(w.Fragment,null,/*#__PURE__*/w.createElement(i.span,b({id:u.textId},c,{ref:p})),u.isSelected&&a.valueNode&&!a.valueNodeHasChildren?/*#__PURE__*/x.createPortal(c.children,a.valueNode):null,a.bubbleSelect?/*#__PURE__*/x.createPortal(/*#__PURE__*/
3
- w.createElement("option",{value:u.value},null===(o=d.current)||void 0===o?void 0:o.textContent),a.bubbleSelect):null)}));/*#__PURE__*/export const SelectItemIndicator=/*#__PURE__*/w.forwardRef(((e,t)=>{const{__scopeSelect:o,...n}=e;return A("SelectItemIndicator",o).isSelected?/*#__PURE__*/w.createElement(i.span,b({"aria-hidden":!0},n,{ref:t})):null}));/*#__PURE__*/export const SelectScrollUpButton=/*#__PURE__*/w.forwardRef(((e,t)=>{const o=k("SelectScrollUpButton",e.__scopeSelect),[n,r]=w.useState(!1),l=v(t,o.onScrollButtonChange);return w.useEffect((()=>{if(o.viewport&&o.isPositioned){const t=o.viewport;function e(){const e=t.scrollTop>0;r(e)}return e(),t.addEventListener("scroll",e),()=>t.removeEventListener("scroll",e)}}),[o.viewport,o.isPositioned]),n?/*#__PURE__*/w.createElement(O,b({},e,{ref:l,onAutoScroll:()=>{const{viewport:e,selectedItem:t}=o;e&&t&&(e.scrollTop=e.scrollTop-t.offsetHeight)}})):null}));/*#__PURE__*/export const SelectScrollDownButton=/*#__PURE__*/w.forwardRef(((e,t)=>{const o=k("SelectScrollDownButton",e.__scopeSelect),[n,r]=w.useState(!1),l=v(t,o.onScrollButtonChange);return w.useEffect((()=>{if(o.viewport&&o.isPositioned){const t=o.viewport;function e(){const e=t.scrollHeight-t.clientHeight,o=Math.ceil(t.scrollTop)<e;r(o)}return e(),t.addEventListener("scroll",e),()=>t.removeEventListener("scroll",e)}}),[o.viewport,o.isPositioned]),n?/*#__PURE__*/w.createElement(O,b({},e,{ref:l,onAutoScroll:()=>{const{viewport:e,selectedItem:t}=o;e&&t&&(e.scrollTop=e.scrollTop+t.offsetHeight)}})):null}));/*#__PURE__*/const O=/*#__PURE__*/w.forwardRef(((e,t)=>{const{__scopeSelect:o,onAutoScroll:n,...l}=e,c=k("SelectScrollButton",o),a=w.useRef(null),s=I(o),u=w.useCallback((()=>{null!==a.current&&(window.clearInterval(a.current),a.current=null)}),[]);return w.useEffect((()=>()=>u()),[u]),r((()=>{var e;const t=s().find((e=>e.ref.current===document.activeElement));null==t||null===(e=t.ref.current)||void 0===e||e.scrollIntoView({block:"nearest"})}),[s]),/*#__PURE__*/w.createElement(i.div,b({"aria-hidden":!0},l,{ref:t,style:{flexShrink:0,...l.style},onPointerMove:g(l.onPointerMove,(()=>{c.onItemLeave(),null===a.current&&(a.current=window.setInterval(n,50))})),onPointerLeave:g(l.onPointerLeave,(()=>{u()}))}))}));export const SelectSeparator=/*#__PURE__*/w.forwardRef(((e,t)=>{const{__scopeSelect:o,...n}=e;/*#__PURE__*/return w.createElement(i.div,b({"aria-hidden":!0},n,{ref:t}))}));/*#__PURE__*/const N=/*#__PURE__*/w.forwardRef(((e,t)=>{const{value:r,...l}=e,c=w.useRef(null),a=v(t,c),i=n(r);return w.useEffect((()=>{const e=c.current,t=window.HTMLSelectElement.prototype,o=Object.getOwnPropertyDescriptor(t,"value").set;if(i!==r&&o){const t=new Event("change",{bubbles:!0});o.call(e,r),e.dispatchEvent(t)}}),[i,r]),/*#__PURE__*/w.createElement(o,{asChild:!0},/*#__PURE__*/w.createElement("select",b({},l,{ref:a,defaultValue:r})))}));function K(e){const t=c(e),o=w.useRef(""),n=w.useRef(0),r=w.useCallback((e=>{const r=o.current+e;t(r),function e(t){o.current=t,window.clearTimeout(n.current),""!==t&&(n.current=window.setTimeout((()=>e("")),1e3))}(r)}),[t]),l=w.useCallback((()=>{o.current="",window.clearTimeout(n.current)}),[]);return w.useEffect((()=>()=>window.clearTimeout(n.current)),[]),[o,r,l]}function F(e,t,o){const n=t.length>1&&Array.from(t).every((e=>e===t[0]))?t[0]:t,r=o?e.indexOf(o):-1;let l=(c=e,a=Math.max(r,0),c.map(((e,t)=>c[(a+t)%c.length])));var c,a;1===n.length&&(l=l.filter((e=>e!==o)));const i=l.find((e=>e.textValue.toLowerCase().startsWith(n.toLowerCase())));return i!==o?i:void 0}export const Root=Select;export const Trigger=SelectTrigger;export const Value=SelectValue;export const Icon=SelectIcon;export const Content=SelectContent;export const Viewport=SelectViewport;export const Group=SelectGroup;export const Label=SelectLabel;export const Item=SelectItem;export const ItemText=SelectItemText;export const ItemIndicator=SelectItemIndicator;export const ScrollUpButton=SelectScrollUpButton;export const ScrollDownButton=SelectScrollDownButton;export const Separator=SelectSeparator;
1
+ import $01b9c$babelruntimehelpersesmextends from "@babel/runtime/helpers/esm/extends";
2
+ import {useState as $01b9c$useState, useRef as $01b9c$useRef, createElement as $01b9c$createElement, useCallback as $01b9c$useCallback, forwardRef as $01b9c$forwardRef, Fragment as $01b9c$Fragment, useEffect as $01b9c$useEffect, useMemo as $01b9c$useMemo} from "react";
3
+ import {createPortal as $01b9c$createPortal} from "react-dom";
4
+ import {clamp as $01b9c$clamp} from "@radix-ui/number";
5
+ import {composeEventHandlers as $01b9c$composeEventHandlers} from "@radix-ui/primitive";
6
+ import {createCollection as $01b9c$createCollection} from "@radix-ui/react-collection";
7
+ import {useComposedRefs as $01b9c$useComposedRefs} from "@radix-ui/react-compose-refs";
8
+ import {createContextScope as $01b9c$createContextScope} from "@radix-ui/react-context";
9
+ import {useDirection as $01b9c$useDirection} from "@radix-ui/react-direction";
10
+ import {DismissableLayer as $01b9c$DismissableLayer} from "@radix-ui/react-dismissable-layer";
11
+ import {useFocusGuards as $01b9c$useFocusGuards} from "@radix-ui/react-focus-guards";
12
+ import {FocusScope as $01b9c$FocusScope} from "@radix-ui/react-focus-scope";
13
+ import {useId as $01b9c$useId} from "@radix-ui/react-id";
14
+ import {useLabelContext as $01b9c$useLabelContext} from "@radix-ui/react-label";
15
+ import {Portal as $01b9c$Portal} from "@radix-ui/react-portal";
16
+ import {Primitive as $01b9c$Primitive} from "@radix-ui/react-primitive";
17
+ import {Slot as $01b9c$Slot} from "@radix-ui/react-slot";
18
+ import {useCallbackRef as $01b9c$useCallbackRef} from "@radix-ui/react-use-callback-ref";
19
+ import {useControllableState as $01b9c$useControllableState} from "@radix-ui/react-use-controllable-state";
20
+ import {useLayoutEffect as $01b9c$useLayoutEffect} from "@radix-ui/react-use-layout-effect";
21
+ import {usePrevious as $01b9c$usePrevious} from "@radix-ui/react-use-previous";
22
+ import {VisuallyHidden as $01b9c$VisuallyHidden} from "@radix-ui/react-visually-hidden";
23
+ import {hideOthers as $01b9c$hideOthers} from "aria-hidden";
24
+ import {RemoveScroll as $01b9c$RemoveScroll} from "react-remove-scroll";
25
+
26
+
27
+
28
+
29
+
30
+
31
+
32
+
33
+
34
+
35
+
36
+
37
+
38
+
39
+
40
+
41
+
42
+
43
+
44
+
45
+
46
+
47
+
48
+
49
+
50
+ const $cc7e05a45900e73f$var$OPEN_KEYS = [
51
+ ' ',
52
+ 'Enter',
53
+ 'ArrowUp',
54
+ 'ArrowDown'
55
+ ];
56
+ const $cc7e05a45900e73f$var$SELECTION_KEYS = [
57
+ ' ',
58
+ 'Enter'
59
+ ];
60
+ /* -------------------------------------------------------------------------------------------------
61
+ * Select
62
+ * -----------------------------------------------------------------------------------------------*/ const $cc7e05a45900e73f$var$SELECT_NAME = 'Select';
63
+ const [$cc7e05a45900e73f$var$Collection, $cc7e05a45900e73f$var$useCollection, $cc7e05a45900e73f$var$createCollectionScope] = $01b9c$createCollection($cc7e05a45900e73f$var$SELECT_NAME);
64
+ const [$cc7e05a45900e73f$var$createSelectContext, $cc7e05a45900e73f$export$286727a75dc039bd] = $01b9c$createContextScope($cc7e05a45900e73f$var$SELECT_NAME, [
65
+ $cc7e05a45900e73f$var$createCollectionScope
66
+ ]);
67
+ const [$cc7e05a45900e73f$var$SelectProvider, $cc7e05a45900e73f$var$useSelectContext] = $cc7e05a45900e73f$var$createSelectContext($cc7e05a45900e73f$var$SELECT_NAME);
68
+ const [$cc7e05a45900e73f$var$SelectNativeOptionsProvider, $cc7e05a45900e73f$var$useSelectNativeOptionsContext] = $cc7e05a45900e73f$var$createSelectContext($cc7e05a45900e73f$var$SELECT_NAME);
69
+ const $cc7e05a45900e73f$export$ef9b1a59e592288f = (props)=>{
70
+ const { __scopeSelect: __scopeSelect , children: children , open: openProp , defaultOpen: defaultOpen , onOpenChange: onOpenChange , value: valueProp , defaultValue: defaultValue , onValueChange: onValueChange , dir: dir , name: name , autoComplete: autoComplete } = props;
71
+ const [trigger, setTrigger] = $01b9c$useState(null);
72
+ const [valueNode, setValueNode] = $01b9c$useState(null);
73
+ const [valueNodeHasChildren, setValueNodeHasChildren] = $01b9c$useState(false);
74
+ const direction = $01b9c$useDirection(dir);
75
+ const [open = false, setOpen] = $01b9c$useControllableState({
76
+ prop: openProp,
77
+ defaultProp: defaultOpen,
78
+ onChange: onOpenChange
79
+ });
80
+ const [value, setValue] = $01b9c$useControllableState({
81
+ prop: valueProp,
82
+ defaultProp: defaultValue,
83
+ onChange: onValueChange
84
+ });
85
+ const triggerPointerDownPosRef = $01b9c$useRef(null); // We set this to true by default so that events bubble to forms without JS (SSR)
86
+ const isFormControl = trigger ? Boolean(trigger.closest('form')) : true;
87
+ const [nativeOptionsSet, setNativeOptionsSet] = $01b9c$useState(new Set()); // The native `select` only associates the correct default value if the corresponding
88
+ // `option` is rendered as a child **at the same time** as itself.
89
+ // Because it might take a few renders for our items to gather the information to build
90
+ // the native `option`(s), we generate a key on the `select` to make sure React re-builds it
91
+ // each time the options change.
92
+ const nativeSelectKey = Array.from(nativeOptionsSet).map((option)=>option.props.value
93
+ ).join(';');
94
+ return /*#__PURE__*/ $01b9c$createElement($cc7e05a45900e73f$var$SelectProvider, {
95
+ scope: __scopeSelect,
96
+ trigger: trigger,
97
+ onTriggerChange: setTrigger,
98
+ valueNode: valueNode,
99
+ onValueNodeChange: setValueNode,
100
+ valueNodeHasChildren: valueNodeHasChildren,
101
+ onValueNodeHasChildrenChange: setValueNodeHasChildren,
102
+ contentId: $01b9c$useId(),
103
+ value: value,
104
+ onValueChange: setValue,
105
+ open: open,
106
+ onOpenChange: setOpen,
107
+ dir: direction,
108
+ triggerPointerDownPosRef: triggerPointerDownPosRef
109
+ }, /*#__PURE__*/ $01b9c$createElement($cc7e05a45900e73f$var$Collection.Provider, {
110
+ scope: __scopeSelect
111
+ }, /*#__PURE__*/ $01b9c$createElement($cc7e05a45900e73f$var$SelectNativeOptionsProvider, {
112
+ scope: props.__scopeSelect,
113
+ onNativeOptionAdd: $01b9c$useCallback((option)=>{
114
+ setNativeOptionsSet((prev)=>new Set(prev).add(option)
115
+ );
116
+ }, []),
117
+ onNativeOptionRemove: $01b9c$useCallback((option)=>{
118
+ setNativeOptionsSet((prev)=>{
119
+ const optionsSet = new Set(prev);
120
+ optionsSet.delete(option);
121
+ return optionsSet;
122
+ });
123
+ }, [])
124
+ }, children)), isFormControl ? /*#__PURE__*/ $01b9c$createElement($cc7e05a45900e73f$var$BubbleSelect, {
125
+ key: nativeSelectKey,
126
+ "aria-hidden": true,
127
+ tabIndex: -1,
128
+ name: name,
129
+ autoComplete: autoComplete,
130
+ value: value // enable form autofill
131
+ ,
132
+ onChange: (event)=>setValue(event.target.value)
133
+ }, Array.from(nativeOptionsSet)) : null);
134
+ };
135
+ /*#__PURE__*/ Object.assign($cc7e05a45900e73f$export$ef9b1a59e592288f, {
136
+ displayName: $cc7e05a45900e73f$var$SELECT_NAME
137
+ });
138
+ /* -------------------------------------------------------------------------------------------------
139
+ * SelectTrigger
140
+ * -----------------------------------------------------------------------------------------------*/ const $cc7e05a45900e73f$var$TRIGGER_NAME = 'SelectTrigger';
141
+ const $cc7e05a45900e73f$export$3ac1e88a1c0b9f1 = /*#__PURE__*/ $01b9c$forwardRef((props, forwardedRef)=>{
142
+ const { __scopeSelect: __scopeSelect , disabled: disabled = false , 'aria-labelledby': ariaLabelledby , ...triggerProps } = props;
143
+ const context = $cc7e05a45900e73f$var$useSelectContext($cc7e05a45900e73f$var$TRIGGER_NAME, __scopeSelect);
144
+ const composedRefs = $01b9c$useComposedRefs(forwardedRef, context.onTriggerChange);
145
+ const getItems = $cc7e05a45900e73f$var$useCollection(__scopeSelect);
146
+ const labelId = $01b9c$useLabelContext(context.trigger);
147
+ const labelledBy = ariaLabelledby || labelId;
148
+ const [searchRef, handleTypeaheadSearch, resetTypeahead] = $cc7e05a45900e73f$var$useTypeaheadSearch((search)=>{
149
+ const enabledItems = getItems().filter((item)=>!item.disabled
150
+ );
151
+ const currentItem = enabledItems.find((item)=>item.value === context.value
152
+ );
153
+ const nextItem = $cc7e05a45900e73f$var$findNextItem(enabledItems, search, currentItem);
154
+ if (nextItem !== undefined) context.onValueChange(nextItem.value);
155
+ });
156
+ const handleOpen = ()=>{
157
+ if (!disabled) {
158
+ context.onOpenChange(true); // reset typeahead when we open
159
+ resetTypeahead();
160
+ }
161
+ };
162
+ return /*#__PURE__*/ $01b9c$createElement($01b9c$Primitive.button, $01b9c$babelruntimehelpersesmextends({
163
+ type: "button",
164
+ role: "combobox",
165
+ "aria-controls": context.contentId,
166
+ "aria-expanded": context.open,
167
+ "aria-autocomplete": "none",
168
+ "aria-labelledby": labelledBy,
169
+ dir: context.dir,
170
+ "data-state": context.open ? 'open' : 'closed',
171
+ disabled: disabled,
172
+ "data-disabled": disabled ? '' : undefined,
173
+ "data-placeholder": context.value === undefined ? '' : undefined
174
+ }, triggerProps, {
175
+ ref: composedRefs,
176
+ onPointerDown: $01b9c$composeEventHandlers(triggerProps.onPointerDown, (event)=>{
177
+ // prevent implicit pointer capture
178
+ // https://www.w3.org/TR/pointerevents3/#implicit-pointer-capture
179
+ event.target.releasePointerCapture(event.pointerId); // only call handler if it's the left button (mousedown gets triggered by all mouse buttons)
180
+ // but not when the control key is pressed (avoiding MacOS right click)
181
+ if (event.button === 0 && event.ctrlKey === false) {
182
+ handleOpen();
183
+ context.triggerPointerDownPosRef.current = {
184
+ x: Math.round(event.pageX),
185
+ y: Math.round(event.pageY)
186
+ }; // prevent trigger from stealing focus from the active item after opening.
187
+ event.preventDefault();
188
+ }
189
+ }),
190
+ onKeyDown: $01b9c$composeEventHandlers(triggerProps.onKeyDown, (event)=>{
191
+ const isTypingAhead = searchRef.current !== '';
192
+ const isModifierKey = event.ctrlKey || event.altKey || event.metaKey;
193
+ if (!isModifierKey && event.key.length === 1) handleTypeaheadSearch(event.key);
194
+ if (isTypingAhead && event.key === ' ') return;
195
+ if ($cc7e05a45900e73f$var$OPEN_KEYS.includes(event.key)) {
196
+ handleOpen();
197
+ event.preventDefault();
198
+ }
199
+ })
200
+ }));
201
+ });
202
+ /*#__PURE__*/ Object.assign($cc7e05a45900e73f$export$3ac1e88a1c0b9f1, {
203
+ displayName: $cc7e05a45900e73f$var$TRIGGER_NAME
204
+ });
205
+ /* -------------------------------------------------------------------------------------------------
206
+ * SelectValue
207
+ * -----------------------------------------------------------------------------------------------*/ const $cc7e05a45900e73f$var$VALUE_NAME = 'SelectValue';
208
+ const $cc7e05a45900e73f$export$e288731fd71264f0 = /*#__PURE__*/ $01b9c$forwardRef((props, forwardedRef)=>{
209
+ // We ignore `className` and `style` as this part shouldn't be styled.
210
+ const { __scopeSelect: __scopeSelect , className: className , style: style , children: children , placeholder: placeholder , ...valueProps } = props;
211
+ const context = $cc7e05a45900e73f$var$useSelectContext($cc7e05a45900e73f$var$VALUE_NAME, __scopeSelect);
212
+ const { onValueNodeHasChildrenChange: onValueNodeHasChildrenChange } = context;
213
+ const hasChildren = children !== undefined;
214
+ const composedRefs = $01b9c$useComposedRefs(forwardedRef, context.onValueNodeChange);
215
+ $01b9c$useLayoutEffect(()=>{
216
+ onValueNodeHasChildrenChange(hasChildren);
217
+ }, [
218
+ onValueNodeHasChildrenChange,
219
+ hasChildren
220
+ ]);
221
+ return /*#__PURE__*/ $01b9c$createElement($01b9c$Primitive.span, $01b9c$babelruntimehelpersesmextends({}, valueProps, {
222
+ ref: composedRefs // we don't want events from the portalled `SelectValue` children to bubble
223
+ ,
224
+ style: {
225
+ pointerEvents: 'none'
226
+ }
227
+ }), context.value === undefined && placeholder !== undefined ? placeholder : children);
228
+ });
229
+ /*#__PURE__*/ Object.assign($cc7e05a45900e73f$export$e288731fd71264f0, {
230
+ displayName: $cc7e05a45900e73f$var$VALUE_NAME
231
+ });
232
+ /* -------------------------------------------------------------------------------------------------
233
+ * SelectIcon
234
+ * -----------------------------------------------------------------------------------------------*/ const $cc7e05a45900e73f$var$ICON_NAME = 'SelectIcon';
235
+ const $cc7e05a45900e73f$export$99b400cabb58c515 = /*#__PURE__*/ $01b9c$forwardRef((props, forwardedRef)=>{
236
+ const { __scopeSelect: __scopeSelect , children: children , ...iconProps } = props;
237
+ return /*#__PURE__*/ $01b9c$createElement($01b9c$Primitive.span, $01b9c$babelruntimehelpersesmextends({
238
+ "aria-hidden": true
239
+ }, iconProps, {
240
+ ref: forwardedRef
241
+ }), children || '▼');
242
+ });
243
+ /*#__PURE__*/ Object.assign($cc7e05a45900e73f$export$99b400cabb58c515, {
244
+ displayName: $cc7e05a45900e73f$var$ICON_NAME
245
+ });
246
+ /* -------------------------------------------------------------------------------------------------
247
+ * SelectPortal
248
+ * -----------------------------------------------------------------------------------------------*/ const $cc7e05a45900e73f$var$PORTAL_NAME = 'SelectPortal';
249
+ const $cc7e05a45900e73f$export$b2af6c9944296213 = (props)=>{
250
+ return /*#__PURE__*/ $01b9c$createElement($01b9c$Portal, $01b9c$babelruntimehelpersesmextends({
251
+ asChild: true
252
+ }, props));
253
+ };
254
+ /*#__PURE__*/ Object.assign($cc7e05a45900e73f$export$b2af6c9944296213, {
255
+ displayName: $cc7e05a45900e73f$var$PORTAL_NAME
256
+ });
257
+ /* -------------------------------------------------------------------------------------------------
258
+ * SelectContent
259
+ * -----------------------------------------------------------------------------------------------*/ const $cc7e05a45900e73f$var$CONTENT_NAME = 'SelectContent';
260
+ const $cc7e05a45900e73f$export$c973a4b3cb86a03d = /*#__PURE__*/ $01b9c$forwardRef((props, forwardedRef)=>{
261
+ const context = $cc7e05a45900e73f$var$useSelectContext($cc7e05a45900e73f$var$CONTENT_NAME, props.__scopeSelect);
262
+ const [fragment, setFragment] = $01b9c$useState(); // setting the fragment in `useLayoutEffect` as `DocumentFragment` doesn't exist on the server
263
+ $01b9c$useLayoutEffect(()=>{
264
+ setFragment(new DocumentFragment());
265
+ }, []);
266
+ return /*#__PURE__*/ $01b9c$createElement($01b9c$Fragment, null, context.open ? /*#__PURE__*/ $01b9c$createElement($cc7e05a45900e73f$var$SelectContentImpl, $01b9c$babelruntimehelpersesmextends({}, props, {
267
+ ref: forwardedRef
268
+ })) : fragment ? /*#__PURE__*/ $01b9c$createPortal(/*#__PURE__*/ $01b9c$createElement($cc7e05a45900e73f$var$SelectContentProvider, {
269
+ scope: props.__scopeSelect
270
+ }, /*#__PURE__*/ $01b9c$createElement($cc7e05a45900e73f$var$Collection.Slot, {
271
+ scope: props.__scopeSelect
272
+ }, /*#__PURE__*/ $01b9c$createElement("div", null, props.children))), fragment) : null);
273
+ });
274
+ /*#__PURE__*/ Object.assign($cc7e05a45900e73f$export$c973a4b3cb86a03d, {
275
+ displayName: $cc7e05a45900e73f$var$CONTENT_NAME
276
+ });
277
+ const $cc7e05a45900e73f$var$CONTENT_MARGIN = 10;
278
+ const [$cc7e05a45900e73f$var$SelectContentProvider, $cc7e05a45900e73f$var$useSelectContentContext] = $cc7e05a45900e73f$var$createSelectContext($cc7e05a45900e73f$var$CONTENT_NAME);
279
+ const $cc7e05a45900e73f$var$SelectContentImpl = /*#__PURE__*/ $01b9c$forwardRef((props, forwardedRef)=>{
280
+ const { __scopeSelect: __scopeSelect , onCloseAutoFocus: onCloseAutoFocus , ...contentProps } = props;
281
+ const context = $cc7e05a45900e73f$var$useSelectContext($cc7e05a45900e73f$var$CONTENT_NAME, __scopeSelect);
282
+ const [contentWrapper, setContentWrapper] = $01b9c$useState(null);
283
+ const [content, setContent] = $01b9c$useState(null);
284
+ const [viewport, setViewport] = $01b9c$useState(null);
285
+ const composedRefs = $01b9c$useComposedRefs(forwardedRef, (node)=>setContent(node)
286
+ );
287
+ const [selectedItem, setSelectedItem] = $01b9c$useState(null);
288
+ const [selectedItemText, setSelectedItemText] = $01b9c$useState(null);
289
+ const getItems = $cc7e05a45900e73f$var$useCollection(__scopeSelect);
290
+ const [isPositioned, setIsPositioned] = $01b9c$useState(false);
291
+ const shouldRepositionRef = $01b9c$useRef(true);
292
+ const shouldExpandOnScrollRef = $01b9c$useRef(false);
293
+ const firstValidItemFoundRef = $01b9c$useRef(false); // aria-hide everything except the content (better supported equivalent to setting aria-modal)
294
+ $01b9c$useEffect(()=>{
295
+ if (content) return $01b9c$hideOthers(content);
296
+ }, [
297
+ content
298
+ ]); // Make sure the whole tree has focus guards as our `Select` may be
299
+ // the last element in the DOM (because of the `Portal`)
300
+ $01b9c$useFocusGuards();
301
+ const [contentZIndex, setContentZIndex] = $01b9c$useState();
302
+ $01b9c$useLayoutEffect(()=>{
303
+ if (content) setContentZIndex(window.getComputedStyle(content).zIndex);
304
+ }, [
305
+ content
306
+ ]);
307
+ const focusFirst = $01b9c$useCallback((candidates)=>{
308
+ const [firstItem, ...restItems] = getItems().map((item)=>item.ref.current
309
+ );
310
+ const [lastItem] = restItems.slice(-1);
311
+ const PREVIOUSLY_FOCUSED_ELEMENT = document.activeElement;
312
+ for (const candidate of candidates){
313
+ // if focus is already where we want to go, we don't want to keep going through the candidates
314
+ if (candidate === PREVIOUSLY_FOCUSED_ELEMENT) return;
315
+ candidate === null || candidate === void 0 || candidate.scrollIntoView({
316
+ block: 'nearest'
317
+ }); // viewport might have padding so scroll to its edges when focusing first/last items.
318
+ if (candidate === firstItem && viewport) viewport.scrollTop = 0;
319
+ if (candidate === lastItem && viewport) viewport.scrollTop = viewport.scrollHeight;
320
+ candidate === null || candidate === void 0 || candidate.focus();
321
+ if (document.activeElement !== PREVIOUSLY_FOCUSED_ELEMENT) return;
322
+ }
323
+ }, [
324
+ getItems,
325
+ viewport
326
+ ]);
327
+ const position = $01b9c$useCallback(()=>{
328
+ if (context.trigger && context.valueNode && contentWrapper && content && viewport && selectedItem && selectedItemText) {
329
+ const triggerRect = context.trigger.getBoundingClientRect(); // -----------------------------------------------------------------------------------------
330
+ // Horizontal positioning
331
+ // -----------------------------------------------------------------------------------------
332
+ const contentRect = content.getBoundingClientRect();
333
+ const valueNodeRect = context.valueNode.getBoundingClientRect();
334
+ const itemTextRect = selectedItemText.getBoundingClientRect();
335
+ if (context.dir !== 'rtl') {
336
+ const itemTextOffset = itemTextRect.left - contentRect.left;
337
+ const left = valueNodeRect.left - itemTextOffset;
338
+ const leftDelta = triggerRect.left - left;
339
+ const minContentWidth = triggerRect.width + leftDelta;
340
+ const contentWidth = Math.max(minContentWidth, contentRect.width);
341
+ const rightEdge = window.innerWidth - $cc7e05a45900e73f$var$CONTENT_MARGIN;
342
+ const clampedLeft = $01b9c$clamp(left, [
343
+ $cc7e05a45900e73f$var$CONTENT_MARGIN,
344
+ rightEdge - contentWidth
345
+ ]);
346
+ contentWrapper.style.minWidth = minContentWidth + 'px';
347
+ contentWrapper.style.left = clampedLeft + 'px';
348
+ } else {
349
+ const itemTextOffset = contentRect.right - itemTextRect.right;
350
+ const right = window.innerWidth - valueNodeRect.right - itemTextOffset;
351
+ const rightDelta = window.innerWidth - triggerRect.right - right;
352
+ const minContentWidth = triggerRect.width + rightDelta;
353
+ const contentWidth = Math.max(minContentWidth, contentRect.width);
354
+ const leftEdge = window.innerWidth - $cc7e05a45900e73f$var$CONTENT_MARGIN;
355
+ const clampedRight = $01b9c$clamp(right, [
356
+ $cc7e05a45900e73f$var$CONTENT_MARGIN,
357
+ leftEdge - contentWidth
358
+ ]);
359
+ contentWrapper.style.minWidth = minContentWidth + 'px';
360
+ contentWrapper.style.right = clampedRight + 'px';
361
+ } // -----------------------------------------------------------------------------------------
362
+ // Vertical positioning
363
+ // -----------------------------------------------------------------------------------------
364
+ const items = getItems();
365
+ const availableHeight = window.innerHeight - $cc7e05a45900e73f$var$CONTENT_MARGIN * 2;
366
+ const itemsHeight = viewport.scrollHeight;
367
+ const contentStyles = window.getComputedStyle(content);
368
+ const contentBorderTopWidth = parseInt(contentStyles.borderTopWidth, 10);
369
+ const contentPaddingTop = parseInt(contentStyles.paddingTop, 10);
370
+ const contentBorderBottomWidth = parseInt(contentStyles.borderBottomWidth, 10);
371
+ const contentPaddingBottom = parseInt(contentStyles.paddingBottom, 10);
372
+ const fullContentHeight = contentBorderTopWidth + contentPaddingTop + itemsHeight + contentPaddingBottom + contentBorderBottomWidth; // prettier-ignore
373
+ const minContentHeight = Math.min(selectedItem.offsetHeight * 5, fullContentHeight);
374
+ const viewportStyles = window.getComputedStyle(viewport);
375
+ const viewportPaddingTop = parseInt(viewportStyles.paddingTop, 10);
376
+ const viewportPaddingBottom = parseInt(viewportStyles.paddingBottom, 10);
377
+ const topEdgeToTriggerMiddle = triggerRect.top + triggerRect.height / 2 - $cc7e05a45900e73f$var$CONTENT_MARGIN;
378
+ const triggerMiddleToBottomEdge = availableHeight - topEdgeToTriggerMiddle;
379
+ const selectedItemHalfHeight = selectedItem.offsetHeight / 2;
380
+ const itemOffsetMiddle = selectedItem.offsetTop + selectedItemHalfHeight;
381
+ const contentTopToItemMiddle = contentBorderTopWidth + contentPaddingTop + itemOffsetMiddle;
382
+ const itemMiddleToContentBottom = fullContentHeight - contentTopToItemMiddle;
383
+ const willAlignWithoutTopOverflow = contentTopToItemMiddle <= topEdgeToTriggerMiddle;
384
+ if (willAlignWithoutTopOverflow) {
385
+ const isLastItem = selectedItem === items[items.length - 1].ref.current;
386
+ contentWrapper.style.bottom = "0px";
387
+ const viewportOffsetBottom = content.clientHeight - viewport.offsetTop - viewport.offsetHeight;
388
+ const clampedTriggerMiddleToBottomEdge = Math.max(triggerMiddleToBottomEdge, selectedItemHalfHeight + (isLastItem ? viewportPaddingBottom : 0) + viewportOffsetBottom + contentBorderBottomWidth);
389
+ const height = contentTopToItemMiddle + clampedTriggerMiddleToBottomEdge;
390
+ contentWrapper.style.height = height + 'px';
391
+ } else {
392
+ const isFirstItem = selectedItem === items[0].ref.current;
393
+ contentWrapper.style.top = "0px";
394
+ const clampedTopEdgeToTriggerMiddle = Math.max(topEdgeToTriggerMiddle, contentBorderTopWidth + viewport.offsetTop + (isFirstItem ? viewportPaddingTop : 0) + selectedItemHalfHeight);
395
+ const height = clampedTopEdgeToTriggerMiddle + itemMiddleToContentBottom;
396
+ contentWrapper.style.height = height + 'px';
397
+ viewport.scrollTop = contentTopToItemMiddle - topEdgeToTriggerMiddle + viewport.offsetTop;
398
+ }
399
+ contentWrapper.style.margin = `${$cc7e05a45900e73f$var$CONTENT_MARGIN}px 0`;
400
+ contentWrapper.style.minHeight = minContentHeight + 'px';
401
+ contentWrapper.style.maxHeight = availableHeight + 'px'; // -----------------------------------------------------------------------------------------
402
+ setIsPositioned(true); // we don't want the initial scroll position adjustment to trigger "expand on scroll"
403
+ // so we explicitly turn it on only after they've registered.
404
+ requestAnimationFrame(()=>shouldExpandOnScrollRef.current = true
405
+ );
406
+ }
407
+ }, [
408
+ getItems,
409
+ context.trigger,
410
+ context.valueNode,
411
+ contentWrapper,
412
+ content,
413
+ viewport,
414
+ selectedItem,
415
+ selectedItemText,
416
+ context.dir
417
+ ]);
418
+ $01b9c$useLayoutEffect(()=>position()
419
+ , [
420
+ position
421
+ ]);
422
+ const focusSelectedItem = $01b9c$useCallback(()=>focusFirst([
423
+ selectedItem,
424
+ content
425
+ ])
426
+ , [
427
+ focusFirst,
428
+ selectedItem,
429
+ content
430
+ ]); // Since this is not dependent on layout, we want to ensure this runs at the same time as
431
+ // other effects across components. Hence why we don't call `focusSelectedItem` inside `position`.
432
+ $01b9c$useEffect(()=>{
433
+ if (isPositioned) focusSelectedItem();
434
+ }, [
435
+ isPositioned,
436
+ focusSelectedItem
437
+ ]); // When the viewport becomes scrollable at the top, the scroll up button will mount.
438
+ // Because it is part of the normal flow, it will push down the viewport, thus throwing our
439
+ // trigger => selectedItem alignment off by the amount the viewport was pushed down.
440
+ // We wait for this to happen and then re-run the positining logic one more time to account for it.
441
+ const handleScrollButtonChange = $01b9c$useCallback((node)=>{
442
+ if (node && shouldRepositionRef.current === true) {
443
+ position();
444
+ focusSelectedItem();
445
+ shouldRepositionRef.current = false;
446
+ }
447
+ }, [
448
+ position,
449
+ focusSelectedItem
450
+ ]); // prevent selecting items on `pointerup` in some cases after opening from `pointerdown`
451
+ // and close on `pointerup` outside.
452
+ const { onOpenChange: onOpenChange , triggerPointerDownPosRef: triggerPointerDownPosRef } = context;
453
+ $01b9c$useEffect(()=>{
454
+ if (content) {
455
+ let pointerMoveDelta = {
456
+ x: 0,
457
+ y: 0
458
+ };
459
+ const handlePointerMove = (event)=>{
460
+ var _triggerPointerDownPo, _triggerPointerDownPo2, _triggerPointerDownPo3, _triggerPointerDownPo4;
461
+ pointerMoveDelta = {
462
+ x: Math.abs(Math.round(event.pageX) - ((_triggerPointerDownPo = (_triggerPointerDownPo2 = triggerPointerDownPosRef.current) === null || _triggerPointerDownPo2 === void 0 ? void 0 : _triggerPointerDownPo2.x) !== null && _triggerPointerDownPo !== void 0 ? _triggerPointerDownPo : 0)),
463
+ y: Math.abs(Math.round(event.pageY) - ((_triggerPointerDownPo3 = (_triggerPointerDownPo4 = triggerPointerDownPosRef.current) === null || _triggerPointerDownPo4 === void 0 ? void 0 : _triggerPointerDownPo4.y) !== null && _triggerPointerDownPo3 !== void 0 ? _triggerPointerDownPo3 : 0))
464
+ };
465
+ };
466
+ const handlePointerUp = (event)=>{
467
+ // If the pointer hasn't moved by a certain threshold then we prevent selecting item on `pointerup`.
468
+ if (pointerMoveDelta.x <= 10 && pointerMoveDelta.y <= 10) event.preventDefault();
469
+ else // otherwise, if the event was outside the content, close.
470
+ if (!content.contains(event.target)) onOpenChange(false);
471
+ document.removeEventListener('pointermove', handlePointerMove);
472
+ triggerPointerDownPosRef.current = null;
473
+ };
474
+ if (triggerPointerDownPosRef.current !== null) {
475
+ document.addEventListener('pointermove', handlePointerMove);
476
+ document.addEventListener('pointerup', handlePointerUp, {
477
+ capture: true,
478
+ once: true
479
+ });
480
+ }
481
+ return ()=>{
482
+ document.removeEventListener('pointermove', handlePointerMove);
483
+ document.removeEventListener('pointerup', handlePointerUp, {
484
+ capture: true
485
+ });
486
+ };
487
+ }
488
+ }, [
489
+ content,
490
+ onOpenChange,
491
+ triggerPointerDownPosRef
492
+ ]);
493
+ $01b9c$useEffect(()=>{
494
+ const close = ()=>onOpenChange(false)
495
+ ;
496
+ window.addEventListener('blur', close);
497
+ window.addEventListener('resize', close);
498
+ return ()=>{
499
+ window.removeEventListener('blur', close);
500
+ window.removeEventListener('resize', close);
501
+ };
502
+ }, [
503
+ onOpenChange
504
+ ]);
505
+ const [searchRef, handleTypeaheadSearch] = $cc7e05a45900e73f$var$useTypeaheadSearch((search)=>{
506
+ const enabledItems = getItems().filter((item)=>!item.disabled
507
+ );
508
+ const currentItem = enabledItems.find((item)=>item.ref.current === document.activeElement
509
+ );
510
+ const nextItem = $cc7e05a45900e73f$var$findNextItem(enabledItems, search, currentItem);
511
+ if (nextItem) /**
512
+ * Imperative focus during keydown is risky so we prevent React's batching updates
513
+ * to avoid potential bugs. See: https://github.com/facebook/react/issues/20332
514
+ */ setTimeout(()=>nextItem.ref.current.focus()
515
+ );
516
+ });
517
+ const itemRefCallback = $01b9c$useCallback((node, value, disabled)=>{
518
+ const isFirstValidItem = !firstValidItemFoundRef.current && !disabled;
519
+ const isSelectedItem = context.value !== undefined && context.value === value;
520
+ if (isSelectedItem || isFirstValidItem) {
521
+ setSelectedItem(node);
522
+ if (isFirstValidItem) firstValidItemFoundRef.current = true;
523
+ }
524
+ }, [
525
+ context.value
526
+ ]);
527
+ const handleItemLeave = $01b9c$useCallback(()=>content === null || content === void 0 ? void 0 : content.focus()
528
+ , [
529
+ content
530
+ ]);
531
+ const itemTextRefCallback = $01b9c$useCallback((node, value, disabled)=>{
532
+ const isFirstValidItem = !firstValidItemFoundRef.current && !disabled;
533
+ const isSelectedItem = context.value !== undefined && context.value === value;
534
+ if (isSelectedItem || isFirstValidItem) setSelectedItemText(node);
535
+ }, [
536
+ context.value
537
+ ]);
538
+ return /*#__PURE__*/ $01b9c$createElement($cc7e05a45900e73f$var$SelectContentProvider, {
539
+ scope: __scopeSelect,
540
+ contentWrapper: contentWrapper,
541
+ content: content,
542
+ viewport: viewport,
543
+ onViewportChange: setViewport,
544
+ itemRefCallback: itemRefCallback,
545
+ selectedItem: selectedItem,
546
+ onItemLeave: handleItemLeave,
547
+ itemTextRefCallback: itemTextRefCallback,
548
+ selectedItemText: selectedItemText,
549
+ onScrollButtonChange: handleScrollButtonChange,
550
+ isPositioned: isPositioned,
551
+ shouldExpandOnScrollRef: shouldExpandOnScrollRef,
552
+ searchRef: searchRef
553
+ }, /*#__PURE__*/ $01b9c$createElement($01b9c$RemoveScroll, {
554
+ as: $01b9c$Slot,
555
+ allowPinchZoom: true
556
+ }, /*#__PURE__*/ $01b9c$createElement("div", {
557
+ ref: setContentWrapper,
558
+ style: {
559
+ display: 'flex',
560
+ flexDirection: 'column',
561
+ position: 'fixed',
562
+ zIndex: contentZIndex
563
+ }
564
+ }, /*#__PURE__*/ $01b9c$createElement($01b9c$FocusScope, {
565
+ asChild: true // we make sure we're not trapping once it's been closed
566
+ ,
567
+ trapped: context.open,
568
+ onMountAutoFocus: (event)=>{
569
+ // we prevent open autofocus because we manually focus the selected item
570
+ event.preventDefault();
571
+ },
572
+ onUnmountAutoFocus: $01b9c$composeEventHandlers(onCloseAutoFocus, (event)=>{
573
+ var _context$trigger;
574
+ (_context$trigger = context.trigger) === null || _context$trigger === void 0 || _context$trigger.focus({
575
+ preventScroll: true
576
+ });
577
+ event.preventDefault();
578
+ })
579
+ }, /*#__PURE__*/ $01b9c$createElement($01b9c$DismissableLayer, $01b9c$babelruntimehelpersesmextends({
580
+ role: "listbox",
581
+ id: context.contentId,
582
+ "data-state": context.open ? 'open' : 'closed',
583
+ dir: context.dir,
584
+ onContextMenu: (event)=>event.preventDefault()
585
+ }, contentProps, {
586
+ ref: composedRefs,
587
+ style: {
588
+ display: 'flex',
589
+ flexDirection: 'column',
590
+ // When we get the height of the content, it includes borders. If we were to set
591
+ // the height without having `boxSizing: 'border-box'` it would be too big.
592
+ boxSizing: 'border-box',
593
+ maxHeight: '100%',
594
+ outline: 'none',
595
+ ...contentProps.style
596
+ },
597
+ disableOutsidePointerEvents: true // When focus is trapped, a focusout event may still happen.
598
+ ,
599
+ onFocusOutside: (event)=>event.preventDefault()
600
+ ,
601
+ onDismiss: ()=>context.onOpenChange(false)
602
+ ,
603
+ onKeyDown: $01b9c$composeEventHandlers(contentProps.onKeyDown, (event)=>{
604
+ const isModifierKey = event.ctrlKey || event.altKey || event.metaKey; // select should not be navigated using tab key so we prevent it
605
+ if (event.key === 'Tab') event.preventDefault();
606
+ if (!isModifierKey && event.key.length === 1) handleTypeaheadSearch(event.key);
607
+ if ([
608
+ 'ArrowUp',
609
+ 'ArrowDown',
610
+ 'Home',
611
+ 'End'
612
+ ].includes(event.key)) {
613
+ const items = getItems().filter((item)=>!item.disabled
614
+ );
615
+ let candidateNodes = items.map((item)=>item.ref.current
616
+ );
617
+ if ([
618
+ 'ArrowUp',
619
+ 'End'
620
+ ].includes(event.key)) candidateNodes = candidateNodes.slice().reverse();
621
+ if ([
622
+ 'ArrowUp',
623
+ 'ArrowDown'
624
+ ].includes(event.key)) {
625
+ const currentElement = event.target;
626
+ const currentIndex = candidateNodes.indexOf(currentElement);
627
+ candidateNodes = candidateNodes.slice(currentIndex + 1);
628
+ }
629
+ /**
630
+ * Imperative focus during keydown is risky so we prevent React's batching updates
631
+ * to avoid potential bugs. See: https://github.com/facebook/react/issues/20332
632
+ */ setTimeout(()=>focusFirst(candidateNodes)
633
+ );
634
+ event.preventDefault();
635
+ }
636
+ })
637
+ }))))));
638
+ });
639
+ /* -------------------------------------------------------------------------------------------------
640
+ * SelectViewport
641
+ * -----------------------------------------------------------------------------------------------*/ const $cc7e05a45900e73f$var$VIEWPORT_NAME = 'SelectViewport';
642
+ const $cc7e05a45900e73f$export$9ed6e7b40248d36d = /*#__PURE__*/ $01b9c$forwardRef((props, forwardedRef)=>{
643
+ const { __scopeSelect: __scopeSelect , ...viewportProps } = props;
644
+ const contentContext = $cc7e05a45900e73f$var$useSelectContentContext($cc7e05a45900e73f$var$VIEWPORT_NAME, __scopeSelect);
645
+ const composedRefs = $01b9c$useComposedRefs(forwardedRef, contentContext.onViewportChange);
646
+ const prevScrollTopRef = $01b9c$useRef(0);
647
+ return /*#__PURE__*/ $01b9c$createElement($01b9c$Fragment, null, /*#__PURE__*/ $01b9c$createElement("style", {
648
+ dangerouslySetInnerHTML: {
649
+ __html: `[data-radix-select-viewport]{scrollbar-width:none;-ms-overflow-style:none;-webkit-overflow-scrolling:touch;}[data-radix-select-viewport]::-webkit-scrollbar{display:none}`
650
+ }
651
+ }), /*#__PURE__*/ $01b9c$createElement($cc7e05a45900e73f$var$Collection.Slot, {
652
+ scope: __scopeSelect
653
+ }, /*#__PURE__*/ $01b9c$createElement($01b9c$Primitive.div, $01b9c$babelruntimehelpersesmextends({
654
+ "data-radix-select-viewport": "",
655
+ role: "presentation"
656
+ }, viewportProps, {
657
+ ref: composedRefs,
658
+ style: {
659
+ // we use position: 'relative' here on the `viewport` so that when we call
660
+ // `selectedItem.offsetTop` in calculations, the offset is relative to the viewport
661
+ // (independent of the scrollUpButton).
662
+ position: 'relative',
663
+ flex: 1,
664
+ overflow: 'auto',
665
+ ...viewportProps.style
666
+ },
667
+ onScroll: $01b9c$composeEventHandlers(viewportProps.onScroll, (event)=>{
668
+ const viewport = event.currentTarget;
669
+ const { contentWrapper: contentWrapper , shouldExpandOnScrollRef: shouldExpandOnScrollRef } = contentContext;
670
+ if (shouldExpandOnScrollRef !== null && shouldExpandOnScrollRef !== void 0 && shouldExpandOnScrollRef.current && contentWrapper) {
671
+ const scrolledBy = Math.abs(prevScrollTopRef.current - viewport.scrollTop);
672
+ if (scrolledBy > 0) {
673
+ const availableHeight = window.innerHeight - $cc7e05a45900e73f$var$CONTENT_MARGIN * 2;
674
+ const cssMinHeight = parseFloat(contentWrapper.style.minHeight);
675
+ const cssHeight = parseFloat(contentWrapper.style.height);
676
+ const prevHeight = Math.max(cssMinHeight, cssHeight);
677
+ if (prevHeight < availableHeight) {
678
+ const nextHeight = prevHeight + scrolledBy;
679
+ const clampedNextHeight = Math.min(availableHeight, nextHeight);
680
+ const heightDiff = nextHeight - clampedNextHeight;
681
+ contentWrapper.style.height = clampedNextHeight + 'px';
682
+ if (contentWrapper.style.bottom === '0px') {
683
+ viewport.scrollTop = heightDiff > 0 ? heightDiff : 0; // ensure the content stays pinned to the bottom
684
+ contentWrapper.style.justifyContent = 'flex-end';
685
+ }
686
+ }
687
+ }
688
+ }
689
+ prevScrollTopRef.current = viewport.scrollTop;
690
+ })
691
+ }))));
692
+ });
693
+ /*#__PURE__*/ Object.assign($cc7e05a45900e73f$export$9ed6e7b40248d36d, {
694
+ displayName: $cc7e05a45900e73f$var$VIEWPORT_NAME
695
+ });
696
+ /* -------------------------------------------------------------------------------------------------
697
+ * SelectGroup
698
+ * -----------------------------------------------------------------------------------------------*/ const $cc7e05a45900e73f$var$GROUP_NAME = 'SelectGroup';
699
+ const [$cc7e05a45900e73f$var$SelectGroupContextProvider, $cc7e05a45900e73f$var$useSelectGroupContext] = $cc7e05a45900e73f$var$createSelectContext($cc7e05a45900e73f$var$GROUP_NAME);
700
+ const $cc7e05a45900e73f$export$ee25a334c55de1f4 = /*#__PURE__*/ $01b9c$forwardRef((props, forwardedRef)=>{
701
+ const { __scopeSelect: __scopeSelect , ...groupProps } = props;
702
+ const groupId = $01b9c$useId();
703
+ return /*#__PURE__*/ $01b9c$createElement($cc7e05a45900e73f$var$SelectGroupContextProvider, {
704
+ scope: __scopeSelect,
705
+ id: groupId
706
+ }, /*#__PURE__*/ $01b9c$createElement($01b9c$Primitive.div, $01b9c$babelruntimehelpersesmextends({
707
+ role: "group",
708
+ "aria-labelledby": groupId
709
+ }, groupProps, {
710
+ ref: forwardedRef
711
+ })));
712
+ });
713
+ /*#__PURE__*/ Object.assign($cc7e05a45900e73f$export$ee25a334c55de1f4, {
714
+ displayName: $cc7e05a45900e73f$var$GROUP_NAME
715
+ });
716
+ /* -------------------------------------------------------------------------------------------------
717
+ * SelectLabel
718
+ * -----------------------------------------------------------------------------------------------*/ const $cc7e05a45900e73f$var$LABEL_NAME = 'SelectLabel';
719
+ const $cc7e05a45900e73f$export$f67338d29bd972f8 = /*#__PURE__*/ $01b9c$forwardRef((props, forwardedRef)=>{
720
+ const { __scopeSelect: __scopeSelect , ...labelProps } = props;
721
+ const groupContext = $cc7e05a45900e73f$var$useSelectGroupContext($cc7e05a45900e73f$var$LABEL_NAME, __scopeSelect);
722
+ return /*#__PURE__*/ $01b9c$createElement($01b9c$Primitive.div, $01b9c$babelruntimehelpersesmextends({
723
+ id: groupContext.id
724
+ }, labelProps, {
725
+ ref: forwardedRef
726
+ }));
727
+ });
728
+ /*#__PURE__*/ Object.assign($cc7e05a45900e73f$export$f67338d29bd972f8, {
729
+ displayName: $cc7e05a45900e73f$var$LABEL_NAME
730
+ });
731
+ /* -------------------------------------------------------------------------------------------------
732
+ * SelectItem
733
+ * -----------------------------------------------------------------------------------------------*/ const $cc7e05a45900e73f$var$ITEM_NAME = 'SelectItem';
734
+ const [$cc7e05a45900e73f$var$SelectItemContextProvider, $cc7e05a45900e73f$var$useSelectItemContext] = $cc7e05a45900e73f$var$createSelectContext($cc7e05a45900e73f$var$ITEM_NAME);
735
+ const $cc7e05a45900e73f$export$13ef48a934230896 = /*#__PURE__*/ $01b9c$forwardRef((props, forwardedRef)=>{
736
+ const { __scopeSelect: __scopeSelect , value: value , disabled: disabled = false , textValue: textValueProp , ...itemProps } = props;
737
+ const context = $cc7e05a45900e73f$var$useSelectContext($cc7e05a45900e73f$var$ITEM_NAME, __scopeSelect);
738
+ const contentContext = $cc7e05a45900e73f$var$useSelectContentContext($cc7e05a45900e73f$var$ITEM_NAME, __scopeSelect);
739
+ const isSelected = context.value === value;
740
+ const [textValue, setTextValue] = $01b9c$useState(textValueProp !== null && textValueProp !== void 0 ? textValueProp : '');
741
+ const [isFocused, setIsFocused] = $01b9c$useState(false);
742
+ const composedRefs = $01b9c$useComposedRefs(forwardedRef, (node)=>{
743
+ var _contentContext$itemR;
744
+ return (_contentContext$itemR = contentContext.itemRefCallback) === null || _contentContext$itemR === void 0 ? void 0 : _contentContext$itemR.call(contentContext, node, value, disabled);
745
+ });
746
+ const textId = $01b9c$useId();
747
+ const handleSelect = ()=>{
748
+ if (!disabled) {
749
+ context.onValueChange(value);
750
+ context.onOpenChange(false);
751
+ }
752
+ };
753
+ return /*#__PURE__*/ $01b9c$createElement($cc7e05a45900e73f$var$SelectItemContextProvider, {
754
+ scope: __scopeSelect,
755
+ value: value,
756
+ disabled: disabled,
757
+ textId: textId,
758
+ isSelected: isSelected,
759
+ onItemTextChange: $01b9c$useCallback((node)=>{
760
+ setTextValue((prevTextValue)=>{
761
+ var _node$textContent;
762
+ return prevTextValue || ((_node$textContent = node === null || node === void 0 ? void 0 : node.textContent) !== null && _node$textContent !== void 0 ? _node$textContent : '').trim();
763
+ });
764
+ }, [])
765
+ }, /*#__PURE__*/ $01b9c$createElement($cc7e05a45900e73f$var$Collection.ItemSlot, {
766
+ scope: __scopeSelect,
767
+ value: value,
768
+ disabled: disabled,
769
+ textValue: textValue
770
+ }, /*#__PURE__*/ $01b9c$createElement($01b9c$Primitive.div, $01b9c$babelruntimehelpersesmextends({
771
+ role: "option",
772
+ "aria-labelledby": textId,
773
+ "data-highlighted": isFocused ? '' : undefined // `isFocused` caveat fixes stuttering in VoiceOver
774
+ ,
775
+ "aria-selected": isSelected && isFocused,
776
+ "data-state": isSelected ? 'checked' : 'unchecked',
777
+ "aria-disabled": disabled || undefined,
778
+ "data-disabled": disabled ? '' : undefined,
779
+ tabIndex: disabled ? undefined : -1
780
+ }, itemProps, {
781
+ ref: composedRefs,
782
+ onFocus: $01b9c$composeEventHandlers(itemProps.onFocus, ()=>setIsFocused(true)
783
+ ),
784
+ onBlur: $01b9c$composeEventHandlers(itemProps.onBlur, ()=>setIsFocused(false)
785
+ ),
786
+ onPointerUp: $01b9c$composeEventHandlers(itemProps.onPointerUp, handleSelect),
787
+ onPointerMove: $01b9c$composeEventHandlers(itemProps.onPointerMove, (event)=>{
788
+ if (disabled) {
789
+ var _contentContext$onIte;
790
+ (_contentContext$onIte = contentContext.onItemLeave) === null || _contentContext$onIte === void 0 || _contentContext$onIte.call(contentContext);
791
+ } else // even though safari doesn't support this option, it's acceptable
792
+ // as it only means it might scroll a few pixels when using the pointer.
793
+ event.currentTarget.focus({
794
+ preventScroll: true
795
+ });
796
+ }),
797
+ onPointerLeave: $01b9c$composeEventHandlers(itemProps.onPointerLeave, (event)=>{
798
+ if (event.currentTarget === document.activeElement) {
799
+ var _contentContext$onIte2;
800
+ (_contentContext$onIte2 = contentContext.onItemLeave) === null || _contentContext$onIte2 === void 0 || _contentContext$onIte2.call(contentContext);
801
+ }
802
+ }),
803
+ onKeyDown: $01b9c$composeEventHandlers(itemProps.onKeyDown, (event)=>{
804
+ var _contentContext$searc;
805
+ const isTypingAhead = ((_contentContext$searc = contentContext.searchRef) === null || _contentContext$searc === void 0 ? void 0 : _contentContext$searc.current) !== '';
806
+ if (isTypingAhead && event.key === ' ') return;
807
+ if ($cc7e05a45900e73f$var$SELECTION_KEYS.includes(event.key)) handleSelect(); // prevent page scroll if using the space key to select an item
808
+ if (event.key === ' ') event.preventDefault();
809
+ })
810
+ }))));
811
+ });
812
+ /*#__PURE__*/ Object.assign($cc7e05a45900e73f$export$13ef48a934230896, {
813
+ displayName: $cc7e05a45900e73f$var$ITEM_NAME
814
+ });
815
+ /* -------------------------------------------------------------------------------------------------
816
+ * SelectItemText
817
+ * -----------------------------------------------------------------------------------------------*/ const $cc7e05a45900e73f$var$ITEM_TEXT_NAME = 'SelectItemText';
818
+ const $cc7e05a45900e73f$export$3572fb0fb821ff49 = /*#__PURE__*/ $01b9c$forwardRef((props, forwardedRef)=>{
819
+ // We ignore `className` and `style` as this part shouldn't be styled.
820
+ const { __scopeSelect: __scopeSelect , className: className , style: style , ...itemTextProps } = props;
821
+ const context = $cc7e05a45900e73f$var$useSelectContext($cc7e05a45900e73f$var$ITEM_TEXT_NAME, __scopeSelect);
822
+ const contentContext = $cc7e05a45900e73f$var$useSelectContentContext($cc7e05a45900e73f$var$ITEM_TEXT_NAME, __scopeSelect);
823
+ const itemContext = $cc7e05a45900e73f$var$useSelectItemContext($cc7e05a45900e73f$var$ITEM_TEXT_NAME, __scopeSelect);
824
+ const nativeOptionsContext = $cc7e05a45900e73f$var$useSelectNativeOptionsContext($cc7e05a45900e73f$var$ITEM_TEXT_NAME, __scopeSelect);
825
+ const [itemTextNode, setItemTextNode] = $01b9c$useState(null);
826
+ const composedRefs = $01b9c$useComposedRefs(forwardedRef, (node)=>setItemTextNode(node)
827
+ , itemContext.onItemTextChange, (node)=>{
828
+ var _contentContext$itemT;
829
+ return (_contentContext$itemT = contentContext.itemTextRefCallback) === null || _contentContext$itemT === void 0 ? void 0 : _contentContext$itemT.call(contentContext, node, itemContext.value, itemContext.disabled);
830
+ });
831
+ const textContent = itemTextNode === null || itemTextNode === void 0 ? void 0 : itemTextNode.textContent;
832
+ const nativeOption = $01b9c$useMemo(()=>/*#__PURE__*/ $01b9c$createElement("option", {
833
+ key: itemContext.value,
834
+ value: itemContext.value,
835
+ disabled: itemContext.disabled
836
+ }, textContent)
837
+ , [
838
+ itemContext.disabled,
839
+ itemContext.value,
840
+ textContent
841
+ ]);
842
+ const { onNativeOptionAdd: onNativeOptionAdd , onNativeOptionRemove: onNativeOptionRemove } = nativeOptionsContext;
843
+ $01b9c$useLayoutEffect(()=>{
844
+ onNativeOptionAdd(nativeOption);
845
+ return ()=>onNativeOptionRemove(nativeOption)
846
+ ;
847
+ }, [
848
+ onNativeOptionAdd,
849
+ onNativeOptionRemove,
850
+ nativeOption
851
+ ]);
852
+ return /*#__PURE__*/ $01b9c$createElement($01b9c$Fragment, null, /*#__PURE__*/ $01b9c$createElement($01b9c$Primitive.span, $01b9c$babelruntimehelpersesmextends({
853
+ id: itemContext.textId
854
+ }, itemTextProps, {
855
+ ref: composedRefs
856
+ })), itemContext.isSelected && context.valueNode && !context.valueNodeHasChildren ? /*#__PURE__*/ $01b9c$createPortal(itemTextProps.children, context.valueNode) : null);
857
+ });
858
+ /*#__PURE__*/ Object.assign($cc7e05a45900e73f$export$3572fb0fb821ff49, {
859
+ displayName: $cc7e05a45900e73f$var$ITEM_TEXT_NAME
860
+ });
861
+ /* -------------------------------------------------------------------------------------------------
862
+ * SelectItemIndicator
863
+ * -----------------------------------------------------------------------------------------------*/ const $cc7e05a45900e73f$var$ITEM_INDICATOR_NAME = 'SelectItemIndicator';
864
+ const $cc7e05a45900e73f$export$6b9198de19accfe6 = /*#__PURE__*/ $01b9c$forwardRef((props, forwardedRef)=>{
865
+ const { __scopeSelect: __scopeSelect , ...itemIndicatorProps } = props;
866
+ const itemContext = $cc7e05a45900e73f$var$useSelectItemContext($cc7e05a45900e73f$var$ITEM_INDICATOR_NAME, __scopeSelect);
867
+ return itemContext.isSelected ? /*#__PURE__*/ $01b9c$createElement($01b9c$Primitive.span, $01b9c$babelruntimehelpersesmextends({
868
+ "aria-hidden": true
869
+ }, itemIndicatorProps, {
870
+ ref: forwardedRef
871
+ })) : null;
872
+ });
873
+ /*#__PURE__*/ Object.assign($cc7e05a45900e73f$export$6b9198de19accfe6, {
874
+ displayName: $cc7e05a45900e73f$var$ITEM_INDICATOR_NAME
875
+ });
876
+ /* -------------------------------------------------------------------------------------------------
877
+ * SelectScrollUpButton
878
+ * -----------------------------------------------------------------------------------------------*/ const $cc7e05a45900e73f$var$SCROLL_UP_BUTTON_NAME = 'SelectScrollUpButton';
879
+ const $cc7e05a45900e73f$export$d8117927658af6d7 = /*#__PURE__*/ $01b9c$forwardRef((props, forwardedRef)=>{
880
+ const contentContext = $cc7e05a45900e73f$var$useSelectContentContext($cc7e05a45900e73f$var$SCROLL_UP_BUTTON_NAME, props.__scopeSelect);
881
+ const [canScrollUp1, setCanScrollUp] = $01b9c$useState(false);
882
+ const composedRefs = $01b9c$useComposedRefs(forwardedRef, contentContext.onScrollButtonChange);
883
+ $01b9c$useLayoutEffect(()=>{
884
+ if (contentContext.viewport && contentContext.isPositioned) {
885
+ const viewport = contentContext.viewport;
886
+ function handleScroll() {
887
+ const canScrollUp = viewport.scrollTop > 0;
888
+ setCanScrollUp(canScrollUp);
889
+ }
890
+ handleScroll();
891
+ viewport.addEventListener('scroll', handleScroll);
892
+ return ()=>viewport.removeEventListener('scroll', handleScroll)
893
+ ;
894
+ }
895
+ }, [
896
+ contentContext.viewport,
897
+ contentContext.isPositioned
898
+ ]);
899
+ return canScrollUp1 ? /*#__PURE__*/ $01b9c$createElement($cc7e05a45900e73f$var$SelectScrollButtonImpl, $01b9c$babelruntimehelpersesmextends({}, props, {
900
+ ref: composedRefs,
901
+ onAutoScroll: ()=>{
902
+ const { viewport: viewport , selectedItem: selectedItem } = contentContext;
903
+ if (viewport && selectedItem) viewport.scrollTop = viewport.scrollTop - selectedItem.offsetHeight;
904
+ }
905
+ })) : null;
906
+ });
907
+ /*#__PURE__*/ Object.assign($cc7e05a45900e73f$export$d8117927658af6d7, {
908
+ displayName: $cc7e05a45900e73f$var$SCROLL_UP_BUTTON_NAME
909
+ });
910
+ /* -------------------------------------------------------------------------------------------------
911
+ * SelectScrollDownButton
912
+ * -----------------------------------------------------------------------------------------------*/ const $cc7e05a45900e73f$var$SCROLL_DOWN_BUTTON_NAME = 'SelectScrollDownButton';
913
+ const $cc7e05a45900e73f$export$ff951e476c12189 = /*#__PURE__*/ $01b9c$forwardRef((props, forwardedRef)=>{
914
+ const contentContext = $cc7e05a45900e73f$var$useSelectContentContext($cc7e05a45900e73f$var$SCROLL_DOWN_BUTTON_NAME, props.__scopeSelect);
915
+ const [canScrollDown1, setCanScrollDown] = $01b9c$useState(false);
916
+ const composedRefs = $01b9c$useComposedRefs(forwardedRef, contentContext.onScrollButtonChange);
917
+ $01b9c$useLayoutEffect(()=>{
918
+ if (contentContext.viewport && contentContext.isPositioned) {
919
+ const viewport = contentContext.viewport;
920
+ function handleScroll() {
921
+ const maxScroll = viewport.scrollHeight - viewport.clientHeight; // we use Math.ceil here because if the UI is zoomed-in
922
+ // `scrollTop` is not always reported as an integer
923
+ const canScrollDown = Math.ceil(viewport.scrollTop) < maxScroll;
924
+ setCanScrollDown(canScrollDown);
925
+ }
926
+ handleScroll();
927
+ viewport.addEventListener('scroll', handleScroll);
928
+ return ()=>viewport.removeEventListener('scroll', handleScroll)
929
+ ;
930
+ }
931
+ }, [
932
+ contentContext.viewport,
933
+ contentContext.isPositioned
934
+ ]);
935
+ return canScrollDown1 ? /*#__PURE__*/ $01b9c$createElement($cc7e05a45900e73f$var$SelectScrollButtonImpl, $01b9c$babelruntimehelpersesmextends({}, props, {
936
+ ref: composedRefs,
937
+ onAutoScroll: ()=>{
938
+ const { viewport: viewport , selectedItem: selectedItem } = contentContext;
939
+ if (viewport && selectedItem) viewport.scrollTop = viewport.scrollTop + selectedItem.offsetHeight;
940
+ }
941
+ })) : null;
942
+ });
943
+ /*#__PURE__*/ Object.assign($cc7e05a45900e73f$export$ff951e476c12189, {
944
+ displayName: $cc7e05a45900e73f$var$SCROLL_DOWN_BUTTON_NAME
945
+ });
946
+ const $cc7e05a45900e73f$var$SelectScrollButtonImpl = /*#__PURE__*/ $01b9c$forwardRef((props, forwardedRef)=>{
947
+ const { __scopeSelect: __scopeSelect , onAutoScroll: onAutoScroll , ...scrollIndicatorProps } = props;
948
+ const contentContext = $cc7e05a45900e73f$var$useSelectContentContext('SelectScrollButton', __scopeSelect);
949
+ const autoScrollTimerRef = $01b9c$useRef(null);
950
+ const getItems = $cc7e05a45900e73f$var$useCollection(__scopeSelect);
951
+ const clearAutoScrollTimer = $01b9c$useCallback(()=>{
952
+ if (autoScrollTimerRef.current !== null) {
953
+ window.clearInterval(autoScrollTimerRef.current);
954
+ autoScrollTimerRef.current = null;
955
+ }
956
+ }, []);
957
+ $01b9c$useEffect(()=>{
958
+ return ()=>clearAutoScrollTimer()
959
+ ;
960
+ }, [
961
+ clearAutoScrollTimer
962
+ ]); // When the viewport becomes scrollable on either side, the relevant scroll button will mount.
963
+ // Because it is part of the normal flow, it will push down (top button) or shrink (bottom button)
964
+ // the viewport, potentially causing the active item to now be partially out of view.
965
+ // We re-run the `scrollIntoView` logic to make sure it stays within the viewport.
966
+ $01b9c$useLayoutEffect(()=>{
967
+ var _activeItem$ref$curre;
968
+ const activeItem = getItems().find((item)=>item.ref.current === document.activeElement
969
+ );
970
+ activeItem === null || activeItem === void 0 || (_activeItem$ref$curre = activeItem.ref.current) === null || _activeItem$ref$curre === void 0 || _activeItem$ref$curre.scrollIntoView({
971
+ block: 'nearest'
972
+ });
973
+ }, [
974
+ getItems
975
+ ]);
976
+ return /*#__PURE__*/ $01b9c$createElement($01b9c$Primitive.div, $01b9c$babelruntimehelpersesmextends({
977
+ "aria-hidden": true
978
+ }, scrollIndicatorProps, {
979
+ ref: forwardedRef,
980
+ style: {
981
+ flexShrink: 0,
982
+ ...scrollIndicatorProps.style
983
+ },
984
+ onPointerMove: $01b9c$composeEventHandlers(scrollIndicatorProps.onPointerMove, ()=>{
985
+ var _contentContext$onIte3;
986
+ (_contentContext$onIte3 = contentContext.onItemLeave) === null || _contentContext$onIte3 === void 0 || _contentContext$onIte3.call(contentContext);
987
+ if (autoScrollTimerRef.current === null) autoScrollTimerRef.current = window.setInterval(onAutoScroll, 50);
988
+ }),
989
+ onPointerLeave: $01b9c$composeEventHandlers(scrollIndicatorProps.onPointerLeave, ()=>{
990
+ clearAutoScrollTimer();
991
+ })
992
+ }));
993
+ });
994
+ /* -------------------------------------------------------------------------------------------------
995
+ * SelectSeparator
996
+ * -----------------------------------------------------------------------------------------------*/ const $cc7e05a45900e73f$var$SEPARATOR_NAME = 'SelectSeparator';
997
+ const $cc7e05a45900e73f$export$eba4b1df07cb1d3 = /*#__PURE__*/ $01b9c$forwardRef((props, forwardedRef)=>{
998
+ const { __scopeSelect: __scopeSelect , ...separatorProps } = props;
999
+ return /*#__PURE__*/ $01b9c$createElement($01b9c$Primitive.div, $01b9c$babelruntimehelpersesmextends({
1000
+ "aria-hidden": true
1001
+ }, separatorProps, {
1002
+ ref: forwardedRef
1003
+ }));
1004
+ });
1005
+ /*#__PURE__*/ Object.assign($cc7e05a45900e73f$export$eba4b1df07cb1d3, {
1006
+ displayName: $cc7e05a45900e73f$var$SEPARATOR_NAME
1007
+ });
1008
+ /* -----------------------------------------------------------------------------------------------*/ const $cc7e05a45900e73f$var$BubbleSelect = /*#__PURE__*/ $01b9c$forwardRef((props, forwardedRef)=>{
1009
+ const { value: value , ...selectProps } = props;
1010
+ const ref = $01b9c$useRef(null);
1011
+ const composedRefs = $01b9c$useComposedRefs(forwardedRef, ref);
1012
+ const prevValue = $01b9c$usePrevious(value); // Bubble value change to parents (e.g form change event)
1013
+ $01b9c$useEffect(()=>{
1014
+ const select = ref.current;
1015
+ const selectProto = window.HTMLSelectElement.prototype;
1016
+ const descriptor = Object.getOwnPropertyDescriptor(selectProto, 'value');
1017
+ const setValue = descriptor.set;
1018
+ if (prevValue !== value && setValue) {
1019
+ const event = new Event('change', {
1020
+ bubbles: true
1021
+ });
1022
+ setValue.call(select, value);
1023
+ select.dispatchEvent(event);
1024
+ }
1025
+ }, [
1026
+ prevValue,
1027
+ value
1028
+ ]);
1029
+ /**
1030
+ * We purposefully use a `select` here to support form autofill as much
1031
+ * as possible.
1032
+ *
1033
+ * We purposefully do not add the `value` attribute here to allow the value
1034
+ * to be set programatically and bubble to any parent form `onChange` event.
1035
+ * Adding the `value` will cause React to consider the programatic
1036
+ * dispatch a duplicate and it will get swallowed.
1037
+ *
1038
+ * We use `VisuallyHidden` rather than `display: "none"` because Safari autofill
1039
+ * won't work otherwise.
1040
+ */ return /*#__PURE__*/ $01b9c$createElement($01b9c$VisuallyHidden, {
1041
+ asChild: true
1042
+ }, /*#__PURE__*/ $01b9c$createElement("select", $01b9c$babelruntimehelpersesmextends({}, selectProps, {
1043
+ ref: composedRefs,
1044
+ defaultValue: value
1045
+ })));
1046
+ });
1047
+ $cc7e05a45900e73f$var$BubbleSelect.displayName = 'BubbleSelect';
1048
+ function $cc7e05a45900e73f$var$useTypeaheadSearch(onSearchChange) {
1049
+ const handleSearchChange = $01b9c$useCallbackRef(onSearchChange);
1050
+ const searchRef = $01b9c$useRef('');
1051
+ const timerRef = $01b9c$useRef(0);
1052
+ const handleTypeaheadSearch = $01b9c$useCallback((key)=>{
1053
+ const search = searchRef.current + key;
1054
+ handleSearchChange(search);
1055
+ (function updateSearch(value) {
1056
+ searchRef.current = value;
1057
+ window.clearTimeout(timerRef.current); // Reset `searchRef` 1 second after it was last updated
1058
+ if (value !== '') timerRef.current = window.setTimeout(()=>updateSearch('')
1059
+ , 1000);
1060
+ })(search);
1061
+ }, [
1062
+ handleSearchChange
1063
+ ]);
1064
+ const resetTypeahead = $01b9c$useCallback(()=>{
1065
+ searchRef.current = '';
1066
+ window.clearTimeout(timerRef.current);
1067
+ }, []);
1068
+ $01b9c$useEffect(()=>{
1069
+ return ()=>window.clearTimeout(timerRef.current)
1070
+ ;
1071
+ }, []);
1072
+ return [
1073
+ searchRef,
1074
+ handleTypeaheadSearch,
1075
+ resetTypeahead
1076
+ ];
1077
+ }
1078
+ /**
1079
+ * This is the "meat" of the typeahead matching logic. It takes in a list of items,
1080
+ * the search and the current item, and returns the next item (or `undefined`).
1081
+ *
1082
+ * We normalize the search because if a user has repeatedly pressed a character,
1083
+ * we want the exact same behavior as if we only had that one character
1084
+ * (ie. cycle through items starting with that character)
1085
+ *
1086
+ * We also reorder the items by wrapping the array around the current item.
1087
+ * This is so we always look forward from the current item, and picking the first
1088
+ * item will always be the correct one.
1089
+ *
1090
+ * Finally, if the normalized search is exactly one character, we exclude the
1091
+ * current item from the values because otherwise it would be the first to match always
1092
+ * and focus would never move. This is as opposed to the regular case, where we
1093
+ * don't want focus to move if the current item still matches.
1094
+ */ function $cc7e05a45900e73f$var$findNextItem(items, search, currentItem) {
1095
+ const isRepeated = search.length > 1 && Array.from(search).every((char)=>char === search[0]
1096
+ );
1097
+ const normalizedSearch = isRepeated ? search[0] : search;
1098
+ const currentItemIndex = currentItem ? items.indexOf(currentItem) : -1;
1099
+ let wrappedItems = $cc7e05a45900e73f$var$wrapArray(items, Math.max(currentItemIndex, 0));
1100
+ const excludeCurrentItem = normalizedSearch.length === 1;
1101
+ if (excludeCurrentItem) wrappedItems = wrappedItems.filter((v)=>v !== currentItem
1102
+ );
1103
+ const nextItem = wrappedItems.find((item)=>item.textValue.toLowerCase().startsWith(normalizedSearch.toLowerCase())
1104
+ );
1105
+ return nextItem !== currentItem ? nextItem : undefined;
1106
+ }
1107
+ /**
1108
+ * Wraps an array around itself at a given start index
1109
+ * Example: `wrapArray(['a', 'b', 'c', 'd'], 2) === ['c', 'd', 'a', 'b']`
1110
+ */ function $cc7e05a45900e73f$var$wrapArray(array, startIndex) {
1111
+ return array.map((_, index)=>array[(startIndex + index) % array.length]
1112
+ );
1113
+ }
1114
+ const $cc7e05a45900e73f$export$be92b6f5f03c0fe9 = $cc7e05a45900e73f$export$ef9b1a59e592288f;
1115
+ const $cc7e05a45900e73f$export$41fb9f06171c75f4 = $cc7e05a45900e73f$export$3ac1e88a1c0b9f1;
1116
+ const $cc7e05a45900e73f$export$4c8d1a57a761ef94 = $cc7e05a45900e73f$export$e288731fd71264f0;
1117
+ const $cc7e05a45900e73f$export$f04a61298a47a40f = $cc7e05a45900e73f$export$99b400cabb58c515;
1118
+ const $cc7e05a45900e73f$export$602eac185826482c = $cc7e05a45900e73f$export$b2af6c9944296213;
1119
+ const $cc7e05a45900e73f$export$7c6e2c02157bb7d2 = $cc7e05a45900e73f$export$c973a4b3cb86a03d;
1120
+ const $cc7e05a45900e73f$export$d5c6c08dc2d3ca7 = $cc7e05a45900e73f$export$9ed6e7b40248d36d;
1121
+ const $cc7e05a45900e73f$export$eb2fcfdbd7ba97d4 = $cc7e05a45900e73f$export$ee25a334c55de1f4;
1122
+ const $cc7e05a45900e73f$export$b04be29aa201d4f5 = $cc7e05a45900e73f$export$f67338d29bd972f8;
1123
+ const $cc7e05a45900e73f$export$6d08773d2e66f8f2 = $cc7e05a45900e73f$export$13ef48a934230896;
1124
+ const $cc7e05a45900e73f$export$d6e5bf9c43ea9319 = $cc7e05a45900e73f$export$3572fb0fb821ff49;
1125
+ const $cc7e05a45900e73f$export$c3468e2714d175fa = $cc7e05a45900e73f$export$6b9198de19accfe6;
1126
+ const $cc7e05a45900e73f$export$2f60d3ec9ad468f2 = $cc7e05a45900e73f$export$d8117927658af6d7;
1127
+ const $cc7e05a45900e73f$export$bf1aedc3039c8d63 = $cc7e05a45900e73f$export$ff951e476c12189;
1128
+ const $cc7e05a45900e73f$export$1ff3c3f08ae963c0 = $cc7e05a45900e73f$export$eba4b1df07cb1d3;
1129
+
1130
+
1131
+
1132
+
1133
+ export {$cc7e05a45900e73f$export$286727a75dc039bd as createSelectScope, $cc7e05a45900e73f$export$ef9b1a59e592288f as Select, $cc7e05a45900e73f$export$3ac1e88a1c0b9f1 as SelectTrigger, $cc7e05a45900e73f$export$e288731fd71264f0 as SelectValue, $cc7e05a45900e73f$export$99b400cabb58c515 as SelectIcon, $cc7e05a45900e73f$export$b2af6c9944296213 as SelectPortal, $cc7e05a45900e73f$export$c973a4b3cb86a03d as SelectContent, $cc7e05a45900e73f$export$9ed6e7b40248d36d as SelectViewport, $cc7e05a45900e73f$export$ee25a334c55de1f4 as SelectGroup, $cc7e05a45900e73f$export$f67338d29bd972f8 as SelectLabel, $cc7e05a45900e73f$export$13ef48a934230896 as SelectItem, $cc7e05a45900e73f$export$3572fb0fb821ff49 as SelectItemText, $cc7e05a45900e73f$export$6b9198de19accfe6 as SelectItemIndicator, $cc7e05a45900e73f$export$d8117927658af6d7 as SelectScrollUpButton, $cc7e05a45900e73f$export$ff951e476c12189 as SelectScrollDownButton, $cc7e05a45900e73f$export$eba4b1df07cb1d3 as SelectSeparator, $cc7e05a45900e73f$export$be92b6f5f03c0fe9 as Root, $cc7e05a45900e73f$export$41fb9f06171c75f4 as Trigger, $cc7e05a45900e73f$export$4c8d1a57a761ef94 as Value, $cc7e05a45900e73f$export$f04a61298a47a40f as Icon, $cc7e05a45900e73f$export$602eac185826482c as Portal, $cc7e05a45900e73f$export$7c6e2c02157bb7d2 as Content, $cc7e05a45900e73f$export$d5c6c08dc2d3ca7 as Viewport, $cc7e05a45900e73f$export$eb2fcfdbd7ba97d4 as Group, $cc7e05a45900e73f$export$b04be29aa201d4f5 as Label, $cc7e05a45900e73f$export$6d08773d2e66f8f2 as Item, $cc7e05a45900e73f$export$d6e5bf9c43ea9319 as ItemText, $cc7e05a45900e73f$export$c3468e2714d175fa as ItemIndicator, $cc7e05a45900e73f$export$2f60d3ec9ad468f2 as ScrollUpButton, $cc7e05a45900e73f$export$bf1aedc3039c8d63 as ScrollDownButton, $cc7e05a45900e73f$export$1ff3c3f08ae963c0 as Separator};
4
1134
  //# sourceMappingURL=index.module.js.map