@rc-component/trigger 2.2.5 → 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/Popup/Arrow.js CHANGED
@@ -1,35 +1,38 @@
1
1
  import classNames from 'classnames';
2
2
  import * as React from 'react';
3
3
  export default function Arrow(props) {
4
- var prefixCls = props.prefixCls,
5
- align = props.align,
6
- arrow = props.arrow,
7
- arrowPos = props.arrowPos;
8
- var _ref = arrow || {},
9
- className = _ref.className,
10
- content = _ref.content;
11
- var _arrowPos$x = arrowPos.x,
12
- x = _arrowPos$x === void 0 ? 0 : _arrowPos$x,
13
- _arrowPos$y = arrowPos.y,
14
- y = _arrowPos$y === void 0 ? 0 : _arrowPos$y;
15
- var arrowRef = React.useRef();
4
+ const {
5
+ prefixCls,
6
+ align,
7
+ arrow,
8
+ arrowPos
9
+ } = props;
10
+ const {
11
+ className,
12
+ content
13
+ } = arrow || {};
14
+ const {
15
+ x = 0,
16
+ y = 0
17
+ } = arrowPos;
18
+ const arrowRef = React.useRef();
16
19
 
17
20
  // Skip if no align
18
21
  if (!align || !align.points) {
19
22
  return null;
20
23
  }
21
- var alignStyle = {
24
+ const alignStyle = {
22
25
  position: 'absolute'
23
26
  };
24
27
 
25
28
  // Skip if no need to align
26
29
  if (align.autoArrow !== false) {
27
- var popupPoints = align.points[0];
28
- var targetPoints = align.points[1];
29
- var popupTB = popupPoints[0];
30
- var popupLR = popupPoints[1];
31
- var targetTB = targetPoints[0];
32
- var targetLR = targetPoints[1];
30
+ const popupPoints = align.points[0];
31
+ const targetPoints = align.points[1];
32
+ const popupTB = popupPoints[0];
33
+ const popupLR = popupPoints[1];
34
+ const targetTB = targetPoints[0];
35
+ const targetLR = targetPoints[1];
33
36
 
34
37
  // Top & Bottom
35
38
  if (popupTB === targetTB || !['t', 'b'].includes(popupTB)) {
@@ -51,7 +54,7 @@ export default function Arrow(props) {
51
54
  }
52
55
  return /*#__PURE__*/React.createElement("div", {
53
56
  ref: arrowRef,
54
- className: classNames("".concat(prefixCls, "-arrow"), className),
57
+ className: classNames(`${prefixCls}-arrow`, className),
55
58
  style: alignStyle
56
59
  }, content);
57
60
  }
@@ -1,4 +1,4 @@
1
- import type { CSSMotionProps } from 'rc-motion';
1
+ import type { CSSMotionProps } from '@rc-component/motion';
2
2
  import * as React from 'react';
3
3
  export interface MaskProps {
4
4
  prefixCls: string;
package/es/Popup/Mask.js CHANGED
@@ -1,13 +1,15 @@
1
- import _extends from "@babel/runtime/helpers/esm/extends";
1
+ function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
2
2
  import classNames from 'classnames';
3
- import CSSMotion from 'rc-motion';
3
+ import CSSMotion from '@rc-component/motion';
4
4
  import * as React from 'react';
5
5
  export default function Mask(props) {
6
- var prefixCls = props.prefixCls,
7
- open = props.open,
8
- zIndex = props.zIndex,
9
- mask = props.mask,
10
- motion = props.motion;
6
+ const {
7
+ prefixCls,
8
+ open,
9
+ zIndex,
10
+ mask,
11
+ motion
12
+ } = props;
11
13
  if (!mask) {
12
14
  return null;
13
15
  }
@@ -15,13 +17,12 @@ export default function Mask(props) {
15
17
  motionAppear: true,
16
18
  visible: open,
17
19
  removeOnLeave: true
18
- }), function (_ref) {
19
- var className = _ref.className;
20
- return /*#__PURE__*/React.createElement("div", {
21
- style: {
22
- zIndex: zIndex
23
- },
24
- className: classNames("".concat(prefixCls, "-mask"), className)
25
- });
26
- });
20
+ }), ({
21
+ className
22
+ }) => /*#__PURE__*/React.createElement("div", {
23
+ style: {
24
+ zIndex
25
+ },
26
+ className: classNames(`${prefixCls}-mask`, className)
27
+ }));
27
28
  }
@@ -1,10 +1,7 @@
1
1
  import * as React from 'react';
