UNPKG

react-autosuggest

Version:

WAI-ARIA compliant React autosuggest component

1,399 lines (1,180 loc) 115 kB
(function webpackUniversalModuleDefinition(root, factory) { if(typeof exports === 'object' && typeof module === 'object') module.exports = factory(require("React")); else if(typeof define === 'function' && define.amd) define(["React"], factory); else if(typeof exports === 'object') exports["Autosuggest"] = factory(require("React")); else root["Autosuggest"] = factory(root["React"]); })(this, function(__WEBPACK_EXTERNAL_MODULE_3__) { return /******/ (function(modules) { // webpackBootstrap /******/ // The module cache /******/ var installedModules = {}; /******/ // The require function /******/ function __webpack_require__(moduleId) { /******/ // Check if module is in cache /******/ if(installedModules[moduleId]) /******/ return installedModules[moduleId].exports; /******/ // Create a new module (and put it into the cache) /******/ var module = installedModules[moduleId] = { /******/ exports: {}, /******/ id: moduleId, /******/ loaded: false /******/ }; /******/ // Execute the module function /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); /******/ // Flag the module as loaded /******/ module.loaded = true; /******/ // Return the exports of the module /******/ return module.exports; /******/ } /******/ // expose the modules object (__webpack_modules__) /******/ __webpack_require__.m = modules; /******/ // expose the module cache /******/ __webpack_require__.c = installedModules; /******/ // __webpack_public_path__ /******/ __webpack_require__.p = ""; /******/ // Load entry module and return exports /******/ return __webpack_require__(0); /******/ }) /************************************************************************/ /******/ ([ /* 0 */ /***/ (function(module, exports, __webpack_require__) { 'use strict'; module.exports = __webpack_require__(1).default; /***/ }), /* 1 */ /***/ (function(module, exports, __webpack_require__) { /* WEBPACK VAR INJECTION */(function(process) {'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); var _react = __webpack_require__(3); var _react2 = _interopRequireDefault(_react); var _propTypes = __webpack_require__(4); var _propTypes2 = _interopRequireDefault(_propTypes); var _arrays = __webpack_require__(13); var _arrays2 = _interopRequireDefault(_arrays); var _reactAutowhatever = __webpack_require__(14); var _reactAutowhatever2 = _interopRequireDefault(_reactAutowhatever); var _theme = __webpack_require__(23); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } var alwaysTrue = function alwaysTrue() { return true; }; var defaultShouldRenderSuggestions = function defaultShouldRenderSuggestions(value) { return value.trim().length > 0; }; var defaultRenderSuggestionsContainer = function defaultRenderSuggestionsContainer(_ref) { var containerProps = _ref.containerProps, children = _ref.children; return _react2.default.createElement( 'div', containerProps, children ); }; var Autosuggest = function (_Component) { _inherits(Autosuggest, _Component); function Autosuggest(_ref2) { var alwaysRenderSuggestions = _ref2.alwaysRenderSuggestions; _classCallCheck(this, Autosuggest); var _this = _possibleConstructorReturn(this, (Autosuggest.__proto__ || Object.getPrototypeOf(Autosuggest)).call(this)); _initialiseProps.call(_this); _this.state = { isFocused: false, isCollapsed: !alwaysRenderSuggestions, highlightedSectionIndex: null, highlightedSuggestionIndex: null, highlightedSuggestion: null, valueBeforeUpDown: null }; _this.justPressedUpDown = false; _this.justMouseEntered = false; _this.pressedSuggestion = null; return _this; } _createClass(Autosuggest, [{ key: 'componentDidMount', value: function componentDidMount() { document.addEventListener('mousedown', this.onDocumentMouseDown); document.addEventListener('mouseup', this.onDocumentMouseUp); this.input = this.autowhatever.input; this.suggestionsContainer = this.autowhatever.itemsContainer; } }, { key: 'componentWillReceiveProps', value: function componentWillReceiveProps(nextProps) { if ((0, _arrays2.default)(nextProps.suggestions, this.props.suggestions)) { if (nextProps.highlightFirstSuggestion && nextProps.suggestions.length > 0 && this.justPressedUpDown === false && this.justMouseEntered === false) { this.highlightFirstSuggestion(); } } else { if (this.willRenderSuggestions(nextProps)) { if (this.state.isCollapsed && !this.justSelectedSuggestion) { this.revealSuggestions(); } } else { this.resetHighlightedSuggestion(); } } } }, { key: 'componentDidUpdate', value: function componentDidUpdate(prevProps, prevState) { var _props = this.props, suggestions = _props.suggestions, onSuggestionHighlighted = _props.onSuggestionHighlighted, highlightFirstSuggestion = _props.highlightFirstSuggestion; if (!(0, _arrays2.default)(suggestions, prevProps.suggestions) && suggestions.length > 0 && highlightFirstSuggestion) { this.highlightFirstSuggestion(); return; } if (onSuggestionHighlighted) { var highlightedSuggestion = this.getHighlightedSuggestion(); var prevHighlightedSuggestion = prevState.highlightedSuggestion; if (highlightedSuggestion != prevHighlightedSuggestion) { onSuggestionHighlighted({ suggestion: highlightedSuggestion }); } } } }, { key: 'componentWillUnmount', value: function componentWillUnmount() { document.removeEventListener('mousedown', this.onDocumentMouseDown); document.removeEventListener('mouseup', this.onDocumentMouseUp); } }, { key: 'updateHighlightedSuggestion', value: function updateHighlightedSuggestion(sectionIndex, suggestionIndex, prevValue) { var _this2 = this; this.setState(function (state) { var valueBeforeUpDown = state.valueBeforeUpDown; if (suggestionIndex === null) { valueBeforeUpDown = null; } else if (valueBeforeUpDown === null && typeof prevValue !== 'undefined') { valueBeforeUpDown = prevValue; } return { highlightedSectionIndex: sectionIndex, highlightedSuggestionIndex: suggestionIndex, highlightedSuggestion: suggestionIndex === null ? null : _this2.getSuggestion(sectionIndex, suggestionIndex), valueBeforeUpDown: valueBeforeUpDown }; }); } }, { key: 'resetHighlightedSuggestion', value: function resetHighlightedSuggestion() { var shouldResetValueBeforeUpDown = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true; this.setState(function (state) { var valueBeforeUpDown = state.valueBeforeUpDown; return { highlightedSectionIndex: null, highlightedSuggestionIndex: null, highlightedSuggestion: null, valueBeforeUpDown: shouldResetValueBeforeUpDown ? null : valueBeforeUpDown }; }); } }, { key: 'revealSuggestions', value: function revealSuggestions() { this.setState({ isCollapsed: false }); } }, { key: 'closeSuggestions', value: function closeSuggestions() { this.setState({ highlightedSectionIndex: null, highlightedSuggestionIndex: null, highlightedSuggestion: null, valueBeforeUpDown: null, isCollapsed: true }); } }, { key: 'getSuggestion', value: function getSuggestion(sectionIndex, suggestionIndex) { var _props2 = this.props, suggestions = _props2.suggestions, multiSection = _props2.multiSection, getSectionSuggestions = _props2.getSectionSuggestions; if (multiSection) { return getSectionSuggestions(suggestions[sectionIndex])[suggestionIndex]; } return suggestions[suggestionIndex]; } }, { key: 'getHighlightedSuggestion', value: function getHighlightedSuggestion() { var _state = this.state, highlightedSectionIndex = _state.highlightedSectionIndex, highlightedSuggestionIndex = _state.highlightedSuggestionIndex; if (highlightedSuggestionIndex === null) { return null; } return this.getSuggestion(highlightedSectionIndex, highlightedSuggestionIndex); } }, { key: 'getSuggestionValueByIndex', value: function getSuggestionValueByIndex(sectionIndex, suggestionIndex) { var getSuggestionValue = this.props.getSuggestionValue; return getSuggestionValue(this.getSuggestion(sectionIndex, suggestionIndex)); } }, { key: 'getSuggestionIndices', value: function getSuggestionIndices(suggestionElement) { var sectionIndex = suggestionElement.getAttribute('data-section-index'); var suggestionIndex = suggestionElement.getAttribute('data-suggestion-index'); return { sectionIndex: typeof sectionIndex === 'string' ? parseInt(sectionIndex, 10) : null, suggestionIndex: parseInt(suggestionIndex, 10) }; } }, { key: 'findSuggestionElement', value: function findSuggestionElement(startNode) { var node = startNode; do { if (node.getAttribute('data-suggestion-index') !== null) { return node; } node = node.parentNode; } while (node !== null); console.error('Clicked element:', startNode); // eslint-disable-line no-console throw new Error("Couldn't find suggestion element"); } }, { key: 'maybeCallOnChange', value: function maybeCallOnChange(event, newValue, method) { var _props$inputProps = this.props.inputProps, value = _props$inputProps.value, onChange = _props$inputProps.onChange; if (newValue !== value) { onChange(event, { newValue: newValue, method: method }); } } }, { key: 'willRenderSuggestions', value: function willRenderSuggestions(props) { var suggestions = props.suggestions, inputProps = props.inputProps, shouldRenderSuggestions = props.shouldRenderSuggestions; var value = inputProps.value; return suggestions.length > 0 && shouldRenderSuggestions(value); } }, { key: 'getQuery', value: function getQuery() { var inputProps = this.props.inputProps; var value = inputProps.value; var valueBeforeUpDown = this.state.valueBeforeUpDown; return (valueBeforeUpDown === null ? value : valueBeforeUpDown).trim(); } }, { key: 'render', value: function render() { var _this3 = this; var _props3 = this.props, suggestions = _props3.suggestions, renderInputComponent = _props3.renderInputComponent, onSuggestionsFetchRequested = _props3.onSuggestionsFetchRequested, renderSuggestion = _props3.renderSuggestion, inputProps = _props3.inputProps, multiSection = _props3.multiSection, renderSectionTitle = _props3.renderSectionTitle, id = _props3.id, getSectionSuggestions = _props3.getSectionSuggestions, theme = _props3.theme, getSuggestionValue = _props3.getSuggestionValue, alwaysRenderSuggestions = _props3.alwaysRenderSuggestions, highlightFirstSuggestion = _props3.highlightFirstSuggestion; var _state2 = this.state, isFocused = _state2.isFocused, isCollapsed = _state2.isCollapsed, highlightedSectionIndex = _state2.highlightedSectionIndex, highlightedSuggestionIndex = _state2.highlightedSuggestionIndex, valueBeforeUpDown = _state2.valueBeforeUpDown; var shouldRenderSuggestions = alwaysRenderSuggestions ? alwaysTrue : this.props.shouldRenderSuggestions; var value = inputProps.value, _onFocus = inputProps.onFocus, _onKeyDown = inputProps.onKeyDown; var willRenderSuggestions = this.willRenderSuggestions(this.props); var isOpen = alwaysRenderSuggestions || isFocused && !isCollapsed && willRenderSuggestions; var items = isOpen ? suggestions : []; var autowhateverInputProps = _extends({}, inputProps, { onFocus: function onFocus(event) { if (!_this3.justSelectedSuggestion && !_this3.justClickedOnSuggestionsContainer) { var shouldRender = shouldRenderSuggestions(value); _this3.setState({ isFocused: true, isCollapsed: !shouldRender }); _onFocus && _onFocus(event); if (shouldRender) { onSuggestionsFetchRequested({ value: value, reason: 'input-focused' }); } } }, onBlur: function onBlur(event) { if (_this3.justClickedOnSuggestionsContainer) { _this3.input.focus(); return; } _this3.blurEvent = event; if (!_this3.justSelectedSuggestion) { _this3.onBlur(); _this3.onSuggestionsClearRequested(); } }, onChange: function onChange(event) { var value = event.target.value; var shouldRender = shouldRenderSuggestions(value); _this3.maybeCallOnChange(event, value, 'type'); _this3.setState(_extends({}, highlightFirstSuggestion ? {} : { highlightedSectionIndex: null, highlightedSuggestionIndex: null, highlightedSuggestion: null }, { valueBeforeUpDown: null, isCollapsed: !shouldRender })); if (shouldRender) { onSuggestionsFetchRequested({ value: value, reason: 'input-changed' }); } else { _this3.onSuggestionsClearRequested(); } }, onKeyDown: function onKeyDown(event, data) { var keyCode = event.keyCode; switch (keyCode) { case 40: // ArrowDown case 38: // ArrowUp if (isCollapsed) { if (shouldRenderSuggestions(value)) { onSuggestionsFetchRequested({ value: value, reason: 'suggestions-revealed' }); _this3.revealSuggestions(); } } else if (suggestions.length > 0) { var newHighlightedSectionIndex = data.newHighlightedSectionIndex, newHighlightedItemIndex = data.newHighlightedItemIndex; var newValue = void 0; if (newHighlightedItemIndex === null) { // valueBeforeUpDown can be null if, for example, user // hovers on the first suggestion and then pressed Up. // If that happens, use the original input value. newValue = valueBeforeUpDown === null ? value : valueBeforeUpDown; } else { newValue = _this3.getSuggestionValueByIndex(newHighlightedSectionIndex, newHighlightedItemIndex); } _this3.updateHighlightedSuggestion(newHighlightedSectionIndex, newHighlightedItemIndex, value); _this3.maybeCallOnChange(event, newValue, keyCode === 40 ? 'down' : 'up'); } event.preventDefault(); // Prevents the cursor from moving _this3.justPressedUpDown = true; setTimeout(function () { _this3.justPressedUpDown = false; }); break; // Enter case 13: { // See #388 if (event.keyCode === 229) { break; } var highlightedSuggestion = _this3.getHighlightedSuggestion(); if (isOpen && !alwaysRenderSuggestions) { _this3.closeSuggestions(); } if (highlightedSuggestion != null) { var _newValue = getSuggestionValue(highlightedSuggestion); _this3.maybeCallOnChange(event, _newValue, 'enter'); _this3.onSuggestionSelected(event, { suggestion: highlightedSuggestion, suggestionValue: _newValue, suggestionIndex: highlightedSuggestionIndex, sectionIndex: highlightedSectionIndex, method: 'enter' }); _this3.justSelectedSuggestion = true; setTimeout(function () { _this3.justSelectedSuggestion = false; }); } break; } // Escape case 27: { if (isOpen) { // If input.type === 'search', the browser clears the input // when Escape is pressed. We want to disable this default // behaviour so that, when suggestions are shown, we just hide // them, without clearing the input. event.preventDefault(); } var willCloseSuggestions = isOpen && !alwaysRenderSuggestions; if (valueBeforeUpDown === null) { // Didn't interact with Up/Down if (!willCloseSuggestions) { var _newValue2 = ''; _this3.maybeCallOnChange(event, _newValue2, 'escape'); if (shouldRenderSuggestions(_newValue2)) { onSuggestionsFetchRequested({ value: _newValue2, reason: 'escape-pressed' }); } else { _this3.onSuggestionsClearRequested(); } } } else { // Interacted with Up/Down _this3.maybeCallOnChange(event, valueBeforeUpDown, 'escape'); } if (willCloseSuggestions) { _this3.onSuggestionsClearRequested(); _this3.closeSuggestions(); } else { _this3.resetHighlightedSuggestion(); } break; } } _onKeyDown && _onKeyDown(event); } }); var renderSuggestionData = { query: this.getQuery() }; return _react2.default.createElement(_reactAutowhatever2.default, { multiSection: multiSection, items: items, renderInputComponent: renderInputComponent, renderItemsContainer: this.renderSuggestionsContainer, renderItem: renderSuggestion, renderItemData: renderSuggestionData, renderSectionTitle: renderSectionTitle, getSectionItems: getSectionSuggestions, highlightedSectionIndex: highlightedSectionIndex, highlightedItemIndex: highlightedSuggestionIndex, inputProps: autowhateverInputProps, itemProps: this.itemProps, theme: (0, _theme.mapToAutowhateverTheme)(theme), id: id, ref: this.storeAutowhateverRef }); } }]); return Autosuggest; }(_react.Component); Autosuggest.defaultProps = { renderSuggestionsContainer: defaultRenderSuggestionsContainer, shouldRenderSuggestions: defaultShouldRenderSuggestions, alwaysRenderSuggestions: false, multiSection: false, focusInputOnSuggestionClick: true, highlightFirstSuggestion: false, theme: _theme.defaultTheme, id: '1' }; var _initialiseProps = function _initialiseProps() { var _this4 = this; this.onDocumentMouseDown = function (event) { _this4.justClickedOnSuggestionsContainer = false; var node = event.detail && event.detail.target || // This is for testing only. Please show me a better way to emulate this. event.target; while (node !== null && node !== document) { if (node.getAttribute('data-suggestion-index') !== null) { // Suggestion was clicked return; } if (node === _this4.suggestionsContainer) { // Something else inside suggestions container was clicked _this4.justClickedOnSuggestionsContainer = true; return; } node = node.parentNode; } }; this.storeAutowhateverRef = function (autowhatever) { if (autowhatever !== null) { _this4.autowhatever = autowhatever; } }; this.onSuggestionMouseEnter = function (event, _ref3) { var sectionIndex = _ref3.sectionIndex, itemIndex = _ref3.itemIndex; _this4.updateHighlightedSuggestion(sectionIndex, itemIndex); if (event.target === _this4.pressedSuggestion) { _this4.justSelectedSuggestion = true; } _this4.justMouseEntered = true; setTimeout(function () { _this4.justMouseEntered = false; }); }; this.highlightFirstSuggestion = function () { _this4.updateHighlightedSuggestion(_this4.props.multiSection ? 0 : null, 0); }; this.onDocumentMouseUp = function () { if (_this4.pressedSuggestion && !_this4.justSelectedSuggestion) { _this4.input.focus(); } _this4.pressedSuggestion = null; }; this.onSuggestionMouseDown = function (event) { // Checking if this.justSelectedSuggestion is already true to not duplicate touch events in chrome // See: https://github.com/facebook/react/issues/9809#issuecomment-413978405 if (!_this4.justSelectedSuggestion) { _this4.justSelectedSuggestion = true; _this4.pressedSuggestion = event.target; } }; this.onSuggestionsClearRequested = function () { var onSuggestionsClearRequested = _this4.props.onSuggestionsClearRequested; onSuggestionsClearRequested && onSuggestionsClearRequested(); }; this.onSuggestionSelected = function (event, data) { var _props4 = _this4.props, alwaysRenderSuggestions = _props4.alwaysRenderSuggestions, onSuggestionSelected = _props4.onSuggestionSelected, onSuggestionsFetchRequested = _props4.onSuggestionsFetchRequested; onSuggestionSelected && onSuggestionSelected(event, data); if (alwaysRenderSuggestions) { onSuggestionsFetchRequested({ value: data.suggestionValue, reason: 'suggestion-selected' }); } else { _this4.onSuggestionsClearRequested(); } _this4.resetHighlightedSuggestion(); }; this.onSuggestionClick = function (event) { var _props5 = _this4.props, alwaysRenderSuggestions = _props5.alwaysRenderSuggestions, focusInputOnSuggestionClick = _props5.focusInputOnSuggestionClick; var _getSuggestionIndices = _this4.getSuggestionIndices(_this4.findSuggestionElement(event.target)), sectionIndex = _getSuggestionIndices.sectionIndex, suggestionIndex = _getSuggestionIndices.suggestionIndex; var clickedSuggestion = _this4.getSuggestion(sectionIndex, suggestionIndex); var clickedSuggestionValue = _this4.props.getSuggestionValue(clickedSuggestion); _this4.maybeCallOnChange(event, clickedSuggestionValue, 'click'); _this4.onSuggestionSelected(event, { suggestion: clickedSuggestion, suggestionValue: clickedSuggestionValue, suggestionIndex: suggestionIndex, sectionIndex: sectionIndex, method: 'click' }); if (!alwaysRenderSuggestions) { _this4.closeSuggestions(); } if (focusInputOnSuggestionClick === true) { _this4.input.focus(); } else { _this4.onBlur(); } setTimeout(function () { _this4.justSelectedSuggestion = false; }); }; this.onBlur = function () { var _props6 = _this4.props, inputProps = _props6.inputProps, shouldRenderSuggestions = _props6.shouldRenderSuggestions; var value = inputProps.value, onBlur = inputProps.onBlur; var highlightedSuggestion = _this4.getHighlightedSuggestion(); var shouldRender = shouldRenderSuggestions(value); _this4.setState({ isFocused: false, highlightedSectionIndex: null, highlightedSuggestionIndex: null, highlightedSuggestion: null, valueBeforeUpDown: null, isCollapsed: !shouldRender }); onBlur && onBlur(_this4.blurEvent, { highlightedSuggestion: highlightedSuggestion }); }; this.onSuggestionMouseLeave = function (event) { _this4.resetHighlightedSuggestion(false); // shouldResetValueBeforeUpDown if (_this4.justSelectedSuggestion && event.target === _this4.pressedSuggestion) { _this4.justSelectedSuggestion = false; } }; this.onSuggestionTouchStart = function () { _this4.justSelectedSuggestion = true; // todo: event.preventDefault when https://github.com/facebook/react/issues/2043 // todo: gets released so onSuggestionMouseDown won't fire in chrome }; this.onSuggestionTouchMove = function () { _this4.justSelectedSuggestion = false; _this4.pressedSuggestion = null; _this4.input.focus(); }; this.itemProps = function (_ref4) { var sectionIndex = _ref4.sectionIndex, itemIndex = _ref4.itemIndex; return { 'data-section-index': sectionIndex, 'data-suggestion-index': itemIndex, onMouseEnter: _this4.onSuggestionMouseEnter, onMouseLeave: _this4.onSuggestionMouseLeave, onMouseDown: _this4.onSuggestionMouseDown, onTouchStart: _this4.onSuggestionTouchStart, onTouchMove: _this4.onSuggestionTouchMove, onClick: _this4.onSuggestionClick }; }; this.renderSuggestionsContainer = function (_ref5) { var containerProps = _ref5.containerProps, children = _ref5.children; var renderSuggestionsContainer = _this4.props.renderSuggestionsContainer; return renderSuggestionsContainer({ containerProps: containerProps, children: children, query: _this4.getQuery() }); }; }; exports.default = Autosuggest; Autosuggest.propTypes = process.env.NODE_ENV !== "production" ? { suggestions: _propTypes2.default.array.isRequired, onSuggestionsFetchRequested: function onSuggestionsFetchRequested(props, propName) { var onSuggestionsFetchRequested = props[propName]; if (typeof onSuggestionsFetchRequested !== 'function') { throw new Error("'onSuggestionsFetchRequested' must be implemented. See: https://github.com/moroshko/react-autosuggest#onSuggestionsFetchRequestedProp"); } }, onSuggestionsClearRequested: function onSuggestionsClearRequested(props, propName) { var onSuggestionsClearRequested = props[propName]; if (props.alwaysRenderSuggestions === false && typeof onSuggestionsClearRequested !== 'function') { throw new Error("'onSuggestionsClearRequested' must be implemented. See: https://github.com/moroshko/react-autosuggest#onSuggestionsClearRequestedProp"); } }, onSuggestionSelected: _propTypes2.default.func, onSuggestionHighlighted: _propTypes2.default.func, renderInputComponent: _propTypes2.default.func, renderSuggestionsContainer: _propTypes2.default.func, getSuggestionValue: _propTypes2.default.func.isRequired, renderSuggestion: _propTypes2.default.func.isRequired, inputProps: function inputProps(props, propName) { var inputProps = props[propName]; if (!inputProps.hasOwnProperty('value')) { throw new Error("'inputProps' must have 'value'."); } if (!inputProps.hasOwnProperty('onChange')) { throw new Error("'inputProps' must have 'onChange'."); } }, shouldRenderSuggestions: _propTypes2.default.func, alwaysRenderSuggestions: _propTypes2.default.bool, multiSection: _propTypes2.default.bool, renderSectionTitle: function renderSectionTitle(props, propName) { var renderSectionTitle = props[propName]; if (props.multiSection === true && typeof renderSectionTitle !== 'function') { throw new Error("'renderSectionTitle' must be implemented. See: https://github.com/moroshko/react-autosuggest#renderSectionTitleProp"); } }, getSectionSuggestions: function getSectionSuggestions(props, propName) { var getSectionSuggestions = props[propName]; if (props.multiSection === true && typeof getSectionSuggestions !== 'function') { throw new Error("'getSectionSuggestions' must be implemented. See: https://github.com/moroshko/react-autosuggest#getSectionSuggestionsProp"); } }, focusInputOnSuggestionClick: _propTypes2.default.bool, highlightFirstSuggestion: _propTypes2.default.bool, theme: _propTypes2.default.object, id: _propTypes2.default.string } : {}; /* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(2))) /***/ }), /* 2 */ /***/ (function(module, exports) { // shim for using process in browser var process = module.exports = {}; // cached from whatever global is present so that test runners that stub it // don't break things. But we need to wrap it in a try catch in case it is // wrapped in strict mode code which doesn't define any globals. It's inside a // function because try/catches deoptimize in certain engines. var cachedSetTimeout; var cachedClearTimeout; function defaultSetTimout() { throw new Error('setTimeout has not been defined'); } function defaultClearTimeout () { throw new Error('clearTimeout has not been defined'); } (function () { try { if (typeof setTimeout === 'function') { cachedSetTimeout = setTimeout; } else { cachedSetTimeout = defaultSetTimout; } } catch (e) { cachedSetTimeout = defaultSetTimout; } try { if (typeof clearTimeout === 'function') { cachedClearTimeout = clearTimeout; } else { cachedClearTimeout = defaultClearTimeout; } } catch (e) { cachedClearTimeout = defaultClearTimeout; } } ()) function runTimeout(fun) { if (cachedSetTimeout === setTimeout) { //normal enviroments in sane situations return setTimeout(fun, 0); } // if setTimeout wasn't available but was latter defined if ((cachedSetTimeout === defaultSetTimout || !cachedSetTimeout) && setTimeout) { cachedSetTimeout = setTimeout; return setTimeout(fun, 0); } try { // when when somebody has screwed with setTimeout but no I.E. maddness return cachedSetTimeout(fun, 0); } catch(e){ try { // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally return cachedSetTimeout.call(null, fun, 0); } catch(e){ // same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error return cachedSetTimeout.call(this, fun, 0); } } } function runClearTimeout(marker) { if (cachedClearTimeout === clearTimeout) { //normal enviroments in sane situations return clearTimeout(marker); } // if clearTimeout wasn't available but was latter defined if ((cachedClearTimeout === defaultClearTimeout || !cachedClearTimeout) && clearTimeout) { cachedClearTimeout = clearTimeout; return clearTimeout(marker); } try { // when when somebody has screwed with setTimeout but no I.E. maddness return cachedClearTimeout(marker); } catch (e){ try { // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally return cachedClearTimeout.call(null, marker); } catch (e){ // same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error. // Some versions of I.E. have different rules for clearTimeout vs setTimeout return cachedClearTimeout.call(this, marker); } } } var queue = []; var draining = false; var currentQueue; var queueIndex = -1; function cleanUpNextTick() { if (!draining || !currentQueue) { return; } draining = false; if (currentQueue.length) { queue = currentQueue.concat(queue); } else { queueIndex = -1; } if (queue.length) { drainQueue(); } } function drainQueue() { if (draining) { return; } var timeout = runTimeout(cleanUpNextTick); draining = true; var len = queue.length; while(len) { currentQueue = queue; queue = []; while (++queueIndex < len) { if (currentQueue) { currentQueue[queueIndex].run(); } } queueIndex = -1; len = queue.length; } currentQueue = null; draining = false; runClearTimeout(timeout); } process.nextTick = function (fun) { var args = new Array(arguments.length - 1); if (arguments.length > 1) { for (var i = 1; i < arguments.length; i++) { args[i - 1] = arguments[i]; } } queue.push(new Item(fun, args)); if (queue.length === 1 && !draining) { runTimeout(drainQueue); } }; // v8 likes predictible objects function Item(fun, array) { this.fun = fun; this.array = array; } Item.prototype.run = function () { this.fun.apply(null, this.array); }; process.title = 'browser'; process.browser = true; process.env = {}; process.argv = []; process.version = ''; // empty string to avoid regexp issues process.versions = {}; function noop() {} process.on = noop; process.addListener = noop; process.once = noop; process.off = noop; process.removeListener = noop; process.removeAllListeners = noop; process.emit = noop; process.prependListener = noop; process.prependOnceListener = noop; process.listeners = function (name) { return [] } process.binding = function (name) { throw new Error('process.binding is not supported'); }; process.cwd = function () { return '/' }; process.chdir = function (dir) { throw new Error('process.chdir is not supported'); }; process.umask = function() { return 0; }; /***/ }), /* 3 */ /***/ (function(module, exports) { module.exports = __WEBPACK_EXTERNAL_MODULE_3__; /***/ }), /* 4 */ /***/ (function(module, exports, __webpack_require__) { /* WEBPACK VAR INJECTION */(function(process) {/** * Copyright (c) 2013-present, Facebook, Inc. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */ if (process.env.NODE_ENV !== 'production') { var REACT_ELEMENT_TYPE = (typeof Symbol === 'function' && Symbol.for && Symbol.for('react.element')) || 0xeac7; var isValidElement = function(object) { return typeof object === 'object' && object !== null && object.$$typeof === REACT_ELEMENT_TYPE; }; // By explicitly using `prop-types` you are opting into new development behavior. // http://fb.me/prop-types-in-prod var throwOnDirectAccess = true; module.exports = __webpack_require__(5)(isValidElement, throwOnDirectAccess); } else { // By explicitly using `prop-types` you are opting into new production behavior. // http://fb.me/prop-types-in-prod module.exports = __webpack_require__(12)(); } /* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(2))) /***/ }), /* 5 */ /***/ (function(module, exports, __webpack_require__) { /* WEBPACK VAR INJECTION */(function(process) {/** * Copyright (c) 2013-present, Facebook, Inc. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */ 'use strict'; var emptyFunction = __webpack_require__(6); var invariant = __webpack_require__(7); var warning = __webpack_require__(8); var assign = __webpack_require__(9); var ReactPropTypesSecret = __webpack_require__(10); var checkPropTypes = __webpack_require__(11); module.exports = function(isValidElement, throwOnDirectAccess) { /* global Symbol */ var ITERATOR_SYMBOL = typeof Symbol === 'function' && Symbol.iterator; var FAUX_ITERATOR_SYMBOL = '@@iterator'; // Before Symbol spec. /** * Returns the iterator method function contained on the iterable object. * * Be sure to invoke the function with the iterable as context: * * var iteratorFn = getIteratorFn(myIterable); * if (iteratorFn) { * var iterator = iteratorFn.call(myIterable); * ... * } * * @param {?object} maybeIterable * @return {?function} */ function getIteratorFn(maybeIterable) { var iteratorFn = maybeIterable && (ITERATOR_SYMBOL && maybeIterable[ITERATOR_SYMBOL] || maybeIterable[FAUX_ITERATOR_SYMBOL]); if (typeof iteratorFn === 'function') { return iteratorFn; } } /** * Collection of methods that allow declaration and validation of props that are * supplied to React components. Example usage: * * var Props = require('ReactPropTypes'); * var MyArticle = React.createClass({ * propTypes: { * // An optional string prop named "description". * description: Props.string, * * // A required enum prop named "category". * category: Props.oneOf(['News','Photos']).isRequired, * * // A prop named "dialog" that requires an instance of Dialog. * dialog: Props.instanceOf(Dialog).isRequired * }, * render: function() { ... } * }); * * A more formal specification of how these methods are used: * * type := array|bool|func|object|number|string|oneOf([...])|instanceOf(...) * decl := ReactPropTypes.{type}(.isRequired)? * * Each and every declaration produces a function with the same signature. This * allows the creation of custom validation functions. For example: * * var MyLink = React.createClass({ * propTypes: { * // An optional string or URI prop named "href". * href: function(props, propName, componentName) { * var propValue = props[propName]; * if (propValue != null && typeof propValue !== 'string' && * !(propValue instanceof URI)) { * return new Error( * 'Expected a string or an URI for ' + propName + ' in ' + * componentName * ); * } * } * }, * render: function() {...} * }); * * @internal */ var ANONYMOUS = '<<anonymous>>'; // Important! // Keep this list in sync with production version in `./factoryWithThrowingShims.js`. var ReactPropTypes = { array: createPrimitiveTypeChecker('array'), bool: createPrimitiveTypeChecker('boolean'), func: createPrimitiveTypeChecker('function'), number: createPrimitiveTypeChecker('number'), object: createPrimitiveTypeChecker('object'), string: createPrimitiveTypeChecker('string'), symbol: createPrimitiveTypeChecker('symbol'), any: createAnyTypeChecker(), arrayOf: createArrayOfTypeChecker, element: createElementTypeChecker(), instanceOf: createInstanceTypeChecker, node: createNodeChecker(), objectOf: createObjectOfTypeChecker, oneOf: createEnumTypeChecker, oneOfType: createUnionTypeChecker, shape: createShapeTypeChecker, exact: createStrictShapeTypeChecker, }; /** * inlined Object.is polyfill to avoid requiring consumers ship their own * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is */ /*eslint-disable no-self-compare*/ function is(x, y) { // SameValue algorithm if (x === y) { // Steps 1-5, 7-10 // Steps 6.b-6.e: +0 != -0 return x !== 0 || 1 / x === 1 / y; } else { // Step 6.a: NaN == NaN return x !== x && y !== y; } } /*eslint-enable no-self-compare*/ /** * We use an Error-like object for backward compatibility as people may call * PropTypes directly and inspect their output. However, we don't use real * Errors anymore. We don't inspect their stack anyway, and creating them * is prohibitively expensive if they are created too often, such as what * happens in oneOfType() for any type before the one that matched. */ function PropTypeError(message) { this.message = message; this.stack = ''; } // Make `instanceof Error` still work for returned errors. PropTypeError.prototype = Error.prototype; function createChainableTypeChecker(validate) { if (process.env.NODE_ENV !== 'production') { var manualPropTypeCallCache = {}; var manualPropTypeWarningCount = 0; } function checkType(isRequired, props, propName, componentName, location, propFullName, secret) { componentName = componentName || ANONYMOUS; propFullName = propFullName || propName; if (secret !== ReactPropTypesSecret) { if (throwOnDirectAccess) { // New behavior only for users of `prop-types` package invariant( false, 'Calling PropTypes validators directly is not supported by the `prop-types` package. ' + 'Use `PropTypes.checkPropTypes()` to call them. ' + 'Read more at http://fb.me/use-check-prop-types' ); } else if (process.env.NODE_ENV !== 'production' && typeof console !== 'undefined') { // Old behavior for people using React.PropTypes var cacheKey = componentName + ':' + propName; if ( !manualPropTypeCallCache[cacheKey] && // Avoid spamming the console because they are often not actionable except for lib authors manualPropTypeWarningCount < 3 ) { warning( false, 'You are manually calling a React.PropTypes validation ' + 'function for the `%s` prop on `%s`. This is deprecated ' + 'and will throw in the standalone `prop-types` package. ' + 'You may be seeing this warning due to a third-party PropTypes ' + 'library. See https://fb.me/react-warning-dont-call-proptypes ' + 'for details.', propFullName, componentName ); manualPropTypeCallCache[cacheKey] = true; manualPropTypeWarningCount++; } } } if (props[propName] == null) { if (isRequired) { if (props[propName] === null) { return new PropTypeError('The ' + location + ' `' + propFullName + '` is marked as required ' + ('in `' + componentName + '`, but its value is `null`.')); } return new PropTypeError('The ' + location + ' `' + propFullName + '` is marked as required in ' + ('`' + componentName + '`, but its value is `undefined`.')); } return null; } else { return validate(props, propName, componentName, location, propFullName); } } var chainedCheckType = checkType.bind(null, false); chainedCheckType.isRequired = checkType.bind(null, true); return chainedCheckType; } function createPrimitiveTypeChecker(expectedType) { function validate(props, propName, componentName, location, propFullName, secret) { var propValue = props[propName]; var propType = getPropType(propValue); if (propType !== expectedType) { // `propValue` being instance of, say, date/regexp, pass the 'object' // check, but we can offer a more precise error message here rather than // 'of type `object`'. var preciseType = getPreciseType(propValue); return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type ' + ('`' + preciseType + '` supplied to `' + componentName + '`, expected ') + ('`' + expectedType + '`.')); } return null; } return createChainableTypeChecker(validate); } function createAnyTypeChecker() { return createChainableTypeChecker(emptyFunction.thatReturnsNull); } function createArrayOfTypeChecker(typeChecker) { function validate(props, propName, componentName, location, propFullName) { if (typeof typeChecker !== 'function') { return new PropTypeError('Property `' + propFullName + '` of component `' + componentName + '` has invalid PropType notation inside arrayOf.'); } var propValue = props[propName]; if (!Array.isArray(propValue)) { var propType = getPropType(propValue); return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type ' + ('`' + propType + '` supplied to `' + componentName + '`, expected an array.')); } for (var i = 0; i < propValue.length; i++) { var error = typeChecker(propValue, i, componentName, location, propFullName + '[' + i + ']', ReactPropTypesSecret); if (error instanceof Error) { return error; } } return null; } return createChainableTypeChecker(validate); } function createElementTypeChecker() { function validate(props, propName, componentName, location, propFullName) { var propValue = props[propName]; if (!isValidElement(propValue)) { var propType = getPropType(propValue); return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type ' + ('`' + propType + '` supplied to `' + componentName + '`, expected a single ReactElement.')); } return null; } return createChainableTypeChecker(validate); } function createInstanceTypeChecker(expectedClass) { function validate(props, propName, componentName, location, propFullName) { if (!(props[propName] instanceof expectedClass)) { var expectedClassName = expectedClass.name || ANONYMOUS; var actualClassName = getClassName(props[propName]); return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type ' + ('`' + actualClassName + '` supplied to `' + componentName + '`, expected ') + ('instance of `' + expectedClassName + '`.')); } return null; } return createChainableTypeChecker(validate); } function createEnumTypeChecker(expectedValues) { if (!Array.isArray(expectedValues)) { process.env.NODE_ENV !== 'production' ? warning(false, 'Invalid argument supplied to oneOf, expected an instance of array.') : void 0; return emptyFunction.thatReturnsNull; } function validate(props, propName, componentName, location, propFullName) { var propValue = props[propName]; for (var i = 0; i < expectedValues.length; i++) { if (is(propValue, expectedValues[i])) { return null; } } var valuesString = JSON.stringify(expectedValues); return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of value `' + propValue + '` ' + ('supplied to `' + componentName + '`, expected one of ' + valuesString + '.')); }