@rc-component/trigger 2.2.6 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/es/index.js CHANGED
@@ -1,16 +1,12 @@
1
- import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
2
- import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
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", "fresh", "alignPoint", "onPopupClick", "onPopupAlign", "arrow", "popupMotion", "maskMotion", "popupTransitionName", "popupAnimation", "maskTransitionName", "maskAnimation", "className", "getTriggerDOMNode"];
5
1
  import Portal from '@rc-component/portal';
6
2
  import classNames from 'classnames';
7
- import ResizeObserver from 'rc-resize-observer';
8
- import { isDOM } from "rc-util/es/Dom/findDOMNode";
9
- import { getShadowRoot } from "rc-util/es/Dom/shadow";
10
- import useEvent from "rc-util/es/hooks/useEvent";
11
- import useId from "rc-util/es/hooks/useId";
12
- import useLayoutEffect from "rc-util/es/hooks/useLayoutEffect";
13
- import isMobile from "rc-util/es/isMobile";
3
+ import ResizeObserver from '@rc-component/resize-observer';
4
+ import { isDOM } from "@rc-component/util/es/Dom/findDOMNode";
5
+ import { getShadowRoot } from "@rc-component/util/es/Dom/shadow";
6
+ import useEvent from "@rc-component/util/es/hooks/useEvent";
7
+ import useId from "@rc-component/util/es/hooks/useId";
8
+ import useLayoutEffect from "@rc-component/util/es/hooks/useLayoutEffect";
9
+ import isMobile from "@rc-component/util/es/isMobile";
14
10
  import * as React from 'react';
15
11
  import Popup from "./Popup";
16
12
  import TriggerWrapper from "./TriggerWrapper";
@@ -19,7 +15,7 @@ import useAction from "./hooks/useAction";
19
15
  import useAlign from "./hooks/useAlign";
20
16
  import useWatch from "./hooks/useWatch";
21
17
  import useWinClick from "./hooks/useWinClick";
22
- import { getAlignPopupClassName, getMotion } from "./util";
18
+ import { getAlignPopupClassName } from "./util";
23
19
 
24
20
  // Removed Props List
25
21
  // Seems this can be auto
@@ -27,106 +23,96 @@ import { getAlignPopupClassName, getMotion } from "./util";
27
23
 
28
24
  // New version will not wrap popup with `rc-trigger-popup-content` when multiple children
29
25
 
