@rc-component/trigger 1.0.1 → 1.0.2
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/es/Popup/index.d.ts +1 -0
- package/es/Popup/index.js +1 -1
- package/es/index.d.ts +3 -2
- package/es/index.js +397 -391
- package/es/mock.d.ts +3 -0
- package/es/mock.js +11 -0
- package/lib/Popup/index.d.ts +1 -0
- package/lib/Popup/index.js +2 -2
- package/lib/index.d.ts +3 -2
- package/lib/index.js +398 -391
- package/lib/mock.d.ts +3 -0
- package/lib/mock.js +19 -0
- package/package.json +2 -2
package/lib/index.js
CHANGED
|
@@ -6,9 +6,11 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
value: true
|
|
7
7
|
});
|
|
8
8
|
exports.default = void 0;
|
|
9
|
+
exports.generateTrigger = generateTrigger;
|
|
9
10
|
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
10
11
|
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
11
12
|
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
|
|
13
|
+
var _portal = _interopRequireDefault(require("@rc-component/portal"));
|
|
12
14
|
var _classnames = _interopRequireDefault(require("classnames"));
|
|
13
15
|
var _rcResizeObserver = _interopRequireDefault(require("rc-resize-observer"));
|
|
14
16
|
var _useEvent = _interopRequireDefault(require("rc-util/lib/hooks/useEvent"));
|
|
@@ -24,435 +26,440 @@ var _Popup = _interopRequireDefault(require("./Popup"));
|
|
|
24
26
|
var _TriggerWrapper = _interopRequireDefault(require("./TriggerWrapper"));
|
|
25
27
|
var _util = require("./util");
|
|
26
28
|
var _excluded = ["prefixCls", "children", "action", "showAction", "hideAction", "popupVisible", "defaultPopupVisible", "onPopupVisibleChange", "afterPopupVisibleChange", "mouseEnterDelay", "mouseLeaveDelay", "focusDelay", "blurDelay", "mask", "maskClosable", "getPopupContainer", "forceRender", "autoDestroy", "destroyPopupOnHide", "popup", "popupClassName", "popupStyle", "popupPlacement", "builtinPlacements", "popupAlign", "zIndex", "stretch", "getPopupClassNameFromAlign", "alignPoint", "onPopupClick", "onPopupAlign", "arrow", "popupMotion", "maskMotion", "popupTransitionName", "popupAnimation", "maskTransitionName", "maskAnimation", "className", "getTriggerDOMNode"];
|
|
27
|
-
|
|
28
|
-
var
|
|
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
|
-
|
|
29
|
+
function generateTrigger() {
|
|
30
|
+
var PortalComponent = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : _portal.default;
|
|
31
|
+
var Trigger = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
32
|
+
var _props$prefixCls = props.prefixCls,
|
|
33
|
+
prefixCls = _props$prefixCls === void 0 ? 'rc-trigger-popup' : _props$prefixCls,
|
|
34
|
+
children = props.children,
|
|
35
|
+
_props$action = props.action,
|
|
36
|
+
action = _props$action === void 0 ? 'hover' : _props$action,
|
|
37
|
+
showAction = props.showAction,
|
|
38
|
+
hideAction = props.hideAction,
|
|
39
|
+
popupVisible = props.popupVisible,
|
|
40
|
+
defaultPopupVisible = props.defaultPopupVisible,
|
|
41
|
+
onPopupVisibleChange = props.onPopupVisibleChange,
|
|
42
|
+
afterPopupVisibleChange = props.afterPopupVisibleChange,
|
|
43
|
+
mouseEnterDelay = props.mouseEnterDelay,
|
|
44
|
+
_props$mouseLeaveDela = props.mouseLeaveDelay,
|
|
45
|
+
mouseLeaveDelay = _props$mouseLeaveDela === void 0 ? 0.1 : _props$mouseLeaveDela,
|
|
46
|
+
focusDelay = props.focusDelay,
|
|
47
|
+
blurDelay = props.blurDelay,
|
|
48
|
+
mask = props.mask,
|
|
49
|
+
_props$maskClosable = props.maskClosable,
|
|
50
|
+
maskClosable = _props$maskClosable === void 0 ? true : _props$maskClosable,
|
|
51
|
+
getPopupContainer = props.getPopupContainer,
|
|
52
|
+
forceRender = props.forceRender,
|
|
53
|
+
autoDestroy = props.autoDestroy,
|
|
54
|
+
destroyPopupOnHide = props.destroyPopupOnHide,
|
|
55
|
+
popup = props.popup,
|
|
56
|
+
popupClassName = props.popupClassName,
|
|
57
|
+
popupStyle = props.popupStyle,
|
|
58
|
+
popupPlacement = props.popupPlacement,
|
|
59
|
+
_props$builtinPlaceme = props.builtinPlacements,
|
|
60
|
+
builtinPlacements = _props$builtinPlaceme === void 0 ? {} : _props$builtinPlaceme,
|
|
61
|
+
popupAlign = props.popupAlign,
|
|
62
|
+
zIndex = props.zIndex,
|
|
63
|
+
stretch = props.stretch,
|
|
64
|
+
getPopupClassNameFromAlign = props.getPopupClassNameFromAlign,
|
|
65
|
+
alignPoint = props.alignPoint,
|
|
66
|
+
onPopupClick = props.onPopupClick,
|
|
67
|
+
onPopupAlign = props.onPopupAlign,
|
|
68
|
+
arrow = props.arrow,
|
|
69
|
+
popupMotion = props.popupMotion,
|
|
70
|
+
maskMotion = props.maskMotion,
|
|
71
|
+
popupTransitionName = props.popupTransitionName,
|
|
72
|
+
popupAnimation = props.popupAnimation,
|
|
73
|
+
maskTransitionName = props.maskTransitionName,
|
|
74
|
+
maskAnimation = props.maskAnimation,
|
|
75
|
+
className = props.className,
|
|
76
|
+
getTriggerDOMNode = props.getTriggerDOMNode,
|
|
77
|
+
restProps = (0, _objectWithoutProperties2.default)(props, _excluded);
|
|
78
|
+
var mergedAutoDestroy = autoDestroy || destroyPopupOnHide || false;
|
|
75
79
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
80
|
+
// ========================== Context ===========================
|
|
81
|
+
var subPopupElements = React.useRef({});
|
|
82
|
+
var parentContext = React.useContext(_context.default);
|
|
83
|
+
var context = React.useMemo(function () {
|
|
84
|
+
return {
|
|
85
|
+
registerSubPopup: function registerSubPopup(id, subPopupEle) {
|
|
86
|
+
subPopupElements.current[id] = subPopupEle;
|
|
87
|
+
parentContext === null || parentContext === void 0 ? void 0 : parentContext.registerSubPopup(id, subPopupEle);
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
}, [parentContext]);
|
|
87
91
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
92
|
+
// =========================== Popup ============================
|
|
93
|
+
var id = (0, _useId.default)();
|
|
94
|
+
var _React$useState = React.useState(null),
|
|
95
|
+
_React$useState2 = (0, _slicedToArray2.default)(_React$useState, 2),
|
|
96
|
+
popupEle = _React$useState2[0],
|
|
97
|
+
setPopupEle = _React$useState2[1];
|
|
98
|
+
var setPopupRef = React.useCallback(function (node) {
|
|
99
|
+
if (node instanceof HTMLElement) {
|
|
100
|
+
setPopupEle(node);
|
|
101
|
+
}
|
|
102
|
+
parentContext === null || parentContext === void 0 ? void 0 : parentContext.registerSubPopup(id, node);
|
|
103
|
+
}, []);
|
|
100
104
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
105
|
+
// =========================== Target ===========================
|
|
106
|
+
// Use state to control here since `useRef` update not trigger render
|
|
107
|
+
var _React$useState3 = React.useState(null),
|
|
108
|
+
_React$useState4 = (0, _slicedToArray2.default)(_React$useState3, 2),
|
|
109
|
+
targetEle = _React$useState4[0],
|
|
110
|
+
setTargetEle = _React$useState4[1];
|
|
111
|
+
var setTargetRef = React.useCallback(function (node) {
|
|
112
|
+
if (node instanceof HTMLElement) {
|
|
113
|
+
setTargetEle(node);
|
|
114
|
+
}
|
|
115
|
+
}, []);
|
|
112
116
|
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
117
|
+
// ========================== Children ==========================
|
|
118
|
+
var child = React.Children.only(children);
|
|
119
|
+
var originChildProps = (child === null || child === void 0 ? void 0 : child.props) || {};
|
|
120
|
+
var cloneProps = {};
|
|
121
|
+
var inPopupOrChild = (0, _useEvent.default)(function (ele) {
|
|
122
|
+
var childDOM = targetEle;
|
|
123
|
+
return (childDOM === null || childDOM === void 0 ? void 0 : childDOM.contains(ele)) || ele === childDOM || (popupEle === null || popupEle === void 0 ? void 0 : popupEle.contains(ele)) || ele === popupEle || Object.values(subPopupElements.current).some(function (subPopupEle) {
|
|
124
|
+
return subPopupEle.contains(ele) || ele === subPopupEle;
|
|
125
|
+
});
|
|
121
126
|
});
|
|
122
|
-
});
|
|
123
127
|
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
128
|
+
// =========================== Motion ===========================
|
|
129
|
+
var mergePopupMotion = (0, _util.getMotion)(prefixCls, popupMotion, popupAnimation, popupTransitionName);
|
|
130
|
+
var mergeMaskMotion = (0, _util.getMotion)(prefixCls, maskMotion, maskAnimation, maskTransitionName);
|
|
127
131
|
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
132
|
+
// ============================ Open ============================
|
|
133
|
+
var _useMergedState = (0, _useMergedState3.default)(defaultPopupVisible || false, {
|
|
134
|
+
value: popupVisible
|
|
135
|
+
}),
|
|
136
|
+
_useMergedState2 = (0, _slicedToArray2.default)(_useMergedState, 2),
|
|
137
|
+
mergedOpen = _useMergedState2[0],
|
|
138
|
+
setMergedOpen = _useMergedState2[1];
|
|
139
|
+
var openRef = React.useRef(mergedOpen);
|
|
140
|
+
openRef.current = mergedOpen;
|
|
141
|
+
var internalTriggerOpen = (0, _useEvent.default)(function (nextOpen) {
|
|
142
|
+
if (mergedOpen !== nextOpen) {
|
|
143
|
+
setMergedOpen(nextOpen);
|
|
144
|
+
onPopupVisibleChange === null || onPopupVisibleChange === void 0 ? void 0 : onPopupVisibleChange(nextOpen);
|
|
145
|
+
}
|
|
146
|
+
});
|
|
143
147
|
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
internalTriggerOpen(nextOpen);
|
|
154
|
-
} else {
|
|
155
|
-
delayRef.current = setTimeout(function () {
|
|
148
|
+
// Trigger for delay
|
|
149
|
+
var delayRef = React.useRef();
|
|
150
|
+
var clearDelay = function clearDelay() {
|
|
151
|
+
clearTimeout(delayRef.current);
|
|
152
|
+
};
|
|
153
|
+
var triggerOpen = function triggerOpen(nextOpen) {
|
|
154
|
+
var delay = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
|
|
155
|
+
clearDelay();
|
|
156
|
+
if (delay === 0) {
|
|
156
157
|
internalTriggerOpen(nextOpen);
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
}, []);
|
|
163
|
-
|
|
164
|
-
// ========================== Motion ============================
|
|
165
|
-
var _React$useState5 = React.useState(false),
|
|
166
|
-
_React$useState6 = (0, _slicedToArray2.default)(_React$useState5, 2),
|
|
167
|
-
inMotion = _React$useState6[0],
|
|
168
|
-
setInMotion = _React$useState6[1];
|
|
169
|
-
(0, _useLayoutEffect.default)(function () {
|
|
170
|
-
setInMotion(true);
|
|
171
|
-
}, [mergedOpen]);
|
|
172
|
-
var _React$useState7 = React.useState(null),
|
|
173
|
-
_React$useState8 = (0, _slicedToArray2.default)(_React$useState7, 2),
|
|
174
|
-
motionPrepareResolve = _React$useState8[0],
|
|
175
|
-
setMotionPrepareResolve = _React$useState8[1];
|
|
176
|
-
|
|
177
|
-
// =========================== Align ============================
|
|
178
|
-
var _React$useState9 = React.useState([0, 0]),
|
|
179
|
-
_React$useState10 = (0, _slicedToArray2.default)(_React$useState9, 2),
|
|
180
|
-
mousePos = _React$useState10[0],
|
|
181
|
-
setMousePos = _React$useState10[1];
|
|
182
|
-
var setMousePosByEvent = function setMousePosByEvent(event) {
|
|
183
|
-
setMousePos([event.clientX, event.clientY]);
|
|
184
|
-
};
|
|
185
|
-
var _useAlign = (0, _useAlign3.default)(mergedOpen, popupEle, alignPoint ? mousePos : targetEle, popupPlacement, builtinPlacements, popupAlign, onPopupAlign),
|
|
186
|
-
_useAlign2 = (0, _slicedToArray2.default)(_useAlign, 9),
|
|
187
|
-
ready = _useAlign2[0],
|
|
188
|
-
offsetX = _useAlign2[1],
|
|
189
|
-
offsetY = _useAlign2[2],
|
|
190
|
-
arrowX = _useAlign2[3],
|
|
191
|
-
arrowY = _useAlign2[4],
|
|
192
|
-
scaleX = _useAlign2[5],
|
|
193
|
-
scaleY = _useAlign2[6],
|
|
194
|
-
alignInfo = _useAlign2[7],
|
|
195
|
-
onAlign = _useAlign2[8];
|
|
196
|
-
var triggerAlign = (0, _useEvent.default)(function () {
|
|
197
|
-
if (!inMotion) {
|
|
198
|
-
onAlign();
|
|
199
|
-
}
|
|
200
|
-
});
|
|
201
|
-
(0, _useWatch.default)(mergedOpen, targetEle, popupEle, triggerAlign);
|
|
202
|
-
(0, _useLayoutEffect.default)(function () {
|
|
203
|
-
triggerAlign();
|
|
204
|
-
}, [mousePos]);
|
|
205
|
-
var alignedClassName = React.useMemo(function () {
|
|
206
|
-
var baseClassName = (0, _util.getAlignPopupClassName)(builtinPlacements, prefixCls, alignInfo, alignPoint);
|
|
207
|
-
return (0, _classnames.default)(baseClassName, getPopupClassNameFromAlign === null || getPopupClassNameFromAlign === void 0 ? void 0 : getPopupClassNameFromAlign(alignInfo));
|
|
208
|
-
}, [alignInfo, getPopupClassNameFromAlign, builtinPlacements, prefixCls, alignPoint]);
|
|
209
|
-
React.useImperativeHandle(ref, function () {
|
|
210
|
-
return {
|
|
211
|
-
forceAlign: triggerAlign
|
|
158
|
+
} else {
|
|
159
|
+
delayRef.current = setTimeout(function () {
|
|
160
|
+
internalTriggerOpen(nextOpen);
|
|
161
|
+
}, delay * 1000);
|
|
162
|
+
}
|
|
212
163
|
};
|
|
213
|
-
|
|
164
|
+
React.useEffect(function () {
|
|
165
|
+
return clearDelay;
|
|
166
|
+
}, []);
|
|
214
167
|
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
168
|
+
// ========================== Motion ============================
|
|
169
|
+
var _React$useState5 = React.useState(false),
|
|
170
|
+
_React$useState6 = (0, _slicedToArray2.default)(_React$useState5, 2),
|
|
171
|
+
inMotion = _React$useState6[0],
|
|
172
|
+
setInMotion = _React$useState6[1];
|
|
173
|
+
(0, _useLayoutEffect.default)(function () {
|
|
174
|
+
setInMotion(true);
|
|
175
|
+
}, [mergedOpen]);
|
|
176
|
+
var _React$useState7 = React.useState(null),
|
|
177
|
+
_React$useState8 = (0, _slicedToArray2.default)(_React$useState7, 2),
|
|
178
|
+
motionPrepareResolve = _React$useState8[0],
|
|
179
|
+
setMotionPrepareResolve = _React$useState8[1];
|
|
221
180
|
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
181
|
+
// =========================== Align ============================
|
|
182
|
+
var _React$useState9 = React.useState([0, 0]),
|
|
183
|
+
_React$useState10 = (0, _slicedToArray2.default)(_React$useState9, 2),
|
|
184
|
+
mousePos = _React$useState10[0],
|
|
185
|
+
setMousePos = _React$useState10[1];
|
|
186
|
+
var setMousePosByEvent = function setMousePosByEvent(event) {
|
|
187
|
+
setMousePos([event.clientX, event.clientY]);
|
|
188
|
+
};
|
|
189
|
+
var _useAlign = (0, _useAlign3.default)(mergedOpen, popupEle, alignPoint ? mousePos : targetEle, popupPlacement, builtinPlacements, popupAlign, onPopupAlign),
|
|
190
|
+
_useAlign2 = (0, _slicedToArray2.default)(_useAlign, 9),
|
|
191
|
+
ready = _useAlign2[0],
|
|
192
|
+
offsetX = _useAlign2[1],
|
|
193
|
+
offsetY = _useAlign2[2],
|
|
194
|
+
arrowX = _useAlign2[3],
|
|
195
|
+
arrowY = _useAlign2[4],
|
|
196
|
+
scaleX = _useAlign2[5],
|
|
197
|
+
scaleY = _useAlign2[6],
|
|
198
|
+
alignInfo = _useAlign2[7],
|
|
199
|
+
onAlign = _useAlign2[8];
|
|
200
|
+
var triggerAlign = (0, _useEvent.default)(function () {
|
|
201
|
+
if (!inMotion) {
|
|
202
|
+
onAlign();
|
|
203
|
+
}
|
|
204
|
+
});
|
|
205
|
+
(0, _useWatch.default)(mergedOpen, targetEle, popupEle, triggerAlign);
|
|
206
|
+
(0, _useLayoutEffect.default)(function () {
|
|
207
|
+
triggerAlign();
|
|
208
|
+
}, [mousePos]);
|
|
209
|
+
var alignedClassName = React.useMemo(function () {
|
|
210
|
+
var baseClassName = (0, _util.getAlignPopupClassName)(builtinPlacements, prefixCls, alignInfo, alignPoint);
|
|
211
|
+
return (0, _classnames.default)(baseClassName, getPopupClassNameFromAlign === null || getPopupClassNameFromAlign === void 0 ? void 0 : getPopupClassNameFromAlign(alignInfo));
|
|
212
|
+
}, [alignInfo, getPopupClassNameFromAlign, builtinPlacements, prefixCls, alignPoint]);
|
|
213
|
+
React.useImperativeHandle(ref, function () {
|
|
214
|
+
return {
|
|
215
|
+
forceAlign: triggerAlign
|
|
216
|
+
};
|
|
228
217
|
});
|
|
229
|
-
};
|
|
230
|
-
(0, _useLayoutEffect.default)(function () {
|
|
231
|
-
if (motionPrepareResolve) {
|
|
232
|
-
onAlign();
|
|
233
|
-
motionPrepareResolve();
|
|
234
|
-
setMotionPrepareResolve(null);
|
|
235
|
-
}
|
|
236
|
-
}, [motionPrepareResolve]);
|
|
237
|
-
|
|
238
|
-
// ========================== Stretch ===========================
|
|
239
|
-
var _React$useState11 = React.useState(0),
|
|
240
|
-
_React$useState12 = (0, _slicedToArray2.default)(_React$useState11, 2),
|
|
241
|
-
targetWidth = _React$useState12[0],
|
|
242
|
-
setTargetWidth = _React$useState12[1];
|
|
243
|
-
var _React$useState13 = React.useState(0),
|
|
244
|
-
_React$useState14 = (0, _slicedToArray2.default)(_React$useState13, 2),
|
|
245
|
-
targetHeight = _React$useState14[0],
|
|
246
|
-
setTargetHeight = _React$useState14[1];
|
|
247
|
-
var onTargetResize = function onTargetResize(_, ele) {
|
|
248
|
-
triggerAlign();
|
|
249
|
-
if (stretch) {
|
|
250
|
-
var rect = ele.getBoundingClientRect();
|
|
251
|
-
setTargetWidth(rect.width);
|
|
252
|
-
setTargetHeight(rect.height);
|
|
253
|
-
}
|
|
254
|
-
};
|
|
255
|
-
|
|
256
|
-
// =========================== Action ===========================
|
|
257
|
-
var _useAction = (0, _useAction3.default)(action, showAction, hideAction),
|
|
258
|
-
_useAction2 = (0, _slicedToArray2.default)(_useAction, 2),
|
|
259
|
-
showActions = _useAction2[0],
|
|
260
|
-
hideActions = _useAction2[1];
|
|
261
|
-
|
|
262
|
-
// Util wrapper for trigger action
|
|
263
|
-
var wrapperAction = function wrapperAction(eventName, nextOpen, delay, preEvent) {
|
|
264
|
-
cloneProps[eventName] = function (event) {
|
|
265
|
-
var _originChildProps$eve;
|
|
266
|
-
preEvent === null || preEvent === void 0 ? void 0 : preEvent(event);
|
|
267
|
-
triggerOpen(nextOpen, delay);
|
|
268
218
|
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
219
|
+
// ========================== Motion ============================
|
|
220
|
+
var onVisibleChanged = function onVisibleChanged(visible) {
|
|
221
|
+
setInMotion(false);
|
|
222
|
+
onAlign();
|
|
223
|
+
afterPopupVisibleChange === null || afterPopupVisibleChange === void 0 ? void 0 : afterPopupVisibleChange(visible);
|
|
274
224
|
};
|
|
275
|
-
};
|
|
276
225
|
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
226
|
+
// We will trigger align when motion is in prepare
|
|
227
|
+
var onPrepare = function onPrepare() {
|
|
228
|
+
return new Promise(function (resolve) {
|
|
229
|
+
setMotionPrepareResolve(function () {
|
|
230
|
+
return resolve;
|
|
231
|
+
});
|
|
232
|
+
});
|
|
233
|
+
};
|
|
234
|
+
(0, _useLayoutEffect.default)(function () {
|
|
235
|
+
if (motionPrepareResolve) {
|
|
236
|
+
onAlign();
|
|
237
|
+
motionPrepareResolve();
|
|
238
|
+
setMotionPrepareResolve(null);
|
|
288
239
|
}
|
|
240
|
+
}, [motionPrepareResolve]);
|
|
289
241
|
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
242
|
+
// ========================== Stretch ===========================
|
|
243
|
+
var _React$useState11 = React.useState(0),
|
|
244
|
+
_React$useState12 = (0, _slicedToArray2.default)(_React$useState11, 2),
|
|
245
|
+
targetWidth = _React$useState12[0],
|
|
246
|
+
setTargetWidth = _React$useState12[1];
|
|
247
|
+
var _React$useState13 = React.useState(0),
|
|
248
|
+
_React$useState14 = (0, _slicedToArray2.default)(_React$useState13, 2),
|
|
249
|
+
targetHeight = _React$useState14[0],
|
|
250
|
+
setTargetHeight = _React$useState14[1];
|
|
251
|
+
var onTargetResize = function onTargetResize(_, ele) {
|
|
252
|
+
triggerAlign();
|
|
253
|
+
if (stretch) {
|
|
254
|
+
var rect = ele.getBoundingClientRect();
|
|
255
|
+
setTargetWidth(rect.width);
|
|
256
|
+
setTargetHeight(rect.height);
|
|
293
257
|
}
|
|
294
|
-
(_originChildProps$onC = originChildProps.onClick) === null || _originChildProps$onC === void 0 ? void 0 : _originChildProps$onC.call.apply(_originChildProps$onC, [originChildProps, event].concat(args));
|
|
295
258
|
};
|
|
296
|
-
}
|
|
297
259
|
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
260
|
+
// =========================== Action ===========================
|
|
261
|
+
var _useAction = (0, _useAction3.default)(action, showAction, hideAction),
|
|
262
|
+
_useAction2 = (0, _slicedToArray2.default)(_useAction, 2),
|
|
263
|
+
showActions = _useAction2[0],
|
|
264
|
+
hideActions = _useAction2[1];
|
|
265
|
+
|
|
266
|
+
// Util wrapper for trigger action
|
|
267
|
+
var wrapperAction = function wrapperAction(eventName, nextOpen, delay, preEvent) {
|
|
268
|
+
cloneProps[eventName] = function (event) {
|
|
269
|
+
var _originChildProps$eve;
|
|
270
|
+
preEvent === null || preEvent === void 0 ? void 0 : preEvent(event);
|
|
271
|
+
triggerOpen(nextOpen, delay);
|
|
272
|
+
|
|
273
|
+
// Pass to origin
|
|
274
|
+
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
275
|
+
args[_key - 1] = arguments[_key];
|
|
305
276
|
}
|
|
277
|
+
(_originChildProps$eve = originChildProps[eventName]) === null || _originChildProps$eve === void 0 ? void 0 : _originChildProps$eve.call.apply(_originChildProps$eve, [originChildProps, event].concat(args));
|
|
306
278
|
};
|
|
307
|
-
var win = (0, _util.getWin)(popupEle);
|
|
308
|
-
win.addEventListener('click', onWindowClick);
|
|
309
|
-
return function () {
|
|
310
|
-
win.removeEventListener('click', onWindowClick);
|
|
311
|
-
};
|
|
312
|
-
}
|
|
313
|
-
}, [clickToHide, popupEle, mask, maskClosable]);
|
|
314
|
-
|
|
315
|
-
// ======================= Action: Hover ========================
|
|
316
|
-
var hoverToShow = showActions.has('hover');
|
|
317
|
-
var hoverToHide = hideActions.has('hover');
|
|
318
|
-
var onPopupMouseEnter;
|
|
319
|
-
var onPopupMouseLeave;
|
|
320
|
-
if (hoverToShow) {
|
|
321
|
-
wrapperAction('onMouseEnter', true, mouseEnterDelay, function (event) {
|
|
322
|
-
setMousePosByEvent(event);
|
|
323
|
-
});
|
|
324
|
-
onPopupMouseEnter = function onPopupMouseEnter() {
|
|
325
|
-
triggerOpen(true, mouseEnterDelay);
|
|
326
279
|
};
|
|
327
280
|
|
|
328
|
-
//
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
281
|
+
// ======================= Action: Click ========================
|
|
282
|
+
var clickToShow = showActions.has('click');
|
|
283
|
+
var clickToHide = hideActions.has('click') || hideActions.has('contextMenu');
|
|
284
|
+
if (clickToShow || clickToHide) {
|
|
285
|
+
cloneProps.onClick = function (event) {
|
|
286
|
+
var _originChildProps$onC;
|
|
287
|
+
if (openRef.current && clickToHide) {
|
|
288
|
+
triggerOpen(false);
|
|
289
|
+
} else if (!openRef.current && clickToShow) {
|
|
290
|
+
setMousePosByEvent(event);
|
|
291
|
+
triggerOpen(true);
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
// Pass to origin
|
|
295
|
+
for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
|
|
296
|
+
args[_key2 - 1] = arguments[_key2];
|
|
297
|
+
}
|
|
298
|
+
(_originChildProps$onC = originChildProps.onClick) === null || _originChildProps$onC === void 0 ? void 0 : _originChildProps$onC.call.apply(_originChildProps$onC, [originChildProps, event].concat(args));
|
|
334
299
|
};
|
|
335
300
|
}
|
|
336
|
-
}
|
|
337
|
-
if (hoverToHide) {
|
|
338
|
-
wrapperAction('onMouseLeave', false, mouseLeaveDelay);
|
|
339
|
-
onPopupMouseLeave = function onPopupMouseLeave() {
|
|
340
|
-
triggerOpen(false, mouseLeaveDelay);
|
|
341
|
-
};
|
|
342
|
-
}
|
|
343
301
|
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
302
|
+
// Click to hide is special action since click popup element should not hide
|
|
303
|
+
React.useEffect(function () {
|
|
304
|
+
if (clickToHide && popupEle && (!mask || maskClosable)) {
|
|
305
|
+
var onWindowClick = function onWindowClick(_ref) {
|
|
306
|
+
var target = _ref.target;
|
|
307
|
+
if (openRef.current && !inPopupOrChild(target)) {
|
|
308
|
+
triggerOpen(false);
|
|
309
|
+
}
|
|
310
|
+
};
|
|
311
|
+
var win = (0, _util.getWin)(popupEle);
|
|
312
|
+
win.addEventListener('click', onWindowClick);
|
|
313
|
+
return function () {
|
|
314
|
+
win.removeEventListener('click', onWindowClick);
|
|
315
|
+
};
|
|
316
|
+
}
|
|
317
|
+
}, [clickToHide, popupEle, mask, maskClosable]);
|
|
351
318
|
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
event
|
|
319
|
+
// ======================= Action: Hover ========================
|
|
320
|
+
var hoverToShow = showActions.has('hover');
|
|
321
|
+
var hoverToHide = hideActions.has('hover');
|
|
322
|
+
var onPopupMouseEnter;
|
|
323
|
+
var onPopupMouseLeave;
|
|
324
|
+
if (hoverToShow) {
|
|
325
|
+
wrapperAction('onMouseEnter', true, mouseEnterDelay, function (event) {
|
|
326
|
+
setMousePosByEvent(event);
|
|
327
|
+
});
|
|
328
|
+
onPopupMouseEnter = function onPopupMouseEnter() {
|
|
329
|
+
triggerOpen(true, mouseEnterDelay);
|
|
330
|
+
};
|
|
359
331
|
|
|
360
|
-
//
|
|
361
|
-
|
|
362
|
-
|
|
332
|
+
// Align Point
|
|
333
|
+
if (alignPoint) {
|
|
334
|
+
cloneProps.onMouseMove = function (event) {
|
|
335
|
+
var _originChildProps$onM;
|
|
336
|
+
// setMousePosByEvent(event);
|
|
337
|
+
(_originChildProps$onM = originChildProps.onMouseMove) === null || _originChildProps$onM === void 0 ? void 0 : _originChildProps$onM.call(originChildProps, event);
|
|
338
|
+
};
|
|
363
339
|
}
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
340
|
+
}
|
|
341
|
+
if (hoverToHide) {
|
|
342
|
+
wrapperAction('onMouseLeave', false, mouseLeaveDelay);
|
|
343
|
+
onPopupMouseLeave = function onPopupMouseLeave() {
|
|
344
|
+
triggerOpen(false, mouseLeaveDelay);
|
|
345
|
+
};
|
|
346
|
+
}
|
|
367
347
|
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
348
|
+
// ======================= Action: Focus ========================
|
|
349
|
+
if (showActions.has('focus')) {
|
|
350
|
+
wrapperAction('onFocus', true, focusDelay);
|
|
351
|
+
}
|
|
352
|
+
if (hideActions.has('focus')) {
|
|
353
|
+
wrapperAction('onBlur', false, blurDelay);
|
|
354
|
+
}
|
|
372
355
|
|
|
373
|
-
|
|
374
|
-
|
|
356
|
+
// ==================== Action: ContextMenu =====================
|
|
357
|
+
if (showActions.has('contextMenu')) {
|
|
358
|
+
cloneProps.onContextMenu = function (event) {
|
|
359
|
+
var _originChildProps$onC2;
|
|
360
|
+
setMousePosByEvent(event);
|
|
361
|
+
triggerOpen(true);
|
|
362
|
+
event.preventDefault();
|
|
375
363
|
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
passedEventList.forEach(function (eventName) {
|
|
380
|
-
if (restProps[eventName]) {
|
|
381
|
-
passedProps[eventName] = function () {
|
|
382
|
-
var _mergedChildrenProps$;
|
|
383
|
-
for (var _len4 = arguments.length, args = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
|
|
384
|
-
args[_key4] = arguments[_key4];
|
|
364
|
+
// Pass to origin
|
|
365
|
+
for (var _len3 = arguments.length, args = new Array(_len3 > 1 ? _len3 - 1 : 0), _key3 = 1; _key3 < _len3; _key3++) {
|
|
366
|
+
args[_key3 - 1] = arguments[_key3];
|
|
385
367
|
}
|
|
386
|
-
(
|
|
387
|
-
restProps[eventName].apply(restProps, args);
|
|
368
|
+
(_originChildProps$onC2 = originChildProps.onContextMenu) === null || _originChildProps$onC2 === void 0 ? void 0 : _originChildProps$onC2.call.apply(_originChildProps$onC2, [originChildProps, event].concat(args));
|
|
388
369
|
};
|
|
389
370
|
}
|
|
390
|
-
});
|
|
391
371
|
|
|
392
|
-
|
|
393
|
-
|
|
372
|
+
// ========================= ClassName ==========================
|
|
373
|
+
if (className) {
|
|
374
|
+
cloneProps.className = (0, _classnames.default)(originChildProps.className, className);
|
|
375
|
+
}
|
|
394
376
|
|
|
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
|
-
|
|
377
|
+
// =========================== Render ===========================
|
|
378
|
+
var mergedChildrenProps = (0, _objectSpread2.default)((0, _objectSpread2.default)({}, originChildProps), cloneProps);
|
|
379
|
+
|
|
380
|
+
// Pass props into cloneProps for nest usage
|
|
381
|
+
var passedProps = {};
|
|
382
|
+
var passedEventList = ['onContextMenu', 'onClick', 'onMouseDown', 'onTouchStart', 'onMouseEnter', 'onMouseLeave', 'onFocus', 'onBlur'];
|
|
383
|
+
passedEventList.forEach(function (eventName) {
|
|
384
|
+
if (restProps[eventName]) {
|
|
385
|
+
passedProps[eventName] = function () {
|
|
386
|
+
var _mergedChildrenProps$;
|
|
387
|
+
for (var _len4 = arguments.length, args = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
|
|
388
|
+
args[_key4] = arguments[_key4];
|
|
389
|
+
}
|
|
390
|
+
(_mergedChildrenProps$ = mergedChildrenProps[eventName]) === null || _mergedChildrenProps$ === void 0 ? void 0 : _mergedChildrenProps$.call.apply(_mergedChildrenProps$, [mergedChildrenProps].concat(args));
|
|
391
|
+
restProps[eventName].apply(restProps, args);
|
|
392
|
+
};
|
|
393
|
+
}
|
|
394
|
+
});
|
|
395
|
+
|
|
396
|
+
// Child Node
|
|
397
|
+
var triggerNode = /*#__PURE__*/React.cloneElement(child, (0, _objectSpread2.default)((0, _objectSpread2.default)({}, mergedChildrenProps), passedProps));
|
|
398
|
+
|
|
399
|
+
// Render
|
|
400
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(_context.default.Provider, {
|
|
401
|
+
value: context
|
|
402
|
+
}, /*#__PURE__*/React.createElement(_Popup.default, {
|
|
403
|
+
portal: PortalComponent,
|
|
404
|
+
ref: setPopupRef,
|
|
405
|
+
prefixCls: prefixCls,
|
|
406
|
+
popup: popup,
|
|
407
|
+
className: (0, _classnames.default)(popupClassName, alignedClassName),
|
|
408
|
+
style: popupStyle,
|
|
409
|
+
target: targetEle,
|
|
410
|
+
onMouseEnter: onPopupMouseEnter,
|
|
411
|
+
onMouseLeave: onPopupMouseLeave,
|
|
412
|
+
zIndex: zIndex
|
|
413
|
+
// Open
|
|
414
|
+
,
|
|
415
|
+
open: mergedOpen,
|
|
416
|
+
keepDom: inMotion
|
|
417
|
+
// Click
|
|
418
|
+
,
|
|
419
|
+
onClick: onPopupClick
|
|
420
|
+
// Mask
|
|
421
|
+
,
|
|
422
|
+
mask: mask
|
|
423
|
+
// Motion
|
|
424
|
+
,
|
|
425
|
+
motion: mergePopupMotion,
|
|
426
|
+
maskMotion: mergeMaskMotion,
|
|
427
|
+
onVisibleChanged: onVisibleChanged,
|
|
428
|
+
onPrepare: onPrepare
|
|
429
|
+
// Portal
|
|
430
|
+
,
|
|
431
|
+
forceRender: forceRender,
|
|
432
|
+
autoDestroy: mergedAutoDestroy,
|
|
433
|
+
getPopupContainer: getPopupContainer
|
|
434
|
+
// Arrow
|
|
435
|
+
,
|
|
436
|
+
align: alignInfo,
|
|
437
|
+
arrow: arrow
|
|
438
|
+
// Align
|
|
439
|
+
,
|
|
440
|
+
ready: ready,
|
|
441
|
+
offsetX: offsetX,
|
|
442
|
+
offsetY: offsetY,
|
|
443
|
+
arrowX: arrowX,
|
|
444
|
+
arrowY: arrowY,
|
|
445
|
+
onAlign: triggerAlign
|
|
446
|
+
// Stretch
|
|
447
|
+
,
|
|
448
|
+
stretch: stretch,
|
|
449
|
+
targetWidth: targetWidth / scaleX,
|
|
450
|
+
targetHeight: targetHeight / scaleY
|
|
451
|
+
})), /*#__PURE__*/React.createElement(_rcResizeObserver.default, {
|
|
452
|
+
disabled: !mergedOpen,
|
|
453
|
+
ref: setTargetRef,
|
|
454
|
+
onResize: onTargetResize
|
|
455
|
+
}, /*#__PURE__*/React.createElement(_TriggerWrapper.default, {
|
|
456
|
+
getTriggerDOMNode: getTriggerDOMNode
|
|
457
|
+
}, triggerNode)));
|
|
458
|
+
});
|
|
459
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
460
|
+
Trigger.displayName = 'Trigger';
|
|
461
|
+
}
|
|
462
|
+
return Trigger;
|
|
456
463
|
}
|
|
457
|
-
var _default =
|
|
464
|
+
var _default = generateTrigger(_portal.default);
|
|
458
465
|
exports.default = _default;
|