@rc-component/trigger 1.2.0 → 1.3.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/hooks/useAlign.js +54 -21
- 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 +53 -20
- 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;
|
|
@@ -171,13 +204,13 @@ export default function useAlign(open, popupEle, target, placement, builtinPlace
|
|
|
171
204
|
var needAdjustY = adjustY === true || adjustY >= 0;
|
|
172
205
|
|
|
173
206
|
// Bottom to Top
|
|
174
|
-
if (needAdjustY && popupPoints[0] === 't' && nextPopupBottom >
|
|
207
|
+
if (needAdjustY && popupPoints[0] === 't' && nextPopupBottom > visibleArea.bottom) {
|
|
175
208
|
nextOffsetY = targetAlignPointTL.y - popupAlignPointBR.y - popupOffsetY;
|
|
176
209
|
nextAlignInfo.points = [reversePoints(popupPoints, 0), reversePoints(targetPoints, 0)];
|
|
177
210
|
}
|
|
178
211
|
|
|
179
212
|
// Top to Bottom
|
|
180
|
-
if (needAdjustY && popupPoints[0] === 'b' && nextPopupY <
|
|
213
|
+
if (needAdjustY && popupPoints[0] === 'b' && nextPopupY < visibleArea.top) {
|
|
181
214
|
nextOffsetY = targetAlignPointBR.y - popupAlignPointTL.y - popupOffsetY;
|
|
182
215
|
nextAlignInfo.points = [reversePoints(popupPoints, 0), reversePoints(targetPoints, 0)];
|
|
183
216
|
}
|
|
@@ -189,13 +222,13 @@ export default function useAlign(open, popupEle, target, placement, builtinPlace
|
|
|
189
222
|
|
|
190
223
|
// >>>>> Flip
|
|
191
224
|
// Right to Left
|
|
192
|
-
if (needAdjustX && popupPoints[1] === 'l' && nextPopupRight >
|
|
225
|
+
if (needAdjustX && popupPoints[1] === 'l' && nextPopupRight > visibleArea.right) {
|
|
193
226
|
nextOffsetX = targetAlignPointTL.x - popupAlignPointBR.x - popupOffsetX;
|
|
194
227
|
nextAlignInfo.points = [reversePoints(popupPoints, 1), reversePoints(targetPoints, 1)];
|
|
195
228
|
}
|
|
196
229
|
|
|
197
230
|
// Left to Right
|
|
198
|
-
if (needAdjustX && popupPoints[1] === 'r' && nextPopupX <
|
|
231
|
+
if (needAdjustX && popupPoints[1] === 'r' && nextPopupX < visibleArea.left) {
|
|
199
232
|
nextOffsetX = targetAlignPointBR.x - popupAlignPointTL.x - popupOffsetX;
|
|
200
233
|
nextAlignInfo.points = [reversePoints(popupPoints, 1), reversePoints(targetPoints, 1)];
|
|
201
234
|
}
|
|
@@ -204,36 +237,36 @@ export default function useAlign(open, popupEle, target, placement, builtinPlace
|
|
|
204
237
|
var numShiftX = shiftX === true ? 0 : shiftX;
|
|
205
238
|
if (typeof numShiftX === 'number') {
|
|
206
239
|
// Left
|
|
207
|
-
if (nextPopupX <
|
|
208
|
-
nextOffsetX -= nextPopupX;
|
|
209
|
-
if (targetRect.x + targetRect.width < numShiftX) {
|
|
210
|
-
nextOffsetX += targetRect.x + targetRect.width - numShiftX;
|
|
240
|
+
if (nextPopupX < visibleArea.left) {
|
|
241
|
+
nextOffsetX -= nextPopupX - visibleArea.left;
|
|
242
|
+
if (targetRect.x + targetRect.width < visibleArea.left + numShiftX) {
|
|
243
|
+
nextOffsetX += targetRect.x - visibleArea.left + targetRect.width - numShiftX;
|
|
211
244
|
}
|
|
212
245
|
}
|
|
213
246
|
|
|
214
247
|
// Right
|
|
215
|
-
if (nextPopupRight >
|
|
216
|
-
nextOffsetX -= nextPopupRight -
|
|
217
|
-
if (targetRect.x >
|
|
218
|
-
nextOffsetX += targetRect.x -
|
|
248
|
+
if (nextPopupRight > visibleArea.right) {
|
|
249
|
+
nextOffsetX -= nextPopupRight - visibleArea.right;
|
|
250
|
+
if (targetRect.x > visibleArea.right - numShiftX) {
|
|
251
|
+
nextOffsetX += targetRect.x - visibleArea.right + numShiftX;
|
|
219
252
|
}
|
|
220
253
|
}
|
|
221
254
|
}
|
|
222
255
|
var numShiftY = shiftY === true ? 0 : shiftY;
|
|
223
256
|
if (typeof numShiftY === 'number') {
|
|
224
257
|
// Top
|
|
225
|
-
if (nextPopupY <
|
|
226
|
-
nextOffsetY -= nextPopupY;
|
|
227
|
-
if (targetRect.y + targetRect.height < numShiftY) {
|
|
228
|
-
nextOffsetY += targetRect.y + targetRect.height - numShiftY;
|
|
258
|
+
if (nextPopupY < visibleArea.top) {
|
|
259
|
+
nextOffsetY -= nextPopupY - visibleArea.top;
|
|
260
|
+
if (targetRect.y + targetRect.height < visibleArea.top + numShiftY) {
|
|
261
|
+
nextOffsetY += targetRect.y - visibleArea.top + targetRect.height - numShiftY;
|
|
229
262
|
}
|
|
230
263
|
}
|
|
231
264
|
|
|
232
265
|
// Bottom
|
|
233
|
-
if (nextPopupBottom >
|
|
234
|
-
nextOffsetY -= nextPopupBottom -
|
|
235
|
-
if (targetRect.y >
|
|
236
|
-
nextOffsetY += targetRect.y -
|
|
266
|
+
if (nextPopupBottom > visibleArea.bottom) {
|
|
267
|
+
nextOffsetY -= nextPopupBottom - visibleArea.bottom;
|
|
268
|
+
if (targetRect.y > visibleArea.bottom - numShiftY) {
|
|
269
|
+
nextOffsetY += targetRect.y - visibleArea.bottom + numShiftY;
|
|
237
270
|
}
|
|
238
271
|
}
|
|
239
272
|
}
|
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;
|
|
@@ -179,13 +212,13 @@ function useAlign(open, popupEle, target, placement, builtinPlacements, popupAli
|
|
|
179
212
|
var needAdjustY = adjustY === true || adjustY >= 0;
|
|
180
213
|
|
|
181
214
|
// Bottom to Top
|
|
182
|
-
if (needAdjustY && popupPoints[0] === 't' && nextPopupBottom >
|
|
215
|
+
if (needAdjustY && popupPoints[0] === 't' && nextPopupBottom > visibleArea.bottom) {
|
|
183
216
|
nextOffsetY = targetAlignPointTL.y - popupAlignPointBR.y - popupOffsetY;
|
|
184
217
|
nextAlignInfo.points = [reversePoints(popupPoints, 0), reversePoints(targetPoints, 0)];
|
|
185
218
|
}
|
|
186
219
|
|
|
187
220
|
// Top to Bottom
|
|
188
|
-
if (needAdjustY && popupPoints[0] === 'b' && nextPopupY <
|
|
221
|
+
if (needAdjustY && popupPoints[0] === 'b' && nextPopupY < visibleArea.top) {
|
|
189
222
|
nextOffsetY = targetAlignPointBR.y - popupAlignPointTL.y - popupOffsetY;
|
|
190
223
|
nextAlignInfo.points = [reversePoints(popupPoints, 0), reversePoints(targetPoints, 0)];
|
|
191
224
|
}
|
|
@@ -197,13 +230,13 @@ function useAlign(open, popupEle, target, placement, builtinPlacements, popupAli
|
|
|
197
230
|
|
|
198
231
|
// >>>>> Flip
|
|
199
232
|
// Right to Left
|
|
200
|
-
if (needAdjustX && popupPoints[1] === 'l' && nextPopupRight >
|
|
233
|
+
if (needAdjustX && popupPoints[1] === 'l' && nextPopupRight > visibleArea.right) {
|
|
201
234
|
nextOffsetX = targetAlignPointTL.x - popupAlignPointBR.x - popupOffsetX;
|
|
202
235
|
nextAlignInfo.points = [reversePoints(popupPoints, 1), reversePoints(targetPoints, 1)];
|
|
203
236
|
}
|
|
204
237
|
|
|
205
238
|
// Left to Right
|
|
206
|
-
if (needAdjustX && popupPoints[1] === 'r' && nextPopupX <
|
|
239
|
+
if (needAdjustX && popupPoints[1] === 'r' && nextPopupX < visibleArea.left) {
|
|
207
240
|
nextOffsetX = targetAlignPointBR.x - popupAlignPointTL.x - popupOffsetX;
|
|
208
241
|
nextAlignInfo.points = [reversePoints(popupPoints, 1), reversePoints(targetPoints, 1)];
|
|
209
242
|
}
|
|
@@ -212,36 +245,36 @@ function useAlign(open, popupEle, target, placement, builtinPlacements, popupAli
|
|
|
212
245
|
var numShiftX = shiftX === true ? 0 : shiftX;
|
|
213
246
|
if (typeof numShiftX === 'number') {
|
|
214
247
|
// Left
|
|
215
|
-
if (nextPopupX <
|
|
216
|
-
nextOffsetX -= nextPopupX;
|
|
217
|
-
if (targetRect.x + targetRect.width < numShiftX) {
|
|
218
|
-
nextOffsetX += targetRect.x + targetRect.width - numShiftX;
|
|
248
|
+
if (nextPopupX < visibleArea.left) {
|
|
249
|
+
nextOffsetX -= nextPopupX - visibleArea.left;
|
|
250
|
+
if (targetRect.x + targetRect.width < visibleArea.left + numShiftX) {
|
|
251
|
+
nextOffsetX += targetRect.x - visibleArea.left + targetRect.width - numShiftX;
|
|
219
252
|
}
|
|
220
253
|
}
|
|
221
254
|
|
|
222
255
|
// Right
|
|
223
|
-
if (nextPopupRight >
|
|
224
|
-
nextOffsetX -= nextPopupRight -
|
|
225
|
-
if (targetRect.x >
|
|
226
|
-
nextOffsetX += targetRect.x -
|
|
256
|
+
if (nextPopupRight > visibleArea.right) {
|
|
257
|
+
nextOffsetX -= nextPopupRight - visibleArea.right;
|
|
258
|
+
if (targetRect.x > visibleArea.right - numShiftX) {
|
|
259
|
+
nextOffsetX += targetRect.x - visibleArea.right + numShiftX;
|
|
227
260
|
}
|
|
228
261
|
}
|
|
229
262
|
}
|
|
230
263
|
var numShiftY = shiftY === true ? 0 : shiftY;
|
|
231
264
|
if (typeof numShiftY === 'number') {
|
|
232
265
|
// Top
|
|
233
|
-
if (nextPopupY <
|
|
234
|
-
nextOffsetY -= nextPopupY;
|
|
235
|
-
if (targetRect.y + targetRect.height < numShiftY) {
|
|
236
|
-
nextOffsetY += targetRect.y + targetRect.height - numShiftY;
|
|
266
|
+
if (nextPopupY < visibleArea.top) {
|
|
267
|
+
nextOffsetY -= nextPopupY - visibleArea.top;
|
|
268
|
+
if (targetRect.y + targetRect.height < visibleArea.top + numShiftY) {
|
|
269
|
+
nextOffsetY += targetRect.y - visibleArea.top + targetRect.height - numShiftY;
|
|
237
270
|
}
|
|
238
271
|
}
|
|
239
272
|
|
|
240
273
|
// Bottom
|
|
241
|
-
if (nextPopupBottom >
|
|
242
|
-
nextOffsetY -= nextPopupBottom -
|
|
243
|
-
if (targetRect.y >
|
|
244
|
-
nextOffsetY += targetRect.y -
|
|
274
|
+
if (nextPopupBottom > visibleArea.bottom) {
|
|
275
|
+
nextOffsetY -= nextPopupBottom - visibleArea.bottom;
|
|
276
|
+
if (targetRect.y > visibleArea.bottom - numShiftY) {
|
|
277
|
+
nextOffsetY += targetRect.y - visibleArea.bottom + numShiftY;
|
|
245
278
|
}
|
|
246
279
|
}
|
|
247
280
|
}
|
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.0",
|
|
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": {
|