From 1aa5134a1c2fd72daedabb45c2a81483c8bfeb96 Mon Sep 17 00:00:00 2001 From: Jed Watson Date: Sun, 10 Sep 2017 00:00:50 +1000 Subject: [PATCH] Updating build --- dist/react-select.js | 4288 +++++++++++++++-------------- dist/react-select.min.css | 2 +- dist/react-select.min.js | 3 +- examples/dist/example.less | 555 ++++ examples/dist/standalone.html | 4 +- lib/Async.js | 349 +-- lib/AsyncCreatable.js | 78 +- lib/Creatable.js | 338 +-- lib/Option.js | 115 +- lib/Select.js | 903 +++--- lib/Value.js | 101 +- lib/index.js | 40 +- lib/utils/defaultArrowRenderer.js | 29 +- lib/utils/defaultClearRenderer.js | 22 +- lib/utils/defaultFilterOptions.js | 26 +- lib/utils/defaultMenuRenderer.js | 63 +- lib/utils/stripDiacritics.js | 4 +- 17 files changed, 3668 insertions(+), 3252 deletions(-) create mode 100644 examples/dist/example.less diff --git a/dist/react-select.js b/dist/react-select.js index b98d5cb108..20821719ac 100644 --- a/dist/react-select.js +++ b/dist/react-select.js @@ -1,2337 +1,2489 @@ -(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.Select = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o -1) return false; + if (props.filterOption) return props.filterOption.call(_this, option, filterValue); + if (!filterValue) return true; + var valueTest = String(option[props.valueKey]); + var labelTest = String(option[props.labelKey]); + if (props.ignoreAccents) { + if (props.matchProp !== 'label') valueTest = stripDiacritics(valueTest); + if (props.matchProp !== 'value') labelTest = stripDiacritics(labelTest); + } + if (props.ignoreCase) { + if (props.matchProp !== 'label') valueTest = valueTest.toLowerCase(); + if (props.matchProp !== 'value') labelTest = labelTest.toLowerCase(); + } + return props.matchPos === 'start' ? props.matchProp !== 'label' && valueTest.substr(0, filterValue.length) === filterValue || props.matchProp !== 'value' && labelTest.substr(0, filterValue.length) === filterValue : props.matchProp !== 'label' && valueTest.indexOf(filterValue) >= 0 || props.matchProp !== 'value' && labelTest.indexOf(filterValue) >= 0; + }); +} -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; } +function menuRenderer(_ref) { + var focusedOption = _ref.focusedOption, + instancePrefix = _ref.instancePrefix, + labelKey = _ref.labelKey, + onFocus = _ref.onFocus, + onSelect = _ref.onSelect, + optionClassName = _ref.optionClassName, + optionComponent = _ref.optionComponent, + optionRenderer = _ref.optionRenderer, + options = _ref.options, + valueArray = _ref.valueArray, + valueKey = _ref.valueKey, + onOptionRef = _ref.onOptionRef; -var _react = (typeof window !== "undefined" ? window['React'] : typeof global !== "undefined" ? global['React'] : null); + var Option = optionComponent; -var _react2 = _interopRequireDefault(_react); + return options.map(function (option, i) { + var isSelected = valueArray && valueArray.indexOf(option) > -1; + var isFocused = option === focusedOption; + var optionClass = classNames(optionClassName, { + 'Select-option': true, + 'is-selected': isSelected, + 'is-focused': isFocused, + 'is-disabled': option.disabled + }); -var _propTypes = require('prop-types'); + return React__default.createElement( + Option, + { + className: optionClass, + instancePrefix: instancePrefix, + isDisabled: option.disabled, + isFocused: isFocused, + isSelected: isSelected, + key: 'option-' + i + '-' + option[valueKey], + onFocus: onFocus, + onSelect: onSelect, + option: option, + optionIndex: i, + ref: function ref(_ref2) { + onOptionRef(_ref2, isFocused); + } + }, + optionRenderer(option, i) + ); + }); +} -var _propTypes2 = _interopRequireDefault(_propTypes); +function clearRenderer() { + return React__default.createElement('span', { + className: 'Select-clear', + dangerouslySetInnerHTML: { __html: '×' } + }); +} -var _Select = require('./Select'); +var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { + return typeof obj; +} : function (obj) { + return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; +}; -var _Select2 = _interopRequireDefault(_Select); -var _utilsStripDiacritics = require('./utils/stripDiacritics'); -var _utilsStripDiacritics2 = _interopRequireDefault(_utilsStripDiacritics); -var propTypes = { - autoload: _propTypes2['default'].bool.isRequired, // automatically call the `loadOptions` prop on-mount; defaults to true - cache: _propTypes2['default'].any, // object to use to cache results; set to null/false to disable caching - children: _propTypes2['default'].func.isRequired, // Child function responsible for creating the inner Select component; (props: Object): PropTypes.element - ignoreAccents: _propTypes2['default'].bool, // strip diacritics when filtering; defaults to true - ignoreCase: _propTypes2['default'].bool, // perform case-insensitive filtering; defaults to true - loadingPlaceholder: _propTypes2['default'].oneOfType([// replaces the placeholder while options are loading - _propTypes2['default'].string, _propTypes2['default'].node]), - loadOptions: _propTypes2['default'].func.isRequired, // callback to load options asynchronously; (inputValue: string, callback: Function): ?Promise - multi: _propTypes2['default'].bool, // multi-value input - options: _propTypes2['default'].array.isRequired, // array of options - placeholder: _propTypes2['default'].oneOfType([// field placeholder, displayed when there's no value (shared with Select) - _propTypes2['default'].string, _propTypes2['default'].node]), - noResultsText: _propTypes2['default'].oneOfType([// field noResultsText, displayed when no options come back from the server - _propTypes2['default'].string, _propTypes2['default'].node]), - onChange: _propTypes2['default'].func, // onChange handler: function (newValue) {} - searchPromptText: _propTypes2['default'].oneOfType([// label to prompt for search input - _propTypes2['default'].string, _propTypes2['default'].node]), - onInputChange: _propTypes2['default'].func, // optional for keeping track of what is being typed - value: _propTypes2['default'].any }; - -// initial field value -var defaultCache = {}; -var defaultProps = { - autoload: true, - cache: defaultCache, - children: defaultChildren, - ignoreAccents: true, - ignoreCase: true, - loadingPlaceholder: 'Loading...', - options: [], - searchPromptText: 'Type to search' +var asyncGenerator = function () { + function AwaitValue(value) { + this.value = value; + } + + function AsyncGenerator(gen) { + var front, back; + + function send(key, arg) { + return new Promise(function (resolve, reject) { + var request = { + key: key, + arg: arg, + resolve: resolve, + reject: reject, + next: null + }; + + if (back) { + back = back.next = request; + } else { + front = back = request; + resume(key, arg); + } + }); + } + + function resume(key, arg) { + try { + var result = gen[key](arg); + var value = result.value; + + if (value instanceof AwaitValue) { + Promise.resolve(value.value).then(function (arg) { + resume("next", arg); + }, function (arg) { + resume("throw", arg); + }); + } else { + settle(result.done ? "return" : "normal", result.value); + } + } catch (err) { + settle("throw", err); + } + } + + function settle(type, value) { + switch (type) { + case "return": + front.resolve({ + value: value, + done: true + }); + break; + + case "throw": + front.reject(value); + break; + + default: + front.resolve({ + value: value, + done: false + }); + break; + } + + front = front.next; + + if (front) { + resume(front.key, front.arg); + } else { + back = null; + } + } + + this._invoke = send; + + if (typeof gen.return !== "function") { + this.return = undefined; + } + } + + if (typeof Symbol === "function" && Symbol.asyncIterator) { + AsyncGenerator.prototype[Symbol.asyncIterator] = function () { + return this; + }; + } + + AsyncGenerator.prototype.next = function (arg) { + return this._invoke("next", arg); + }; + + AsyncGenerator.prototype.throw = function (arg) { + return this._invoke("throw", arg); + }; + + AsyncGenerator.prototype.return = function (arg) { + return this._invoke("return", arg); + }; + + return { + wrap: function (fn) { + return function () { + return new AsyncGenerator(fn.apply(this, arguments)); + }; + }, + await: function (value) { + return new AwaitValue(value); + } + }; +}(); + + + + + +var classCallCheck = function (instance, Constructor) { + if (!(instance instanceof Constructor)) { + throw new TypeError("Cannot call a class as a function"); + } }; -var Async = (function (_Component) { - _inherits(Async, _Component); +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 defineProperty = function (obj, key, value) { + if (key in obj) { + Object.defineProperty(obj, key, { + value: value, + enumerable: true, + configurable: true, + writable: true + }); + } else { + obj[key] = value; + } + + return obj; +}; - function Async(props, context) { - _classCallCheck(this, Async); +var _extends = Object.assign || function (target) { + for (var i = 1; i < arguments.length; i++) { + var source = arguments[i]; - _get(Object.getPrototypeOf(Async.prototype), 'constructor', this).call(this, props, context); + for (var key in source) { + if (Object.prototype.hasOwnProperty.call(source, key)) { + target[key] = source[key]; + } + } + } - this._cache = props.cache === defaultCache ? {} : props.cache; + return target; +}; - this.state = { - isLoading: false, - options: props.options - }; - this._onInputChange = this._onInputChange.bind(this); - } - _createClass(Async, [{ - key: 'componentDidMount', - value: function componentDidMount() { - var autoload = this.props.autoload; +var inherits = function (subClass, superClass) { + if (typeof superClass !== "function" && superClass !== null) { + throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); + } - if (autoload) { - this.loadOptions(''); - } - } - }, { - key: 'componentWillUpdate', - value: function componentWillUpdate(nextProps, nextState) { - var _this = this; + 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 propertiesToSync = ['options']; - propertiesToSync.forEach(function (prop) { - if (_this.props[prop] !== nextProps[prop]) { - _this.setState(_defineProperty({}, prop, nextProps[prop])); - } - }); - } - }, { - key: 'clearOptions', - value: function clearOptions() { - this.setState({ options: [] }); - } - }, { - key: 'loadOptions', - value: function loadOptions(inputValue) { - var _this2 = this; - var loadOptions = this.props.loadOptions; - var cache = this._cache; - if (cache && cache.hasOwnProperty(inputValue)) { - this.setState({ - options: cache[inputValue] - }); - return; - } - var callback = function callback(error, data) { - if (callback === _this2._callback) { - _this2._callback = null; - var options = data && data.options || []; - if (cache) { - cache[inputValue] = options; - } - _this2.setState({ - isLoading: false, - options: options - }); - } - }; +var objectWithoutProperties = function (obj, keys) { + var target = {}; - // Ignore all but the most recent request - this._callback = callback; + for (var i in obj) { + if (keys.indexOf(i) >= 0) continue; + if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; + target[i] = obj[i]; + } - var promise = loadOptions(inputValue, callback); - if (promise) { - promise.then(function (data) { - return callback(null, data); - }, function (error) { - return callback(error); - }); - } + return target; +}; - if (this._callback && !this.state.isLoading) { - this.setState({ - isLoading: true - }); - } +var possibleConstructorReturn = function (self, call) { + if (!self) { + throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + } - return inputValue; - } - }, { - key: '_onInputChange', - value: function _onInputChange(inputValue) { - var _props = this.props; - var ignoreAccents = _props.ignoreAccents; - var ignoreCase = _props.ignoreCase; - var onInputChange = _props.onInputChange; + return call && (typeof call === "object" || typeof call === "function") ? call : self; +}; - if (ignoreAccents) { - inputValue = (0, _utilsStripDiacritics2['default'])(inputValue); - } +var Option = function (_React$Component) { + inherits(Option, _React$Component); - if (ignoreCase) { - inputValue = inputValue.toLowerCase(); - } + function Option(props) { + classCallCheck(this, Option); - if (onInputChange) { - onInputChange(inputValue); - } + var _this = possibleConstructorReturn(this, (Option.__proto__ || Object.getPrototypeOf(Option)).call(this, props)); - return this.loadOptions(inputValue); + _this.handleMouseDown = _this.handleMouseDown.bind(_this); + _this.handleMouseEnter = _this.handleMouseEnter.bind(_this); + _this.handleMouseMove = _this.handleMouseMove.bind(_this); + _this.handleTouchStart = _this.handleTouchStart.bind(_this); + _this.handleTouchEnd = _this.handleTouchEnd.bind(_this); + _this.handleTouchMove = _this.handleTouchMove.bind(_this); + _this.onFocus = _this.onFocus.bind(_this); + return _this; + } + + createClass(Option, [{ + key: 'blockEvent', + value: function blockEvent(event) { + event.preventDefault(); + event.stopPropagation(); + if (event.target.tagName !== 'A' || !('href' in event.target)) { + return; + } + if (event.target.target) { + window.open(event.target.href, event.target.target); + } else { + window.location.href = event.target.href; + } } }, { - key: 'inputValue', - value: function inputValue() { - if (this.select) { - return this.select.state.inputValue; - } - return ''; + key: 'handleMouseDown', + value: function handleMouseDown(event) { + event.preventDefault(); + event.stopPropagation(); + this.props.onSelect(this.props.option, event); } }, { - key: 'noResultsText', - value: function noResultsText() { - var _props2 = this.props; - var loadingPlaceholder = _props2.loadingPlaceholder; - var noResultsText = _props2.noResultsText; - var searchPromptText = _props2.searchPromptText; - var isLoading = this.state.isLoading; - - var inputValue = this.inputValue(); + key: 'handleMouseEnter', + value: function handleMouseEnter(event) { + this.onFocus(event); + } + }, { + key: 'handleMouseMove', + value: function handleMouseMove(event) { + this.onFocus(event); + } + }, { + key: 'handleTouchEnd', + value: function handleTouchEnd(event) { + // Check if the view is being dragged, In this case + // we don't want to fire the click event (because the user only wants to scroll) + if (this.dragging) return; - if (isLoading) { - return loadingPlaceholder; - } - if (inputValue && noResultsText) { - return noResultsText; - } - return searchPromptText; + this.handleMouseDown(event); } }, { - key: 'focus', - value: function focus() { - this.select.focus(); + key: 'handleTouchMove', + value: function handleTouchMove(event) { + // Set a flag that the view is being dragged + this.dragging = true; + } + }, { + key: 'handleTouchStart', + value: function handleTouchStart(event) { + // Set a flag that the view is not being dragged + this.dragging = false; + } + }, { + key: 'onFocus', + value: function onFocus(event) { + if (!this.props.isFocused) { + this.props.onFocus(this.props.option, event); + } } }, { key: 'render', value: function render() { - var _this3 = this; - - var _props3 = this.props; - var children = _props3.children; - var loadingPlaceholder = _props3.loadingPlaceholder; - var placeholder = _props3.placeholder; - var _state = this.state; - var isLoading = _state.isLoading; - var options = _state.options; + var _props = this.props, + option = _props.option, + instancePrefix = _props.instancePrefix, + optionIndex = _props.optionIndex; - var props = { - noResultsText: this.noResultsText(), - placeholder: isLoading ? loadingPlaceholder : placeholder, - options: isLoading && loadingPlaceholder ? [] : options, - ref: function ref(_ref) { - return _this3.select = _ref; - }, - onChange: function onChange(newValues) { - if (_this3.props.multi && _this3.props.value && newValues.length > _this3.props.value.length) { - _this3.clearOptions(); - } - _this3.props.onChange(newValues); - } - }; + var className = classNames(this.props.className, option.className); - return children(_extends({}, this.props, props, { - isLoading: isLoading, - onInputChange: this._onInputChange - })); + return option.disabled ? React__default.createElement( + 'div', + { className: className, + onMouseDown: this.blockEvent, + onClick: this.blockEvent }, + this.props.children + ) : React__default.createElement( + 'div', + { className: className, + style: option.style, + role: 'option', + onMouseDown: this.handleMouseDown, + onMouseEnter: this.handleMouseEnter, + onMouseMove: this.handleMouseMove, + onTouchStart: this.handleTouchStart, + onTouchMove: this.handleTouchMove, + onTouchEnd: this.handleTouchEnd, + id: instancePrefix + '-option-' + optionIndex, + title: option.title }, + this.props.children + ); } }]); + return Option; +}(React__default.Component); + + + +Option.propTypes = { + children: PropTypes.node, + className: PropTypes.string, // className (based on mouse position) + instancePrefix: PropTypes.string.isRequired, // unique prefix for the ids (used for aria) + isDisabled: PropTypes.bool, // the option is disabled + isFocused: PropTypes.bool, // the option is focused + isSelected: PropTypes.bool, // the option is selected + onFocus: PropTypes.func, // method to handle mouseEnter on option element + onSelect: PropTypes.func, // method to handle click on option element + onUnfocus: PropTypes.func, // method to handle mouseLeave on option element + option: PropTypes.object.isRequired, // object that is base for that option + optionIndex: PropTypes.number // index of the option, used to generate unique ids for aria +}; - return Async; -})(_react.Component); - -exports['default'] = Async; - -Async.propTypes = propTypes; -Async.defaultProps = defaultProps; - -function defaultChildren(props) { - return _react2['default'].createElement(_Select2['default'], props); -} -module.exports = exports['default']; - -}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) -},{"./Select":5,"./utils/stripDiacritics":11,"prop-types":undefined}],2:[function(require,module,exports){ -(function (global){ -'use strict'; - -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; }; - -function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } +var Value = function (_React$Component) { + inherits(Value, _React$Component); -var _react = (typeof window !== "undefined" ? window['React'] : typeof global !== "undefined" ? global['React'] : null); + function Value(props) { + classCallCheck(this, Value); -var _react2 = _interopRequireDefault(_react); + var _this = possibleConstructorReturn(this, (Value.__proto__ || Object.getPrototypeOf(Value)).call(this, props)); -var _createReactClass = require('create-react-class'); + _this.handleMouseDown = _this.handleMouseDown.bind(_this); + _this.onRemove = _this.onRemove.bind(_this); + _this.handleTouchEndRemove = _this.handleTouchEndRemove.bind(_this); + _this.handleTouchMove = _this.handleTouchMove.bind(_this); + _this.handleTouchStart = _this.handleTouchStart.bind(_this); + return _this; + } -var _createReactClass2 = _interopRequireDefault(_createReactClass); + createClass(Value, [{ + key: 'handleMouseDown', + value: function handleMouseDown(event) { + if (event.type === 'mousedown' && event.button !== 0) { + return; + } + if (this.props.onClick) { + event.stopPropagation(); + this.props.onClick(this.props.value, event); + return; + } + if (this.props.value.href) { + event.stopPropagation(); + } + } + }, { + key: 'onRemove', + value: function onRemove(event) { + event.preventDefault(); + event.stopPropagation(); + this.props.onRemove(this.props.value); + } + }, { + key: 'handleTouchEndRemove', + value: function handleTouchEndRemove(event) { + // Check if the view is being dragged, In this case + // we don't want to fire the click event (because the user only wants to scroll) + if (this.dragging) return; -var _Select = require('./Select'); + // Fire the mouse events + this.onRemove(event); + } + }, { + key: 'handleTouchMove', + value: function handleTouchMove(event) { + // Set a flag that the view is being dragged + this.dragging = true; + } + }, { + key: 'handleTouchStart', + value: function handleTouchStart(event) { + // Set a flag that the view is not being dragged + this.dragging = false; + } + }, { + key: 'renderRemoveIcon', + value: function renderRemoveIcon() { + if (this.props.disabled || !this.props.onRemove) return; + return React__default.createElement( + 'span', + { className: 'Select-value-icon', + 'aria-hidden': 'true', + onMouseDown: this.onRemove, + onTouchEnd: this.handleTouchEndRemove, + onTouchStart: this.handleTouchStart, + onTouchMove: this.handleTouchMove }, + '\xD7' + ); + } + }, { + key: 'renderLabel', + value: function renderLabel() { + var className = 'Select-value-label'; + return this.props.onClick || this.props.value.href ? React__default.createElement( + 'a', + { className: className, href: this.props.value.href, target: this.props.value.target, onMouseDown: this.handleMouseDown, onTouchEnd: this.handleMouseDown }, + this.props.children + ) : React__default.createElement( + 'span', + { className: className, role: 'option', 'aria-selected': 'true', id: this.props.id }, + this.props.children + ); + } + }, { + key: 'render', + value: function render() { + return React__default.createElement( + 'div', + { className: classNames('Select-value', this.props.value.className), + style: this.props.value.style, + title: this.props.value.title + }, + this.renderRemoveIcon(), + this.renderLabel() + ); + } + }]); + return Value; +}(React__default.Component); -var _Select2 = _interopRequireDefault(_Select); -function reduce(obj) { - var props = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1]; - return Object.keys(obj).reduce(function (props, key) { - var value = obj[key]; - if (value !== undefined) props[key] = value; - return props; - }, props); -} +Value.propTypes = { + children: PropTypes.node, + disabled: PropTypes.bool, // disabled prop passed to ReactSelect + id: PropTypes.string, // Unique id for the value - used for aria + onClick: PropTypes.func, // method to handle click on value label + onRemove: PropTypes.func, // method to handle removal of the value + value: PropTypes.object.isRequired // the option object for this value +}; -var AsyncCreatable = (0, _createReactClass2['default'])({ - displayName: 'AsyncCreatableSelect', - - focus: function focus() { - this.select.focus(); - }, - - render: function render() { - var _this = this; - - return _react2['default'].createElement( - _Select2['default'].Async, - this.props, - function (asyncProps) { - return _react2['default'].createElement( - _Select2['default'].Creatable, - _this.props, - function (creatableProps) { - return _react2['default'].createElement(_Select2['default'], _extends({}, reduce(asyncProps, reduce(creatableProps, {})), { - onInputChange: function (input) { - creatableProps.onInputChange(input); - return asyncProps.onInputChange(input); - }, - ref: function (ref) { - _this.select = ref; - creatableProps.ref(ref); - asyncProps.ref(ref); - } - })); - } - ); - } - ); +/*! + Copyright (c) 2016 Jed Watson. + Licensed under the MIT License (MIT), see + http://jedwatson.github.io/react-select +*/ +function stringifyValue(value) { + var valueType = typeof value === 'undefined' ? 'undefined' : _typeof(value); + if (valueType === 'string') { + return value; + } else if (valueType === 'object') { + return JSON.stringify(value); + } else if (valueType === 'number' || valueType === 'boolean') { + return String(value); + } else { + return ''; } -}); - -module.exports = AsyncCreatable; - -}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) -},{"./Select":5,"create-react-class":undefined}],3:[function(require,module,exports){ -(function (global){ -'use strict'; - -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; }; - -function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } - -function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; } - -var _react = (typeof window !== "undefined" ? window['React'] : typeof global !== "undefined" ? global['React'] : null); - -var _react2 = _interopRequireDefault(_react); - -var _createReactClass = require('create-react-class'); - -var _createReactClass2 = _interopRequireDefault(_createReactClass); - -var _propTypes = require('prop-types'); - -var _propTypes2 = _interopRequireDefault(_propTypes); - -var _Select = require('./Select'); - -var _Select2 = _interopRequireDefault(_Select); - -var _utilsDefaultFilterOptions = require('./utils/defaultFilterOptions'); - -var _utilsDefaultFilterOptions2 = _interopRequireDefault(_utilsDefaultFilterOptions); - -var _utilsDefaultMenuRenderer = require('./utils/defaultMenuRenderer'); - -var _utilsDefaultMenuRenderer2 = _interopRequireDefault(_utilsDefaultMenuRenderer); - -var Creatable = (0, _createReactClass2['default'])({ - displayName: 'CreatableSelect', - - propTypes: { - // Child function responsible for creating the inner Select component - // This component can be used to compose HOCs (eg Creatable and Async) - // (props: Object): PropTypes.element - children: _propTypes2['default'].func, - - // See Select.propTypes.filterOptions - filterOptions: _propTypes2['default'].any, - - // Searches for any matching option within the set of options. - // This function prevents duplicate options from being created. - // ({ option: Object, options: Array, labelKey: string, valueKey: string }): boolean - isOptionUnique: _propTypes2['default'].func, - - // Determines if the current input text represents a valid option. - // ({ label: string }): boolean - isValidNewOption: _propTypes2['default'].func, - - // See Select.propTypes.menuRenderer - menuRenderer: _propTypes2['default'].any, - - // Factory to create new option. - // ({ label: string, labelKey: string, valueKey: string }): Object - newOptionCreator: _propTypes2['default'].func, - - // input change handler: function (inputValue) {} - onInputChange: _propTypes2['default'].func, +} - // input keyDown handler: function (event) {} - onInputKeyDown: _propTypes2['default'].func, +var stringOrNode = PropTypes.oneOfType([PropTypes.string, PropTypes.node]); - // new option click handler: function (option) {} - onNewOptionClick: _propTypes2['default'].func, +var instanceId = 1; - // See Select.propTypes.options - options: _propTypes2['default'].array, +var Select$1 = function (_React$Component) { + inherits(Select, _React$Component); + + function Select(props) { + classCallCheck(this, Select); + + var _this = possibleConstructorReturn(this, (Select.__proto__ || Object.getPrototypeOf(Select)).call(this, props)); + + _this.handleTouchOutside = _this.handleTouchOutside.bind(_this); + _this.handleTouchMove = _this.handleTouchMove.bind(_this); + _this.handleTouchStart = _this.handleTouchStart.bind(_this); + _this.handleTouchEnd = _this.handleTouchEnd.bind(_this); + _this.handleTouchEndClearValue = _this.handleTouchEndClearValue.bind(_this); + _this.handleMouseDown = _this.handleMouseDown.bind(_this); + _this.handleMouseDownOnArrow = _this.handleMouseDownOnArrow.bind(_this); + _this.handleMouseDownOnMenu = _this.handleMouseDownOnMenu.bind(_this); + _this.handleInputFocus = _this.handleInputFocus.bind(_this); + _this.handleInputBlur = _this.handleInputBlur.bind(_this); + _this.handleInputChange = _this.handleInputChange.bind(_this); + _this.handleInputValueChange = _this.handleInputValueChange.bind(_this); + _this.handleKeyDown = _this.handleKeyDown.bind(_this); + _this.handleValueClick = _this.handleValueClick.bind(_this); + _this.handleMenuScroll = _this.handleMenuScroll.bind(_this); + _this.handleRequired = _this.handleRequired.bind(_this); + _this.getOptionLabel = _this.getOptionLabel.bind(_this); + _this.onOptionRef = _this.onOptionRef.bind(_this); + _this.clearValue = _this.clearValue.bind(_this); + _this.removeValue = _this.removeValue.bind(_this); + _this.selectValue = _this.selectValue.bind(_this); + _this.focusOption = _this.focusOption.bind(_this); + + _this.state = { + inputValue: '', + isFocused: false, + isOpen: false, + isPseudoFocused: false, + required: false + }; + return _this; + } - // Creates prompt/placeholder option text. - // (filterText: string): string - promptTextCreator: _propTypes2['default'].func, + createClass(Select, [{ + key: 'componentWillMount', + value: function componentWillMount() { + this._instancePrefix = 'react-select-' + (this.props.instanceId || ++instanceId) + '-'; + var valueArray = this.getValueArray(this.props.value); - // Decides if a keyDown event (eg its `keyCode`) should result in the creation of a new option. - shouldKeyDownEventCreateNewOption: _propTypes2['default'].func - }, + if (this.props.required) { + this.setState({ + required: this.handleRequired(valueArray[0], this.props.multi) + }); + } + } + }, { + key: 'componentDidMount', + value: function componentDidMount() { + if (this.props.autofocus) { + this.focus(); + } + } + }, { + key: 'componentWillReceiveProps', + value: function componentWillReceiveProps(nextProps) { + var valueArray = this.getValueArray(nextProps.value, nextProps); - // Default prop methods - statics: { - isOptionUnique: isOptionUnique, - isValidNewOption: isValidNewOption, - newOptionCreator: newOptionCreator, - promptTextCreator: promptTextCreator, - shouldKeyDownEventCreateNewOption: shouldKeyDownEventCreateNewOption - }, + if (nextProps.required) { + this.setState({ + required: this.handleRequired(valueArray[0], nextProps.multi) + }); + } else if (this.props.required) { + // Used to be required but it's not any more + this.setState({ required: false }); + } + } + }, { + key: 'componentWillUpdate', + value: function componentWillUpdate(nextProps, nextState) { + if (nextState.isOpen !== this.state.isOpen) { + this.toggleTouchOutsideEvent(nextState.isOpen); + var handler = nextState.isOpen ? nextProps.onOpen : nextProps.onClose; + handler && handler(); + } + } + }, { + key: 'componentDidUpdate', + value: function componentDidUpdate(prevProps, prevState) { + // focus to the selected option + if (this.menu && this.focused && this.state.isOpen && !this.hasScrolledToOption) { + var focusedOptionNode = ReactDOM.findDOMNode(this.focused); + var menuNode = ReactDOM.findDOMNode(this.menu); + menuNode.scrollTop = focusedOptionNode.offsetTop; + this.hasScrolledToOption = true; + } else if (!this.state.isOpen) { + this.hasScrolledToOption = false; + } - getDefaultProps: function getDefaultProps() { - return { - filterOptions: _utilsDefaultFilterOptions2['default'], - isOptionUnique: isOptionUnique, - isValidNewOption: isValidNewOption, - menuRenderer: _utilsDefaultMenuRenderer2['default'], - newOptionCreator: newOptionCreator, - promptTextCreator: promptTextCreator, - shouldKeyDownEventCreateNewOption: shouldKeyDownEventCreateNewOption - }; - }, - - createNewOption: function createNewOption() { - var _props = this.props; - var isValidNewOption = _props.isValidNewOption; - var newOptionCreator = _props.newOptionCreator; - var onNewOptionClick = _props.onNewOptionClick; - var _props$options = _props.options; - var options = _props$options === undefined ? [] : _props$options; - var shouldKeyDownEventCreateNewOption = _props.shouldKeyDownEventCreateNewOption; - - if (isValidNewOption({ label: this.inputValue })) { - var option = newOptionCreator({ label: this.inputValue, labelKey: this.labelKey, valueKey: this.valueKey }); - var _isOptionUnique = this.isOptionUnique({ option: option }); - - // Don't add the same option twice. - if (_isOptionUnique) { - if (onNewOptionClick) { - onNewOptionClick(option); + if (this._scrollToFocusedOptionOnUpdate && this.focused && this.menu) { + this._scrollToFocusedOptionOnUpdate = false; + var focusedDOM = ReactDOM.findDOMNode(this.focused); + var menuDOM = ReactDOM.findDOMNode(this.menu); + var focusedRect = focusedDOM.getBoundingClientRect(); + var menuRect = menuDOM.getBoundingClientRect(); + if (focusedRect.bottom > menuRect.bottom || focusedRect.top < menuRect.top) { + menuDOM.scrollTop = focusedDOM.offsetTop + focusedDOM.clientHeight - menuDOM.offsetHeight; + } + } + if (this.props.scrollMenuIntoView && this.menuContainer) { + var menuContainerRect = this.menuContainer.getBoundingClientRect(); + if (window.innerHeight < menuContainerRect.bottom + this.props.menuBuffer) { + window.scrollBy(0, menuContainerRect.bottom + this.props.menuBuffer - window.innerHeight); + } + } + if (prevProps.disabled !== this.props.disabled) { + this.setState({ isFocused: false }); // eslint-disable-line react/no-did-update-set-state + this.closeMenu(); + } + } + }, { + key: 'componentWillUnmount', + value: function componentWillUnmount() { + if (!document.removeEventListener && document.detachEvent) { + document.detachEvent('ontouchstart', this.handleTouchOutside); + } else { + document.removeEventListener('touchstart', this.handleTouchOutside); + } + } + }, { + key: 'toggleTouchOutsideEvent', + value: function toggleTouchOutsideEvent(enabled) { + if (enabled) { + if (!document.addEventListener && document.attachEvent) { + document.attachEvent('ontouchstart', this.handleTouchOutside); } else { - options.unshift(option); - - this.select.selectValue(option); + document.addEventListener('touchstart', this.handleTouchOutside); + } + } else { + if (!document.removeEventListener && document.detachEvent) { + document.detachEvent('ontouchstart', this.handleTouchOutside); + } else { + document.removeEventListener('touchstart', this.handleTouchOutside); } } } - }, - - filterOptions: function filterOptions() { - var _props2 = this.props; - var filterOptions = _props2.filterOptions; - var isValidNewOption = _props2.isValidNewOption; - var options = _props2.options; - var promptTextCreator = _props2.promptTextCreator; - - // TRICKY Check currently selected options as well. - // Don't display a create-prompt for a value that's selected. - // This covers async edge-cases where a newly-created Option isn't yet in the async-loaded array. - var excludeOptions = arguments[2] || []; - - var filteredOptions = filterOptions.apply(undefined, arguments) || []; + }, { + key: 'handleTouchOutside', + value: function handleTouchOutside(event) { + // handle touch outside on ios to dismiss menu + if (this.wrapper && !this.wrapper.contains(event.target)) { + this.closeMenu(); + } + } + }, { + key: 'focus', + value: function focus() { + if (!this.input) return; + this.input.focus(); + } + }, { + key: 'blurInput', + value: function blurInput() { + if (!this.input) return; + this.input.blur(); + } + }, { + key: 'handleTouchMove', + value: function handleTouchMove(event) { + // Set a flag that the view is being dragged + this.dragging = true; + } + }, { + key: 'handleTouchStart', + value: function handleTouchStart(event) { + // Set a flag that the view is not being dragged + this.dragging = false; + } + }, { + key: 'handleTouchEnd', + value: function handleTouchEnd(event) { + // Check if the view is being dragged, In this case + // we don't want to fire the click event (because the user only wants to scroll) + if (this.dragging) return; - if (isValidNewOption({ label: this.inputValue })) { - var _newOptionCreator = this.props.newOptionCreator; + // Fire the mouse events + this.handleMouseDown(event); + } + }, { + key: 'handleTouchEndClearValue', + value: function handleTouchEndClearValue(event) { + // Check if the view is being dragged, In this case + // we don't want to fire the click event (because the user only wants to scroll) + if (this.dragging) return; - var option = _newOptionCreator({ - label: this.inputValue, - labelKey: this.labelKey, - valueKey: this.valueKey - }); + // Clear the value + this.clearValue(event); + } + }, { + key: 'handleMouseDown', + value: function handleMouseDown(event) { + // if the event was triggered by a mousedown and not the primary + // button, or if the component is disabled, ignore it. + if (this.props.disabled || event.type === 'mousedown' && event.button !== 0) { + return; + } - // TRICKY Compare to all options (not just filtered options) in case option has already been selected). - // For multi-selects, this would remove it from the filtered list. - var _isOptionUnique2 = this.isOptionUnique({ - option: option, - options: excludeOptions.concat(filteredOptions) - }); + if (event.target.tagName === 'INPUT') { + return; + } - if (_isOptionUnique2) { - var _prompt = promptTextCreator(this.inputValue); + // prevent default event handlers + event.stopPropagation(); + event.preventDefault(); - this._createPlaceholderOption = _newOptionCreator({ - label: _prompt, - labelKey: this.labelKey, - valueKey: this.valueKey + // for the non-searchable select, toggle the menu + if (!this.props.searchable) { + // TODO: This code means that if a select is searchable, onClick the options menu will not appear, only on subsequent click will it open. + this.focus(); + return this.setState({ + isOpen: !this.state.isOpen }); - - filteredOptions.unshift(this._createPlaceholderOption); } - } - - return filteredOptions; - }, - - isOptionUnique: function isOptionUnique(_ref2) { - var option = _ref2.option; - var options = _ref2.options; - var isOptionUnique = this.props.isOptionUnique; - - options = options || this.select.filterOptions(); - - return isOptionUnique({ - labelKey: this.labelKey, - option: option, - options: options, - valueKey: this.valueKey - }); - }, - menuRenderer: function menuRenderer(params) { - var menuRenderer = this.props.menuRenderer; + if (this.state.isFocused) { + // On iOS, we can get into a state where we think the input is focused but it isn't really, + // since iOS ignores programmatic calls to input.focus() that weren't triggered by a click event. + // Call focus() again here to be safe. + this.focus(); - return menuRenderer(_extends({}, params, { - onSelect: this.onOptionSelect, - selectValue: this.onOptionSelect - })); - }, + var input = this.input; + if (typeof input.getInput === 'function') { + // Get the actual DOM input if the ref is an component + input = input.getInput(); + } - onInputChange: function onInputChange(input) { - var onInputChange = this.props.onInputChange; + // clears the value so that the cursor will be at the end of input when the component re-renders + input.value = ''; - if (onInputChange) { - onInputChange(input); + // if the input is focused, ensure the menu is open + this.setState({ + isOpen: true, + isPseudoFocused: false + }); + } else { + // otherwise, focus the input and open the menu + this._openAfterFocus = this.props.openAfterFocus; + this.focus(); + } } - - // This value may be needed in between Select mounts (when this.select is null) - this.inputValue = input; - }, - - onInputKeyDown: function onInputKeyDown(event) { - var _props3 = this.props; - var shouldKeyDownEventCreateNewOption = _props3.shouldKeyDownEventCreateNewOption; - var onInputKeyDown = _props3.onInputKeyDown; - - var focusedOption = this.select.getFocusedOption(); - - if (focusedOption && focusedOption === this._createPlaceholderOption && shouldKeyDownEventCreateNewOption({ keyCode: event.keyCode })) { - this.createNewOption(); - - // Prevent decorated Select from doing anything additional with this keyDown event + }, { + key: 'handleMouseDownOnArrow', + value: function handleMouseDownOnArrow(event) { + // if the event was triggered by a mousedown and not the primary + // button, or if the component is disabled, ignore it. + if (this.props.disabled || event.type === 'mousedown' && event.button !== 0) { + return; + } + // If the menu isn't open, let the event bubble to the main handleMouseDown + if (!this.state.isOpen) { + return; + } + // prevent default event handlers + event.stopPropagation(); event.preventDefault(); - } else if (onInputKeyDown) { - onInputKeyDown(event); + // close the menu + this.closeMenu(); } - }, + }, { + key: 'handleMouseDownOnMenu', + value: function handleMouseDownOnMenu(event) { + // if the event was triggered by a mousedown and not the primary + // button, or if the component is disabled, ignore it. + if (this.props.disabled || event.type === 'mousedown' && event.button !== 0) { + return; + } + event.stopPropagation(); + event.preventDefault(); - onOptionSelect: function onOptionSelect(option, event) { - if (option === this._createPlaceholderOption) { - this.createNewOption(); - } else { - this.select.selectValue(option); + this._openAfterFocus = true; + this.focus(); } - }, - - focus: function focus() { - this.select.focus(); - }, - - render: function render() { - var _this = this; - - var _props4 = this.props; - var newOptionCreator = _props4.newOptionCreator; - var shouldKeyDownEventCreateNewOption = _props4.shouldKeyDownEventCreateNewOption; - - var restProps = _objectWithoutProperties(_props4, ['newOptionCreator', 'shouldKeyDownEventCreateNewOption']); - - var children = this.props.children; + }, { + key: 'closeMenu', + value: function closeMenu() { + if (this.props.onCloseResetsInput) { + this.setState({ + isOpen: false, + isPseudoFocused: this.state.isFocused && !this.props.multi, + inputValue: this.handleInputValueChange('') + }); + } else { + this.setState({ + isOpen: false, + isPseudoFocused: this.state.isFocused && !this.props.multi + }); + } + this.hasScrolledToOption = false; + } + }, { + key: 'handleInputFocus', + value: function handleInputFocus(event) { + if (this.props.disabled) return; + var isOpen = this.state.isOpen || this._openAfterFocus || this.props.openOnFocus; + if (this.props.onFocus) { + this.props.onFocus(event); + } + this.setState({ + isFocused: true, + isOpen: isOpen + }); + this._openAfterFocus = false; + } + }, { + key: 'handleInputBlur', + value: function handleInputBlur(event) { + // The check for menu.contains(activeElement) is necessary to prevent IE11's scrollbar from closing the menu in certain contexts. + if (this.menu && (this.menu === document.activeElement || this.menu.contains(document.activeElement))) { + this.focus(); + return; + } - // We can't use destructuring default values to set the children, - // because it won't apply work if `children` is null. A falsy check is - // more reliable in real world use-cases. - if (!children) { - children = defaultChildren; + if (this.props.onBlur) { + this.props.onBlur(event); + } + var onBlurredState = { + isFocused: false, + isOpen: false, + isPseudoFocused: false + }; + if (this.props.onBlurResetsInput) { + onBlurredState.inputValue = this.handleInputValueChange(''); + } + this.setState(onBlurredState); } + }, { + key: 'handleInputChange', + value: function handleInputChange(event) { + var newInputValue = event.target.value; - var props = _extends({}, restProps, { - allowCreate: true, - filterOptions: this.filterOptions, - menuRenderer: this.menuRenderer, - onInputChange: this.onInputChange, - onInputKeyDown: this.onInputKeyDown, - ref: function ref(_ref) { - _this.select = _ref; + if (this.state.inputValue !== event.target.value) { + newInputValue = this.handleInputValueChange(newInputValue); + } - // These values may be needed in between Select mounts (when this.select is null) - if (_ref) { - _this.labelKey = _ref.props.labelKey; - _this.valueKey = _ref.props.valueKey; + this.setState({ + isOpen: true, + isPseudoFocused: false, + inputValue: newInputValue + }); + } + }, { + key: 'handleInputValueChange', + value: function handleInputValueChange(newValue) { + if (this.props.onInputChange) { + var nextState = this.props.onInputChange(newValue); + // Note: != used deliberately here to catch undefined and null + if (nextState != null && (typeof nextState === 'undefined' ? 'undefined' : _typeof(nextState)) !== 'object') { + newValue = '' + nextState; } } - }); - - return children(props); - } -}); - -function defaultChildren(props) { - return _react2['default'].createElement(_Select2['default'], props); -}; - -function isOptionUnique(_ref3) { - var option = _ref3.option; - var options = _ref3.options; - var labelKey = _ref3.labelKey; - var valueKey = _ref3.valueKey; - - return options.filter(function (existingOption) { - return existingOption[labelKey] === option[labelKey] || existingOption[valueKey] === option[valueKey]; - }).length === 0; -}; - -function isValidNewOption(_ref4) { - var label = _ref4.label; - - return !!label; -}; - -function newOptionCreator(_ref5) { - var label = _ref5.label; - var labelKey = _ref5.labelKey; - var valueKey = _ref5.valueKey; - - var option = {}; - option[valueKey] = label; - option[labelKey] = label; - option.className = 'Select-create-option-placeholder'; - return option; -}; - -function promptTextCreator(label) { - return 'Create option "' + label + '"'; -} - -function shouldKeyDownEventCreateNewOption(_ref6) { - var keyCode = _ref6.keyCode; - - switch (keyCode) { - case 9: // TAB - case 13: // ENTER - case 188: - // COMMA - return true; - } - - return false; -}; - -module.exports = Creatable; - -}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) -},{"./Select":5,"./utils/defaultFilterOptions":9,"./utils/defaultMenuRenderer":10,"create-react-class":undefined,"prop-types":undefined}],4:[function(require,module,exports){ -(function (global){ -'use strict'; - -function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } - -var _react = (typeof window !== "undefined" ? window['React'] : typeof global !== "undefined" ? global['React'] : null); - -var _react2 = _interopRequireDefault(_react); - -var _createReactClass = require('create-react-class'); - -var _createReactClass2 = _interopRequireDefault(_createReactClass); - -var _propTypes = require('prop-types'); - -var _propTypes2 = _interopRequireDefault(_propTypes); - -var _classnames = (typeof window !== "undefined" ? window['classNames'] : typeof global !== "undefined" ? global['classNames'] : null); - -var _classnames2 = _interopRequireDefault(_classnames); - -var Option = (0, _createReactClass2['default'])({ - propTypes: { - children: _propTypes2['default'].node, - className: _propTypes2['default'].string, // className (based on mouse position) - instancePrefix: _propTypes2['default'].string.isRequired, // unique prefix for the ids (used for aria) - isDisabled: _propTypes2['default'].bool, // the option is disabled - isFocused: _propTypes2['default'].bool, // the option is focused - isSelected: _propTypes2['default'].bool, // the option is selected - onFocus: _propTypes2['default'].func, // method to handle mouseEnter on option element - onSelect: _propTypes2['default'].func, // method to handle click on option element - onUnfocus: _propTypes2['default'].func, // method to handle mouseLeave on option element - option: _propTypes2['default'].object.isRequired, // object that is base for that option - optionIndex: _propTypes2['default'].number }, - // index of the option, used to generate unique ids for aria - blockEvent: function blockEvent(event) { - event.preventDefault(); - event.stopPropagation(); - if (event.target.tagName !== 'A' || !('href' in event.target)) { - return; - } - if (event.target.target) { - window.open(event.target.href, event.target.target); - } else { - window.location.href = event.target.href; - } - }, - - handleMouseDown: function handleMouseDown(event) { - event.preventDefault(); - event.stopPropagation(); - this.props.onSelect(this.props.option, event); - }, - - handleMouseEnter: function handleMouseEnter(event) { - this.onFocus(event); - }, - - handleMouseMove: function handleMouseMove(event) { - this.onFocus(event); - }, - - handleTouchEnd: function handleTouchEnd(event) { - // Check if the view is being dragged, In this case - // we don't want to fire the click event (because the user only wants to scroll) - if (this.dragging) return; - - this.handleMouseDown(event); - }, - - handleTouchMove: function handleTouchMove(event) { - // Set a flag that the view is being dragged - this.dragging = true; - }, - - handleTouchStart: function handleTouchStart(event) { - // Set a flag that the view is not being dragged - this.dragging = false; - }, - - onFocus: function onFocus(event) { - if (!this.props.isFocused) { - this.props.onFocus(this.props.option, event); - } - }, - render: function render() { - var _props = this.props; - var option = _props.option; - var instancePrefix = _props.instancePrefix; - var optionIndex = _props.optionIndex; - - var className = (0, _classnames2['default'])(this.props.className, option.className); - - return option.disabled ? _react2['default'].createElement( - 'div', - { className: className, - onMouseDown: this.blockEvent, - onClick: this.blockEvent }, - this.props.children - ) : _react2['default'].createElement( - 'div', - { className: className, - style: option.style, - role: 'option', - onMouseDown: this.handleMouseDown, - onMouseEnter: this.handleMouseEnter, - onMouseMove: this.handleMouseMove, - onTouchStart: this.handleTouchStart, - onTouchMove: this.handleTouchMove, - onTouchEnd: this.handleTouchEnd, - id: instancePrefix + '-option-' + optionIndex, - title: option.title }, - this.props.children - ); - } -}); - -module.exports = Option; - -}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) -},{"create-react-class":undefined,"prop-types":undefined}],5:[function(require,module,exports){ -(function (global){ -/*! - Copyright (c) 2016 Jed Watson. - Licensed under the MIT License (MIT), see - http://jedwatson.github.io/react-select -*/ - -'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; }; - -function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } - -function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; } - -function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } - -var _react = (typeof window !== "undefined" ? window['React'] : typeof global !== "undefined" ? global['React'] : null); - -var _react2 = _interopRequireDefault(_react); - -var _createReactClass = require('create-react-class'); - -var _createReactClass2 = _interopRequireDefault(_createReactClass); - -var _propTypes = require('prop-types'); - -var _propTypes2 = _interopRequireDefault(_propTypes); - -var _reactDom = (typeof window !== "undefined" ? window['ReactDOM'] : typeof global !== "undefined" ? global['ReactDOM'] : null); - -var _reactDom2 = _interopRequireDefault(_reactDom); - -var _reactInputAutosize = (typeof window !== "undefined" ? window['AutosizeInput'] : typeof global !== "undefined" ? global['AutosizeInput'] : null); - -var _reactInputAutosize2 = _interopRequireDefault(_reactInputAutosize); - -var _classnames = (typeof window !== "undefined" ? window['classNames'] : typeof global !== "undefined" ? global['classNames'] : null); - -var _classnames2 = _interopRequireDefault(_classnames); - -var _utilsDefaultArrowRenderer = require('./utils/defaultArrowRenderer'); - -var _utilsDefaultArrowRenderer2 = _interopRequireDefault(_utilsDefaultArrowRenderer); - -var _utilsDefaultFilterOptions = require('./utils/defaultFilterOptions'); - -var _utilsDefaultFilterOptions2 = _interopRequireDefault(_utilsDefaultFilterOptions); - -var _utilsDefaultMenuRenderer = require('./utils/defaultMenuRenderer'); - -var _utilsDefaultMenuRenderer2 = _interopRequireDefault(_utilsDefaultMenuRenderer); - -var _utilsDefaultClearRenderer = require('./utils/defaultClearRenderer'); - -var _utilsDefaultClearRenderer2 = _interopRequireDefault(_utilsDefaultClearRenderer); - -var _Async = require('./Async'); - -var _Async2 = _interopRequireDefault(_Async); - -var _AsyncCreatable = require('./AsyncCreatable'); - -var _AsyncCreatable2 = _interopRequireDefault(_AsyncCreatable); - -var _Creatable = require('./Creatable'); - -var _Creatable2 = _interopRequireDefault(_Creatable); - -var _Option = require('./Option'); + return newValue; + } + }, { + key: 'handleKeyDown', + value: function handleKeyDown(event) { + if (this.props.disabled) return; -var _Option2 = _interopRequireDefault(_Option); + if (typeof this.props.onInputKeyDown === 'function') { + this.props.onInputKeyDown(event); + if (event.defaultPrevented) { + return; + } + } -var _Value = require('./Value'); + switch (event.keyCode) { + case 8: + // backspace + if (!this.state.inputValue && this.props.backspaceRemoves) { + event.preventDefault(); + this.popValue(); + } + return; + case 9: + // tab + if (event.shiftKey || !this.state.isOpen || !this.props.tabSelectsValue) { + return; + } + this.selectFocusedOption(); + return; + case 13: + // enter + if (!this.state.isOpen) return; + event.stopPropagation(); + this.selectFocusedOption(); + break; + case 27: + // escape + if (this.state.isOpen) { + this.closeMenu(); + event.stopPropagation(); + } else if (this.props.clearable && this.props.escapeClearsValue) { + this.clearValue(event); + event.stopPropagation(); + } + break; + case 38: + // up + this.focusPreviousOption(); + break; + case 40: + // down + this.focusNextOption(); + break; + case 33: + // page up + this.focusPageUpOption(); + break; + case 34: + // page down + this.focusPageDownOption(); + break; + case 35: + // end key + if (event.shiftKey) { + return; + } + this.focusEndOption(); + break; + case 36: + // home key + if (event.shiftKey) { + return; + } + this.focusStartOption(); + break; + case 46: + // backspace + if (!this.state.inputValue && this.props.deleteRemoves) { + event.preventDefault(); + this.popValue(); + } + return; + default: + return; + } + event.preventDefault(); + } + }, { + key: 'handleValueClick', + value: function handleValueClick(option, event) { + if (!this.props.onValueClick) return; + this.props.onValueClick(option, event); + } + }, { + key: 'handleMenuScroll', + value: function handleMenuScroll(event) { + if (!this.props.onMenuScrollToBottom) return; + var target = event.target; -var _Value2 = _interopRequireDefault(_Value); + if (target.scrollHeight > target.offsetHeight && !(target.scrollHeight - target.offsetHeight - target.scrollTop)) { + this.props.onMenuScrollToBottom(); + } + } + }, { + key: 'handleRequired', + value: function handleRequired(value, multi) { + if (!value) return true; + return multi ? value.length === 0 : Object.keys(value).length === 0; + } + }, { + key: 'getOptionLabel', + value: function getOptionLabel(op) { + return op[this.props.labelKey]; + } -function stringifyValue(value) { - var valueType = typeof value; - if (valueType === 'string') { - return value; - } else if (valueType === 'object') { - return JSON.stringify(value); - } else if (valueType === 'number' || valueType === 'boolean') { - return String(value); - } else { - return ''; - } -} + /** + * Turns a value into an array from the given options + * @param {String|Number|Array} value - the value of the select input + * @param {Object} nextProps - optionally specify the nextProps so the returned array uses the latest configuration + * @returns {Array} the value of the select represented in an array + */ -var stringOrNode = _propTypes2['default'].oneOfType([_propTypes2['default'].string, _propTypes2['default'].node]); + }, { + key: 'getValueArray', + value: function getValueArray(value, nextProps) { + var _this2 = this; -var instanceId = 1; + /** support optionally passing in the `nextProps` so `componentWillReceiveProps` updates will function as expected */ + var props = (typeof nextProps === 'undefined' ? 'undefined' : _typeof(nextProps)) === 'object' ? nextProps : this.props; + if (props.multi) { + if (typeof value === 'string') value = value.split(props.delimiter); + if (!Array.isArray(value)) { + if (value === null || value === undefined) return []; + value = [value]; + } + return value.map(function (value) { + return _this2.expandValue(value, props); + }).filter(function (i) { + return i; + }); + } + var expandedValue = this.expandValue(value, props); + return expandedValue ? [expandedValue] : []; + } -var Select = (0, _createReactClass2['default'])({ - - displayName: 'Select', - - propTypes: { - addLabelText: _propTypes2['default'].string, // placeholder displayed when you want to add a label on a multi-value input - 'aria-describedby': _propTypes2['default'].string, // HTML ID(s) of element(s) that should be used to describe this input (for assistive tech) - 'aria-label': _propTypes2['default'].string, // Aria label (for assistive tech) - 'aria-labelledby': _propTypes2['default'].string, // HTML ID of an element that should be used as the label (for assistive tech) - arrowRenderer: _propTypes2['default'].func, // Create drop-down caret element - autoBlur: _propTypes2['default'].bool, // automatically blur the component when an option is selected - autofocus: _propTypes2['default'].bool, // autofocus the component on mount - autosize: _propTypes2['default'].bool, // whether to enable autosizing or not - backspaceRemoves: _propTypes2['default'].bool, // whether backspace removes an item if there is no text input - backspaceToRemoveMessage: _propTypes2['default'].string, // Message to use for screenreaders to press backspace to remove the current item - {label} is replaced with the item label - className: _propTypes2['default'].string, // className for the outer element - clearAllText: stringOrNode, // title for the "clear" control when multi: true - clearRenderer: _propTypes2['default'].func, // create clearable x element - clearValueText: stringOrNode, // title for the "clear" control - clearable: _propTypes2['default'].bool, // should it be possible to reset value - deleteRemoves: _propTypes2['default'].bool, // whether backspace removes an item if there is no text input - delimiter: _propTypes2['default'].string, // delimiter to use to join multiple values for the hidden field value - disabled: _propTypes2['default'].bool, // whether the Select is disabled or not - escapeClearsValue: _propTypes2['default'].bool, // whether escape clears the value when the menu is closed - filterOption: _propTypes2['default'].func, // method to filter a single option (option, filterString) - filterOptions: _propTypes2['default'].any, // boolean to enable default filtering or function to filter the options array ([options], filterString, [values]) - ignoreAccents: _propTypes2['default'].bool, // whether to strip diacritics when filtering - ignoreCase: _propTypes2['default'].bool, // whether to perform case-insensitive filtering - inputProps: _propTypes2['default'].object, // custom attributes for the Input - inputRenderer: _propTypes2['default'].func, // returns a custom input component - instanceId: _propTypes2['default'].string, // set the components instanceId - isLoading: _propTypes2['default'].bool, // whether the Select is loading externally or not (such as options being loaded) - joinValues: _propTypes2['default'].bool, // joins multiple values into a single form field with the delimiter (legacy mode) - labelKey: _propTypes2['default'].string, // path of the label value in option objects - matchPos: _propTypes2['default'].string, // (any|start) match the start or entire string when filtering - matchProp: _propTypes2['default'].string, // (any|label|value) which option property to filter on - menuBuffer: _propTypes2['default'].number, // optional buffer (in px) between the bottom of the viewport and the bottom of the menu - menuContainerStyle: _propTypes2['default'].object, // optional style to apply to the menu container - menuRenderer: _propTypes2['default'].func, // renders a custom menu with options - menuStyle: _propTypes2['default'].object, // optional style to apply to the menu - multi: _propTypes2['default'].bool, // multi-value input - name: _propTypes2['default'].string, // generates a hidden tag with this field name for html forms - noResultsText: stringOrNode, // placeholder displayed when there are no matching search results - onBlur: _propTypes2['default'].func, // onBlur handler: function (event) {} - onBlurResetsInput: _propTypes2['default'].bool, // whether input is cleared on blur - onChange: _propTypes2['default'].func, // onChange handler: function (newValue) {} - onClose: _propTypes2['default'].func, // fires when the menu is closed - onCloseResetsInput: _propTypes2['default'].bool, // whether input is cleared when menu is closed through the arrow - onFocus: _propTypes2['default'].func, // onFocus handler: function (event) {} - onInputChange: _propTypes2['default'].func, // onInputChange handler: function (inputValue) {} - onInputKeyDown: _propTypes2['default'].func, // input keyDown handler: function (event) {} - onMenuScrollToBottom: _propTypes2['default'].func, // fires when the menu is scrolled to the bottom; can be used to paginate options - onOpen: _propTypes2['default'].func, // fires when the menu is opened - onValueClick: _propTypes2['default'].func, // onClick handler for value labels: function (value, event) {} - openAfterFocus: _propTypes2['default'].bool, // boolean to enable opening dropdown when focused - openOnFocus: _propTypes2['default'].bool, // always open options menu on focus - optionClassName: _propTypes2['default'].string, // additional class(es) to apply to the