@rc-component/trigger 2.2.6 → 3.1.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 +11 -12
package/lib/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';
|
package/lib/mock.js
CHANGED
|
@@ -1,27 +1,24 @@
|
|
|
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 _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
10
7
|
var React = _interopRequireWildcard(require("react"));
|
|
11
8
|
var _index = require("./index");
|
|
12
|
-
var
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
React.useEffect(
|
|
22
|
-
getContainer
|
|
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
|
+
const MockPortal = ({
|
|
12
|
+
open,
|
|
13
|
+
autoDestroy,
|
|
14
|
+
children,
|
|
15
|
+
getContainer
|
|
16
|
+
}) => {
|
|
17
|
+
const [visible, setVisible] = React.useState(open);
|
|
18
|
+
React.useEffect(() => {
|
|
19
|
+
getContainer?.();
|
|
23
20
|
});
|
|
24
|
-
React.useEffect(
|
|
21
|
+
React.useEffect(() => {
|
|
25
22
|
if (open) {
|
|
26
23
|
setVisible(true);
|
|
27
24
|
} else if (autoDestroy) {
|
package/lib/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/lib/util.js
CHANGED
|
@@ -1,55 +1,32 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
3
|
Object.defineProperty(exports, "__esModule", {
|
|
5
4
|
value: true
|
|
6
5
|
});
|
|
7
6
|
exports.collectScroller = collectScroller;
|
|
8
7
|
exports.getAlignPopupClassName = getAlignPopupClassName;
|
|
9
|
-
exports.getMotion = getMotion;
|
|
10
8
|
exports.getVisibleArea = getVisibleArea;
|
|
11
9
|
exports.getWin = getWin;
|
|
12
10
|
exports.toNum = toNum;
|
|
13
|
-
|
|
14
|
-
function isPointsEq() {
|
|
15
|
-
var a1 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
16
|
-
var a2 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
|
|
17
|
-
var isAlignPoint = arguments.length > 2 ? arguments[2] : undefined;
|
|
11
|
+
function isPointsEq(a1 = [], a2 = [], isAlignPoint) {
|
|
18
12
|
if (isAlignPoint) {
|
|
19
13
|
return a1[0] === a2[0];
|
|
20
14
|
}
|
|
21
15
|
return a1[0] === a2[0] && a1[1] === a2[1];
|
|
22
16
|
}
|
|
23
17
|
function getAlignPopupClassName(builtinPlacements, prefixCls, align, isAlignPoint) {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
18
|
+
const {
|
|
19
|
+
points
|
|
20
|
+
} = align;
|
|
21
|
+
const placements = Object.keys(builtinPlacements);
|
|
22
|
+
for (let i = 0; i < placements.length; i += 1) {
|
|
23
|
+
const placement = placements[i];
|
|
24
|
+
if (isPointsEq(builtinPlacements[placement]?.points, points, isAlignPoint)) {
|
|
25
|
+
return `${prefixCls}-placement-${placement}`;
|
|
31
26
|
}
|
|
32
27
|
}
|
|
33
28
|
return '';
|
|
34
29
|
}
|
|
35
|
-
|
|
36
|
-
/** @deprecated We should not use this if we can refactor all deps */
|
|
37
|
-
function getMotion(prefixCls, motion, animation, transitionName) {
|
|
38
|
-
if (motion) {
|
|
39
|
-
return motion;
|
|
40
|
-
}
|
|
41
|
-
if (animation) {
|
|
42
|
-
return {
|
|
43
|
-
motionName: "".concat(prefixCls, "-").concat(animation)
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
if (transitionName) {
|
|
47
|
-
return {
|
|
48
|
-
motionName: transitionName
|
|
49
|
-
};
|
|
50
|
-
}
|
|
51
|
-
return null;
|
|
52
|
-
}
|
|
53
30
|
function getWin(ele) {
|
|
54
31
|
return ele.ownerDocument.defaultView;
|
|
55
32
|
}
|
|
@@ -60,25 +37,23 @@ function getWin(ele) {
|
|
|
60
37
|
* @param areaOnly Only return the parent which will cut visible area
|
|
61
38
|
*/
|
|
62
39
|
function collectScroller(ele) {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
40
|
+
const scrollerList = [];
|
|
41
|
+
let current = ele?.parentElement;
|
|
42
|
+
const scrollStyle = ['hidden', 'scroll', 'clip', 'auto'];
|
|
66
43
|
while (current) {
|
|
67
|
-
|
|
68
|
-
overflowX
|
|
69
|
-
overflowY
|
|
70
|
-
overflow
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
})) {
|
|
44
|
+
const {
|
|
45
|
+
overflowX,
|
|
46
|
+
overflowY,
|
|
47
|
+
overflow
|
|
48
|
+
} = getWin(current).getComputedStyle(current);
|
|
49
|
+
if ([overflowX, overflowY, overflow].some(o => scrollStyle.includes(o))) {
|
|
74
50
|
scrollerList.push(current);
|
|
75
51
|
}
|
|
76
52
|
current = current.parentElement;
|
|
77
53
|
}
|
|
78
54
|
return scrollerList;
|
|
79
55
|
}
|
|
80
|
-
function toNum(num) {
|
|
81
|
-
var defaultValue = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
|
|
56
|
+
function toNum(num, defaultValue = 1) {
|
|
82
57
|
return Number.isNaN(num) ? defaultValue : num;
|
|
83
58
|
}
|
|
84
59
|
function getPxValue(val) {
|
|
@@ -107,56 +82,61 @@ function getPxValue(val) {
|
|
|
107
82
|
* Get visible area of element
|
|
108
83
|
*/
|
|
109
84
|
function getVisibleArea(initArea, scrollerList) {
|
|
110
|
-
|
|
111
|
-
|
|
85
|
+
const visibleArea = {
|
|
86
|
+
...initArea
|
|
87
|
+
};
|
|
88
|
+
(scrollerList || []).forEach(ele => {
|
|
112
89
|
if (ele instanceof HTMLBodyElement || ele instanceof HTMLHtmlElement) {
|
|
113
90
|
return;
|
|
114
91
|
}
|
|
115
92
|
|
|
116
93
|
// Skip if static position which will not affect visible area
|
|
117
|
-
|
|
118
|
-
overflow
|
|
119
|
-
overflowClipMargin
|
|
120
|
-
borderTopWidth
|
|
121
|
-
borderBottomWidth
|
|
122
|
-
borderLeftWidth
|
|
123
|
-
borderRightWidth
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
94
|
+
const {
|
|
95
|
+
overflow,
|
|
96
|
+
overflowClipMargin,
|
|
97
|
+
borderTopWidth,
|
|
98
|
+
borderBottomWidth,
|
|
99
|
+
borderLeftWidth,
|
|
100
|
+
borderRightWidth
|
|
101
|
+
} = getWin(ele).getComputedStyle(ele);
|
|
102
|
+
const eleRect = ele.getBoundingClientRect();
|
|
103
|
+
const {
|
|
104
|
+
offsetHeight: eleOutHeight,
|
|
105
|
+
clientHeight: eleInnerHeight,
|
|
106
|
+
offsetWidth: eleOutWidth,
|
|
107
|
+
clientWidth: eleInnerWidth
|
|
108
|
+
} = ele;
|
|
109
|
+
const borderTopNum = getPxValue(borderTopWidth);
|
|
110
|
+
const borderBottomNum = getPxValue(borderBottomWidth);
|
|
111
|
+
const borderLeftNum = getPxValue(borderLeftWidth);
|
|
112
|
+
const borderRightNum = getPxValue(borderRightWidth);
|
|
113
|
+
const scaleX = toNum(Math.round(eleRect.width / eleOutWidth * 1000) / 1000);
|
|
114
|
+
const scaleY = toNum(Math.round(eleRect.height / eleOutHeight * 1000) / 1000);
|
|
135
115
|
|
|
136
116
|
// Original visible area
|
|
137
|
-
|
|
138
|
-
|
|
117
|
+
const eleScrollWidth = (eleOutWidth - eleInnerWidth - borderLeftNum - borderRightNum) * scaleX;
|
|
118
|
+
const eleScrollHeight = (eleOutHeight - eleInnerHeight - borderTopNum - borderBottomNum) * scaleY;
|
|
139
119
|
|
|
140
120
|
// Cut border size
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
121
|
+
const scaledBorderTopWidth = borderTopNum * scaleY;
|
|
122
|
+
const scaledBorderBottomWidth = borderBottomNum * scaleY;
|
|
123
|
+
const scaledBorderLeftWidth = borderLeftNum * scaleX;
|
|
124
|
+
const scaledBorderRightWidth = borderRightNum * scaleX;
|
|
145
125
|
|
|
146
126
|
// Clip margin
|
|
147
|
-
|
|
148
|
-
|
|
127
|
+
let clipMarginWidth = 0;
|
|
128
|
+
let clipMarginHeight = 0;
|
|
149
129
|
if (overflow === 'clip') {
|
|
150
|
-
|
|
130
|
+
const clipNum = getPxValue(overflowClipMargin);
|
|
151
131
|
clipMarginWidth = clipNum * scaleX;
|
|
152
132
|
clipMarginHeight = clipNum * scaleY;
|
|
153
133
|
}
|
|
154
134
|
|
|
155
135
|
// Region
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
136
|
+
const eleLeft = eleRect.x + scaledBorderLeftWidth - clipMarginWidth;
|
|
137
|
+
const eleTop = eleRect.y + scaledBorderTopWidth - clipMarginHeight;
|
|
138
|
+
const eleRight = eleLeft + eleRect.width + 2 * clipMarginWidth - scaledBorderLeftWidth - scaledBorderRightWidth - eleScrollWidth;
|
|
139
|
+
const eleBottom = eleTop + eleRect.height + 2 * clipMarginHeight - scaledBorderTopWidth - scaledBorderBottomWidth - eleScrollHeight;
|
|
160
140
|
visibleArea.left = Math.max(visibleArea.left, eleLeft);
|
|
161
141
|
visibleArea.top = Math.max(visibleArea.top, eleTop);
|
|
162
142
|
visibleArea.right = Math.min(visibleArea.right, eleRight);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rc-component/trigger",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.1.0",
|
|
4
4
|
"description": "base abstract trigger component for react",
|
|
5
5
|
"engines": {
|
|
6
6
|
"node": ">=8.x"
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
"start": "dumi dev",
|
|
34
34
|
"build": "dumi build",
|
|
35
35
|
"compile": "father build && lessc assets/index.less assets/index.css",
|
|
36
|
-
"prepublishOnly": "npm run compile && np
|
|
36
|
+
"prepublishOnly": "npm run compile && rc-np",
|
|
37
37
|
"lint": "eslint src/ docs/examples/ --ext .tsx,.ts,.jsx,.js",
|
|
38
38
|
"test": "rc-test",
|
|
39
39
|
"prettier": "prettier --write .",
|
|
@@ -41,21 +41,21 @@
|
|
|
41
41
|
"now-build": "npm run build"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
|
-
"@rc-component/father-plugin": "^
|
|
44
|
+
"@rc-component/father-plugin": "^2.0.0",
|
|
45
|
+
"@rc-component/np": "^1.0.3",
|
|
45
46
|
"@testing-library/jest-dom": "^6.1.4",
|
|
46
47
|
"@testing-library/react": "^16.0.0",
|
|
47
48
|
"@types/classnames": "^2.2.10",
|
|
48
49
|
"@types/jest": "^29.5.2",
|
|
49
50
|
"@types/node": "^22.0.2",
|
|
50
51
|
"@types/react": "^18.0.0",
|
|
51
|
-
"@types/react-dom": "^18.0.
|
|
52
|
+
"@types/react-dom": "^18.0.0",
|
|
52
53
|
"@umijs/fabric": "^4.0.1",
|
|
53
54
|
"cross-env": "^7.0.1",
|
|
54
55
|
"dumi": "^2.1.0",
|
|
55
56
|
"eslint": "^8.51.0",
|
|
56
57
|
"father": "^4.0.0",
|
|
57
58
|
"less": "^4.2.0",
|
|
58
|
-
"np": "^10.0.5",
|
|
59
59
|
"prettier": "^3.3.3",
|
|
60
60
|
"rc-test": "^7.0.13",
|
|
61
61
|
"react": "^18.0.0",
|
|
@@ -64,15 +64,14 @@
|
|
|
64
64
|
"typescript": "^5.1.6"
|
|
65
65
|
},
|
|
66
66
|
"dependencies": {
|
|
67
|
-
"@
|
|
68
|
-
"@rc-component/portal": "^
|
|
69
|
-
"
|
|
70
|
-
"rc-
|
|
71
|
-
"
|
|
72
|
-
"rc-util": "^5.44.0"
|
|
67
|
+
"@rc-component/motion": "^1.1.4",
|
|
68
|
+
"@rc-component/portal": "^2.0.0",
|
|
69
|
+
"@rc-component/resize-observer": "^1.0.0",
|
|
70
|
+
"@rc-component/util": "^1.2.1",
|
|
71
|
+
"classnames": "^2.3.2"
|
|
73
72
|
},
|
|
74
73
|
"peerDependencies": {
|
|
75
74
|
"react": ">=16.9.0",
|
|
76
75
|
"react-dom": ">=16.9.0"
|
|
77
76
|
}
|
|
78
|
-
}
|
|
77
|
+
}
|