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