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

react-select.cjs.prod.js 5.2 KiB

3 лет назад
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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 _inheritsLoose(subClass, superClass) {
  16. subClass.prototype = Object.create(superClass.prototype), subClass.prototype.constructor = subClass,
  17. subClass.__proto__ = superClass;
  18. }
  19. function _extends() {
  20. return (_extends = Object.assign || function(target) {
  21. for (var i = 1; i < arguments.length; i++) {
  22. var source = arguments[i];
  23. for (var key in source) Object.prototype.hasOwnProperty.call(source, key) && (target[key] = source[key]);
  24. }
  25. return target;
  26. }).apply(this, arguments);
  27. }
  28. var compareOption = function(inputValue, option) {
  29. void 0 === inputValue && (inputValue = "");
  30. var candidate = String(inputValue).toLowerCase(), optionValue = String(option.value).toLowerCase(), optionLabel = String(option.label).toLowerCase();
  31. return optionValue === candidate || optionLabel === candidate;
  32. }, builtins = {
  33. formatCreateLabel: function(inputValue) {
  34. return 'Create "' + inputValue + '"';
  35. },
  36. isValidNewOption: function(inputValue, selectValue, selectOptions) {
  37. return !(!inputValue || selectValue.some((function(option) {
  38. return compareOption(inputValue, option);
  39. })) || selectOptions.some((function(option) {
  40. return compareOption(inputValue, option);
  41. })));
  42. },
  43. getNewOptionData: function(inputValue, optionLabel) {
  44. return {
  45. label: optionLabel,
  46. value: inputValue,
  47. __isNew__: !0
  48. };
  49. }
  50. }, defaultProps = _extends({
  51. allowCreateWhileLoading: !1,
  52. createOptionPosition: "last"
  53. }, builtins), makeCreatableSelect = function(SelectComponent) {
  54. var _class, _temp;
  55. return _temp = _class = function(_Component) {
  56. function Creatable(props) {
  57. var _this;
  58. (_this = _Component.call(this, props) || this).select = void 0, _this.onChange = function(newValue, actionMeta) {
  59. var _this$props = _this.props, getNewOptionData = _this$props.getNewOptionData, inputValue = _this$props.inputValue, isMulti = _this$props.isMulti, onChange = _this$props.onChange, onCreateOption = _this$props.onCreateOption, value = _this$props.value, name = _this$props.name;
  60. if ("select-option" !== actionMeta.action) return onChange(newValue, actionMeta);
  61. var newOption = _this.state.newOption, valueArray = Array.isArray(newValue) ? newValue : [ newValue ];
  62. if (valueArray[valueArray.length - 1] !== newOption) onChange(newValue, actionMeta); else if (onCreateOption) onCreateOption(inputValue); else {
  63. var newOptionData = getNewOptionData(inputValue, inputValue), newActionMeta = {
  64. action: "create-option",
  65. name: name
  66. };
  67. onChange(isMulti ? [].concat(utils.cleanValue(value), [ newOptionData ]) : newOptionData, newActionMeta);
  68. }
  69. };
  70. var options = props.options || [];
  71. return _this.state = {
  72. newOption: void 0,
  73. options: options
  74. }, _this;
  75. }
  76. _inheritsLoose(Creatable, _Component);
  77. var _proto = Creatable.prototype;
  78. return _proto.UNSAFE_componentWillReceiveProps = function(nextProps) {
  79. var allowCreateWhileLoading = nextProps.allowCreateWhileLoading, createOptionPosition = nextProps.createOptionPosition, formatCreateLabel = nextProps.formatCreateLabel, getNewOptionData = nextProps.getNewOptionData, inputValue = nextProps.inputValue, isLoading = nextProps.isLoading, isValidNewOption = nextProps.isValidNewOption, value = nextProps.value, options = nextProps.options || [], newOption = this.state.newOption;
  80. newOption = isValidNewOption(inputValue, utils.cleanValue(value), options) ? getNewOptionData(inputValue, formatCreateLabel(inputValue)) : void 0,
  81. this.setState({
  82. newOption: newOption,
  83. options: !allowCreateWhileLoading && isLoading || !newOption ? options : "first" === createOptionPosition ? [ newOption ].concat(options) : [].concat(options, [ newOption ])
  84. });
  85. }, _proto.focus = function() {
  86. this.select.focus();
  87. }, _proto.blur = function() {
  88. this.select.blur();
  89. }, _proto.render = function() {
  90. var _this2 = this, options = this.state.options;
  91. return React__default.createElement(SelectComponent, _extends({}, this.props, {
  92. ref: function(_ref) {
  93. _this2.select = _ref;
  94. },
  95. options: options,
  96. onChange: this.onChange
  97. }));
  98. }, Creatable;
  99. }(React.Component), _class.defaultProps = defaultProps, _temp;
  100. }, SelectCreatable = makeCreatableSelect(reactSelect.Select), Creatable = stateManager.manageState(SelectCreatable);
  101. exports.default = Creatable, exports.defaultProps = defaultProps, exports.makeCreatableSelect = makeCreatableSelect;