@ucloud-fe/react-components 1.3.24 → 1.3.27

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,867 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.default = void 0;
9
+
10
+ var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
11
+
12
+ var _newArrowCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/newArrowCheck"));
13
+
14
+ var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
15
+
16
+ var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
17
+
18
+ var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized"));
19
+
20
+ var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
21
+
22
+ var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
23
+
24
+ var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
25
+
26
+ var _react = _interopRequireDefault(require("react"));
27
+
28
+ var _propTypes = _interopRequireDefault(require("prop-types"));
29
+
30
+ var _reactDom = require("react-dom");
31
+
32
+ var _reactLifecyclesCompat = require("react-lifecycles-compat");
33
+
34
+ var _contains = _interopRequireDefault(require("rc-util/lib/Dom/contains"));
35
+
36
+ var _addEventListener = _interopRequireDefault(require("rc-util/lib/Dom/addEventListener"));
37
+
38
+ var _ContainerRender = _interopRequireDefault(require("rc-util/lib/ContainerRender"));
39
+
40
+ var _Portal = _interopRequireDefault(require("rc-util/lib/Portal"));
41
+
42
+ var _classnames = _interopRequireDefault(require("classnames"));
43
+
44
+ var _utils = require("./utils");
45
+
46
+ var _Popup = _interopRequireDefault(require("./Popup"));
47
+
48
+ function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2.default)(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2.default)(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2.default)(this, result); }; }
49
+
50
+ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
51
+
52
+ function noop() {}
53
+
54
+ function returnEmptyString() {
55
+ return '';
56
+ }
57
+
58
+ function returnDocument() {
59
+ return window.document;
60
+ }
61
+
62
+ var ALL_HANDLERS = ['onClick', 'onMouseDown', 'onTouchStart', 'onMouseEnter', 'onMouseLeave', 'onFocus', 'onBlur', 'onContextMenu'];
63
+ var IS_REACT_16 = !!_reactDom.createPortal;
64
+ var contextTypes = {
65
+ rcTrigger: _propTypes.default.shape({
66
+ onPopupMouseDown: _propTypes.default.func
67
+ })
68
+ };
69
+
70
+ var Trigger = /*#__PURE__*/function (_React$Component) {
71
+ (0, _inherits2.default)(Trigger, _React$Component);
72
+
73
+ var _super = _createSuper(Trigger);
74
+
75
+ function Trigger(_props) {
76
+ var _this2 = this;
77
+
78
+ var _this;
79
+
80
+ (0, _classCallCheck2.default)(this, Trigger);
81
+ _this = _super.call(this, _props);
82
+ _this.state = {};
83
+
84
+ _this.onMouseEnter = function (e) {
85
+ (0, _newArrowCheck2.default)(this, _this2);
86
+ var mouseEnterDelay = _this.props.mouseEnterDelay;
87
+
88
+ _this.fireEvents('onMouseEnter', e);
89
+
90
+ _this.delaySetPopupVisible(true, mouseEnterDelay, mouseEnterDelay ? null : e);
91
+ }.bind(this);
92
+
93
+ _this.onMouseMove = function (e) {
94
+ (0, _newArrowCheck2.default)(this, _this2);
95
+
96
+ _this.fireEvents('onMouseMove', e);
97
+
98
+ _this.setPoint(e);
99
+ }.bind(this);
100
+
101
+ _this.onMouseLeave = function (e) {
102
+ (0, _newArrowCheck2.default)(this, _this2);
103
+
104
+ _this.fireEvents('onMouseLeave', e);
105
+
106
+ _this.delaySetPopupVisible(false, _this.props.mouseLeaveDelay);
107
+ }.bind(this);
108
+
109
+ _this.onPopupMouseEnter = function () {
110
+ (0, _newArrowCheck2.default)(this, _this2);
111
+
112
+ _this.clearDelayTimer();
113
+ }.bind(this);
114
+
115
+ _this.onPopupMouseLeave = function (e) {
116
+ (0, _newArrowCheck2.default)(this, _this2);
117
+
118
+ // https://github.com/react-component/trigger/pull/13
119
+ // react bug?
120
+ if (e.relatedTarget && !e.relatedTarget.setTimeout && _this._component && _this._component.getPopupDomNode && (0, _contains.default)(_this._component.getPopupDomNode(), e.relatedTarget)) {
121
+ return;
122
+ }
123
+
124
+ _this.delaySetPopupVisible(false, _this.props.mouseLeaveDelay);
125
+ }.bind(this);
126
+
127
+ _this.onFocus = function (e) {
128
+ (0, _newArrowCheck2.default)(this, _this2);
129
+
130
+ _this.fireEvents('onFocus', e); // incase focusin and focusout
131
+
132
+
133
+ _this.clearDelayTimer();
134
+
135
+ if (_this.isFocusToShow()) {
136
+ _this.focusTime = Date.now();
137
+
138
+ _this.delaySetPopupVisible(true, _this.props.focusDelay);
139
+ }
140
+ }.bind(this);
141
+
142
+ _this.onMouseDown = function (e) {
143
+ (0, _newArrowCheck2.default)(this, _this2);
144
+
145
+ _this.fireEvents('onMouseDown', e);
146
+
147
+ _this.preClickTime = Date.now();
148
+ }.bind(this);
149
+
150
+ _this.onTouchStart = function (e) {
151
+ (0, _newArrowCheck2.default)(this, _this2);
152
+
153
+ _this.fireEvents('onTouchStart', e);
154
+
155
+ _this.preTouchTime = Date.now();
156
+ }.bind(this);
157
+
158
+ _this.onBlur = function (e) {
159
+ (0, _newArrowCheck2.default)(this, _this2);
160
+
161
+ _this.fireEvents('onBlur', e);
162
+
163
+ _this.clearDelayTimer();
164
+
165
+ if (_this.isBlurToHide()) {
166
+ _this.delaySetPopupVisible(false, _this.props.blurDelay);
167
+ }
168
+ }.bind(this);
169
+
170
+ _this.onContextMenu = function (e) {
171
+ (0, _newArrowCheck2.default)(this, _this2);
172
+ e.preventDefault();
173
+
174
+ _this.fireEvents('onContextMenu', e);
175
+
176
+ _this.setPopupVisible(true, e);
177
+ }.bind(this);
178
+
179
+ _this.onContextMenuClose = function () {
180
+ (0, _newArrowCheck2.default)(this, _this2);
181
+
182
+ if (_this.isContextMenuToShow()) {
183
+ _this.close();
184
+ }
185
+ }.bind(this);
186
+
187
+ _this.onClick = function (event) {
188
+ (0, _newArrowCheck2.default)(this, _this2);
189
+
190
+ _this.fireEvents('onClick', event); // focus will trigger click
191
+
192
+
193
+ if (_this.focusTime) {
194
+ var preTime;
195
+
196
+ if (_this.preClickTime && _this.preTouchTime) {
197
+ preTime = Math.min(_this.preClickTime, _this.preTouchTime);
198
+ } else if (_this.preClickTime) {
199
+ preTime = _this.preClickTime;
200
+ } else if (_this.preTouchTime) {
201
+ preTime = _this.preTouchTime;
202
+ }
203
+
204
+ if (Math.abs(preTime - _this.focusTime) < 20) {
205
+ return;
206
+ }
207
+
208
+ _this.focusTime = 0;
209
+ }
210
+
211
+ _this.preClickTime = 0;
212
+ _this.preTouchTime = 0; // Only prevent default when all the action is click.
213
+ // https://github.com/ant-design/ant-design/issues/17043
214
+ // https://github.com/ant-design/ant-design/issues/17291
215
+
216
+ if (_this.isClickToShow() && (_this.isClickToHide() || _this.isBlurToHide()) && event && event.preventDefault) {
217
+ event.preventDefault();
218
+ }
219
+
220
+ var nextVisible = !_this.state.popupVisible;
221
+
222
+ if (_this.isClickToHide() && !nextVisible || nextVisible && _this.isClickToShow()) {
223
+ _this.setPopupVisible(!_this.state.popupVisible, event);
224
+ }
225
+ }.bind(this);
226
+
227
+ _this.onPopupMouseDown = function () {
228
+ var _this3 = this;
229
+
230
+ var _this$context$rcTrigg = _this.context.rcTrigger,
231
+ rcTrigger = _this$context$rcTrigg === void 0 ? {} : _this$context$rcTrigg;
232
+ _this.hasPopupMouseDown = true;
233
+ clearTimeout(_this.mouseDownTimeout);
234
+ _this.mouseDownTimeout = setTimeout(function () {
235
+ (0, _newArrowCheck2.default)(this, _this3);
236
+ _this.hasPopupMouseDown = false;
237
+ }.bind(this), 0);
238
+
239
+ if (rcTrigger.onPopupMouseDown) {
240
+ rcTrigger.onPopupMouseDown.apply(rcTrigger, arguments);
241
+ }
242
+ };
243
+
244
+ _this.onDocumentClick = function (event) {
245
+ (0, _newArrowCheck2.default)(this, _this2);
246
+
247
+ if (_this.props.mask && !_this.props.maskClosable) {
248
+ return;
249
+ }
250
+
251
+ var target = event.target;
252
+ var root = (0, _reactDom.findDOMNode)((0, _assertThisInitialized2.default)(_this));
253
+
254
+ if (!(0, _contains.default)(root, target) && !_this.hasPopupMouseDown) {
255
+ _this.close();
256
+ }
257
+ }.bind(this);
258
+
259
+ _this.getRootDomNode = function () {
260
+ (0, _newArrowCheck2.default)(this, _this2);
261
+ return (0, _reactDom.findDOMNode)((0, _assertThisInitialized2.default)(_this));
262
+ }.bind(this);
263
+
264
+ _this.getPopupClassNameFromAlign = function (align) {
265
+ (0, _newArrowCheck2.default)(this, _this2);
266
+ var className = [];
267
+ var _this$props = _this.props,
268
+ popupPlacement = _this$props.popupPlacement,
269
+ builtinPlacements = _this$props.builtinPlacements,
270
+ prefixCls = _this$props.prefixCls,
271
+ alignPoint = _this$props.alignPoint,
272
+ getPopupClassNameFromAlign = _this$props.getPopupClassNameFromAlign;
273
+
274
+ if (popupPlacement && builtinPlacements) {
275
+ className.push((0, _utils.getAlignPopupClassName)(builtinPlacements, prefixCls, align, alignPoint));
276
+ }
277
+
278
+ if (getPopupClassNameFromAlign) {
279
+ className.push(getPopupClassNameFromAlign(align));
280
+ }
281
+
282
+ return className.join(' ');
283
+ }.bind(this);
284
+
285
+ _this.getComponent = function () {
286
+ (0, _newArrowCheck2.default)(this, _this2);
287
+ var _this$props2 = _this.props,
288
+ prefixCls = _this$props2.prefixCls,
289
+ destroyPopupOnHide = _this$props2.destroyPopupOnHide,
290
+ popupClassName = _this$props2.popupClassName,
291
+ action = _this$props2.action,
292
+ onPopupAlign = _this$props2.onPopupAlign,
293
+ popupAnimation = _this$props2.popupAnimation,
294
+ popupTransitionName = _this$props2.popupTransitionName,
295
+ popupStyle = _this$props2.popupStyle,
296
+ mask = _this$props2.mask,
297
+ maskAnimation = _this$props2.maskAnimation,
298
+ maskTransitionName = _this$props2.maskTransitionName,
299
+ zIndex = _this$props2.zIndex,
300
+ popup = _this$props2.popup,
301
+ stretch = _this$props2.stretch,
302
+ alignPoint = _this$props2.alignPoint;
303
+ var _this$state = _this.state,
304
+ popupVisible = _this$state.popupVisible,
305
+ point = _this$state.point;
306
+
307
+ var align = _this.getPopupAlign();
308
+
309
+ var mouseProps = {};
310
+
311
+ if (_this.isMouseEnterToShow()) {
312
+ mouseProps.onMouseEnter = _this.onPopupMouseEnter;
313
+ }
314
+
315
+ if (_this.isMouseLeaveToHide()) {
316
+ mouseProps.onMouseLeave = _this.onPopupMouseLeave;
317
+ }
318
+
319
+ mouseProps.onMouseDown = _this.onPopupMouseDown;
320
+ mouseProps.onTouchStart = _this.onPopupMouseDown;
321
+ return /*#__PURE__*/_react.default.createElement(_Popup.default, (0, _extends2.default)({
322
+ prefixCls: prefixCls,
323
+ destroyPopupOnHide: destroyPopupOnHide,
324
+ visible: popupVisible,
325
+ point: alignPoint && point,
326
+ className: popupClassName,
327
+ action: action,
328
+ align: align,
329
+ onAlign: onPopupAlign,
330
+ animation: popupAnimation,
331
+ getClassNameFromAlign: _this.getPopupClassNameFromAlign
332
+ }, mouseProps, {
333
+ stretch: stretch,
334
+ getRootDomNode: _this.getRootDomNode,
335
+ style: popupStyle,
336
+ mask: mask,
337
+ zIndex: zIndex,
338
+ transitionName: popupTransitionName,
339
+ maskAnimation: maskAnimation,
340
+ maskTransitionName: maskTransitionName,
341
+ ref: _this.savePopup
342
+ }), typeof popup === 'function' ? popup() : popup);
343
+ }.bind(this);
344
+
345
+ _this.getContainer = function () {
346
+ (0, _newArrowCheck2.default)(this, _this2);
347
+
348
+ var _assertThisInitialize = (0, _assertThisInitialized2.default)(_this),
349
+ props = _assertThisInitialize.props;
350
+
351
+ var popupContainer = document.createElement('div'); // Make sure default popup container will never cause scrollbar appearing
352
+ // https://github.com/react-component/trigger/issues/41
353
+
354
+ popupContainer.style.position = 'absolute';
355
+ popupContainer.style.top = '0';
356
+ popupContainer.style.left = '0';
357
+ popupContainer.style.width = '100%';
358
+ var mountNode = props.getPopupContainer ? props.getPopupContainer((0, _reactDom.findDOMNode)((0, _assertThisInitialized2.default)(_this))) : props.getDocument().body;
359
+ mountNode.appendChild(popupContainer);
360
+ return popupContainer;
361
+ }.bind(this);
362
+
363
+ _this.setPoint = function (point) {
364
+ (0, _newArrowCheck2.default)(this, _this2);
365
+ var alignPoint = _this.props.alignPoint;
366
+ if (!alignPoint || !point) return;
367
+
368
+ _this.setState({
369
+ point: {
370
+ pageX: point.pageX,
371
+ pageY: point.pageY
372
+ }
373
+ });
374
+ }.bind(this);
375
+
376
+ _this.handlePortalUpdate = function () {
377
+ (0, _newArrowCheck2.default)(this, _this2);
378
+
379
+ if (_this.state.prevPopupVisible !== _this.state.popupVisible) {
380
+ _this.props.afterPopupVisibleChange(_this.state.popupVisible);
381
+ }
382
+ }.bind(this);
383
+
384
+ _this.savePopup = function (node) {
385
+ (0, _newArrowCheck2.default)(this, _this2);
386
+ _this._component = node;
387
+ }.bind(this);
388
+
389
+ var _popupVisible;
390
+
391
+ if ('popupVisible' in _props) {
392
+ _popupVisible = !!_props.popupVisible;
393
+ } else {
394
+ _popupVisible = !!_props.defaultPopupVisible;
395
+ }
396
+
397
+ _this.state = {
398
+ prevPopupVisible: _popupVisible,
399
+ popupVisible: _popupVisible
400
+ };
401
+ ALL_HANDLERS.forEach(function (h) {
402
+ var _this4 = this;
403
+
404
+ (0, _newArrowCheck2.default)(this, _this2);
405
+
406
+ _this["fire".concat(h)] = function (e) {
407
+ (0, _newArrowCheck2.default)(this, _this4);
408
+
409
+ _this.fireEvents(h, e);
410
+ }.bind(this);
411
+ }.bind(this));
412
+ return _this;
413
+ }
414
+
415
+ (0, _createClass2.default)(Trigger, [{
416
+ key: "getChildContext",
417
+ value: function getChildContext() {
418
+ return {
419
+ rcTrigger: {
420
+ onPopupMouseDown: this.onPopupMouseDown
421
+ }
422
+ };
423
+ }
424
+ }, {
425
+ key: "componentDidMount",
426
+ value: function componentDidMount() {
427
+ this.componentDidUpdate({}, {
428
+ popupVisible: this.state.popupVisible
429
+ });
430
+ }
431
+ }, {
432
+ key: "componentDidUpdate",
433
+ value: function componentDidUpdate(_, prevState) {
434
+ var _this5 = this;
435
+
436
+ var props = this.props;
437
+ var state = this.state;
438
+
439
+ var triggerAfterPopupVisibleChange = function triggerAfterPopupVisibleChange() {
440
+ (0, _newArrowCheck2.default)(this, _this5);
441
+
442
+ if (prevState.popupVisible !== state.popupVisible) {
443
+ props.afterPopupVisibleChange(state.popupVisible);
444
+ }
445
+ }.bind(this);
446
+
447
+ if (!IS_REACT_16) {
448
+ this.renderComponent(null, triggerAfterPopupVisibleChange);
449
+ } // We must listen to `mousedown` or `touchstart`, edge case:
450
+ // https://github.com/ant-design/ant-design/issues/5804
451
+ // https://github.com/react-component/calendar/issues/250
452
+ // https://github.com/react-component/trigger/issues/50
453
+
454
+
455
+ if (state.popupVisible) {
456
+ var currentDocument;
457
+
458
+ if (!this.clickOutsideHandler && (this.isClickToHide() || this.isContextMenuToShow())) {
459
+ currentDocument = props.getDocument();
460
+ this.clickOutsideHandler = (0, _addEventListener.default)(currentDocument, 'mousedown', this.onDocumentClick);
461
+ } // always hide on mobile
462
+
463
+
464
+ if (!this.touchOutsideHandler) {
465
+ currentDocument = currentDocument || props.getDocument();
466
+ this.touchOutsideHandler = (0, _addEventListener.default)(currentDocument, 'touchstart', this.onDocumentClick);
467
+ } // close popup when trigger type contains 'onContextMenu' and document is scrolling.
468
+
469
+
470
+ if (!this.contextMenuOutsideHandler1 && this.isContextMenuToShow()) {
471
+ currentDocument = currentDocument || props.getDocument();
472
+ this.contextMenuOutsideHandler1 = (0, _addEventListener.default)(currentDocument, 'scroll', this.onContextMenuClose);
473
+ } // close popup when trigger type contains 'onContextMenu' and window is blur.
474
+
475
+
476
+ if (!this.contextMenuOutsideHandler2 && this.isContextMenuToShow()) {
477
+ this.contextMenuOutsideHandler2 = (0, _addEventListener.default)(window, 'blur', this.onContextMenuClose);
478
+ }
479
+
480
+ return;
481
+ }
482
+
483
+ this.clearOutsideHandler();
484
+ }
485
+ }, {
486
+ key: "componentWillUnmount",
487
+ value: function componentWillUnmount() {
488
+ this.clearDelayTimer();
489
+ this.clearOutsideHandler();
490
+ clearTimeout(this.mouseDownTimeout);
491
+ }
492
+ }, {
493
+ key: "getPopupDomNode",
494
+ value: function getPopupDomNode() {
495
+ // for test
496
+ if (this._component && this._component.getPopupDomNode) {
497
+ return this._component.getPopupDomNode();
498
+ }
499
+
500
+ return null;
501
+ }
502
+ }, {
503
+ key: "getPopupAlign",
504
+ value: function getPopupAlign() {
505
+ var props = this.props;
506
+ var popupPlacement = props.popupPlacement,
507
+ popupAlign = props.popupAlign,
508
+ builtinPlacements = props.builtinPlacements;
509
+
510
+ if (popupPlacement && builtinPlacements) {
511
+ return (0, _utils.getAlignFromPlacement)(builtinPlacements, popupPlacement, popupAlign);
512
+ }
513
+
514
+ return popupAlign;
515
+ }
516
+ }, {
517
+ key: "setPopupVisible",
518
+ value:
519
+ /**
520
+ * @param popupVisible Show or not the popup element
521
+ * @param event SyntheticEvent, used for `pointAlign`
522
+ */
523
+ function setPopupVisible(popupVisible, event) {
524
+ var alignPoint = this.props.alignPoint;
525
+ var prevPopupVisible = this.state.popupVisible;
526
+ this.clearDelayTimer();
527
+
528
+ if (prevPopupVisible !== popupVisible) {
529
+ if (!('popupVisible' in this.props)) {
530
+ this.setState({
531
+ popupVisible: popupVisible,
532
+ prevPopupVisible: prevPopupVisible
533
+ });
534
+ }
535
+
536
+ this.props.onPopupVisibleChange(popupVisible);
537
+ } // Always record the point position since mouseEnterDelay will delay the show
538
+
539
+
540
+ if (alignPoint && event) {
541
+ this.setPoint(event);
542
+ }
543
+ }
544
+ }, {
545
+ key: "delaySetPopupVisible",
546
+ value: function delaySetPopupVisible(visible, delayS, event) {
547
+ var _this6 = this;
548
+
549
+ var delay = delayS * 1000;
550
+ this.clearDelayTimer();
551
+
552
+ if (delay) {
553
+ var point = event ? {
554
+ pageX: event.pageX,
555
+ pageY: event.pageY
556
+ } : null;
557
+ this.delayTimer = setTimeout(function () {
558
+ (0, _newArrowCheck2.default)(this, _this6);
559
+ this.setPopupVisible(visible, point);
560
+ this.clearDelayTimer();
561
+ }.bind(this), delay);
562
+ } else {
563
+ this.setPopupVisible(visible, event);
564
+ }
565
+ }
566
+ }, {
567
+ key: "clearDelayTimer",
568
+ value: function clearDelayTimer() {
569
+ if (this.delayTimer) {
570
+ clearTimeout(this.delayTimer);
571
+ this.delayTimer = null;
572
+ }
573
+ }
574
+ }, {
575
+ key: "clearOutsideHandler",
576
+ value: function clearOutsideHandler() {
577
+ if (this.clickOutsideHandler) {
578
+ this.clickOutsideHandler.remove();
579
+ this.clickOutsideHandler = null;
580
+ }
581
+
582
+ if (this.contextMenuOutsideHandler1) {
583
+ this.contextMenuOutsideHandler1.remove();
584
+ this.contextMenuOutsideHandler1 = null;
585
+ }
586
+
587
+ if (this.contextMenuOutsideHandler2) {
588
+ this.contextMenuOutsideHandler2.remove();
589
+ this.contextMenuOutsideHandler2 = null;
590
+ }
591
+
592
+ if (this.touchOutsideHandler) {
593
+ this.touchOutsideHandler.remove();
594
+ this.touchOutsideHandler = null;
595
+ }
596
+ }
597
+ }, {
598
+ key: "createTwoChains",
599
+ value: function createTwoChains(event) {
600
+ var childPros = this.props.children.props;
601
+ var props = this.props;
602
+
603
+ if (childPros[event] && props[event]) {
604
+ return this["fire".concat(event)];
605
+ }
606
+
607
+ return childPros[event] || props[event];
608
+ }
609
+ }, {
610
+ key: "isClickToShow",
611
+ value: function isClickToShow() {
612
+ var _this$props3 = this.props,
613
+ action = _this$props3.action,
614
+ showAction = _this$props3.showAction;
615
+ return action.indexOf('click') !== -1 || showAction.indexOf('click') !== -1;
616
+ }
617
+ }, {
618
+ key: "isContextMenuToShow",
619
+ value: function isContextMenuToShow() {
620
+ var _this$props4 = this.props,
621
+ action = _this$props4.action,
622
+ showAction = _this$props4.showAction;
623
+ return action.indexOf('contextMenu') !== -1 || showAction.indexOf('contextMenu') !== -1;
624
+ }
625
+ }, {
626
+ key: "isClickToHide",
627
+ value: function isClickToHide() {
628
+ var _this$props5 = this.props,
629
+ action = _this$props5.action,
630
+ hideAction = _this$props5.hideAction;
631
+ return action.indexOf('click') !== -1 || hideAction.indexOf('click') !== -1;
632
+ }
633
+ }, {
634
+ key: "isMouseEnterToShow",
635
+ value: function isMouseEnterToShow() {
636
+ var _this$props6 = this.props,
637
+ action = _this$props6.action,
638
+ showAction = _this$props6.showAction;
639
+ return action.indexOf('hover') !== -1 || showAction.indexOf('mouseEnter') !== -1;
640
+ }
641
+ }, {
642
+ key: "isMouseLeaveToHide",
643
+ value: function isMouseLeaveToHide() {
644
+ var _this$props7 = this.props,
645
+ action = _this$props7.action,
646
+ hideAction = _this$props7.hideAction;
647
+ return action.indexOf('hover') !== -1 || hideAction.indexOf('mouseLeave') !== -1;
648
+ }
649
+ }, {
650
+ key: "isFocusToShow",
651
+ value: function isFocusToShow() {
652
+ var _this$props8 = this.props,
653
+ action = _this$props8.action,
654
+ showAction = _this$props8.showAction;
655
+ return action.indexOf('focus') !== -1 || showAction.indexOf('focus') !== -1;
656
+ }
657
+ }, {
658
+ key: "isBlurToHide",
659
+ value: function isBlurToHide() {
660
+ var _this$props9 = this.props,
661
+ action = _this$props9.action,
662
+ hideAction = _this$props9.hideAction;
663
+ return action.indexOf('focus') !== -1 || hideAction.indexOf('blur') !== -1;
664
+ }
665
+ }, {
666
+ key: "forcePopupAlign",
667
+ value: function forcePopupAlign() {
668
+ if (this.state.popupVisible && this._component && this._component.alignInstance) {
669
+ this._component.alignInstance.forceAlign();
670
+ }
671
+ }
672
+ }, {
673
+ key: "fireEvents",
674
+ value: function fireEvents(type, e) {
675
+ var childCallback = this.props.children.props[type];
676
+
677
+ if (childCallback) {
678
+ childCallback(e);
679
+ }
680
+
681
+ var callback = this.props[type];
682
+
683
+ if (callback) {
684
+ callback(e);
685
+ }
686
+ }
687
+ }, {
688
+ key: "close",
689
+ value: function close() {
690
+ this.setPopupVisible(false);
691
+ }
692
+ }, {
693
+ key: "render",
694
+ value: function render() {
695
+ var _this7 = this;
696
+
697
+ var popupVisible = this.state.popupVisible;
698
+ var _this$props10 = this.props,
699
+ children = _this$props10.children,
700
+ forceRender = _this$props10.forceRender,
701
+ alignPoint = _this$props10.alignPoint,
702
+ className = _this$props10.className;
703
+
704
+ var child = _react.default.Children.only(children);
705
+
706
+ var newChildProps = {
707
+ key: 'trigger'
708
+ };
709
+
710
+ if (this.isContextMenuToShow()) {
711
+ newChildProps.onContextMenu = this.onContextMenu;
712
+ } else {
713
+ newChildProps.onContextMenu = this.createTwoChains('onContextMenu');
714
+ }
715
+
716
+ if (this.isClickToHide() || this.isClickToShow()) {
717
+ newChildProps.onClick = this.onClick;
718
+ newChildProps.onMouseDown = this.onMouseDown;
719
+ newChildProps.onTouchStart = this.onTouchStart;
720
+ } else {
721
+ newChildProps.onClick = this.createTwoChains('onClick');
722
+ newChildProps.onMouseDown = this.createTwoChains('onMouseDown');
723
+ newChildProps.onTouchStart = this.createTwoChains('onTouchStart');
724
+ }
725
+
726
+ if (this.isMouseEnterToShow()) {
727
+ newChildProps.onMouseEnter = this.onMouseEnter;
728
+
729
+ if (alignPoint) {
730
+ newChildProps.onMouseMove = this.onMouseMove;
731
+ }
732
+ } else {
733
+ newChildProps.onMouseEnter = this.createTwoChains('onMouseEnter');
734
+ }
735
+
736
+ if (this.isMouseLeaveToHide()) {
737
+ newChildProps.onMouseLeave = this.onMouseLeave;
738
+ } else {
739
+ newChildProps.onMouseLeave = this.createTwoChains('onMouseLeave');
740
+ }
741
+
742
+ if (this.isFocusToShow() || this.isBlurToHide()) {
743
+ newChildProps.onFocus = this.onFocus;
744
+ newChildProps.onBlur = this.onBlur;
745
+ } else {
746
+ newChildProps.onFocus = this.createTwoChains('onFocus');
747
+ newChildProps.onBlur = this.createTwoChains('onBlur');
748
+ }
749
+
750
+ var childrenClassName = (0, _classnames.default)(child && child.props && child.props.className, className);
751
+
752
+ if (childrenClassName) {
753
+ newChildProps.className = childrenClassName;
754
+ }
755
+
756
+ var trigger = /*#__PURE__*/_react.default.cloneElement(child, newChildProps);
757
+
758
+ if (!IS_REACT_16) {
759
+ return /*#__PURE__*/_react.default.createElement(_ContainerRender.default, {
760
+ parent: this,
761
+ visible: popupVisible,
762
+ autoMount: false,
763
+ forceRender: forceRender,
764
+ getComponent: this.getComponent,
765
+ getContainer: this.getContainer
766
+ }, function (_ref) {
767
+ (0, _newArrowCheck2.default)(this, _this7);
768
+ var renderComponent = _ref.renderComponent;
769
+ this.renderComponent = renderComponent;
770
+ return trigger;
771
+ }.bind(this));
772
+ }
773
+
774
+ var portal; // prevent unmounting after it's rendered
775
+
776
+ if (popupVisible || this._component || forceRender) {
777
+ portal = /*#__PURE__*/_react.default.createElement(_Portal.default, {
778
+ key: "portal",
779
+ getContainer: this.getContainer,
780
+ didUpdate: this.handlePortalUpdate
781
+ }, this.getComponent());
782
+ }
783
+
784
+ return [trigger, portal];
785
+ }
786
+ }], [{
787
+ key: "getDerivedStateFromProps",
788
+ value: function getDerivedStateFromProps(_ref2, prevState) {
789
+ var popupVisible = _ref2.popupVisible;
790
+ var newState = {};
791
+
792
+ if (popupVisible !== undefined && prevState.popupVisible !== popupVisible) {
793
+ newState.popupVisible = popupVisible;
794
+ newState.prevPopupVisible = prevState.popupVisible;
795
+ }
796
+
797
+ return newState;
798
+ }
799
+ }]);
800
+ return Trigger;
801
+ }(_react.default.Component);
802
+
803
+ Trigger.propTypes = {
804
+ children: _propTypes.default.any,
805
+ action: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.arrayOf(_propTypes.default.string)]),
806
+ showAction: _propTypes.default.any,
807
+ hideAction: _propTypes.default.any,
808
+ getPopupClassNameFromAlign: _propTypes.default.any,
809
+ onPopupVisibleChange: _propTypes.default.func,
810
+ afterPopupVisibleChange: _propTypes.default.func,
811
+ popup: _propTypes.default.oneOfType([_propTypes.default.node, _propTypes.default.func]).isRequired,
812
+ popupStyle: _propTypes.default.object,
813
+ prefixCls: _propTypes.default.string,
814
+ popupClassName: _propTypes.default.string,
815
+ className: _propTypes.default.string,
816
+ popupPlacement: _propTypes.default.string,
817
+ builtinPlacements: _propTypes.default.object,
818
+ popupTransitionName: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.object]),
819
+ popupAnimation: _propTypes.default.any,
820
+ mouseEnterDelay: _propTypes.default.number,
821
+ mouseLeaveDelay: _propTypes.default.number,
822
+ zIndex: _propTypes.default.number,
823
+ focusDelay: _propTypes.default.number,
824
+ blurDelay: _propTypes.default.number,
825
+ getPopupContainer: _propTypes.default.func,
826
+ getDocument: _propTypes.default.func,
827
+ forceRender: _propTypes.default.bool,
828
+ destroyPopupOnHide: _propTypes.default.bool,
829
+ mask: _propTypes.default.bool,
830
+ maskClosable: _propTypes.default.bool,
831
+ onPopupAlign: _propTypes.default.func,
832
+ popupAlign: _propTypes.default.object,
833
+ popupVisible: _propTypes.default.bool,
834
+ defaultPopupVisible: _propTypes.default.bool,
835
+ maskTransitionName: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.object]),
836
+ maskAnimation: _propTypes.default.string,
837
+ stretch: _propTypes.default.string,
838
+ alignPoint: _propTypes.default.bool // Maybe we can support user pass position in the future
839
+
840
+ };
841
+ Trigger.contextTypes = contextTypes;
842
+ Trigger.childContextTypes = contextTypes;
843
+ Trigger.defaultProps = {
844
+ prefixCls: 'rc-trigger-popup',
845
+ getPopupClassNameFromAlign: returnEmptyString,
846
+ getDocument: returnDocument,
847
+ onPopupVisibleChange: noop,
848
+ afterPopupVisibleChange: noop,
849
+ onPopupAlign: noop,
850
+ popupClassName: '',
851
+ mouseEnterDelay: 0,
852
+ mouseLeaveDelay: 0.1,
853
+ focusDelay: 0,
854
+ blurDelay: 0.15,
855
+ popupStyle: {},
856
+ destroyPopupOnHide: false,
857
+ popupAlign: {},
858
+ defaultPopupVisible: false,
859
+ mask: false,
860
+ maskClosable: true,
861
+ action: [],
862
+ showAction: [],
863
+ hideAction: []
864
+ };
865
+ (0, _reactLifecyclesCompat.polyfill)(Trigger);
866
+ var _default = Trigger;
867
+ exports.default = _default;