downshift
Version:
🏎 A set of primitives to build simple, flexible, WAI-ARIA compliant React autocomplete, combobox or select dropdown components.
1 lines • 50.4 kB
JavaScript
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("react")):"function"==typeof define&&define.amd?define(["exports","react"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).Downshift={},e.React)}(this,(function(e,t){"use strict";function n(e,t){if(null==e)return{};var n={};for(var i in e)if({}.hasOwnProperty.call(e,i)){if(-1!==t.indexOf(i))continue;n[i]=e[i]}return n}function i(){return i=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var i in n)({}).hasOwnProperty.call(n,i)&&(e[i]=n[i])}return e},i.apply(null,arguments)}function o(e,t){return o=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},o(e,t)}function r(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var u,s,l,a,c={exports:{}};c.exports=function(){if(a)return l;a=1;var e=s?u:(s=1,u="SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED");function t(){}function n(){}return n.resetWarningCache=t,l=function(){function i(t,n,i,o,r,u){if(u!==e){var s=new Error("Calling PropTypes validators directly is not supported by the `prop-types` package. Use PropTypes.checkPropTypes() to call them. Read more at http://fb.me/use-check-prop-types");throw s.name="Invariant Violation",s}}function o(){return i}i.isRequired=i;var r={array:i,bigint:i,bool:i,func:i,number:i,object:i,string:i,symbol:i,any:i,arrayOf:o,element:i,elementType:i,instanceOf:o,node:i,objectOf:o,oneOf:o,oneOfType:o,shape:o,exact:o,checkPropTypes:n,resetWarningCache:t};return r.PropTypes=r,r}}()();var d,p=r(c.exports),f={};!function(){if(d)return f;d=1;var e,t=Symbol.for("react.element"),n=Symbol.for("react.portal"),i=Symbol.for("react.fragment"),o=Symbol.for("react.strict_mode"),r=Symbol.for("react.profiler"),u=Symbol.for("react.provider"),s=Symbol.for("react.context"),l=Symbol.for("react.server_context"),a=Symbol.for("react.forward_ref"),c=Symbol.for("react.suspense"),p=Symbol.for("react.suspense_list"),h=Symbol.for("react.memo"),g=Symbol.for("react.lazy"),m=Symbol.for("react.offscreen");function I(e){if("object"==typeof e&&null!==e){var d=e.$$typeof;switch(d){case t:switch(e=e.type){case i:case r:case o:case c:case p:return e;default:switch(e=e&&e.$$typeof){case l:case s:case a:case g:case h:case u:return e;default:return d}}case n:return d}}}e=Symbol.for("react.module.reference"),f.ContextConsumer=s,f.ContextProvider=u,f.Element=t,f.ForwardRef=a,f.Fragment=i,f.Lazy=g,f.Memo=h,f.Portal=n,f.Profiler=r,f.StrictMode=o,f.Suspense=c,f.SuspenseList=p,f.isAsyncMode=function(){return!1},f.isConcurrentMode=function(){return!1},f.isContextConsumer=function(e){return I(e)===s},f.isContextProvider=function(e){return I(e)===u},f.isElement=function(e){return"object"==typeof e&&null!==e&&e.$$typeof===t},f.isForwardRef=function(e){return I(e)===a},f.isFragment=function(e){return I(e)===i},f.isLazy=function(e){return I(e)===g},f.isMemo=function(e){return I(e)===h},f.isPortal=function(e){return I(e)===n},f.isProfiler=function(e){return I(e)===r},f.isStrictMode=function(e){return I(e)===o},f.isSuspense=function(e){return I(e)===c},f.isSuspenseList=function(e){return I(e)===p},f.isValidElementType=function(t){return"string"==typeof t||"function"==typeof t||t===i||t===r||t===o||t===c||t===p||t===m||"object"==typeof t&&null!==t&&(t.$$typeof===g||t.$$typeof===h||t.$$typeof===u||t.$$typeof===s||t.$$typeof===a||t.$$typeof===e||void 0!==t.getModuleId)},f.typeOf=I}();const h=e=>"object"==typeof e&&null!=e&&1===e.nodeType,g=(e,t)=>(!t||"hidden"!==e)&&"visible"!==e&&"clip"!==e,m=(e,t)=>{if(e.clientHeight<e.scrollHeight||e.clientWidth<e.scrollWidth){const n=getComputedStyle(e,null);return g(n.overflowY,t)||g(n.overflowX,t)||(e=>{const t=(e=>{if(!e.ownerDocument||!e.ownerDocument.defaultView)return null;try{return e.ownerDocument.defaultView.frameElement}catch(e){return null}})(e);return!!t&&(t.clientHeight<e.scrollHeight||t.clientWidth<e.scrollWidth)})(e)}return!1},I=(e,t,n,i,o,r,u,s)=>r<e&&u>t||r>e&&u<t?0:r<=e&&s<=n||u>=t&&s>=n?r-e-i:u>t&&s<n||r<e&&s>n?u-t+o:0,v=e=>{const t=e.parentElement;return null==t?e.getRootNode().host||null:t};var y=0;function b(e){return"function"==typeof e?e:x}function x(){}function w(e,t){if(e){var n=((e,t)=>{var n,i,o,r;if("undefined"==typeof document)return[];const{inline:u,boundary:s,skipOverflowHiddenElements:l}=t,a="function"==typeof s?s:e=>e!==s;if(!h(e))throw new TypeError("Invalid target");const c=document.scrollingElement||document.documentElement,d=[];let p=e;for(;h(p)&&a(p);){if(p=v(p),p===c){d.push(p);break}null!=p&&p===document.body&&m(p)&&!m(document.documentElement)||null!=p&&m(p,l)&&d.push(p)}const f=null!=(i=null==(n=window.visualViewport)?void 0:n.width)?i:innerWidth,g=null!=(r=null==(o=window.visualViewport)?void 0:o.height)?r:innerHeight,{scrollX:y,scrollY:b}=window,{height:x,width:w,top:S,right:C,bottom:D,left:k}=e.getBoundingClientRect(),{top:O,right:M,left:E}=(e=>{const t=window.getComputedStyle(e);return{top:parseFloat(t.scrollMarginTop)||0,right:parseFloat(t.scrollMarginRight)||0,bottom:parseFloat(t.scrollMarginBottom)||0,left:parseFloat(t.scrollMarginLeft)||0}})(e);let K=S-O,P="center"===u?k+w/2-E+M:"end"===u?C+M:k-E;const T=[];for(let e=0;e<d.length;e++){const t=d[e],{height:n,width:i,top:o,right:r,bottom:s,left:l}=t.getBoundingClientRect();if(S>=0&&k>=0&&D<=g&&C<=f&&(t===c&&!m(t)||S>=o&&D<=s&&k>=l&&C<=r))return T;const a=getComputedStyle(t),p=parseInt(a.borderLeftWidth,10),h=parseInt(a.borderTopWidth,10),v=parseInt(a.borderRightWidth,10),O=parseInt(a.borderBottomWidth,10);let M=0,E=0;const R="offsetWidth"in t?t.offsetWidth-t.clientWidth-p-v:0,H="offsetHeight"in t?t.offsetHeight-t.clientHeight-h-O:0,V="offsetWidth"in t?0===t.offsetWidth?0:i/t.offsetWidth:0,B="offsetHeight"in t?0===t.offsetHeight?0:n/t.offsetHeight:0;if(c===t)M=I(b,b+g,g,h,O,b+K,b+K+x,x),E="start"===u?P:"center"===u?P-f/2:"end"===u?P-f:I(y,y+f,f,p,v,y+P,y+P+w,w),M=Math.max(0,M+b),E=Math.max(0,E+y);else{M=I(o,s,n,h,O+H,K,K+x,x),E="start"===u?P-l-p:"center"===u?P-(l+i/2)+R/2:"end"===u?P-r+v+R:I(l,r,i,p,v+R,P,P+w,w);const{scrollLeft:e,scrollTop:a}=t;M=0===B?0:Math.max(0,Math.min(a+M/B,t.scrollHeight-n/B+H)),E=0===V?0:Math.max(0,Math.min(e+E/V,t.scrollWidth-i/V+R)),K+=a-M,P+=e-E}T.push({el:t,top:M,left:E})}return T})(e,{boundary:t});n.forEach((function(e){var t=e.el,n=e.top,i=e.left;t.scrollTop=n,t.scrollLeft=i}))}}function S(e,t,n){return e===t||t instanceof n.Node&&e.contains&&e.contains(t)}function C(e,t){var n;function i(){n&&clearTimeout(n)}function o(){for(var o=arguments.length,r=new Array(o),u=0;u<o;u++)r[u]=arguments[u];i(),n=setTimeout((function(){n=null,e.apply(void 0,r)}),t)}return o.cancel=i,o}function D(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];return function(e){for(var n=arguments.length,i=new Array(n>1?n-1:0),o=1;o<n;o++)i[o-1]=arguments[o];return t.some((function(t){return t&&t.apply(void 0,[e].concat(i)),e.preventDownshiftDefault||e.hasOwnProperty("nativeEvent")&&e.nativeEvent.preventDownshiftDefault}))}}function k(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];return function(e){t.forEach((function(t){"function"==typeof t?t(e):t&&(t.current=e)}))}}function O(){return String(y++)}function M(e){var t=e.isOpen,n=e.resultCount,i=e.previousResultCount;return t?n?n!==i?n+" result"+(1===n?" is":"s are")+" available, use up and down arrow keys to navigate. Press Enter key to select.":"":"No results are available.":""}function E(e,t){return!(e=Array.isArray(e)?e[0]:e)&&t?t:e}var K=["highlightedIndex","inputValue","isOpen","selectedItem","type"];function P(e){void 0===e&&(e={});var t={};return K.forEach((function(n){e.hasOwnProperty(n)&&(t[n]=e[n])})),t}function T(e,t){return e&&t?Object.keys(e).reduce((function(n,i){return n[i]=R(t,i)?t[i]:e[i],n}),{}):e}function R(e,t){return void 0!==e[t]}function H(e){var t=e.key,n=e.keyCode;return n>=37&&n<=40&&0!==t.indexOf("Arrow")?"Arrow"+t:t}function V(e,t,n,i,o){void 0===o&&(o=!1);var r=n.length;if(0===r)return-1;var u=r-1;("number"!=typeof e||e<0||e>u)&&(e=t>0?-1:u+1);var s=e+t;s<0?s=o?u:0:s>u&&(s=o?0:u);var l=B(s,t<0,n,i,o);return-1===l?e>=r?-1:e:l}function B(e,t,n,i,o){void 0===o&&(o=!1);var r=n.length;if(t){for(var u=e;u>=0;u--)if(!i(n[u],u))return u}else for(var s=e;s<r;s++)if(!i(n[s],s))return s;return o?B(t?r-1:0,t,n,i):-1}function A(e,t,n,i){return void 0===i&&(i=!0),n&&t.some((function(t){return t&&(S(t,e,n)||i&&S(t,n.document.activeElement,n))}))}var L=C((function(e){F(e).textContent=""}),500);function F(e){var t=e.getElementById("a11y-status-message");return t||((t=e.createElement("div")).setAttribute("id","a11y-status-message"),t.setAttribute("role","status"),t.setAttribute("aria-live","polite"),t.setAttribute("aria-relevant","additions text"),Object.assign(t.style,{border:"0",clip:"rect(0 0 0 0)",height:"1px",margin:"-1px",overflow:"hidden",padding:"0",position:"absolute",width:"1px"}),e.body.appendChild(t),t)}function _(e,t){e&&t&&(F(t).textContent=e,L(t))}var N=Object.freeze({__proto__:null,blurButton:14,blurInput:10,changeInput:11,clickButton:13,clickItem:9,controlledPropUpdatedSelectedItem:15,itemMouseEnter:2,keyDownArrowDown:4,keyDownArrowUp:3,keyDownEnd:8,keyDownEnter:6,keyDownEscape:5,keyDownHome:7,keyDownSpaceButton:12,mouseUp:1,touchEnd:16,unknown:0}),j=["refKey","ref"],U=["onClick","onPress","onKeyDown","onKeyUp","onBlur"],W=["onKeyDown","onBlur","onChange","onInput","onChangeText"],$=["refKey","ref"],q=["onMouseMove","onMouseDown","onClick","onPress","index","item"],z=function(){var e=function(e){function r(t){var o=e.call(this,t)||this;o.id=o.props.id||"downshift-"+O(),o.menuId=o.props.menuId||o.id+"-menu",o.labelId=o.props.labelId||o.id+"-label",o.inputId=o.props.inputId||o.id+"-input",o.getItemId=o.props.getItemId||function(e){return o.id+"-item-"+e},o.items=[],o.itemCount=null,o.previousResultCount=0,o.timeoutIds=[],o.internalSetTimeout=function(e,t){var n=setTimeout((function(){o.timeoutIds=o.timeoutIds.filter((function(e){return e!==n})),e()}),t);o.timeoutIds.push(n)},o.setItemCount=function(e){o.itemCount=e},o.unsetItemCount=function(){o.itemCount=null},o.isItemDisabled=function(e,t){var n=o.getItemNodeFromIndex(t);return n&&n.hasAttribute("disabled")},o.setHighlightedIndex=function(e,t){void 0===e&&(e=o.props.defaultHighlightedIndex),void 0===t&&(t={}),t=P(t),o.internalSetState(i({highlightedIndex:e},t))},o.clearSelection=function(e){o.internalSetState({selectedItem:null,inputValue:"",highlightedIndex:o.props.defaultHighlightedIndex,isOpen:o.props.defaultIsOpen},e)},o.selectItem=function(e,t,n){t=P(t),o.internalSetState(i({isOpen:o.props.defaultIsOpen,highlightedIndex:o.props.defaultHighlightedIndex,selectedItem:e,inputValue:o.props.itemToString(e)},t),n)},o.selectItemAtIndex=function(e,t,n){var i=o.items[e];null!=i&&o.selectItem(i,t,n)},o.selectHighlightedItem=function(e,t){return o.selectItemAtIndex(o.getState().highlightedIndex,e,t)},o.internalSetState=function(e,t){var n,r,u={},s="function"==typeof e;return!s&&e.hasOwnProperty("inputValue")&&o.props.onInputValueChange(e.inputValue,i({},o.getStateAndHelpers(),e)),o.setState((function(t){var l;t=o.getState(t);var a=s?e(t):e;a=o.props.stateReducer(t,a),n=a.hasOwnProperty("selectedItem");var c={};return n&&a.selectedItem!==t.selectedItem&&(r=a.selectedItem),(l=a).type||(l.type=0),Object.keys(a).forEach((function(e){t[e]!==a[e]&&(u[e]=a[e]),"type"!==e&&(a[e],R(o.props,e)||(c[e]=a[e]))})),s&&a.hasOwnProperty("inputValue")&&o.props.onInputValueChange(a.inputValue,i({},o.getStateAndHelpers(),a)),c}),(function(){b(t)(),Object.keys(u).length>1&&o.props.onStateChange(u,o.getStateAndHelpers()),n&&o.props.onSelect(e.selectedItem,o.getStateAndHelpers()),void 0!==r&&o.props.onChange(r,o.getStateAndHelpers()),o.props.onUserAction(u,o.getStateAndHelpers())}))},o.rootRef=function(e){return o._rootNode=e},o.getRootProps=function(e,t){var r,u=void 0===e?{}:e,s=u.refKey,l=void 0===s?"ref":s,a=u.ref,c=n(u,j),d=(void 0===t?{}:t).suppressRefError,p=void 0!==d&&d;o.getRootProps.called=!0,o.getRootProps.refKey=l,o.getRootProps.suppressRefError=p;var f=o.getState().isOpen;return i(((r={})[l]=k(a,o.rootRef),r.role="combobox",r["aria-expanded"]=f,r["aria-haspopup"]="listbox",r["aria-owns"]=f?o.menuId:void 0,r["aria-labelledby"]=o.labelId,r),c)},o.keyDownHandlers={ArrowDown:function(e){var t=this;if(e.preventDefault(),this.getState().isOpen){var n=e.shiftKey?5:1;this.moveHighlightedIndex(n,{type:4})}else this.internalSetState({isOpen:!0,type:4},(function(){var e=t.getItemCount();if(e>0){var n=V(t.getState().highlightedIndex,1,{length:e},t.isItemDisabled,!0);t.setHighlightedIndex(n,{type:4})}}))},ArrowUp:function(e){var t=this;if(e.preventDefault(),this.getState().isOpen){var n=e.shiftKey?-5:-1;this.moveHighlightedIndex(n,{type:3})}else this.internalSetState({isOpen:!0,type:3},(function(){var e=t.getItemCount();if(e>0){var n=V(t.getState().highlightedIndex,-1,{length:e},t.isItemDisabled,!0);t.setHighlightedIndex(n,{type:3})}}))},Enter:function(e){if(229!==e.which){var t=this.getState(),n=t.isOpen,i=t.highlightedIndex;if(n&&null!=i){e.preventDefault();var o=this.items[i],r=this.getItemNodeFromIndex(i);if(null==o||r&&r.hasAttribute("disabled"))return;this.selectHighlightedItem({type:6})}}},Escape:function(e){e.preventDefault(),this.reset(i({type:5},!this.state.isOpen&&{selectedItem:null,inputValue:""}))}},o.buttonKeyDownHandlers=i({},o.keyDownHandlers,{" ":function(e){e.preventDefault(),this.toggleMenu({type:12})}}),o.inputKeyDownHandlers=i({},o.keyDownHandlers,{Home:function(e){var t=this.getState().isOpen;if(t){e.preventDefault();var n=this.getItemCount();if(!(n<=0)&&t){var i=B(0,!1,{length:n},this.isItemDisabled);this.setHighlightedIndex(i,{type:7})}}},End:function(e){var t=this.getState().isOpen;if(t){e.preventDefault();var n=this.getItemCount();if(!(n<=0)&&t){var i=B(n-1,!0,{length:n},this.isItemDisabled);this.setHighlightedIndex(i,{type:8})}}}}),o.getToggleButtonProps=function(e){var t=void 0===e?{}:e,r=t.onClick;t.onPress;var u=t.onKeyDown,s=t.onKeyUp,l=t.onBlur,a=n(t,U),c=o.getState().isOpen,d={onClick:D(r,o.buttonHandleClick),onKeyDown:D(u,o.buttonHandleKeyDown),onKeyUp:D(s,o.buttonHandleKeyUp),onBlur:D(l,o.buttonHandleBlur)};return i({type:"button",role:"button","aria-label":c?"close menu":"open menu","aria-haspopup":!0,"data-toggle":!0},a.disabled?{}:d,a)},o.buttonHandleKeyUp=function(e){e.preventDefault()},o.buttonHandleKeyDown=function(e){var t=H(e);o.buttonKeyDownHandlers[t]&&o.buttonKeyDownHandlers[t].call(o,e)},o.buttonHandleClick=function(e){if(e.preventDefault(),o.props.environment){var t=o.props.environment.document,n=t.body,i=t.activeElement;n&&n===i&&e.target.focus()}o.internalSetTimeout((function(){return o.toggleMenu({type:13})}))},o.buttonHandleBlur=function(e){var t=e.target;o.internalSetTimeout((function(){if(!o.isMouseDown&&o.props.environment){var e=o.props.environment.document.activeElement;null!=e&&e.id===o.inputId||e===t||o.reset({type:14})}}))},o.getLabelProps=function(e){return i({htmlFor:o.inputId,id:o.labelId},e)},o.getInputProps=function(e){var t=void 0===e?{}:e,r=t.onKeyDown,u=t.onBlur,s=t.onChange,l=t.onInput;t.onChangeText;var a=n(t,W),c={};var d,p=o.getState(),f=p.inputValue,h=p.isOpen,g=p.highlightedIndex;a.disabled||((d={}).onChange=D(s,l,o.inputHandleChange),d.onKeyDown=D(r,o.inputHandleKeyDown),d.onBlur=D(u,o.inputHandleBlur),c=d);return i({"aria-autocomplete":"list","aria-activedescendant":h&&"number"==typeof g&&g>=0?o.getItemId(g):void 0,"aria-controls":h?o.menuId:void 0,"aria-labelledby":a&&a["aria-label"]?void 0:o.labelId,autoComplete:"off",value:f,id:o.inputId},c,a)},o.inputHandleKeyDown=function(e){var t=H(e);t&&o.inputKeyDownHandlers[t]&&o.inputKeyDownHandlers[t].call(o,e)},o.inputHandleChange=function(e){o.internalSetState({type:11,isOpen:!0,inputValue:e.target.value,highlightedIndex:o.props.defaultHighlightedIndex})},o.inputHandleBlur=function(){o.internalSetTimeout((function(){var e;if(!o.isMouseDown&&o.props.environment){var t=o.props.environment.document.activeElement;(null==t||null==(e=t.dataset)?void 0:e.toggle)&&o._rootNode&&o._rootNode.contains(t)||o.reset({type:10})}}))},o.menuRef=function(e){o._menuNode=e},o.getMenuProps=function(e,t){var r,u=void 0===e?{}:e,s=u.refKey,l=void 0===s?"ref":s,a=u.ref,c=n(u,$),d=(void 0===t?{}:t).suppressRefError,p=void 0!==d&&d;return o.getMenuProps.called=!0,o.getMenuProps.refKey=l,o.getMenuProps.suppressRefError=p,i(((r={})[l]=k(a,o.menuRef),r.role="listbox",r["aria-labelledby"]=c&&c["aria-label"]?void 0:o.labelId,r.id=o.menuId,r),c)},o.getItemProps=function(e){var t,r=void 0===e?{}:e,u=r.onMouseMove,s=r.onMouseDown,l=r.onClick;r.onPress;var a=r.index,c=r.item,d=void 0===c?void 0:c,p=n(r,q);void 0===a?(o.items.push(d),a=o.items.indexOf(d)):o.items[a]=d;var f=l,h=((t={onMouseMove:D(u,(function(){a!==o.getState().highlightedIndex&&(o.setHighlightedIndex(a,{type:2}),o.avoidScrolling=!0,o.internalSetTimeout((function(){return o.avoidScrolling=!1}),250))})),onMouseDown:D(s,(function(e){e.preventDefault()}))}).onClick=D(f,(function(){o.selectItemAtIndex(a,{type:9})})),t),g=p.disabled?{onMouseDown:h.onMouseDown}:h;return i({id:o.getItemId(a),role:"option","aria-selected":o.getState().highlightedIndex===a},g,p)},o.clearItems=function(){o.items=[]},o.reset=function(e,t){void 0===e&&(e={}),e=P(e),o.internalSetState((function(t){var n=t.selectedItem;return i({isOpen:o.props.defaultIsOpen,highlightedIndex:o.props.defaultHighlightedIndex,inputValue:o.props.itemToString(n)},e)}),t)},o.toggleMenu=function(e,t){void 0===e&&(e={}),e=P(e),o.internalSetState((function(t){var n=t.isOpen;return i({isOpen:!n},n&&{highlightedIndex:o.props.defaultHighlightedIndex},e)}),(function(){var n=o.getState(),i=n.isOpen,r=n.highlightedIndex;i&&o.getItemCount()>0&&"number"==typeof r&&o.setHighlightedIndex(r,e),b(t)()}))},o.openMenu=function(e){o.internalSetState({isOpen:!0},e)},o.closeMenu=function(e){o.internalSetState({isOpen:!1},e)},o.updateStatus=C((function(){var e;if(null!=(e=o.props)&&null!=(e=e.environment)&&e.document){var t=o.getState(),n=o.items[t.highlightedIndex],r=o.getItemCount(),u=o.props.getA11yStatusMessage(i({itemToString:o.props.itemToString,previousResultCount:o.previousResultCount,resultCount:r,highlightedItem:n},t));o.previousResultCount=r,_(u,o.props.environment.document)}}),200);var r=o.props,u=r.defaultHighlightedIndex,s=r.initialHighlightedIndex,l=void 0===s?u:s,a=r.defaultIsOpen,c=r.initialIsOpen,d=void 0===c?a:c,p=r.initialInputValue,f=void 0===p?"":p,h=r.initialSelectedItem,g=void 0===h?null:h,m=o.getState({highlightedIndex:l,isOpen:d,inputValue:f,selectedItem:g});return null!=m.selectedItem&&void 0===o.props.initialInputValue&&(m.inputValue=o.props.itemToString(m.selectedItem)),o.state=m,o}!function(e,t){e.prototype=Object.create(t.prototype),e.prototype.constructor=e,o(e,t)}(r,e);var u=r.prototype;return u.internalClearTimeouts=function(){this.timeoutIds.forEach((function(e){clearTimeout(e)})),this.timeoutIds=[]},u.getState=function(e){return void 0===e&&(e=this.state),T(e,this.props)},u.getItemCount=function(){var e=this.items.length;return null!=this.itemCount?e=this.itemCount:void 0!==this.props.itemCount&&(e=this.props.itemCount),e},u.getItemNodeFromIndex=function(e){return this.props.environment?this.props.environment.document.getElementById(this.getItemId(e)):null},u.scrollHighlightedItemIntoView=function(){var e=this.getItemNodeFromIndex(this.getState().highlightedIndex);this.props.scrollIntoView(e,this._menuNode)},u.moveHighlightedIndex=function(e,t){var n=this.getItemCount(),i=this.getState().highlightedIndex;if(n>0){var o=V(i,e,{length:n},this.isItemDisabled,!0);this.setHighlightedIndex(o,t)}},u.getStateAndHelpers=function(){var e=this.getState(),t=e.highlightedIndex,n=e.inputValue,i=e.selectedItem,o=e.isOpen,r=this.props.itemToString,u=this.id,s=this.getRootProps,l=this.getToggleButtonProps,a=this.getLabelProps,c=this.getMenuProps,d=this.getInputProps,p=this.getItemProps,f=this.openMenu,h=this.closeMenu,g=this.toggleMenu,m=this.selectItem,I=this.selectItemAtIndex,v=this.selectHighlightedItem,y=this.setHighlightedIndex,b=this.clearSelection,x=this.clearItems;return{getRootProps:s,getToggleButtonProps:l,getLabelProps:a,getMenuProps:c,getInputProps:d,getItemProps:p,reset:this.reset,openMenu:f,closeMenu:h,toggleMenu:g,selectItem:m,selectItemAtIndex:I,selectHighlightedItem:v,setHighlightedIndex:y,clearSelection:b,clearItems:x,setItemCount:this.setItemCount,unsetItemCount:this.unsetItemCount,setState:this.internalSetState,itemToString:r,id:u,highlightedIndex:t,inputValue:n,isOpen:o,selectedItem:i}},u.componentDidMount=function(){var e=this;if(this.props.environment){var t=function(){e.isMouseDown=!0},n=function(t){e.isMouseDown=!1,!A(t.target,[e._rootNode,e._menuNode],e.props.environment)&&e.getState().isOpen&&e.reset({type:1},(function(){return e.props.onOuterClick(e.getStateAndHelpers())}))},i=function(){e.isTouchMove=!1},o=function(){e.isTouchMove=!0},r=function(t){var n=A(t.target,[e._rootNode,e._menuNode],e.props.environment,!1);e.isTouchMove||n||!e.getState().isOpen||e.reset({type:16},(function(){return e.props.onOuterClick(e.getStateAndHelpers())}))},u=this.props.environment;u.addEventListener("mousedown",t),u.addEventListener("mouseup",n),u.addEventListener("touchstart",i),u.addEventListener("touchmove",o),u.addEventListener("touchend",r),this.cleanup=function(){e.internalClearTimeouts(),e.updateStatus.cancel(),u.removeEventListener("mousedown",t),u.removeEventListener("mouseup",n),u.removeEventListener("touchstart",i),u.removeEventListener("touchmove",o),u.removeEventListener("touchend",r)}}else this.cleanup=function(){e.internalClearTimeouts()}},u.shouldScroll=function(e,t){var n=(void 0===this.props.highlightedIndex?this.getState():this.props).highlightedIndex,i=(void 0===t.highlightedIndex?e:t).highlightedIndex;return n&&this.getState().isOpen&&!e.isOpen||n!==i},u.componentDidUpdate=function(e,t){R(this.props,"selectedItem")&&this.props.selectedItemChanged(e.selectedItem,this.props.selectedItem)&&this.internalSetState({type:15,inputValue:this.props.itemToString(this.props.selectedItem)}),!this.avoidScrolling&&this.shouldScroll(t,e)&&this.scrollHighlightedItemIntoView(),this.updateStatus()},u.componentWillUnmount=function(){this.cleanup()},u.render=function(){var e=E(this.props.children,x);this.clearItems(),this.getRootProps.called=!1,this.getRootProps.refKey=void 0,this.getRootProps.suppressRefError=void 0,this.getMenuProps.called=!1,this.getMenuProps.refKey=void 0,this.getMenuProps.suppressRefError=void 0,this.getLabelProps.called=!1,this.getInputProps.called=!1;var n=E(e(this.getStateAndHelpers()));return n?this.getRootProps.called||this.props.suppressRefError?n:function(e){return"string"==typeof e.type}(n)?t.cloneElement(n,this.getRootProps(function(e){return e.props}(n))):void 0:null},r}(t.Component);return e.defaultProps={defaultHighlightedIndex:null,defaultIsOpen:!1,getA11yStatusMessage:M,itemToString:function(e){return null==e?"":String(e)},onStateChange:x,onInputValueChange:x,onUserAction:x,onChange:x,onSelect:x,onOuterClick:x,selectedItemChanged:function(e,t){return e!==t},environment:"undefined"==typeof window?void 0:window,stateReducer:function(e,t){return t},suppressRefError:!1,scrollIntoView:w},e.stateChangeTypes=N,e}(),Y={highlightedIndex:-1,isOpen:!1,selectedItem:null,inputValue:""};function X(e,t,n){var o=e.props,r=e.type,u={};Object.keys(t).forEach((function(o){!function(e,t,n,o){var r=t.props,u=t.type,s="on"+ee(e)+"Change";r[s]&&void 0!==o[e]&&o[e]!==n[e]&&r[s](i({type:u},o))}(o,e,t,n),n[o]!==t[o]&&(u[o]=n[o])})),o.onStateChange&&Object.keys(u).length&&o.onStateChange(i({type:r},u))}var G=C((function(e,t){_(e,t)}),200),J="undefined"!=typeof window&&void 0!==window.document&&void 0!==window.document.createElement?t.useLayoutEffect:t.useEffect,Q="useId"in t?function(e){var n=e.id,i=e.labelId,o=e.menuId,r=e.getItemId,u=e.toggleButtonId,s=e.inputId,l="downshift-"+t.useId();return n||(n=l),t.useRef({labelId:i||n+"-label",menuId:o||n+"-menu",getItemId:r||function(e){return n+"-item-"+e},toggleButtonId:u||n+"-toggle-button",inputId:s||n+"-input"}).current}:function(e){var n=e.id,i=void 0===n?"downshift-"+O():n,o=e.labelId,r=e.menuId,u=e.getItemId,s=e.toggleButtonId,l=e.inputId;return t.useRef({labelId:o||i+"-label",menuId:r||i+"-menu",getItemId:u||function(e){return i+"-item-"+e},toggleButtonId:s||i+"-toggle-button",inputId:l||i+"-input"}).current};function Z(e,t,n,i){var o,r;if(void 0===e){if(void 0===t)throw new Error(i);o=n[t],r=t}else r=void 0===t?n.indexOf(e):t,o=e;return[o,r]}function ee(e){return""+e.slice(0,1).toUpperCase()+e.slice(1)}function te(e){var n=t.useRef(e);return n.current=e,n}function ne(e,n,o,r){var u=t.useRef(),s=t.useRef(),l=t.useCallback((function(t,n){s.current=n,t=T(t,n.props);var o=e(t,n);return n.props.stateReducer(t,i({},n,{changes:o}))}),[e]),a=t.useReducer(l,n,o),c=a[0],d=a[1],p=te(n),f=t.useCallback((function(e){return d(i({props:p.current},e))}),[p]),h=s.current;return t.useEffect((function(){var e=T(u.current,null==h?void 0:h.props);h&&u.current&&!r(e,c)&&X(h,e,c),u.current=c}),[c,h,r]),[c,f]}function ie(e,t,n,i){var o=ne(e,t,n,i),r=o[0],u=o[1];return[T(r,t),u]}var oe={itemToString:function(e){return e?String(e):""},itemToKey:function(e){return e},stateReducer:function(e,t){return t.changes},scrollIntoView:w,environment:"undefined"==typeof window?void 0:window};function re(e,t,n){void 0===n&&(n=Y);var i=e["default"+ee(t)];return void 0!==i?i:n[t]}function ue(e,t,n){void 0===n&&(n=Y);var i=e[t];if(void 0!==i)return i;var o=e["initial"+ee(t)];return void 0!==o?o:re(e,t,n)}function se(e){var t=ue(e,"selectedItem"),n=ue(e,"isOpen"),i=function(e){var t=ue(e,"highlightedIndex");if(t>-1&&e.isItemDisabled(e.items[t],t))return-1;return t}(e),o=ue(e,"inputValue");return{highlightedIndex:i<0&&t&&n?e.items.findIndex((function(n){return e.itemToKey(n)===e.itemToKey(t)})):i,isOpen:n,selectedItem:t,inputValue:o}}function le(e,t,n){var i=e.items,o=e.initialHighlightedIndex,r=e.defaultHighlightedIndex,u=e.isItemDisabled,s=e.itemToKey,l=t.selectedItem,a=t.highlightedIndex;return 0===i.length?-1:void 0===o||a!==o||u(i[o],o)?void 0===r||u(i[r],r)?l?i.findIndex((function(e){return s(l)===s(e)})):n<0&&!u(i[i.length-1],i.length-1)?i.length-1:n>0&&!u(i[0],0)?0:-1:r:o}function ae(e,n,i){var o=t.useRef({isMouseDown:!1,isTouchMove:!1,isTouchEnd:!1});return t.useEffect((function(){if(!e)return x;var t=i.map((function(e){return e.current}));function r(){o.current.isTouchEnd=!1,o.current.isMouseDown=!0}function u(i){o.current.isMouseDown=!1,A(i.target,t,e)||n()}function s(){o.current.isTouchEnd=!1,o.current.isTouchMove=!1}function l(){o.current.isTouchMove=!0}function a(i){o.current.isTouchEnd=!0,o.current.isTouchMove||A(i.target,t,e,!1)||n()}return e.addEventListener("mousedown",r),e.addEventListener("mouseup",u),e.addEventListener("touchstart",s),e.addEventListener("touchmove",l),e.addEventListener("touchend",a),function(){e.removeEventListener("mousedown",r),e.removeEventListener("mouseup",u),e.removeEventListener("touchstart",s),e.removeEventListener("touchmove",l),e.removeEventListener("touchend",a)}}),[i,e,n]),o.current}var ce=function(){return x};function de(e,n,i,o){void 0===o&&(o={});var r=o.document,u=ge();t.useEffect((function(){if(e&&!u&&r){var t=e(n);G(t,r)}}),i),t.useEffect((function(){return function(){var e,t;G.cancel(),(t=null==(e=r)?void 0:e.getElementById("a11y-status-message"))&&t.remove()}}),[r])}function pe(e){var n=e.highlightedIndex,i=e.isOpen,o=e.itemRefs,r=e.getItemNodeFromIndex,u=e.menuElement,s=e.scrollIntoView,l=t.useRef(!0);return J((function(){n<0||!i||!Object.keys(o.current).length||(!1===l.current?l.current=!0:s(r(n),u))}),[n]),l}function fe(e,t,n){var o;return void 0===n&&(n=!0),i({isOpen:!1,highlightedIndex:-1},(null==(o=e.items)?void 0:o.length)&&t>=0&&i({selectedItem:e.items[t],isOpen:re(e,"isOpen"),highlightedIndex:re(e,"highlightedIndex")},n&&{inputValue:e.itemToString(e.items[t])}))}function he(e,t){return e.isOpen===t.isOpen&&e.inputValue===t.inputValue&&e.highlightedIndex===t.highlightedIndex&&e.selectedItem===t.selectedItem}function ge(){var e=t.useRef(!0);return t.useEffect((function(){return e.current=!1,function(){e.current=!0}}),[]),e.current}function me(e){var t=re(e,"highlightedIndex");return t>-1&&e.isItemDisabled(e.items[t],t)?-1:t}var Ie={environment:p.shape({addEventListener:p.func.isRequired,removeEventListener:p.func.isRequired,document:p.shape({createElement:p.func.isRequired,getElementById:p.func.isRequired,activeElement:p.any.isRequired,body:p.any.isRequired}).isRequired,Node:p.func.isRequired}),itemToString:p.func,itemToKey:p.func,stateReducer:p.func},ve=i({},Ie,{getA11yStatusMessage:p.func,highlightedIndex:p.number,defaultHighlightedIndex:p.number,initialHighlightedIndex:p.number,isOpen:p.bool,defaultIsOpen:p.bool,initialIsOpen:p.bool,selectedItem:p.any,initialSelectedItem:p.any,defaultSelectedItem:p.any,id:p.string,labelId:p.string,menuId:p.string,getItemId:p.func,toggleButtonId:p.string,onSelectedItemChange:p.func,onHighlightedIndexChange:p.func,onStateChange:p.func,onIsOpenChange:p.func,scrollIntoView:p.func});function ye(e,t,n){var o,r=t.type,u=t.props;switch(r){case n.ItemMouseMove:o={highlightedIndex:t.disabled?-1:t.index};break;case n.MenuMouseLeave:o={highlightedIndex:-1};break;case n.ToggleButtonClick:case n.FunctionToggleMenu:o={isOpen:!e.isOpen,highlightedIndex:e.isOpen?-1:le(u,e,0)};break;case n.FunctionOpenMenu:o={isOpen:!0,highlightedIndex:le(u,e,0)};break;case n.FunctionCloseMenu:o={isOpen:!1};break;case n.FunctionSetHighlightedIndex:o={highlightedIndex:u.isItemDisabled(u.items[t.highlightedIndex],t.highlightedIndex)?-1:t.highlightedIndex};break;case n.FunctionSetInputValue:o={inputValue:t.inputValue};break;case n.FunctionReset:o={highlightedIndex:me(u),isOpen:re(u,"isOpen"),selectedItem:re(u,"selectedItem"),inputValue:re(u,"inputValue")};break;default:throw new Error("Reducer called without proper action type.")}return i({},e,o)}var be=function(){return be=Object.assign||function(e){for(var t,n=1,i=arguments.length;n<i;n++)for(var o in t=arguments[n])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},be.apply(this,arguments)};"function"==typeof SuppressedError&&SuppressedError,be(be({},ve),{items:p.array.isRequired,isItemDisabled:p.func});var xe=be(be({},oe),{isItemDisabled:function(){return!1}}),we=Object.freeze({__proto__:null,FunctionCloseMenu:17,FunctionOpenMenu:16,FunctionReset:21,FunctionSelectItem:19,FunctionSetHighlightedIndex:18,FunctionSetInputValue:20,FunctionToggleMenu:15,ItemClick:14,ItemMouseMove:13,MenuMouseLeave:12,ToggleButtonBlur:11,ToggleButtonClick:0,ToggleButtonKeyDownArrowDown:1,ToggleButtonKeyDownArrowUp:2,ToggleButtonKeyDownCharacter:3,ToggleButtonKeyDownEnd:6,ToggleButtonKeyDownEnter:7,ToggleButtonKeyDownEscape:4,ToggleButtonKeyDownHome:5,ToggleButtonKeyDownPageDown:10,ToggleButtonKeyDownPageUp:9,ToggleButtonKeyDownSpaceButton:8});function Se(e,t){var n,o,r=t.type,u=t.props,s=t.altKey;switch(r){case 14:o={isOpen:re(u,"isOpen"),highlightedIndex:me(u),selectedItem:u.items[t.index]};break;case 3:var l=t.key,a=""+e.inputValue+l;o={inputValue:a,highlightedIndex:function(e){for(var t=e.keysSoFar,n=e.highlightedIndex,i=e.items,o=e.itemToString,r=e.isItemDisabled,u=t.toLowerCase(),s=0;s<i.length;s++){var l=(s+n+(t.length<2?1:0))%i.length,a=i[l];if(void 0!==a&&o(a).toLowerCase().startsWith(u)&&!r(a,l))return l}return n}({keysSoFar:a,highlightedIndex:!e.isOpen&&e.selectedItem?u.items.findIndex((function(t){return u.itemToKey(t)===u.itemToKey(e.selectedItem)})):e.highlightedIndex,items:u.items,itemToString:u.itemToString,isItemDisabled:u.isItemDisabled}),isOpen:!0};break;case 1:o={highlightedIndex:e.isOpen?V(e.highlightedIndex,1,u.items,u.isItemDisabled):s&&null==e.selectedItem?-1:le(u,e,1),isOpen:!0};break;case 2:if(e.isOpen&&s)o=fe(u,e.highlightedIndex,!1);else o={highlightedIndex:e.isOpen?V(e.highlightedIndex,-1,u.items,u.isItemDisabled):le(u,e,-1),isOpen:!0};break;case 7:case 8:o=fe(u,e.highlightedIndex,!1);break;case 5:o={highlightedIndex:B(0,!1,u.items,u.isItemDisabled),isOpen:!0};break;case 6:o={highlightedIndex:B(u.items.length-1,!0,u.items,u.isItemDisabled),isOpen:!0};break;case 9:o={highlightedIndex:V(e.highlightedIndex,-10,u.items,u.isItemDisabled)};break;case 10:o={highlightedIndex:V(e.highlightedIndex,10,u.items,u.isItemDisabled)};break;case 4:o={isOpen:!1,highlightedIndex:-1};break;case 11:o=i({isOpen:!1,highlightedIndex:-1},e.highlightedIndex>=0&&(null==(n=u.items)?void 0:n.length)&&{selectedItem:u.items[e.highlightedIndex]});break;case 19:o={selectedItem:t.selectedItem};break;default:return ye(e,t,we)}return i({},e,o)}var Ce=["onClick"],De=["onMouseLeave","refKey","ref"],ke=["onBlur","onClick","onPress","onKeyDown","refKey","ref"],Oe=["item","index","onMouseMove","onClick","onMouseDown","onPress","refKey","disabled","ref"];function Me(e){void 0===e&&(e={});var o=i({},xe,e),r=o.scrollIntoView,u=o.environment,s=o.getA11yStatusMessage,l=ie(Se,o,se,he),a=l[0],c=l[1],d=a.isOpen,p=a.highlightedIndex,f=a.selectedItem,h=a.inputValue,g=t.useRef(null),m=t.useRef(null),I=t.useRef({}),v=t.useRef(null),y=Q(o),b=te({state:a,props:o}),x=t.useCallback((function(e){return I.current[y.getItemId(e)]}),[y]);de(s,a,[d,p,f,h],u);var w=pe({menuElement:m.current,highlightedIndex:p,isOpen:d,itemRefs:I,scrollIntoView:r,getItemNodeFromIndex:x});t.useEffect((function(){return v.current=C((function(e){e({type:20,inputValue:""})}),500),function(){v.current.cancel()}}),[]),t.useEffect((function(){h&&v.current(c)}),[c,h]),t.useEffect((function(){ue(o,"isOpen")&&g.current&&g.current.focus()}),[]);var S=ae(u,t.useCallback((function(){b.current.state.isOpen&&c({type:11})}),[c,b]),t.useMemo((function(){return[m,g]}),[m.current,g.current])),O=ce();t.useEffect((function(){d||(I.current={})}),[d]);var M=t.useMemo((function(){return{ArrowDown:function(e){e.preventDefault(),c({type:1,altKey:e.altKey})},ArrowUp:function(e){e.preventDefault(),c({type:2,altKey:e.altKey})},Home:function(e){e.preventDefault(),c({type:5})},End:function(e){e.preventDefault(),c({type:6})},Escape:function(){b.current.state.isOpen&&c({type:4})},Enter:function(e){e.preventDefault(),c({type:b.current.state.isOpen?7:0})},PageUp:function(e){b.current.state.isOpen&&(e.preventDefault(),c({type:9}))},PageDown:function(e){b.current.state.isOpen&&(e.preventDefault(),c({type:10}))}," ":function(e){e.preventDefault();var t=b.current.state;t.isOpen?t.inputValue?c({type:3,key:" "}):c({type:8}):c({type:0})}}}),[c,b]),E=t.useCallback((function(){c({type:15})}),[c]),K=t.useCallback((function(){c({type:17})}),[c]),P=t.useCallback((function(){c({type:16})}),[c]),T=t.useCallback((function(e){c({type:18,highlightedIndex:e})}),[c]),R=t.useCallback((function(e){c({type:19,selectedItem:e})}),[c]),V=t.useCallback((function(){c({type:21})}),[c]),B=t.useCallback((function(e){c({type:20,inputValue:e})}),[c]),A=t.useCallback((function(e){var t=void 0===e?{}:e,o=t.onClick,r=n(t,Ce);return i({id:y.labelId,htmlFor:y.toggleButtonId,onClick:D(o,(function(){var e;null==(e=g.current)||e.focus()}))},r)}),[y]),L=t.useCallback((function(e,t){var o,r=void 0===e?{}:e,u=r.onMouseLeave,s=r.refKey,l=void 0===s?"ref":s,a=r.ref,d=n(r,De);return(void 0===t?{}:t).suppressRefError,i(((o={})[l]=k(a,(function(e){m.current=e})),o.id=y.menuId,o.role="listbox",o["aria-labelledby"]=d&&d["aria-label"]?void 0:""+y.labelId,o.onMouseLeave=D(u,(function(){c({type:12})})),o),d)}),[c,O,y]),F=t.useCallback((function(e,t){var o,r=void 0===e?{}:e,u=r.onBlur,s=r.onClick;r.onPress;var l=r.onKeyDown,a=r.refKey,d=void 0===a?"ref":a,p=r.ref,f=n(r,ke);(void 0===t?{}:t).suppressRefError;var h=b.current.state,m=i(((o={})[d]=k(p,(function(e){g.current=e})),o["aria-activedescendant"]=h.isOpen&&h.highlightedIndex>-1?y.getItemId(h.highlightedIndex):"",o["aria-controls"]=y.menuId,o["aria-expanded"]=b.current.state.isOpen,o["aria-haspopup"]="listbox",o["aria-labelledby"]=f&&f["aria-label"]?void 0:""+y.labelId,o.id=y.toggleButtonId,o.role="combobox",o.tabIndex=0,o.onBlur=D(u,(function(){h.isOpen&&!S.isMouseDown&&c({type:11})})),o),f);return f.disabled||(m.onClick=D(s,(function(){c({type:0})})),m.onKeyDown=D(l,(function(e){var t=H(e);t&&M[t]?M[t](e):function(e){return/^\S{1}$/.test(e)}(t)&&c({type:3,key:t})}))),m}),[c,y,b,S,O,M]),_=t.useCallback((function(e){var t,o=void 0===e?{}:e,r=o.item,u=o.index,s=o.onMouseMove,l=o.onClick,a=o.onMouseDown;o.onPress;var d=o.refKey,p=void 0===d?"ref":d,f=o.disabled,h=o.ref,g=n(o,Oe);void 0!==f&&console.warn('Passing "disabled" as an argument to getItemProps is not supported anymore. Please use the isItemDisabled prop from useSelect.');var m=b.current,v=m.state,x=m.props,C=Z(r,u,x.items,"Pass either item or index to getItemProps!"),O=C[0],M=C[1],E=x.isItemDisabled(O,M),K=i(((t={})[p]=k(h,(function(e){e&&(I.current[y.getItemId(M)]=e)})),t["aria-disabled"]=E,t["aria-selected"]=O===v.selectedItem,t.id=y.getItemId(M),t.role="option",t),g);return E||(K.onClick=D(l,(function(){c({type:14,index:M})}))),K.onMouseMove=D(s,(function(){S.isTouchEnd||M===v.highlightedIndex||(w.current=!1,c({type:13,index:M,disabled:E}))})),K.onMouseDown=D(a,(function(e){return e.preventDefault()})),K}),[b,y,S,w,c]);return{getToggleButtonProps:F,getLabelProps:A,getMenuProps:L,getItemProps:_,toggleMenu:E,openMenu:P,closeMenu:K,setHighlightedIndex:T,selectItem:R,reset:V,setInputValue:B,highlightedIndex:p,isOpen:d,selectedItem:f,inputValue:h}}Me.stateChangeTypes=we;var Ee=Object.freeze({__proto__:null,ControlledPropUpdatedSelectedItem:22,FunctionCloseMenu:17,FunctionOpenMenu:16,FunctionReset:21,FunctionSelectItem:19,FunctionSetHighlightedIndex:18,FunctionSetInputValue:20,FunctionToggleMenu:15,InputBlur:9,InputChange:8,InputClick:10,InputKeyDownArrowDown:0,InputKeyDownArrowUp:1,InputKeyDownEnd:4,InputKeyDownEnter:7,InputKeyDownEscape:2,InputKeyDownHome:3,InputKeyDownPageDown:6,InputKeyDownPageUp:5,ItemClick:13,ItemMouseMove:12,MenuMouseLeave:11,ToggleButtonClick:14});function Ke(e){var t=se(e),n=t.selectedItem,o=t.inputValue;return""===o&&n&&void 0===e.defaultInputValue&&void 0===e.initialInputValue&&void 0===e.inputValue&&(o=e.itemToString(n)),i({},t,{inputValue:o})}i({},ve,{items:p.array.isRequired,isItemDisabled:p.func,inputValue:p.string,defaultInputValue:p.string,initialInputValue:p.string,inputId:p.string,onInputValueChange:p.func});var Pe=i({},oe,{isItemDisabled:function(){return!1}});function Te(e,t){var n,o,r=t.type,u=t.props,s=t.altKey;switch(r){case 13:o={isOpen:re(u,"isOpen"),highlightedIndex:me(u),selectedItem:u.items[t.index],inputValue:u.itemToString(u.items[t.index])};break;case 0:o=e.isOpen?{highlightedIndex:V(e.highlightedIndex,1,u.items,u.isItemDisabled,!0)}:{highlightedIndex:s&&null==e.selectedItem?-1:le(u,e,1),isOpen:u.items.length>=0};break;case 1:o=e.isOpen?s?fe(u,e.highlightedIndex):{highlightedIndex:V(e.highlightedIndex,-1,u.items,u.isItemDisabled,!0)}:{highlightedIndex:le(u,e,-1),isOpen:u.items.length>=0};break;case 7:o=fe(u,e.highlightedIndex);break;case 2:o=i({isOpen:!1,highlightedIndex:-1},!e.isOpen&&{selectedItem:null,inputValue:""});break;case 5:o={highlightedIndex:V(e.highlightedIndex,-10,u.items,u.isItemDisabled,!0)};break;case 6:o={highlightedIndex:V(e.highlightedIndex,10,u.items,u.isItemDisabled,!0)};break;case 3:o={highlightedIndex:B(0,!1,u.items,u.isItemDisabled)};break;case 4:o={highlightedIndex:B(u.items.length-1,!0,u.items,u.isItemDisabled)};break;case 9:o=i({isOpen:!1,highlightedIndex:-1},e.highlightedIndex>=0&&(null==(n=u.items)?void 0:n.length)&&t.selectItem&&{selectedItem:u.items[e.highlightedIndex],inputValue:u.itemToString(u.items[e.highlightedIndex])});break;case 8:o={isOpen:!0,highlightedIndex:me(u),inputValue:t.inputValue};break;case 10:o={isOpen:!e.isOpen,highlightedIndex:e.isOpen?-1:le(u,e,0)};break;case 19:o={selectedItem:t.selectedItem,inputValue:u.itemToString(t.selectedItem)};break;case 22:o={inputValue:t.inputValue};break;default:return ye(e,t,Ee)}return i({},e,o)}var Re=["onMouseLeave","refKey","ref"],He=["item","index","refKey","ref","onMouseMove","onMouseDown","onClick","onPress","disabled"],Ve=["onClick","onPress","refKey","ref"],Be=["onKeyDown","onChange","onInput","onBlur","onChangeText","onClick","refKey","ref"];function Ae(e){void 0===e&&(e={});var o=i({},Pe,e),r=o.items,u=o.scrollIntoView,s=o.environment,l=o.getA11yStatusMessage,a=function(e,n,i,o){var r=t.useRef(),u=ne(e,n,i,o),s=u[0],l=u[1],a=ge();return t.useEffect((function(){R(n,"selectedItem")&&(a||n.itemToKey(n.selectedItem)!==n.itemToKey(r.current)&&l({type:22,inputValue:n.itemToString(n.selectedItem)}),r.current=s.selectedItem===r.current?n.selectedItem:s.selectedItem)}),[s.selectedItem,n.selectedItem]),[T(s,n),l]}(Te,o,Ke,he),c=a[0],d=a[1],p=c.isOpen,f=c.highlightedIndex,h=c.selectedItem,g=c.inputValue,m=t.useRef(null),I=t.useRef({}),v=t.useRef(null),y=t.useRef(null),b=ge(),x=Q(o),w=t.useRef(),S=te({state:c,props:o}),C=t.useCallback((function(e){return I.current[x.getItemId(e)]}),[x]);de(l,c,[p,f,h,g],s);var O=pe({menuElement:m.current,highlightedIndex:f,isOpen:p,itemRefs:I,scrollIntoView:u,getItemNodeFromIndex:C});t.useEffect((function(){ue(o,"isOpen")&&v.current&&v.current.focus()}),[]),t.useEffect((function(){b||(w.current=r.length)}));var M=ae(s,t.useCallback((function(){S.current.state.isOpen&&d({type:9,selectItem:!1})}),[d,S]),t.useMemo((function(){return[m,y,v]}),[m.current,y.current,v.current])),E=ce();t.useEffect((function(){p||(I.current={})}),[p]),t.useEffect((function(){var e;p&&null!=s&&s.document&&null!=v&&null!=(e=v.current)&&e.focus&&s.document.activeElement!==v.current&&v.current.focus()}),[p,s]);var K=t.useMemo((function(){return{ArrowDown:function(e){e.preventDefault(),d({type:0,altKey:e.altKey})},ArrowUp:function(e){e.preventDefault(),d({type:1,altKey:e.altKey})},Home:function(e){S.current.state.isOpen&&(e.preventDefault(),d({type:3}))},End:function(e){S.current.state.isOpen&&(e.preventDefault(),d({type:4}))},Escape:function(e){var t=S.current.state;(t.isOpen||t.inputValue||t.selectedItem||t.highlightedIndex>-1)&&(e.preventDefault(),d({type:2}))},Enter:function(e){S.current.state.isOpen&&229!==e.which&&(e.preventDefault(),d({type:7}))},PageUp:function(e){S.current.state.isOpen&&(e.preventDefault(),d({type:5}))},PageDown:function(e){S.current.state.isOpen&&(e.preventDefault(),d({type:6}))}}}),[d,S]),P=t.useCallback((function(e){return i({id:x.labelId,htmlFor:x.inputId},e)}),[x]),V=t.useCallback((function(e,t){var o,r=void 0===e?{}:e,u=r.onMouseLeave,s=r.refKey,l=void 0===s?"ref":s,a=r.ref,c=n(r,Re);return(void 0===t?{}:t).suppressRefError,i(((o={})[l]=k(a,(function(e){m.current=e})),o.id=x.menuId,o.role="listbox",o["aria-labelledby"]=c&&c["aria-label"]?void 0:""+x.labelId,o.onMouseLeave=D(u,(function(){d({type:11})})),o),c)}),[d,E,x]),B=t.useCallback((function(e){var t,o,r=void 0===e?{}:e,u=r.item,s=r.index,l=r.refKey,a=void 0===l?"ref":l,c=r.ref,p=r.onMouseMove,f=r.onMouseDown,h=r.onClick;r.onPress;var g=r.disabled,m=n(r,He);void 0!==g&&console.warn('Passing "disabled" as an argument to getItemProps is not supported anymore. Please use the isItemDisabled prop from useCombobox.');var v=S.current,y=v.props,b=v.state,w=Z(u,s,y.items,"Pass either item or index to getItemProps!"),C=w[0],E=w[1],K=y.isItemDisabled(C,E),P=h;return i(((t={})[a]=k(c,(function(e){e&&(I.current[x.getItemId(E)]=e)})),t["aria-disabled"]=K,t["aria-selected"]=E===b.highlightedIndex,t.id=x.getItemId(E),t.role="option",t),!K&&((o={}).onClick=D(P,(function(){d({type:13,index:E})})),o),{onMouseMove:D(p,(function(){M.isTouchEnd||E===b.highlightedIndex||(O.current=!1,d({type:12,index:E,disabled:K}))})),onMouseDown:D(f,(function(e){return e.preventDefault()}))},m)}),[d,x,S,M,O]),A=t.useCallback((function(e){var t,o=void 0===e?{}:e,r=o.onClick;o.onPress;var u=o.refKey,s=void 0===u?"ref":u,l=o.ref,a=n(o,Ve),c=S.current.state;return i(((t={})[s]=k(l,(function(e){y.current=e})),t["aria-controls"]=x.menuId,t["aria-expanded"]=c.isOpen,t.id=x.toggleButtonId,t.tabIndex=-1,t),!a.disabled&&i({},{onClick:D(r,(function(){d({type:14})}))}),a)}),[d,S,x]),L=t.useCallback((function(e,t){var o,r=void 0===e?{}:e,u=r.onKeyDown,l=r.onChange,a=r.onInput,c=r.onBlur;r.onChangeText;var p=r.onClick,f=r.refKey,h=void 0===f?"ref":f,g=r.ref,m=n(r,Be);(void 0===t?{}:t).suppressRefError;var I,y=S.current.state,b={};m.disabled||((I={}).onChange=D(l,a,(function(e){d({type:8,inputValue:e.target.value})})),I.onKeyDown=D(u,(function(e){var t=H(e);t&&K[t]&&K[t](e)})),I.onBlur=D(c,(function(e){if(null!=s&&s.document&&y.isOpen&&!M.isMouseDown){var t=null===e.relatedTarget&&s.document.activeElement!==s.document.body;d({type:9,selectItem:!t})}})),I.onClick=D(p,(function(){d({type:10})})),b=I);return i(((o={})[h]=k(g,(function(e){v.current=e})),o["aria-activedescendant"]=y.isOpen&&y.highlightedIndex>-1?x.getItemId(y.highlightedIndex):"",o["aria-autocomplete"]="list",o["aria-controls"]=x.menuId,o["aria-expanded"]=y.isOpen,o["aria-labelledby"]=m&&m["aria-label"]?void 0:x.labelId,o.autoComplete="off",o.id=x.inputId,o.role="combobox",o.value=y.inputValue,o),b,m)}),[d,x,s,K,S,M,E]),F=t.useCallback((function(){d({type:15})}),[d]),_=t.useCallback((function(){d({type:17})}),[d]),N=t.useCallback((function(){d({type:16})}),[d]),j=t.useCallback((function(e){d({type:18,highlightedIndex:e})}),[d]),U=t.useCallback((function(e){d({type:19,selectedItem:e})}),[d]);return{getItemProps:B,getLabelProps:P,getMenuProps:V,getInputProps:L,getToggleButtonProps:A,toggleMenu:F,openMenu:N,closeMenu:_,setHighlightedIndex:j,setInputValue:t.useCallback((function(e){d({type:20,inputValue:e})}),[d]),selectItem:U,reset:t.useCallback((function(){d({type:21})}),[d]),highlightedIndex:f,isOpen:p,selectedItem:h,inputValue:g}}Ae.stateChangeTypes=Ee;var Le={activeIndex:-1,selectedItems:[]};function Fe(e,t){return ue(e,t,Le)}function _e(e,t){return re(e,t,Le)}function Ne(e){return{activeIndex:Fe(e,"activeIndex"),selectedItems:Fe(e,"selectedItems")}}function je(e){if(e.shiftKey||e.metaKey||e.ctrlKey||e.altKey)return!1;var t=e.target;return!(t instanceof HTMLInputElement&&""!==t.value)||0===t.selectionStart&&0===t.selectionEnd}function Ue(e,t){return e.selectedItems===t.selectedItems&&e.activeIndex===t.activeIndex}p.array,p.array,p.array,p.func,p.number,p.number,p.number,p.func,p.func,p.string,p.string;var We={itemToKey:oe.itemToKey,stateReducer:oe.stateReducer,environment:oe.environment,keyNavigationNext:"ArrowRight",keyNavigationPrevious:"ArrowLeft"},$e=Object.freeze({__proto__:null,DropdownClick:7,DropdownKeyDownBackspace:6,DropdownKeyDownNavigationPrevious:5,FunctionAddSelectedItem:8,FunctionRemoveSelectedItem:9,FunctionReset:12,FunctionSetActiveIndex:11,FunctionSetSelectedItems:10,SelectedItemClick:0,SelectedItemKeyDownBackspace:2,SelectedItemKeyDownDelete:1,SelectedItemKeyDownNavigationNext:3,SelectedItemKeyDownNavigationPrevious:4});function qe(e,t){var n,o=t.type,r=t.index,u=t.props,s=t.selectedItem,l=e.activeIndex,a=e.selectedItems;switch(o){case 0:n={activeIndex:r};break;case 4:n={activeIndex:l-1<0?0:l-1};break;case 3:n={activeIndex:l+1>=a.length?-1:l+1};break;case 2:case 1:if(l<0)break;var c=l;1===a.length?c=-1:l===a.length-1&&(c=a.length-2),n=i({selectedItems:[].concat(a.slice(0,l),a.slice(l+1))},{activeIndex:c});break;case 5:n={activeIndex:a.length-1};break;case 6:n={selectedItems:a.slice(0,a.length-1)};break;case 8:n={selectedItems:[].concat(a,[s])};break;case 7:n={activeIndex:-1};break;case 9:var d=l,p=a.findIndex((function(e){return u.itemToKey(e)===u.itemToKey(s)}));if(p<0)break;1===a.length?d=-1:p===a.length-1&&(d=a.length-2),n={selectedItems:[].concat(a.slice(0,p),a.slice(p+1)),activeIndex:d};break;case 10:n={selectedItems:t.selectedItems};break;case 11:n={activeIndex:t.activeIndex};break;case 12:n={activeIndex:_e(u,"activeIndex"),selectedItems:_e(u,"selectedItems")};break;default:throw new Error("Reducer called without proper action type.")}return i({},e,n)}var ze=["refKey","ref","onClick","onKeyDown","selectedItem","index"],Ye=["refKey","ref","onKeyDown","onClick","preventKeyAction"];function Xe(e){void 0===e&&(e={});var o=i({},We,e),r=o.getA11yStatusMessage,u=o.environment,s=o.keyNavigationNext,l=o.keyNavigationPrevious,a=ie(qe,o,Ne,Ue),c=a[0],d=a[1],p=c.activeIndex,f=c.selectedItems,h=ge(),g=t.useRef(null),m=t.useRef();m.current=[];var I=te({state:c,props:o});de(r,c,[p,f],u),t.useEffect((function(){h||(-1===p&&g.current?g.current.focus():m.current[p]&&m.current[p].focus())}),[p]);var v=ce(),y=t.useMemo((function(){var e;return(e={})[l]=function(){d({type:4})},e[s]=function(){d({type:3})},e.Delete=function(){d({type:1})},e.Backspace=function(){d({type:2})},e}),[d,s,l]),b=t.useMemo((function(){var e;return(e={})[l]=function(e){je(e)&&d({type:5})},e.Backspace=function(e){je(e)&&d({type:6})},e}),[d,l]);return{getSelectedItemProps:t.useCallback((function(e){var t,o=void 0===e?{}:e,r=o.refKey,u=void 0===r?"ref":r,s=o.ref,l=o.onClick,a=o.onKeyDown,c=o.selectedItem,p=o.index,f=n(o,ze),h=I.current.state,g=Z(c,p,h.selectedItems,"Pass either item or index to getSelectedItemProps!")[1],v=g>-1&&g===h.activeIndex;return i(((t={})[u]=k(s,(function(e){e&&m.current.push(e)})),t.tabIndex=v?0:-1,t.onClick=D(l,(function(){d({type:0,index:g})})),t.onKeyDown=D(a,(function(e){var t=H(e);t&&y[t]&&y[t](e)})),t),f)}),[d,I,y]),getDropdownProps:t.useCallback((function(e,t){var o,r=void 0===e?{}:e,u=r.refKey,s=void 0===u?"ref":u,l=r.ref,a=r.onKeyDown,c=r.onClick,p=r.preventKeyAction,f=void 0!==p&&p,h=n(r,Ye);return(void 0===t?{}:t).suppressRefError,i(((o={})[s]=k(l,(function(e){e&&(g.current=e)})),o),!f&&{onKeyDown:D(a,(function(e){var t=H(e);t&&b[t]&&b[t](e)})),onClick:D(c,(function(){d({type:7})}))},h)}),[d,b,v]),addSelectedItem:t.useCallback((function(e){d({type:8,selectedItem:e})}),[d]),removeSelectedItem:t.useCallback((function(e){d({type:9,selectedItem:e})}),[d]),setSelectedItems:t.useCallback((function(e){d({type:10,selectedItems:e})}),[d]),setActiveIndex:t.useCallback((f