@autobest-ui/components 2.3.0 → 2.5.0
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.
- package/esm/accordion/Item.js +6 -23
- package/esm/accordion/index.js +8 -36
- package/esm/affix/PortalAffix.js +7 -11
- package/esm/affix/index.js +30 -70
- package/esm/carousel/index.js +45 -141
- package/esm/checkbox/index.js +12 -37
- package/esm/collapse/index.js +11 -49
- package/esm/confirm/index.d.ts +8 -0
- package/esm/confirm/index.js +23 -31
- package/esm/date-picker/DateEnum.js +0 -3
- package/esm/date-picker/calendar/Day.js +62 -78
- package/esm/date-picker/calendar/MonthYear.js +20 -53
- package/esm/date-picker/calendar/grid/index.js +7 -12
- package/esm/date-picker/calendar/index.js +4 -31
- package/esm/date-picker/index.js +11 -51
- package/esm/date-picker/utils.js +6 -11
- package/esm/drawer/Child.js +10 -20
- package/esm/drawer/index.js +22 -71
- package/esm/ellipsis/index.js +9 -17
- package/esm/guide/index.js +25 -63
- package/esm/index.d.ts +2 -2
- package/esm/index.js +1 -1
- package/esm/input-number/ControlArrow.js +0 -2
- package/esm/input-number/constants.js +2 -2
- package/esm/input-number/index.js +26 -106
- package/esm/lazy-image/index.js +10 -55
- package/esm/link-list/index.js +11 -35
- package/esm/loading/index.js +15 -42
- package/esm/loading-container/index.js +3 -6
- package/esm/loading-icon/index.js +0 -2
- package/esm/mask/index.js +6 -9
- package/esm/message/index.d.ts +44 -7
- package/esm/message/index.js +96 -111
- package/esm/message/renderMessage.d.ts +17 -0
- package/esm/message/renderMessage.js +137 -0
- package/esm/message/style/index.css +1 -1
- package/esm/modal/Title.js +5 -12
- package/esm/modal/getPopupLocation.js +5 -7
- package/esm/modal/index.js +44 -125
- package/esm/move/index.js +32 -132
- package/esm/move/range.js +6 -12
- package/esm/move/utils.js +3 -10
- package/esm/popover/index.js +9 -28
- package/esm/portal/index.js +1 -22
- package/esm/script/index.js +19 -59
- package/esm/select/index.js +28 -106
- package/esm/show-more/index.js +40 -103
- package/esm/skeleton/Item.js +1 -3
- package/esm/skeleton/index.js +5 -11
- package/esm/style.css +1 -1
- package/esm/table/body/BodyRow.js +11 -28
- package/esm/table/body/CheckIcon.js +10 -18
- package/esm/table/body/index.js +8 -12
- package/esm/table/header/CheckIcon.js +3 -11
- package/esm/table/header/HeaderCell.js +12 -33
- package/esm/table/header/HeaderRow.js +6 -17
- package/esm/table/index.js +30 -100
- package/esm/tabs/index.js +35 -118
- package/esm/tooltip/index.js +0 -4
- package/esm/trigger/align.js +6 -6
- package/esm/trigger/bottomAlign.js +33 -45
- package/esm/trigger/constants.js +0 -1
- package/esm/trigger/getPopupLocation.js +48 -68
- package/esm/trigger/index.js +52 -187
- package/esm/trigger/leftAlign.js +33 -47
- package/esm/trigger/ref.js +2 -7
- package/esm/trigger/rightAlign.js +33 -45
- package/esm/trigger/topAlign.js +33 -45
- package/esm/trigger/utils.js +28 -45
- package/lib/accordion/Item.js +6 -27
- package/lib/accordion/index.js +8 -41
- package/lib/affix/PortalAffix.js +7 -17
- package/lib/affix/index.js +30 -75
- package/lib/carousel/index.js +45 -146
- package/lib/checkbox/index.js +12 -41
- package/lib/collapse/index.js +11 -53
- package/lib/confirm/index.d.ts +8 -0
- package/lib/confirm/index.js +23 -38
- package/lib/date-picker/DateEnum.js +0 -3
- package/lib/date-picker/calendar/Day.js +62 -87
- package/lib/date-picker/calendar/MonthYear.js +20 -62
- package/lib/date-picker/calendar/grid/index.js +7 -16
- package/lib/date-picker/calendar/index.js +4 -37
- package/lib/date-picker/index.js +9 -58
- package/lib/date-picker/utils.js +6 -26
- package/lib/drawer/Child.js +10 -25
- package/lib/drawer/index.js +22 -78
- package/lib/ellipsis/index.js +9 -23
- package/lib/guide/index.js +25 -71
- package/lib/index.d.ts +2 -2
- package/lib/index.js +12 -32
- package/lib/input-number/ControlArrow.js +0 -4
- package/lib/input-number/constants.js +2 -2
- package/lib/input-number/index.js +26 -114
- package/lib/lazy-image/index.js +10 -58
- package/lib/link-list/index.js +11 -40
- package/lib/loading/index.js +13 -48
- package/lib/loading-bar/index.js +0 -5
- package/lib/loading-container/index.js +3 -11
- package/lib/loading-icon/index.js +0 -7
- package/lib/mask/index.js +6 -17
- package/lib/message/index.d.ts +44 -7
- package/lib/message/index.js +97 -120
- package/lib/message/renderMessage.d.ts +17 -0
- package/lib/message/renderMessage.js +144 -0
- package/lib/message/style/index.css +1 -1
- package/lib/modal/Affix.js +0 -4
- package/lib/modal/Title.js +5 -15
- package/lib/modal/getPopupLocation.js +5 -9
- package/lib/modal/index.js +44 -135
- package/lib/move/index.js +32 -144
- package/lib/move/range.js +6 -14
- package/lib/move/utils.js +3 -12
- package/lib/popover/index.js +9 -33
- package/lib/portal/index.js +1 -25
- package/lib/script/index.js +19 -61
- package/lib/select/index.js +28 -113
- package/lib/show-more/index.js +40 -110
- package/lib/skeleton/Item.js +1 -8
- package/lib/skeleton/index.js +5 -16
- package/lib/style.css +1 -1
- package/lib/table/body/BodyRow.js +11 -33
- package/lib/table/body/CheckIcon.js +10 -22
- package/lib/table/body/index.js +8 -17
- package/lib/table/header/CheckIcon.js +3 -15
- package/lib/table/header/HeaderCell.js +12 -37
- package/lib/table/header/HeaderRow.js +6 -22
- package/lib/table/index.js +30 -107
- package/lib/tabs/index.js +35 -122
- package/lib/tooltip/index.js +0 -9
- package/lib/trigger/align.js +0 -4
- package/lib/trigger/bottomAlign.js +33 -48
- package/lib/trigger/constants.js +0 -2
- package/lib/trigger/getPopupLocation.js +48 -74
- package/lib/trigger/index.js +52 -198
- package/lib/trigger/leftAlign.js +33 -50
- package/lib/trigger/ref.js +2 -12
- package/lib/trigger/rightAlign.js +33 -48
- package/lib/trigger/topAlign.js +33 -48
- package/lib/trigger/utils.js +28 -53
- package/package.json +7 -3
package/esm/trigger/index.js
CHANGED
|
@@ -9,39 +9,29 @@ var __extends = this && this.__extends || function () {
|
|
|
9
9
|
if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p];
|
|
10
10
|
}
|
|
11
11
|
};
|
|
12
|
-
|
|
13
12
|
return _extendStatics(d, b);
|
|
14
13
|
};
|
|
15
|
-
|
|
16
14
|
return function (d, b) {
|
|
17
15
|
if (typeof b !== "function" && b !== null) throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
18
|
-
|
|
19
16
|
_extendStatics(d, b);
|
|
20
|
-
|
|
21
17
|
function __() {
|
|
22
18
|
this.constructor = d;
|
|
23
19
|
}
|
|
24
|
-
|
|
25
20
|
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
26
21
|
};
|
|
27
22
|
}();
|
|
28
|
-
|
|
29
23
|
var __assign = this && this.__assign || function () {
|
|
30
24
|
__assign = Object.assign || function (t) {
|
|
31
25
|
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
32
26
|
s = arguments[i];
|
|
33
|
-
|
|
34
27
|
for (var p in s) {
|
|
35
28
|
if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
|
|
36
29
|
}
|
|
37
30
|
}
|
|
38
|
-
|
|
39
31
|
return t;
|
|
40
32
|
};
|
|
41
|
-
|
|
42
33
|
return __assign.apply(this, arguments);
|
|
43
34
|
};
|
|
44
|
-
|
|
45
35
|
import React from 'react';
|
|
46
36
|
import { findDOMNode } from 'react-dom';
|
|
47
37
|
import classNames from 'classnames';
|
|
@@ -50,108 +40,83 @@ import { CSSTransition } from 'react-transition-group';
|
|
|
50
40
|
import Portal from '../portal';
|
|
51
41
|
import { supportRef, composeRef } from './ref';
|
|
52
42
|
import getPopupLocation from './getPopupLocation';
|
|
53
|
-
|
|
54
43
|
function noop() {}
|
|
55
|
-
|
|
56
|
-
var Trigger =
|
|
57
|
-
/** @class */
|
|
58
|
-
function (_super) {
|
|
44
|
+
var Trigger = /** @class */function (_super) {
|
|
59
45
|
__extends(Trigger, _super);
|
|
60
|
-
|
|
61
46
|
function Trigger(props) {
|
|
62
47
|
var _this = _super.call(this, props) || this;
|
|
63
|
-
|
|
64
48
|
_this.prefixCls = 'ab-trigger';
|
|
65
49
|
_this.popupRef = /*#__PURE__*/React.createRef();
|
|
66
50
|
_this.maskRef = /*#__PURE__*/React.createRef();
|
|
67
51
|
_this.triggerRef = /*#__PURE__*/React.createRef();
|
|
68
|
-
|
|
69
52
|
_this.isClickToHide = function () {
|
|
70
53
|
return _this.props.trigger.indexOf('click') !== -1;
|
|
71
54
|
};
|
|
72
|
-
|
|
73
55
|
_this.clearPopupTimer = function (popupEl) {
|
|
74
56
|
clearTimeout(_this.popupTimer);
|
|
75
|
-
|
|
76
57
|
var element = popupEl || _this.getPopupDomNode();
|
|
77
|
-
|
|
78
58
|
if (element) {
|
|
79
59
|
element.style.visibility = '';
|
|
80
60
|
}
|
|
81
61
|
};
|
|
82
|
-
|
|
83
62
|
_this.forceAlign = function (popupEl) {
|
|
84
63
|
var rootEl = _this.getRootDomNode();
|
|
85
|
-
|
|
86
64
|
popupEl = popupEl || _this.getPopupDomNode();
|
|
87
|
-
|
|
88
65
|
if (!popupEl || !rootEl) {
|
|
89
66
|
return;
|
|
90
67
|
}
|
|
91
|
-
|
|
92
68
|
_this.clearPopupTimer(popupEl);
|
|
93
|
-
|
|
94
69
|
var _a = _this.props,
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
70
|
+
placement = _a.placement,
|
|
71
|
+
translateX = _a.translateX,
|
|
72
|
+
translateY = _a.translateY,
|
|
73
|
+
rootToPopupSpacing = _a.rootToPopupSpacing,
|
|
74
|
+
popupLimitSpacing = _a.popupLimitSpacing,
|
|
75
|
+
isTransformHorizontalDirection = _a.isTransformHorizontalDirection,
|
|
76
|
+
hiddenArrow = _a.hiddenArrow,
|
|
77
|
+
onArrowStyleChange = _a.onArrowStyleChange,
|
|
78
|
+
maxHeight = _a.maxHeight,
|
|
79
|
+
isMinRootWidth = _a.isMinRootWidth,
|
|
80
|
+
isMaxRootWidth = _a.isMaxRootWidth,
|
|
81
|
+
isInsertNode = _a.isInsertNode;
|
|
108
82
|
if (maxHeight) {
|
|
109
83
|
popupEl.style.maxHeight = "".concat(maxHeight, "px");
|
|
110
84
|
popupEl.style.overflowY = 'auto';
|
|
111
85
|
}
|
|
112
|
-
|
|
113
86
|
if (isMinRootWidth || isMaxRootWidth) {
|
|
114
87
|
var rootWidth = getElementSize(rootEl).width;
|
|
115
|
-
|
|
116
88
|
if (isMinRootWidth) {
|
|
117
89
|
popupEl.style.minWidth = "".concat(rootWidth, "px");
|
|
118
90
|
}
|
|
119
|
-
|
|
120
91
|
if (isMaxRootWidth) {
|
|
121
92
|
popupEl.style.maxWidth = "".concat(rootWidth, "px");
|
|
122
93
|
popupEl.style.overflowX = 'auto';
|
|
123
94
|
}
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
|
|
95
|
+
}
|
|
96
|
+
// 计算Popup元素应该显示的位置
|
|
127
97
|
var _b = getPopupLocation(placement, rootEl, popupEl, translateX, translateY, rootToPopupSpacing, popupLimitSpacing, isTransformHorizontalDirection, hiddenArrow, isInsertNode),
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
98
|
+
left = _b.left,
|
|
99
|
+
top = _b.top,
|
|
100
|
+
arrowStyle = _b.arrowStyle,
|
|
101
|
+
transformOrigin = _b.transformOrigin,
|
|
102
|
+
popupMaxWidthByCalc = _b.maxWidth,
|
|
103
|
+
popupMaxHeightByCalc = _b.maxHeight,
|
|
104
|
+
width = _b.width,
|
|
105
|
+
height = _b.height;
|
|
137
106
|
_this.prevPopupSize = {
|
|
138
107
|
width: width,
|
|
139
108
|
height: height
|
|
140
109
|
};
|
|
141
|
-
|
|
142
110
|
if (!hiddenArrow && onArrowStyleChange && JSON.stringify(arrowStyle) !== JSON.stringify(_this.prevArrowStyle)) {
|
|
143
111
|
_this.prevArrowStyle = arrowStyle;
|
|
144
112
|
onArrowStyleChange(arrowStyle);
|
|
145
113
|
}
|
|
146
|
-
|
|
147
114
|
popupEl.style.transformOrigin = transformOrigin;
|
|
148
115
|
popupEl.style.left = "".concat(left, "px");
|
|
149
116
|
popupEl.style.top = "".concat(top, "px");
|
|
150
|
-
|
|
151
117
|
if (popupMaxHeightByCalc) {
|
|
152
118
|
popupEl.style.maxHeight = "".concat(popupMaxWidthByCalc, "px");
|
|
153
119
|
}
|
|
154
|
-
|
|
155
120
|
if (popupMaxWidthByCalc) {
|
|
156
121
|
popupEl.style.maxWidth = "".concat(popupMaxWidthByCalc, "px");
|
|
157
122
|
popupEl.style.overflowX = 'auto';
|
|
@@ -159,89 +124,67 @@ function (_super) {
|
|
|
159
124
|
popupEl.style.maxWidth = '';
|
|
160
125
|
}
|
|
161
126
|
};
|
|
162
|
-
|
|
163
127
|
_this.getRootDomNode = function () {
|
|
164
128
|
var getCurrentDOMNode = _this.props.getCurrentDOMNode;
|
|
165
|
-
|
|
166
129
|
if (getCurrentDOMNode) {
|
|
167
130
|
return getCurrentDOMNode(_this.triggerRef.current);
|
|
168
131
|
}
|
|
169
|
-
|
|
170
132
|
try {
|
|
171
133
|
// 支持children是组件的情况, 穿透组件获取HTML元素
|
|
172
134
|
// eslint-disable-next-line react/no-find-dom-node
|
|
173
135
|
var domNode = findDOMNode(_this.triggerRef.current);
|
|
174
|
-
|
|
175
136
|
if (domNode) {
|
|
176
137
|
return domNode;
|
|
177
138
|
}
|
|
178
139
|
} catch (err) {}
|
|
179
|
-
|
|
180
140
|
return null;
|
|
181
141
|
};
|
|
182
142
|
/**
|
|
183
143
|
* 全局事件回调
|
|
184
144
|
* @param event
|
|
185
145
|
*/
|
|
186
|
-
|
|
187
|
-
|
|
188
146
|
_this.onDocumentClick = function (event) {
|
|
189
147
|
if (!_this.state.visible) {
|
|
190
148
|
return;
|
|
191
149
|
}
|
|
192
|
-
|
|
193
150
|
var target = event.target;
|
|
194
|
-
|
|
195
151
|
var root = _this.getRootDomNode();
|
|
196
|
-
|
|
197
152
|
var popupNode = _this.getPopupDomNode();
|
|
198
|
-
|
|
199
153
|
if (!root || !target || !popupNode) {
|
|
200
154
|
return;
|
|
201
155
|
}
|
|
202
|
-
|
|
203
156
|
var showMask = _this.props.showMask;
|
|
204
|
-
|
|
205
157
|
var maskEl = _this.getMaskDomNode();
|
|
206
|
-
|
|
207
158
|
if (showMask && !maskEl) {
|
|
208
159
|
return;
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
|
|
160
|
+
}
|
|
161
|
+
// 排除操作当前元素
|
|
212
162
|
if (!contains(root, target) && (!showMask || maskEl === target) && !contains(popupNode, target) && !_this.hasPopupMouseDown) {
|
|
213
163
|
_this.hidePopup();
|
|
214
164
|
}
|
|
215
165
|
};
|
|
216
|
-
|
|
217
166
|
_this.showPopup = function () {
|
|
218
167
|
_this.triggerPopup(true);
|
|
219
168
|
};
|
|
220
|
-
|
|
221
169
|
_this.hidePopup = function (ev) {
|
|
222
170
|
if (ev) {
|
|
223
171
|
ev.stopPropagation();
|
|
224
172
|
ev.nativeEvent.stopImmediatePropagation();
|
|
225
173
|
}
|
|
226
|
-
|
|
227
174
|
_this.triggerPopup(false);
|
|
228
175
|
};
|
|
229
|
-
|
|
230
176
|
_this.onVisibleChange = function (visible) {
|
|
231
177
|
var prevVisible = _this.state.visible;
|
|
232
178
|
clearTimeout(_this.delayTimer);
|
|
233
|
-
|
|
234
179
|
if (prevVisible !== visible) {
|
|
235
180
|
if (!_this.isOutsideControl()) {
|
|
236
181
|
_this.setState({
|
|
237
182
|
visible: visible
|
|
238
183
|
});
|
|
239
184
|
}
|
|
240
|
-
|
|
241
185
|
var _a = _this.props,
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
186
|
+
onVisibleChange = _a.onVisibleChange,
|
|
187
|
+
name_1 = _a.name;
|
|
245
188
|
if (onVisibleChange) {
|
|
246
189
|
onVisibleChange(visible, name_1);
|
|
247
190
|
}
|
|
@@ -251,21 +194,17 @@ function (_super) {
|
|
|
251
194
|
* 设置显示与隐藏
|
|
252
195
|
* @param nextVisible
|
|
253
196
|
*/
|
|
254
|
-
|
|
255
|
-
|
|
256
197
|
_this.triggerPopup = function (nextVisible) {
|
|
257
198
|
if (nextVisible) {
|
|
258
|
-
_this.hasPopupMouseDown = true;
|
|
259
|
-
|
|
199
|
+
_this.hasPopupMouseDown = true;
|
|
200
|
+
// 禁止执行全局监听,回调函数中的隐藏功能
|
|
260
201
|
clearTimeout(_this.mouseDownTimeout);
|
|
261
202
|
_this.mouseDownTimeout = setTimeout(function () {
|
|
262
203
|
_this.hasPopupMouseDown = false;
|
|
263
204
|
}, 0);
|
|
264
205
|
}
|
|
265
|
-
|
|
266
206
|
_this.onVisibleChange(nextVisible);
|
|
267
207
|
};
|
|
268
|
-
|
|
269
208
|
_this.onPopupMouseDown = function () {
|
|
270
209
|
_this.hasPopupMouseDown = true;
|
|
271
210
|
clearTimeout(_this.mouseDownTimeout);
|
|
@@ -273,59 +212,45 @@ function (_super) {
|
|
|
273
212
|
_this.hasPopupMouseDown = false;
|
|
274
213
|
}, 0);
|
|
275
214
|
};
|
|
276
|
-
|
|
277
215
|
_this.onClick = function (event) {
|
|
278
216
|
if (event && event.preventDefault) {
|
|
279
217
|
event.preventDefault();
|
|
280
218
|
}
|
|
281
|
-
|
|
282
219
|
var touch = isTouchScreen();
|
|
283
|
-
|
|
284
220
|
if (event.type === 'touchstart' && touch || event.type === 'mousedown' && !touch) {
|
|
285
221
|
_this.triggerPopup(!_this.state.visible);
|
|
286
222
|
}
|
|
287
223
|
};
|
|
288
|
-
|
|
289
224
|
_this.onMouseEnter = function () {
|
|
290
225
|
_this.delaySetPopupVisible(true, _this.props.mouseEnterDelay);
|
|
291
226
|
};
|
|
292
|
-
|
|
293
227
|
_this.onMouseLeave = function () {
|
|
294
228
|
_this.delaySetPopupVisible(false, _this.props.mouseLeaveDelay);
|
|
295
229
|
};
|
|
296
|
-
|
|
297
230
|
_this.onPopupMouseEnter = function () {
|
|
298
231
|
clearTimeout(_this.delayTimer);
|
|
299
232
|
};
|
|
300
|
-
|
|
301
233
|
_this.onPopupMouseLeave = function () {
|
|
302
234
|
_this.delaySetPopupVisible(false, _this.props.mouseLeaveDelay);
|
|
303
235
|
};
|
|
304
|
-
|
|
305
236
|
_this.onExited = function () {
|
|
306
237
|
_this.clearPopupTimer();
|
|
307
|
-
|
|
308
238
|
var onDestroy = _this.props.onDestroy;
|
|
309
|
-
|
|
310
239
|
if (onDestroy) {
|
|
311
240
|
onDestroy();
|
|
312
241
|
}
|
|
313
242
|
};
|
|
314
|
-
|
|
315
243
|
_this.isCurrentTrigger = function (eventName, trigger) {
|
|
316
244
|
return trigger.indexOf(eventName) !== -1;
|
|
317
245
|
};
|
|
318
|
-
|
|
319
246
|
_this.isOutsideControl = function () {
|
|
320
247
|
return 'visible' in _this.props;
|
|
321
248
|
};
|
|
322
|
-
|
|
323
249
|
_this.onPreventThrough = function (event) {
|
|
324
250
|
if (event && event.preventDefault) {
|
|
325
251
|
event.preventDefault();
|
|
326
252
|
}
|
|
327
253
|
};
|
|
328
|
-
|
|
329
254
|
_this.state = {
|
|
330
255
|
visible: false,
|
|
331
256
|
isUserOperated: false,
|
|
@@ -333,7 +258,6 @@ function (_super) {
|
|
|
333
258
|
};
|
|
334
259
|
return _this;
|
|
335
260
|
}
|
|
336
|
-
|
|
337
261
|
Trigger.getPopupInnerHeight = function (element) {
|
|
338
262
|
if (element.children && element.children.length) {
|
|
339
263
|
var height_1 = getStyleValue(element, 'padding-top') + getStyleValue(element, 'padding-bottom');
|
|
@@ -343,53 +267,40 @@ function (_super) {
|
|
|
343
267
|
});
|
|
344
268
|
return height_1;
|
|
345
269
|
}
|
|
346
|
-
|
|
347
270
|
return getElementSize(element).height;
|
|
348
271
|
};
|
|
349
|
-
|
|
350
272
|
Trigger.getDerivedStateFromProps = function (nextProps, preState) {
|
|
351
273
|
var nextState = {};
|
|
352
|
-
|
|
353
274
|
if ('visible' in nextProps) {
|
|
354
275
|
nextState.visible = nextProps.visible;
|
|
355
|
-
}
|
|
356
|
-
|
|
357
|
-
|
|
276
|
+
}
|
|
277
|
+
// 在触摸屏下, hover 事件转成click
|
|
358
278
|
if (nextProps.trigger === 'hover' && isTouchScreen()) {
|
|
359
279
|
nextState.trigger = 'click';
|
|
360
280
|
}
|
|
361
|
-
|
|
362
281
|
var isUserOperated = preState.isUserOperated || nextState.visible || preState.visible;
|
|
363
|
-
|
|
364
282
|
if (isUserOperated !== preState.isUserOperated) {
|
|
365
283
|
nextState.isUserOperated = isUserOperated;
|
|
366
284
|
}
|
|
367
|
-
|
|
368
285
|
if (isEmptyObject(nextState)) {
|
|
369
286
|
return null;
|
|
370
287
|
}
|
|
371
|
-
|
|
372
288
|
return nextState;
|
|
373
289
|
};
|
|
374
|
-
|
|
375
290
|
Trigger.prototype.componentDidMount = function () {
|
|
376
291
|
this.componentDidUpdate();
|
|
377
292
|
};
|
|
378
|
-
|
|
379
293
|
Trigger.prototype.componentDidUpdate = function () {
|
|
380
294
|
var _this = this;
|
|
381
|
-
|
|
382
295
|
var visible = this.state.visible;
|
|
383
|
-
|
|
384
296
|
if (!visible) {
|
|
385
297
|
// 其中参数是解决: 当同时多个trigger在同一个组件中,一个更新(一个使用visible)导致多个都发生componentDidUpdate
|
|
386
298
|
// 应该不让其他trigger 的delay事件销毁
|
|
387
299
|
this.clearOutsideHandler(true);
|
|
388
300
|
return;
|
|
389
301
|
}
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
302
|
+
var popupEl = this.getPopupDomNode();
|
|
303
|
+
// 加入 resize 监听
|
|
393
304
|
if (this.props.monitorWindowResize && !this.resizeHandler) {
|
|
394
305
|
var handle = this.props.windowResizeHidden ? throttleWithRAF(function () {
|
|
395
306
|
return _this.triggerPopup(false);
|
|
@@ -397,126 +308,99 @@ function (_super) {
|
|
|
397
308
|
return _this.forceAlign();
|
|
398
309
|
});
|
|
399
310
|
this.resizeHandler = addEventListener(window, 'resize', handle);
|
|
400
|
-
}
|
|
401
|
-
|
|
402
|
-
|
|
311
|
+
}
|
|
312
|
+
// 加入 scroll 监听
|
|
403
313
|
if (visible && this.props.scrollClosable && !this.scrollHandler) {
|
|
404
314
|
this.scrollHandler = addEventListener(window, 'scroll', function () {
|
|
405
315
|
if (_this.scrollHandler) {
|
|
406
316
|
_this.scrollHandler.remove();
|
|
407
|
-
|
|
408
317
|
_this.scrollHandler = null;
|
|
409
318
|
}
|
|
410
|
-
|
|
411
319
|
_this.triggerPopup(false);
|
|
412
320
|
});
|
|
413
|
-
}
|
|
414
|
-
|
|
415
|
-
|
|
321
|
+
}
|
|
322
|
+
// 需要监听 `mousedown` or `touchstart`, 而不是click
|
|
416
323
|
var currentDocument;
|
|
417
324
|
var touch = isTouchScreen();
|
|
418
|
-
|
|
419
325
|
if (!this.clickOutsideHandler && !touch && this.isClickToHide()) {
|
|
420
326
|
currentDocument = window.document;
|
|
421
327
|
this.clickOutsideHandler = addEventListener(currentDocument, 'mousedown', this.onDocumentClick);
|
|
422
|
-
}
|
|
423
|
-
|
|
424
|
-
|
|
328
|
+
}
|
|
329
|
+
// always hide on mobile
|
|
425
330
|
if (!this.touchOutsideHandler) {
|
|
426
331
|
currentDocument = currentDocument || window.document;
|
|
427
332
|
this.touchOutsideHandler = addEventListener(currentDocument, 'touchstart', this.onDocumentClick);
|
|
428
333
|
}
|
|
429
|
-
|
|
430
334
|
if (popupEl && this.prevPopupSize) {
|
|
431
335
|
var _a = getElementSize(popupEl),
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
336
|
+
width = _a.width,
|
|
337
|
+
height = _a.height;
|
|
435
338
|
if (this.prevPopupSize.width !== width || this.prevPopupSize.height !== height) {
|
|
436
339
|
this.clearPopupTimer(popupEl);
|
|
437
340
|
popupEl.style.visibility = 'hidden';
|
|
438
341
|
this.popupTimer = setTimeout(function () {
|
|
439
342
|
_this.forceAlign(popupEl);
|
|
440
|
-
|
|
441
343
|
popupEl.style.visibility = '';
|
|
442
344
|
});
|
|
443
345
|
}
|
|
444
346
|
}
|
|
445
347
|
};
|
|
446
|
-
|
|
447
348
|
Trigger.prototype.componentWillUnmount = function () {
|
|
448
349
|
// remove绑定事件
|
|
449
350
|
this.clearOutsideHandler();
|
|
450
351
|
};
|
|
451
|
-
|
|
452
352
|
Trigger.prototype.getPopupDomNode = function () {
|
|
453
353
|
if (this.popupRef && this.popupRef.current) {
|
|
454
354
|
return this.popupRef.current;
|
|
455
355
|
}
|
|
456
|
-
|
|
457
356
|
return null;
|
|
458
357
|
};
|
|
459
|
-
|
|
460
358
|
Trigger.prototype.getMaskDomNode = function () {
|
|
461
359
|
if (this.maskRef && this.maskRef.current) {
|
|
462
360
|
return this.maskRef.current;
|
|
463
361
|
}
|
|
464
|
-
|
|
465
362
|
return null;
|
|
466
363
|
};
|
|
467
|
-
|
|
468
364
|
Trigger.prototype.clearOutsideHandler = function (ignoreDelayTimer) {
|
|
469
365
|
// clearTimeout(this.mouseDownTimeout);
|
|
470
366
|
if (!ignoreDelayTimer) {
|
|
471
367
|
clearTimeout(this.delayTimer);
|
|
472
368
|
}
|
|
473
|
-
|
|
474
369
|
this.clearPopupTimer();
|
|
475
|
-
|
|
476
370
|
if (this.resizeHandler) {
|
|
477
371
|
this.resizeHandler.remove();
|
|
478
372
|
this.resizeHandler = null;
|
|
479
373
|
}
|
|
480
|
-
|
|
481
374
|
if (this.scrollHandler) {
|
|
482
375
|
this.scrollHandler.remove();
|
|
483
376
|
this.scrollHandler = null;
|
|
484
377
|
}
|
|
485
|
-
|
|
486
378
|
if (this.clickOutsideHandler) {
|
|
487
379
|
this.clickOutsideHandler.remove();
|
|
488
380
|
this.clickOutsideHandler = null;
|
|
489
381
|
}
|
|
490
|
-
|
|
491
382
|
if (this.touchOutsideHandler) {
|
|
492
383
|
this.touchOutsideHandler.remove();
|
|
493
384
|
this.touchOutsideHandler = null;
|
|
494
385
|
}
|
|
495
386
|
};
|
|
496
|
-
|
|
497
387
|
Trigger.prototype.delaySetPopupVisible = function (visible, delayTime) {
|
|
498
388
|
var _this = this;
|
|
499
|
-
|
|
500
389
|
clearTimeout(this.delayTimer);
|
|
501
|
-
|
|
502
390
|
if (delayTime) {
|
|
503
391
|
var delay = delayTime * 1000;
|
|
504
392
|
this.delayTimer = setTimeout(function () {
|
|
505
393
|
_this.triggerPopup(visible);
|
|
506
|
-
|
|
507
394
|
clearTimeout(_this.delayTimer);
|
|
508
395
|
}, delay);
|
|
509
396
|
} else {
|
|
510
397
|
this.triggerPopup(visible);
|
|
511
398
|
}
|
|
512
399
|
};
|
|
513
|
-
|
|
514
400
|
Trigger.prototype.renderMask = function () {
|
|
515
401
|
var _a;
|
|
516
|
-
|
|
517
402
|
var visible = this.state.visible;
|
|
518
403
|
var showMask = this.props.showMask;
|
|
519
|
-
|
|
520
404
|
if (showMask) {
|
|
521
405
|
var cls = this.prefixCls;
|
|
522
406
|
return /*#__PURE__*/React.createElement("div", {
|
|
@@ -525,32 +409,27 @@ function (_super) {
|
|
|
525
409
|
onTouchEnd: this.onPreventThrough
|
|
526
410
|
});
|
|
527
411
|
}
|
|
528
|
-
|
|
529
412
|
return null;
|
|
530
413
|
};
|
|
531
|
-
|
|
532
414
|
Trigger.prototype.renderPopupContent = function () {
|
|
533
415
|
var _a;
|
|
534
|
-
|
|
535
416
|
var cls = this.prefixCls;
|
|
536
417
|
var _b = this.props,
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
418
|
+
popup = _b.popup,
|
|
419
|
+
wrapClassName = _b.wrapClassName,
|
|
420
|
+
isTransformHorizontalDirection = _b.isTransformHorizontalDirection,
|
|
421
|
+
isInsertNode = _b.isInsertNode;
|
|
541
422
|
var _c = this.state,
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
var wrapClass = classNames("".concat(cls, "-wrap"), wrapClassName, (_a = {}, _a["".concat(cls, "-hidden")] = isInsertNode && !isUserOperated && !visible, _a));
|
|
546
|
-
|
|
423
|
+
visible = _c.visible,
|
|
424
|
+
isUserOperated = _c.isUserOperated,
|
|
425
|
+
trigger = _c.trigger;
|
|
426
|
+
var wrapClass = classNames("".concat(cls, "-wrap"), wrapClassName, (_a = {}, _a["".concat(cls, "-hidden")] = isInsertNode && !isUserOperated && !visible, _a));
|
|
427
|
+
// hover 下,对popup增加相应的事件,延迟隐藏,可以在弹框中停留
|
|
547
428
|
var mouseProps = {};
|
|
548
|
-
|
|
549
429
|
if (this.isCurrentTrigger('hover', trigger)) {
|
|
550
430
|
mouseProps.onMouseEnter = this.onPopupMouseEnter;
|
|
551
431
|
mouseProps.onMouseLeave = this.onPopupMouseLeave;
|
|
552
432
|
}
|
|
553
|
-
|
|
554
433
|
mouseProps.onMouseDown = this.onPopupMouseDown;
|
|
555
434
|
mouseProps.onTouchStart = this.onPopupMouseDown;
|
|
556
435
|
return /*#__PURE__*/React.createElement(CSSTransition, {
|
|
@@ -568,8 +447,6 @@ function (_super) {
|
|
|
568
447
|
/**
|
|
569
448
|
* 扩充children属性,根据trigger绑定不同事件
|
|
570
449
|
*/
|
|
571
|
-
|
|
572
|
-
|
|
573
450
|
Trigger.prototype.renderChildComponent = function () {
|
|
574
451
|
var children = this.props.children;
|
|
575
452
|
var trigger = this.state.trigger;
|
|
@@ -577,50 +454,39 @@ function (_super) {
|
|
|
577
454
|
var newChildProps = {
|
|
578
455
|
key: 'trigger'
|
|
579
456
|
};
|
|
580
|
-
|
|
581
457
|
if (this.isCurrentTrigger('hover', trigger) && this.props.trigger === trigger) {
|
|
582
458
|
newChildProps.onMouseEnter = this.onMouseEnter;
|
|
583
459
|
newChildProps.onMouseLeave = this.onMouseLeave;
|
|
584
460
|
}
|
|
585
|
-
|
|
586
461
|
if (!this.isOutsideControl() || this.props.trigger !== trigger) {
|
|
587
462
|
if (this.isCurrentTrigger('click', trigger)) {
|
|
588
463
|
newChildProps.onMouseDown = this.onClick;
|
|
589
464
|
newChildProps.onTouchStart = this.onClick;
|
|
590
465
|
}
|
|
591
|
-
|
|
592
466
|
if (this.isCurrentTrigger('focus', trigger)) {
|
|
593
467
|
newChildProps.onFocus = this.showPopup;
|
|
594
468
|
newChildProps.onBlur = this.hidePopup;
|
|
595
469
|
}
|
|
596
470
|
}
|
|
597
|
-
|
|
598
471
|
var cloneProps = __assign({}, newChildProps);
|
|
599
|
-
|
|
600
472
|
if (supportRef(child)) {
|
|
601
473
|
cloneProps.ref = composeRef(this.triggerRef, child.ref);
|
|
602
|
-
}
|
|
603
|
-
|
|
604
|
-
|
|
474
|
+
}
|
|
475
|
+
// 对当前children元素添加额外属性
|
|
605
476
|
return /*#__PURE__*/React.cloneElement(child, cloneProps);
|
|
606
477
|
};
|
|
607
|
-
|
|
608
478
|
Trigger.prototype.renderPopupComponent = function () {
|
|
609
479
|
if (this.props.isInsertNode) {
|
|
610
480
|
return /*#__PURE__*/React.createElement(React.Fragment, null, this.renderMask(), this.renderPopupContent());
|
|
611
481
|
}
|
|
612
|
-
|
|
613
482
|
if (this.state.visible || this.popupRef.current) {
|
|
614
483
|
return /*#__PURE__*/React.createElement(Portal, null, /*#__PURE__*/React.createElement(React.Fragment, null, this.renderMask(), this.renderPopupContent()));
|
|
615
484
|
}
|
|
616
|
-
|
|
617
485
|
return null;
|
|
618
486
|
};
|
|
619
|
-
|
|
620
487
|
Trigger.prototype.render = function () {
|
|
621
488
|
return /*#__PURE__*/React.createElement(React.Fragment, null, this.renderChildComponent(), this.renderPopupComponent());
|
|
622
489
|
};
|
|
623
|
-
|
|
624
490
|
Trigger.defaultProps = {
|
|
625
491
|
placement: 'Top',
|
|
626
492
|
trigger: 'hover',
|
|
@@ -644,5 +510,4 @@ function (_super) {
|
|
|
644
510
|
};
|
|
645
511
|
return Trigger;
|
|
646
512
|
}(React.Component);
|
|
647
|
-
|
|
648
513
|
export default Trigger;
|