@radix-ui/react-select 0.1.2-rc.5 → 0.1.2-rc.50

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