-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvendors~bots.5774de5dfac3d7c6dece.js
2361 lines (2033 loc) · 228 KB
/
vendors~bots.5774de5dfac3d7c6dece.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
(window["webpackJsonp"] = window["webpackJsonp"] || []).push([[23],{
/***/ 2589:
/***/ (function(module, exports, __webpack_require__) {
"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 _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 _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 _propTypes = __webpack_require__(731);
var _propTypes2 = _interopRequireDefault(_propTypes);
var _react = __webpack_require__(389);
var _react2 = _interopRequireDefault(_react);
var _Select = __webpack_require__(2590);
var _Select2 = _interopRequireDefault(_Select);
var _stripDiacritics = __webpack_require__(2595);
var _stripDiacritics2 = _interopRequireDefault(_stripDiacritics);
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 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
loadOptions: _propTypes2.default.func.isRequired, // callback to load options asynchronously; (inputValue: string, callback: Function): ?Promise
loadingPlaceholder: _propTypes2.default.oneOfType([// replaces the placeholder while options are loading
_propTypes2.default.string, _propTypes2.default.node]),
multi: _propTypes2.default.bool, // multi-value input
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) {}
onInputChange: _propTypes2.default.func, // optional for keeping track of what is being typed
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]),
searchPromptText: _propTypes2.default.oneOfType([// label to prompt for search input
_propTypes2.default.string, _propTypes2.default.node]),
value: _propTypes2.default.any // initial field value
};
var defaultCache = {};
var defaultChildren = function defaultChildren(props) {
return _react2.default.createElement(_Select2.default, props);
};
var defaultProps = {
autoload: true,
cache: defaultCache,
children: defaultChildren,
ignoreAccents: true,
ignoreCase: true,
loadingPlaceholder: 'Loading...',
options: [],
searchPromptText: 'Type to search'
};
var Async = function (_Component) {
_inherits(Async, _Component);
function Async(props, context) {
_classCallCheck(this, Async);
var _this = _possibleConstructorReturn(this, (Async.__proto__ || Object.getPrototypeOf(Async)).call(this, props, context));
_this._cache = props.cache === defaultCache ? {} : props.cache;
_this.state = {
inputValue: '',
isLoading: false,
options: props.options
};
_this.onInputChange = _this.onInputChange.bind(_this);
return _this;
}
_createClass(Async, [{
key: 'componentDidMount',
value: function componentDidMount() {
var autoload = this.props.autoload;
if (autoload) {
this.loadOptions('');
}
}
}, {
key: 'componentWillReceiveProps',
value: function componentWillReceiveProps(nextProps) {
if (nextProps.options !== this.props.options) {
this.setState({
options: nextProps.options
});
}
}
}, {
key: 'componentWillUnmount',
value: function componentWillUnmount() {
this._callback = null;
}
}, {
key: 'loadOptions',
value: function loadOptions(inputValue) {
var _this2 = this;
var loadOptions = this.props.loadOptions;
var cache = this._cache;
if (cache && Object.prototype.hasOwnProperty.call(cache, inputValue)) {
this._callback = null;
this.setState({
isLoading: false,
options: cache[inputValue]
});
return;
}
var callback = function callback(error, data) {
var options = data && data.options || [];
if (cache) {
cache[inputValue] = options;
}
if (callback === _this2._callback) {
_this2._callback = null;
_this2.setState({
isLoading: false,
options: options
});
}
};
// Ignore all but the most recent request
this._callback = callback;
var promise = loadOptions(inputValue, callback);
if (promise) {
promise.then(function (data) {
return callback(null, data);
}, function (error) {
return callback(error);
});
}
if (this._callback && !this.state.isLoading) {
this.setState({
isLoading: true
});
}
}
}, {
key: 'onInputChange',
value: function onInputChange(inputValue) {
var _props = this.props,
ignoreAccents = _props.ignoreAccents,
ignoreCase = _props.ignoreCase,
onInputChange = _props.onInputChange;
var newInputValue = inputValue;
if (onInputChange) {
var value = onInputChange(newInputValue);
// Note: != used deliberately here to catch undefined and null
if (value != null && (typeof value === 'undefined' ? 'undefined' : _typeof(value)) !== 'object') {
newInputValue = '' + value;
}
}
var transformedInputValue = newInputValue;
if (ignoreAccents) {
transformedInputValue = (0, _stripDiacritics2.default)(transformedInputValue);
}
if (ignoreCase) {
transformedInputValue = transformedInputValue.toLowerCase();
}
this.setState({ inputValue: newInputValue });
this.loadOptions(transformedInputValue);
// Return new input value, but without applying toLowerCase() to avoid modifying the user's view case of the input while typing.
return newInputValue;
}
}, {
key: 'noResultsText',
value: function noResultsText() {
var _props2 = this.props,
loadingPlaceholder = _props2.loadingPlaceholder,
noResultsText = _props2.noResultsText,
searchPromptText = _props2.searchPromptText;
var _state = this.state,
inputValue = _state.inputValue,
isLoading = _state.isLoading;
if (isLoading) {
return loadingPlaceholder;
}
if (inputValue && noResultsText) {
return noResultsText;
}
return searchPromptText;
}
}, {
key: 'focus',
value: function focus() {
this.select.focus();
}
}, {
key: 'render',
value: function render() {
var _this3 = this;
var _props3 = this.props,
children = _props3.children,
loadingPlaceholder = _props3.loadingPlaceholder,
placeholder = _props3.placeholder;
var _state2 = this.state,
isLoading = _state2.isLoading,
options = _state2.options;
var props = {
noResultsText: this.noResultsText(),
placeholder: isLoading ? loadingPlaceholder : placeholder,
options: isLoading && loadingPlaceholder ? [] : options,
ref: function ref(_ref) {
return _this3.select = _ref;
}
};
return children(_extends({}, this.props, props, {
isLoading: isLoading,
onInputChange: this.onInputChange
}));
}
}]);
return Async;
}(_react.Component);
exports.default = Async;
Async.propTypes = propTypes;
Async.defaultProps = defaultProps;
/***/ }),
/***/ 2590:
/***/ (function(module, exports, __webpack_require__) {
"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 _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; }; /*!
Copyright (c) 2018 Jed Watson.
Licensed under the MIT License (MIT), see
http://jedwatson.github.io/react-select
*/
var _reactInputAutosize = __webpack_require__(2591);
var _reactInputAutosize2 = _interopRequireDefault(_reactInputAutosize);
var _classnames = __webpack_require__(856);
var _classnames2 = _interopRequireDefault(_classnames);
var _propTypes = __webpack_require__(731);
var _propTypes2 = _interopRequireDefault(_propTypes);
var _react = __webpack_require__(389);
var _react2 = _interopRequireDefault(_react);
var _reactDom = __webpack_require__(398);
var _defaultArrowRenderer = __webpack_require__(2592);
var _defaultArrowRenderer2 = _interopRequireDefault(_defaultArrowRenderer);
var _defaultClearRenderer = __webpack_require__(2593);
var _defaultClearRenderer2 = _interopRequireDefault(_defaultClearRenderer);
var _defaultFilterOptions = __webpack_require__(2594);
var _defaultFilterOptions2 = _interopRequireDefault(_defaultFilterOptions);
var _defaultMenuRenderer = __webpack_require__(2597);
var _defaultMenuRenderer2 = _interopRequireDefault(_defaultMenuRenderer);
var _Option = __webpack_require__(2598);
var _Option2 = _interopRequireDefault(_Option);
var _Value = __webpack_require__(2600);
var _Value2 = _interopRequireDefault(_Value);
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; }
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 stringifyValue = function stringifyValue(value) {
return typeof value === 'string' ? value : value !== null && JSON.stringify(value) || '';
};
var stringOrNode = _propTypes2.default.oneOfType([_propTypes2.default.string, _propTypes2.default.node]);
var stringOrNumber = _propTypes2.default.oneOfType([_propTypes2.default.string, _propTypes2.default.number]);
var instanceId = 1;
var shouldShowValue = function shouldShowValue(state, props) {
var inputValue = state.inputValue,
isPseudoFocused = state.isPseudoFocused,
isFocused = state.isFocused;
var onSelectResetsInput = props.onSelectResetsInput;
if (!inputValue) return true;
if (!onSelectResetsInput) {
return !(!isFocused && isPseudoFocused || isFocused && !isPseudoFocused);
}
return false;
};
var shouldShowPlaceholder = function shouldShowPlaceholder(state, props, isOpen) {
var inputValue = state.inputValue,
isPseudoFocused = state.isPseudoFocused,
isFocused = state.isFocused;
var onSelectResetsInput = props.onSelectResetsInput;
return !inputValue || !onSelectResetsInput && !isOpen && !isPseudoFocused && !isFocused;
};
/**
* Retrieve a value from the given options and valueKey
* @param {String|Number|Array} value - the selected value(s)
* @param {Object} props - the Select component's props (or nextProps)
*/
var expandValue = function expandValue(value, props) {
var valueType = typeof value === 'undefined' ? 'undefined' : _typeof(value);
if (valueType !== 'string' && valueType !== 'number' && valueType !== 'boolean') return value;
var options = props.options,
valueKey = props.valueKey;
if (!options) return;
for (var i = 0; i < options.length; i++) {
if (String(options[i][valueKey]) === String(value)) return options[i];
}
};
var handleRequired = function handleRequired(value, multi) {
if (!value) return true;
return multi ? value.length === 0 : Object.keys(value).length === 0;
};
var Select = 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));
['clearValue', 'focusOption', 'getOptionLabel', 'handleInputBlur', 'handleInputChange', 'handleInputFocus', 'handleInputValueChange', 'handleKeyDown', 'handleMenuScroll', 'handleMouseDown', 'handleMouseDownOnArrow', 'handleMouseDownOnMenu', 'handleTouchEnd', 'handleTouchEndClearValue', 'handleTouchMove', 'handleTouchOutside', 'handleTouchStart', 'handleValueClick', 'onOptionRef', 'removeValue', 'selectValue'].forEach(function (fn) {
return _this[fn] = _this[fn].bind(_this);
});
_this.state = {
inputValue: '',
isFocused: false,
isOpen: false,
isPseudoFocused: false,
required: false
};
return _this;
}
_createClass(Select, [{
key: 'componentWillMount',
value: function componentWillMount() {
this._instancePrefix = 'react-select-' + (this.props.instanceId || ++instanceId) + '-';
var valueArray = this.getValueArray(this.props.value);
if (this.props.required) {
this.setState({
required: handleRequired(valueArray[0], this.props.multi)
});
}
}
}, {
key: 'componentDidMount',
value: function componentDidMount() {
if (typeof this.props.autofocus !== 'undefined' && typeof console !== 'undefined') {
console.warn('Warning: The autofocus prop has changed to autoFocus, support will be removed after [email protected]');
}
if (this.props.autoFocus || this.props.autofocus) {
this.focus();
}
}
}, {
key: 'componentWillReceiveProps',
value: function componentWillReceiveProps(nextProps) {
var valueArray = this.getValueArray(nextProps.value, nextProps);
if (nextProps.required) {
this.setState({
required: handleRequired(valueArray[0], nextProps.multi)
});
} else if (this.props.required) {
// Used to be required but it's not any more
this.setState({ required: false });
}
if (this.state.inputValue && this.props.value !== nextProps.value && nextProps.onSelectResetsInput) {
this.setState({ inputValue: this.handleInputValueChange('') });
}
}
}, {
key: 'componentDidUpdate',
value: function componentDidUpdate(prevProps, prevState) {
// focus to the selected option
if (this.menu && this.focused && this.state.isOpen && !this.hasScrolledToOption) {
var focusedOptionNode = (0, _reactDom.findDOMNode)(this.focused);
var menuNode = (0, _reactDom.findDOMNode)(this.menu);
var scrollTop = menuNode.scrollTop;
var scrollBottom = scrollTop + menuNode.offsetHeight;
var optionTop = focusedOptionNode.offsetTop;
var optionBottom = optionTop + focusedOptionNode.offsetHeight;
if (scrollTop > optionTop || scrollBottom < optionBottom) {
menuNode.scrollTop = focusedOptionNode.offsetTop;
}
// We still set hasScrolledToOption to true even if we didn't
// actually need to scroll, as we've still confirmed that the
// option is in view.
this.hasScrolledToOption = true;
} else if (!this.state.isOpen) {
this.hasScrolledToOption = false;
}
if (this._scrollToFocusedOptionOnUpdate && this.focused && this.menu) {
this._scrollToFocusedOptionOnUpdate = false;
var focusedDOM = (0, _reactDom.findDOMNode)(this.focused);
var menuDOM = (0, _reactDom.findDOMNode)(this.menu);
var focusedRect = focusedDOM.getBoundingClientRect();
var menuRect = menuDOM.getBoundingClientRect();
if (focusedRect.bottom > menuRect.bottom) {
menuDOM.scrollTop = focusedDOM.offsetTop + focusedDOM.clientHeight - menuDOM.offsetHeight;
} else if (focusedRect.top < menuRect.top) {
menuDOM.scrollTop = focusedDOM.offsetTop;
}
}
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();
}
if (prevState.isOpen !== this.state.isOpen) {
this.toggleTouchOutsideEvent(this.state.isOpen);
var handler = this.state.isOpen ? this.props.onOpen : this.props.onClose;
handler && handler();
}
}
}, {
key: 'componentWillUnmount',
value: function componentWillUnmount() {
this.toggleTouchOutsideEvent(false);
}
}, {
key: 'toggleTouchOutsideEvent',
value: function toggleTouchOutsideEvent(enabled) {
var eventTogglerName = enabled ? document.addEventListener ? 'addEventListener' : 'attachEvent' : document.removeEventListener ? 'removeEventListener' : 'detachEvent';
var pref = document.addEventListener ? '' : 'on';
document[eventTogglerName](pref + 'touchstart', this.handleTouchOutside);
document[eventTogglerName](pref + 'mousedown', this.handleTouchOutside);
}
}, {
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() {
// Set a flag that the view is being dragged
this.dragging = true;
}
}, {
key: 'handleTouchStart',
value: function handleTouchStart() {
// 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;
// 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;
// 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;
}
if (event.target.tagName === 'INPUT') {
if (!this.state.isFocused) {
this._openAfterFocus = this.props.openOnClick;
this.focus();
} else if (!this.state.isOpen) {
this.setState({
isOpen: true,
isPseudoFocused: false,
focusedOption: null
});
}
return;
}
// prevent default event handlers
event.preventDefault();
// for the non-searchable select, toggle the menu
if (!this.props.searchable) {
// 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,
focusedOption: null
});
}
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();
var input = this.input;
var toOpen = true;
if (typeof input.getInput === 'function') {
// Get the actual DOM input if the ref is an <AutosizeInput /> component
input = input.getInput();
}
// clears the value so that the cursor will be at the end of input when the component re-renders
input.value = '';
if (this._focusAfterClear) {
toOpen = false;
this._focusAfterClear = false;
}
// if the input is focused, ensure the menu is open
this.setState({
isOpen: toOpen,
isPseudoFocused: false,
focusedOption: null
});
} else {
// otherwise, focus the input and open the menu
this._openAfterFocus = this.props.openOnClick;
this.focus();
this.setState({ focusedOption: null });
}
}
}, {
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 (this.state.isOpen) {
// prevent default event handlers
event.stopPropagation();
event.preventDefault();
// close the menu
this.closeMenu();
} else {
// If the menu isn't open, let the event bubble to the main handleMouseDown
this.setState({
isOpen: true
});
}
}
}, {
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();
this._openAfterFocus = true;
this.focus();
}
}, {
key: 'closeMenu',
value: function closeMenu() {
if (this.props.onCloseResetsInput) {
this.setState({
inputValue: this.handleInputValueChange(''),
isOpen: false,
isPseudoFocused: this.state.isFocused && !this.props.multi
});
} 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 toOpen = this.state.isOpen || this._openAfterFocus || this.props.openOnFocus;
toOpen = this._focusAfterClear ? false : toOpen; //if focus happens after clear values, don't open dropdown yet.
if (this.props.onFocus) {
this.props.onFocus(event);
}
this.setState({
isFocused: true,
isOpen: !!toOpen
});
this._focusAfterClear = false;
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;
}
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;
if (this.state.inputValue !== event.target.value) {
newInputValue = this.handleInputValueChange(newInputValue);
}
this.setState({
inputValue: newInputValue,
isOpen: true,
isPseudoFocused: false
});
}
}, {
key: 'setInputValue',
value: function setInputValue(newValue) {
if (this.props.onInputChange) {
var nextState = this.props.onInputChange(newValue);
if (nextState != null && (typeof nextState === 'undefined' ? 'undefined' : _typeof(nextState)) !== 'object') {
newValue = '' + nextState;
}
}
this.setState({
inputValue: newValue
});
}
}, {
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 newValue;
}
}, {
key: 'handleKeyDown',
value: function handleKeyDown(event) {
if (this.props.disabled) return;
if (typeof this.props.onInputKeyDown === 'function') {
this.props.onInputKeyDown(event);
if (event.defaultPrevented) {
return;
}
}
switch (event.keyCode) {
case 8:
// backspace
if (!this.state.inputValue && this.props.backspaceRemoves) {
event.preventDefault();
this.popValue();
}
break;
case 9:
// tab
if (event.shiftKey || !this.state.isOpen || !this.props.tabSelectsValue) {
break;
}
event.preventDefault();
this.selectFocusedOption();
break;
case 13:
// enter
event.preventDefault();
event.stopPropagation();
if (this.state.isOpen) {
this.selectFocusedOption();
} else {
this.focusNextOption();
}
break;
case 27:
// escape
event.preventDefault();
if (this.state.isOpen) {
this.closeMenu();
event.stopPropagation();
} else if (this.props.clearable && this.props.escapeClearsValue) {
this.clearValue(event);
event.stopPropagation();
}
break;
case 32:
// space
if (this.props.searchable) {
break;
}
event.preventDefault();
if (!this.state.isOpen) {
this.focusNextOption();
break;
}
event.stopPropagation();
this.selectFocusedOption();
break;
case 38:
// up
event.preventDefault();
this.focusPreviousOption();
break;
case 40:
// down
event.preventDefault();
this.focusNextOption();
break;
case 33:
// page up
event.preventDefault();
this.focusPageUpOption();
break;
case 34:
// page down
event.preventDefault();
this.focusPageDownOption();
break;
case 35:
// end key
if (event.shiftKey) {
break;
}
event.preventDefault();
this.focusEndOption();
break;
case 36:
// home key
if (event.shiftKey) {
break;
}
event.preventDefault();
this.focusStartOption();
break;
case 46:
// delete
if (!this.state.inputValue && this.props.deleteRemoves) {
event.preventDefault();
this.popValue();
}
break;
}
}
}, {
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;
if (target.scrollHeight > target.offsetHeight && target.scrollHeight - target.offsetHeight - target.scrollTop <= 0) {
this.props.onMenuScrollToBottom();
}
}
}, {
key: 'getOptionLabel',
value: function getOptionLabel(op) {
return op[this.props.labelKey];
}
/**
* 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
*/
}, {
key: 'getValueArray',
value: function getValueArray(value) {
var nextProps = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : undefined;
/** 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 expandValue(value, props);
}).filter(function (i) {
return i;
});
}
var expandedValue = expandValue(value, props);
return expandedValue ? [expandedValue] : [];
}
}, {
key: 'setValue',
value: function setValue(value) {
var _this2 = this;
if (this.props.autoBlur) {
this.blurInput();
}
if (this.props.required) {
var required = handleRequired(value, this.props.multi);
this.setState({ required: required });
}
if (this.props.simpleValue && value) {
value = this.props.multi ? value.map(function (i) {
return i[_this2.props.valueKey];
}).join(this.props.delimiter) : value[this.props.valueKey];
}
if (this.props.onChange) {
this.props.onChange(value);
}
}
}, {
key: 'selectValue',
value: function selectValue(value) {
var _this3 = this;
// NOTE: we actually add/set the value in a callback to make sure the
// input value is empty to avoid styling issues in Chrome
if (this.props.closeOnSelect) {
this.hasScrolledToOption = false;
}
var updatedValue = this.props.onSelectResetsInput ? '' : this.state.inputValue;
if (this.props.multi) {
this.setState({
focusedIndex: null,
inputValue: this.handleInputValueChange(updatedValue),
isOpen: !this.props.closeOnSelect
}, function () {
var valueArray = _this3.getValueArray(_this3.props.value);