30
- export function generateTrigger() {
31
- var PortalComponent = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : Portal;
32
- var Trigger = /*#__PURE__*/React.forwardRef(function (props, ref) {
33
- var _props$prefixCls = props.prefixCls,
34
- prefixCls = _props$prefixCls === void 0 ? 'rc-trigger-popup' : _props$prefixCls,
35
- children = props.children,
36
- _props$action = props.action,
37
- action = _props$action === void 0 ? 'hover' : _props$action,
38
- showAction = props.showAction,
39
- hideAction = props.hideAction,
40
- popupVisible = props.popupVisible,
41
- defaultPopupVisible = props.defaultPopupVisible,
42
- onPopupVisibleChange = props.onPopupVisibleChange,
43
- afterPopupVisibleChange = props.afterPopupVisibleChange,
44
- mouseEnterDelay = props.mouseEnterDelay,
45
- _props$mouseLeaveDela = props.mouseLeaveDelay,
46
- mouseLeaveDelay = _props$mouseLeaveDela === void 0 ? 0.1 : _props$mouseLeaveDela,
47
- focusDelay = props.focusDelay,
48
- blurDelay = props.blurDelay,
49
- mask = props.mask,
50
- _props$maskClosable = props.maskClosable,
51
- maskClosable = _props$maskClosable === void 0 ? true : _props$maskClosable,
52
- getPopupContainer = props.getPopupContainer,
53
- forceRender = props.forceRender,
54
- autoDestroy = props.autoDestroy,
55
- destroyPopupOnHide = props.destroyPopupOnHide,
56
- popup = props.popup,
57
- popupClassName = props.popupClassName,
58
- popupStyle = props.popupStyle,
59
- popupPlacement = props.popupPlacement,
60
- _props$builtinPlaceme = props.builtinPlacements,
61
- builtinPlacements = _props$builtinPlaceme === void 0 ? {} : _props$builtinPlaceme,
62
- popupAlign = props.popupAlign,
63
- zIndex = props.zIndex,
64
- stretch = props.stretch,
65
- getPopupClassNameFromAlign = props.getPopupClassNameFromAlign,
66
- fresh = props.fresh,
67
- alignPoint = props.alignPoint,
68
- onPopupClick = props.onPopupClick,
69
- onPopupAlign = props.onPopupAlign,
70
- arrow = props.arrow,
71
- popupMotion = props.popupMotion,
72
- maskMotion = props.maskMotion,
73
- popupTransitionName = props.popupTransitionName,
74
- popupAnimation = props.popupAnimation,
75
- maskTransitionName = props.maskTransitionName,
76
- maskAnimation = props.maskAnimation,
77
- className = props.className,
78
- getTriggerDOMNode = props.getTriggerDOMNode,
79
- restProps = _objectWithoutProperties(props, _excluded);
80
- var mergedAutoDestroy = autoDestroy || destroyPopupOnHide || false;
26
+ export function generateTrigger(PortalComponent = Portal) {
27
+ const Trigger = /*#__PURE__*/React.forwardRef((props, ref) => {
28
+ const {
29
+ prefixCls = 'rc-trigger-popup',
30
+ children,
31
+ // Action
32
+ action = 'hover',
33
+ showAction,
34
+ hideAction,
35
+ // Open
36
+ popupVisible,
37
+ defaultPopupVisible,
38
+ onPopupVisibleChange,
39
+ afterPopupVisibleChange,
40
+ // Delay
41
+ mouseEnterDelay,
42
+ mouseLeaveDelay = 0.1,
43
+ focusDelay,
44
+ blurDelay,
45
+ // Mask
46
+ mask,
47
+ maskClosable = true,
48
+ // Portal
49
+ getPopupContainer,
50
+ forceRender,
51
+ autoDestroy,
52
+ // Popup
53
+ popup,
54
+ popupClassName,
55
+ popupStyle,
56
+ popupPlacement,
57
+ builtinPlacements = {},
58
+ popupAlign,
59
+ zIndex,
60
+ stretch,
61
+ getPopupClassNameFromAlign,
62
+ fresh,
63
+ alignPoint,
64
+ onPopupClick,
65
+ onPopupAlign,
66
+ // Arrow
67
+ arrow,
68
+ // Motion
69
+ popupMotion,
70
+ maskMotion,
71
+ // Private
72
+ getTriggerDOMNode,
73
+ ...restProps
74
+ } = props;
75
+ const mergedAutoDestroy = autoDestroy || false;
81
76
 
82
77
  // =========================== Mobile ===========================
83
- var _React$useState = React.useState(false),
84
- _React$useState2 = _slicedToArray(_React$useState, 2),
85
- mobile = _React$useState2[0],
86
- setMobile = _React$useState2[1];
87
- useLayoutEffect(function () {
78
+ const [mobile, setMobile] = React.useState(false);
79
+ useLayoutEffect(() => {
88
80
  setMobile(isMobile());
89
81
  }, []);
90
82
 
91
83
  // ========================== Context ===========================
92
- var subPopupElements = React.useRef({});
93
- var parentContext = React.useContext(TriggerContext);
94
- var context = React.useMemo(function () {
84
+ const subPopupElements = React.useRef({});
85
+ const parentContext = React.useContext(TriggerContext);
86
+ const context = React.useMemo(() => {
95
87
  return {
96
- registerSubPopup: function registerSubPopup(id, subPopupEle) {
88
+ registerSubPopup: (id, subPopupEle) => {
97
89
  subPopupElements.current[id] = subPopupEle;
98
- parentContext === null || parentContext === void 0 || parentContext.registerSubPopup(id, subPopupEle);
90
+ parentContext?.registerSubPopup(id, subPopupEle);
99
91
  }
100
92
  };
101
93
  }, [parentContext]);
102
94
 
103
95
  // =========================== Popup ============================
104
- var id = useId();
105
- var _React$useState3 = React.useState(null),
106
- _React$useState4 = _slicedToArray(_React$useState3, 2),
107
- popupEle = _React$useState4[0],
108
- setPopupEle = _React$useState4[1];
96
+ const id = useId();
97
+ const [popupEle, setPopupEle] = React.useState(null);
109
98
 
110
99
  // Used for forwardRef popup. Not use internal
111
- var externalPopupRef = React.useRef(null);
112
- var setPopupRef = useEvent(function (node) {
100
+ const externalPopupRef = React.useRef(null);
101
+ const setPopupRef = useEvent(node => {
113
102
  externalPopupRef.current = node;
114
103
  if (isDOM(node) && popupEle !== node) {
115
104
  setPopupEle(node);
116
105
  }
117
- parentContext === null || parentContext === void 0 || parentContext.registerSubPopup(id, node);
106
+ parentContext?.registerSubPopup(id, node);
118
107
  });
119
108
 
120
109
  // =========================== Target ===========================
121
110
  // Use state to control here since `useRef` update not trigger render
122
- var _React$useState5 = React.useState(null),
123
- _React$useState6 = _slicedToArray(_React$useState5, 2),
124
- targetEle = _React$useState6[0],
125
- setTargetEle = _React$useState6[1];
111
+ const [targetEle, setTargetEle] = React.useState(null);
126
112
 
127
113
  // Used for forwardRef target. Not use internal
128
- var externalForwardRef = React.useRef(null);
129
- var setTargetRef = useEvent(function (node) {
114
+ const externalForwardRef = React.useRef(null);
115
+ const setTargetRef = useEvent(node => {
130
116
  if (isDOM(node) && targetEle !== node) {
131
117
  setTargetEle(node);
132
118
  externalForwardRef.current = node;
@@ -134,191 +120,141 @@ export function generateTrigger() {
134
120
  });
135
121
 
136
122
  // ========================== Children ==========================
137
- var child = React.Children.only(children);
138
- var originChildProps = (child === null || child === void 0 ? void 0 : child.props) || {};
139
- var cloneProps = {};
140
- var inPopupOrChild = useEvent(function (ele) {
141
- var _getShadowRoot, _getShadowRoot2;
142
- var childDOM = targetEle;
143
- return (childDOM === null || childDOM === void 0 ? void 0 : childDOM.contains(ele)) || ((_getShadowRoot = getShadowRoot(childDOM)) === null || _getShadowRoot === void 0 ? void 0 : _getShadowRoot.host) === ele || ele === childDOM || (popupEle === null || popupEle === void 0 ? void 0 : popupEle.contains(ele)) || ((_getShadowRoot2 = getShadowRoot(popupEle)) === null || _getShadowRoot2 === void 0 ? void 0 : _getShadowRoot2.host) === ele || ele === popupEle || Object.values(subPopupElements.current).some(function (subPopupEle) {
144
- return (subPopupEle === null || subPopupEle === void 0 ? void 0 : subPopupEle.contains(ele)) || ele === subPopupEle;
145
- });
123
+ const child = React.Children.only(children);
124
+ const originChildProps = child?.props || {};
125
+ const cloneProps = {};
126
+ const inPopupOrChild = useEvent(ele => {
127
+ const childDOM = targetEle;
128
+ return childDOM?.contains(ele) || getShadowRoot(childDOM)?.host === ele || ele === childDOM || popupEle?.contains(ele) || getShadowRoot(popupEle)?.host === ele || ele === popupEle || Object.values(subPopupElements.current).some(subPopupEle => subPopupEle?.contains(ele) || ele === subPopupEle);
146
129
  });
147
130
 
148
- // =========================== Motion ===========================
149
- var mergePopupMotion = getMotion(prefixCls, popupMotion, popupAnimation, popupTransitionName);
150
- var mergeMaskMotion = getMotion(prefixCls, maskMotion, maskAnimation, maskTransitionName);
151
-
152
131
  // ============================ Open ============================
153
- var _React$useState7 = React.useState(defaultPopupVisible || false),
154
- _React$useState8 = _slicedToArray(_React$useState7, 2),
155
- internalOpen = _React$useState8[0],
156
- setInternalOpen = _React$useState8[1];
132
+ const [internalOpen, setInternalOpen] = React.useState(defaultPopupVisible || false);
157
133
 
158
134
  // Render still use props as first priority
159
- var mergedOpen = popupVisible !== null && popupVisible !== void 0 ? popupVisible : internalOpen;
135
+ const mergedOpen = popupVisible ?? internalOpen;
160
136
 
161
137
  // We use effect sync here in case `popupVisible` back to `undefined`
162
- var setMergedOpen = useEvent(function (nextOpen) {
138
+ const setMergedOpen = useEvent(nextOpen => {
163
139
  if (popupVisible === undefined) {
164
140
  setInternalOpen(nextOpen);
165
141
  }
166
142
  });
167
- useLayoutEffect(function () {
143
+ useLayoutEffect(() => {
168
144
  setInternalOpen(popupVisible || false);
169
145
  }, [popupVisible]);
170
- var openRef = React.useRef(mergedOpen);
146
+ const openRef = React.useRef(mergedOpen);
171
147
  openRef.current = mergedOpen;
172
- var lastTriggerRef = React.useRef([]);
148
+ const lastTriggerRef = React.useRef([]);
173
149
  lastTriggerRef.current = [];
174
- var internalTriggerOpen = useEvent(function (nextOpen) {
175
- var _lastTriggerRef$curre;
150
+ const internalTriggerOpen = useEvent(nextOpen => {
176
151
  setMergedOpen(nextOpen);
177
152
 
178
153
  // Enter or Pointer will both trigger open state change
179
154
  // We only need take one to avoid duplicated change event trigger
180
155
  // Use `lastTriggerRef` to record last open type
181
- if (((_lastTriggerRef$curre = lastTriggerRef.current[lastTriggerRef.current.length - 1]) !== null && _lastTriggerRef$curre !== void 0 ? _lastTriggerRef$curre : mergedOpen) !== nextOpen) {
156
+ if ((lastTriggerRef.current[lastTriggerRef.current.length - 1] ?? mergedOpen) !== nextOpen) {
182
157
  lastTriggerRef.current.push(nextOpen);
183
- onPopupVisibleChange === null || onPopupVisibleChange === void 0 || onPopupVisibleChange(nextOpen);
158
+ onPopupVisibleChange?.(nextOpen);
184
159
  }
185
160
  });
186
161
 
187
162
  // Trigger for delay
188
- var delayRef = React.useRef();
189
- var clearDelay = function clearDelay() {
163
+ const delayRef = React.useRef();
164
+ const clearDelay = () => {
190
165
  clearTimeout(delayRef.current);
191
166
  };
192
- var triggerOpen = function triggerOpen(nextOpen) {
193
- var delay = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
167
+ const triggerOpen = (nextOpen, delay = 0) => {
194
168
  clearDelay();
195
169
  if (delay === 0) {
196
170
  internalTriggerOpen(nextOpen);
197
171
  } else {
198
- delayRef.current = setTimeout(function () {
172
+ delayRef.current = setTimeout(() => {
199
173
  internalTriggerOpen(nextOpen);
200
174
  }, delay * 1000);
201
175
  }
202
176
  };
203
- React.useEffect(function () {
204
- return clearDelay;
205
- }, []);
177
+ React.useEffect(() => clearDelay, []);
206
178
 
207
179
  // ========================== Motion ============================
208
- var _React$useState9 = React.useState(false),
209
- _React$useState10 = _slicedToArray(_React$useState9, 2),
210
- inMotion = _React$useState10[0],
211
- setInMotion = _React$useState10[1];
212
- useLayoutEffect(function (firstMount) {
180
+ const [inMotion, setInMotion] = React.useState(false);
181
+ useLayoutEffect(firstMount => {
213
182
  if (!firstMount || mergedOpen) {
214
183
  setInMotion(true);
215
184
  }
216
185
  }, [mergedOpen]);
217
- var _React$useState11 = React.useState(null),
218
- _React$useState12 = _slicedToArray(_React$useState11, 2),
219
- motionPrepareResolve = _React$useState12[0],
220
- setMotionPrepareResolve = _React$useState12[1];
186
+ const [motionPrepareResolve, setMotionPrepareResolve] = React.useState(null);
221
187
 
222
188
  // =========================== Align ============================
223
- var _React$useState13 = React.useState(null),
224
- _React$useState14 = _slicedToArray(_React$useState13, 2),
225
- mousePos = _React$useState14[0],
226
- setMousePos = _React$useState14[1];
227
- var setMousePosByEvent = function setMousePosByEvent(event) {
189
+ const [mousePos, setMousePos] = React.useState(null);
190
+ const setMousePosByEvent = event => {
228
191
  setMousePos([event.clientX, event.clientY]);
229
192
  };
230
- var _useAlign = useAlign(mergedOpen, popupEle, alignPoint && mousePos !== null ? mousePos : targetEle, popupPlacement, builtinPlacements, popupAlign, onPopupAlign),
231
- _useAlign2 = _slicedToArray(_useAlign, 11),
232
- ready = _useAlign2[0],
233
- offsetX = _useAlign2[1],
234
- offsetY = _useAlign2[2],
235
- offsetR = _useAlign2[3],
236
- offsetB = _useAlign2[4],
237
- arrowX = _useAlign2[5],
238
- arrowY = _useAlign2[6],
239
- scaleX = _useAlign2[7],
240
- scaleY = _useAlign2[8],
241
- alignInfo = _useAlign2[9],
242
- onAlign = _useAlign2[10];
243
- var _useAction = useAction(mobile, action, showAction, hideAction),
244
- _useAction2 = _slicedToArray(_useAction, 2),
245
- showActions = _useAction2[0],
246
- hideActions = _useAction2[1];
247
- var clickToShow = showActions.has('click');
248
- var clickToHide = hideActions.has('click') || hideActions.has('contextMenu');
249
- var triggerAlign = useEvent(function () {
193
+ const [ready, offsetX, offsetY, offsetR, offsetB, arrowX, arrowY, scaleX, scaleY, alignInfo, onAlign] = useAlign(mergedOpen, popupEle, alignPoint && mousePos !== null ? mousePos : targetEle, popupPlacement, builtinPlacements, popupAlign, onPopupAlign);
194
+ const [showActions, hideActions] = useAction(mobile, action, showAction, hideAction);
195
+ const clickToShow = showActions.has('click');
196
+ const clickToHide = hideActions.has('click') || hideActions.has('contextMenu');
197
+ const triggerAlign = useEvent(() => {
250
198
  if (!inMotion) {
251
199
  onAlign();
252
200
  }
253
201
  });
254
- var onScroll = function onScroll() {
202
+ const onScroll = () => {
255
203
  if (openRef.current && alignPoint && clickToHide) {
256
204
  triggerOpen(false);
257
205
  }
258
206
  };
259
207
  useWatch(mergedOpen, targetEle, popupEle, triggerAlign, onScroll);
260
- useLayoutEffect(function () {
208
+ useLayoutEffect(() => {
261
209
  triggerAlign();
262
210
  }, [mousePos, popupPlacement]);
263
211
 
264
212
  // When no builtinPlacements and popupAlign changed
265
- useLayoutEffect(function () {
266
- if (mergedOpen && !(builtinPlacements !== null && builtinPlacements !== void 0 && builtinPlacements[popupPlacement])) {
213
+ useLayoutEffect(() => {
214
+ if (mergedOpen && !builtinPlacements?.[popupPlacement]) {
267
215
  triggerAlign();
268
216
  }
269
217
  }, [JSON.stringify(popupAlign)]);
270
- var alignedClassName = React.useMemo(function () {
271
- var baseClassName = getAlignPopupClassName(builtinPlacements, prefixCls, alignInfo, alignPoint);
272
- return classNames(baseClassName, getPopupClassNameFromAlign === null || getPopupClassNameFromAlign === void 0 ? void 0 : getPopupClassNameFromAlign(alignInfo));
218
+ const alignedClassName = React.useMemo(() => {
219
+ const baseClassName = getAlignPopupClassName(builtinPlacements, prefixCls, alignInfo, alignPoint);
220
+ return classNames(baseClassName, getPopupClassNameFromAlign?.(alignInfo));
273
221
  }, [alignInfo, getPopupClassNameFromAlign, builtinPlacements, prefixCls, alignPoint]);
274
222
 
275
223
  // ============================ Refs ============================
276
- React.useImperativeHandle(ref, function () {
277
- return {
278
- nativeElement: externalForwardRef.current,
279
- popupElement: externalPopupRef.current,
280
- forceAlign: triggerAlign
281
- };
282
- });
224
+ React.useImperativeHandle(ref, () => ({
225
+ nativeElement: externalForwardRef.current,
226
+ popupElement: externalPopupRef.current,
227
+ forceAlign: triggerAlign
228
+ }));
283
229
 
284
230
  // ========================== Stretch ===========================
285
- var _React$useState15 = React.useState(0),
286
- _React$useState16 = _slicedToArray(_React$useState15, 2),
287
- targetWidth = _React$useState16[0],
288
- setTargetWidth = _React$useState16[1];
289
- var _React$useState17 = React.useState(0),
290
- _React$useState18 = _slicedToArray(_React$useState17, 2),
291
- targetHeight = _React$useState18[0],
292
- setTargetHeight = _React$useState18[1];
293
- var syncTargetSize = function syncTargetSize() {
231
+ const [targetWidth, setTargetWidth] = React.useState(0);
232
+ const [targetHeight, setTargetHeight] = React.useState(0);
233
+ const syncTargetSize = () => {
294
234
  if (stretch && targetEle) {
295
- var rect = targetEle.getBoundingClientRect();
235
+ const rect = targetEle.getBoundingClientRect();
296
236
  setTargetWidth(rect.width);
297
237
  setTargetHeight(rect.height);
298
238
  }
299
239
  };
300
- var onTargetResize = function onTargetResize() {
240
+ const onTargetResize = () => {
301
241
  syncTargetSize();
302
242
  triggerAlign();
303
243
  };
304
244
 
305
245
  // ========================== Motion ============================
306
- var onVisibleChanged = function onVisibleChanged(visible) {
246
+ const onVisibleChanged = visible => {
307
247
  setInMotion(false);
308
248
  onAlign();
309
- afterPopupVisibleChange === null || afterPopupVisibleChange === void 0 || afterPopupVisibleChange(visible);
249
+ afterPopupVisibleChange?.(visible);
310
250
  };
311
251
 
312
252
  // We will trigger align when motion is in prepare
313
- var onPrepare = function onPrepare() {
314
- return new Promise(function (resolve) {
315
- syncTargetSize();
316
- setMotionPrepareResolve(function () {
317
- return resolve;
318
- });
319
- });
320
- };
321
- useLayoutEffect(function () {
253
+ const onPrepare = () => new Promise(resolve => {
254
+ syncTargetSize();
255
+ setMotionPrepareResolve(() => resolve);
256
+ });
257
+ useLayoutEffect(() => {
322
258
  if (motionPrepareResolve) {
323
259
  onAlign();
324
260
  motionPrepareResolve();
@@ -331,23 +267,18 @@ export function generateTrigger() {
331
267
  * Util wrapper for trigger action
332
268
  */
333
269
  function wrapperAction(eventName, nextOpen, delay, preEvent) {
334
- cloneProps[eventName] = function (event) {
335
- var _originChildProps$eve;
336
- preEvent === null || preEvent === void 0 || preEvent(event);
270
+ cloneProps[eventName] = (event, ...args) => {
271
+ preEvent?.(event);
337
272
  triggerOpen(nextOpen, delay);
338
273
 
339
274
  // Pass to origin
340
- for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
341
- args[_key - 1] = arguments[_key];
342
- }
343
- (_originChildProps$eve = originChildProps[eventName]) === null || _originChildProps$eve === void 0 || _originChildProps$eve.call.apply(_originChildProps$eve, [originChildProps, event].concat(args));
275
+ originChildProps[eventName]?.(event, ...args);
344
276
  };
345
277
  }
346
278
 
347
279
  // ======================= Action: Click ========================
348
280
  if (clickToShow || clickToHide) {
349
- cloneProps.onClick = function (event) {
350
- var _originChildProps$onC;
281
+ cloneProps.onClick = (event, ...args) => {
351
282
  if (openRef.current && clickToHide) {
352
283
  triggerOpen(false);
353
284
  } else if (!openRef.current && clickToShow) {
@@ -356,49 +287,45 @@ export function generateTrigger() {
356
287
  }
357
288
 
358
289
  // Pass to origin
359
- for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
360
- args[_key2 - 1] = arguments[_key2];
361
- }
362
- (_originChildProps$onC = originChildProps.onClick) === null || _originChildProps$onC === void 0 || _originChildProps$onC.call.apply(_originChildProps$onC, [originChildProps, event].concat(args));
290
+ originChildProps.onClick?.(event, ...args);
363
291
  };
364
292
  }
365
293
 
366
294
  // Click to hide is special action since click popup element should not hide
367
- var onPopupPointerDown = useWinClick(mergedOpen, clickToHide, targetEle, popupEle, mask, maskClosable, inPopupOrChild, triggerOpen);
295
+ const onPopupPointerDown = useWinClick(mergedOpen, clickToHide, targetEle, popupEle, mask, maskClosable, inPopupOrChild, triggerOpen);
368
296
 
369
297
  // ======================= Action: Hover ========================
370
- var hoverToShow = showActions.has('hover');
371
- var hoverToHide = hideActions.has('hover');
372
- var onPopupMouseEnter;
373
- var onPopupMouseLeave;
298
+ const hoverToShow = showActions.has('hover');
299
+ const hoverToHide = hideActions.has('hover');
300
+ let onPopupMouseEnter;
301
+ let onPopupMouseLeave;
374
302
  if (hoverToShow) {
375
303
  // Compatible with old browser which not support pointer event
376
- wrapperAction('onMouseEnter', true, mouseEnterDelay, function (event) {
304
+ wrapperAction('onMouseEnter', true, mouseEnterDelay, event => {
377
305
  setMousePosByEvent(event);
378
306
  });
379
- wrapperAction('onPointerEnter', true, mouseEnterDelay, function (event) {
307
+ wrapperAction('onPointerEnter', true, mouseEnterDelay, event => {
380
308
  setMousePosByEvent(event);
381
309
  });
382
- onPopupMouseEnter = function onPopupMouseEnter(event) {
310
+ onPopupMouseEnter = event => {
383
311
  // Only trigger re-open when popup is visible
384
- if ((mergedOpen || inMotion) && popupEle !== null && popupEle !== void 0 && popupEle.contains(event.target)) {
312
+ if ((mergedOpen || inMotion) && popupEle?.contains(event.target)) {
385
313
  triggerOpen(true, mouseEnterDelay);
386
314
  }
387
315
  };
388
316
 
389
317
  // Align Point
390
318
  if (alignPoint) {
391
- cloneProps.onMouseMove = function (event) {
392
- var _originChildProps$onM;
319
+ cloneProps.onMouseMove = event => {
393
320
  // setMousePosByEvent(event);
394
- (_originChildProps$onM = originChildProps.onMouseMove) === null || _originChildProps$onM === void 0 || _originChildProps$onM.call(originChildProps, event);
321
+ originChildProps.onMouseMove?.(event);
395
322
  };
396
323
  }
397
324
  }
398
325
  if (hoverToHide) {
399
326
  wrapperAction('onMouseLeave', false, mouseLeaveDelay);
400
327
  wrapperAction('onPointerLeave', false, mouseLeaveDelay);
401
- onPopupMouseLeave = function onPopupMouseLeave() {
328
+ onPopupMouseLeave = () => {
402
329
  triggerOpen(false, mouseLeaveDelay);
403
330
  };
404
331
  }
@@ -413,8 +340,7 @@ export function generateTrigger() {
413
340
 
414
341
  // ==================== Action: ContextMenu =====================
415
342
  if (showActions.has('contextMenu')) {
416
- cloneProps.onContextMenu = function (event) {
417
- var _originChildProps$onC2;
343
+ cloneProps.onContextMenu = (event, ...args) => {
418
344
  if (openRef.current && hideActions.has('contextMenu')) {
419
345
  triggerOpen(false);
420
346
  } else {
@@ -424,44 +350,41 @@ export function generateTrigger() {
424
350
  event.preventDefault();
425
351
 
426
352
  // Pass to origin
427
- for (var _len3 = arguments.length, args = new Array(_len3 > 1 ? _len3 - 1 : 0), _key3 = 1; _key3 < _len3; _key3++) {
428
- args[_key3 - 1] = arguments[_key3];
429
- }
430
- (_originChildProps$onC2 = originChildProps.onContextMenu) === null || _originChildProps$onC2 === void 0 || _originChildProps$onC2.call.apply(_originChildProps$onC2, [originChildProps, event].concat(args));
353
+ originChildProps.onContextMenu?.(event, ...args);
431
354
  };
432
355
  }
433
356
 
434
- // ========================= ClassName ==========================
435
- if (className) {
436
- cloneProps.className = classNames(originChildProps.className, className);
437
- }
438
-
439
357
  // =========================== Render ===========================
440
- var mergedChildrenProps = _objectSpread(_objectSpread({}, originChildProps), cloneProps);
358
+ const mergedChildrenProps = {
359
+ ...originChildProps,
360
+ ...cloneProps
361
+ };
441
362
 
442
363
  // Pass props into cloneProps for nest usage
443
- var passedProps = {};
444
- var passedEventList = ['onContextMenu', 'onClick', 'onMouseDown', 'onTouchStart', 'onMouseEnter', 'onMouseLeave', 'onFocus', 'onBlur'];
445
- passedEventList.forEach(function (eventName) {
364
+ const passedProps = {};
365
+ const passedEventList = ['onContextMenu', 'onClick', 'onMouseDown', 'onTouchStart', 'onMouseEnter', 'onMouseLeave', 'onFocus', 'onBlur'];
366
+ passedEventList.forEach(eventName => {
446
367
  if (restProps[eventName]) {
447
- passedProps[eventName] = function () {
448
- var _mergedChildrenProps$;
449
- for (var _len4 = arguments.length, args = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
450
- args[_key4] = arguments[_key4];
451
- }
452
- (_mergedChildrenProps$ = mergedChildrenProps[eventName]) === null || _mergedChildrenProps$ === void 0 || _mergedChildrenProps$.call.apply(_mergedChildrenProps$, [mergedChildrenProps].concat(args));
453
- restProps[eventName].apply(restProps, args);
368
+ passedProps[eventName] = (...args) => {
369
+ mergedChildrenProps[eventName]?.(...args);
370
+ restProps[eventName](...args);
454
371
  };
455
372
  }
456
373
  });
457
374
 
458
375
  // Child Node
459
- var triggerNode = /*#__PURE__*/React.cloneElement(child, _objectSpread(_objectSpread({}, mergedChildrenProps), passedProps));
460
- var arrowPos = {
376
+ const triggerNode = /*#__PURE__*/React.cloneElement(child, {
377
+ ...mergedChildrenProps,
378
+ ...passedProps
379
+ });
380
+ const arrowPos = {
461
381
  x: arrowX,
462
382
  y: arrowY
463
383
  };
464
- var innerArrow = arrow ? _objectSpread({}, arrow !== true ? arrow : {}) : null;
384
+ const innerArrow = arrow ? {
385
+ // true and Object likely
386
+ ...(arrow !== true ? arrow : {})
387
+ } : null;
465
388
 
466
389
  // Render
467
390
  return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(ResizeObserver, {
@@ -500,8 +423,8 @@ export function generateTrigger() {
500
423
  mask: mask
501
424
  // Motion
502
425
  ,
503
- motion: mergePopupMotion,
504
- maskMotion: mergeMaskMotion,
426
+ motion: popupMotion,
427
+ maskMotion: maskMotion,
505
428
  onVisibleChanged: onVisibleChanged,
506
429
  onPrepare: onPrepare
507
430
  // Portal
package/es/interface.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  /// <reference types="react" />
2
- import type { CSSMotionProps } from 'rc-motion';
2
+ import type { CSSMotionProps } from '@rc-component/motion';
3
3
  export type Placement = 'top' | 'left' | 'right' | 'bottom' | 'topLeft' | 'topRight' | 'bottomLeft' | 'bottomRight' | 'leftTop' | 'leftBottom' | 'rightTop' | 'rightBottom';
4
4
  export type AlignPointTopBottom = 't' | 'b' | 'c';
5
5
  export type AlignPointLeftRight = 'l' | 'r' | 'c';