2
- var PopupContent = /*#__PURE__*/React.memo(function (_ref) {
3
- var children = _ref.children;
4
- return children;
5
- }, function (_, next) {
6
- return next.cache;
7
- });
2
+ const PopupContent = /*#__PURE__*/React.memo(({
3
+ children
4
+ }) => children, (_, next) => next.cache);
8
5
  if (process.env.NODE_ENV !== 'production') {
9
6
  PopupContent.displayName = 'PopupContent';
10
7
  }
@@ -1,4 +1,4 @@
1
- import type { CSSMotionProps } from 'rc-motion';
1
+ import type { CSSMotionProps } from '@rc-component/motion';
2
2
  import * as React from 'react';
3
3
  import type { TriggerProps } from '../';
4
4
  import type { AlignType, ArrowPos, ArrowTypeOuter } from '../interface';
package/es/Popup/index.js CHANGED
@@ -1,65 +1,68 @@
1
- import _extends from "@babel/runtime/helpers/esm/extends";
2
- import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
3
- import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
1
+ function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
4
2
  import classNames from 'classnames';
5
- import CSSMotion from 'rc-motion';
6
- import ResizeObserver from 'rc-resize-observer';
7
- import useLayoutEffect from "rc-util/es/hooks/useLayoutEffect";
8
- import { composeRef } from "rc-util/es/ref";
3
+ import CSSMotion from '@rc-component/motion';
4
+ import ResizeObserver from '@rc-component/resize-observer';
5
+ import useLayoutEffect from "@rc-component/util/es/hooks/useLayoutEffect";
6
+ import { composeRef } from "@rc-component/util/es/ref";
9
7
  import * as React from 'react';
10
8
  import Arrow from "./Arrow";
11
9
  import Mask from "./Mask";
12
10
  import PopupContent from "./PopupContent";
