@rc-component/trigger 1.2.0 → 1.3.1
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 +62 -23
- package/es/hooks/useWatch.js +1 -16
- package/es/util.d.ts +1 -1
- package/es/util.js +15 -5
- package/lib/hooks/useAlign.js +61 -22
- package/lib/hooks/useWatch.js +2 -17
- package/lib/util.d.ts +1 -1
- package/lib/util.js +16 -7
- package/package.json +2 -2
package/es/hooks/useAlign.js
CHANGED
|
@@ -3,7 +3,7 @@ import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
|
3
3
|
import useEvent from "rc-util/es/hooks/useEvent";
|
|
4
4
|
import useLayoutEffect from "rc-util/es/hooks/useLayoutEffect";
|
|
5
5
|
import * as React from 'react';
|
|
6
|
-
import { getWin } from "../util";
|
|
6
|
+
import { collectScroller, getWin } from "../util";
|
|
7
7
|
function toNum(num) {
|
|
8
8
|
return Number.isNaN(num) ? 1 : num;
|
|
9
9
|
}
|
|
@@ -68,6 +68,14 @@ export default function useAlign(open, popupEle, target, placement, builtinPlace
|
|
|
68
68
|
offsetInfo = _React$useState2[0],
|
|
69
69
|
setOffsetInfo = _React$useState2[1];
|
|
70
70
|
var alignCountRef = React.useRef(0);
|
|
71
|
+
var scrollerList = React.useMemo(function () {
|
|
72
|
+
if (!popupEle) {
|
|
73
|
+
return [];
|
|
74
|
+
}
|
|
75
|
+
return collectScroller(popupEle);
|
|
76
|
+
}, [popupEle]);
|
|
77
|
+
|
|
78
|
+
// ========================= Align =========================
|
|
71
79
|
var onAlign = useEvent(function () {
|
|
72
80
|
if (popupEle && target && open) {
|
|
73
81
|
var popupElement = popupEle;
|
|
@@ -108,6 +116,31 @@ export default function useAlign(open, popupEle, target, placement, builtinPlace
|
|
|
108
116
|
var popupHeight = popupRect.height;
|
|
109
117
|
var popupWidth = popupRect.width;
|
|
110
118
|
|
|
119
|
+
// Get bounding of visible area
|
|
120
|
+
var visibleArea = {
|
|
121
|
+
left: 0,
|
|
122
|
+
top: 0,
|
|
123
|
+
right: clientWidth,
|
|
124
|
+
bottom: clientHeight
|
|
125
|
+
};
|
|
126
|
+
(scrollerList || []).forEach(function (ele) {
|
|
127
|
+
var eleRect = ele.getBoundingClientRect();
|
|
128
|
+
var eleOutHeight = ele.offsetHeight,
|
|
129
|
+
eleInnerHeight = ele.clientHeight,
|
|
130
|
+
eleOutWidth = ele.offsetWidth,
|
|
131
|
+
eleInnerWidth = ele.clientWidth;
|
|
132
|
+
var scaleX = toNum(Math.round(eleRect.width / eleOutWidth * 1000) / 1000);
|
|
133
|
+
var scaleY = toNum(Math.round(eleRect.height / eleOutHeight * 1000) / 1000);
|
|
134
|
+
var scrollWidth = (eleOutWidth - eleInnerWidth) * scaleX;
|
|
135
|
+
var scrollHeight = (eleOutHeight - eleInnerHeight) * scaleY;
|
|
136
|
+
var eleRight = eleRect.x + eleRect.width - scrollWidth;
|
|
137
|
+
var eleBottom = eleRect.y + eleRect.height - scrollHeight;
|
|
138
|
+
visibleArea.left = Math.max(visibleArea.left, eleRect.left);
|
|
139
|
+
visibleArea.top = Math.max(visibleArea.top, eleRect.top);
|
|
140
|
+
visibleArea.right = Math.min(visibleArea.right, eleRight);
|
|
141
|
+
visibleArea.bottom = Math.min(visibleArea.bottom, eleBottom);
|
|
142
|
+
});
|
|
143
|
+
|
|
111
144
|
// Reset back
|
|
112
145
|
popupElement.style.left = originLeft;
|
|
113
146
|
popupElement.style.top = originTop;
|
|
@@ -164,20 +197,26 @@ export default function useAlign(open, popupEle, target, placement, builtinPlace
|
|
|
164
197
|
adjustY = overflow.adjustY,
|
|
165
198
|
shiftX = overflow.shiftX,
|
|
166
199
|
shiftY = overflow.shiftY;
|
|
200
|
+
var supportAdjust = function supportAdjust(val) {
|
|
201
|
+
if (typeof val === 'boolean') {
|
|
202
|
+
return val;
|
|
203
|
+
}
|
|
204
|
+
return val >= 0;
|
|
205
|
+
};
|
|
167
206
|
|
|
168
207
|
// >>>>>>>>>> Top & Bottom
|
|
169
208
|
var nextPopupY = popupRect.y + nextOffsetY;
|
|
170
209
|
var nextPopupBottom = nextPopupY + popupHeight;
|
|
171
|
-
var needAdjustY = adjustY
|
|
210
|
+
var needAdjustY = supportAdjust(adjustY);
|
|
172
211
|
|
|
173
212
|
// Bottom to Top
|
|
174
|
-
if (needAdjustY && popupPoints[0] === 't' && nextPopupBottom >
|
|
213
|
+
if (needAdjustY && popupPoints[0] === 't' && nextPopupBottom > visibleArea.bottom) {
|
|
175
214
|
nextOffsetY = targetAlignPointTL.y - popupAlignPointBR.y - popupOffsetY;
|
|
176
215
|
nextAlignInfo.points = [reversePoints(popupPoints, 0), reversePoints(targetPoints, 0)];
|
|
177
216
|
}
|
|
178
217
|
|
|
179
218
|
// Top to Bottom
|
|
180
|
-
if (needAdjustY && popupPoints[0] === 'b' && nextPopupY <
|
|
219
|
+
if (needAdjustY && popupPoints[0] === 'b' && nextPopupY < visibleArea.top) {
|
|
181
220
|
nextOffsetY = targetAlignPointBR.y - popupAlignPointTL.y - popupOffsetY;
|
|
182
221
|
nextAlignInfo.points = [reversePoints(popupPoints, 0), reversePoints(targetPoints, 0)];
|
|
183
222
|
}
|
|
@@ -185,17 +224,17 @@ export default function useAlign(open, popupEle, target, placement, builtinPlace
|
|
|
185
224
|
// >>>>>>>>>> Left & Right
|
|
186
225
|
var nextPopupX = popupRect.x + nextOffsetX;
|
|
187
226
|
var nextPopupRight = nextPopupX + popupWidth;
|
|
188
|
-
var needAdjustX = adjustX
|
|
227
|
+
var needAdjustX = supportAdjust(adjustX);
|
|
189
228
|
|
|
190
229
|
// >>>>> Flip
|
|
191
230
|
// Right to Left
|
|
192
|
-
if (needAdjustX && popupPoints[1] === 'l' && nextPopupRight >
|
|
231
|
+
if (needAdjustX && popupPoints[1] === 'l' && nextPopupRight > visibleArea.right) {
|
|
193
232
|
nextOffsetX = targetAlignPointTL.x - popupAlignPointBR.x - popupOffsetX;
|
|
194
233
|
nextAlignInfo.points = [reversePoints(popupPoints, 1), reversePoints(targetPoints, 1)];
|
|
195
234
|
}
|
|
196
235
|
|
|
197
236
|
// Left to Right
|
|
198
|
-
if (needAdjustX && popupPoints[1] === 'r' && nextPopupX <
|
|
237
|
+
if (needAdjustX && popupPoints[1] === 'r' && nextPopupX < visibleArea.left) {
|
|
199
238
|
nextOffsetX = targetAlignPointBR.x - popupAlignPointTL.x - popupOffsetX;
|
|
200
239
|
nextAlignInfo.points = [reversePoints(popupPoints, 1), reversePoints(targetPoints, 1)];
|
|
201
240
|
}
|
|
@@ -204,36 +243,36 @@ export default function useAlign(open, popupEle, target, placement, builtinPlace
|
|
|
204
243
|
var numShiftX = shiftX === true ? 0 : shiftX;
|
|
205
244
|
if (typeof numShiftX === 'number') {
|
|
206
245
|
// Left
|
|
207
|
-
if (nextPopupX <
|
|
208
|
-
nextOffsetX -= nextPopupX;
|
|
209
|
-
if (targetRect.x + targetRect.width < numShiftX) {
|
|
210
|
-
nextOffsetX += targetRect.x + targetRect.width - numShiftX;
|
|
246
|
+
if (nextPopupX < visibleArea.left) {
|
|
247
|
+
nextOffsetX -= nextPopupX - visibleArea.left;
|
|
248
|
+
if (targetRect.x + targetRect.width < visibleArea.left + numShiftX) {
|
|
249
|
+
nextOffsetX += targetRect.x - visibleArea.left + targetRect.width - numShiftX;
|
|
211
250
|
}
|
|
212
251
|
}
|
|
213
252
|
|
|
214
253
|
// Right
|
|
215
|
-
if (nextPopupRight >
|
|
216
|
-
nextOffsetX -= nextPopupRight -
|
|
217
|
-
if (targetRect.x >
|
|
218
|
-
nextOffsetX += targetRect.x -
|
|
254
|
+
if (nextPopupRight > visibleArea.right) {
|
|
255
|
+
nextOffsetX -= nextPopupRight - visibleArea.right;
|
|
256
|
+
if (targetRect.x > visibleArea.right - numShiftX) {
|
|
257
|
+
nextOffsetX += targetRect.x - visibleArea.right + numShiftX;
|
|
219
258
|
}
|
|
220
259
|
}
|
|
221
260
|
}
|
|
222
261
|
var numShiftY = shiftY === true ? 0 : shiftY;
|
|
223
262
|
if (typeof numShiftY === 'number') {
|
|
224
263
|
// Top
|
|
225
|
-
if (nextPopupY <
|
|
226
|
-
nextOffsetY -= nextPopupY;
|
|
227
|
-
if (targetRect.y + targetRect.height < numShiftY) {
|
|
228
|
-
nextOffsetY += targetRect.y + targetRect.height - numShiftY;
|
|
264
|
+
if (nextPopupY < visibleArea.top) {
|
|
265
|
+
nextOffsetY -= nextPopupY - visibleArea.top;
|
|
266
|
+
if (targetRect.y + targetRect.height < visibleArea.top + numShiftY) {
|
|
267
|
+
nextOffsetY += targetRect.y - visibleArea.top + targetRect.height - numShiftY;
|
|
229
268
|
}
|
|
230
269
|
}
|
|
231
270
|
|
|
232
271
|
// Bottom
|
|
233
|
-
if (nextPopupBottom >
|
|
234
|
-
nextOffsetY -= nextPopupBottom -
|
|
235
|
-
if (targetRect.y >
|
|
236
|
-
nextOffsetY += targetRect.y -
|
|
272
|
+
if (nextPopupBottom > visibleArea.bottom) {
|
|
273
|
+
nextOffsetY -= nextPopupBottom - visibleArea.bottom;
|
|
274
|
+
if (targetRect.y > visibleArea.bottom - numShiftY) {
|
|
275
|
+
nextOffsetY += targetRect.y - visibleArea.bottom + numShiftY;
|
|
237
276
|
}
|
|
238
277
|
}
|
|
239
278
|
}
|
package/es/hooks/useWatch.js
CHANGED
|
@@ -1,21 +1,6 @@
|
|
|
1
1
|
import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
|
|
2
2
|
import useLayoutEffect from "rc-util/es/hooks/useLayoutEffect";
|
|
3
|
-
import { getWin } from "../util";
|
|
4
|
-
function collectScroller(ele) {
|
|
5
|
-
var scrollerList = [];
|
|
6
|
-
var current = ele === null || ele === void 0 ? void 0 : ele.parentElement;
|
|
7
|
-
var scrollStyle = ['hidden', 'scroll', 'auto'];
|
|
8
|
-
while (current) {
|
|
9
|
-
var _getWin$getComputedSt = getWin(current).getComputedStyle(current),
|
|
10
|
-
overflowX = _getWin$getComputedSt.overflowX,
|
|
11
|
-
overflowY = _getWin$getComputedSt.overflowY;
|
|
12
|
-
if (scrollStyle.includes(overflowX) || scrollStyle.includes(overflowY)) {
|
|
13
|
-
scrollerList.push(current);
|
|
14
|
-
}
|
|
15
|
-
current = current.parentElement;
|
|
16
|
-
}
|
|
17
|
-
return scrollerList;
|
|
18
|
-
}
|
|
3
|
+
import { collectScroller, getWin } from "../util";
|
|
19
4
|
export default function useWatch(open, target, popup, onAlign) {
|
|
20
5
|
useLayoutEffect(function () {
|
|
21
6
|
if (open && target && popup) {
|
package/es/util.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { CSSMotionProps } from 'rc-motion';
|
|
2
2
|
import type { AlignType, AnimationType, BuildInPlacements, TransitionNameType } from './interface';
|
|
3
|
-
export declare function getAlignFromPlacement(builtinPlacements: BuildInPlacements, placementStr: string, align: AlignType): AlignType;
|
|
4
3
|
export declare function getAlignPopupClassName(builtinPlacements: BuildInPlacements, prefixCls: string, align: AlignType, isAlignPoint: boolean): string;
|
|
5
4
|
/** @deprecated We should not use this if we can refactor all deps */
|
|
6
5
|
export declare function getMotion(prefixCls: string, motion: CSSMotionProps, animation: AnimationType, transitionName: TransitionNameType): CSSMotionProps;
|
|
7
6
|
export declare function getWin(ele: HTMLElement): Window & typeof globalThis;
|
|
7
|
+
export declare function collectScroller(ele: HTMLElement): HTMLElement[];
|
package/es/util.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
2
1
|
function isPointsEq() {
|
|
3
2
|
var a1 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
4
3
|
var a2 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
|
|
@@ -8,10 +7,6 @@ function isPointsEq() {
|
|
|
8
7
|
}
|
|
9
8
|
return a1[0] === a2[0] && a1[1] === a2[1];
|
|
10
9
|
}
|
|
11
|
-
export function getAlignFromPlacement(builtinPlacements, placementStr, align) {
|
|
12
|
-
var baseAlign = builtinPlacements[placementStr] || {};
|
|
13
|
-
return _objectSpread(_objectSpread({}, baseAlign), align);
|
|
14
|
-
}
|
|
15
10
|
export function getAlignPopupClassName(builtinPlacements, prefixCls, align, isAlignPoint) {
|
|
16
11
|
var points = align.points;
|
|
17
12
|
var placements = Object.keys(builtinPlacements);
|
|
@@ -44,4 +39,19 @@ export function getMotion(prefixCls, motion, animation, transitionName) {
|
|
|
44
39
|
}
|
|
45
40
|
export function getWin(ele) {
|
|
46
41
|
return ele.ownerDocument.defaultView;
|
|
42
|
+
}
|
|
43
|
+
export function collectScroller(ele) {
|
|
44
|
+
var scrollerList = [];
|
|
45
|
+
var current = ele === null || ele === void 0 ? void 0 : ele.parentElement;
|
|
46
|
+
var scrollStyle = ['hidden', 'scroll', 'auto'];
|
|
47
|
+
while (current) {
|
|
48
|
+
var _getWin$getComputedSt = getWin(current).getComputedStyle(current),
|
|
49
|
+
overflowX = _getWin$getComputedSt.overflowX,
|
|
50
|
+
overflowY = _getWin$getComputedSt.overflowY;
|
|
51
|
+
if (scrollStyle.includes(overflowX) || scrollStyle.includes(overflowY)) {
|
|
52
|
+
scrollerList.push(current);
|
|
53
|
+
}
|
|
54
|
+
current = current.parentElement;
|
|
55
|
+
}
|
|
56
|
+
return scrollerList;
|
|
47
57
|
}
|
package/lib/hooks/useAlign.js
CHANGED
|
@@ -76,6 +76,14 @@ function useAlign(open, popupEle, target, placement, builtinPlacements, popupAli
|
|
|
76
76
|
offsetInfo = _React$useState2[0],
|
|
77
77
|
setOffsetInfo = _React$useState2[1];
|
|
78
78
|
var alignCountRef = React.useRef(0);
|
|
79
|
+
var scrollerList = React.useMemo(function () {
|
|
80
|
+
if (!popupEle) {
|
|
81
|
+
return [];
|
|
82
|
+
}
|
|
83
|
+
return (0, _util.collectScroller)(popupEle);
|
|
84
|
+
}, [popupEle]);
|
|
85
|
+
|
|
86
|
+
// ========================= Align =========================
|
|
79
87
|
var onAlign = (0, _useEvent.default)(function () {
|
|
80
88
|
if (popupEle && target && open) {
|
|
81
89
|
var popupElement = popupEle;
|
|
@@ -116,6 +124,31 @@ function useAlign(open, popupEle, target, placement, builtinPlacements, popupAli
|
|
|
116
124
|
var popupHeight = popupRect.height;
|
|
117
125
|
var popupWidth = popupRect.width;
|
|
118
126
|
|
|
127
|
+
// Get bounding of visible area
|
|
128
|
+
var visibleArea = {
|
|
129
|
+
left: 0,
|
|
130
|
+
top: 0,
|
|
131
|
+
right: clientWidth,
|
|
132
|
+
bottom: clientHeight
|
|
133
|
+
};
|
|
134
|
+
(scrollerList || []).forEach(function (ele) {
|
|
135
|
+
var eleRect = ele.getBoundingClientRect();
|
|
136
|
+
var eleOutHeight = ele.offsetHeight,
|
|
137
|
+
eleInnerHeight = ele.clientHeight,
|
|
138
|
+
eleOutWidth = ele.offsetWidth,
|
|
139
|
+
eleInnerWidth = ele.clientWidth;
|
|
140
|
+
var scaleX = toNum(Math.round(eleRect.width / eleOutWidth * 1000) / 1000);
|
|
141
|
+
var scaleY = toNum(Math.round(eleRect.height / eleOutHeight * 1000) / 1000);
|
|
142
|
+
var scrollWidth = (eleOutWidth - eleInnerWidth) * scaleX;
|
|
143
|
+
var scrollHeight = (eleOutHeight - eleInnerHeight) * scaleY;
|
|
144
|
+
var eleRight = eleRect.x + eleRect.width - scrollWidth;
|
|
145
|
+
var eleBottom = eleRect.y + eleRect.height - scrollHeight;
|
|
146
|
+
visibleArea.left = Math.max(visibleArea.left, eleRect.left);
|
|
147
|
+
visibleArea.top = Math.max(visibleArea.top, eleRect.top);
|
|
148
|
+
visibleArea.right = Math.min(visibleArea.right, eleRight);
|
|
149
|
+
visibleArea.bottom = Math.min(visibleArea.bottom, eleBottom);
|
|
150
|
+
});
|
|
151
|
+
|
|
119
152
|
// Reset back
|
|
120
153
|
popupElement.style.left = originLeft;
|
|
121
154
|
popupElement.style.top = originTop;
|
|
@@ -172,20 +205,26 @@ function useAlign(open, popupEle, target, placement, builtinPlacements, popupAli
|
|
|
172
205
|
adjustY = overflow.adjustY,
|
|
173
206
|
shiftX = overflow.shiftX,
|
|
174
207
|
shiftY = overflow.shiftY;
|
|
208
|
+
var supportAdjust = function supportAdjust(val) {
|
|
209
|
+
if (typeof val === 'boolean') {
|
|
210
|
+
return val;
|
|
211
|
+
}
|
|
212
|
+
return val >= 0;
|
|
213
|
+
};
|
|
175
214
|
|
|
176
215
|
// >>>>>>>>>> Top & Bottom
|
|
177
216
|
var nextPopupY = popupRect.y + nextOffsetY;
|
|
178
217
|
var nextPopupBottom = nextPopupY + popupHeight;
|
|
179
|
-
var needAdjustY = adjustY
|
|
218
|
+
var needAdjustY = supportAdjust(adjustY);
|
|
180
219
|
|
|
181
220
|
// Bottom to Top
|
|
182
|
-
if (needAdjustY && popupPoints[0] === 't' && nextPopupBottom >
|
|
221
|
+
if (needAdjustY && popupPoints[0] === 't' && nextPopupBottom > visibleArea.bottom) {
|
|
183
222
|
nextOffsetY = targetAlignPointTL.y - popupAlignPointBR.y - popupOffsetY;
|
|
184
223
|
nextAlignInfo.points = [reversePoints(popupPoints, 0), reversePoints(targetPoints, 0)];
|
|
185
224
|
}
|
|
186
225
|
|
|
187
226
|
// Top to Bottom
|
|
188
|
-
if (needAdjustY && popupPoints[0] === 'b' && nextPopupY <
|
|
227
|
+
if (needAdjustY && popupPoints[0] === 'b' && nextPopupY < visibleArea.top) {
|
|
189
228
|
nextOffsetY = targetAlignPointBR.y - popupAlignPointTL.y - popupOffsetY;
|
|
190
229
|
nextAlignInfo.points = [reversePoints(popupPoints, 0), reversePoints(targetPoints, 0)];
|
|
191
230
|
}
|
|
@@ -193,17 +232,17 @@ function useAlign(open, popupEle, target, placement, builtinPlacements, popupAli
|
|
|
193
232
|
// >>>>>>>>>> Left & Right
|
|
194
233
|
var nextPopupX = popupRect.x + nextOffsetX;
|
|
195
234
|
var nextPopupRight = nextPopupX + popupWidth;
|
|
196
|
-
var needAdjustX = adjustX
|
|
235
|
+
var needAdjustX = supportAdjust(adjustX);
|
|
197
236
|
|
|
198
237
|
// >>>>> Flip
|
|
199
238
|
// Right to Left
|
|
200
|
-
if (needAdjustX && popupPoints[1] === 'l' && nextPopupRight >
|
|
239
|
+
if (needAdjustX && popupPoints[1] === 'l' && nextPopupRight > visibleArea.right) {
|
|
201
240
|
nextOffsetX = targetAlignPointTL.x - popupAlignPointBR.x - popupOffsetX;
|
|
202
241
|
nextAlignInfo.points = [reversePoints(popupPoints, 1), reversePoints(targetPoints, 1)];
|
|
203
242
|
}
|
|
204
243
|
|
|
205
244
|
// Left to Right
|
|
206
|
-
if (needAdjustX && popupPoints[1] === 'r' && nextPopupX <
|
|
245
|
+
if (needAdjustX && popupPoints[1] === 'r' && nextPopupX < visibleArea.left) {
|
|
207
246
|
nextOffsetX = targetAlignPointBR.x - popupAlignPointTL.x - popupOffsetX;
|
|
208
247
|
nextAlignInfo.points = [reversePoints(popupPoints, 1), reversePoints(targetPoints, 1)];
|
|
209
248
|
}
|
|
@@ -212,36 +251,36 @@ function useAlign(open, popupEle, target, placement, builtinPlacements, popupAli
|
|
|
212
251
|
var numShiftX = shiftX === true ? 0 : shiftX;
|
|
213
252
|
if (typeof numShiftX === 'number') {
|
|
214
253
|
// Left
|
|
215
|
-
if (nextPopupX <
|
|
216
|
-
nextOffsetX -= nextPopupX;
|
|
217
|
-
if (targetRect.x + targetRect.width < numShiftX) {
|
|
218
|
-
nextOffsetX += targetRect.x + targetRect.width - numShiftX;
|
|
254
|
+
if (nextPopupX < visibleArea.left) {
|
|
255
|
+
nextOffsetX -= nextPopupX - visibleArea.left;
|
|
256
|
+
if (targetRect.x + targetRect.width < visibleArea.left + numShiftX) {
|
|
257
|
+
nextOffsetX += targetRect.x - visibleArea.left + targetRect.width - numShiftX;
|
|
219
258
|
}
|
|
220
259
|
}
|
|
221
260
|
|
|
222
261
|
// Right
|
|
223
|
-
if (nextPopupRight >
|
|
224
|
-
nextOffsetX -= nextPopupRight -
|
|
225
|
-
if (targetRect.x >
|
|
226
|
-
nextOffsetX += targetRect.x -
|
|
262
|
+
if (nextPopupRight > visibleArea.right) {
|
|
263
|
+
nextOffsetX -= nextPopupRight - visibleArea.right;
|
|
264
|
+
if (targetRect.x > visibleArea.right - numShiftX) {
|
|
265
|
+
nextOffsetX += targetRect.x - visibleArea.right + numShiftX;
|
|
227
266
|
}
|
|
228
267
|
}
|
|
229
268
|
}
|
|
230
269
|
var numShiftY = shiftY === true ? 0 : shiftY;
|
|
231
270
|
if (typeof numShiftY === 'number') {
|
|
232
271
|
// Top
|
|
233
|
-
if (nextPopupY <
|
|
234
|
-
nextOffsetY -= nextPopupY;
|
|
235
|
-
if (targetRect.y + targetRect.height < numShiftY) {
|
|
236
|
-
nextOffsetY += targetRect.y + targetRect.height - numShiftY;
|
|
272
|
+
if (nextPopupY < visibleArea.top) {
|
|
273
|
+
nextOffsetY -= nextPopupY - visibleArea.top;
|
|
274
|
+
if (targetRect.y + targetRect.height < visibleArea.top + numShiftY) {
|
|
275
|
+
nextOffsetY += targetRect.y - visibleArea.top + targetRect.height - numShiftY;
|
|
237
276
|
}
|
|
238
277
|
}
|
|
239
278
|
|
|
240
279
|
// Bottom
|
|
241
|
-
if (nextPopupBottom >
|
|
242
|
-
nextOffsetY -= nextPopupBottom -
|
|
243
|
-
if (targetRect.y >
|
|
244
|
-
nextOffsetY += targetRect.y -
|
|
280
|
+
if (nextPopupBottom > visibleArea.bottom) {
|
|
281
|
+
nextOffsetY -= nextPopupBottom - visibleArea.bottom;
|
|
282
|
+
if (targetRect.y > visibleArea.bottom - numShiftY) {
|
|
283
|
+
nextOffsetY += targetRect.y - visibleArea.bottom + numShiftY;
|
|
245
284
|
}
|
|
246
285
|
}
|
|
247
286
|
}
|
package/lib/hooks/useWatch.js
CHANGED
|
@@ -8,28 +8,13 @@ exports.default = useWatch;
|
|
|
8
8
|
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
9
9
|
var _useLayoutEffect = _interopRequireDefault(require("rc-util/lib/hooks/useLayoutEffect"));
|
|
10
10
|
var _util = require("../util");
|
|
11
|
-
function collectScroller(ele) {
|
|
12
|
-
var scrollerList = [];
|
|
13
|
-
var current = ele === null || ele === void 0 ? void 0 : ele.parentElement;
|
|
14
|
-
var scrollStyle = ['hidden', 'scroll', 'auto'];
|
|
15
|
-
while (current) {
|
|
16
|
-
var _getWin$getComputedSt = (0, _util.getWin)(current).getComputedStyle(current),
|
|
17
|
-
overflowX = _getWin$getComputedSt.overflowX,
|
|
18
|
-
overflowY = _getWin$getComputedSt.overflowY;
|
|
19
|
-
if (scrollStyle.includes(overflowX) || scrollStyle.includes(overflowY)) {
|
|
20
|
-
scrollerList.push(current);
|
|
21
|
-
}
|
|
22
|
-
current = current.parentElement;
|
|
23
|
-
}
|
|
24
|
-
return scrollerList;
|
|
25
|
-
}
|
|
26
11
|
function useWatch(open, target, popup, onAlign) {
|
|
27
12
|
(0, _useLayoutEffect.default)(function () {
|
|
28
13
|
if (open && target && popup) {
|
|
29
14
|
var targetElement = target;
|
|
30
15
|
var popupElement = popup;
|
|
31
|
-
var targetScrollList = collectScroller(targetElement);
|
|
32
|
-
var popupScrollList = collectScroller(popupElement);
|
|
16
|
+
var targetScrollList = (0, _util.collectScroller)(targetElement);
|
|
17
|
+
var popupScrollList = (0, _util.collectScroller)(popupElement);
|
|
33
18
|
var win = (0, _util.getWin)(popupElement);
|
|
34
19
|
var mergedList = new Set([win].concat((0, _toConsumableArray2.default)(targetScrollList), (0, _toConsumableArray2.default)(popupScrollList)));
|
|
35
20
|
function notifyScroll() {
|
package/lib/util.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { CSSMotionProps } from 'rc-motion';
|
|
2
2
|
import type { AlignType, AnimationType, BuildInPlacements, TransitionNameType } from './interface';
|
|
3
|
-
export declare function getAlignFromPlacement(builtinPlacements: BuildInPlacements, placementStr: string, align: AlignType): AlignType;
|
|
4
3
|
export declare function getAlignPopupClassName(builtinPlacements: BuildInPlacements, prefixCls: string, align: AlignType, isAlignPoint: boolean): string;
|
|
5
4
|
/** @deprecated We should not use this if we can refactor all deps */
|
|
6
5
|
export declare function getMotion(prefixCls: string, motion: CSSMotionProps, animation: AnimationType, transitionName: TransitionNameType): CSSMotionProps;
|
|
7
6
|
export declare function getWin(ele: HTMLElement): Window & typeof globalThis;
|
|
7
|
+
export declare function collectScroller(ele: HTMLElement): HTMLElement[];
|
package/lib/util.js
CHANGED
|
@@ -1,14 +1,12 @@
|
|
|
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
|
-
exports.
|
|
6
|
+
exports.collectScroller = collectScroller;
|
|
8
7
|
exports.getAlignPopupClassName = getAlignPopupClassName;
|
|
9
8
|
exports.getMotion = getMotion;
|
|
10
9
|
exports.getWin = getWin;
|
|
11
|
-
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
12
10
|
function isPointsEq() {
|
|
13
11
|
var a1 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
14
12
|
var a2 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
|
|
@@ -18,10 +16,6 @@ function isPointsEq() {
|
|
|
18
16
|
}
|
|
19
17
|
return a1[0] === a2[0] && a1[1] === a2[1];
|
|
20
18
|
}
|
|
21
|
-
function getAlignFromPlacement(builtinPlacements, placementStr, align) {
|
|
22
|
-
var baseAlign = builtinPlacements[placementStr] || {};
|
|
23
|
-
return (0, _objectSpread2.default)((0, _objectSpread2.default)({}, baseAlign), align);
|
|
24
|
-
}
|
|
25
19
|
function getAlignPopupClassName(builtinPlacements, prefixCls, align, isAlignPoint) {
|
|
26
20
|
var points = align.points;
|
|
27
21
|
var placements = Object.keys(builtinPlacements);
|
|
@@ -54,4 +48,19 @@ function getMotion(prefixCls, motion, animation, transitionName) {
|
|
|
54
48
|
}
|
|
55
49
|
function getWin(ele) {
|
|
56
50
|
return ele.ownerDocument.defaultView;
|
|
51
|
+
}
|
|
52
|
+
function collectScroller(ele) {
|
|
53
|
+
var scrollerList = [];
|
|
54
|
+
var current = ele === null || ele === void 0 ? void 0 : ele.parentElement;
|
|
55
|
+
var scrollStyle = ['hidden', 'scroll', 'auto'];
|
|
56
|
+
while (current) {
|
|
57
|
+
var _getWin$getComputedSt = getWin(current).getComputedStyle(current),
|
|
58
|
+
overflowX = _getWin$getComputedSt.overflowX,
|
|
59
|
+
overflowY = _getWin$getComputedSt.overflowY;
|
|
60
|
+
if (scrollStyle.includes(overflowX) || scrollStyle.includes(overflowY)) {
|
|
61
|
+
scrollerList.push(current);
|
|
62
|
+
}
|
|
63
|
+
current = current.parentElement;
|
|
64
|
+
}
|
|
65
|
+
return scrollerList;
|
|
57
66
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rc-component/trigger",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.1",
|
|
4
4
|
"description": "base abstract trigger component for react",
|
|
5
5
|
"engines": {
|
|
6
6
|
"node": ">=8.x"
|
|
@@ -65,7 +65,7 @@
|
|
|
65
65
|
"classnames": "^2.3.2",
|
|
66
66
|
"rc-align": "^4.0.0",
|
|
67
67
|
"rc-motion": "^2.0.0",
|
|
68
|
-
"rc-resize-observer": "^1.3.
|
|
68
|
+
"rc-resize-observer": "^1.3.1",
|
|
69
69
|
"rc-util": "^5.27.1"
|
|
70
70
|
},
|
|
71
71
|
"peerDependencies": {
|