Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

downshift

Package Overview
Dependencies
Maintainers
1
Versions
354
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

downshift - npm Package Compare versions

Comparing version 1.0.0-beta.21 to 1.0.0-beta.22

52

dist/downshift.cjs.js

@@ -199,15 +199,8 @@ 'use strict';

/**
* Get the closest element that scrolls
* @param {HTMLElement} node - the child element to start searching for scroll parent at
* @param {HTMLElement} rootNode - the root element of the component
* @return {HTMLElement} the closest parentNode that scrolls
*/
function getClosestScrollParent(node, rootNode) {
if (node !== null && node !== rootNode) {
var isScrollable = node.scrollHeight > node.clientHeight;
if (isScrollable) {
function findParent(finder, node, rootNode) {
if (node !== null && node !== rootNode.parentNode) {
if (finder(node)) {
return node;
} else {
return getClosestScrollParent(node.parentNode);
return findParent(finder, node.parentNode, rootNode);
}

@@ -220,2 +213,12 @@ } else {

/**
* Get the closest element that scrolls
* @param {HTMLElement} node - the child element to start searching for scroll parent at
* @param {HTMLElement} rootNode - the root element of the component
* @return {HTMLElement} the closest parentNode that scrolls
*/
var getClosestScrollParent = findParent.bind(null, function (node) {
return node.scrollHeight > node.clientHeight;
});
/**
* Scroll node into view if necessary

@@ -226,3 +229,3 @@ * @param {HTMLElement} node - the element that should scroll into view

*/
function scrollIntoView(node, rootNode, alignToTop) {
function scrollIntoView(node, rootNode) {
var scrollParent = getClosestScrollParent(node, rootNode);

@@ -239,3 +242,3 @@ if (scrollParent === null) {

var nodeTop = nodeOffsetTop - scrollParentTop;
if (alignToTop || nodeTop < scrollParent.scrollTop) {
if (nodeTop < scrollParent.scrollTop) {
// the item is above the scrollable area

@@ -417,9 +420,2 @@ scrollParent.scrollTop = nodeTop;

_this.highlightSelectedItem = function () {
var highlightedIndex = _this.getIndexFromItem(_this.getState().selectedItem) || 0;
_this.internalSetState({ highlightedIndex: highlightedIndex }, function () {
_this.maybeScrollToHighlightedElement(highlightedIndex, true);
});
};
_this.highlightIndex = function (index) {

@@ -524,5 +520,8 @@ _this.openMenu(function () {

}
var index = _this.getItemIndexFromId(target.getAttribute('id'));
if (isNumber(index)) {
_this.selectItemAtIndex(index);
var itemParent = findParent(function (node) {
var index = _this.getItemIndexFromId(node.getAttribute('id'));
return isNumber(index);
}, target, _this._rootNode);
if (itemParent) {
_this.selectItemAtIndex(_this.getItemIndexFromId(itemParent.getAttribute('id')));
}

@@ -789,6 +788,6 @@ };

key: 'maybeScrollToHighlightedElement',
value: function maybeScrollToHighlightedElement(highlightedIndex, alignToTop) {
value: function maybeScrollToHighlightedElement(highlightedIndex) {
var node = this.getItemNodeFromIndex(highlightedIndex);
var rootNode = this._rootNode;
scrollIntoView(node, rootNode, alignToTop);
scrollIntoView(node, rootNode);
}

@@ -1060,3 +1059,4 @@

},
onStateChange: function onStateChange() {} };
onStateChange: function onStateChange() {},
onChange: function onChange() {} };
Downshift$1.stateChangeTypes = {

@@ -1063,0 +1063,0 @@ mouseUp: '__autocomplete_mouseup__'

@@ -194,15 +194,8 @@ import React, { Component } from 'react';

/**
* Get the closest element that scrolls
* @param {HTMLElement} node - the child element to start searching for scroll parent at
* @param {HTMLElement} rootNode - the root element of the component
* @return {HTMLElement} the closest parentNode that scrolls
*/
function getClosestScrollParent(node, rootNode) {
if (node !== null && node !== rootNode) {
var isScrollable = node.scrollHeight > node.clientHeight;
if (isScrollable) {
function findParent(finder, node, rootNode) {
if (node !== null && node !== rootNode.parentNode) {
if (finder(node)) {
return node;
} else {
return getClosestScrollParent(node.parentNode);
return findParent(finder, node.parentNode, rootNode);
}

@@ -215,2 +208,12 @@ } else {

/**
* Get the closest element that scrolls
* @param {HTMLElement} node - the child element to start searching for scroll parent at
* @param {HTMLElement} rootNode - the root element of the component
* @return {HTMLElement} the closest parentNode that scrolls
*/
var getClosestScrollParent = findParent.bind(null, function (node) {
return node.scrollHeight > node.clientHeight;
});
/**
* Scroll node into view if necessary

@@ -221,3 +224,3 @@ * @param {HTMLElement} node - the element that should scroll into view

*/
function scrollIntoView(node, rootNode, alignToTop) {
function scrollIntoView(node, rootNode) {
var scrollParent = getClosestScrollParent(node, rootNode);

@@ -234,3 +237,3 @@ if (scrollParent === null) {

var nodeTop = nodeOffsetTop - scrollParentTop;
if (alignToTop || nodeTop < scrollParent.scrollTop) {
if (nodeTop < scrollParent.scrollTop) {
// the item is above the scrollable area

@@ -412,9 +415,2 @@ scrollParent.scrollTop = nodeTop;

_this.highlightSelectedItem = function () {
var highlightedIndex = _this.getIndexFromItem(_this.getState().selectedItem) || 0;
_this.internalSetState({ highlightedIndex: highlightedIndex }, function () {
_this.maybeScrollToHighlightedElement(highlightedIndex, true);
});
};
_this.highlightIndex = function (index) {

@@ -519,5 +515,8 @@ _this.openMenu(function () {

}
var index = _this.getItemIndexFromId(target.getAttribute('id'));
if (isNumber(index)) {
_this.selectItemAtIndex(index);
var itemParent = findParent(function (node) {
var index = _this.getItemIndexFromId(node.getAttribute('id'));
return isNumber(index);
}, target, _this._rootNode);
if (itemParent) {
_this.selectItemAtIndex(_this.getItemIndexFromId(itemParent.getAttribute('id')));
}

@@ -784,6 +783,6 @@ };

key: 'maybeScrollToHighlightedElement',
value: function maybeScrollToHighlightedElement(highlightedIndex, alignToTop) {
value: function maybeScrollToHighlightedElement(highlightedIndex) {
var node = this.getItemNodeFromIndex(highlightedIndex);
var rootNode = this._rootNode;
scrollIntoView(node, rootNode, alignToTop);
scrollIntoView(node, rootNode);
}

@@ -1055,3 +1054,4 @@

},
onStateChange: function onStateChange() {} };
onStateChange: function onStateChange() {},
onChange: function onChange() {} };
Downshift$1.stateChangeTypes = {

@@ -1058,0 +1058,0 @@ mouseUp: '__autocomplete_mouseup__'

@@ -225,15 +225,8 @@ 'use strict';

/**
* Get the closest element that scrolls
* @param {HTMLElement} node - the child element to start searching for scroll parent at
* @param {HTMLElement} rootNode - the root element of the component
* @return {HTMLElement} the closest parentNode that scrolls
*/
function getClosestScrollParent(node, rootNode) {
if (node !== null && node !== rootNode) {
var isScrollable = node.scrollHeight > node.clientHeight;
if (isScrollable) {
function findParent(finder, node, rootNode) {
if (node !== null && node !== rootNode.parentNode) {
if (finder(node)) {
return node;
} else {
return getClosestScrollParent(node.parentNode);
return findParent(finder, node.parentNode, rootNode);
}

@@ -246,2 +239,12 @@ } else {

/**
* Get the closest element that scrolls
* @param {HTMLElement} node - the child element to start searching for scroll parent at
* @param {HTMLElement} rootNode - the root element of the component
* @return {HTMLElement} the closest parentNode that scrolls
*/
var getClosestScrollParent = findParent.bind(null, function (node) {
return node.scrollHeight > node.clientHeight;
});
/**
* Scroll node into view if necessary

@@ -252,3 +255,3 @@ * @param {HTMLElement} node - the element that should scroll into view

*/
function scrollIntoView(node, rootNode, alignToTop) {
function scrollIntoView(node, rootNode) {
var scrollParent = getClosestScrollParent(node, rootNode);

@@ -265,3 +268,3 @@ if (scrollParent === null) {

var nodeTop = nodeOffsetTop - scrollParentTop;
if (alignToTop || nodeTop < scrollParent.scrollTop) {
if (nodeTop < scrollParent.scrollTop) {
// the item is above the scrollable area

@@ -443,9 +446,2 @@ scrollParent.scrollTop = nodeTop;

_this.highlightSelectedItem = function () {
var highlightedIndex = _this.getIndexFromItem(_this.getState().selectedItem) || 0;
_this.internalSetState({ highlightedIndex: highlightedIndex }, function () {
_this.maybeScrollToHighlightedElement(highlightedIndex, true);
});
};
_this.highlightIndex = function (index) {

@@ -550,5 +546,8 @@ _this.openMenu(function () {

}
var index = _this.getItemIndexFromId(target.getAttribute('id'));
if (isNumber(index)) {
_this.selectItemAtIndex(index);
var itemParent = findParent(function (node) {
var index = _this.getItemIndexFromId(node.getAttribute('id'));
return isNumber(index);
}, target, _this._rootNode);
if (itemParent) {
_this.selectItemAtIndex(_this.getItemIndexFromId(itemParent.getAttribute('id')));
}

@@ -815,6 +814,6 @@ };

key: 'maybeScrollToHighlightedElement',
value: function maybeScrollToHighlightedElement(highlightedIndex, alignToTop) {
value: function maybeScrollToHighlightedElement(highlightedIndex) {
var node = this.getItemNodeFromIndex(highlightedIndex);
var rootNode = this._rootNode;
scrollIntoView(node, rootNode, alignToTop);
scrollIntoView(node, rootNode);
}

@@ -1086,3 +1085,4 @@

},
onStateChange: function onStateChange() {} };
onStateChange: function onStateChange() {},
onChange: function onChange() {} };
Downshift$1.stateChangeTypes = {

@@ -1089,0 +1089,0 @@ mouseUp: '__autocomplete_mouseup__'

@@ -224,15 +224,8 @@ import { Component } from 'preact';

/**
* Get the closest element that scrolls
* @param {HTMLElement} node - the child element to start searching for scroll parent at
* @param {HTMLElement} rootNode - the root element of the component
* @return {HTMLElement} the closest parentNode that scrolls
*/
function getClosestScrollParent(node, rootNode) {
if (node !== null && node !== rootNode) {
var isScrollable = node.scrollHeight > node.clientHeight;
if (isScrollable) {
function findParent(finder, node, rootNode) {
if (node !== null && node !== rootNode.parentNode) {
if (finder(node)) {
return node;
} else {
return getClosestScrollParent(node.parentNode);
return findParent(finder, node.parentNode, rootNode);
}

@@ -245,2 +238,12 @@ } else {

/**
* Get the closest element that scrolls
* @param {HTMLElement} node - the child element to start searching for scroll parent at
* @param {HTMLElement} rootNode - the root element of the component
* @return {HTMLElement} the closest parentNode that scrolls
*/
var getClosestScrollParent = findParent.bind(null, function (node) {
return node.scrollHeight > node.clientHeight;
});
/**
* Scroll node into view if necessary

@@ -251,3 +254,3 @@ * @param {HTMLElement} node - the element that should scroll into view

*/
function scrollIntoView(node, rootNode, alignToTop) {
function scrollIntoView(node, rootNode) {
var scrollParent = getClosestScrollParent(node, rootNode);

@@ -264,3 +267,3 @@ if (scrollParent === null) {

var nodeTop = nodeOffsetTop - scrollParentTop;
if (alignToTop || nodeTop < scrollParent.scrollTop) {
if (nodeTop < scrollParent.scrollTop) {
// the item is above the scrollable area

@@ -442,9 +445,2 @@ scrollParent.scrollTop = nodeTop;

_this.highlightSelectedItem = function () {
var highlightedIndex = _this.getIndexFromItem(_this.getState().selectedItem) || 0;
_this.internalSetState({ highlightedIndex: highlightedIndex }, function () {
_this.maybeScrollToHighlightedElement(highlightedIndex, true);
});
};
_this.highlightIndex = function (index) {

@@ -549,5 +545,8 @@ _this.openMenu(function () {

}
var index = _this.getItemIndexFromId(target.getAttribute('id'));
if (isNumber(index)) {
_this.selectItemAtIndex(index);
var itemParent = findParent(function (node) {
var index = _this.getItemIndexFromId(node.getAttribute('id'));
return isNumber(index);
}, target, _this._rootNode);
if (itemParent) {
_this.selectItemAtIndex(_this.getItemIndexFromId(itemParent.getAttribute('id')));
}

@@ -814,6 +813,6 @@ };

key: 'maybeScrollToHighlightedElement',
value: function maybeScrollToHighlightedElement(highlightedIndex, alignToTop) {
value: function maybeScrollToHighlightedElement(highlightedIndex) {
var node = this.getItemNodeFromIndex(highlightedIndex);
var rootNode = this._rootNode;
scrollIntoView(node, rootNode, alignToTop);
scrollIntoView(node, rootNode);
}

@@ -1085,3 +1084,4 @@

},
onStateChange: function onStateChange() {} };
onStateChange: function onStateChange() {},
onChange: function onChange() {} };
Downshift$1.stateChangeTypes = {

@@ -1088,0 +1088,0 @@ mouseUp: '__autocomplete_mouseup__'

@@ -228,15 +228,8 @@ (function (global, factory) {

/**
* Get the closest element that scrolls
* @param {HTMLElement} node - the child element to start searching for scroll parent at
* @param {HTMLElement} rootNode - the root element of the component
* @return {HTMLElement} the closest parentNode that scrolls
*/
function getClosestScrollParent(node, rootNode) {
if (node !== null && node !== rootNode) {
var isScrollable = node.scrollHeight > node.clientHeight;
if (isScrollable) {
function findParent(finder, node, rootNode) {
if (node !== null && node !== rootNode.parentNode) {
if (finder(node)) {
return node;
} else {
return getClosestScrollParent(node.parentNode);
return findParent(finder, node.parentNode, rootNode);
}

@@ -249,2 +242,12 @@ } else {

/**
* Get the closest element that scrolls
* @param {HTMLElement} node - the child element to start searching for scroll parent at
* @param {HTMLElement} rootNode - the root element of the component
* @return {HTMLElement} the closest parentNode that scrolls
*/
var getClosestScrollParent = findParent.bind(null, function (node) {
return node.scrollHeight > node.clientHeight;
});
/**
* Scroll node into view if necessary

@@ -255,3 +258,3 @@ * @param {HTMLElement} node - the element that should scroll into view

*/
function scrollIntoView(node, rootNode, alignToTop) {
function scrollIntoView(node, rootNode) {
var scrollParent = getClosestScrollParent(node, rootNode);

@@ -268,3 +271,3 @@ if (scrollParent === null) {

var nodeTop = nodeOffsetTop - scrollParentTop;
if (alignToTop || nodeTop < scrollParent.scrollTop) {
if (nodeTop < scrollParent.scrollTop) {
// the item is above the scrollable area

@@ -446,9 +449,2 @@ scrollParent.scrollTop = nodeTop;

_this.highlightSelectedItem = function () {
var highlightedIndex = _this.getIndexFromItem(_this.getState().selectedItem) || 0;
_this.internalSetState({ highlightedIndex: highlightedIndex }, function () {
_this.maybeScrollToHighlightedElement(highlightedIndex, true);
});
};
_this.highlightIndex = function (index) {

@@ -553,5 +549,8 @@ _this.openMenu(function () {

}
var index = _this.getItemIndexFromId(target.getAttribute('id'));
if (isNumber(index)) {
_this.selectItemAtIndex(index);
var itemParent = findParent(function (node) {
var index = _this.getItemIndexFromId(node.getAttribute('id'));
return isNumber(index);
}, target, _this._rootNode);
if (itemParent) {
_this.selectItemAtIndex(_this.getItemIndexFromId(itemParent.getAttribute('id')));
}

@@ -818,6 +817,6 @@ };

key: 'maybeScrollToHighlightedElement',
value: function maybeScrollToHighlightedElement(highlightedIndex, alignToTop) {
value: function maybeScrollToHighlightedElement(highlightedIndex) {
var node = this.getItemNodeFromIndex(highlightedIndex);
var rootNode = this._rootNode;
scrollIntoView(node, rootNode, alignToTop);
scrollIntoView(node, rootNode);
}

@@ -1089,3 +1088,4 @@

},
onStateChange: function onStateChange() {} };
onStateChange: function onStateChange() {},
onChange: function onChange() {} };
Downshift$1.stateChangeTypes = {

@@ -1092,0 +1092,0 @@ mouseUp: '__autocomplete_mouseup__'

@@ -1,2 +0,2 @@

!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t(require("preact")):"function"==typeof define&&define.amd?define(["preact"],t):e.downshift=t(e.preact)}(this,function(e){"use strict";function t(){}function n(e){var t=k[k.length-1]===e;k=t?[].concat(P(k),[e]):[e],r().innerHTML=""+k.filter(Boolean).map(o).join("")}function o(e,t){return'<div style="display:'+(t===k.length-1?"block":"none")+';">'+e+"</div>"}function r(){return O||((O=document.createElement("div")).setAttribute("id","a11y-status-message"),O.setAttribute("role","status"),O.setAttribute("aria-live","assertive"),O.setAttribute("aria-relevant","additions text"),Object.assign(O.style,{border:"0",clip:"rect(0 0 0 0)",height:"1px",margin:"-1px",overflow:"hidden",padding:"0",position:"absolute",width:"1px"}),document.body.appendChild(O),O)}function i(e){return"function"==typeof e?e:u}function u(){}function l(e,t){return null!==e&&e!==t?e.scrollHeight>e.clientHeight?e:l(e.parentNode):null}function s(e,t,n){var o=l(e,t);if(null!==o){var r=getComputedStyle(o),i=o.getBoundingClientRect(),u=parseInt(r.borderTopWidth,10),s=i.top+u,a=e.getBoundingClientRect(),d=a.top+o.scrollTop-s;n||d<o.scrollTop?o.scrollTop=d:d+a.height>o.scrollTop+i.height&&(o.scrollTop=d+a.height-i.height)}}function a(e,t){var n=void 0;return function(){for(var o=arguments.length,r=Array(o),i=0;i<o;i++)r[i]=arguments[i];n&&clearTimeout(n),n=setTimeout(function(){n=null,e.apply(void 0,r)},t)}}function d(){for(var e=arguments.length,t=Array(e),n=0;n<e;n++)t[n]=arguments[n];return function(e){for(var n=arguments.length,o=Array(n>1?n-1:0),r=1;r<n;r++)o[r-1]=arguments[r];return t.some(function(t){return t&&t.apply(void 0,[e].concat(o)),e.defaultPrevented})}}function h(e){return e+"-"+H++}function p(){for(var e=arguments.length,t=Array(e),n=0;n<e;n++)t[n]=arguments[n];return t.find(function(e){return void 0!==e})}function c(e){return e===e&&"number"==typeof e}function f(e,t){return Object.keys(t).every(function(n){return e[n]===t[n]})}function g(e,t){var n=t.refKey,o="ref"!==n,r="string"!=typeof e.type;if(r&&!o)throw new Error("downshift: You returned a non-DOM element. You must specify a refKey in getRootProps");if(!r&&o)throw new Error('downshift: You returned a DOM element. You should not specify a refKey in getRootProps. You specified "'+n+'"');if(!e.props.hasOwnProperty(n))throw new Error('downshift: You must apply the ref prop "'+n+'" from getRootProps onto your root element.');if(!e.props.hasOwnProperty("onClick"))throw new Error('downshift: You must apply the "onClick" prop from getRootProps onto your root element.')}var m=e.default;m.Children={only:function(e){return e&&e[0]}},t.isRequired=t;var y={element:t,func:t,number:t,any:t,bool:t,string:t},I=function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")},v=function(){function e(e,t){for(var n=0;n<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,o.key,o)}}return function(t,n,o){return n&&e(t.prototype,n),o&&e(t,o),t}}(),w=function(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e},b=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var o in n)Object.prototype.hasOwnProperty.call(n,o)&&(e[o]=n[o])}return e},S=function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)},x=function(e,t){var n={};for(var o in e)t.indexOf(o)>=0||Object.prototype.hasOwnProperty.call(e,o)&&(n[o]=e[o]);return n},C=function(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t},P=function(e){if(Array.isArray(e)){for(var t=0,n=Array(e.length);t<e.length;t++)n[t]=e[t];return n}return Array.from(e)},O="undefined"==typeof document?null:document.getElementById("a11y-status-message"),k=[],H=1,M=function(e){function t(){var e;I(this,t);for(var o=arguments.length,r=Array(o),u=0;u<o;u++)r[u]=arguments[u];var l=C(this,(e=t.__proto__||Object.getPrototypeOf(t)).call.apply(e,[this].concat(r)));return l.input=null,l.items=[],l.previousResultCount=0,l.getItemFromIndex=function(e){return l.items&&l.items[0]?l.items[e]:null},l.getIndexFromItem=function(e){var t=l.items.findIndex(function(t){return t===e});return-1===t?null:t},l.getItemNodeFromIndex=function(e){return document.getElementById(l.getItemId(e))},l.setHighlightedIndex=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:l.props.defaultHighlightedIndex;l.internalSetState({highlightedIndex:e},function(){l.maybeScrollToHighlightedElement(e)})},l.highlightSelectedItem=function(){var e=l.getIndexFromItem(l.getState().selectedItem)||0;l.internalSetState({highlightedIndex:e},function(){l.maybeScrollToHighlightedElement(e,!0)})},l.highlightIndex=function(e){l.openMenu(function(){l.setHighlightedIndex(e)})},l.moveHighlightedIndex=function(e){l.getState().isOpen?l.changeHighlighedIndex(e):l.highlightIndex()},l.changeHighlighedIndex=function(e){var t=l.items.length-1;if(!(t<0)){var n=l.getState().highlightedIndex;null===n&&(n=e>0?-1:t+1);var o=n+e;o<0?o=t:o>t&&(o=0),l.setHighlightedIndex(o)}},l.clearSelection=function(){l.internalSetState({selectedItem:null,inputValue:"",isOpen:!1},function(){var e=document.getElementById(l.inputId);e&&e.focus&&e.focus()})},l.selectItem=function(e){l.reset(),l.internalSetState({selectedItem:e,inputValue:l.props.itemToString(e)})},l.selectItemAtIndex=function(e){if(null!==e){var t=l.getItemFromIndex(e);t&&l.selectItem(t)}},l.selectHighlightedItem=function(){return l.selectItemAtIndex(l.getState().highlightedIndex)},l.rootRef=function(e){return l._rootNode=e},l.getRootProps=function(){var e,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=t.refKey,o=void 0===n?"ref":n,r=t.onClick,i=x(t,["refKey","onClick"]);return l.getRootProps.called=!0,l.getRootProps.refKey=o,b((e={},w(e,o,l.rootRef),w(e,"onClick",d(r,l.root_handleClick)),e),i)},l.root_handleClick=function(e){e.preventDefault();var t=e.target;if(t){var n=l.getItemIndexFromId(t.getAttribute("id"));c(n)&&l.selectItemAtIndex(n)}},l.keyDownHandlers={ArrowDown:function(e){e.preventDefault();var t=e.shiftKey?5:1;this.moveHighlightedIndex(t)},ArrowUp:function(e){e.preventDefault();var t=e.shiftKey?-5:-1;this.moveHighlightedIndex(t)},Enter:function(e){e.preventDefault(),this.getState().isOpen&&this.selectHighlightedItem()},Escape:function(e){e.preventDefault(),this.reset()}},l.buttonKeyDownHandlers=b({},l.keyDownHandlers,{" ":function(e){e.preventDefault();var t=this.getState(),n=t.isOpen,o=t.highlightedIndex;n?null===o?this.closeMenu():this.selectHighlightedItem():this.openMenu()}}),l.getButtonProps=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=e.onClick,n=e.onKeyDown,o=x(e,["onClick","onKeyDown"]),r=l.getState().isOpen;return b({role:"button","aria-label":r?"close menu":"open menu","aria-expanded":r,"aria-haspopup":!0,onClick:d(t,l.button_handleClick),onKeyDown:d(n,l.button_handleKeyDown)},o)},l.button_handleKeyDown=function(e){l.buttonKeyDownHandlers[e.key]&&l.buttonKeyDownHandlers[e.key].call(l,e)},l.button_handleClick=function(e){e.preventDefault(),l.toggleMenu()},l.getLabelProps=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};if(l.getLabelProps.called=!0,l.getInputProps.called&&e.htmlFor&&e.htmlFor!==l.inputId)throw new Error('downshift: You provided the htmlFor of "'+e.htmlFor+'" for your label, but the id of your input is "'+l.inputId+'". You must either remove the id from your input or set the htmlFor of the label equal to the input id.');return l.inputId=p(l.inputId,e.htmlFor,h("downshift-input")),b({},e,{htmlFor:l.inputId})},l.getInputProps=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=e.onChange,n=e.onKeyDown,o=e.onBlur,r=x(e,["onChange","onKeyDown","onBlur"]);if(l.getInputProps.called=!0,l.getLabelProps.called&&r.id&&r.id!==l.inputId)throw new Error('downshift: You provided the id of "'+r.id+'" for your input, but the htmlFor of your label is "'+l.inputId+'". You must either remove the id from your input or set the htmlFor of the label equal to the input id.');l.inputId=p(l.inputId,r.id,h("downshift-input"));var i=l.getState(),u=i.inputValue,s=i.isOpen,a=i.highlightedIndex;return b({role:"combobox","aria-autocomplete":"list","aria-expanded":s,"aria-activedescendant":"number"==typeof a&&a>=0?l.getItemId(a):null,autoComplete:"off",value:u,onChange:d(t,l.input_handleChange),onKeyDown:d(n,l.input_handleKeyDown),onBlur:d(o,l.input_handleBlur)},r,{id:l.inputId})},l.input_handleKeyDown=function(e){e.key&&l.keyDownHandlers[e.key]?l.keyDownHandlers[e.key].call(l,e):["Shift","Meta","Alt","Control"].includes(e.key)||l.openMenu()},l.input_handleChange=function(e){l.internalSetState({inputValue:e.target.value})},l.input_handleBlur=function(){l.isMouseDown||l.reset()},l.getItemProps=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=e.onMouseEnter,n=e.item,o=e.index,r=x(e,["onMouseEnter","item","index"]);return l.items[o]=n,b({id:l.getItemId(o),onMouseEnter:d(t,function(){l.setHighlightedIndex(o)})},r)},l.reset=function(e){l.internalSetState(function(t){var n=t.selectedItem;return{type:e,isOpen:!1,highlightedIndex:null,inputValue:l.props.itemToString(n)}})},l.toggleMenu=function(e,t){l.internalSetState(function(t){var n=!t.isOpen;return"boolean"==typeof e&&(n=e),{isOpen:n}},function(){l.getState().isOpen&&l.setHighlightedIndex(),i(t)()})},l.openMenu=function(e){l.toggleMenu(!0,e)},l.closeMenu=function(e){l.toggleMenu(!1,e)},l.updateStatus=a(function(){if(l._isMounted){var e=l.getState(),t=l.getItemFromIndex(e.highlightedIndex)||{},o=l.items.length,r=l.props.getA11yStatusMessage(b({itemToString:l.props.itemToString,previousResultCount:l.previousResultCount,resultCount:o,highlightedItem:t},e));l.previousResultCount=o,n(r)}},200),l.id=h("downshift"),l.state={highlightedIndex:l.props.defaultHighlightedIndex,inputValue:l.props.defaultInputValue,isOpen:l.props.defaultIsOpen,selectedItem:l.props.defaultSelectedItem},l.root_handleClick=d(l.props.onClick,l.root_handleClick),l}return S(t,e),v(t,[{key:"getState",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:this.state;return Object.keys(t).reduce(function(t,n){return t[n]=void 0===e.props[n]?e.state[n]:e.props[n],t},{})}},{key:"maybeScrollToHighlightedElement",value:function(e,t){s(this.getItemNodeFromIndex(e),this._rootNode,t)}},{key:"internalSetState",value:function(e,t){var n=this,o={},r=void 0,u=void 0;return this.setState(function(t){t=n.getState(t);var i={},l={};return(r="function"==typeof e?e(t):e).hasOwnProperty("selectedItem")&&(o.selectedItem=r.selectedItem,o.previousItem=t.selectedItem),Object.keys(r).forEach(function(e){"type"!==e&&(l[e]=r[e],n.props.hasOwnProperty(e)||(i[e]=r[e]))}),u=!f(t,l),i},function(){i(t)(),u&&n.props.onStateChange(r),Object.keys(o).length&&n.props.onChange(o)})}},{key:"getControllerStateAndHelpers",value:function(){var e=this.getState(),t=e.highlightedIndex,n=e.inputValue,o=e.selectedItem,r=e.isOpen;return{getRootProps:this.getRootProps,getButtonProps:this.getButtonProps,getLabelProps:this.getLabelProps,getInputProps:this.getInputProps,getItemProps:this.getItemProps,openMenu:this.openMenu,closeMenu:this.closeMenu,toggleMenu:this.toggleMenu,selectItem:this.selectItem,selectItemAtIndex:this.selectItemAtIndex,selectHighlightedItem:this.selectHighlightedItem,setHighlightedIndex:this.setHighlightedIndex,clearSelection:this.clearSelection,highlightedIndex:t,inputValue:n,isOpen:r,selectedItem:o}}},{key:"getItemId",value:function(e){return this.id+"-item-"+e}},{key:"getItemIndexFromId",value:function(e){return e?Number(e.split(this.id+"-item-")[1]):null}},{key:"componentDidMount",value:function(){var e=this;this._isMounted=!0;var n=function(){e.isMouseDown=!0},o=function(n){e.isMouseDown=!1,e._rootNode.contains(n.target)||e.reset(t.stateChangeTypes.mouseUp)};window.addEventListener("mousedown",n),window.addEventListener("mouseup",o),this.cleanup=function(){e._isMounted=!1,window.removeEventListener("mousedown",n),window.removeEventListener("mouseup",o)}}},{key:"componentDidUpdate",value:function(){this.updateStatus()}},{key:"componentWillUnmount",value:function(){this.cleanup()}},{key:"render",value:function(){var e=this.props.children;this.items=[],this.getRootProps.called=!1,this.getRootProps.refKey=void 0,this.getLabelProps.called=!1,this.getInputProps.called=!1;var t=e&&e(this.getControllerStateAndHelpers());if(!t)return null;var n=m.Children.only(t);if(this.getRootProps.called)return g(n,this.getRootProps),n;if("string"==typeof n.type)return m.cloneElement(n,this.getRootProps(n.props));throw new Error("downshift: If you return a non-DOM element, you must use apply the getRootProps function")}}]),t}(e.Component);return M.propTypes={children:y.func,defaultHighlightedIndex:y.number,defaultSelectedItem:y.any,defaultInputValue:y.string,defaultIsOpen:y.bool,getA11yStatusMessage:y.func,itemToString:y.func,onChange:y.func,onStateChange:y.func,onClick:y.func,selectedItem:y.any,isOpen:y.bool,inputValue:y.string,highlightedIndex:y.number},M.defaultProps={defaultHighlightedIndex:null,defaultSelectedItem:null,defaultInputValue:"",defaultIsOpen:!1,getA11yStatusMessage:function(e){var t=e.isOpen,n=e.highlightedItem,o=e.selectedItem,r=e.resultCount,i=e.previousResultCount,u=e.itemToString;if(!t)return o?u(o):"";var l=r!==i;return r?!n||l?r+" "+(1===r?"result is":"results are")+" available, use up and down arrow keys to navigate.":u(n):"No results."},itemToString:function(e){return null==e?"":String(e)},onStateChange:function(){}},M.stateChangeTypes={mouseUp:"__autocomplete_mouseup__"},M});
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t(require("preact")):"function"==typeof define&&define.amd?define(["preact"],t):e.downshift=t(e.preact)}(this,function(e){"use strict";function t(){}function n(e){var t=k[k.length-1]===e;k=t?[].concat(P(k),[e]):[e],r().innerHTML=""+k.filter(Boolean).map(o).join("")}function o(e,t){return'<div style="display:'+(t===k.length-1?"block":"none")+';">'+e+"</div>"}function r(){return O||((O=document.createElement("div")).setAttribute("id","a11y-status-message"),O.setAttribute("role","status"),O.setAttribute("aria-live","assertive"),O.setAttribute("aria-relevant","additions text"),Object.assign(O.style,{border:"0",clip:"rect(0 0 0 0)",height:"1px",margin:"-1px",overflow:"hidden",padding:"0",position:"absolute",width:"1px"}),document.body.appendChild(O),O)}function i(e){return"function"==typeof e?e:u}function u(){}function l(e,t,n){return null!==t&&t!==n.parentNode?e(t)?t:l(e,t.parentNode,n):null}function s(e,t){var n=M(e,t);if(null!==n){var o=getComputedStyle(n),r=n.getBoundingClientRect(),i=parseInt(o.borderTopWidth,10),u=r.top+i,l=e.getBoundingClientRect(),s=l.top+n.scrollTop-u;s<n.scrollTop?n.scrollTop=s:s+l.height>n.scrollTop+r.height&&(n.scrollTop=s+l.height-r.height)}}function a(e,t){var n=void 0;return function(){for(var o=arguments.length,r=Array(o),i=0;i<o;i++)r[i]=arguments[i];n&&clearTimeout(n),n=setTimeout(function(){n=null,e.apply(void 0,r)},t)}}function d(){for(var e=arguments.length,t=Array(e),n=0;n<e;n++)t[n]=arguments[n];return function(e){for(var n=arguments.length,o=Array(n>1?n-1:0),r=1;r<n;r++)o[r-1]=arguments[r];return t.some(function(t){return t&&t.apply(void 0,[e].concat(o)),e.defaultPrevented})}}function p(e){return e+"-"+H++}function h(){for(var e=arguments.length,t=Array(e),n=0;n<e;n++)t[n]=arguments[n];return t.find(function(e){return void 0!==e})}function c(e){return e===e&&"number"==typeof e}function f(e,t){return Object.keys(t).every(function(n){return e[n]===t[n]})}function g(e,t){var n=t.refKey,o="ref"!==n,r="string"!=typeof e.type;if(r&&!o)throw new Error("downshift: You returned a non-DOM element. You must specify a refKey in getRootProps");if(!r&&o)throw new Error('downshift: You returned a DOM element. You should not specify a refKey in getRootProps. You specified "'+n+'"');if(!e.props.hasOwnProperty(n))throw new Error('downshift: You must apply the ref prop "'+n+'" from getRootProps onto your root element.');if(!e.props.hasOwnProperty("onClick"))throw new Error('downshift: You must apply the "onClick" prop from getRootProps onto your root element.')}var m=e.default;m.Children={only:function(e){return e&&e[0]}},t.isRequired=t;var y={element:t,func:t,number:t,any:t,bool:t,string:t},I=function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")},v=function(){function e(e,t){for(var n=0;n<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,o.key,o)}}return function(t,n,o){return n&&e(t.prototype,n),o&&e(t,o),t}}(),b=function(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e},w=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var o in n)Object.prototype.hasOwnProperty.call(n,o)&&(e[o]=n[o])}return e},x=function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)},S=function(e,t){var n={};for(var o in e)t.indexOf(o)>=0||Object.prototype.hasOwnProperty.call(e,o)&&(n[o]=e[o]);return n},C=function(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t},P=function(e){if(Array.isArray(e)){for(var t=0,n=Array(e.length);t<e.length;t++)n[t]=e[t];return n}return Array.from(e)},O="undefined"==typeof document?null:document.getElementById("a11y-status-message"),k=[],H=1,M=l.bind(null,function(e){return e.scrollHeight>e.clientHeight}),_=function(e){function t(){var e;I(this,t);for(var o=arguments.length,r=Array(o),u=0;u<o;u++)r[u]=arguments[u];var s=C(this,(e=t.__proto__||Object.getPrototypeOf(t)).call.apply(e,[this].concat(r)));return s.input=null,s.items=[],s.previousResultCount=0,s.getItemFromIndex=function(e){return s.items&&s.items[0]?s.items[e]:null},s.getIndexFromItem=function(e){var t=s.items.findIndex(function(t){return t===e});return-1===t?null:t},s.getItemNodeFromIndex=function(e){return document.getElementById(s.getItemId(e))},s.setHighlightedIndex=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:s.props.defaultHighlightedIndex;s.internalSetState({highlightedIndex:e},function(){s.maybeScrollToHighlightedElement(e)})},s.highlightIndex=function(e){s.openMenu(function(){s.setHighlightedIndex(e)})},s.moveHighlightedIndex=function(e){s.getState().isOpen?s.changeHighlighedIndex(e):s.highlightIndex()},s.changeHighlighedIndex=function(e){var t=s.items.length-1;if(!(t<0)){var n=s.getState().highlightedIndex;null===n&&(n=e>0?-1:t+1);var o=n+e;o<0?o=t:o>t&&(o=0),s.setHighlightedIndex(o)}},s.clearSelection=function(){s.internalSetState({selectedItem:null,inputValue:"",isOpen:!1},function(){var e=document.getElementById(s.inputId);e&&e.focus&&e.focus()})},s.selectItem=function(e){s.reset(),s.internalSetState({selectedItem:e,inputValue:s.props.itemToString(e)})},s.selectItemAtIndex=function(e){if(null!==e){var t=s.getItemFromIndex(e);t&&s.selectItem(t)}},s.selectHighlightedItem=function(){return s.selectItemAtIndex(s.getState().highlightedIndex)},s.rootRef=function(e){return s._rootNode=e},s.getRootProps=function(){var e,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=t.refKey,o=void 0===n?"ref":n,r=t.onClick,i=S(t,["refKey","onClick"]);return s.getRootProps.called=!0,s.getRootProps.refKey=o,w((e={},b(e,o,s.rootRef),b(e,"onClick",d(r,s.root_handleClick)),e),i)},s.root_handleClick=function(e){e.preventDefault();var t=e.target;if(t){var n=l(function(e){return c(s.getItemIndexFromId(e.getAttribute("id")))},t,s._rootNode);n&&s.selectItemAtIndex(s.getItemIndexFromId(n.getAttribute("id")))}},s.keyDownHandlers={ArrowDown:function(e){e.preventDefault();var t=e.shiftKey?5:1;this.moveHighlightedIndex(t)},ArrowUp:function(e){e.preventDefault();var t=e.shiftKey?-5:-1;this.moveHighlightedIndex(t)},Enter:function(e){e.preventDefault(),this.getState().isOpen&&this.selectHighlightedItem()},Escape:function(e){e.preventDefault(),this.reset()}},s.buttonKeyDownHandlers=w({},s.keyDownHandlers,{" ":function(e){e.preventDefault();var t=this.getState(),n=t.isOpen,o=t.highlightedIndex;n?null===o?this.closeMenu():this.selectHighlightedItem():this.openMenu()}}),s.getButtonProps=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=e.onClick,n=e.onKeyDown,o=S(e,["onClick","onKeyDown"]),r=s.getState().isOpen;return w({role:"button","aria-label":r?"close menu":"open menu","aria-expanded":r,"aria-haspopup":!0,onClick:d(t,s.button_handleClick),onKeyDown:d(n,s.button_handleKeyDown)},o)},s.button_handleKeyDown=function(e){s.buttonKeyDownHandlers[e.key]&&s.buttonKeyDownHandlers[e.key].call(s,e)},s.button_handleClick=function(e){e.preventDefault(),s.toggleMenu()},s.getLabelProps=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};if(s.getLabelProps.called=!0,s.getInputProps.called&&e.htmlFor&&e.htmlFor!==s.inputId)throw new Error('downshift: You provided the htmlFor of "'+e.htmlFor+'" for your label, but the id of your input is "'+s.inputId+'". You must either remove the id from your input or set the htmlFor of the label equal to the input id.');return s.inputId=h(s.inputId,e.htmlFor,p("downshift-input")),w({},e,{htmlFor:s.inputId})},s.getInputProps=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=e.onChange,n=e.onKeyDown,o=e.onBlur,r=S(e,["onChange","onKeyDown","onBlur"]);if(s.getInputProps.called=!0,s.getLabelProps.called&&r.id&&r.id!==s.inputId)throw new Error('downshift: You provided the id of "'+r.id+'" for your input, but the htmlFor of your label is "'+s.inputId+'". You must either remove the id from your input or set the htmlFor of the label equal to the input id.');s.inputId=h(s.inputId,r.id,p("downshift-input"));var i=s.getState(),u=i.inputValue,l=i.isOpen,a=i.highlightedIndex;return w({role:"combobox","aria-autocomplete":"list","aria-expanded":l,"aria-activedescendant":"number"==typeof a&&a>=0?s.getItemId(a):null,autoComplete:"off",value:u,onChange:d(t,s.input_handleChange),onKeyDown:d(n,s.input_handleKeyDown),onBlur:d(o,s.input_handleBlur)},r,{id:s.inputId})},s.input_handleKeyDown=function(e){e.key&&s.keyDownHandlers[e.key]?s.keyDownHandlers[e.key].call(s,e):["Shift","Meta","Alt","Control"].includes(e.key)||s.openMenu()},s.input_handleChange=function(e){s.internalSetState({inputValue:e.target.value})},s.input_handleBlur=function(){s.isMouseDown||s.reset()},s.getItemProps=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=e.onMouseEnter,n=e.item,o=e.index,r=S(e,["onMouseEnter","item","index"]);return s.items[o]=n,w({id:s.getItemId(o),onMouseEnter:d(t,function(){s.setHighlightedIndex(o)})},r)},s.reset=function(e){s.internalSetState(function(t){var n=t.selectedItem;return{type:e,isOpen:!1,highlightedIndex:null,inputValue:s.props.itemToString(n)}})},s.toggleMenu=function(e,t){s.internalSetState(function(t){var n=!t.isOpen;return"boolean"==typeof e&&(n=e),{isOpen:n}},function(){s.getState().isOpen&&s.setHighlightedIndex(),i(t)()})},s.openMenu=function(e){s.toggleMenu(!0,e)},s.closeMenu=function(e){s.toggleMenu(!1,e)},s.updateStatus=a(function(){if(s._isMounted){var e=s.getState(),t=s.getItemFromIndex(e.highlightedIndex)||{},o=s.items.length,r=s.props.getA11yStatusMessage(w({itemToString:s.props.itemToString,previousResultCount:s.previousResultCount,resultCount:o,highlightedItem:t},e));s.previousResultCount=o,n(r)}},200),s.id=p("downshift"),s.state={highlightedIndex:s.props.defaultHighlightedIndex,inputValue:s.props.defaultInputValue,isOpen:s.props.defaultIsOpen,selectedItem:s.props.defaultSelectedItem},s.root_handleClick=d(s.props.onClick,s.root_handleClick),s}return x(t,e),v(t,[{key:"getState",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:this.state;return Object.keys(t).reduce(function(t,n){return t[n]=void 0===e.props[n]?e.state[n]:e.props[n],t},{})}},{key:"maybeScrollToHighlightedElement",value:function(e){s(this.getItemNodeFromIndex(e),this._rootNode)}},{key:"internalSetState",value:function(e,t){var n=this,o={},r=void 0,u=void 0;return this.setState(function(t){t=n.getState(t);var i={},l={};return(r="function"==typeof e?e(t):e).hasOwnProperty("selectedItem")&&(o.selectedItem=r.selectedItem,o.previousItem=t.selectedItem),Object.keys(r).forEach(function(e){"type"!==e&&(l[e]=r[e],n.props.hasOwnProperty(e)||(i[e]=r[e]))}),u=!f(t,l),i},function(){i(t)(),u&&n.props.onStateChange(r),Object.keys(o).length&&n.props.onChange(o)})}},{key:"getControllerStateAndHelpers",value:function(){var e=this.getState(),t=e.highlightedIndex,n=e.inputValue,o=e.selectedItem,r=e.isOpen;return{getRootProps:this.getRootProps,getButtonProps:this.getButtonProps,getLabelProps:this.getLabelProps,getInputProps:this.getInputProps,getItemProps:this.getItemProps,openMenu:this.openMenu,closeMenu:this.closeMenu,toggleMenu:this.toggleMenu,selectItem:this.selectItem,selectItemAtIndex:this.selectItemAtIndex,selectHighlightedItem:this.selectHighlightedItem,setHighlightedIndex:this.setHighlightedIndex,clearSelection:this.clearSelection,highlightedIndex:t,inputValue:n,isOpen:r,selectedItem:o}}},{key:"getItemId",value:function(e){return this.id+"-item-"+e}},{key:"getItemIndexFromId",value:function(e){return e?Number(e.split(this.id+"-item-")[1]):null}},{key:"componentDidMount",value:function(){var e=this;this._isMounted=!0;var n=function(){e.isMouseDown=!0},o=function(n){e.isMouseDown=!1,e._rootNode.contains(n.target)||e.reset(t.stateChangeTypes.mouseUp)};window.addEventListener("mousedown",n),window.addEventListener("mouseup",o),this.cleanup=function(){e._isMounted=!1,window.removeEventListener("mousedown",n),window.removeEventListener("mouseup",o)}}},{key:"componentDidUpdate",value:function(){this.updateStatus()}},{key:"componentWillUnmount",value:function(){this.cleanup()}},{key:"render",value:function(){var e=this.props.children;this.items=[],this.getRootProps.called=!1,this.getRootProps.refKey=void 0,this.getLabelProps.called=!1,this.getInputProps.called=!1;var t=e&&e(this.getControllerStateAndHelpers());if(!t)return null;var n=m.Children.only(t);if(this.getRootProps.called)return g(n,this.getRootProps),n;if("string"==typeof n.type)return m.cloneElement(n,this.getRootProps(n.props));throw new Error("downshift: If you return a non-DOM element, you must use apply the getRootProps function")}}]),t}(e.Component);return _.propTypes={children:y.func,defaultHighlightedIndex:y.number,defaultSelectedItem:y.any,defaultInputValue:y.string,defaultIsOpen:y.bool,getA11yStatusMessage:y.func,itemToString:y.func,onChange:y.func,onStateChange:y.func,onClick:y.func,selectedItem:y.any,isOpen:y.bool,inputValue:y.string,highlightedIndex:y.number},_.defaultProps={defaultHighlightedIndex:null,defaultSelectedItem:null,defaultInputValue:"",defaultIsOpen:!1,getA11yStatusMessage:function(e){var t=e.isOpen,n=e.highlightedItem,o=e.selectedItem,r=e.resultCount,i=e.previousResultCount,u=e.itemToString;if(!t)return o?u(o):"";var l=r!==i;return r?!n||l?r+" "+(1===r?"result is":"results are")+" available, use up and down arrow keys to navigate.":u(n):"No results."},itemToString:function(e){return null==e?"":String(e)},onStateChange:function(){},onChange:function(){}},_.stateChangeTypes={mouseUp:"__autocomplete_mouseup__"},_});
//# sourceMappingURL=downshift.preact.umd.min.js.map

@@ -200,15 +200,8 @@ (function (global, factory) {

/**
* Get the closest element that scrolls
* @param {HTMLElement} node - the child element to start searching for scroll parent at
* @param {HTMLElement} rootNode - the root element of the component
* @return {HTMLElement} the closest parentNode that scrolls
*/
function getClosestScrollParent(node, rootNode) {
if (node !== null && node !== rootNode) {
var isScrollable = node.scrollHeight > node.clientHeight;
if (isScrollable) {
function findParent(finder, node, rootNode) {
if (node !== null && node !== rootNode.parentNode) {
if (finder(node)) {
return node;
} else {
return getClosestScrollParent(node.parentNode);
return findParent(finder, node.parentNode, rootNode);
}

@@ -221,2 +214,12 @@ } else {

/**
* Get the closest element that scrolls
* @param {HTMLElement} node - the child element to start searching for scroll parent at
* @param {HTMLElement} rootNode - the root element of the component
* @return {HTMLElement} the closest parentNode that scrolls
*/
var getClosestScrollParent = findParent.bind(null, function (node) {
return node.scrollHeight > node.clientHeight;
});
/**
* Scroll node into view if necessary

@@ -227,3 +230,3 @@ * @param {HTMLElement} node - the element that should scroll into view

*/
function scrollIntoView(node, rootNode, alignToTop) {
function scrollIntoView(node, rootNode) {
var scrollParent = getClosestScrollParent(node, rootNode);

@@ -240,3 +243,3 @@ if (scrollParent === null) {

var nodeTop = nodeOffsetTop - scrollParentTop;
if (alignToTop || nodeTop < scrollParent.scrollTop) {
if (nodeTop < scrollParent.scrollTop) {
// the item is above the scrollable area

@@ -418,9 +421,2 @@ scrollParent.scrollTop = nodeTop;

_this.highlightSelectedItem = function () {
var highlightedIndex = _this.getIndexFromItem(_this.getState().selectedItem) || 0;
_this.internalSetState({ highlightedIndex: highlightedIndex }, function () {
_this.maybeScrollToHighlightedElement(highlightedIndex, true);
});
};
_this.highlightIndex = function (index) {

@@ -525,5 +521,8 @@ _this.openMenu(function () {

}
var index = _this.getItemIndexFromId(target.getAttribute('id'));
if (isNumber(index)) {
_this.selectItemAtIndex(index);
var itemParent = findParent(function (node) {
var index = _this.getItemIndexFromId(node.getAttribute('id'));
return isNumber(index);
}, target, _this._rootNode);
if (itemParent) {
_this.selectItemAtIndex(_this.getItemIndexFromId(itemParent.getAttribute('id')));
}

@@ -790,6 +789,6 @@ };

key: 'maybeScrollToHighlightedElement',
value: function maybeScrollToHighlightedElement(highlightedIndex, alignToTop) {
value: function maybeScrollToHighlightedElement(highlightedIndex) {
var node = this.getItemNodeFromIndex(highlightedIndex);
var rootNode = this._rootNode;
scrollIntoView(node, rootNode, alignToTop);
scrollIntoView(node, rootNode);
}

@@ -1061,3 +1060,4 @@

},
onStateChange: function onStateChange() {} };
onStateChange: function onStateChange() {},
onChange: function onChange() {} };
Downshift$1.stateChangeTypes = {

@@ -1064,0 +1064,0 @@ mouseUp: '__autocomplete_mouseup__'

@@ -1,2 +0,2 @@

!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t(require("react"),require("prop-types")):"function"==typeof define&&define.amd?define(["react","prop-types"],t):e.downshift=t(e.React,e.PropTypes)}(this,function(e,t){"use strict";function n(e){var t=O[O.length-1]===e;O=t?[].concat(P(O),[e]):[e],r().innerHTML=""+O.filter(Boolean).map(o).join("")}function o(e,t){return'<div style="display:'+(t===O.length-1?"block":"none")+';">'+e+"</div>"}function r(){return C||((C=document.createElement("div")).setAttribute("id","a11y-status-message"),C.setAttribute("role","status"),C.setAttribute("aria-live","assertive"),C.setAttribute("aria-relevant","additions text"),Object.assign(C.style,{border:"0",clip:"rect(0 0 0 0)",height:"1px",margin:"-1px",overflow:"hidden",padding:"0",position:"absolute",width:"1px"}),document.body.appendChild(C),C)}function i(e){return"function"==typeof e?e:u}function u(){}function l(e,t){return null!==e&&e!==t?e.scrollHeight>e.clientHeight?e:l(e.parentNode):null}function s(e,t,n){var o=l(e,t);if(null!==o){var r=getComputedStyle(o),i=o.getBoundingClientRect(),u=parseInt(r.borderTopWidth,10),s=i.top+u,a=e.getBoundingClientRect(),d=a.top+o.scrollTop-s;n||d<o.scrollTop?o.scrollTop=d:d+a.height>o.scrollTop+i.height&&(o.scrollTop=d+a.height-i.height)}}function a(e,t){var n=void 0;return function(){for(var o=arguments.length,r=Array(o),i=0;i<o;i++)r[i]=arguments[i];n&&clearTimeout(n),n=setTimeout(function(){n=null,e.apply(void 0,r)},t)}}function d(){for(var e=arguments.length,t=Array(e),n=0;n<e;n++)t[n]=arguments[n];return function(e){for(var n=arguments.length,o=Array(n>1?n-1:0),r=1;r<n;r++)o[r-1]=arguments[r];return t.some(function(t){return t&&t.apply(void 0,[e].concat(o)),e.defaultPrevented})}}function p(e){return e+"-"+k++}function h(){for(var e=arguments.length,t=Array(e),n=0;n<e;n++)t[n]=arguments[n];return t.find(function(e){return void 0!==e})}function c(e){return e===e&&"number"==typeof e}function f(e,t){return Object.keys(t).every(function(n){return e[n]===t[n]})}function g(e,t){var n=t.refKey,o="ref"!==n,r="string"!=typeof e.type;if(r&&!o)throw new Error("downshift: You returned a non-DOM element. You must specify a refKey in getRootProps");if(!r&&o)throw new Error('downshift: You returned a DOM element. You should not specify a refKey in getRootProps. You specified "'+n+'"');if(!e.props.hasOwnProperty(n))throw new Error('downshift: You must apply the ref prop "'+n+'" from getRootProps onto your root element.');if(!e.props.hasOwnProperty("onClick"))throw new Error('downshift: You must apply the "onClick" prop from getRootProps onto your root element.')}var m="default"in e?e.default:e;t=t&&t.hasOwnProperty("default")?t.default:t;var y=function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")},I=function(){function e(e,t){for(var n=0;n<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,o.key,o)}}return function(t,n,o){return n&&e(t.prototype,n),o&&e(t,o),t}}(),v=function(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e},w=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var o in n)Object.prototype.hasOwnProperty.call(n,o)&&(e[o]=n[o])}return e},b=function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)},S=function(e,t){var n={};for(var o in e)t.indexOf(o)>=0||Object.prototype.hasOwnProperty.call(e,o)&&(n[o]=e[o]);return n},x=function(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t},P=function(e){if(Array.isArray(e)){for(var t=0,n=Array(e.length);t<e.length;t++)n[t]=e[t];return n}return Array.from(e)},C="undefined"==typeof document?null:document.getElementById("a11y-status-message"),O=[],k=1,H=function(e){function t(){var e;y(this,t);for(var o=arguments.length,r=Array(o),u=0;u<o;u++)r[u]=arguments[u];var l=x(this,(e=t.__proto__||Object.getPrototypeOf(t)).call.apply(e,[this].concat(r)));return l.input=null,l.items=[],l.previousResultCount=0,l.getItemFromIndex=function(e){return l.items&&l.items[0]?l.items[e]:null},l.getIndexFromItem=function(e){var t=l.items.findIndex(function(t){return t===e});return-1===t?null:t},l.getItemNodeFromIndex=function(e){return document.getElementById(l.getItemId(e))},l.setHighlightedIndex=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:l.props.defaultHighlightedIndex;l.internalSetState({highlightedIndex:e},function(){l.maybeScrollToHighlightedElement(e)})},l.highlightSelectedItem=function(){var e=l.getIndexFromItem(l.getState().selectedItem)||0;l.internalSetState({highlightedIndex:e},function(){l.maybeScrollToHighlightedElement(e,!0)})},l.highlightIndex=function(e){l.openMenu(function(){l.setHighlightedIndex(e)})},l.moveHighlightedIndex=function(e){l.getState().isOpen?l.changeHighlighedIndex(e):l.highlightIndex()},l.changeHighlighedIndex=function(e){var t=l.items.length-1;if(!(t<0)){var n=l.getState().highlightedIndex;null===n&&(n=e>0?-1:t+1);var o=n+e;o<0?o=t:o>t&&(o=0),l.setHighlightedIndex(o)}},l.clearSelection=function(){l.internalSetState({selectedItem:null,inputValue:"",isOpen:!1},function(){var e=document.getElementById(l.inputId);e&&e.focus&&e.focus()})},l.selectItem=function(e){l.reset(),l.internalSetState({selectedItem:e,inputValue:l.props.itemToString(e)})},l.selectItemAtIndex=function(e){if(null!==e){var t=l.getItemFromIndex(e);t&&l.selectItem(t)}},l.selectHighlightedItem=function(){return l.selectItemAtIndex(l.getState().highlightedIndex)},l.rootRef=function(e){return l._rootNode=e},l.getRootProps=function(){var e,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=t.refKey,o=void 0===n?"ref":n,r=t.onClick,i=S(t,["refKey","onClick"]);return l.getRootProps.called=!0,l.getRootProps.refKey=o,w((e={},v(e,o,l.rootRef),v(e,"onClick",d(r,l.root_handleClick)),e),i)},l.root_handleClick=function(e){e.preventDefault();var t=e.target;if(t){var n=l.getItemIndexFromId(t.getAttribute("id"));c(n)&&l.selectItemAtIndex(n)}},l.keyDownHandlers={ArrowDown:function(e){e.preventDefault();var t=e.shiftKey?5:1;this.moveHighlightedIndex(t)},ArrowUp:function(e){e.preventDefault();var t=e.shiftKey?-5:-1;this.moveHighlightedIndex(t)},Enter:function(e){e.preventDefault(),this.getState().isOpen&&this.selectHighlightedItem()},Escape:function(e){e.preventDefault(),this.reset()}},l.buttonKeyDownHandlers=w({},l.keyDownHandlers,{" ":function(e){e.preventDefault();var t=this.getState(),n=t.isOpen,o=t.highlightedIndex;n?null===o?this.closeMenu():this.selectHighlightedItem():this.openMenu()}}),l.getButtonProps=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=e.onClick,n=e.onKeyDown,o=S(e,["onClick","onKeyDown"]),r=l.getState().isOpen;return w({role:"button","aria-label":r?"close menu":"open menu","aria-expanded":r,"aria-haspopup":!0,onClick:d(t,l.button_handleClick),onKeyDown:d(n,l.button_handleKeyDown)},o)},l.button_handleKeyDown=function(e){l.buttonKeyDownHandlers[e.key]&&l.buttonKeyDownHandlers[e.key].call(l,e)},l.button_handleClick=function(e){e.preventDefault(),l.toggleMenu()},l.getLabelProps=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};if(l.getLabelProps.called=!0,l.getInputProps.called&&e.htmlFor&&e.htmlFor!==l.inputId)throw new Error('downshift: You provided the htmlFor of "'+e.htmlFor+'" for your label, but the id of your input is "'+l.inputId+'". You must either remove the id from your input or set the htmlFor of the label equal to the input id.');return l.inputId=h(l.inputId,e.htmlFor,p("downshift-input")),w({},e,{htmlFor:l.inputId})},l.getInputProps=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=e.onChange,n=e.onKeyDown,o=e.onBlur,r=S(e,["onChange","onKeyDown","onBlur"]);if(l.getInputProps.called=!0,l.getLabelProps.called&&r.id&&r.id!==l.inputId)throw new Error('downshift: You provided the id of "'+r.id+'" for your input, but the htmlFor of your label is "'+l.inputId+'". You must either remove the id from your input or set the htmlFor of the label equal to the input id.');l.inputId=h(l.inputId,r.id,p("downshift-input"));var i=l.getState(),u=i.inputValue,s=i.isOpen,a=i.highlightedIndex;return w({role:"combobox","aria-autocomplete":"list","aria-expanded":s,"aria-activedescendant":"number"==typeof a&&a>=0?l.getItemId(a):null,autoComplete:"off",value:u,onChange:d(t,l.input_handleChange),onKeyDown:d(n,l.input_handleKeyDown),onBlur:d(o,l.input_handleBlur)},r,{id:l.inputId})},l.input_handleKeyDown=function(e){e.key&&l.keyDownHandlers[e.key]?l.keyDownHandlers[e.key].call(l,e):["Shift","Meta","Alt","Control"].includes(e.key)||l.openMenu()},l.input_handleChange=function(e){l.internalSetState({inputValue:e.target.value})},l.input_handleBlur=function(){l.isMouseDown||l.reset()},l.getItemProps=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=e.onMouseEnter,n=e.item,o=e.index,r=S(e,["onMouseEnter","item","index"]);return l.items[o]=n,w({id:l.getItemId(o),onMouseEnter:d(t,function(){l.setHighlightedIndex(o)})},r)},l.reset=function(e){l.internalSetState(function(t){var n=t.selectedItem;return{type:e,isOpen:!1,highlightedIndex:null,inputValue:l.props.itemToString(n)}})},l.toggleMenu=function(e,t){l.internalSetState(function(t){var n=!t.isOpen;return"boolean"==typeof e&&(n=e),{isOpen:n}},function(){l.getState().isOpen&&l.setHighlightedIndex(),i(t)()})},l.openMenu=function(e){l.toggleMenu(!0,e)},l.closeMenu=function(e){l.toggleMenu(!1,e)},l.updateStatus=a(function(){if(l._isMounted){var e=l.getState(),t=l.getItemFromIndex(e.highlightedIndex)||{},o=l.items.length,r=l.props.getA11yStatusMessage(w({itemToString:l.props.itemToString,previousResultCount:l.previousResultCount,resultCount:o,highlightedItem:t},e));l.previousResultCount=o,n(r)}},200),l.id=p("downshift"),l.state={highlightedIndex:l.props.defaultHighlightedIndex,inputValue:l.props.defaultInputValue,isOpen:l.props.defaultIsOpen,selectedItem:l.props.defaultSelectedItem},l.root_handleClick=d(l.props.onClick,l.root_handleClick),l}return b(t,e),I(t,[{key:"getState",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:this.state;return Object.keys(t).reduce(function(t,n){return t[n]=void 0===e.props[n]?e.state[n]:e.props[n],t},{})}},{key:"maybeScrollToHighlightedElement",value:function(e,t){s(this.getItemNodeFromIndex(e),this._rootNode,t)}},{key:"internalSetState",value:function(e,t){var n=this,o={},r=void 0,u=void 0;return this.setState(function(t){t=n.getState(t);var i={},l={};return(r="function"==typeof e?e(t):e).hasOwnProperty("selectedItem")&&(o.selectedItem=r.selectedItem,o.previousItem=t.selectedItem),Object.keys(r).forEach(function(e){"type"!==e&&(l[e]=r[e],n.props.hasOwnProperty(e)||(i[e]=r[e]))}),u=!f(t,l),i},function(){i(t)(),u&&n.props.onStateChange(r),Object.keys(o).length&&n.props.onChange(o)})}},{key:"getControllerStateAndHelpers",value:function(){var e=this.getState(),t=e.highlightedIndex,n=e.inputValue,o=e.selectedItem,r=e.isOpen;return{getRootProps:this.getRootProps,getButtonProps:this.getButtonProps,getLabelProps:this.getLabelProps,getInputProps:this.getInputProps,getItemProps:this.getItemProps,openMenu:this.openMenu,closeMenu:this.closeMenu,toggleMenu:this.toggleMenu,selectItem:this.selectItem,selectItemAtIndex:this.selectItemAtIndex,selectHighlightedItem:this.selectHighlightedItem,setHighlightedIndex:this.setHighlightedIndex,clearSelection:this.clearSelection,highlightedIndex:t,inputValue:n,isOpen:r,selectedItem:o}}},{key:"getItemId",value:function(e){return this.id+"-item-"+e}},{key:"getItemIndexFromId",value:function(e){return e?Number(e.split(this.id+"-item-")[1]):null}},{key:"componentDidMount",value:function(){var e=this;this._isMounted=!0;var n=function(){e.isMouseDown=!0},o=function(n){e.isMouseDown=!1,e._rootNode.contains(n.target)||e.reset(t.stateChangeTypes.mouseUp)};window.addEventListener("mousedown",n),window.addEventListener("mouseup",o),this.cleanup=function(){e._isMounted=!1,window.removeEventListener("mousedown",n),window.removeEventListener("mouseup",o)}}},{key:"componentDidUpdate",value:function(){this.updateStatus()}},{key:"componentWillUnmount",value:function(){this.cleanup()}},{key:"render",value:function(){var e=this.props.children;this.items=[],this.getRootProps.called=!1,this.getRootProps.refKey=void 0,this.getLabelProps.called=!1,this.getInputProps.called=!1;var t=e&&e(this.getControllerStateAndHelpers());if(!t)return null;var n=m.Children.only(t);if(this.getRootProps.called)return g(n,this.getRootProps),n;if("string"==typeof n.type)return m.cloneElement(n,this.getRootProps(n.props));throw new Error("downshift: If you return a non-DOM element, you must use apply the getRootProps function")}}]),t}(e.Component);return H.propTypes={children:t.func,defaultHighlightedIndex:t.number,defaultSelectedItem:t.any,defaultInputValue:t.string,defaultIsOpen:t.bool,getA11yStatusMessage:t.func,itemToString:t.func,onChange:t.func,onStateChange:t.func,onClick:t.func,selectedItem:t.any,isOpen:t.bool,inputValue:t.string,highlightedIndex:t.number},H.defaultProps={defaultHighlightedIndex:null,defaultSelectedItem:null,defaultInputValue:"",defaultIsOpen:!1,getA11yStatusMessage:function(e){var t=e.isOpen,n=e.highlightedItem,o=e.selectedItem,r=e.resultCount,i=e.previousResultCount,u=e.itemToString;if(!t)return o?u(o):"";var l=r!==i;return r?!n||l?r+" "+(1===r?"result is":"results are")+" available, use up and down arrow keys to navigate.":u(n):"No results."},itemToString:function(e){return null==e?"":String(e)},onStateChange:function(){}},H.stateChangeTypes={mouseUp:"__autocomplete_mouseup__"},H});
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t(require("react"),require("prop-types")):"function"==typeof define&&define.amd?define(["react","prop-types"],t):e.downshift=t(e.React,e.PropTypes)}(this,function(e,t){"use strict";function n(e){var t=O[O.length-1]===e;O=t?[].concat(P(O),[e]):[e],r().innerHTML=""+O.filter(Boolean).map(o).join("")}function o(e,t){return'<div style="display:'+(t===O.length-1?"block":"none")+';">'+e+"</div>"}function r(){return C||((C=document.createElement("div")).setAttribute("id","a11y-status-message"),C.setAttribute("role","status"),C.setAttribute("aria-live","assertive"),C.setAttribute("aria-relevant","additions text"),Object.assign(C.style,{border:"0",clip:"rect(0 0 0 0)",height:"1px",margin:"-1px",overflow:"hidden",padding:"0",position:"absolute",width:"1px"}),document.body.appendChild(C),C)}function i(e){return"function"==typeof e?e:u}function u(){}function l(e,t,n){return null!==t&&t!==n.parentNode?e(t)?t:l(e,t.parentNode,n):null}function s(e,t){var n=H(e,t);if(null!==n){var o=getComputedStyle(n),r=n.getBoundingClientRect(),i=parseInt(o.borderTopWidth,10),u=r.top+i,l=e.getBoundingClientRect(),s=l.top+n.scrollTop-u;s<n.scrollTop?n.scrollTop=s:s+l.height>n.scrollTop+r.height&&(n.scrollTop=s+l.height-r.height)}}function a(e,t){var n=void 0;return function(){for(var o=arguments.length,r=Array(o),i=0;i<o;i++)r[i]=arguments[i];n&&clearTimeout(n),n=setTimeout(function(){n=null,e.apply(void 0,r)},t)}}function d(){for(var e=arguments.length,t=Array(e),n=0;n<e;n++)t[n]=arguments[n];return function(e){for(var n=arguments.length,o=Array(n>1?n-1:0),r=1;r<n;r++)o[r-1]=arguments[r];return t.some(function(t){return t&&t.apply(void 0,[e].concat(o)),e.defaultPrevented})}}function p(e){return e+"-"+k++}function h(){for(var e=arguments.length,t=Array(e),n=0;n<e;n++)t[n]=arguments[n];return t.find(function(e){return void 0!==e})}function c(e){return e===e&&"number"==typeof e}function f(e,t){return Object.keys(t).every(function(n){return e[n]===t[n]})}function g(e,t){var n=t.refKey,o="ref"!==n,r="string"!=typeof e.type;if(r&&!o)throw new Error("downshift: You returned a non-DOM element. You must specify a refKey in getRootProps");if(!r&&o)throw new Error('downshift: You returned a DOM element. You should not specify a refKey in getRootProps. You specified "'+n+'"');if(!e.props.hasOwnProperty(n))throw new Error('downshift: You must apply the ref prop "'+n+'" from getRootProps onto your root element.');if(!e.props.hasOwnProperty("onClick"))throw new Error('downshift: You must apply the "onClick" prop from getRootProps onto your root element.')}var m="default"in e?e.default:e;t=t&&t.hasOwnProperty("default")?t.default:t;var y=function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")},I=function(){function e(e,t){for(var n=0;n<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,o.key,o)}}return function(t,n,o){return n&&e(t.prototype,n),o&&e(t,o),t}}(),v=function(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e},w=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var o in n)Object.prototype.hasOwnProperty.call(n,o)&&(e[o]=n[o])}return e},b=function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)},x=function(e,t){var n={};for(var o in e)t.indexOf(o)>=0||Object.prototype.hasOwnProperty.call(e,o)&&(n[o]=e[o]);return n},S=function(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t},P=function(e){if(Array.isArray(e)){for(var t=0,n=Array(e.length);t<e.length;t++)n[t]=e[t];return n}return Array.from(e)},C="undefined"==typeof document?null:document.getElementById("a11y-status-message"),O=[],k=1,H=l.bind(null,function(e){return e.scrollHeight>e.clientHeight}),M=function(e){function t(){var e;y(this,t);for(var o=arguments.length,r=Array(o),u=0;u<o;u++)r[u]=arguments[u];var s=S(this,(e=t.__proto__||Object.getPrototypeOf(t)).call.apply(e,[this].concat(r)));return s.input=null,s.items=[],s.previousResultCount=0,s.getItemFromIndex=function(e){return s.items&&s.items[0]?s.items[e]:null},s.getIndexFromItem=function(e){var t=s.items.findIndex(function(t){return t===e});return-1===t?null:t},s.getItemNodeFromIndex=function(e){return document.getElementById(s.getItemId(e))},s.setHighlightedIndex=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:s.props.defaultHighlightedIndex;s.internalSetState({highlightedIndex:e},function(){s.maybeScrollToHighlightedElement(e)})},s.highlightIndex=function(e){s.openMenu(function(){s.setHighlightedIndex(e)})},s.moveHighlightedIndex=function(e){s.getState().isOpen?s.changeHighlighedIndex(e):s.highlightIndex()},s.changeHighlighedIndex=function(e){var t=s.items.length-1;if(!(t<0)){var n=s.getState().highlightedIndex;null===n&&(n=e>0?-1:t+1);var o=n+e;o<0?o=t:o>t&&(o=0),s.setHighlightedIndex(o)}},s.clearSelection=function(){s.internalSetState({selectedItem:null,inputValue:"",isOpen:!1},function(){var e=document.getElementById(s.inputId);e&&e.focus&&e.focus()})},s.selectItem=function(e){s.reset(),s.internalSetState({selectedItem:e,inputValue:s.props.itemToString(e)})},s.selectItemAtIndex=function(e){if(null!==e){var t=s.getItemFromIndex(e);t&&s.selectItem(t)}},s.selectHighlightedItem=function(){return s.selectItemAtIndex(s.getState().highlightedIndex)},s.rootRef=function(e){return s._rootNode=e},s.getRootProps=function(){var e,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=t.refKey,o=void 0===n?"ref":n,r=t.onClick,i=x(t,["refKey","onClick"]);return s.getRootProps.called=!0,s.getRootProps.refKey=o,w((e={},v(e,o,s.rootRef),v(e,"onClick",d(r,s.root_handleClick)),e),i)},s.root_handleClick=function(e){e.preventDefault();var t=e.target;if(t){var n=l(function(e){return c(s.getItemIndexFromId(e.getAttribute("id")))},t,s._rootNode);n&&s.selectItemAtIndex(s.getItemIndexFromId(n.getAttribute("id")))}},s.keyDownHandlers={ArrowDown:function(e){e.preventDefault();var t=e.shiftKey?5:1;this.moveHighlightedIndex(t)},ArrowUp:function(e){e.preventDefault();var t=e.shiftKey?-5:-1;this.moveHighlightedIndex(t)},Enter:function(e){e.preventDefault(),this.getState().isOpen&&this.selectHighlightedItem()},Escape:function(e){e.preventDefault(),this.reset()}},s.buttonKeyDownHandlers=w({},s.keyDownHandlers,{" ":function(e){e.preventDefault();var t=this.getState(),n=t.isOpen,o=t.highlightedIndex;n?null===o?this.closeMenu():this.selectHighlightedItem():this.openMenu()}}),s.getButtonProps=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=e.onClick,n=e.onKeyDown,o=x(e,["onClick","onKeyDown"]),r=s.getState().isOpen;return w({role:"button","aria-label":r?"close menu":"open menu","aria-expanded":r,"aria-haspopup":!0,onClick:d(t,s.button_handleClick),onKeyDown:d(n,s.button_handleKeyDown)},o)},s.button_handleKeyDown=function(e){s.buttonKeyDownHandlers[e.key]&&s.buttonKeyDownHandlers[e.key].call(s,e)},s.button_handleClick=function(e){e.preventDefault(),s.toggleMenu()},s.getLabelProps=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};if(s.getLabelProps.called=!0,s.getInputProps.called&&e.htmlFor&&e.htmlFor!==s.inputId)throw new Error('downshift: You provided the htmlFor of "'+e.htmlFor+'" for your label, but the id of your input is "'+s.inputId+'". You must either remove the id from your input or set the htmlFor of the label equal to the input id.');return s.inputId=h(s.inputId,e.htmlFor,p("downshift-input")),w({},e,{htmlFor:s.inputId})},s.getInputProps=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=e.onChange,n=e.onKeyDown,o=e.onBlur,r=x(e,["onChange","onKeyDown","onBlur"]);if(s.getInputProps.called=!0,s.getLabelProps.called&&r.id&&r.id!==s.inputId)throw new Error('downshift: You provided the id of "'+r.id+'" for your input, but the htmlFor of your label is "'+s.inputId+'". You must either remove the id from your input or set the htmlFor of the label equal to the input id.');s.inputId=h(s.inputId,r.id,p("downshift-input"));var i=s.getState(),u=i.inputValue,l=i.isOpen,a=i.highlightedIndex;return w({role:"combobox","aria-autocomplete":"list","aria-expanded":l,"aria-activedescendant":"number"==typeof a&&a>=0?s.getItemId(a):null,autoComplete:"off",value:u,onChange:d(t,s.input_handleChange),onKeyDown:d(n,s.input_handleKeyDown),onBlur:d(o,s.input_handleBlur)},r,{id:s.inputId})},s.input_handleKeyDown=function(e){e.key&&s.keyDownHandlers[e.key]?s.keyDownHandlers[e.key].call(s,e):["Shift","Meta","Alt","Control"].includes(e.key)||s.openMenu()},s.input_handleChange=function(e){s.internalSetState({inputValue:e.target.value})},s.input_handleBlur=function(){s.isMouseDown||s.reset()},s.getItemProps=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=e.onMouseEnter,n=e.item,o=e.index,r=x(e,["onMouseEnter","item","index"]);return s.items[o]=n,w({id:s.getItemId(o),onMouseEnter:d(t,function(){s.setHighlightedIndex(o)})},r)},s.reset=function(e){s.internalSetState(function(t){var n=t.selectedItem;return{type:e,isOpen:!1,highlightedIndex:null,inputValue:s.props.itemToString(n)}})},s.toggleMenu=function(e,t){s.internalSetState(function(t){var n=!t.isOpen;return"boolean"==typeof e&&(n=e),{isOpen:n}},function(){s.getState().isOpen&&s.setHighlightedIndex(),i(t)()})},s.openMenu=function(e){s.toggleMenu(!0,e)},s.closeMenu=function(e){s.toggleMenu(!1,e)},s.updateStatus=a(function(){if(s._isMounted){var e=s.getState(),t=s.getItemFromIndex(e.highlightedIndex)||{},o=s.items.length,r=s.props.getA11yStatusMessage(w({itemToString:s.props.itemToString,previousResultCount:s.previousResultCount,resultCount:o,highlightedItem:t},e));s.previousResultCount=o,n(r)}},200),s.id=p("downshift"),s.state={highlightedIndex:s.props.defaultHighlightedIndex,inputValue:s.props.defaultInputValue,isOpen:s.props.defaultIsOpen,selectedItem:s.props.defaultSelectedItem},s.root_handleClick=d(s.props.onClick,s.root_handleClick),s}return b(t,e),I(t,[{key:"getState",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:this.state;return Object.keys(t).reduce(function(t,n){return t[n]=void 0===e.props[n]?e.state[n]:e.props[n],t},{})}},{key:"maybeScrollToHighlightedElement",value:function(e){s(this.getItemNodeFromIndex(e),this._rootNode)}},{key:"internalSetState",value:function(e,t){var n=this,o={},r=void 0,u=void 0;return this.setState(function(t){t=n.getState(t);var i={},l={};return(r="function"==typeof e?e(t):e).hasOwnProperty("selectedItem")&&(o.selectedItem=r.selectedItem,o.previousItem=t.selectedItem),Object.keys(r).forEach(function(e){"type"!==e&&(l[e]=r[e],n.props.hasOwnProperty(e)||(i[e]=r[e]))}),u=!f(t,l),i},function(){i(t)(),u&&n.props.onStateChange(r),Object.keys(o).length&&n.props.onChange(o)})}},{key:"getControllerStateAndHelpers",value:function(){var e=this.getState(),t=e.highlightedIndex,n=e.inputValue,o=e.selectedItem,r=e.isOpen;return{getRootProps:this.getRootProps,getButtonProps:this.getButtonProps,getLabelProps:this.getLabelProps,getInputProps:this.getInputProps,getItemProps:this.getItemProps,openMenu:this.openMenu,closeMenu:this.closeMenu,toggleMenu:this.toggleMenu,selectItem:this.selectItem,selectItemAtIndex:this.selectItemAtIndex,selectHighlightedItem:this.selectHighlightedItem,setHighlightedIndex:this.setHighlightedIndex,clearSelection:this.clearSelection,highlightedIndex:t,inputValue:n,isOpen:r,selectedItem:o}}},{key:"getItemId",value:function(e){return this.id+"-item-"+e}},{key:"getItemIndexFromId",value:function(e){return e?Number(e.split(this.id+"-item-")[1]):null}},{key:"componentDidMount",value:function(){var e=this;this._isMounted=!0;var n=function(){e.isMouseDown=!0},o=function(n){e.isMouseDown=!1,e._rootNode.contains(n.target)||e.reset(t.stateChangeTypes.mouseUp)};window.addEventListener("mousedown",n),window.addEventListener("mouseup",o),this.cleanup=function(){e._isMounted=!1,window.removeEventListener("mousedown",n),window.removeEventListener("mouseup",o)}}},{key:"componentDidUpdate",value:function(){this.updateStatus()}},{key:"componentWillUnmount",value:function(){this.cleanup()}},{key:"render",value:function(){var e=this.props.children;this.items=[],this.getRootProps.called=!1,this.getRootProps.refKey=void 0,this.getLabelProps.called=!1,this.getInputProps.called=!1;var t=e&&e(this.getControllerStateAndHelpers());if(!t)return null;var n=m.Children.only(t);if(this.getRootProps.called)return g(n,this.getRootProps),n;if("string"==typeof n.type)return m.cloneElement(n,this.getRootProps(n.props));throw new Error("downshift: If you return a non-DOM element, you must use apply the getRootProps function")}}]),t}(e.Component);return M.propTypes={children:t.func,defaultHighlightedIndex:t.number,defaultSelectedItem:t.any,defaultInputValue:t.string,defaultIsOpen:t.bool,getA11yStatusMessage:t.func,itemToString:t.func,onChange:t.func,onStateChange:t.func,onClick:t.func,selectedItem:t.any,isOpen:t.bool,inputValue:t.string,highlightedIndex:t.number},M.defaultProps={defaultHighlightedIndex:null,defaultSelectedItem:null,defaultInputValue:"",defaultIsOpen:!1,getA11yStatusMessage:function(e){var t=e.isOpen,n=e.highlightedItem,o=e.selectedItem,r=e.resultCount,i=e.previousResultCount,u=e.itemToString;if(!t)return o?u(o):"";var l=r!==i;return r?!n||l?r+" "+(1===r?"result is":"results are")+" available, use up and down arrow keys to navigate.":u(n):"No results."},itemToString:function(e){return null==e?"":String(e)},onStateChange:function(){},onChange:function(){}},M.stateChangeTypes={mouseUp:"__autocomplete_mouseup__"},M});
//# sourceMappingURL=downshift.umd.min.js.map
{
"name": "downshift",
"version": "1.0.0-beta.21",
"version": "1.0.0-beta.22",
"description": "A set of primitives to build simple, flexible, WAI-ARIA compliant React autocomplete components",

@@ -5,0 +5,0 @@ "main": "dist/downshift.cjs.js",

@@ -195,3 +195,3 @@ <h1 align="center">

> `function({selectedItem, previousItem})` | *required*
> `function({selectedItem, previousItem})` | optional, no useful default

@@ -202,3 +202,3 @@ Called when the user selects an item

> `function({highlightedIndex, inputValue, isOpen, selectedItem})` | not required, no useful default
> `function({highlightedIndex, inputValue, isOpen, selectedItem})` | optional, no useful default

@@ -205,0 +205,0 @@ This function is called anytime the internal state changes. This can be useful

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc