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.18 to 1.0.0-beta.19

4

dist/downshift.cjs.js

@@ -442,3 +442,3 @@ 'use strict';

var item = _this.getItemFromIndex(itemIndex);
if (!isNumber(item)) {
if (!item) {
return;

@@ -1028,3 +1028,3 @@ }

itemToString: function itemToString(i) {
return i == null ? String(i) : '';
return i == null ? '' : String(i);
},

@@ -1031,0 +1031,0 @@ onStateChange: function onStateChange() {} };

@@ -437,3 +437,3 @@ import React, { Component } from 'react';

var item = _this.getItemFromIndex(itemIndex);
if (!isNumber(item)) {
if (!item) {
return;

@@ -1023,3 +1023,3 @@ }

itemToString: function itemToString(i) {
return i == null ? String(i) : '';
return i == null ? '' : String(i);
},

@@ -1026,0 +1026,0 @@ onStateChange: function onStateChange() {} };

@@ -468,3 +468,3 @@ 'use strict';

var item = _this.getItemFromIndex(itemIndex);
if (!isNumber(item)) {
if (!item) {
return;

@@ -1054,3 +1054,3 @@ }

itemToString: function itemToString(i) {
return i == null ? String(i) : '';
return i == null ? '' : String(i);
},

@@ -1057,0 +1057,0 @@ onStateChange: function onStateChange() {} };

@@ -467,3 +467,3 @@ import { Component } from 'preact';

var item = _this.getItemFromIndex(itemIndex);
if (!isNumber(item)) {
if (!item) {
return;

@@ -1053,3 +1053,3 @@ }

itemToString: function itemToString(i) {
return i == null ? String(i) : '';
return i == null ? '' : String(i);
},

@@ -1056,0 +1056,0 @@ onStateChange: function onStateChange() {} };

@@ -471,3 +471,3 @@ (function (global, factory) {

var item = _this.getItemFromIndex(itemIndex);
if (!isNumber(item)) {
if (!item) {
return;

@@ -1057,3 +1057,3 @@ }

itemToString: function itemToString(i) {
return i == null ? String(i) : '';
return i == null ? '' : String(i);
},

@@ -1060,0 +1060,0 @@ onStateChange: function onStateChange() {} };

@@ -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(w(k),[e]):[e],i().innerHTML=""+k.filter(Boolean).map(o).join("")}function o(e,t){return'<div style="display:'+(t===k.length-1?"block":"none")+';">'+e+"</div>"}function i(){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 r(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 a(e,t,n){var o=l(e,t);if(null!==o){var i=getComputedStyle(o),r=o.getBoundingClientRect(),u=parseInt(i.borderTopWidth,10),a=r.top+u,s=e.getBoundingClientRect(),d=s.top+o.scrollTop-a;n||d<o.scrollTop?o.scrollTop=d:d+s.height>o.scrollTop+r.height&&(o.scrollTop=d+s.height-r.height)}}function s(e,t){var n=void 0;return function(){for(var o=arguments.length,i=Array(o),r=0;r<o;r++)i[r]=arguments[r];n&&clearTimeout(n),n=setTimeout(function(){n=null,e.apply(void 0,i)},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),i=1;i<n;i++)o[i-1]=arguments[i];return t.some(function(t){return t&&t.apply(void 0,[e].concat(o)),e.defaultPrevented})}}function c(e){return e+"-"+O++}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 p(e){return e===e&&"number"==typeof e}var g=e.default;g.Children={only:function(e){return e&&e[0]}},t.isRequired=t;var f={element:t,func:t,number:t,any:t,bool:t,string:t},m=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}}(),y=function(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e},v=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},w=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"),k=[],O=1,P=function(e){function t(){var e;m(this,t);for(var o=arguments.length,i=Array(o),u=0;u<o;u++)i[u]=arguments[u];var l=x(this,(e=t.__proto__||Object.getPrototypeOf(t)).call.apply(e,[this].concat(i)));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);p(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,i=t.onClick,r=S(t,["refKey","onClick"]);return l.getRootProps.called=!0,v((e={},y(e,o,l.rootRef),y(e,"onClick",d(i,l.root_handleClick)),e),r)},l.root_handleClick=function(e){e.preventDefault();var t=e.target;if(t){var n=l.getItemIndexFromId(t.getAttribute("id"));p(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=v({},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"]),i=l.getState().isOpen;return v({role:"button","aria-label":i?"close menu":"open menu","aria-expanded":i,"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,c("downshift-input")),v({},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,i=S(e,["onChange","onKeyDown","onBlur"]);if(l.getInputProps.called=!0,l.getLabelProps.called&&i.id&&i.id!==l.inputId)throw new Error('downshift: You provided the id of "'+i.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,i.id,c("downshift-input"));var r=l.getState(),u=r.inputValue,a=r.isOpen,s=r.highlightedIndex;return v({role:"combobox","aria-autocomplete":"list","aria-expanded":a,"aria-activedescendant":"number"==typeof s&&s>=0?l.getItemId(s):null,autoComplete:"off",value:u,onChange:d(t,l.input_handleChange),onKeyDown:d(n,l.input_handleKeyDown),onBlur:d(o,l.input_handleBlur)},i,{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,i=S(e,["onMouseEnter","item","index"]);return l.items[o]=n,v({id:l.getItemId(o),onMouseEnter:d(t,function(){l.setHighlightedIndex(o)})},i)},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(),r(t)()})},l.openMenu=function(e){l.toggleMenu(!0,e)},l.closeMenu=function(e){l.toggleMenu(!1,e)},l.updateStatus=s(function(){if(l._isMounted){var e=l.getState(),t=l.getItemFromIndex(e.highlightedIndex)||{},o=l.items.length,i=l.props.getA11yStatusMessage(v({itemToString:l.props.itemToString,previousResultCount:l.previousResultCount,resultCount:o,highlightedItem:t},e));l.previousResultCount=o,n(i)}},200),l.id=c("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){a(this.getItemNodeFromIndex(e),this._rootNode,t)}},{key:"internalSetState",value:function(e,t){var n=this,o={},i=void 0;return this.setState(function(t){t=n.getState(t);var r={};return(i="function"==typeof e?e(t):e).hasOwnProperty("selectedItem")&&(o.selectedItem=i.selectedItem,o.previousItem=t.selectedItem),Object.keys(i).forEach(function(e){"type"!==e&&(n.props.hasOwnProperty(e)||(r[e]=i[e]))}),r},function(){r(t)(),n.props.onStateChange(i),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,i=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:i,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;var o=n.target;e._rootNode.contains(o)||e.reset(t.stateChangeTypes.mouseUp)};document.body.addEventListener("mousedown",n),document.body.addEventListener("mouseup",o),this.cleanup=function(){e._isMounted=!1,document.body.removeEventListener("mousedown",n),document.body.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.getLabelProps.called=!1,this.getInputProps.called=!1;var t=g.Children.only(e(this.getControllerStateAndHelpers()));if(t){if(this.getRootProps.called)return t;if("string"==typeof t.type)return g.cloneElement(t,this.getRootProps(t.props));throw new Error("downshift: If you return a non-DOM element, you must use apply the getRootProps function")}return t}}]),t}(e.Component);return P.propTypes={children:f.func.isRequired,defaultHighlightedIndex:f.number,defaultSelectedItem:f.any,defaultInputValue:f.string,defaultIsOpen:f.bool,getA11yStatusMessage:f.func,itemToString:f.func,onChange:f.func.isRequired,onStateChange:f.func,onClick:f.func,selectedItem:f.any,isOpen:f.bool,inputValue:f.string,highlightedIndex:f.number},P.defaultProps={defaultHighlightedIndex:null,defaultSelectedItem:null,defaultInputValue:"",defaultIsOpen:!1,getA11yStatusMessage:function(e){var t=e.isOpen,n=e.highlightedItem,o=e.selectedItem,i=e.resultCount,r=e.previousResultCount,u=e.itemToString;if(!t)return o?u(o):"";var l=i!==r;return i?!n||l?i+" "+(1===i?"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(){}},P.stateChangeTypes={mouseUp:"__autocomplete_mouseup__"},P});
!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(w(k),[e]):[e],i().innerHTML=""+k.filter(Boolean).map(o).join("")}function o(e,t){return'<div style="display:'+(t===k.length-1?"block":"none")+';">'+e+"</div>"}function i(){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 r(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 a(e,t,n){var o=l(e,t);if(null!==o){var i=getComputedStyle(o),r=o.getBoundingClientRect(),u=parseInt(i.borderTopWidth,10),a=r.top+u,s=e.getBoundingClientRect(),d=s.top+o.scrollTop-a;n||d<o.scrollTop?o.scrollTop=d:d+s.height>o.scrollTop+r.height&&(o.scrollTop=d+s.height-r.height)}}function s(e,t){var n=void 0;return function(){for(var o=arguments.length,i=Array(o),r=0;r<o;r++)i[r]=arguments[r];n&&clearTimeout(n),n=setTimeout(function(){n=null,e.apply(void 0,i)},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),i=1;i<n;i++)o[i-1]=arguments[i];return t.some(function(t){return t&&t.apply(void 0,[e].concat(o)),e.defaultPrevented})}}function c(e){return e+"-"+O++}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 p(e){return e===e&&"number"==typeof e}var g=e.default;g.Children={only:function(e){return e&&e[0]}},t.isRequired=t;var f={element:t,func:t,number:t,any:t,bool:t,string:t},m=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}}(),y=function(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e},v=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},w=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"),k=[],O=1,P=function(e){function t(){var e;m(this,t);for(var o=arguments.length,i=Array(o),u=0;u<o;u++)i[u]=arguments[u];var l=x(this,(e=t.__proto__||Object.getPrototypeOf(t)).call.apply(e,[this].concat(i)));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,i=t.onClick,r=S(t,["refKey","onClick"]);return l.getRootProps.called=!0,v((e={},y(e,o,l.rootRef),y(e,"onClick",d(i,l.root_handleClick)),e),r)},l.root_handleClick=function(e){e.preventDefault();var t=e.target;if(t){var n=l.getItemIndexFromId(t.getAttribute("id"));p(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=v({},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"]),i=l.getState().isOpen;return v({role:"button","aria-label":i?"close menu":"open menu","aria-expanded":i,"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,c("downshift-input")),v({},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,i=S(e,["onChange","onKeyDown","onBlur"]);if(l.getInputProps.called=!0,l.getLabelProps.called&&i.id&&i.id!==l.inputId)throw new Error('downshift: You provided the id of "'+i.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,i.id,c("downshift-input"));var r=l.getState(),u=r.inputValue,a=r.isOpen,s=r.highlightedIndex;return v({role:"combobox","aria-autocomplete":"list","aria-expanded":a,"aria-activedescendant":"number"==typeof s&&s>=0?l.getItemId(s):null,autoComplete:"off",value:u,onChange:d(t,l.input_handleChange),onKeyDown:d(n,l.input_handleKeyDown),onBlur:d(o,l.input_handleBlur)},i,{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,i=S(e,["onMouseEnter","item","index"]);return l.items[o]=n,v({id:l.getItemId(o),onMouseEnter:d(t,function(){l.setHighlightedIndex(o)})},i)},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(),r(t)()})},l.openMenu=function(e){l.toggleMenu(!0,e)},l.closeMenu=function(e){l.toggleMenu(!1,e)},l.updateStatus=s(function(){if(l._isMounted){var e=l.getState(),t=l.getItemFromIndex(e.highlightedIndex)||{},o=l.items.length,i=l.props.getA11yStatusMessage(v({itemToString:l.props.itemToString,previousResultCount:l.previousResultCount,resultCount:o,highlightedItem:t},e));l.previousResultCount=o,n(i)}},200),l.id=c("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){a(this.getItemNodeFromIndex(e),this._rootNode,t)}},{key:"internalSetState",value:function(e,t){var n=this,o={},i=void 0;return this.setState(function(t){t=n.getState(t);var r={};return(i="function"==typeof e?e(t):e).hasOwnProperty("selectedItem")&&(o.selectedItem=i.selectedItem,o.previousItem=t.selectedItem),Object.keys(i).forEach(function(e){"type"!==e&&(n.props.hasOwnProperty(e)||(r[e]=i[e]))}),r},function(){r(t)(),n.props.onStateChange(i),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,i=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:i,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;var o=n.target;e._rootNode.contains(o)||e.reset(t.stateChangeTypes.mouseUp)};document.body.addEventListener("mousedown",n),document.body.addEventListener("mouseup",o),this.cleanup=function(){e._isMounted=!1,document.body.removeEventListener("mousedown",n),document.body.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.getLabelProps.called=!1,this.getInputProps.called=!1;var t=g.Children.only(e(this.getControllerStateAndHelpers()));if(t){if(this.getRootProps.called)return t;if("string"==typeof t.type)return g.cloneElement(t,this.getRootProps(t.props));throw new Error("downshift: If you return a non-DOM element, you must use apply the getRootProps function")}return t}}]),t}(e.Component);return P.propTypes={children:f.func.isRequired,defaultHighlightedIndex:f.number,defaultSelectedItem:f.any,defaultInputValue:f.string,defaultIsOpen:f.bool,getA11yStatusMessage:f.func,itemToString:f.func,onChange:f.func.isRequired,onStateChange:f.func,onClick:f.func,selectedItem:f.any,isOpen:f.bool,inputValue:f.string,highlightedIndex:f.number},P.defaultProps={defaultHighlightedIndex:null,defaultSelectedItem:null,defaultInputValue:"",defaultIsOpen:!1,getA11yStatusMessage:function(e){var t=e.isOpen,n=e.highlightedItem,o=e.selectedItem,i=e.resultCount,r=e.previousResultCount,u=e.itemToString;if(!t)return o?u(o):"";var l=i!==r;return i?!n||l?i+" "+(1===i?"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(){}},P.stateChangeTypes={mouseUp:"__autocomplete_mouseup__"},P});
//# sourceMappingURL=downshift.preact.umd.min.js.map

@@ -443,3 +443,3 @@ (function (global, factory) {

var item = _this.getItemFromIndex(itemIndex);
if (!isNumber(item)) {
if (!item) {
return;

@@ -1029,3 +1029,3 @@ }

itemToString: function itemToString(i) {
return i == null ? String(i) : '';
return i == null ? '' : String(i);
},

@@ -1032,0 +1032,0 @@ onStateChange: function onStateChange() {} };

@@ -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=C[C.length-1]===e;C=t?[].concat(x(C),[e]):[e],i().innerHTML=""+C.filter(Boolean).map(o).join("")}function o(e,t){return'<div style="display:'+(t===C.length-1?"block":"none")+';">'+e+"</div>"}function i(){return w||((w=document.createElement("div")).setAttribute("id","a11y-status-message"),w.setAttribute("role","status"),w.setAttribute("aria-live","assertive"),w.setAttribute("aria-relevant","additions text"),Object.assign(w.style,{border:"0",clip:"rect(0 0 0 0)",height:"1px",margin:"-1px",overflow:"hidden",padding:"0",position:"absolute",width:"1px"}),document.body.appendChild(w),w)}function r(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 a(e,t,n){var o=l(e,t);if(null!==o){var i=getComputedStyle(o),r=o.getBoundingClientRect(),u=parseInt(i.borderTopWidth,10),a=r.top+u,s=e.getBoundingClientRect(),d=s.top+o.scrollTop-a;n||d<o.scrollTop?o.scrollTop=d:d+s.height>o.scrollTop+r.height&&(o.scrollTop=d+s.height-r.height)}}function s(e,t){var n=void 0;return function(){for(var o=arguments.length,i=Array(o),r=0;r<o;r++)i[r]=arguments[r];n&&clearTimeout(n),n=setTimeout(function(){n=null,e.apply(void 0,i)},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),i=1;i<n;i++)o[i-1]=arguments[i];return t.some(function(t){return t&&t.apply(void 0,[e].concat(o)),e.defaultPrevented})}}function h(e){return e+"-"+O++}function c(){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 p(e){return e===e&&"number"==typeof e}var g="default"in e?e.default:e;t=t&&t.hasOwnProperty("default")?t.default:t;var f=function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")},m=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}}(),I=function(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e},y=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},v=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)},b=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},x=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)},w="undefined"==typeof document?null:document.getElementById("a11y-status-message"),C=[],O=1,k=function(e){function t(){var e;f(this,t);for(var o=arguments.length,i=Array(o),u=0;u<o;u++)i[u]=arguments[u];var l=S(this,(e=t.__proto__||Object.getPrototypeOf(t)).call.apply(e,[this].concat(i)));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);p(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,i=t.onClick,r=b(t,["refKey","onClick"]);return l.getRootProps.called=!0,y((e={},I(e,o,l.rootRef),I(e,"onClick",d(i,l.root_handleClick)),e),r)},l.root_handleClick=function(e){e.preventDefault();var t=e.target;if(t){var n=l.getItemIndexFromId(t.getAttribute("id"));p(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=y({},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=b(e,["onClick","onKeyDown"]),i=l.getState().isOpen;return y({role:"button","aria-label":i?"close menu":"open menu","aria-expanded":i,"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=c(l.inputId,e.htmlFor,h("downshift-input")),y({},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,i=b(e,["onChange","onKeyDown","onBlur"]);if(l.getInputProps.called=!0,l.getLabelProps.called&&i.id&&i.id!==l.inputId)throw new Error('downshift: You provided the id of "'+i.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=c(l.inputId,i.id,h("downshift-input"));var r=l.getState(),u=r.inputValue,a=r.isOpen,s=r.highlightedIndex;return y({role:"combobox","aria-autocomplete":"list","aria-expanded":a,"aria-activedescendant":"number"==typeof s&&s>=0?l.getItemId(s):null,autoComplete:"off",value:u,onChange:d(t,l.input_handleChange),onKeyDown:d(n,l.input_handleKeyDown),onBlur:d(o,l.input_handleBlur)},i,{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,i=b(e,["onMouseEnter","item","index"]);return l.items[o]=n,y({id:l.getItemId(o),onMouseEnter:d(t,function(){l.setHighlightedIndex(o)})},i)},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(),r(t)()})},l.openMenu=function(e){l.toggleMenu(!0,e)},l.closeMenu=function(e){l.toggleMenu(!1,e)},l.updateStatus=s(function(){if(l._isMounted){var e=l.getState(),t=l.getItemFromIndex(e.highlightedIndex)||{},o=l.items.length,i=l.props.getA11yStatusMessage(y({itemToString:l.props.itemToString,previousResultCount:l.previousResultCount,resultCount:o,highlightedItem:t},e));l.previousResultCount=o,n(i)}},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 v(t,e),m(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){a(this.getItemNodeFromIndex(e),this._rootNode,t)}},{key:"internalSetState",value:function(e,t){var n=this,o={},i=void 0;return this.setState(function(t){t=n.getState(t);var r={};return(i="function"==typeof e?e(t):e).hasOwnProperty("selectedItem")&&(o.selectedItem=i.selectedItem,o.previousItem=t.selectedItem),Object.keys(i).forEach(function(e){"type"!==e&&(n.props.hasOwnProperty(e)||(r[e]=i[e]))}),r},function(){r(t)(),n.props.onStateChange(i),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,i=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:i,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;var o=n.target;e._rootNode.contains(o)||e.reset(t.stateChangeTypes.mouseUp)};document.body.addEventListener("mousedown",n),document.body.addEventListener("mouseup",o),this.cleanup=function(){e._isMounted=!1,document.body.removeEventListener("mousedown",n),document.body.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.getLabelProps.called=!1,this.getInputProps.called=!1;var t=g.Children.only(e(this.getControllerStateAndHelpers()));if(t){if(this.getRootProps.called)return t;if("string"==typeof t.type)return g.cloneElement(t,this.getRootProps(t.props));throw new Error("downshift: If you return a non-DOM element, you must use apply the getRootProps function")}return t}}]),t}(e.Component);return k.propTypes={children:t.func.isRequired,defaultHighlightedIndex:t.number,defaultSelectedItem:t.any,defaultInputValue:t.string,defaultIsOpen:t.bool,getA11yStatusMessage:t.func,itemToString:t.func,onChange:t.func.isRequired,onStateChange:t.func,onClick:t.func,selectedItem:t.any,isOpen:t.bool,inputValue:t.string,highlightedIndex:t.number},k.defaultProps={defaultHighlightedIndex:null,defaultSelectedItem:null,defaultInputValue:"",defaultIsOpen:!1,getA11yStatusMessage:function(e){var t=e.isOpen,n=e.highlightedItem,o=e.selectedItem,i=e.resultCount,r=e.previousResultCount,u=e.itemToString;if(!t)return o?u(o):"";var l=i!==r;return i?!n||l?i+" "+(1===i?"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(){}},k.stateChangeTypes={mouseUp:"__autocomplete_mouseup__"},k});
!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=C[C.length-1]===e;C=t?[].concat(x(C),[e]):[e],i().innerHTML=""+C.filter(Boolean).map(o).join("")}function o(e,t){return'<div style="display:'+(t===C.length-1?"block":"none")+';">'+e+"</div>"}function i(){return w||((w=document.createElement("div")).setAttribute("id","a11y-status-message"),w.setAttribute("role","status"),w.setAttribute("aria-live","assertive"),w.setAttribute("aria-relevant","additions text"),Object.assign(w.style,{border:"0",clip:"rect(0 0 0 0)",height:"1px",margin:"-1px",overflow:"hidden",padding:"0",position:"absolute",width:"1px"}),document.body.appendChild(w),w)}function r(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 a(e,t,n){var o=l(e,t);if(null!==o){var i=getComputedStyle(o),r=o.getBoundingClientRect(),u=parseInt(i.borderTopWidth,10),a=r.top+u,s=e.getBoundingClientRect(),d=s.top+o.scrollTop-a;n||d<o.scrollTop?o.scrollTop=d:d+s.height>o.scrollTop+r.height&&(o.scrollTop=d+s.height-r.height)}}function s(e,t){var n=void 0;return function(){for(var o=arguments.length,i=Array(o),r=0;r<o;r++)i[r]=arguments[r];n&&clearTimeout(n),n=setTimeout(function(){n=null,e.apply(void 0,i)},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),i=1;i<n;i++)o[i-1]=arguments[i];return t.some(function(t){return t&&t.apply(void 0,[e].concat(o)),e.defaultPrevented})}}function h(e){return e+"-"+O++}function c(){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 p(e){return e===e&&"number"==typeof e}var g="default"in e?e.default:e;t=t&&t.hasOwnProperty("default")?t.default:t;var f=function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")},m=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}}(),I=function(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e},y=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},v=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)},b=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},x=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)},w="undefined"==typeof document?null:document.getElementById("a11y-status-message"),C=[],O=1,k=function(e){function t(){var e;f(this,t);for(var o=arguments.length,i=Array(o),u=0;u<o;u++)i[u]=arguments[u];var l=S(this,(e=t.__proto__||Object.getPrototypeOf(t)).call.apply(e,[this].concat(i)));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,i=t.onClick,r=b(t,["refKey","onClick"]);return l.getRootProps.called=!0,y((e={},I(e,o,l.rootRef),I(e,"onClick",d(i,l.root_handleClick)),e),r)},l.root_handleClick=function(e){e.preventDefault();var t=e.target;if(t){var n=l.getItemIndexFromId(t.getAttribute("id"));p(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=y({},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=b(e,["onClick","onKeyDown"]),i=l.getState().isOpen;return y({role:"button","aria-label":i?"close menu":"open menu","aria-expanded":i,"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=c(l.inputId,e.htmlFor,h("downshift-input")),y({},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,i=b(e,["onChange","onKeyDown","onBlur"]);if(l.getInputProps.called=!0,l.getLabelProps.called&&i.id&&i.id!==l.inputId)throw new Error('downshift: You provided the id of "'+i.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=c(l.inputId,i.id,h("downshift-input"));var r=l.getState(),u=r.inputValue,a=r.isOpen,s=r.highlightedIndex;return y({role:"combobox","aria-autocomplete":"list","aria-expanded":a,"aria-activedescendant":"number"==typeof s&&s>=0?l.getItemId(s):null,autoComplete:"off",value:u,onChange:d(t,l.input_handleChange),onKeyDown:d(n,l.input_handleKeyDown),onBlur:d(o,l.input_handleBlur)},i,{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,i=b(e,["onMouseEnter","item","index"]);return l.items[o]=n,y({id:l.getItemId(o),onMouseEnter:d(t,function(){l.setHighlightedIndex(o)})},i)},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(),r(t)()})},l.openMenu=function(e){l.toggleMenu(!0,e)},l.closeMenu=function(e){l.toggleMenu(!1,e)},l.updateStatus=s(function(){if(l._isMounted){var e=l.getState(),t=l.getItemFromIndex(e.highlightedIndex)||{},o=l.items.length,i=l.props.getA11yStatusMessage(y({itemToString:l.props.itemToString,previousResultCount:l.previousResultCount,resultCount:o,highlightedItem:t},e));l.previousResultCount=o,n(i)}},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 v(t,e),m(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){a(this.getItemNodeFromIndex(e),this._rootNode,t)}},{key:"internalSetState",value:function(e,t){var n=this,o={},i=void 0;return this.setState(function(t){t=n.getState(t);var r={};return(i="function"==typeof e?e(t):e).hasOwnProperty("selectedItem")&&(o.selectedItem=i.selectedItem,o.previousItem=t.selectedItem),Object.keys(i).forEach(function(e){"type"!==e&&(n.props.hasOwnProperty(e)||(r[e]=i[e]))}),r},function(){r(t)(),n.props.onStateChange(i),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,i=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:i,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;var o=n.target;e._rootNode.contains(o)||e.reset(t.stateChangeTypes.mouseUp)};document.body.addEventListener("mousedown",n),document.body.addEventListener("mouseup",o),this.cleanup=function(){e._isMounted=!1,document.body.removeEventListener("mousedown",n),document.body.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.getLabelProps.called=!1,this.getInputProps.called=!1;var t=g.Children.only(e(this.getControllerStateAndHelpers()));if(t){if(this.getRootProps.called)return t;if("string"==typeof t.type)return g.cloneElement(t,this.getRootProps(t.props));throw new Error("downshift: If you return a non-DOM element, you must use apply the getRootProps function")}return t}}]),t}(e.Component);return k.propTypes={children:t.func.isRequired,defaultHighlightedIndex:t.number,defaultSelectedItem:t.any,defaultInputValue:t.string,defaultIsOpen:t.bool,getA11yStatusMessage:t.func,itemToString:t.func,onChange:t.func.isRequired,onStateChange:t.func,onClick:t.func,selectedItem:t.any,isOpen:t.bool,inputValue:t.string,highlightedIndex:t.number},k.defaultProps={defaultHighlightedIndex:null,defaultSelectedItem:null,defaultInputValue:"",defaultIsOpen:!1,getA11yStatusMessage:function(e){var t=e.isOpen,n=e.highlightedItem,o=e.selectedItem,i=e.resultCount,r=e.previousResultCount,u=e.itemToString;if(!t)return o?u(o):"";var l=i!==r;return i?!n||l?i+" "+(1===i?"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(){}},k.stateChangeTypes={mouseUp:"__autocomplete_mouseup__"},k});
//# sourceMappingURL=downshift.umd.min.js.map
{
"name": "downshift",
"version": "1.0.0-beta.18",
"version": "1.0.0-beta.19",
"description": "A set of primitives to build simple, flexible, WAI-ARIA compliant React autocomplete components",

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

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

> `function(item: any)` | defaults to: `i => (i == null ? String(i) : '')`
> `function(item: any)` | defaults to: `i => (i == null ? '' : String(i))`

@@ -162,0 +162,0 @@ Used to determine the string value for the selected item (which is used to

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