@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/Popup/Arrow.js +23 -20
- package/es/Popup/Mask.d.ts +1 -1
- package/es/Popup/Mask.js +17 -16
- package/es/Popup/PopupContent.js +3 -6
- package/es/Popup/index.d.ts +1 -1
- package/es/Popup/index.js +83 -78
- package/es/TriggerWrapper.js +9 -7
- package/es/context.js +1 -1
- package/es/hooks/useAction.js +5 -5
- package/es/hooks/useAlign.js +205 -215
- package/es/hooks/useWatch.js +11 -12
- package/es/hooks/useWinClick.js +14 -16
- package/es/index.d.ts +2 -14
- package/es/index.js +167 -244
- package/es/interface.d.ts +1 -1
- package/es/mock.js +10 -13
- package/es/util.d.ts +1 -4
- package/es/util.js +57 -75
- package/lib/Popup/Arrow.js +26 -22
- package/lib/Popup/Mask.d.ts +1 -1
- package/lib/Popup/Mask.js +21 -19
- package/lib/Popup/PopupContent.js +5 -7
- package/lib/Popup/index.d.ts +1 -1
- package/lib/Popup/index.js +89 -83
- package/lib/TriggerWrapper.js +11 -8
- package/lib/context.js +3 -2
- package/lib/hooks/useAction.js +7 -6
- package/lib/hooks/useAlign.js +208 -217
- package/lib/hooks/useWatch.js +12 -13
- package/lib/hooks/useWinClick.js +16 -17
- package/lib/index.d.ts +2 -14
- package/lib/index.js +172 -248
- package/lib/interface.d.ts +1 -1
- package/lib/mock.js +12 -15
- package/lib/util.d.ts +1 -4
- package/lib/util.js +57 -77
- package/package.json +10 -11
package/es/mock.js
CHANGED
|
@@ -1,19 +1,16 @@
|
|
|
1
|
-
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
2
1
|
import * as React from 'react';
|
|
3
2
|
import { generateTrigger } from "./index";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
React.useEffect(function () {
|
|
14
|
-
getContainer === null || getContainer === void 0 || getContainer();
|
|
3
|
+
const MockPortal = ({
|
|
4
|
+
open,
|
|
5
|
+
autoDestroy,
|
|
6
|
+
children,
|
|
7
|
+
getContainer
|
|
8
|
+
}) => {
|
|
9
|
+
const [visible, setVisible] = React.useState(open);
|
|
10
|
+
React.useEffect(() => {
|
|
11
|
+
getContainer?.();
|
|
15
12
|
});
|
|
16
|
-
React.useEffect(
|
|
13
|
+
React.useEffect(() => {
|
|
17
14
|
if (open) {
|
|
18
15
|
setVisible(true);
|
|
19
16
|
} else if (autoDestroy) {
|
package/es/util.d.ts
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type { AlignType, AnimationType, BuildInPlacements, TransitionNameType } from './interface';
|
|
1
|
+
import type { AlignType, BuildInPlacements } from './interface';
|
|
3
2
|
export declare function getAlignPopupClassName(builtinPlacements: BuildInPlacements, prefixCls: string, align: AlignType, isAlignPoint: boolean): string;
|
|
4
|
-
/** @deprecated We should not use this if we can refactor all deps */
|
|
5
|
-
export declare function getMotion(prefixCls: string, motion: CSSMotionProps, animation: AnimationType, transitionName: TransitionNameType): CSSMotionProps;
|
|
6
3
|
export declare function getWin(ele: HTMLElement): Window & typeof globalThis;
|
|
7
4
|
/**
|
|
8
5
|
* Get all the scrollable parent elements of the element
|
package/es/util.js
CHANGED
|
@@ -1,43 +1,22 @@
|
|
|
1
|
-
|
|
2
|
-
function isPointsEq() {
|
|
3
|
-
var a1 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
4
|
-
var a2 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
|
|
5
|
-
var isAlignPoint = arguments.length > 2 ? arguments[2] : undefined;
|
|
1
|
+
function isPointsEq(a1 = [], a2 = [], isAlignPoint) {
|
|
6
2
|
if (isAlignPoint) {
|
|
7
3
|
return a1[0] === a2[0];
|
|
8
4
|
}
|
|
9
5
|
return a1[0] === a2[0] && a1[1] === a2[1];
|
|
10
6
|
}
|
|
11
7
|
export function getAlignPopupClassName(builtinPlacements, prefixCls, align, isAlignPoint) {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
8
|
+
const {
|
|
9
|
+
points
|
|
10
|
+
} = align;
|
|
11
|
+
const placements = Object.keys(builtinPlacements);
|
|
12
|
+
for (let i = 0; i < placements.length; i += 1) {
|
|
13
|
+
const placement = placements[i];
|
|
14
|
+
if (isPointsEq(builtinPlacements[placement]?.points, points, isAlignPoint)) {
|
|
15
|
+
return `${prefixCls}-placement-${placement}`;
|
|
19
16
|
}
|
|
20
17
|
}
|
|
21
18
|
return '';
|
|
22
19
|
}
|
|
23
|
-
|
|
24
|
-
/** @deprecated We should not use this if we can refactor all deps */
|
|
25
|
-
export function getMotion(prefixCls, motion, animation, transitionName) {
|
|
26
|
-
if (motion) {
|
|
27
|
-
return motion;
|
|
28
|
-
}
|
|
29
|
-
if (animation) {
|
|
30
|
-
return {
|
|
31
|
-
motionName: "".concat(prefixCls, "-").concat(animation)
|
|
32
|
-
};
|
|
33
|
-
}
|
|
34
|
-
if (transitionName) {
|
|
35
|
-
return {
|
|
36
|
-
motionName: transitionName
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
return null;
|
|
40
|
-
}
|
|
41
20
|
export function getWin(ele) {
|
|
42
21
|
return ele.ownerDocument.defaultView;
|
|
43
22
|
}
|
|
@@ -48,25 +27,23 @@ export function getWin(ele) {
|
|
|
48
27
|
* @param areaOnly Only return the parent which will cut visible area
|
|
49
28
|
*/
|
|
50
29
|
export function collectScroller(ele) {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
30
|
+
const scrollerList = [];
|
|
31
|
+
let current = ele?.parentElement;
|
|
32
|
+
const scrollStyle = ['hidden', 'scroll', 'clip', 'auto'];
|
|
54
33
|
while (current) {
|
|
55
|
-
|
|
56
|
-
overflowX
|
|
57
|
-
overflowY
|
|
58
|
-
overflow
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
})) {
|
|
34
|
+
const {
|
|
35
|
+
overflowX,
|
|
36
|
+
overflowY,
|
|
37
|
+
overflow
|
|
38
|
+
} = getWin(current).getComputedStyle(current);
|
|
39
|
+
if ([overflowX, overflowY, overflow].some(o => scrollStyle.includes(o))) {
|
|
62
40
|
scrollerList.push(current);
|
|
63
41
|
}
|
|
64
42
|
current = current.parentElement;
|
|
65
43
|
}
|
|
66
44
|
return scrollerList;
|
|
67
45
|
}
|
|
68
|
-
export function toNum(num) {
|
|
69
|
-
var defaultValue = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
|
|
46
|
+
export function toNum(num, defaultValue = 1) {
|
|
70
47
|
return Number.isNaN(num) ? defaultValue : num;
|
|
71
48
|
}
|
|
72
49
|
function getPxValue(val) {
|
|
@@ -95,56 +72,61 @@ function getPxValue(val) {
|
|
|
95
72
|
* Get visible area of element
|
|
96
73
|
*/
|
|
97
74
|
export function getVisibleArea(initArea, scrollerList) {
|
|
98
|
-
|
|
99
|
-
|
|
75
|
+
const visibleArea = {
|
|
76
|
+
...initArea
|
|
77
|
+
};
|
|
78
|
+
(scrollerList || []).forEach(ele => {
|
|
100
79
|
if (ele instanceof HTMLBodyElement || ele instanceof HTMLHtmlElement) {
|
|
101
80
|
return;
|
|
102
81
|
}
|
|
103
82
|
|
|
104
83
|
// Skip if static position which will not affect visible area
|
|
105
|
-
|
|
106
|
-
overflow
|
|
107
|
-
overflowClipMargin
|
|
108
|
-
borderTopWidth
|
|
109
|
-
borderBottomWidth
|
|
110
|
-
borderLeftWidth
|
|
111
|
-
borderRightWidth
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
84
|
+
const {
|
|
85
|
+
overflow,
|
|
86
|
+
overflowClipMargin,
|
|
87
|
+
borderTopWidth,
|
|
88
|
+
borderBottomWidth,
|
|
89
|
+
borderLeftWidth,
|
|
90
|
+
borderRightWidth
|
|
91
|
+
} = getWin(ele).getComputedStyle(ele);
|
|
92
|
+
const eleRect = ele.getBoundingClientRect();
|
|
93
|
+
const {
|
|
94
|
+
offsetHeight: eleOutHeight,
|
|
95
|
+
clientHeight: eleInnerHeight,
|
|
96
|
+
offsetWidth: eleOutWidth,
|
|
97
|
+
clientWidth: eleInnerWidth
|
|
98
|
+
} = ele;
|
|
99
|
+
const borderTopNum = getPxValue(borderTopWidth);
|
|
100
|
+
const borderBottomNum = getPxValue(borderBottomWidth);
|
|
101
|
+
const borderLeftNum = getPxValue(borderLeftWidth);
|
|
102
|
+
const borderRightNum = getPxValue(borderRightWidth);
|
|
103
|
+
const scaleX = toNum(Math.round(eleRect.width / eleOutWidth * 1000) / 1000);
|
|
104
|
+
const scaleY = toNum(Math.round(eleRect.height / eleOutHeight * 1000) / 1000);
|
|
123
105
|
|
|
124
106
|
// Original visible area
|
|
125
|
-
|
|
126
|
-
|
|
107
|
+
const eleScrollWidth = (eleOutWidth - eleInnerWidth - borderLeftNum - borderRightNum) * scaleX;
|
|
108
|
+
const eleScrollHeight = (eleOutHeight - eleInnerHeight - borderTopNum - borderBottomNum) * scaleY;
|
|
127
109
|
|
|
128
110
|
// Cut border size
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
111
|
+
const scaledBorderTopWidth = borderTopNum * scaleY;
|
|
112
|
+
const scaledBorderBottomWidth = borderBottomNum * scaleY;
|
|
113
|
+
const scaledBorderLeftWidth = borderLeftNum * scaleX;
|
|
114
|
+
const scaledBorderRightWidth = borderRightNum * scaleX;
|
|
133
115
|
|
|
134
116
|
// Clip margin
|
|
135
|
-
|
|
136
|
-
|
|
117
|
+
let clipMarginWidth = 0;
|
|
118
|
+
let clipMarginHeight = 0;
|
|
137
119
|
if (overflow === 'clip') {
|
|
138
|
-
|
|
120
|
+
const clipNum = getPxValue(overflowClipMargin);
|
|
139
121
|
clipMarginWidth = clipNum * scaleX;
|
|
140
122
|
clipMarginHeight = clipNum * scaleY;
|
|
141
123
|
}
|
|
142
124
|
|
|
143
125
|
// Region
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
126
|
+
const eleLeft = eleRect.x + scaledBorderLeftWidth - clipMarginWidth;
|
|
127
|
+
const eleTop = eleRect.y + scaledBorderTopWidth - clipMarginHeight;
|
|
128
|
+
const eleRight = eleLeft + eleRect.width + 2 * clipMarginWidth - scaledBorderLeftWidth - scaledBorderRightWidth - eleScrollWidth;
|
|
129
|
+
const eleBottom = eleTop + eleRect.height + 2 * clipMarginHeight - scaledBorderTopWidth - scaledBorderBottomWidth - eleScrollHeight;
|
|
148
130
|
visibleArea.left = Math.max(visibleArea.left, eleLeft);
|
|
149
131
|
visibleArea.top = Math.max(visibleArea.top, eleTop);
|
|
150
132
|
visibleArea.right = Math.min(visibleArea.right, eleRight);
|
package/lib/Popup/Arrow.js
CHANGED
|
@@ -1,43 +1,47 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
|
|
4
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
5
3
|
Object.defineProperty(exports, "__esModule", {
|
|
6
4
|
value: true
|
|
7
5
|
});
|
|
8
6
|
exports.default = Arrow;
|
|
9
7
|
var _classnames = _interopRequireDefault(require("classnames"));
|
|
10
8
|
var React = _interopRequireWildcard(require("react"));
|
|
9
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
10
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
11
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
12
|
function Arrow(props) {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
13
|
+
const {
|
|
14
|
+
prefixCls,
|
|
15
|
+
align,
|
|
16
|
+
arrow,
|
|
17
|
+
arrowPos
|
|
18
|
+
} = props;
|
|
19
|
+
const {
|
|
20
|
+
className,
|
|
21
|
+
content
|
|
22
|
+
} = arrow || {};
|
|
23
|
+
const {
|
|
24
|
+
x = 0,
|
|
25
|
+
y = 0
|
|
26
|
+
} = arrowPos;
|
|
27
|
+
const arrowRef = React.useRef();
|
|
24
28
|
|
|
25
29
|
// Skip if no align
|
|
26
30
|
if (!align || !align.points) {
|
|
27
31
|
return null;
|
|
28
32
|
}
|
|
29
|
-
|
|
33
|
+
const alignStyle = {
|
|
30
34
|
position: 'absolute'
|
|
31
35
|
};
|
|
32
36
|
|
|
33
37
|
// Skip if no need to align
|
|
34
38
|
if (align.autoArrow !== false) {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
39
|
+
const popupPoints = align.points[0];
|
|
40
|
+
const targetPoints = align.points[1];
|
|
41
|
+
const popupTB = popupPoints[0];
|
|
42
|
+
const popupLR = popupPoints[1];
|
|
43
|
+
const targetTB = targetPoints[0];
|
|
44
|
+
const targetLR = targetPoints[1];
|
|
41
45
|
|
|
42
46
|
// Top & Bottom
|
|
43
47
|
if (popupTB === targetTB || !['t', 'b'].includes(popupTB)) {
|
|
@@ -59,7 +63,7 @@ function Arrow(props) {
|
|
|
59
63
|
}
|
|
60
64
|
return /*#__PURE__*/React.createElement("div", {
|
|
61
65
|
ref: arrowRef,
|
|
62
|
-
className: (0, _classnames.default)(
|
|
66
|
+
className: (0, _classnames.default)(`${prefixCls}-arrow`, className),
|
|
63
67
|
style: alignStyle
|
|
64
68
|
}, content);
|
|
65
69
|
}
|
package/lib/Popup/Mask.d.ts
CHANGED
package/lib/Popup/Mask.js
CHANGED
|
@@ -1,35 +1,37 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
|
|
4
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
5
3
|
Object.defineProperty(exports, "__esModule", {
|
|
6
4
|
value: true
|
|
7
5
|
});
|
|
8
6
|
exports.default = Mask;
|
|
9
|
-
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
10
7
|
var _classnames = _interopRequireDefault(require("classnames"));
|
|
11
|
-
var
|
|
8
|
+
var _motion = _interopRequireDefault(require("@rc-component/motion"));
|
|
12
9
|
var React = _interopRequireWildcard(require("react"));
|
|
10
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
11
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
12
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
|
+
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); }
|
|
13
14
|
function Mask(props) {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
15
|
+
const {
|
|
16
|
+
prefixCls,
|
|
17
|
+
open,
|
|
18
|
+
zIndex,
|
|
19
|
+
mask,
|
|
20
|
+
motion
|
|
21
|
+
} = props;
|
|
19
22
|
if (!mask) {
|
|
20
23
|
return null;
|
|
21
24
|
}
|
|
22
|
-
return /*#__PURE__*/React.createElement(
|
|
25
|
+
return /*#__PURE__*/React.createElement(_motion.default, _extends({}, motion, {
|
|
23
26
|
motionAppear: true,
|
|
24
27
|
visible: open,
|
|
25
28
|
removeOnLeave: true
|
|
26
|
-
}),
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
});
|
|
29
|
+
}), ({
|
|
30
|
+
className
|
|
31
|
+
}) => /*#__PURE__*/React.createElement("div", {
|
|
32
|
+
style: {
|
|
33
|
+
zIndex
|
|
34
|
+
},
|
|
35
|
+
className: (0, _classnames.default)(`${prefixCls}-mask`, className)
|
|
36
|
+
}));
|
|
35
37
|
}
|
|
@@ -1,17 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
|
|
4
3
|
Object.defineProperty(exports, "__esModule", {
|
|
5
4
|
value: true
|
|
6
5
|
});
|
|
7
6
|
exports.default = void 0;
|
|
8
7
|
var React = _interopRequireWildcard(require("react"));
|
|
9
|
-
var
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
});
|
|
8
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
9
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
10
|
+
const PopupContent = /*#__PURE__*/React.memo(({
|
|
11
|
+
children
|
|
12
|
+
}) => children, (_, next) => next.cache);
|
|
15
13
|
if (process.env.NODE_ENV !== 'production') {
|
|
16
14
|
PopupContent.displayName = 'PopupContent';
|
|
17
15
|
}
|
package/lib/Popup/index.d.ts
CHANGED
package/lib/Popup/index.js
CHANGED
|
@@ -1,73 +1,77 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
|
|
4
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
5
3
|
Object.defineProperty(exports, "__esModule", {
|
|
6
4
|
value: true
|
|
7
5
|
});
|
|
8
6
|
exports.default = void 0;
|
|
9
|
-
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
10
|
-
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
11
|
-
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
12
7
|
var _classnames = _interopRequireDefault(require("classnames"));
|
|
13
|
-
var
|
|
14
|
-
var
|
|
15
|
-
var _useLayoutEffect = _interopRequireDefault(require("rc-util/lib/hooks/useLayoutEffect"));
|
|
16
|
-
var
|
|
8
|
+
var _motion = _interopRequireDefault(require("@rc-component/motion"));
|
|
9
|
+
var _resizeObserver = _interopRequireDefault(require("@rc-component/resize-observer"));
|
|
10
|
+
var _useLayoutEffect = _interopRequireDefault(require("@rc-component/util/lib/hooks/useLayoutEffect"));
|
|
11
|
+
var _ref = require("@rc-component/util/lib/ref");
|
|
17
12
|
var React = _interopRequireWildcard(require("react"));
|
|
18
13
|
var _Arrow = _interopRequireDefault(require("./Arrow"));
|
|
19
14
|
var _Mask = _interopRequireDefault(require("./Mask"));
|
|
20
15
|
var _PopupContent = _interopRequireDefault(require("./PopupContent"));
|
|
21
|
-
var
|
|
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
|
-
|
|
16
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
17
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
18
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
19
|
+
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); }
|
|
20
|
+
const Popup = /*#__PURE__*/React.forwardRef((props, ref) => {
|
|
21
|
+
const {
|
|
22
|
+
popup,
|
|
23
|
+
className,
|
|
24
|
+
prefixCls,
|
|
25
|
+
style,
|
|
26
|
+
target,
|
|
27
|
+
onVisibleChanged,
|
|
28
|
+
// Open
|
|
29
|
+
open,
|
|
30
|
+
keepDom,
|
|
31
|
+
fresh,
|
|
32
|
+
// Click
|
|
33
|
+
onClick,
|
|
34
|
+
// Mask
|
|
35
|
+
mask,
|
|
36
|
+
// Arrow
|
|
37
|
+
arrow,
|
|
38
|
+
arrowPos,
|
|
39
|
+
align,
|
|
40
|
+
// Motion
|
|
41
|
+
motion,
|
|
42
|
+
maskMotion,
|
|
43
|
+
// Portal
|
|
44
|
+
forceRender,
|
|
45
|
+
getPopupContainer,
|
|
46
|
+
autoDestroy,
|
|
47
|
+
portal: Portal,
|
|
48
|
+
zIndex,
|
|
49
|
+
onMouseEnter,
|
|
50
|
+
onMouseLeave,
|
|
51
|
+
onPointerEnter,
|
|
52
|
+
onPointerDownCapture,
|
|
53
|
+
ready,
|
|
54
|
+
offsetX,
|
|
55
|
+
offsetY,
|
|
56
|
+
offsetR,
|
|
57
|
+
offsetB,
|
|
58
|
+
onAlign,
|
|
59
|
+
onPrepare,
|
|
60
|
+
stretch,
|
|
61
|
+
targetWidth,
|
|
62
|
+
targetHeight
|
|
63
|
+
} = props;
|
|
64
|
+
const childNode = typeof popup === 'function' ? popup() : popup;
|
|
58
65
|
|
|
59
66
|
// We can not remove holder only when motion finished.
|
|
60
|
-
|
|
67
|
+
const isNodeVisible = open || keepDom;
|
|
61
68
|
|
|
62
69
|
// ======================= Container ========================
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
_React$useState2 = (0, _slicedToArray2.default)(_React$useState, 2),
|
|
66
|
-
show = _React$useState2[0],
|
|
67
|
-
setShow = _React$useState2[1];
|
|
70
|
+
const getPopupContainerNeedParams = getPopupContainer?.length > 0;
|
|
71
|
+
const [show, setShow] = React.useState(!getPopupContainer || !getPopupContainerNeedParams);
|
|
68
72
|
|
|
69
73
|
// Delay to show since `getPopupContainer` need target element
|
|
70
|
-
(0, _useLayoutEffect.default)(
|
|
74
|
+
(0, _useLayoutEffect.default)(() => {
|
|
71
75
|
if (!show && getPopupContainerNeedParams && target) {
|
|
72
76
|
setShow(true);
|
|
73
77
|
}
|
|
@@ -79,8 +83,8 @@ var Popup = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
79
83
|
}
|
|
80
84
|
|
|
81
85
|
// >>>>> Offset
|
|
82
|
-
|
|
83
|
-
|
|
86
|
+
const AUTO = 'auto';
|
|
87
|
+
const offsetStyle = {
|
|
84
88
|
left: '-1000vw',
|
|
85
89
|
top: '-1000vh',
|
|
86
90
|
right: AUTO,
|
|
@@ -89,11 +93,12 @@ var Popup = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
89
93
|
|
|
90
94
|
// Set align style
|
|
91
95
|
if (ready || !open) {
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
96
|
+
const {
|
|
97
|
+
points
|
|
98
|
+
} = align;
|
|
99
|
+
const dynamicInset = align.dynamicInset || align._experimental?.dynamicInset;
|
|
100
|
+
const alignRight = dynamicInset && points[0][1] === 'r';
|
|
101
|
+
const alignBottom = dynamicInset && points[0][0] === 'b';
|
|
97
102
|
if (alignRight) {
|
|
98
103
|
offsetStyle.right = offsetR;
|
|
99
104
|
offsetStyle.left = AUTO;
|
|
@@ -111,7 +116,7 @@ var Popup = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
111
116
|
}
|
|
112
117
|
|
|
113
118
|
// >>>>> Misc
|
|
114
|
-
|
|
119
|
+
const miscStyle = {};
|
|
115
120
|
if (stretch) {
|
|
116
121
|
if (stretch.includes('height') && targetHeight) {
|
|
117
122
|
miscStyle.height = targetHeight;
|
|
@@ -129,9 +134,7 @@ var Popup = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
129
134
|
}
|
|
130
135
|
return /*#__PURE__*/React.createElement(Portal, {
|
|
131
136
|
open: forceRender || isNodeVisible,
|
|
132
|
-
getContainer: getPopupContainer &&
|
|
133
|
-
return getPopupContainer(target);
|
|
134
|
-
},
|
|
137
|
+
getContainer: getPopupContainer && (() => getPopupContainer(target)),
|
|
135
138
|
autoDestroy: autoDestroy
|
|
136
139
|
}, /*#__PURE__*/React.createElement(_Mask.default, {
|
|
137
140
|
prefixCls: prefixCls,
|
|
@@ -139,40 +142,43 @@ var Popup = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
139
142
|
zIndex: zIndex,
|
|
140
143
|
mask: mask,
|
|
141
144
|
motion: maskMotion
|
|
142
|
-
}), /*#__PURE__*/React.createElement(
|
|
145
|
+
}), /*#__PURE__*/React.createElement(_resizeObserver.default, {
|
|
143
146
|
onResize: onAlign,
|
|
144
147
|
disabled: !open
|
|
145
|
-
},
|
|
146
|
-
return /*#__PURE__*/React.createElement(
|
|
148
|
+
}, resizeObserverRef => {
|
|
149
|
+
return /*#__PURE__*/React.createElement(_motion.default, _extends({
|
|
147
150
|
motionAppear: true,
|
|
148
151
|
motionEnter: true,
|
|
149
152
|
motionLeave: true,
|
|
150
153
|
removeOnLeave: false,
|
|
151
154
|
forceRender: forceRender,
|
|
152
|
-
leavedClassName:
|
|
155
|
+
leavedClassName: `${prefixCls}-hidden`
|
|
153
156
|
}, motion, {
|
|
154
157
|
onAppearPrepare: onPrepare,
|
|
155
158
|
onEnterPrepare: onPrepare,
|
|
156
159
|
visible: open,
|
|
157
|
-
onVisibleChanged:
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
_onVisibleChanged(nextVisible);
|
|
160
|
+
onVisibleChanged: nextVisible => {
|
|
161
|
+
motion?.onVisibleChanged?.(nextVisible);
|
|
162
|
+
onVisibleChanged(nextVisible);
|
|
161
163
|
}
|
|
162
|
-
}),
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
164
|
+
}), ({
|
|
165
|
+
className: motionClassName,
|
|
166
|
+
style: motionStyle
|
|
167
|
+
}, motionRef) => {
|
|
168
|
+
const cls = (0, _classnames.default)(prefixCls, motionClassName, className);
|
|
166
169
|
return /*#__PURE__*/React.createElement("div", {
|
|
167
|
-
ref: (0,
|
|
170
|
+
ref: (0, _ref.composeRef)(resizeObserverRef, ref, motionRef),
|
|
168
171
|
className: cls,
|
|
169
|
-
style:
|
|
170
|
-
'--arrow-x':
|
|
171
|
-
'--arrow-y':
|
|
172
|
-
|
|
172
|
+
style: {
|
|
173
|
+
'--arrow-x': `${arrowPos.x || 0}px`,
|
|
174
|
+
'--arrow-y': `${arrowPos.y || 0}px`,
|
|
175
|
+
...offsetStyle,
|
|
176
|
+
...miscStyle,
|
|
177
|
+
...motionStyle,
|
|
173
178
|
boxSizing: 'border-box',
|
|
174
|
-
zIndex
|
|
175
|
-
|
|
179
|
+
zIndex,
|
|
180
|
+
...style
|
|
181
|
+
},
|
|
176
182
|
onMouseEnter: onMouseEnter,
|
|
177
183
|
onMouseLeave: onMouseLeave,
|
|
178
184
|
onPointerEnter: onPointerEnter,
|