13
- var Popup = /*#__PURE__*/React.forwardRef(function (props, ref) {
14
- var popup = props.popup,
15
- className = props.className,
16
- prefixCls = props.prefixCls,
17
- style = props.style,
18
- target = props.target,
19
- _onVisibleChanged = props.onVisibleChanged,
20
- open = props.open,
21
- keepDom = props.keepDom,
22
- fresh = props.fresh,
23
- onClick = props.onClick,
24
- mask = props.mask,
25
- arrow = props.arrow,
26
- arrowPos = props.arrowPos,
27
- align = props.align,
28
- motion = props.motion,
29
- maskMotion = props.maskMotion,
30
- forceRender = props.forceRender,
31
- getPopupContainer = props.getPopupContainer,
32
- autoDestroy = props.autoDestroy,
33
- Portal = props.portal,
34
- zIndex = props.zIndex,
35
- onMouseEnter = props.onMouseEnter,
36
- onMouseLeave = props.onMouseLeave,
37
- onPointerEnter = props.onPointerEnter,
38
- onPointerDownCapture = props.onPointerDownCapture,
39
- ready = props.ready,
40
- offsetX = props.offsetX,
41
- offsetY = props.offsetY,
42
- offsetR = props.offsetR,
43
- offsetB = props.offsetB,
44
- onAlign = props.onAlign,
45
- onPrepare = props.onPrepare,
46
- stretch = props.stretch,
47
- targetWidth = props.targetWidth,
48
- targetHeight = props.targetHeight;
49
- var childNode = typeof popup === 'function' ? popup() : popup;
11
+ const Popup = /*#__PURE__*/React.forwardRef((props, ref) => {
12
+ const {
13
+ popup,
14
+ className,
15
+ prefixCls,
16
+ style,
17
+ target,
18
+ onVisibleChanged,
19
+ // Open
20
+ open,
21
+ keepDom,
22
+ fresh,
23
+ // Click
24
+ onClick,
25
+ // Mask
26
+ mask,
27
+ // Arrow
28
+ arrow,
29
+ arrowPos,
30
+ align,
31
+ // Motion
32
+ motion,
33
+ maskMotion,
34
+ // Portal
35
+ forceRender,
36
+ getPopupContainer,
37
+ autoDestroy,
38
+ portal: Portal,
39
+ zIndex,
40
+ onMouseEnter,
41
+ onMouseLeave,
42
+ onPointerEnter,
43
+ onPointerDownCapture,
44
+ ready,
45
+ offsetX,
46
+ offsetY,
47
+ offsetR,
48
+ offsetB,
49
+ onAlign,
50
+ onPrepare,
51
+ stretch,
52
+ targetWidth,
53
+ targetHeight
54
+ } = props;
55
+ const childNode = typeof popup === 'function' ? popup() : popup;
50
56
 
51
57
  // We can not remove holder only when motion finished.
52
- var isNodeVisible = open || keepDom;
58
+ const isNodeVisible = open || keepDom;
53
59
 
54
60
  // ======================= Container ========================
55
- var getPopupContainerNeedParams = (getPopupContainer === null || getPopupContainer === void 0 ? void 0 : getPopupContainer.length) > 0;
56
- var _React$useState = React.useState(!getPopupContainer || !getPopupContainerNeedParams),
57
- _React$useState2 = _slicedToArray(_React$useState, 2),
58
- show = _React$useState2[0],
59
- setShow = _React$useState2[1];
61
+ const getPopupContainerNeedParams = getPopupContainer?.length > 0;
62
+ const [show, setShow] = React.useState(!getPopupContainer || !getPopupContainerNeedParams);
60
63
 
61
64
  // Delay to show since `getPopupContainer` need target element
62
- useLayoutEffect(function () {
65
+ useLayoutEffect(() => {
63
66
  if (!show && getPopupContainerNeedParams && target) {
64
67
  setShow(true);
65
68
  }
@@ -71,8 +74,8 @@ var Popup = /*#__PURE__*/React.forwardRef(function (props, ref) {
71
74
  }
72
75
 
73
76
  // >>>>> Offset
74
- var AUTO = 'auto';
75
- var offsetStyle = {
77
+ const AUTO = 'auto';
78
+ const offsetStyle = {
76
79
  left: '-1000vw',
77
80
  top: '-1000vh',
78
81
  right: AUTO,
@@ -81,11 +84,12 @@ var Popup = /*#__PURE__*/React.forwardRef(function (props, ref) {
81
84
 
82
85
  // Set align style
83
86
  if (ready || !open) {
84
- var _experimental;
85
- var points = align.points;
86
- var dynamicInset = align.dynamicInset || ((_experimental = align._experimental) === null || _experimental === void 0 ? void 0 : _experimental.dynamicInset);
87
- var alignRight = dynamicInset && points[0][1] === 'r';
88
- var alignBottom = dynamicInset && points[0][0] === 'b';
87
+ const {
88
+ points
89
+ } = align;
90
+ const dynamicInset = align.dynamicInset || align._experimental?.dynamicInset;
91
+ const alignRight = dynamicInset && points[0][1] === 'r';
92
+ const alignBottom = dynamicInset && points[0][0] === 'b';
89
93
  if (alignRight) {
90
94
  offsetStyle.right = offsetR;
91
95
  offsetStyle.left = AUTO;
@@ -103,7 +107,7 @@ var Popup = /*#__PURE__*/React.forwardRef(function (props, ref) {
103
107
  }
104
108
 
105
109
  // >>>>> Misc
106
- var miscStyle = {};
110
+ const miscStyle = {};
107
111
  if (stretch) {
108
112
  if (stretch.includes('height') && targetHeight) {
109
113
  miscStyle.height = targetHeight;
@@ -121,9 +125,7 @@ var Popup = /*#__PURE__*/React.forwardRef(function (props, ref) {
121
125
  }
122
126
  return /*#__PURE__*/React.createElement(Portal, {
123
127
  open: forceRender || isNodeVisible,
124
- getContainer: getPopupContainer && function () {
125
- return getPopupContainer(target);
126
- },
128
+ getContainer: getPopupContainer && (() => getPopupContainer(target)),
127
129
  autoDestroy: autoDestroy
128
130
  }, /*#__PURE__*/React.createElement(Mask, {
129
131
  prefixCls: prefixCls,
@@ -134,37 +136,40 @@ var Popup = /*#__PURE__*/React.forwardRef(function (props, ref) {
134
136
  }), /*#__PURE__*/React.createElement(ResizeObserver, {
135
137
  onResize: onAlign,
136
138
  disabled: !open
137
- }, function (resizeObserverRef) {
139
+ }, resizeObserverRef => {
138
140
  return /*#__PURE__*/React.createElement(CSSMotion, _extends({
139
141
  motionAppear: true,
140
142
  motionEnter: true,
141
143
  motionLeave: true,
142
144
  removeOnLeave: false,
143
145
  forceRender: forceRender,
144
- leavedClassName: "".concat(prefixCls, "-hidden")
146
+ leavedClassName: `${prefixCls}-hidden`
145
147
  }, motion, {
146
148
  onAppearPrepare: onPrepare,
147
149
  onEnterPrepare: onPrepare,
148
150
  visible: open,
149
- onVisibleChanged: function onVisibleChanged(nextVisible) {
150
- var _motion$onVisibleChan;
151
- motion === null || motion === void 0 || (_motion$onVisibleChan = motion.onVisibleChanged) === null || _motion$onVisibleChan === void 0 || _motion$onVisibleChan.call(motion, nextVisible);
152
- _onVisibleChanged(nextVisible);
151
+ onVisibleChanged: nextVisible => {
152
+ motion?.onVisibleChanged?.(nextVisible);
153
+ onVisibleChanged(nextVisible);
153
154
  }
154
- }), function (_ref, motionRef) {
155
- var motionClassName = _ref.className,
156
- motionStyle = _ref.style;
157
- var cls = classNames(prefixCls, motionClassName, className);
155
+ }), ({
156
+ className: motionClassName,
157
+ style: motionStyle
158
+ }, motionRef) => {
159
+ const cls = classNames(prefixCls, motionClassName, className);
158
160
  return /*#__PURE__*/React.createElement("div", {
159
161
  ref: composeRef(resizeObserverRef, ref, motionRef),
160
162
  className: cls,
161
- style: _objectSpread(_objectSpread(_objectSpread(_objectSpread({
162
- '--arrow-x': "".concat(arrowPos.x || 0, "px"),
163
- '--arrow-y': "".concat(arrowPos.y || 0, "px")
164
- }, offsetStyle), miscStyle), motionStyle), {}, {
163
+ style: {
164
+ '--arrow-x': `${arrowPos.x || 0}px`,
165
+ '--arrow-y': `${arrowPos.y || 0}px`,
166
+ ...offsetStyle,
167
+ ...miscStyle,
168
+ ...motionStyle,
165
169
  boxSizing: 'border-box',
166
- zIndex: zIndex
167
- }, style),
170
+ zIndex,
171
+ ...style
172
+ },
168
173
  onMouseEnter: onMouseEnter,
169
174
  onMouseLeave: onMouseLeave,
170
175
  onPointerEnter: onPointerEnter,
@@ -1,15 +1,17 @@
1
- import { fillRef, supportRef, useComposeRef } from "rc-util/es/ref";
1
+ import { fillRef, getNodeRef, supportRef, useComposeRef } from "@rc-component/util/es/ref";
2
2
  import * as React from 'react';
3
- var TriggerWrapper = /*#__PURE__*/React.forwardRef(function (props, ref) {
4
- var children = props.children,
5
- getTriggerDOMNode = props.getTriggerDOMNode;
6
- var canUseRef = supportRef(children);
3
+ const TriggerWrapper = /*#__PURE__*/React.forwardRef((props, ref) => {
4
+ const {
5
+ children,
6
+ getTriggerDOMNode
7
+ } = props;
8
+ const canUseRef = supportRef(children);
7
9
 
8
10
  // When use `getTriggerDOMNode`, we should do additional work to get the real dom
9
- var setRef = React.useCallback(function (node) {
11
+ const setRef = React.useCallback(node => {
10
12
  fillRef(ref, getTriggerDOMNode ? getTriggerDOMNode(node) : node);
11
13
  }, [getTriggerDOMNode]);
12
- var mergedRef = useComposeRef(setRef, children.ref);
14
+ const mergedRef = useComposeRef(setRef, getNodeRef(children));
13
15
  return canUseRef ? /*#__PURE__*/React.cloneElement(children, {
14
16
  ref: mergedRef
15
17
  }) : children;
package/es/context.js CHANGED
@@ -1,3 +1,3 @@
1
1
  import * as React from 'react';
2
- var TriggerContext = /*#__PURE__*/React.createContext(null);
2
+ const TriggerContext = /*#__PURE__*/React.createContext(null);
3
3
  export default TriggerContext;
@@ -3,11 +3,11 @@ function toArray(val) {
3
3
  return val ? Array.isArray(val) ? val : [val] : [];
4
4
  }
5
5
  export default function useAction(mobile, action, showAction, hideAction) {
6
- return React.useMemo(function () {
7
- var mergedShowAction = toArray(showAction !== null && showAction !== void 0 ? showAction : action);
8
- var mergedHideAction = toArray(hideAction !== null && hideAction !== void 0 ? hideAction : action);
9
- var showActionSet = new Set(mergedShowAction);
10
- var hideActionSet = new Set(mergedHideAction);
6
+ return React.useMemo(() => {
7
+ const mergedShowAction = toArray(showAction ?? action);
8
+ const mergedHideAction = toArray(hideAction ?? action);
9
+ const showActionSet = new Set(mergedShowAction);
10
+ const hideActionSet = new Set(mergedHideAction);
11
11
  if (mobile) {
12
12
  if (showActionSet.has('hover')) {
13
13
  showActionSet.delete('hover');