ent = scrollTarget.current, scrollTop = _scrollTarget$current.scrollTop, scrollHeight = _scrollTarget$current.scrollHeight, clientHeight = _scrollTarget$current.clientHeight; var target = scrollTarget.current; var isDeltaPositive = delta > 0; var availableScroll = scrollHeight - clientHeight - scrollTop; var shouldCancelScroll = false; if (availableScroll > delta && isBottom.current) { if (onBottomLeave) onBottomLeave(event); isBottom.current = false; } if (isDeltaPositive && isTop.current) { if (onTopLeave) onTopLeave(event); isTop.current = false; } if (isDeltaPositive && delta > availableScroll) { if (onBottomArrive && !isBottom.current) { onBottomArrive(event); } target.scrollTop = scrollHeight; shouldCancelScroll = true; isBottom.current = true; } else if (!isDeltaPositive && -delta > scrollTop) { if (onTopArrive && !isTop.current) { onTopArrive(event); } target.scrollTop = 0; shouldCancelScroll = true; isTop.current = true; } if (shouldCancelScroll) { cancelScroll(event); } }, [onBottomArrive, onBottomLeave, onTopArrive, onTopLeave]); var onWheel = React.useCallback(function(event) { handleEventDelta(event, event.deltaY); }, [handleEventDelta]); var onTouchStart = React.useCallback(function(event) { touchStart.current = event.changedTouches[0].clientY; }, []); var onTouchMove = React.useCallback(function(event) { var deltaY = touchStart.current - event.changedTouches[0].clientY; handleEventDelta(event, deltaY); }, [handleEventDelta]); var startListening = React.useCallback(function(el) { if (!el) return; var notPassive = supportsPassiveEvents ? { passive: false } : false; el.addEventListener("wheel", onWheel, notPassive); el.addEventListener("touchstart", onTouchStart, notPassive); el.addEventListener("touchmove", onTouchMove, notPassive); }, [onTouchMove, onTouchStart, onWheel]); var stopListening = React.useCallback(function(el) { if (!el) return; el.removeEventListener("wheel", onWheel, false); el.removeEventListener("touchstart", onTouchStart, false); el.removeEventListener("touchmove", onTouchMove, false); }, [onTouchMove, onTouchStart, onWheel]); React.useEffect(function() { if (!isEnabled) return; var element = scrollTarget.current; startListening(element); return function() { stopListening(element); }; }, [isEnabled, startListening, stopListening]); return function(element) { scrollTarget.current = element; }; } var STYLE_KEYS = ["boxSizing", "height", "overflow", "paddingRight", "position"]; var LOCK_STYLES = { boxSizing: "border-box", // account for possible declaration `width: 100%;` on body overflow: "hidden", position: "relative", height: "100%" }; function preventTouchMove(e2) { if (e2.cancelable) e2.preventDefault(); } function allowTouchMove(e2) { e2.stopPropagation(); } function preventInertiaScroll() { var top = this.scrollTop; var totalScroll = this.scrollHeight; var currentScroll = top + this.offsetHeight; if (top === 0) { this.scrollTop = 1; } else if (currentScroll === totalScroll) { this.scrollTop = top - 1; } } function isTouchDevice() { return "ontouchstart" in window || navigator.maxTouchPoints; } var canUseDOM = !!(typeof window !== "undefined" && window.document && window.document.createElement); var activeScrollLocks = 0; var listenerOptions = { capture: false, passive: false }; function useScrollLock(_ref3) { var isEnabled = _ref3.isEnabled, _ref$accountForScroll = _ref3.accountForScrollbars, accountForScrollbars = _ref$accountForScroll === void 0 ? true : _ref$accountForScroll; var originalStyles = React.useRef({}); var scrollTarget = React.useRef(null); var addScrollLock = React.useCallback(function(touchScrollTarget) { if (!canUseDOM) return; var target = document.body; var targetStyle = target && target.style; if (accountForScrollbars) { STYLE_KEYS.forEach(function(key) { var val = targetStyle && targetStyle[key]; originalStyles.current[key] = val; }); } if (accountForScrollbars && activeScrollLocks < 1) { var currentPadding = parseInt(originalStyles.current.paddingRight, 10) || 0; var clientWidth = document.body ? document.body.clientWidth : 0; var adjustedPadding = window.innerWidth - clientWidth + currentPadding || 0; Object.keys(LOCK_STYLES).forEach(function(key) { var val = LOCK_STYLES[key]; if (targetStyle) { targetStyle[key] = val; } }); if (targetStyle) { targetStyle.paddingRight = "".concat(adjustedPadding, "px"); } } if (target && isTouchDevice()) { target.addEventListener("touchmove", preventTouchMove, listenerOptions); if (touchScrollTarget) { touchScrollTarget.addEventListener("touchstart", preventInertiaScroll, listenerOptions); touchScrollTarget.addEventListener("touchmove", allowTouchMove, listenerOptions); } } activeScrollLocks += 1; }, [accountForScrollbars]); var removeScrollLock = React.useCallback(function(touchScrollTarget) { if (!canUseDOM) return; var target = document.body; var targetStyle = target && target.style; activeScrollLocks = Math.max(activeScrollLocks - 1, 0); if (accountForScrollbars && activeScrollLocks < 1) { STYLE_KEYS.forEach(function(key) { var val = originalStyles.current[key]; if (targetStyle) { targetStyle[key] = val; } }); } if (target && isTouchDevice()) { target.removeEventListener("touchmove", preventTouchMove, listenerOptions); if (touchScrollTarget) { touchScrollTarget.removeEventListener("touchstart", preventInertiaScroll, listenerOptions); touchScrollTarget.removeEventListener("touchmove", allowTouchMove, listenerOptions); } } }, [accountForScrollbars]); React.useEffect(function() { if (!isEnabled) return; var element = scrollTarget.current; addScrollLock(element); return function() { removeScrollLock(element); }; }, [isEnabled, addScrollLock, removeScrollLock]); return function(element) { scrollTarget.current = element; }; } var blurSelectInput = function blurSelectInput2(event) { var element = event.target; return element.ownerDocument.activeElement && element.ownerDocument.activeElement.blur(); }; var _ref2$1 = { name: "1kfdb0e", styles: "position:fixed;left:0;bottom:0;right:0;top:0" }; function ScrollManager(_ref3) { var children = _ref3.children, lockEnabled = _ref3.lockEnabled, _ref$captureEnabled = _ref3.captureEnabled, captureEnabled = _ref$captureEnabled === void 0 ? true : _ref$captureEnabled, onBottomArrive = _ref3.onBottomArrive, onBottomLeave = _ref3.onBottomLeave, onTopArrive = _ref3.onTopArrive, onTopLeave = _ref3.onTopLeave; var setScrollCaptureTarget = useScrollCapture({ isEnabled: captureEnabled, onBottomArrive, onBottomLeave, onTopArrive, onTopLeave }); var setScrollLockTarget = useScrollLock({ isEnabled: lockEnabled }); var targetRef = function targetRef2(element) { setScrollCaptureTarget(element); setScrollLockTarget(element); }; return jsx(React.Fragment, null, lockEnabled && jsx("div", { onClick: blurSelectInput, css: _ref2$1 }), children(targetRef)); } var _ref2 = { name: "1a0ro4n-requiredInput", styles: "label:requiredInput;opacity:0;pointer-events:none;position:absolute;bottom:0;left:0;right:0;width:100%" }; var RequiredInput = function RequiredInput2(_ref3) { var name = _ref3.name, onFocus2 = _ref3.onFocus; return jsx("input", { required: true, name, tabIndex: -1, "aria-hidden": "true", onFocus: onFocus2, css: _ref2, value: "", onChange: function onChange2() { } }); }; var RequiredInput$1 = RequiredInput; function testPlatform(re) { var _window$navigator$use; return typeof window !== "undefined" && window.navigator != null ? re.test(((_window$navigator$use = window.navigator["userAgentData"]) === null || _window$navigator$use === void 0 ? void 0 : _window$navigator$use.platform) || window.navigator.platform) : false; } function isIPhone() { return testPlatform(/^iPhone/i); } function isMac() { return testPlatform(/^Mac/i); } function isIPad() { return testPlatform(/^iPad/i) || // iPadOS 13 lies and says it's a Mac, but we can distinguish by detecting touch support. isMac() && navigator.maxTouchPoints > 1; } function isIOS() { return isIPhone() || isIPad(); } function isAppleDevice() { return isMac() || isIOS(); } var formatGroupLabel = function formatGroupLabel2(group) { return group.label; }; var getOptionLabel$1 = function getOptionLabel(option) { return option.label; }; var getOptionValue$1 = function getOptionValue(option) { return option.value; }; var isOptionDisabled = function isOptionDisabled2(option) { return !!option.isDisabled; }; var defaultStyles = { clearIndicator: clearIndicatorCSS, container: containerCSS, control: css$1, dropdownIndicator: dropdownIndicatorCSS, group: groupCSS, groupHeading: groupHeadingCSS, indicatorsContainer: indicatorsContainerCSS, indicatorSeparator: indicatorSeparatorCSS, input: inputCSS, loadingIndicator: loadingIndicatorCSS, loadingMessage: loadingMessageCSS, menu: menuCSS, menuList: menuListCSS, menuPortal: menuPortalCSS, multiValue: multiValueCSS, multiValueLabel: multiValueLabelCSS, multiValueRemove: multiValueRemoveCSS, noOptionsMessage: noOptionsMessageCSS, option: optionCSS, placeholder: placeholderCSS, singleValue: css2, valueContainer: valueContainerCSS }; var colors = { primary: "#2684FF", primary75: "#4C9AFF", primary50: "#B2D4FF", primary25: "#DEEBFF", danger: "#DE350B", dangerLight: "#FFBDAD", neutral0: "hsl(0, 0%, 100%)", neutral5: "hsl(0, 0%, 95%)", neutral10: "hsl(0, 0%, 90%)", neutral20: "hsl(0, 0%, 80%)", neutral30: "hsl(0, 0%, 70%)", neutral40: "hsl(0, 0%, 60%)", neutral50: "hsl(0, 0%, 50%)", neutral60: "hsl(0, 0%, 40%)", neutral70: "hsl(0, 0%, 30%)", neutral80: "hsl(0, 0%, 20%)", neutral90: "hsl(0, 0%, 10%)" }; var borderRadius = 4; var baseUnit = 4; var controlHeight = 38; var menuGutter = baseUnit * 2; var spacing = { baseUnit, controlHeight, menuGutter }; var defaultTheme = { borderRadius, colors, spacing }; var defaultProps = { "aria-live": "polite", backspaceRemovesValue: true, blurInputOnSelect: isTouchCapable(), captureMenuScroll: !isTouchCapable(), classNames: {}, closeMenuOnSelect: true, closeMenuOnScroll: false, components: {}, controlShouldRenderValue: true, escapeClearsValue: false, filterOption: createFilter(), formatGroupLabel, getOptionLabel: getOptionLabel$1, getOptionValue: getOptionValue$1, isDisabled: false, isLoading: false, isMulti: false, isRtl: false, isSearchable: true, isOptionDisabled, loadingMessage: function loadingMessage() { return "Loading..."; }, maxMenuHeight: 300, minMenuHeight: 140, menuIsOpen: false, menuPlacement: "bottom", menuPosition: "absolute", menuShouldBlockScroll: false, menuShouldScrollIntoView: !isMobileDevice(), noOptionsMessage: function noOptionsMessage() { return "No options"; }, openMenuOnFocus: false, openMenuOnClick: true, options: [], pageSize: 5, placeholder: "Select...", screenReaderStatus: function screenReaderStatus(_ref3) { var count = _ref3.count; return "".concat(count, " result").concat(count !== 1 ? "s" : "", " available"); }, styles: {}, tabIndex: 0, tabSelectsValue: true, unstyled: false }; function toCategorizedOption(props, option, selectValue, index2) { var isDisabled = _isOptionDisabled(props, option, selectValue); var isSelected = _isOptionSelected(props, option, selectValue); var label = getOptionLabel2(props, option); var value = getOptionValue2(props, option); return { type: "option", data: option, isDisabled, isSelected, label, value, index: index2 }; } function buildCategorizedOptions(props, selectValue) { return props.options.map(function(groupOrOption, groupOrOptionIndex) { if ("options" in groupOrOption) { var categorizedOptions = groupOrOption.options.map(function(option, optionIndex) { return toCategorizedOption(props, option, selectValue, optionIndex); }).filter(function(categorizedOption2) { return isFocusable(props, categorizedOption2); }); return categorizedOptions.length > 0 ? { type: "group", data: groupOrOption, options: categorizedOptions, index: groupOrOptionIndex } : void 0; } var categorizedOption = toCategorizedOption(props, groupOrOption, selectValue, groupOrOptionIndex); return isFocusable(props, categorizedOption) ? categorizedOption : void 0; }).filter(notNullish); } function buildFocusableOptionsFromCategorizedOptions(categorizedOptions) { return categorizedOptions.reduce(function(optionsAccumulator, categorizedOption) { if (categorizedOption.type === "group") { optionsAccumulator.push.apply(optionsAccumulator, _toConsumableArray(categorizedOption.options.map(function(option) { return option.data; }))); } else { optionsAccumulator.push(categorizedOption.data); } return optionsAccumulator; }, []); } function buildFocusableOptionsWithIds(categorizedOptions, optionId) { return categorizedOptions.reduce(function(optionsAccumulator, categorizedOption) { if (categorizedOption.type === "group") { optionsAccumulator.push.apply(optionsAccumulator, _toConsumableArray(categorizedOption.options.map(function(option) { return { data: option.data, id: "".concat(optionId, "-").concat(categorizedOption.index, "-").concat(option.index) }; }))); } else { optionsAccumulator.push({ data: categorizedOption.data, id: "".concat(optionId, "-").concat(categorizedOption.index) }); } return optionsAccumulator; }, []); } function buildFocusableOptions(props, selectValue) { return buildFocusableOptionsFromCategorizedOptions(buildCategorizedOptions(props, selectValue)); } function isFocusable(props, categorizedOption) { var _props$inputValue = props.inputValue, inputValue = _props$inputValue === void 0 ? "" : _props$inputValue; var data = categorizedOption.data, isSelected = categorizedOption.isSelected, label = categorizedOption.label, value = categorizedOption.value; return (!shouldHideSelectedOptions(props) || !isSelected) && _filterOption(props, { label, value, data }, inputValue); } function getNextFocusedValue(state, nextSelectValue) { var focusedValue = state.focusedValue, lastSelectValue = state.selectValue; var lastFocusedIndex = lastSelectValue.indexOf(focusedValue); if (lastFocusedIndex > -1) { var nextFocusedIndex = nextSelectValue.indexOf(focusedValue); if (nextFocusedIndex > -1) { return focusedValue; } else if (lastFocusedIndex < nextSelectValue.length) { return nextSelectValue[lastFocusedIndex]; } } return null; } function getNextFocusedOption(state, options2) { var lastFocusedOption = state.focusedOption; return lastFocusedOption && options2.indexOf(lastFocusedOption) > -1 ? lastFocusedOption : options2[0]; } var getFocusedOptionId = function getFocusedOptionId2(focusableOptionsWithIds, focusedOption) { var _focusableOptionsWith; var focusedOptionId = (_focusableOptionsWith = focusableOptionsWithIds.find(function(option) { return option.data === focusedOption; })) === null || _focusableOptionsWith === void 0 ? void 0 : _focusableOptionsWith.id; return focusedOptionId || null; }; var getOptionLabel2 = function getOptionLabel3(props, data) { return props.getOptionLabel(data); }; var getOptionValue2 = function getOptionValue3(props, data) { return props.getOptionValue(data); }; function _isOptionDisabled(props, option, selectValue) { return typeof props.isOptionDisabled === "function" ? props.isOptionDisabled(option, selectValue) : false; } function _isOptionSelected(props, option, selectValue) { if (selectValue.indexOf(option) > -1) return true; if (typeof props.isOptionSelected === "function") { return props.isOptionSelected(option, selectValue); } var candidate = getOptionValue2(props, option); return selectValue.some(function(i2) { return getOptionValue2(props, i2) === candidate; }); } function _filterOption(props, option, inputValue) { return props.filterOption ? props.filterOption(option, inputValue) : true; } var shouldHideSelectedOptions = function shouldHideSelectedOptions2(props) { var hideSelectedOptions = props.hideSelectedOptions, isMulti = props.isMulti; if (hideSelectedOptions === void 0) return isMulti; return hideSelectedOptions; }; var instanceId = 1; var Select$1 = /* @__PURE__ */ function(_Component) { _inherits(Select2, _Component); var _super = _createSuper(Select2); function Select2(_props) { var _this; _classCallCheck(this, Select2); _this = _super.call(this, _props); _this.state = { ariaSelection: null, focusedOption: null, focusedOptionId: null, focusableOptionsWithIds: [], focusedValue: null, inputIsHidden: false, isFocused: false, selectValue: [], clearFocusValueOnUpdate: false, prevWasFocused: false, inputIsHiddenAfterUpdate: void 0, prevProps: void 0, instancePrefix: "", isAppleDevice: false }; _this.blockOptionHover = false; _this.isComposing = false; _this.commonProps = void 0; _this.initialTouchX = 0; _this.initialTouchY = 0; _this.openAfterFocus = false; _this.scrollToFocusedOptionOnUpdate = false; _this.userIsDragging = void 0; _this.controlRef = null; _this.getControlRef = function(ref) { _this.controlRef = ref; }; _this.focusedOptionRef = null; _this.getFocusedOptionRef = function(ref) { _this.focusedOptionRef = ref; }; _this.menuListRef = null; _this.getMenuListRef = function(ref) { _this.menuListRef = ref; }; _this.inputRef = null; _this.getInputRef = function(ref) { _this.inputRef = ref; }; _this.focus = _this.focusInput; _this.blur = _this.blurInput; _this.onChange = function(newValue, actionMeta) { var _this$props = _this.props, onChange2 = _this$props.onChange, name = _this$props.name; actionMeta.name = name; _this.ariaOnChange(newValue, actionMeta); onChange2(newValue, actionMeta); }; _this.setValue = function(newValue, action, option) { var _this$props2 = _this.props, closeMenuOnSelect = _this$props2.closeMenuOnSelect, isMulti = _this$props2.isMulti, inputValue = _this$props2.inputValue; _this.onInputChange("", { action: "set-value", prevInputValue: inputValue }); if (closeMenuOnSelect) { _this.setState({ inputIsHiddenAfterUpdate: !isMulti }); _this.onMenuClose(); } _this.setState({ clearFocusValueOnUpdate: true }); _this.onChange(newValue, { action, option }); }; _this.selectOption = function(newValue) { var _this$props3 = _this.props, blurInputOnSelect = _this$props3.blurInputOnSelect, isMulti = _this$props3.isMulti, name = _this$props3.name; var selectValue = _this.state.selectValue; var deselected = isMulti && _this.isOptionSelected(newValue, selectValue); var isDisabled = _this.isOptionDisabled(newValue, selectValue); if (deselected) { var candidate = _this.getOptionValue(newValue); _this.setValue(multiValueAsValue(selectValue.filter(function(i2) { return _this.getOptionValue(i2) !== candidate; })), "deselect-option", newValue); } else if (!isDisabled) { if (isMulti) { _this.setValue(multiValueAsValue([].concat(_toConsumableArray(selectValue), [newValue])), "select-option", newValue); } else { _this.setValue(singleValueAsValue(newValue), "select-option"); } } else { _this.ariaOnChange(singleValueAsValue(newValue), { action: "select-option", option: newValue, name }); return; } if (blurInputOnSelect) { _this.blurInput(); } }; _this.removeValue = function(removedValue) { var isMulti = _this.props.isMulti; var selectValue = _this.state.selectValue; var candidate = _this.getOptionValue(removedValue); var newValueArray = selectValue.filter(function(i2) { return _this.getOptionValue(i2) !== candidate; }); var newValue = valueTernary(isMulti, newValueArray, newValueArray[0] || null); _this.onChange(newValue, { action: "remove-value", removedValue }); _this.focusInput(); }; _this.clearValue = function() { var selectValue = _this.state.selectValue; _this.onChange(valueTernary(_this.props.isMulti, [], null), { action: "clear", removedValues: selectValue }); }; _this.popValue = function() { var isMulti = _this.props.isMulti; var selectValue = _this.state.selectValue; var lastSelectedValue = selectValue[selectValue.length - 1]; var newValueArray = selectValue.slice(0, selectValue.length - 1); var newValue = valueTernary(isMulti, newValueArray, newValueArray[0] || null); if (lastSelectedValue) { _this.onChange(newValue, { action: "pop-value", removedValue: lastSelectedValue }); } }; _this.getFocusedOptionId = function(focusedOption) { return getFocusedOptionId(_this.state.focusableOptionsWithIds, focusedOption); }; _this.getFocusableOptionsWithIds = function() { return buildFocusableOptionsWithIds(buildCategorizedOptions(_this.props, _this.state.selectValue), _this.getElementId("option")); }; _this.getValue = function() { return _this.state.selectValue; }; _this.cx = function() { for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { args[_key] = arguments[_key]; } return classNames.apply(void 0, [_this.props.classNamePrefix].concat(args)); }; _this.getOptionLabel = function(data) { return getOptionLabel2(_this.props, data); }; _this.getOptionValue = function(data) { return getOptionValue2(_this.props, data); }; _this.getStyles = function(key, props) { var unstyled = _this.props.unstyled; var base = defaultStyles[key](props, unstyled); base.boxSizing = "border-box"; var custom = _this.props.styles[key]; return custom ? custom(base, props) : base; }; _this.getClassNames = function(key, props) { var _this$props$className, _this$props$className2; return (_this$props$className = (_this$props$className2 = _this.props.classNames)[key]) === null || _this$props$className === void 0 ? void 0 : _this$props$className.call(_this$props$className2, props); }; _this.getElementId = function(element) { return "".concat(_this.state.instancePrefix, "-").concat(element); }; _this.getComponents = function() { return defaultComponents(_this.props); }; _this.buildCategorizedOptions = function() { return buildCategorizedOptions(_this.props, _this.state.selectValue); }; _this.getCategorizedOptions = function() { return _this.props.menuIsOpen ? _this.buildCategorizedOptions() : []; }; _this.buildFocusableOptions = function() { return buildFocusableOptionsFromCategorizedOptions(_this.buildCategorizedOptions()); }; _this.getFocusableOptions = function() { return _this.props.menuIsOpen ? _this.buildFocusableOptions() : []; }; _this.ariaOnChange = function(value, actionMeta) { _this.setState({ ariaSelection: _objectSpread2({ value }, actionMeta) }); }; _this.onMenuMouseDown = function(event) { if (event.button !== 0) { return; } event.stopPropagation(); event.preventDefault(); _this.focusInput(); }; _this.onMenuMouseMove = function(event) { _this.blockOptionHover = false; }; _this.onControlMouseDown = function(event) { if (event.defaultPrevented) { return; } var openMenuOnClick = _this.props.openMenuOnClick; if (!_this.state.isFocused) { if (openMenuOnClick) { _this.openAfterFocus = true; } _this.focusInput(); } else if (!_this.props.menuIsOpen) { if (openMenuOnClick) { _this.openMenu("first"); } } else { if (event.target.tagName !== "INPUT" && event.target.tagName !== "TEXTAREA") { _this.onMenuClose(); } } if (event.target.tagName !== "INPUT" && event.target.tagName !== "TEXTAREA") { event.preventDefault(); } }; _this.onDropdownIndicatorMouseDown = function(event) { if (event && event.type === "mousedown" && event.button !== 0) { return; } if (_this.props.isDisabled) return; var _this$props4 = _this.props, isMulti = _this$props4.isMulti, menuIsOpen = _this$props4.menuIsOpen; _this.focusInput(); if (menuIsOpen) { _this.setState({ inputIsHiddenAfterUpdate: !isMulti }); _this.onMenuClose(); } else { _this.openMenu("first"); } event.preventDefault(); }; _this.onClearIndicatorMouseDown = function(event) { if (event && event.type === "mousedown" && event.button !== 0) { return; } _this.clearValue(); event.preventDefault(); _this.openAfterFocus = false; if (event.type === "touchend") { _this.focusInput(); } else { setTimeout(function() { return _this.focusInput(); }); } }; _this.onScroll = function(event) { if (typeof _this.props.closeMenuOnScroll === "boolean") { if (event.target instanceof HTMLElement && isDocumentElement(event.target)) { _this.props.onMenuClose(); } } else if (typeof _this.props.closeMenuOnScroll === "function") { if (_this.props.closeMenuOnScroll(event)) { _this.props.onMenuClose(); } } }; _this.onCompositionStart = function() { _this.isComposing = true; }; _this.onCompositionEnd = function() { _this.isComposing = false; }; _this.onTouchStart = function(_ref22) { var touches = _ref22.touches; var touch = touches && touches.item(0); if (!touch) { return; } _this.initialTouchX = touch.clientX; _this.initialTouchY = touch.clientY; _this.userIsDragging = false; }; _this.onTouchMove = function(_ref3) { var touches = _ref3.touches; var touch = touches && touches.item(0); if (!touch) { return; } var deltaX = Math.abs(touch.clientX - _this.initialTouchX); var deltaY = Math.abs(touch.clientY - _this.initialTouchY); var moveThreshold = 5; _this.userIsDragging = deltaX > moveThreshold || deltaY > moveThreshold; }; _this.onTouchEnd = function(event) { if (_this.userIsDragging) return; if (_this.controlRef && !_this.controlRef.contains(event.target) && _this.menuListRef && !_this.menuListRef.contains(event.target)) { _this.blurInput(); } _this.initialTouchX = 0; _this.initialTouchY = 0; }; _this.onControlTouchEnd = function(event) { if (_this.userIsDragging) return; _this.onControlMouseDown(event); }; _this.onClearIndicatorTouchEnd = function(event) { if (_this.userIsDragging) return; _this.onClearIndicatorMouseDown(event); }; _this.onDropdownIndicatorTouchEnd = function(event) { if (_this.userIsDragging) return; _this.onDropdownIndicatorMouseDown(event); }; _this.handleInputChange = function(event) { var prevInputValue = _this.props.inputValue; var inputValue = event.currentTarget.value; _this.setState({ inputIsHiddenAfterUpdate: false }); _this.onInputChange(inputValue, { action: "input-change", prevInputValue }); if (!_this.props.menuIsOpen) { _this.onMenuOpen(); } }; _this.onInputFocus = function(event) { if (_this.props.onFocus) { _this.props.onFocus(event); } _this.setState({ inputIsHiddenAfterUpdate: false, isFocused: true }); if (_this.openAfterFocus || _this.props.openMenuOnFocus) { _this.openMenu("first"); } _this.openAfterFocus = false; }; _this.onInputBlur = function(event) { var prevInputValue = _this.props.inputValue; if (_this.menuListRef && _this.menuListRef.contains(document.activeElement)) { _this.inputRef.focus(); return; } if (_this.props.onBlur) { _this.props.onBlur(event); } _this.onInputChange("", { action: "input-blur", prevInputValue }); _this.onMenuClose(); _this.setState({ focusedValue: null, isFocused: false }); }; _this.onOptionHover = function(focusedOption) { if (_this.blockOptionHover || _this.state.focusedOption === focusedOption) { return; } var options2 = _this.getFocusableOptions(); var focusedOptionIndex = options2.indexOf(focusedOption); _this.setState({ focusedOption, focusedOptionId: focusedOptionIndex > -1 ? _this.getFocusedOptionId(focusedOption) : null }); }; _this.shouldHideSelectedOptions = function() { return shouldHideSelectedOptions(_this.props); }; _this.onValueInputFocus = function(e2) { e2.preventDefault(); e2.stopPropagation(); _this.focus(); }; _this.onKeyDown = function(event) { var _this$props5 = _this.props, isMulti = _this$props5.isMulti, backspaceRemovesValue = _this$props5.backspaceRemovesValue, escapeClearsValue = _this$props5.escapeClearsValue, inputValue = _this$props5.inputValue, isClearable = _this$props5.isClearable, isDisabled = _this$props5.isDisabled, menuIsOpen = _this$props5.menuIsOpen, onKeyDown = _this$props5.onKeyDown, tabSelectsValue = _this$props5.tabSelectsValue, openMenuOnFocus = _this$props5.openMenuOnFocus; var _this$state = _this.state, focusedOption = _this$state.focusedOption, focusedValue = _this$state.focusedValue, selectValue = _this$state.selectValue; if (isDisabled) return; if (typeof onKeyDown === "function") { onKeyDown(event); if (event.defaultPrevented) { return; } } _this.blockOptionHover = true; switch (event.key) { case "ArrowLeft": if (!isMulti || inputValue) return; _this.focusValue("previous"); break; case "ArrowRight": if (!isMulti || inputValue) return; _this.focusValue("next"); break; case "Delete": case "Backspace": if (inputValue) return; if (focusedValue) { _this.removeValue(focusedValue); } else { if (!backspaceRemovesValue) return; if (isMulti) { _this.popValue(); } else if (isClearable) { _this.clearValue(); } } break; case "Tab": if (_this.isComposing) return; if (event.shiftKey || !menuIsOpen || !tabSelectsValue || !focusedOption || // don't capture the event if the menu opens on focus and the focused // option is already selected; it breaks the flow of navigation openMenuOnFocus && _this.isOptionSelected(focusedOption, selectValue)) { return; } _this.selectOption(focusedOption); break; case "Enter": if (event.keyCode === 229) { break; } if (menuIsOpen) { if (!focusedOption) return; if (_this.isComposing) return; _this.selectOption(focusedOption); break; } return; case "Escape": if (menuIsOpen) { _this.setState({ inputIsHiddenAfterUpdate: false }); _this.onInputChange("", { action: "menu-close", prevInputValue: inputValue }); _this.onMenuClose(); } else if (isClearable && escapeClearsValue) { _this.clearValue(); } break; case " ": if (inputValue) { return; } if (!menuIsOpen) { _this.openMenu("first"); break; } if (!focusedOption) return; _this.selectOption(focusedOption); break; case "ArrowUp": if (menuIsOpen) { _this.focusOption("up"); } else { _this.openMenu("last"); } break; case "ArrowDown": if (menuIsOpen) { _this.focusOption("down"); } else { _this.openMenu("first"); } break; case "PageUp": if (!menuIsOpen) return; _this.focusOption("pageup"); break; case "PageDown": if (!menuIsOpen) return; _this.focusOption("pagedown"); break; case "Home": if (!menuIsOpen) return; _this.focusOption("first"); break; case "End": if (!menuIsOpen) return; _this.focusOption("last"); break; default: return; } event.preventDefault(); }; _this.state.instancePrefix = "react-select-" + (_this.props.instanceId || ++instanceId); _this.state.selectValue = cleanValue(_props.value); if (_props.menuIsOpen && _this.state.selectValue.length) { var focusableOptionsWithIds = _this.getFocusableOptionsWithIds(); var focusableOptions = _this.buildFocusableOptions(); var optionIndex = focusableOptions.indexOf(_this.state.selectValue[0]); _this.state.focusableOptionsWithIds = focusableOptionsWithIds; _this.state.focusedOption = focusableOptions[optionIndex]; _this.state.focusedOptionId = getFocusedOptionId(focusableOptionsWithIds, focusableOptions[optionIndex]); } return _this; } _createClass(Select2, [{ key: "componentDidMount", value: function componentDidMount() { this.startListeningComposition(); this.startListeningToTouch(); if (this.props.closeMenuOnScroll && document && document.addEventListener) { document.addEventListener("scroll", this.onScroll, true); } if (this.props.autoFocus) { this.focusInput(); } if (this.props.menuIsOpen && this.state.focusedOption && this.menuListRef && this.focusedOptionRef) { scrollIntoView(this.menuListRef, this.focusedOptionRef); } if (isAppleDevice()) { this.setState({ isAppleDevice: true }); } } }, { key: "componentDidUpdate", value: function componentDidUpdate(prevProps) { var _this$props6 = this.props, isDisabled = _this$props6.isDisabled, menuIsOpen = _this$props6.menuIsOpen; var isFocused = this.state.isFocused; if ( // ensure focus is restored correctly when the control becomes enabled isFocused && !isDisabled && prevProps.isDisabled || // ensure focus is on the Input when the menu opens isFocused && menuIsOpen && !prevProps.menuIsOpen ) { this.focusInput(); } if (isFocused && isDisabled && !prevProps.isDisabled) { this.setState({ isFocused: false }, this.onMenuClose); } else if (!isFocused && !isDisabled && prevProps.isDisabled && this.inputRef === document.activeElement) { this.setState({ isFocused: true }); } if (this.menuListRef && this.focusedOptionRef && this.scrollToFocusedOptionOnUpdate) { scrollIntoView(this.menuListRef, this.focusedOptionRef); this.scrollToFocusedOptionOnUpdate = false; } } }, { key: "componentWillUnmount", value: function componentWillUnmount() { this.stopListeningComposition(); this.stopListeningToTouch(); document.removeEventListener("scroll", this.onScroll, true); } // ============================== // Consumer Handlers // ============================== }, { key: "onMenuOpen", value: function onMenuOpen() { this.props.onMenuOpen(); } }, { key: "onMenuClose", value: function onMenuClose() { this.onInputChange("", { action: "menu-close", prevInputValue: this.props.inputValue }); this.props.onMenuClose(); } }, { key: "onInputChange", value: function onInputChange(newValue, actionMeta) { this.props.onInputChange(newValue, actionMeta); } // ============================== // Methods // ============================== }, { key: "focusInput", value: function focusInput() { if (!this.inputRef) return; this.inputRef.focus(); } }, { key: "blurInput", value: function blurInput() { if (!this.inputRef) return; this.inputRef.blur(); } // aliased for consumers }, { key: "openMenu", value: function openMenu(focusOption) { var _this2 = this; var _this$state2 = this.state, selectValue = _this$state2.selectValue, isFocused = _this$state2.isFocused; var focusableOptions = this.buildFocusableOptions(); var openAtIndex = focusOption === "first" ? 0 : focusableOptions.length - 1; if (!this.props.isMulti) { var selectedIndex = focusableOptions.indexOf(selectValue[0]); if (selectedIndex > -1) { openAtIndex = selectedIndex; } } this.scrollToFocusedOptionOnUpdate = !(isFocused && this.menuListRef); this.setState({ inputIsHiddenAfterUpdate: false, focusedValue: null, focusedOption: focusableOptions[openAtIndex], focusedOptionId: this.getFocusedOptionId(focusableOptions[openAtIndex]) }, function() { return _this2.onMenuOpen(); }); } }, { key: "focusValue", value: function focusValue(direction) { var _this$state3 = this.state, selectValue = _this$state3.selectValue, focusedValue = _this$state3.focusedValue; if (!this.props.isMulti) return; this.setState({ focusedOption: null }); var focusedIndex = selectValue.indexOf(focusedValue); if (!focusedValue) { focusedIndex = -1; } var lastIndex = selectValue.length - 1; var nextFocus = -1; if (!selectValue.length) return; switch (direction) { case "previous": if (focusedIndex === 0) { nextFocus = 0; } else if (focusedIndex === -1) { nextFocus = lastIndex; } else { nextFocus = focusedIndex - 1; } break; case "next": if (focusedIndex > -1 && focusedIndex < lastIndex) { nextFocus = focusedIndex + 1; } break; } this.setState({ inputIsHidden: nextFocus !== -1, focusedValue: selectValue[nextFocus] }); } }, { key: "focusOption", value: function focusOption() { var direction = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : "first"; var pageSize = this.props.pageSize; var focusedOption = this.state.focusedOption; var options2 = this.getFocusableOptions(); if (!options2.length) return; var nextFocus = 0; var focusedIndex = options2.indexOf(focusedOption); if (!focusedOption) { focusedIndex = -1; } if (direction === "up") { nextFocus = focusedIndex > 0 ? focusedIndex - 1 : options2.length - 1; } else if (direction === "down") { nextFocus = (focusedIndex + 1) % options2.length; } else if (direction === "pageup") { nextFocus = focusedIndex - pageSize; if (nextFocus < 0) nextFocus = 0; } else if (direction === "pagedown") { nextFocus = focusedIndex + pageSize; if (nextFocus > options2.length - 1) nextFocus = options2.length - 1; } else if (direction === "last") { nextFocus = options2.length - 1; } this.scrollToFocusedOptionOnUpdate = true; this.setState({ focusedOption: options2[nextFocus], focusedValue: null, focusedOptionId: this.getFocusedOptionId(options2[nextFocus]) }); } }, { key: "getTheme", value: ( // ============================== // Getters // ============================== function getTheme() { if (!this.props.theme) { return defaultTheme; } if (typeof this.props.theme === "function") { return this.props.theme(defaultTheme); } return _objectSpread2(_objectSpread2({}, defaultTheme), this.props.theme); } ) }, { key: "getCommonProps", value: function getCommonProps() { var clearValue = this.clearValue, cx = this.cx, getStyles = this.getStyles, getClassNames = this.getClassNames, getValue2 = this.getValue, selectOption = this.selectOption, setValue = this.setValue, props = this.props; var isMulti = props.isMulti, isRtl = props.isRtl, options2 = props.options; var hasValue = this.hasValue(); return { clearValue, cx, getStyles, getClassNames, getValue: getValue2, hasValue, isMulti, isRtl, options: options2, selectOption, selectProps: props, setValue, theme: this.getTheme() }; } }, { key: "hasValue", value: function hasValue() { var selectValue = this.state.selectValue; return selectValue.length > 0; } }, { key: "hasOptions", value: function hasOptions() { return !!this.getFocusableOptions().length; } }, { key: "isClearable", value: function isClearable() { var _this$props7 = this.props, isClearable2 = _this$props7.isClearable, isMulti = _this$props7.isMulti; if (isClearable2 === void 0) return isMulti; return isClearable2; } }, { key: "isOptionDisabled", value: function isOptionDisabled3(option, selectValue) { return _isOptionDisabled(this.props, option, selectValue); } }, { key: "isOptionSelected", value: function isOptionSelected(option, selectValue) { return _isOptionSelected(this.props, option, selectValue); } }, { key: "filterOption", value: function filterOption(option, inputValue) { return _filterOption(this.props, option, inputValue); } }, { key: "formatOptionLabel", value: function formatOptionLabel(data, context) { if (typeof this.props.formatOptionLabel === "function") { var _inputValue = this.props.inputValue; var _selectValue = this.state.selectValue; return this.props.formatOptionLabel(data, { context, inputValue: _inputValue, selectValue: _selectValue }); } else { return this.getOptionLabel(data); } } }, { key: "formatGroupLabel", value: function formatGroupLabel3(data) { return this.props.formatGroupLabel(data); } // ============================== // Mouse Handlers // ============================== }, { key: "startListeningComposition", value: ( // ============================== // Composition Handlers // ============================== function startListeningComposition() { if (document && document.addEventListener) { document.addEventListener("compositionstart", this.onCompositionStart, false); document.addEventListener("compositionend", this.onCompositionEnd, false); } } ) }, { key: "stopListeningComposition", value: function stopListeningComposition() { if (document && document.removeEventListener) { document.removeEventListener("compositionstart", this.onCompositionStart); document.removeEventListener("compositionend", this.onCompositionEnd); } } }, { key: "startListeningToTouch", value: ( // ============================== // Touch Handlers // ============================== function startListeningToTouch() { if (document && document.addEventListener) { document.addEventListener("touchstart", this.onTouchStart, false); document.addEventListener("touchmove", this.onTouchMove, false); document.addEventListener("touchend", this.onTouchEnd, false); } } ) }, { key: "stopListeningToTouch", value: function stopListeningToTouch() { if (document && document.removeEventListener) { document.removeEventListener("touchstart", this.onTouchStart); document.removeEventListener("touchmove", this.onTouchMove); document.removeEventListener("touchend", this.onTouchEnd); } } }, { key: "renderInput", value: ( // ============================== // Renderers // ============================== function renderInput() { var _this$props8 = this.props, isDisabled = _this$props8.isDisabled, isSearchable = _this$props8.isSearchable, inputId = _this$props8.inputId, inputValue = _this$props8.inputValue, tabIndex = _this$props8.tabIndex, form = _this$props8.form, menuIsOpen = _this$props8.menuIsOpen, required = _this$props8.required; var _this$getComponents = this.getComponents(), Input2 = _this$getComponents.Input; var _this$state4 = this.state, inputIsHidden = _this$state4.inputIsHidden, ariaSelection = _this$state4.ariaSelection; var commonProps = this.commonProps; var id = inputId || this.getElementId("input"); var ariaAttributes = _objectSpread2(_objectSpread2(_objectSpread2({ "aria-autocomplete": "list", "aria-expanded": menuIsOpen, "aria-haspopup": true, "aria-errormessage": this.props["aria-errormessage"], "aria-invalid": this.props["aria-invalid"], "aria-label": this.props["aria-label"], "aria-labelledby": this.props["aria-labelledby"], "aria-required": required, role: "combobox", "aria-activedescendant": this.state.isAppleDevice ? void 0 : this.state.focusedOptionId || "" }, menuIsOpen && { "aria-controls": this.getElementId("listbox") }), !isSearchable && { "aria-readonly": true }), this.hasValue() ? (ariaSelection === null || ariaSelection === void 0 ? void 0 : ariaSelection.action) === "initial-input-focus" && { "aria-describedby": this.getElementId("live-region") } : { "aria-describedby": this.getElementId("placeholder") }); if (!isSearchable) { return /* @__PURE__ */ React__namespace.createElement(DummyInput, _extends({ id, innerRef: this.getInputRef, onBlur: this.onInputBlur, onChange: noop, onFocus: this.onInputFocus, disabled: isDisabled, tabIndex, inputMode: "none", form, value: "" }, ariaAttributes)); } return /* @__PURE__ */ React__namespace.createElement(Input2, _extends({}, commonProps, { autoCapitalize: "none", autoComplete: "off", autoCorrect: "off", id, innerRef: this.getInputRef, isDisabled, isHidden: inputIsHidden, onBlur: this.onInputBlur, onChange: this.handleInputChange, onFocus: this.onInputFocus, spellCheck: "false", tabIndex, form, type: "text", value: inputValue }, ariaAttributes)); } ) }, { key: "renderPlaceholderOrValue", value: function renderPlaceholderOrValue() { var _this3 = this; var _this$getComponents2 = this.getComponents(), MultiValue2 = _this$getComponents2.MultiValue, MultiValueContainer2 = _this$getComponents2.MultiValueContainer, MultiValueLabel2 = _this$getComponents2.MultiValueLabel, MultiValueRemove2 = _this$getComponents2.MultiValueRemove, SingleValue2 = _this$getComponents2.SingleValue, Placeholder2 = _this$getComponents2.Placeholder; var commonProps = this.commonProps; var _this$props9 = this.props, controlShouldRenderValue = _this$props9.controlShouldRenderValue, isDisabled = _this$props9.isDisabled, isMulti = _this$props9.isMulti, inputValue = _this$props9.inputValue, placeholder = _this$props9.placeholder; var _this$state5 = this.state, selectValue = _this$state5.selectValue, focusedValue = _this$state5.focusedValue, isFocused = _this$state5.isFocused; if (!this.hasValue() || !controlShouldRenderValue) { return inputValue ? null : /* @__PURE__ */ React__namespace.createElement(Placeholder2, _extends({}, commonProps, { key: "placeholder", isDisabled, isFocused, innerProps: { id: this.getElementId("placeholder") } }), placeholder); } if (isMulti) { return selectValue.map(function(opt, index2) { var isOptionFocused = opt === focusedValue; var key = "".concat(_this3.getOptionLabel(opt), "-").concat(_this3.getOptionValue(opt)); return /* @__PURE__ */ React__namespace.createElement(MultiValue2, _extends({}, commonProps, { components: { Container: MultiValueContainer2, Label: MultiValueLabel2, Remove: MultiValueRemove2 }, isFocused: isOptionFocused, isDisabled, key, index: index2, removeProps: { onClick: function onClick() { return _this3.removeValue(opt); }, onTouchEnd: function onTouchEnd() { return _this3.removeValue(opt); }, onMouseDown: function onMouseDown(e2) { e2.preventDefault(); } }, data: opt }), _this3.formatOptionLabel(opt, "value")); }); } if (i