@rc-component/trigger 1.7.1 → 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.
@@ -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
- (scrollerList || []).forEach(function (ele) {
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;
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
  }
@@ -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
- (scrollerList || []).forEach(function (ele) {
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)) {
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
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rc-component/trigger",
3
- "version": "1.7.1",
3
+ "version": "1.7.2",
4
4
  "description": "base abstract trigger component for react",
5
5
  "engines": {
6
6
  "node": ">=8.x"