@rc-component/trigger 1.0.1 → 1.0.3
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/es/index.js
CHANGED
|
@@ -2,6 +2,7 @@ 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
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,434 +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
|
-
|
|
66
|
-
|
|
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;
|
|
67
70
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
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]);
|
|
79
82
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
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
|
+
}, []);
|
|
92
95
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
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
|
+
}, []);
|
|
104
107
|
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
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
|
+
});
|
|
113
117
|
});
|
|
114
|
-
});
|
|
115
118
|
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
+
// =========================== Motion ===========================
|
|
120
|
+
var mergePopupMotion = getMotion(prefixCls, popupMotion, popupAnimation, popupTransitionName);
|
|
121
|
+
var mergeMaskMotion = getMotion(prefixCls, maskMotion, maskAnimation, maskTransitionName);
|
|
119
122
|
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
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
|
+
});
|
|
135
138
|
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
internalTriggerOpen(nextOpen);
|
|
146
|
-
} else {
|
|
147
|
-
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) {
|
|
148
148
|
internalTriggerOpen(nextOpen);
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
}, []);
|
|
155
|
-
|
|
156
|
-
// ========================== Motion ============================
|
|
157
|
-
var _React$useState5 = React.useState(false),
|
|
158
|
-
_React$useState6 = _slicedToArray(_React$useState5, 2),
|
|
159
|
-
inMotion = _React$useState6[0],
|
|
160
|
-
setInMotion = _React$useState6[1];
|
|
161
|
-
useLayoutEffect(function () {
|
|
162
|
-
setInMotion(true);
|
|
163
|
-
}, [mergedOpen]);
|
|
164
|
-
var _React$useState7 = React.useState(null),
|
|
165
|
-
_React$useState8 = _slicedToArray(_React$useState7, 2),
|
|
166
|
-
motionPrepareResolve = _React$useState8[0],
|
|
167
|
-
setMotionPrepareResolve = _React$useState8[1];
|
|
168
|
-
|
|
169
|
-
// =========================== Align ============================
|
|
170
|
-
var _React$useState9 = React.useState([0, 0]),
|
|
171
|
-
_React$useState10 = _slicedToArray(_React$useState9, 2),
|
|
172
|
-
mousePos = _React$useState10[0],
|
|
173
|
-
setMousePos = _React$useState10[1];
|
|
174
|
-
var setMousePosByEvent = function setMousePosByEvent(event) {
|
|
175
|
-
setMousePos([event.clientX, event.clientY]);
|
|
176
|
-
};
|
|
177
|
-
var _useAlign = useAlign(mergedOpen, popupEle, alignPoint ? mousePos : targetEle, popupPlacement, builtinPlacements, popupAlign, onPopupAlign),
|
|
178
|
-
_useAlign2 = _slicedToArray(_useAlign, 9),
|
|
179
|
-
ready = _useAlign2[0],
|
|
180
|
-
offsetX = _useAlign2[1],
|
|
181
|
-
offsetY = _useAlign2[2],
|
|
182
|
-
arrowX = _useAlign2[3],
|
|
183
|
-
arrowY = _useAlign2[4],
|
|
184
|
-
scaleX = _useAlign2[5],
|
|
185
|
-
scaleY = _useAlign2[6],
|
|
186
|
-
alignInfo = _useAlign2[7],
|
|
187
|
-
onAlign = _useAlign2[8];
|
|
188
|
-
var triggerAlign = useEvent(function () {
|
|
189
|
-
if (!inMotion) {
|
|
190
|
-
onAlign();
|
|
191
|
-
}
|
|
192
|
-
});
|
|
193
|
-
useWatch(mergedOpen, targetEle, popupEle, triggerAlign);
|
|
194
|
-
useLayoutEffect(function () {
|
|
195
|
-
triggerAlign();
|
|
196
|
-
}, [mousePos]);
|
|
197
|
-
var alignedClassName = React.useMemo(function () {
|
|
198
|
-
var baseClassName = getAlignPopupClassName(builtinPlacements, prefixCls, alignInfo, alignPoint);
|
|
199
|
-
return classNames(baseClassName, getPopupClassNameFromAlign === null || getPopupClassNameFromAlign === void 0 ? void 0 : getPopupClassNameFromAlign(alignInfo));
|
|
200
|
-
}, [alignInfo, getPopupClassNameFromAlign, builtinPlacements, prefixCls, alignPoint]);
|
|
201
|
-
React.useImperativeHandle(ref, function () {
|
|
202
|
-
return {
|
|
203
|
-
forceAlign: triggerAlign
|
|
149
|
+
} else {
|
|
150
|
+
delayRef.current = setTimeout(function () {
|
|
151
|
+
internalTriggerOpen(nextOpen);
|
|
152
|
+
}, delay * 1000);
|
|
153
|
+
}
|
|
204
154
|
};
|
|
205
|
-
|
|
155
|
+
React.useEffect(function () {
|
|
156
|
+
return clearDelay;
|
|
157
|
+
}, []);
|
|
206
158
|
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
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];
|
|
213
171
|
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
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
|
+
};
|
|
220
208
|
});
|
|
221
|
-
};
|
|
222
|
-
useLayoutEffect(function () {
|
|
223
|
-
if (motionPrepareResolve) {
|
|
224
|
-
onAlign();
|
|
225
|
-
motionPrepareResolve();
|
|
226
|
-
setMotionPrepareResolve(null);
|
|
227
|
-
}
|
|
228
|
-
}, [motionPrepareResolve]);
|
|
229
|
-
|
|
230
|
-
// ========================== Stretch ===========================
|
|
231
|
-
var _React$useState11 = React.useState(0),
|
|
232
|
-
_React$useState12 = _slicedToArray(_React$useState11, 2),
|
|
233
|
-
targetWidth = _React$useState12[0],
|
|
234
|
-
setTargetWidth = _React$useState12[1];
|
|
235
|
-
var _React$useState13 = React.useState(0),
|
|
236
|
-
_React$useState14 = _slicedToArray(_React$useState13, 2),
|
|
237
|
-
targetHeight = _React$useState14[0],
|
|
238
|
-
setTargetHeight = _React$useState14[1];
|
|
239
|
-
var onTargetResize = function onTargetResize(_, ele) {
|
|
240
|
-
triggerAlign();
|
|
241
|
-
if (stretch) {
|
|
242
|
-
var rect = ele.getBoundingClientRect();
|
|
243
|
-
setTargetWidth(rect.width);
|
|
244
|
-
setTargetHeight(rect.height);
|
|
245
|
-
}
|
|
246
|
-
};
|
|
247
|
-
|
|
248
|
-
// =========================== Action ===========================
|
|
249
|
-
var _useAction = useAction(action, showAction, hideAction),
|
|
250
|
-
_useAction2 = _slicedToArray(_useAction, 2),
|
|
251
|
-
showActions = _useAction2[0],
|
|
252
|
-
hideActions = _useAction2[1];
|
|
253
|
-
|
|
254
|
-
// Util wrapper for trigger action
|
|
255
|
-
var wrapperAction = function wrapperAction(eventName, nextOpen, delay, preEvent) {
|
|
256
|
-
cloneProps[eventName] = function (event) {
|
|
257
|
-
var _originChildProps$eve;
|
|
258
|
-
preEvent === null || preEvent === void 0 ? void 0 : preEvent(event);
|
|
259
|
-
triggerOpen(nextOpen, delay);
|
|
260
209
|
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
210
|
+
// ========================== Motion ============================
|
|
211
|
+
var onVisibleChanged = function onVisibleChanged(visible) {
|
|
212
|
+
setInMotion(false);
|
|
213
|
+
onAlign();
|
|
214
|
+
afterPopupVisibleChange === null || afterPopupVisibleChange === void 0 ? void 0 : afterPopupVisibleChange(visible);
|
|
266
215
|
};
|
|
267
|
-
};
|
|
268
216
|
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
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);
|
|
280
230
|
}
|
|
231
|
+
}, [motionPrepareResolve]);
|
|
281
232
|
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
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);
|
|
285
248
|
}
|
|
286
|
-
(_originChildProps$onC = originChildProps.onClick) === null || _originChildProps$onC === void 0 ? void 0 : _originChildProps$onC.call.apply(_originChildProps$onC, [originChildProps, event].concat(args));
|
|
287
249
|
};
|
|
288
|
-
}
|
|
289
250
|
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
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];
|
|
297
267
|
}
|
|
268
|
+
(_originChildProps$eve = originChildProps[eventName]) === null || _originChildProps$eve === void 0 ? void 0 : _originChildProps$eve.call.apply(_originChildProps$eve, [originChildProps, event].concat(args));
|
|
298
269
|
};
|
|
299
|
-
var win = getWin(popupEle);
|
|
300
|
-
win.addEventListener('click', onWindowClick);
|
|
301
|
-
return function () {
|
|
302
|
-
win.removeEventListener('click', onWindowClick);
|
|
303
|
-
};
|
|
304
|
-
}
|
|
305
|
-
}, [clickToHide, popupEle, mask, maskClosable]);
|
|
306
|
-
|
|
307
|
-
// ======================= Action: Hover ========================
|
|
308
|
-
var hoverToShow = showActions.has('hover');
|
|
309
|
-
var hoverToHide = hideActions.has('hover');
|
|
310
|
-
var onPopupMouseEnter;
|
|
311
|
-
var onPopupMouseLeave;
|
|
312
|
-
if (hoverToShow) {
|
|
313
|
-
wrapperAction('onMouseEnter', true, mouseEnterDelay, function (event) {
|
|
314
|
-
setMousePosByEvent(event);
|
|
315
|
-
});
|
|
316
|
-
onPopupMouseEnter = function onPopupMouseEnter() {
|
|
317
|
-
triggerOpen(true, mouseEnterDelay);
|
|
318
270
|
};
|
|
319
271
|
|
|
320
|
-
//
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
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));
|
|
326
290
|
};
|
|
327
291
|
}
|
|
328
|
-
}
|
|
329
|
-
if (hoverToHide) {
|
|
330
|
-
wrapperAction('onMouseLeave', false, mouseLeaveDelay);
|
|
331
|
-
onPopupMouseLeave = function onPopupMouseLeave() {
|
|
332
|
-
triggerOpen(false, mouseLeaveDelay);
|
|
333
|
-
};
|
|
334
|
-
}
|
|
335
292
|
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
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]);
|
|
343
309
|
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
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
|
+
};
|
|
351
322
|
|
|
352
|
-
//
|
|
353
|
-
|
|
354
|
-
|
|
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
|
+
};
|
|
355
330
|
}
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
331
|
+
}
|
|
332
|
+
if (hoverToHide) {
|
|
333
|
+
wrapperAction('onMouseLeave', false, mouseLeaveDelay);
|
|
334
|
+
onPopupMouseLeave = function onPopupMouseLeave() {
|
|
335
|
+
triggerOpen(false, mouseLeaveDelay);
|
|
336
|
+
};
|
|
337
|
+
}
|
|
359
338
|
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
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
|
+
}
|
|
364
346
|
|
|
365
|
-
|
|
366
|
-
|
|
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();
|
|
367
354
|
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
passedEventList.forEach(function (eventName) {
|
|
372
|
-
if (restProps[eventName]) {
|
|
373
|
-
passedProps[eventName] = function () {
|
|
374
|
-
var _mergedChildrenProps$;
|
|
375
|
-
for (var _len4 = arguments.length, args = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
|
|
376
|
-
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];
|
|
377
358
|
}
|
|
378
|
-
(
|
|
379
|
-
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));
|
|
380
360
|
};
|
|
381
361
|
}
|
|
382
|
-
});
|
|
383
362
|
|
|
384
|
-
|
|
385
|
-
|
|
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));
|
|
386
389
|
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
});
|
|
446
|
-
|
|
447
|
-
|
|
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;
|
|
448
454
|
}
|
|
449
|
-
export default
|
|
455
|
+
export default generateTrigger(Portal);
|