Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

react-select.browser.cjs.js 7.0 KiB

3 лет назад
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. 'use strict';
  2. Object.defineProperty(exports, '__esModule', { value: true });
  3. function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
  4. var React = require('react');
  5. var React__default = _interopDefault(React);
  6. require('memoize-one');
  7. require('@emotion/core');
  8. require('react-dom');
  9. require('prop-types');
  10. var utils = require('../../dist/utils-896a48cb.browser.cjs.js');
  11. require('../../dist/index-30113876.browser.cjs.js');
  12. var reactSelect = require('../../dist/Select-b0ada71d.browser.cjs.js');
  13. require('@emotion/css');
  14. require('react-input-autosize');
  15. var stateManager = require('../../dist/stateManager-61815400.browser.cjs.js');
  16. function _extends() { _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; }; return _extends.apply(this, arguments); }
  17. function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
  18. function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; subClass.__proto__ = superClass; }
  19. var defaultProps = {
  20. cacheOptions: false,
  21. defaultOptions: false,
  22. filterOption: null,
  23. isLoading: false
  24. };
  25. var makeAsyncSelect = function makeAsyncSelect(SelectComponent) {
  26. var _class, _temp;
  27. return _temp = _class =
  28. /*#__PURE__*/
  29. function (_Component) {
  30. _inheritsLoose(Async, _Component);
  31. function Async(props) {
  32. var _this;
  33. _this = _Component.call(this) || this;
  34. _this.select = void 0;
  35. _this.lastRequest = void 0;
  36. _this.mounted = false;
  37. _this.optionsCache = {};
  38. _this.handleInputChange = function (newValue, actionMeta) {
  39. var _this$props = _this.props,
  40. cacheOptions = _this$props.cacheOptions,
  41. onInputChange = _this$props.onInputChange; // TODO
  42. var inputValue = utils.handleInputChange(newValue, actionMeta, onInputChange);
  43. if (!inputValue) {
  44. delete _this.lastRequest;
  45. _this.setState({
  46. inputValue: '',
  47. loadedInputValue: '',
  48. loadedOptions: [],
  49. isLoading: false,
  50. passEmptyOptions: false
  51. });
  52. return;
  53. }
  54. if (cacheOptions && _this.optionsCache[inputValue]) {
  55. _this.setState({
  56. inputValue: inputValue,
  57. loadedInputValue: inputValue,
  58. loadedOptions: _this.optionsCache[inputValue],
  59. isLoading: false,
  60. passEmptyOptions: false
  61. });
  62. } else {
  63. var request = _this.lastRequest = {};
  64. _this.setState({
  65. inputValue: inputValue,
  66. isLoading: true,
  67. passEmptyOptions: !_this.state.loadedInputValue
  68. }, function () {
  69. _this.loadOptions(inputValue, function (options) {
  70. if (!_this.mounted) return;
  71. if (options) {
  72. _this.optionsCache[inputValue] = options;
  73. }
  74. if (request !== _this.lastRequest) return;
  75. delete _this.lastRequest;
  76. _this.setState({
  77. isLoading: false,
  78. loadedInputValue: inputValue,
  79. loadedOptions: options || [],
  80. passEmptyOptions: false
  81. });
  82. });
  83. });
  84. }
  85. return inputValue;
  86. };
  87. _this.state = {
  88. defaultOptions: Array.isArray(props.defaultOptions) ? props.defaultOptions : undefined,
  89. inputValue: typeof props.inputValue !== 'undefined' ? props.inputValue : '',
  90. isLoading: props.defaultOptions === true,
  91. loadedOptions: [],
  92. passEmptyOptions: false
  93. };
  94. return _this;
  95. }
  96. var _proto = Async.prototype;
  97. _proto.componentDidMount = function componentDidMount() {
  98. var _this2 = this;
  99. this.mounted = true;
  100. var defaultOptions = this.props.defaultOptions;
  101. var inputValue = this.state.inputValue;
  102. if (defaultOptions === true) {
  103. this.loadOptions(inputValue, function (options) {
  104. if (!_this2.mounted) return;
  105. var isLoading = !!_this2.lastRequest;
  106. _this2.setState({
  107. defaultOptions: options || [],
  108. isLoading: isLoading
  109. });
  110. });
  111. }
  112. };
  113. _proto.UNSAFE_componentWillReceiveProps = function UNSAFE_componentWillReceiveProps(nextProps) {
  114. // if the cacheOptions prop changes, clear the cache
  115. if (nextProps.cacheOptions !== this.props.cacheOptions) {
  116. this.optionsCache = {};
  117. }
  118. if (nextProps.defaultOptions !== this.props.defaultOptions) {
  119. this.setState({
  120. defaultOptions: Array.isArray(nextProps.defaultOptions) ? nextProps.defaultOptions : undefined
  121. });
  122. }
  123. };
  124. _proto.componentWillUnmount = function componentWillUnmount() {
  125. this.mounted = false;
  126. };
  127. _proto.focus = function focus() {
  128. this.select.focus();
  129. };
  130. _proto.blur = function blur() {
  131. this.select.blur();
  132. };
  133. _proto.loadOptions = function loadOptions(inputValue, callback) {
  134. var loadOptions = this.props.loadOptions;
  135. if (!loadOptions) return callback();
  136. var loader = loadOptions(inputValue, callback);
  137. if (loader && typeof loader.then === 'function') {
  138. loader.then(callback, function () {
  139. return callback();
  140. });
  141. }
  142. };
  143. _proto.render = function render() {
  144. var _this3 = this;
  145. var _this$props2 = this.props,
  146. loadOptions = _this$props2.loadOptions,
  147. isLoadingProp = _this$props2.isLoading,
  148. props = _objectWithoutPropertiesLoose(_this$props2, ["loadOptions", "isLoading"]);
  149. var _this$state = this.state,
  150. defaultOptions = _this$state.defaultOptions,
  151. inputValue = _this$state.inputValue,
  152. isLoading = _this$state.isLoading,
  153. loadedInputValue = _this$state.loadedInputValue,
  154. loadedOptions = _this$state.loadedOptions,
  155. passEmptyOptions = _this$state.passEmptyOptions;
  156. var options = passEmptyOptions ? [] : inputValue && loadedInputValue ? loadedOptions : defaultOptions || [];
  157. return React__default.createElement(SelectComponent, _extends({}, props, {
  158. ref: function ref(_ref) {
  159. _this3.select = _ref;
  160. },
  161. options: options,
  162. isLoading: isLoading || isLoadingProp,
  163. onInputChange: this.handleInputChange
  164. }));
  165. };
  166. return Async;
  167. }(React.Component), _class.defaultProps = defaultProps, _temp;
  168. };
  169. var SelectState = stateManager.manageState(reactSelect.Select);
  170. var Async = makeAsyncSelect(SelectState);
  171. exports.default = Async;
  172. exports.defaultProps = defaultProps;
  173. exports.makeAsyncSelect = makeAsyncSelect;