@rc-component/trigger 1.13.4 → 1.13.6
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 +16 -16
- package/es/hooks/useWinClick.js +34 -20
- package/lib/hooks/useAlign.js +16 -16
- package/lib/hooks/useWinClick.js +34 -20
- package/package.json +1 -1
package/es/hooks/useAlign.js
CHANGED
|
@@ -379,36 +379,36 @@ export default function useAlign(open, popupEle, target, placement, builtinPlace
|
|
|
379
379
|
var numShiftX = shiftX === true ? 0 : shiftX;
|
|
380
380
|
if (typeof numShiftX === 'number') {
|
|
381
381
|
// Left
|
|
382
|
-
if (nextPopupX <
|
|
383
|
-
nextOffsetX -= nextPopupX -
|
|
384
|
-
if (targetRect.x + targetWidth <
|
|
385
|
-
nextOffsetX += targetRect.x -
|
|
382
|
+
if (nextPopupX < visibleRegionArea.left) {
|
|
383
|
+
nextOffsetX -= nextPopupX - visibleRegionArea.left;
|
|
384
|
+
if (targetRect.x + targetWidth < visibleRegionArea.left + numShiftX) {
|
|
385
|
+
nextOffsetX += targetRect.x - visibleRegionArea.left + targetWidth - numShiftX;
|
|
386
386
|
}
|
|
387
387
|
}
|
|
388
388
|
|
|
389
389
|
// Right
|
|
390
|
-
if (nextPopupRight >
|
|
391
|
-
nextOffsetX -= nextPopupRight -
|
|
392
|
-
if (targetRect.x >
|
|
393
|
-
nextOffsetX += targetRect.x -
|
|
390
|
+
if (nextPopupRight > visibleRegionArea.right) {
|
|
391
|
+
nextOffsetX -= nextPopupRight - visibleRegionArea.right;
|
|
392
|
+
if (targetRect.x > visibleRegionArea.right - numShiftX) {
|
|
393
|
+
nextOffsetX += targetRect.x - visibleRegionArea.right + numShiftX;
|
|
394
394
|
}
|
|
395
395
|
}
|
|
396
396
|
}
|
|
397
397
|
var numShiftY = shiftY === true ? 0 : shiftY;
|
|
398
398
|
if (typeof numShiftY === 'number') {
|
|
399
399
|
// Top
|
|
400
|
-
if (nextPopupY <
|
|
401
|
-
nextOffsetY -= nextPopupY -
|
|
402
|
-
if (targetRect.y + targetHeight <
|
|
403
|
-
nextOffsetY += targetRect.y -
|
|
400
|
+
if (nextPopupY < visibleRegionArea.top) {
|
|
401
|
+
nextOffsetY -= nextPopupY - visibleRegionArea.top;
|
|
402
|
+
if (targetRect.y + targetHeight < visibleRegionArea.top + numShiftY) {
|
|
403
|
+
nextOffsetY += targetRect.y - visibleRegionArea.top + targetHeight - numShiftY;
|
|
404
404
|
}
|
|
405
405
|
}
|
|
406
406
|
|
|
407
407
|
// Bottom
|
|
408
|
-
if (nextPopupBottom >
|
|
409
|
-
nextOffsetY -= nextPopupBottom -
|
|
410
|
-
if (targetRect.y >
|
|
411
|
-
nextOffsetY += targetRect.y -
|
|
408
|
+
if (nextPopupBottom > visibleRegionArea.bottom) {
|
|
409
|
+
nextOffsetY -= nextPopupBottom - visibleRegionArea.bottom;
|
|
410
|
+
if (targetRect.y > visibleRegionArea.bottom - numShiftY) {
|
|
411
|
+
nextOffsetY += targetRect.y - visibleRegionArea.bottom + numShiftY;
|
|
412
412
|
}
|
|
413
413
|
}
|
|
414
414
|
}
|
package/es/hooks/useWinClick.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
1
2
|
import { warning } from 'rc-util';
|
|
2
3
|
import { getShadowRoot } from "rc-util/es/Dom/shadow";
|
|
3
4
|
import raf from "rc-util/es/raf";
|
|
@@ -24,29 +25,42 @@ export default function useWinClick(open, clickToHide, targetEle, popupEle, mask
|
|
|
24
25
|
// Click to hide is special action since click popup element should not hide
|
|
25
26
|
React.useEffect(function () {
|
|
26
27
|
if (clickToHide && popupEle && (!mask || maskClosable)) {
|
|
27
|
-
var
|
|
28
|
+
var genClickEvents = function genClickEvents() {
|
|
29
|
+
var clickInside = false;
|
|
28
30
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
31
|
+
// User may mouseDown inside and drag out of popup and mouse up
|
|
32
|
+
// Record here to prevent close
|
|
33
|
+
var onWindowMouseDown = function onWindowMouseDown(_ref) {
|
|
34
|
+
var target = _ref.target;
|
|
35
|
+
clickInside = inPopupOrChild(target);
|
|
36
|
+
};
|
|
37
|
+
var onWindowClick = function onWindowClick(_ref2) {
|
|
38
|
+
var target = _ref2.target;
|
|
39
|
+
if (!lockRef.current && openRef.current && !clickInside && !inPopupOrChild(target)) {
|
|
40
|
+
triggerOpen(false);
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
return [onWindowMouseDown, onWindowClick];
|
|
40
44
|
};
|
|
45
|
+
|
|
46
|
+
// Events
|
|
47
|
+
var _genClickEvents = genClickEvents(),
|
|
48
|
+
_genClickEvents2 = _slicedToArray(_genClickEvents, 2),
|
|
49
|
+
onWinMouseDown = _genClickEvents2[0],
|
|
50
|
+
onWinClick = _genClickEvents2[1];
|
|
51
|
+
var _genClickEvents3 = genClickEvents(),
|
|
52
|
+
_genClickEvents4 = _slicedToArray(_genClickEvents3, 2),
|
|
53
|
+
onShadowMouseDown = _genClickEvents4[0],
|
|
54
|
+
onShadowClick = _genClickEvents4[1];
|
|
41
55
|
var win = getWin(popupEle);
|
|
42
|
-
win.addEventListener('mousedown',
|
|
43
|
-
win.addEventListener('click',
|
|
56
|
+
win.addEventListener('mousedown', onWinMouseDown);
|
|
57
|
+
win.addEventListener('click', onWinClick);
|
|
44
58
|
|
|
45
59
|
// shadow root
|
|
46
60
|
var targetShadowRoot = getShadowRoot(targetEle);
|
|
47
61
|
if (targetShadowRoot) {
|
|
48
|
-
targetShadowRoot.addEventListener('mousedown',
|
|
49
|
-
targetShadowRoot.addEventListener('click',
|
|
62
|
+
targetShadowRoot.addEventListener('mousedown', onShadowMouseDown);
|
|
63
|
+
targetShadowRoot.addEventListener('click', onShadowClick);
|
|
50
64
|
}
|
|
51
65
|
|
|
52
66
|
// Warning if target and popup not in same root
|
|
@@ -57,11 +71,11 @@ export default function useWinClick(open, clickToHide, targetEle, popupEle, mask
|
|
|
57
71
|
warning(targetRoot === popupRoot, "trigger element and popup element should in same shadow root.");
|
|
58
72
|
}
|
|
59
73
|
return function () {
|
|
60
|
-
win.removeEventListener('mousedown',
|
|
61
|
-
win.removeEventListener('click',
|
|
74
|
+
win.removeEventListener('mousedown', onWinMouseDown);
|
|
75
|
+
win.removeEventListener('click', onWinClick);
|
|
62
76
|
if (targetShadowRoot) {
|
|
63
|
-
targetShadowRoot.removeEventListener('mousedown',
|
|
64
|
-
targetShadowRoot.removeEventListener('click',
|
|
77
|
+
targetShadowRoot.removeEventListener('mousedown', onShadowMouseDown);
|
|
78
|
+
targetShadowRoot.removeEventListener('click', onShadowClick);
|
|
65
79
|
}
|
|
66
80
|
};
|
|
67
81
|
}
|
package/lib/hooks/useAlign.js
CHANGED
|
@@ -387,36 +387,36 @@ function useAlign(open, popupEle, target, placement, builtinPlacements, popupAli
|
|
|
387
387
|
var numShiftX = shiftX === true ? 0 : shiftX;
|
|
388
388
|
if (typeof numShiftX === 'number') {
|
|
389
389
|
// Left
|
|
390
|
-
if (nextPopupX <
|
|
391
|
-
nextOffsetX -= nextPopupX -
|
|
392
|
-
if (targetRect.x + targetWidth <
|
|
393
|
-
nextOffsetX += targetRect.x -
|
|
390
|
+
if (nextPopupX < visibleRegionArea.left) {
|
|
391
|
+
nextOffsetX -= nextPopupX - visibleRegionArea.left;
|
|
392
|
+
if (targetRect.x + targetWidth < visibleRegionArea.left + numShiftX) {
|
|
393
|
+
nextOffsetX += targetRect.x - visibleRegionArea.left + targetWidth - numShiftX;
|
|
394
394
|
}
|
|
395
395
|
}
|
|
396
396
|
|
|
397
397
|
// Right
|
|
398
|
-
if (nextPopupRight >
|
|
399
|
-
nextOffsetX -= nextPopupRight -
|
|
400
|
-
if (targetRect.x >
|
|
401
|
-
nextOffsetX += targetRect.x -
|
|
398
|
+
if (nextPopupRight > visibleRegionArea.right) {
|
|
399
|
+
nextOffsetX -= nextPopupRight - visibleRegionArea.right;
|
|
400
|
+
if (targetRect.x > visibleRegionArea.right - numShiftX) {
|
|
401
|
+
nextOffsetX += targetRect.x - visibleRegionArea.right + numShiftX;
|
|
402
402
|
}
|
|
403
403
|
}
|
|
404
404
|
}
|
|
405
405
|
var numShiftY = shiftY === true ? 0 : shiftY;
|
|
406
406
|
if (typeof numShiftY === 'number') {
|
|
407
407
|
// Top
|
|
408
|
-
if (nextPopupY <
|
|
409
|
-
nextOffsetY -= nextPopupY -
|
|
410
|
-
if (targetRect.y + targetHeight <
|
|
411
|
-
nextOffsetY += targetRect.y -
|
|
408
|
+
if (nextPopupY < visibleRegionArea.top) {
|
|
409
|
+
nextOffsetY -= nextPopupY - visibleRegionArea.top;
|
|
410
|
+
if (targetRect.y + targetHeight < visibleRegionArea.top + numShiftY) {
|
|
411
|
+
nextOffsetY += targetRect.y - visibleRegionArea.top + targetHeight - numShiftY;
|
|
412
412
|
}
|
|
413
413
|
}
|
|
414
414
|
|
|
415
415
|
// Bottom
|
|
416
|
-
if (nextPopupBottom >
|
|
417
|
-
nextOffsetY -= nextPopupBottom -
|
|
418
|
-
if (targetRect.y >
|
|
419
|
-
nextOffsetY += targetRect.y -
|
|
416
|
+
if (nextPopupBottom > visibleRegionArea.bottom) {
|
|
417
|
+
nextOffsetY -= nextPopupBottom - visibleRegionArea.bottom;
|
|
418
|
+
if (targetRect.y > visibleRegionArea.bottom - numShiftY) {
|
|
419
|
+
nextOffsetY += targetRect.y - visibleRegionArea.bottom + numShiftY;
|
|
420
420
|
}
|
|
421
421
|
}
|
|
422
422
|
}
|
package/lib/hooks/useWinClick.js
CHANGED
|
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
value: true
|
|
7
7
|
});
|
|
8
8
|
exports.default = useWinClick;
|
|
9
|
+
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
9
10
|
var _rcUtil = require("rc-util");
|
|
10
11
|
var _shadow = require("rc-util/lib/Dom/shadow");
|
|
11
12
|
var _raf = _interopRequireDefault(require("rc-util/lib/raf"));
|
|
@@ -32,29 +33,42 @@ function useWinClick(open, clickToHide, targetEle, popupEle, mask, maskClosable,
|
|
|
32
33
|
// Click to hide is special action since click popup element should not hide
|
|
33
34
|
React.useEffect(function () {
|
|
34
35
|
if (clickToHide && popupEle && (!mask || maskClosable)) {
|
|
35
|
-
var
|
|
36
|
+
var genClickEvents = function genClickEvents() {
|
|
37
|
+
var clickInside = false;
|
|
36
38
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
39
|
+
// User may mouseDown inside and drag out of popup and mouse up
|
|
40
|
+
// Record here to prevent close
|
|
41
|
+
var onWindowMouseDown = function onWindowMouseDown(_ref) {
|
|
42
|
+
var target = _ref.target;
|
|
43
|
+
clickInside = inPopupOrChild(target);
|
|
44
|
+
};
|
|
45
|
+
var onWindowClick = function onWindowClick(_ref2) {
|
|
46
|
+
var target = _ref2.target;
|
|
47
|
+
if (!lockRef.current && openRef.current && !clickInside && !inPopupOrChild(target)) {
|
|
48
|
+
triggerOpen(false);
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
return [onWindowMouseDown, onWindowClick];
|
|
48
52
|
};
|
|
53
|
+
|
|
54
|
+
// Events
|
|
55
|
+
var _genClickEvents = genClickEvents(),
|
|
56
|
+
_genClickEvents2 = (0, _slicedToArray2.default)(_genClickEvents, 2),
|
|
57
|
+
onWinMouseDown = _genClickEvents2[0],
|
|
58
|
+
onWinClick = _genClickEvents2[1];
|
|
59
|
+
var _genClickEvents3 = genClickEvents(),
|
|
60
|
+
_genClickEvents4 = (0, _slicedToArray2.default)(_genClickEvents3, 2),
|
|
61
|
+
onShadowMouseDown = _genClickEvents4[0],
|
|
62
|
+
onShadowClick = _genClickEvents4[1];
|
|
49
63
|
var win = (0, _util.getWin)(popupEle);
|
|
50
|
-
win.addEventListener('mousedown',
|
|
51
|
-
win.addEventListener('click',
|
|
64
|
+
win.addEventListener('mousedown', onWinMouseDown);
|
|
65
|
+
win.addEventListener('click', onWinClick);
|
|
52
66
|
|
|
53
67
|
// shadow root
|
|
54
68
|
var targetShadowRoot = (0, _shadow.getShadowRoot)(targetEle);
|
|
55
69
|
if (targetShadowRoot) {
|
|
56
|
-
targetShadowRoot.addEventListener('mousedown',
|
|
57
|
-
targetShadowRoot.addEventListener('click',
|
|
70
|
+
targetShadowRoot.addEventListener('mousedown', onShadowMouseDown);
|
|
71
|
+
targetShadowRoot.addEventListener('click', onShadowClick);
|
|
58
72
|
}
|
|
59
73
|
|
|
60
74
|
// Warning if target and popup not in same root
|
|
@@ -65,11 +79,11 @@ function useWinClick(open, clickToHide, targetEle, popupEle, mask, maskClosable,
|
|
|
65
79
|
(0, _rcUtil.warning)(targetRoot === popupRoot, "trigger element and popup element should in same shadow root.");
|
|
66
80
|
}
|
|
67
81
|
return function () {
|
|
68
|
-
win.removeEventListener('mousedown',
|
|
69
|
-
win.removeEventListener('click',
|
|
82
|
+
win.removeEventListener('mousedown', onWinMouseDown);
|
|
83
|
+
win.removeEventListener('click', onWinClick);
|
|
70
84
|
if (targetShadowRoot) {
|
|
71
|
-
targetShadowRoot.removeEventListener('mousedown',
|
|
72
|
-
targetShadowRoot.removeEventListener('click',
|
|
85
|
+
targetShadowRoot.removeEventListener('mousedown', onShadowMouseDown);
|
|
86
|
+
targetShadowRoot.removeEventListener('click', onShadowClick);
|
|
73
87
|
}
|
|
74
88
|
};
|
|
75
89
|
}
|