Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

react-select.cjs.prod.js 6.2 KiB

il y a 3 ans
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. "use strict";
  2. function _interopDefault(ex) {
  3. return ex && "object" == typeof ex && "default" in ex ? ex.default : ex;
  4. }
  5. Object.defineProperty(exports, "__esModule", {
  6. value: !0
  7. });
  8. var React = require("react"), React__default = _interopDefault(React);
  9. require("memoize-one"), require("@emotion/core"), require("react-dom"), require("prop-types");
  10. var utils = require("../../dist/utils-2db2ca57.cjs.prod.js");
  11. require("../../dist/index-4f270825.cjs.prod.js");
  12. var reactSelect = require("../../dist/Select-95fb2b5c.cjs.prod.js");
  13. require("@emotion/css"), require("react-input-autosize");
  14. var stateManager = require("../../dist/stateManager-1f3302b2.cjs.prod.js");
  15. function _extends() {
  16. return (_extends = Object.assign || function(target) {
  17. for (var i = 1; i < arguments.length; i++) {
  18. var source = arguments[i];
  19. for (var key in source) Object.prototype.hasOwnProperty.call(source, key) && (target[key] = source[key]);
  20. }
  21. return target;
  22. }).apply(this, arguments);
  23. }
  24. function _objectWithoutPropertiesLoose(source, excluded) {
  25. if (null == source) return {};
  26. var key, i, target = {}, sourceKeys = Object.keys(source);
  27. for (i = 0; i < sourceKeys.length; i++) key = sourceKeys[i], excluded.indexOf(key) >= 0 || (target[key] = source[key]);
  28. return target;
  29. }
  30. function _inheritsLoose(subClass, superClass) {
  31. subClass.prototype = Object.create(superClass.prototype), subClass.prototype.constructor = subClass,
  32. subClass.__proto__ = superClass;
  33. }
  34. var defaultProps = {
  35. cacheOptions: !1,
  36. defaultOptions: !1,
  37. filterOption: null,
  38. isLoading: !1
  39. }, makeAsyncSelect = function(SelectComponent) {
  40. var _class, _temp;
  41. return _temp = _class = function(_Component) {
  42. function Async(props) {
  43. var _this;
  44. return (_this = _Component.call(this) || this).select = void 0, _this.lastRequest = void 0,
  45. _this.mounted = !1, _this.optionsCache = {}, _this.handleInputChange = function(newValue, actionMeta) {
  46. var _this$props = _this.props, cacheOptions = _this$props.cacheOptions, onInputChange = _this$props.onInputChange, inputValue = utils.handleInputChange(newValue, actionMeta, onInputChange);
  47. if (!inputValue) return delete _this.lastRequest, void _this.setState({
  48. inputValue: "",
  49. loadedInputValue: "",
  50. loadedOptions: [],
  51. isLoading: !1,
  52. passEmptyOptions: !1
  53. });
  54. if (cacheOptions && _this.optionsCache[inputValue]) _this.setState({
  55. inputValue: inputValue,
  56. loadedInputValue: inputValue,
  57. loadedOptions: _this.optionsCache[inputValue],
  58. isLoading: !1,
  59. passEmptyOptions: !1
  60. }); else {
  61. var request = _this.lastRequest = {};
  62. _this.setState({
  63. inputValue: inputValue,
  64. isLoading: !0,
  65. passEmptyOptions: !_this.state.loadedInputValue
  66. }, (function() {
  67. _this.loadOptions(inputValue, (function(options) {
  68. _this.mounted && (options && (_this.optionsCache[inputValue] = options), request === _this.lastRequest && (delete _this.lastRequest,
  69. _this.setState({
  70. isLoading: !1,
  71. loadedInputValue: inputValue,
  72. loadedOptions: options || [],
  73. passEmptyOptions: !1
  74. })));
  75. }));
  76. }));
  77. }
  78. return inputValue;
  79. }, _this.state = {
  80. defaultOptions: Array.isArray(props.defaultOptions) ? props.defaultOptions : void 0,
  81. inputValue: void 0 !== props.inputValue ? props.inputValue : "",
  82. isLoading: !0 === props.defaultOptions,
  83. loadedOptions: [],
  84. passEmptyOptions: !1
  85. }, _this;
  86. }
  87. _inheritsLoose(Async, _Component);
  88. var _proto = Async.prototype;
  89. return _proto.componentDidMount = function() {
  90. var _this2 = this;
  91. this.mounted = !0;
  92. var defaultOptions = this.props.defaultOptions, inputValue = this.state.inputValue;
  93. !0 === defaultOptions && this.loadOptions(inputValue, (function(options) {
  94. if (_this2.mounted) {
  95. var isLoading = !!_this2.lastRequest;
  96. _this2.setState({
  97. defaultOptions: options || [],
  98. isLoading: isLoading
  99. });
  100. }
  101. }));
  102. }, _proto.UNSAFE_componentWillReceiveProps = function(nextProps) {
  103. nextProps.cacheOptions !== this.props.cacheOptions && (this.optionsCache = {}),
  104. nextProps.defaultOptions !== this.props.defaultOptions && this.setState({
  105. defaultOptions: Array.isArray(nextProps.defaultOptions) ? nextProps.defaultOptions : void 0
  106. });
  107. }, _proto.componentWillUnmount = function() {
  108. this.mounted = !1;
  109. }, _proto.focus = function() {
  110. this.select.focus();
  111. }, _proto.blur = function() {
  112. this.select.blur();
  113. }, _proto.loadOptions = function(inputValue, callback) {
  114. var loadOptions = this.props.loadOptions;
  115. if (!loadOptions) return callback();
  116. var loader = loadOptions(inputValue, callback);
  117. loader && "function" == typeof loader.then && loader.then(callback, (function() {
  118. return callback();
  119. }));
  120. }, _proto.render = function() {
  121. var _this3 = this, _this$props2 = this.props, isLoadingProp = (_this$props2.loadOptions,
  122. _this$props2.isLoading), props = _objectWithoutPropertiesLoose(_this$props2, [ "loadOptions", "isLoading" ]), _this$state = this.state, defaultOptions = _this$state.defaultOptions, inputValue = _this$state.inputValue, isLoading = _this$state.isLoading, loadedInputValue = _this$state.loadedInputValue, loadedOptions = _this$state.loadedOptions, options = _this$state.passEmptyOptions ? [] : inputValue && loadedInputValue ? loadedOptions : defaultOptions || [];
  123. return React__default.createElement(SelectComponent, _extends({}, props, {
  124. ref: function(_ref) {
  125. _this3.select = _ref;
  126. },
  127. options: options,
  128. isLoading: isLoading || isLoadingProp,
  129. onInputChange: this.handleInputChange
  130. }));
  131. }, Async;
  132. }(React.Component), _class.defaultProps = defaultProps, _temp;
  133. }, SelectState = stateManager.manageState(reactSelect.Select), Async = makeAsyncSelect(SelectState);
  134. exports.default = Async, exports.defaultProps = defaultProps, exports.makeAsyncSelect = makeAsyncSelect;