@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.
@@ -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 < visibleArea.left) {
383
- nextOffsetX -= nextPopupX - visibleArea.left;
384
- if (targetRect.x + targetWidth < visibleArea.left + numShiftX) {
385
- nextOffsetX += targetRect.x - visibleArea.left + targetWidth - numShiftX;
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 > visibleArea.right) {
391
- nextOffsetX -= nextPopupRight - visibleArea.right;
392
- if (targetRect.x > visibleArea.right - numShiftX) {
393
- nextOffsetX += targetRect.x - visibleArea.right + numShiftX;
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 < visibleArea.top) {
401
- nextOffsetY -= nextPopupY - visibleArea.top;
402
- if (targetRect.y + targetHeight < visibleArea.top + numShiftY) {
403
- nextOffsetY += targetRect.y - visibleArea.top + targetHeight - numShiftY;
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 > visibleArea.bottom) {
409
- nextOffsetY -= nextPopupBottom - visibleArea.bottom;
410
- if (targetRect.y > visibleArea.bottom - numShiftY) {
411
- nextOffsetY += targetRect.y - visibleArea.bottom + numShiftY;
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
  }
@@ -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 clickInside = false;
28
+ var genClickEvents = function genClickEvents() {
29
+ var clickInside = false;
28
30
 
29
- // User may mouseDown inside and drag out of popup and mouse up
30
- // Record here to prevent close
31
- var onWindowMouseDown = function onWindowMouseDown(_ref) {
32
- var target = _ref.target;
33
- clickInside = inPopupOrChild(target);
34
- };
35
- var onWindowClick = function onWindowClick(_ref2) {
36
- var target = _ref2.target;
37
- if (!lockRef.current && openRef.current && !clickInside && !inPopupOrChild(target)) {
38
- triggerOpen(false);
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', onWindowMouseDown);
43
- win.addEventListener('click', onWindowClick);
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', onWindowMouseDown);
49
- targetShadowRoot.addEventListener('click', onWindowClick);
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', onWindowMouseDown);
61
- win.removeEventListener('click', onWindowClick);
74
+ win.removeEventListener('mousedown', onWinMouseDown);
75
+ win.removeEventListener('click', onWinClick);
62
76
  if (targetShadowRoot) {
63
- targetShadowRoot.removeEventListener('mousedown', onWindowMouseDown);
64
- targetShadowRoot.removeEventListener('click', onWindowClick);
77
+ targetShadowRoot.removeEventListener('mousedown', onShadowMouseDown);
78
+ targetShadowRoot.removeEventListener('click', onShadowClick);
65
79
  }
66
80
  };
67
81
  }
@@ -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 < visibleArea.left) {
391
- nextOffsetX -= nextPopupX - visibleArea.left;
392
- if (targetRect.x + targetWidth < visibleArea.left + numShiftX) {
393
- nextOffsetX += targetRect.x - visibleArea.left + targetWidth - numShiftX;
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 > visibleArea.right) {
399
- nextOffsetX -= nextPopupRight - visibleArea.right;
400
- if (targetRect.x > visibleArea.right - numShiftX) {
401
- nextOffsetX += targetRect.x - visibleArea.right + numShiftX;
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 < visibleArea.top) {
409
- nextOffsetY -= nextPopupY - visibleArea.top;
410
- if (targetRect.y + targetHeight < visibleArea.top + numShiftY) {
411
- nextOffsetY += targetRect.y - visibleArea.top + targetHeight - numShiftY;
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 > visibleArea.bottom) {
417
- nextOffsetY -= nextPopupBottom - visibleArea.bottom;
418
- if (targetRect.y > visibleArea.bottom - numShiftY) {
419
- nextOffsetY += targetRect.y - visibleArea.bottom + numShiftY;
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
  }
@@ -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 clickInside = false;
36
+ var genClickEvents = function genClickEvents() {
37
+ var clickInside = false;
36
38
 
37
- // User may mouseDown inside and drag out of popup and mouse up
38
- // Record here to prevent close
39
- var onWindowMouseDown = function onWindowMouseDown(_ref) {
40
- var target = _ref.target;
41
- clickInside = inPopupOrChild(target);
42
- };
43
- var onWindowClick = function onWindowClick(_ref2) {
44
- var target = _ref2.target;
45
- if (!lockRef.current && openRef.current && !clickInside && !inPopupOrChild(target)) {
46
- triggerOpen(false);
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', onWindowMouseDown);
51
- win.addEventListener('click', onWindowClick);
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', onWindowMouseDown);
57
- targetShadowRoot.addEventListener('click', onWindowClick);
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', onWindowMouseDown);
69
- win.removeEventListener('click', onWindowClick);
82
+ win.removeEventListener('mousedown', onWinMouseDown);
83
+ win.removeEventListener('click', onWinClick);
70
84
  if (targetShadowRoot) {
71
- targetShadowRoot.removeEventListener('mousedown', onWindowMouseDown);
72
- targetShadowRoot.removeEventListener('click', onWindowClick);
85
+ targetShadowRoot.removeEventListener('mousedown', onShadowMouseDown);
86
+ targetShadowRoot.removeEventListener('click', onShadowClick);
73
87
  }
74
88
  };
75
89
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rc-component/trigger",
3
- "version": "1.13.4",
3
+ "version": "1.13.6",
4
4
  "description": "base abstract trigger component for react",
5
5
  "engines": {
6
6
  "node": ">=8.x"