@rc-component/trigger 1.7.0 → 1.7.2
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/hooks/useAlign.js +10 -30
- package/es/util.d.ts +18 -0
- package/es/util.js +41 -0
- package/lib/hooks/useAlign.js +11 -31
- package/lib/util.d.ts +18 -0
- package/lib/util.js +44 -0
- package/package.json +1 -1
package/es/hooks/useAlign.js
CHANGED
|
@@ -5,10 +5,7 @@ import isVisible from "rc-util/es/Dom/isVisible";
|
|
|
5
5
|
import useEvent from "rc-util/es/hooks/useEvent";
|
|
6
6
|
import useLayoutEffect from "rc-util/es/hooks/useLayoutEffect";
|
|
7
7
|
import * as React from 'react';
|
|
8
|
-
import { collectScroller, getWin } from "../util";
|
|
9
|
-
function toNum(num) {
|
|
10
|
-
return Number.isNaN(num) ? 1 : num;
|
|
11
|
-
}
|
|
8
|
+
import { collectScroller, getVisibleArea, getWin, toNum } from "../util";
|
|
12
9
|
function splitPoints() {
|
|
13
10
|
var points = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
|
|
14
11
|
return [points[0], points[1]];
|
|
@@ -141,26 +138,7 @@ export default function useAlign(open, popupEle, target, placement, builtinPlace
|
|
|
141
138
|
right: clientWidth,
|
|
142
139
|
bottom: clientHeight
|
|
143
140
|
};
|
|
144
|
-
|
|
145
|
-
if (ele instanceof HTMLBodyElement) {
|
|
146
|
-
return;
|
|
147
|
-
}
|
|
148
|
-
var eleRect = ele.getBoundingClientRect();
|
|
149
|
-
var eleOutHeight = ele.offsetHeight,
|
|
150
|
-
eleInnerHeight = ele.clientHeight,
|
|
151
|
-
eleOutWidth = ele.offsetWidth,
|
|
152
|
-
eleInnerWidth = ele.clientWidth;
|
|
153
|
-
var scaleX = toNum(Math.round(eleRect.width / eleOutWidth * 1000) / 1000);
|
|
154
|
-
var scaleY = toNum(Math.round(eleRect.height / eleOutHeight * 1000) / 1000);
|
|
155
|
-
var eleScrollWidth = (eleOutWidth - eleInnerWidth) * scaleX;
|
|
156
|
-
var eleScrollHeight = (eleOutHeight - eleInnerHeight) * scaleY;
|
|
157
|
-
var eleRight = eleRect.x + eleRect.width - eleScrollWidth;
|
|
158
|
-
var eleBottom = eleRect.y + eleRect.height - eleScrollHeight;
|
|
159
|
-
visibleArea.left = Math.max(visibleArea.left, eleRect.left);
|
|
160
|
-
visibleArea.top = Math.max(visibleArea.top, eleRect.top);
|
|
161
|
-
visibleArea.right = Math.min(visibleArea.right, eleRight);
|
|
162
|
-
visibleArea.bottom = Math.min(visibleArea.bottom, eleBottom);
|
|
163
|
-
});
|
|
141
|
+
visibleArea = getVisibleArea(visibleArea, scrollerList);
|
|
164
142
|
|
|
165
143
|
// Reset back
|
|
166
144
|
popupElement.style.left = originLeft;
|
|
@@ -212,14 +190,16 @@ export default function useAlign(open, popupEle, target, placement, builtinPlace
|
|
|
212
190
|
|
|
213
191
|
// ============== Intersection ===============
|
|
214
192
|
// Get area by position. Used for check if flip area is better
|
|
215
|
-
function getIntersectionVisibleArea(
|
|
216
|
-
var
|
|
217
|
-
var
|
|
218
|
-
var
|
|
219
|
-
var
|
|
193
|
+
function getIntersectionVisibleArea(offsetX, offsetY) {
|
|
194
|
+
var l = popupRect.x + offsetX;
|
|
195
|
+
var t = popupRect.y + offsetY;
|
|
196
|
+
var r = l + popupWidth;
|
|
197
|
+
var b = t + popupHeight;
|
|
198
|
+
var visibleL = Math.max(l, visibleArea.left);
|
|
199
|
+
var visibleT = Math.max(t, visibleArea.top);
|
|
220
200
|
var visibleR = Math.min(r, visibleArea.right);
|
|
221
201
|
var visibleB = Math.min(b, visibleArea.bottom);
|
|
222
|
-
return (visibleR -
|
|
202
|
+
return (visibleR - visibleL) * (visibleB - visibleT);
|
|
223
203
|
}
|
|
224
204
|
var originIntersectionVisibleArea = getIntersectionVisibleArea(nextOffsetX, nextOffsetY);
|
|
225
205
|
|
package/es/util.d.ts
CHANGED
|
@@ -4,4 +4,22 @@ export declare function getAlignPopupClassName(builtinPlacements: BuildInPlaceme
|
|
|
4
4
|
/** @deprecated We should not use this if we can refactor all deps */
|
|
5
5
|
export declare function getMotion(prefixCls: string, motion: CSSMotionProps, animation: AnimationType, transitionName: TransitionNameType): CSSMotionProps;
|
|
6
6
|
export declare function getWin(ele: HTMLElement): Window & typeof globalThis;
|
|
7
|
+
/**
|
|
8
|
+
* Get all the scrollable parent elements of the element
|
|
9
|
+
* @param ele The element to be detected
|
|
10
|
+
* @param areaOnly Only return the parent which will cut visible area
|
|
11
|
+
*/
|
|
7
12
|
export declare function collectScroller(ele: HTMLElement): HTMLElement[];
|
|
13
|
+
export declare function toNum(num: number): number;
|
|
14
|
+
export interface VisibleArea {
|
|
15
|
+
left: number;
|
|
16
|
+
top: number;
|
|
17
|
+
right: number;
|
|
18
|
+
bottom: number;
|
|
19
|
+
}
|
|
20
|
+
export declare function getVisibleArea(initArea: VisibleArea, scrollerList?: HTMLElement[]): {
|
|
21
|
+
left: number;
|
|
22
|
+
top: number;
|
|
23
|
+
right: number;
|
|
24
|
+
bottom: number;
|
|
25
|
+
};
|
package/es/util.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
1
2
|
function isPointsEq() {
|
|
2
3
|
var a1 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
3
4
|
var a2 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
|
|
@@ -40,6 +41,12 @@ export function getMotion(prefixCls, motion, animation, transitionName) {
|
|
|
40
41
|
export function getWin(ele) {
|
|
41
42
|
return ele.ownerDocument.defaultView;
|
|
42
43
|
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Get all the scrollable parent elements of the element
|
|
47
|
+
* @param ele The element to be detected
|
|
48
|
+
* @param areaOnly Only return the parent which will cut visible area
|
|
49
|
+
*/
|
|
43
50
|
export function collectScroller(ele) {
|
|
44
51
|
var scrollerList = [];
|
|
45
52
|
var current = ele === null || ele === void 0 ? void 0 : ele.parentElement;
|
|
@@ -54,4 +61,38 @@ export function collectScroller(ele) {
|
|
|
54
61
|
current = current.parentElement;
|
|
55
62
|
}
|
|
56
63
|
return scrollerList;
|
|
64
|
+
}
|
|
65
|
+
export function toNum(num) {
|
|
66
|
+
return Number.isNaN(num) ? 1 : num;
|
|
67
|
+
}
|
|
68
|
+
export function getVisibleArea(initArea, scrollerList) {
|
|
69
|
+
var visibleArea = _objectSpread({}, initArea);
|
|
70
|
+
(scrollerList || []).forEach(function (ele) {
|
|
71
|
+
if (ele instanceof HTMLBodyElement) {
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// Skip if static position which will not affect visible area
|
|
76
|
+
var _getWin$getComputedSt2 = getWin(ele).getComputedStyle(ele),
|
|
77
|
+
position = _getWin$getComputedSt2.position;
|
|
78
|
+
if (position === 'static') {
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
var eleRect = ele.getBoundingClientRect();
|
|
82
|
+
var eleOutHeight = ele.offsetHeight,
|
|
83
|
+
eleInnerHeight = ele.clientHeight,
|
|
84
|
+
eleOutWidth = ele.offsetWidth,
|
|
85
|
+
eleInnerWidth = ele.clientWidth;
|
|
86
|
+
var scaleX = toNum(Math.round(eleRect.width / eleOutWidth * 1000) / 1000);
|
|
87
|
+
var scaleY = toNum(Math.round(eleRect.height / eleOutHeight * 1000) / 1000);
|
|
88
|
+
var eleScrollWidth = (eleOutWidth - eleInnerWidth) * scaleX;
|
|
89
|
+
var eleScrollHeight = (eleOutHeight - eleInnerHeight) * scaleY;
|
|
90
|
+
var eleRight = eleRect.x + eleRect.width - eleScrollWidth;
|
|
91
|
+
var eleBottom = eleRect.y + eleRect.height - eleScrollHeight;
|
|
92
|
+
visibleArea.left = Math.max(visibleArea.left, eleRect.x);
|
|
93
|
+
visibleArea.top = Math.max(visibleArea.top, eleRect.y);
|
|
94
|
+
visibleArea.right = Math.min(visibleArea.right, eleRight);
|
|
95
|
+
visibleArea.bottom = Math.min(visibleArea.bottom, eleBottom);
|
|
96
|
+
});
|
|
97
|
+
return visibleArea;
|
|
57
98
|
}
|
package/lib/hooks/useAlign.js
CHANGED
|
@@ -14,9 +14,6 @@ var _useEvent = _interopRequireDefault(require("rc-util/lib/hooks/useEvent"));
|
|
|
14
14
|
var _useLayoutEffect = _interopRequireDefault(require("rc-util/lib/hooks/useLayoutEffect"));
|
|
15
15
|
var React = _interopRequireWildcard(require("react"));
|
|
16
16
|
var _util = require("../util");
|
|
17
|
-
function toNum(num) {
|
|
18
|
-
return Number.isNaN(num) ? 1 : num;
|
|
19
|
-
}
|
|
20
17
|
function splitPoints() {
|
|
21
18
|
var points = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
|
|
22
19
|
return [points[0], points[1]];
|
|
@@ -149,34 +146,15 @@ function useAlign(open, popupEle, target, placement, builtinPlacements, popupAli
|
|
|
149
146
|
right: clientWidth,
|
|
150
147
|
bottom: clientHeight
|
|
151
148
|
};
|
|
152
|
-
(
|
|
153
|
-
if (ele instanceof HTMLBodyElement) {
|
|
154
|
-
return;
|
|
155
|
-
}
|
|
156
|
-
var eleRect = ele.getBoundingClientRect();
|
|
157
|
-
var eleOutHeight = ele.offsetHeight,
|
|
158
|
-
eleInnerHeight = ele.clientHeight,
|
|
159
|
-
eleOutWidth = ele.offsetWidth,
|
|
160
|
-
eleInnerWidth = ele.clientWidth;
|
|
161
|
-
var scaleX = toNum(Math.round(eleRect.width / eleOutWidth * 1000) / 1000);
|
|
162
|
-
var scaleY = toNum(Math.round(eleRect.height / eleOutHeight * 1000) / 1000);
|
|
163
|
-
var eleScrollWidth = (eleOutWidth - eleInnerWidth) * scaleX;
|
|
164
|
-
var eleScrollHeight = (eleOutHeight - eleInnerHeight) * scaleY;
|
|
165
|
-
var eleRight = eleRect.x + eleRect.width - eleScrollWidth;
|
|
166
|
-
var eleBottom = eleRect.y + eleRect.height - eleScrollHeight;
|
|
167
|
-
visibleArea.left = Math.max(visibleArea.left, eleRect.left);
|
|
168
|
-
visibleArea.top = Math.max(visibleArea.top, eleRect.top);
|
|
169
|
-
visibleArea.right = Math.min(visibleArea.right, eleRight);
|
|
170
|
-
visibleArea.bottom = Math.min(visibleArea.bottom, eleBottom);
|
|
171
|
-
});
|
|
149
|
+
visibleArea = (0, _util.getVisibleArea)(visibleArea, scrollerList);
|
|
172
150
|
|
|
173
151
|
// Reset back
|
|
174
152
|
popupElement.style.left = originLeft;
|
|
175
153
|
popupElement.style.top = originTop;
|
|
176
154
|
|
|
177
155
|
// Calculate scale
|
|
178
|
-
var _scaleX = toNum(Math.round(popupWidth / parseFloat(width) * 1000) / 1000);
|
|
179
|
-
var _scaleY = toNum(Math.round(popupHeight / parseFloat(height) * 1000) / 1000);
|
|
156
|
+
var _scaleX = (0, _util.toNum)(Math.round(popupWidth / parseFloat(width) * 1000) / 1000);
|
|
157
|
+
var _scaleY = (0, _util.toNum)(Math.round(popupHeight / parseFloat(height) * 1000) / 1000);
|
|
180
158
|
|
|
181
159
|
// No need to align since it's not visible in view
|
|
182
160
|
if (_scaleX === 0 || _scaleY === 0 || (0, _findDOMNode.isDOM)(target) && !(0, _isVisible.default)(target)) {
|
|
@@ -220,14 +198,16 @@ function useAlign(open, popupEle, target, placement, builtinPlacements, popupAli
|
|
|
220
198
|
|
|
221
199
|
// ============== Intersection ===============
|
|
222
200
|
// Get area by position. Used for check if flip area is better
|
|
223
|
-
function getIntersectionVisibleArea(
|
|
224
|
-
var
|
|
225
|
-
var
|
|
226
|
-
var
|
|
227
|
-
var
|
|
201
|
+
function getIntersectionVisibleArea(offsetX, offsetY) {
|
|
202
|
+
var l = popupRect.x + offsetX;
|
|
203
|
+
var t = popupRect.y + offsetY;
|
|
204
|
+
var r = l + popupWidth;
|
|
205
|
+
var b = t + popupHeight;
|
|
206
|
+
var visibleL = Math.max(l, visibleArea.left);
|
|
207
|
+
var visibleT = Math.max(t, visibleArea.top);
|
|
228
208
|
var visibleR = Math.min(r, visibleArea.right);
|
|
229
209
|
var visibleB = Math.min(b, visibleArea.bottom);
|
|
230
|
-
return (visibleR -
|
|
210
|
+
return (visibleR - visibleL) * (visibleB - visibleT);
|
|
231
211
|
}
|
|
232
212
|
var originIntersectionVisibleArea = getIntersectionVisibleArea(nextOffsetX, nextOffsetY);
|
|
233
213
|
|
package/lib/util.d.ts
CHANGED
|
@@ -4,4 +4,22 @@ export declare function getAlignPopupClassName(builtinPlacements: BuildInPlaceme
|
|
|
4
4
|
/** @deprecated We should not use this if we can refactor all deps */
|
|
5
5
|
export declare function getMotion(prefixCls: string, motion: CSSMotionProps, animation: AnimationType, transitionName: TransitionNameType): CSSMotionProps;
|
|
6
6
|
export declare function getWin(ele: HTMLElement): Window & typeof globalThis;
|
|
7
|
+
/**
|
|
8
|
+
* Get all the scrollable parent elements of the element
|
|
9
|
+
* @param ele The element to be detected
|
|
10
|
+
* @param areaOnly Only return the parent which will cut visible area
|
|
11
|
+
*/
|
|
7
12
|
export declare function collectScroller(ele: HTMLElement): HTMLElement[];
|
|
13
|
+
export declare function toNum(num: number): number;
|
|
14
|
+
export interface VisibleArea {
|
|
15
|
+
left: number;
|
|
16
|
+
top: number;
|
|
17
|
+
right: number;
|
|
18
|
+
bottom: number;
|
|
19
|
+
}
|
|
20
|
+
export declare function getVisibleArea(initArea: VisibleArea, scrollerList?: HTMLElement[]): {
|
|
21
|
+
left: number;
|
|
22
|
+
top: number;
|
|
23
|
+
right: number;
|
|
24
|
+
bottom: number;
|
|
25
|
+
};
|
package/lib/util.js
CHANGED
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
3
4
|
Object.defineProperty(exports, "__esModule", {
|
|
4
5
|
value: true
|
|
5
6
|
});
|
|
6
7
|
exports.collectScroller = collectScroller;
|
|
7
8
|
exports.getAlignPopupClassName = getAlignPopupClassName;
|
|
8
9
|
exports.getMotion = getMotion;
|
|
10
|
+
exports.getVisibleArea = getVisibleArea;
|
|
9
11
|
exports.getWin = getWin;
|
|
12
|
+
exports.toNum = toNum;
|
|
13
|
+
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
10
14
|
function isPointsEq() {
|
|
11
15
|
var a1 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
12
16
|
var a2 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
|
|
@@ -49,6 +53,12 @@ function getMotion(prefixCls, motion, animation, transitionName) {
|
|
|
49
53
|
function getWin(ele) {
|
|
50
54
|
return ele.ownerDocument.defaultView;
|
|
51
55
|
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Get all the scrollable parent elements of the element
|
|
59
|
+
* @param ele The element to be detected
|
|
60
|
+
* @param areaOnly Only return the parent which will cut visible area
|
|
61
|
+
*/
|
|
52
62
|
function collectScroller(ele) {
|
|
53
63
|
var scrollerList = [];
|
|
54
64
|
var current = ele === null || ele === void 0 ? void 0 : ele.parentElement;
|
|
@@ -63,4 +73,38 @@ function collectScroller(ele) {
|
|
|
63
73
|
current = current.parentElement;
|
|
64
74
|
}
|
|
65
75
|
return scrollerList;
|
|
76
|
+
}
|
|
77
|
+
function toNum(num) {
|
|
78
|
+
return Number.isNaN(num) ? 1 : num;
|
|
79
|
+
}
|
|
80
|
+
function getVisibleArea(initArea, scrollerList) {
|
|
81
|
+
var visibleArea = (0, _objectSpread2.default)({}, initArea);
|
|
82
|
+
(scrollerList || []).forEach(function (ele) {
|
|
83
|
+
if (ele instanceof HTMLBodyElement) {
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// Skip if static position which will not affect visible area
|
|
88
|
+
var _getWin$getComputedSt2 = getWin(ele).getComputedStyle(ele),
|
|
89
|
+
position = _getWin$getComputedSt2.position;
|
|
90
|
+
if (position === 'static') {
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
var eleRect = ele.getBoundingClientRect();
|
|
94
|
+
var eleOutHeight = ele.offsetHeight,
|
|
95
|
+
eleInnerHeight = ele.clientHeight,
|
|
96
|
+
eleOutWidth = ele.offsetWidth,
|
|
97
|
+
eleInnerWidth = ele.clientWidth;
|
|
98
|
+
var scaleX = toNum(Math.round(eleRect.width / eleOutWidth * 1000) / 1000);
|
|
99
|
+
var scaleY = toNum(Math.round(eleRect.height / eleOutHeight * 1000) / 1000);
|
|
100
|
+
var eleScrollWidth = (eleOutWidth - eleInnerWidth) * scaleX;
|
|
101
|
+
var eleScrollHeight = (eleOutHeight - eleInnerHeight) * scaleY;
|
|
102
|
+
var eleRight = eleRect.x + eleRect.width - eleScrollWidth;
|
|
103
|
+
var eleBottom = eleRect.y + eleRect.height - eleScrollHeight;
|
|
104
|
+
visibleArea.left = Math.max(visibleArea.left, eleRect.x);
|
|
105
|
+
visibleArea.top = Math.max(visibleArea.top, eleRect.y);
|
|
106
|
+
visibleArea.right = Math.min(visibleArea.right, eleRight);
|
|
107
|
+
visibleArea.bottom = Math.min(visibleArea.bottom, eleBottom);
|
|
108
|
+
});
|
|
109
|
+
return visibleArea;
|
|
66
110
|
}
|