@radix-ui/react-select 0.1.2-rc.11 → 0.1.2-rc.12

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