@ringcentral/juno 2.4.1 → 2.5.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/components/Buttons/IconButton/IconButton.d.ts +6 -2
- package/components/Buttons/IconButton/IconButton.js +9 -7
- package/components/Buttons/IconButton/styles/StyledIconButton.js +15 -7
- package/components/Buttons/IconButton/utils/IconButtonUtils.d.ts +1 -1
- package/components/Buttons/IconButton/utils/IconButtonUtils.js +9 -1
- package/components/Dialer/DialPad/DialPad.d.ts +25 -7
- package/components/Dialer/DialPad/DialPad.js +6 -6
- package/components/Dialer/DialPad/utils/useDialKeyboard.d.ts +8 -9
- package/components/Dialer/DialTextField/DialTextField.d.ts +3 -1
- package/components/Dialer/DialTextField/DialTextField.js +7 -6
- package/components/Downshift/SuggestionList/SuggestionList.d.ts +74 -2
- package/components/Downshift/SuggestionList/SuggestionList.js +4 -1
- package/components/Downshift/styles/DownshiftStyle.d.ts +1 -1
- package/components/Forms/Picker/DatePicker/styles/StyledDatePickerHeader.d.ts +1 -1
- package/components/Forms/Picker/DatePicker/styles/StyledYear.d.ts +1 -1
- package/components/Forms/Picker/TimePicker/styles/StyledSelectionItem.d.ts +1 -1
- package/components/Forms/Picker/TimePicker/styles/StyledTimeIconButton.d.ts +1 -1
- package/components/Forms/Picker/styles/PickerBaseIconButton.d.ts +1 -1
- package/components/Forms/TextField/styles/ClearIconButton.d.ts +2 -2
- package/components/Grid/Grid.d.ts +1 -1
- package/components/Pagination/Pagination/Pagination.d.ts +1 -1
- package/components/Stepper/StepButton/StepButton.d.ts +1 -1
- package/components/Stepper/StepLabel/StepLabel.d.ts +1 -1
- package/components/Table/TableCell/styles/TableCellStyle.js +3 -1
- package/components/Table/types.d.ts +1 -1
- package/components/TablePagination/TablePagination.d.ts +1 -1
- package/components/VirtualizedMenu/VirtualizedMenu.js +11 -0
- package/components/VirtualizedMenu/VirtualizedMenuList.js +7 -14
- package/components/Virtuoso/react-virtuoso/AATree.js +15 -15
- package/components/Virtuoso/react-virtuoso/Grid.d.ts +193 -106
- package/components/Virtuoso/react-virtuoso/Grid.js +19 -24
- package/components/Virtuoso/react-virtuoso/List.d.ts +2664 -596
- package/components/Virtuoso/react-virtuoso/List.js +83 -70
- package/components/Virtuoso/react-virtuoso/Table.d.ts +6253 -0
- package/components/Virtuoso/react-virtuoso/Table.js +184 -0
- package/components/Virtuoso/react-virtuoso/alignToBottomSystem.d.ts +153 -37
- package/components/Virtuoso/react-virtuoso/components.d.ts +248 -41
- package/components/Virtuoso/react-virtuoso/components.js +2 -0
- package/components/Virtuoso/react-virtuoso/domIOSystem.d.ts +2 -4
- package/components/Virtuoso/react-virtuoso/domIOSystem.js +12 -10
- package/components/Virtuoso/react-virtuoso/followOutputSystem.d.ts +146 -27
- package/components/Virtuoso/react-virtuoso/followOutputSystem.js +28 -15
- package/components/Virtuoso/react-virtuoso/gridSystem.d.ts +67 -52
- package/components/Virtuoso/react-virtuoso/gridSystem.js +17 -15
- package/components/Virtuoso/react-virtuoso/groupedListSystem.d.ts +17 -3
- package/components/Virtuoso/react-virtuoso/hooks/useChangedChildSizes.d.ts +2 -1
- package/components/Virtuoso/react-virtuoso/hooks/useChangedChildSizes.js +32 -7
- package/components/Virtuoso/react-virtuoso/hooks/useScrollTop.d.ts +1 -1
- package/components/Virtuoso/react-virtuoso/hooks/useScrollTop.js +40 -26
- package/components/Virtuoso/react-virtuoso/hooks/useSize.d.ts +2 -2
- package/components/Virtuoso/react-virtuoso/hooks/useSize.js +26 -28
- package/components/Virtuoso/react-virtuoso/hooks/useWindowViewportRect.d.ts +1 -1
- package/components/Virtuoso/react-virtuoso/hooks/useWindowViewportRect.js +32 -12
- package/components/Virtuoso/react-virtuoso/index.d.ts +1 -0
- package/components/Virtuoso/react-virtuoso/index.js +2 -0
- package/components/Virtuoso/react-virtuoso/initialItemCountSystem.d.ts +165 -35
- package/components/Virtuoso/react-virtuoso/initialItemCountSystem.js +1 -8
- package/components/Virtuoso/react-virtuoso/initialScrollTopSystem.d.ts +160 -38
- package/components/Virtuoso/react-virtuoso/initialTopMostItemIndexSystem.d.ts +54 -12
- package/components/Virtuoso/react-virtuoso/initialTopMostItemIndexSystem.js +26 -10
- package/components/Virtuoso/react-virtuoso/interfaces.d.ts +134 -28
- package/components/Virtuoso/react-virtuoso/listStateSystem.d.ts +141 -32
- package/components/Virtuoso/react-virtuoso/listStateSystem.js +1 -2
- package/components/Virtuoso/react-virtuoso/listSystem.d.ts +2123 -407
- package/components/Virtuoso/react-virtuoso/listSystem.js +10 -7
- package/components/Virtuoso/react-virtuoso/loggerSystem.d.ts +17 -0
- package/components/Virtuoso/react-virtuoso/loggerSystem.js +37 -0
- package/components/Virtuoso/react-virtuoso/propsReadySystem.d.ts +8 -1
- package/components/Virtuoso/react-virtuoso/propsReadySystem.js +8 -2
- package/components/Virtuoso/react-virtuoso/scrollIntoViewSystem.d.ts +641 -0
- package/components/Virtuoso/react-virtuoso/scrollIntoViewSystem.js +42 -0
- package/components/Virtuoso/react-virtuoso/scrollSeekSystem.d.ts +52 -67
- package/components/Virtuoso/react-virtuoso/scrollSeekSystem.js +11 -25
- package/components/Virtuoso/react-virtuoso/scrollToIndexSystem.d.ts +26 -5
- package/components/Virtuoso/react-virtuoso/scrollToIndexSystem.js +37 -13
- package/components/Virtuoso/react-virtuoso/sizeRangeSystem.d.ts +11 -4
- package/components/Virtuoso/react-virtuoso/sizeRangeSystem.js +44 -15
- package/components/Virtuoso/react-virtuoso/sizeSystem.d.ts +12 -2
- package/components/Virtuoso/react-virtuoso/sizeSystem.js +109 -52
- package/components/Virtuoso/react-virtuoso/stateFlagsSystem.d.ts +17 -5
- package/components/Virtuoso/react-virtuoso/stateFlagsSystem.js +87 -18
- package/components/Virtuoso/react-virtuoso/topItemCountSystem.d.ts +145 -33
- package/components/Virtuoso/react-virtuoso/totalListHeightSystem.d.ts +149 -35
- package/components/Virtuoso/react-virtuoso/upwardScrollFixSystem.d.ts +183 -42
- package/components/Virtuoso/react-virtuoso/upwardScrollFixSystem.js +37 -26
- package/components/Virtuoso/react-virtuoso/utils/correctItemSize.d.ts +1 -0
- package/components/Virtuoso/react-virtuoso/utils/correctItemSize.js +6 -0
- package/components/Virtuoso/react-virtuoso/windowScrollerSystem.d.ts +7 -4
- package/components/Virtuoso/react-virtuoso/windowScrollerSystem.js +9 -7
- package/components/Virtuoso/utils/useHighlightScroll.d.ts +4 -0
- package/components/Virtuoso/utils/useHighlightScroll.js +17 -0
- package/es6/components/Buttons/IconButton/IconButton.js +11 -9
- package/es6/components/Buttons/IconButton/styles/StyledIconButton.js +16 -8
- package/es6/components/Buttons/IconButton/utils/IconButtonUtils.js +9 -1
- package/es6/components/Dialer/DialPad/DialPad.js +6 -6
- package/es6/components/Dialer/DialTextField/DialTextField.js +7 -6
- package/es6/components/Downshift/SuggestionList/SuggestionList.js +5 -2
- package/es6/components/Table/TableCell/TableCell.js +2 -2
- package/es6/components/Table/TableCell/styles/TableCellStyle.js +3 -1
- package/es6/components/VirtualizedMenu/VirtualizedMenu.js +13 -2
- package/es6/components/VirtualizedMenu/VirtualizedMenuList.js +9 -16
- package/es6/components/Virtuoso/react-virtuoso/AATree.js +15 -15
- package/es6/components/Virtuoso/react-virtuoso/Grid.js +20 -25
- package/es6/components/Virtuoso/react-virtuoso/List.js +84 -72
- package/es6/components/Virtuoso/react-virtuoso/Table.js +182 -0
- package/es6/components/Virtuoso/react-virtuoso/components.js +2 -0
- package/es6/components/Virtuoso/react-virtuoso/domIOSystem.js +13 -10
- package/es6/components/Virtuoso/react-virtuoso/followOutputSystem.js +28 -15
- package/es6/components/Virtuoso/react-virtuoso/gridSystem.js +17 -15
- package/es6/components/Virtuoso/react-virtuoso/hooks/useChangedChildSizes.js +31 -6
- package/es6/components/Virtuoso/react-virtuoso/hooks/useScrollTop.js +40 -26
- package/es6/components/Virtuoso/react-virtuoso/hooks/useSize.js +27 -29
- package/es6/components/Virtuoso/react-virtuoso/hooks/useWindowViewportRect.js +32 -12
- package/es6/components/Virtuoso/react-virtuoso/index.js +1 -0
- package/es6/components/Virtuoso/react-virtuoso/initialItemCountSystem.js +1 -8
- package/es6/components/Virtuoso/react-virtuoso/initialTopMostItemIndexSystem.js +25 -10
- package/es6/components/Virtuoso/react-virtuoso/listStateSystem.js +2 -3
- package/es6/components/Virtuoso/react-virtuoso/listSystem.js +10 -7
- package/es6/components/Virtuoso/react-virtuoso/loggerSystem.js +34 -0
- package/es6/components/Virtuoso/react-virtuoso/propsReadySystem.js +9 -2
- package/es6/components/Virtuoso/react-virtuoso/scrollIntoViewSystem.js +40 -0
- package/es6/components/Virtuoso/react-virtuoso/scrollSeekSystem.js +11 -25
- package/es6/components/Virtuoso/react-virtuoso/scrollToIndexSystem.js +37 -13
- package/es6/components/Virtuoso/react-virtuoso/sizeRangeSystem.js +39 -11
- package/es6/components/Virtuoso/react-virtuoso/sizeSystem.js +109 -52
- package/es6/components/Virtuoso/react-virtuoso/stateFlagsSystem.js +87 -18
- package/es6/components/Virtuoso/react-virtuoso/upwardScrollFixSystem.js +39 -28
- package/es6/components/Virtuoso/react-virtuoso/utils/correctItemSize.js +3 -0
- package/es6/components/Virtuoso/react-virtuoso/windowScrollerSystem.js +9 -7
- package/es6/components/Virtuoso/utils/useHighlightScroll.js +16 -0
- package/es6/foundation/hooks/useLongPress/useLongPress.js +7 -7
- package/es6/foundation/index.js +1 -1
- package/es6/foundation/isWebKit154.js +57 -0
- package/es6/foundation/theme/ThemeProvider.js +4 -4
- package/foundation/hooks/useLongPress/useLongPress.d.ts +3 -1
- package/foundation/hooks/useLongPress/useLongPress.js +7 -7
- package/foundation/index.d.ts +1 -1
- package/foundation/index.js +1 -1
- package/foundation/isWebKit154.d.ts +20 -0
- package/foundation/{isSafari154.js → isWebKit154.js} +22 -17
- package/foundation/theme/ThemeProvider.d.ts +1 -1
- package/foundation/theme/ThemeProvider.js +4 -4
- package/package.json +2 -2
- package/es6/foundation/isSafari154.js +0 -52
- package/foundation/isSafari154.d.ts +0 -15
|
@@ -3,23 +3,32 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
var tslib_1 = require("tslib");
|
|
4
4
|
var react_1 = require("react");
|
|
5
5
|
var u = tslib_1.__importStar(require("@virtuoso.dev/urx"));
|
|
6
|
-
|
|
6
|
+
var correctItemSize_1 = require("../utils/correctItemSize");
|
|
7
|
+
var foundation_1 = require("../../../../foundation");
|
|
8
|
+
function approximatelyEqual(num1, num2) {
|
|
9
|
+
return Math.abs(num1 - num2) < 1.01;
|
|
10
|
+
}
|
|
11
|
+
function useScrollTop(scrollContainerStateCallback, smoothScrollTargetReached, scrollerElement, scrollerRefCallback, customScrollParent) {
|
|
7
12
|
if (scrollerRefCallback === void 0) { scrollerRefCallback = u.noop; }
|
|
8
|
-
if (customWindow === void 0) { customWindow = window; }
|
|
9
13
|
var scrollerRef = react_1.useRef(null);
|
|
10
14
|
var scrollTopTarget = react_1.useRef(null);
|
|
11
15
|
var timeoutRef = react_1.useRef(null);
|
|
12
|
-
var
|
|
16
|
+
var _a = foundation_1.useRcPortalWindowContext().externalWindow, externalWindow = _a === void 0 ? window : _a;
|
|
13
17
|
var handler = react_1.useCallback(function (ev) {
|
|
14
18
|
var el = ev.target;
|
|
15
|
-
var scrollTop = el ===
|
|
16
|
-
|
|
19
|
+
var scrollTop = el === externalWindow ||
|
|
20
|
+
el === externalWindow.document
|
|
21
|
+
? externalWindow.pageYOffset ||
|
|
22
|
+
externalWindow.document.documentElement.scrollTop
|
|
17
23
|
: el.scrollTop;
|
|
18
|
-
|
|
24
|
+
var scrollHeight = el === externalWindow
|
|
25
|
+
? externalWindow.document.documentElement.scrollHeight
|
|
26
|
+
: el.scrollHeight;
|
|
27
|
+
scrollContainerStateCallback([Math.max(scrollTop, 0), scrollHeight]);
|
|
19
28
|
if (scrollTopTarget.current !== null) {
|
|
20
29
|
if (scrollTop === scrollTopTarget.current ||
|
|
21
30
|
scrollTop <= 0 ||
|
|
22
|
-
scrollTop === el.scrollHeight - el
|
|
31
|
+
scrollTop === el.scrollHeight - correctItemSize_1.correctItemSize(el, 'height')) {
|
|
23
32
|
scrollTopTarget.current = null;
|
|
24
33
|
smoothScrollTargetReached(true);
|
|
25
34
|
if (timeoutRef.current) {
|
|
@@ -28,54 +37,59 @@ function useScrollTop(scrollTopCallback, smoothScrollTargetReached, scrollerElem
|
|
|
28
37
|
}
|
|
29
38
|
}
|
|
30
39
|
}
|
|
31
|
-
}, [
|
|
32
|
-
customDocument,
|
|
33
|
-
customWindow,
|
|
34
|
-
scrollTopCallback,
|
|
35
|
-
smoothScrollTargetReached,
|
|
36
|
-
]);
|
|
40
|
+
}, [externalWindow, scrollContainerStateCallback, smoothScrollTargetReached]);
|
|
37
41
|
react_1.useEffect(function () {
|
|
38
|
-
var localRef =
|
|
39
|
-
|
|
42
|
+
var localRef = customScrollParent
|
|
43
|
+
? customScrollParent
|
|
44
|
+
: scrollerRef.current;
|
|
45
|
+
scrollerRefCallback(customScrollParent ? customScrollParent : scrollerRef.current);
|
|
40
46
|
handler({ target: localRef });
|
|
41
47
|
localRef.addEventListener('scroll', handler, { passive: true });
|
|
42
48
|
return function () {
|
|
43
49
|
scrollerRefCallback(null);
|
|
44
50
|
localRef.removeEventListener('scroll', handler);
|
|
45
51
|
};
|
|
46
|
-
}, [
|
|
52
|
+
}, [
|
|
53
|
+
scrollerRef,
|
|
54
|
+
handler,
|
|
55
|
+
scrollerElement,
|
|
56
|
+
scrollerRefCallback,
|
|
57
|
+
customScrollParent,
|
|
58
|
+
]);
|
|
47
59
|
function scrollToCallback(location) {
|
|
48
60
|
var scrollerElement = scrollerRef.current;
|
|
49
|
-
if (!scrollerElement
|
|
61
|
+
if (!scrollerElement ||
|
|
62
|
+
('offsetHeight' in scrollerElement && scrollerElement.offsetHeight === 0)) {
|
|
50
63
|
return;
|
|
51
64
|
}
|
|
52
65
|
var isSmooth = location.behavior === 'smooth';
|
|
53
66
|
var offsetHeight;
|
|
54
67
|
var scrollHeight;
|
|
55
68
|
var scrollTop;
|
|
56
|
-
if (scrollerElement ===
|
|
69
|
+
if (scrollerElement === externalWindow) {
|
|
57
70
|
// this is not a mistake
|
|
58
|
-
scrollHeight = Math.max(
|
|
59
|
-
offsetHeight =
|
|
60
|
-
scrollTop =
|
|
71
|
+
scrollHeight = Math.max(correctItemSize_1.correctItemSize(externalWindow.document.documentElement, 'height'), externalWindow.document.documentElement.scrollHeight);
|
|
72
|
+
offsetHeight = externalWindow.window.innerHeight;
|
|
73
|
+
scrollTop = externalWindow.document.documentElement.scrollTop;
|
|
61
74
|
}
|
|
62
75
|
else {
|
|
63
76
|
scrollHeight = scrollerElement.scrollHeight;
|
|
64
|
-
offsetHeight = scrollerElement
|
|
77
|
+
offsetHeight = correctItemSize_1.correctItemSize(scrollerElement, 'height');
|
|
65
78
|
scrollTop = scrollerElement.scrollTop;
|
|
66
79
|
}
|
|
80
|
+
var maxScrollTop = scrollHeight - offsetHeight;
|
|
81
|
+
location.top = Math.ceil(Math.max(Math.min(maxScrollTop, location.top), 0));
|
|
67
82
|
// avoid system hanging because the DOM never called back
|
|
68
83
|
// with the scrollTop
|
|
69
84
|
// scroller is already at this location
|
|
70
|
-
if (offsetHeight
|
|
71
|
-
|
|
85
|
+
if (approximatelyEqual(offsetHeight, scrollHeight) ||
|
|
86
|
+
location.top === scrollTop) {
|
|
87
|
+
scrollContainerStateCallback([scrollTop, scrollHeight]);
|
|
72
88
|
if (isSmooth) {
|
|
73
89
|
smoothScrollTargetReached(true);
|
|
74
90
|
}
|
|
75
91
|
return;
|
|
76
92
|
}
|
|
77
|
-
var maxScrollTop = scrollHeight - offsetHeight;
|
|
78
|
-
location.top = Math.max(Math.min(maxScrollTop, location.top), 0);
|
|
79
93
|
if (isSmooth) {
|
|
80
94
|
scrollTopTarget.current = location.top;
|
|
81
95
|
if (timeoutRef.current) {
|
|
@@ -3,6 +3,6 @@
|
|
|
3
3
|
export declare type CallbackRefParam = HTMLElement | null;
|
|
4
4
|
export declare function useSizeWithElRef(callback: (e: HTMLElement) => void, enabled?: boolean): {
|
|
5
5
|
ref: import("react").MutableRefObject<HTMLElement | null>;
|
|
6
|
-
callbackRef: (
|
|
6
|
+
callbackRef: (_el: HTMLElement | null) => void;
|
|
7
7
|
};
|
|
8
|
-
export default function useSize(callback: (e: HTMLElement) => void, enabled?: boolean): (
|
|
8
|
+
export default function useSize(callback: (e: HTMLElement) => void, enabled?: boolean): (_el: HTMLElement | null) => void;
|
|
@@ -4,36 +4,34 @@ var react_1 = require("react");
|
|
|
4
4
|
var foundation_1 = require("../../../../foundation");
|
|
5
5
|
function useSizeWithElRef(callback, enabled) {
|
|
6
6
|
if (enabled === void 0) { enabled = true; }
|
|
7
|
-
var externalWindow = foundation_1.useRcPortalWindowContext().externalWindow;
|
|
8
7
|
var ref = react_1.useRef(null);
|
|
9
|
-
var
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
//
|
|
13
|
-
|
|
14
|
-
// https://github.com/edunad/react-virtuoso/commit/581d4558f2994adea375291b76fe59605556c08f
|
|
15
|
-
// requestAnimationFrame(() => {
|
|
16
|
-
//
|
|
17
|
-
// if display: none, the element won't have an offsetParent
|
|
18
|
-
// measuring it at this mode is not going to work
|
|
19
|
-
// https://stackoverflow.com/a/21696585/1009797
|
|
20
|
-
if (element.offsetParent !== null) {
|
|
21
|
-
callback(element);
|
|
22
|
-
}
|
|
23
|
-
// })
|
|
24
|
-
}, externalWindow);
|
|
25
|
-
var callbackRef = function (elRef) {
|
|
26
|
-
if (elRef && enabled) {
|
|
27
|
-
observer.observe(elRef);
|
|
28
|
-
ref.current = elRef;
|
|
29
|
-
}
|
|
30
|
-
else {
|
|
31
|
-
if (ref.current) {
|
|
32
|
-
observer.unobserve(ref.current);
|
|
33
|
-
}
|
|
34
|
-
ref.current = null;
|
|
35
|
-
}
|
|
8
|
+
var _a = foundation_1.useRcPortalWindowContext().externalWindow, externalWindow = _a === void 0 ? window : _a;
|
|
9
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
10
|
+
var callbackRef = function (_el) {
|
|
11
|
+
// eslint-disable-next-line no-void
|
|
12
|
+
void 0;
|
|
36
13
|
};
|
|
14
|
+
// TODO: fix after upgrade ts
|
|
15
|
+
if (typeof externalWindow['ResizeObserver'] !== 'undefined') {
|
|
16
|
+
var observer_1 = new externalWindow['ResizeObserver'](function (entries) {
|
|
17
|
+
var element = entries[0].target;
|
|
18
|
+
if (element.offsetParent !== null) {
|
|
19
|
+
callback(element);
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
callbackRef = function (elRef) {
|
|
23
|
+
if (elRef && enabled) {
|
|
24
|
+
observer_1.observe(elRef);
|
|
25
|
+
ref.current = elRef;
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
if (ref.current) {
|
|
29
|
+
observer_1.unobserve(ref.current);
|
|
30
|
+
}
|
|
31
|
+
ref.current = null;
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
}
|
|
37
35
|
return { ref: ref, callbackRef: callbackRef };
|
|
38
36
|
}
|
|
39
37
|
exports.useSizeWithElRef = useSizeWithElRef;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { WindowViewportInfo } from '../interfaces';
|
|
2
|
-
export default function useWindowViewportRectRef(callback: (info: WindowViewportInfo) => void,
|
|
2
|
+
export default function useWindowViewportRectRef(callback: (info: WindowViewportInfo) => void, customScrollParent?: HTMLElement): (_el: HTMLElement | null) => void;
|
|
@@ -1,37 +1,57 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
var react_1 = require("react");
|
|
4
|
+
var foundation_1 = require("../../../../foundation");
|
|
4
5
|
var useSize_1 = require("./useSize");
|
|
5
|
-
function useWindowViewportRectRef(callback,
|
|
6
|
-
if (customWindow === void 0) { customWindow = window; }
|
|
6
|
+
function useWindowViewportRectRef(callback, customScrollParent) {
|
|
7
7
|
var viewportInfo = react_1.useRef(null);
|
|
8
|
+
var _a = foundation_1.useRcPortalWindowContext().externalWindow, externalWindow = _a === void 0 ? window : _a;
|
|
8
9
|
var calculateInfo = react_1.useCallback(function (element) {
|
|
9
10
|
if (element === null) {
|
|
10
11
|
return;
|
|
11
12
|
}
|
|
12
13
|
var rect = element.getBoundingClientRect();
|
|
13
|
-
var visibleHeight = customWindow.innerHeight - Math.max(0, rect.top);
|
|
14
14
|
var visibleWidth = rect.width;
|
|
15
|
-
var
|
|
15
|
+
var visibleHeight;
|
|
16
|
+
var offsetTop;
|
|
17
|
+
if (customScrollParent) {
|
|
18
|
+
var customScrollParentRect = customScrollParent.getBoundingClientRect();
|
|
19
|
+
var deltaTop = rect.top - customScrollParentRect.top;
|
|
20
|
+
visibleHeight = customScrollParentRect.height - Math.max(0, deltaTop);
|
|
21
|
+
offsetTop = deltaTop + customScrollParent.scrollTop;
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
visibleHeight = externalWindow.innerHeight - Math.max(0, rect.top);
|
|
25
|
+
offsetTop = rect.top + externalWindow.pageYOffset;
|
|
26
|
+
}
|
|
16
27
|
viewportInfo.current = {
|
|
17
28
|
offsetTop: offsetTop,
|
|
18
29
|
visibleHeight: visibleHeight,
|
|
19
30
|
visibleWidth: visibleWidth,
|
|
20
31
|
};
|
|
21
32
|
callback(viewportInfo.current);
|
|
22
|
-
}, [callback,
|
|
23
|
-
var
|
|
24
|
-
var
|
|
33
|
+
}, [callback, customScrollParent, externalWindow]);
|
|
34
|
+
var _b = useSize_1.useSizeWithElRef(calculateInfo), callbackRef = _b.callbackRef, ref = _b.ref;
|
|
35
|
+
var scrollAndResizeEventHandler = react_1.useCallback(function () {
|
|
25
36
|
calculateInfo(ref.current);
|
|
26
37
|
}, [calculateInfo, ref]);
|
|
27
38
|
react_1.useEffect(function () {
|
|
28
|
-
|
|
29
|
-
|
|
39
|
+
if (customScrollParent) {
|
|
40
|
+
customScrollParent.addEventListener('scroll', scrollAndResizeEventHandler);
|
|
41
|
+
var observer_1 = new externalWindow['ResizeObserver'](scrollAndResizeEventHandler);
|
|
42
|
+
observer_1.observe(customScrollParent);
|
|
43
|
+
return function () {
|
|
44
|
+
customScrollParent.removeEventListener('scroll', scrollAndResizeEventHandler);
|
|
45
|
+
observer_1.unobserve(customScrollParent);
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
externalWindow.addEventListener('scroll', scrollAndResizeEventHandler);
|
|
49
|
+
externalWindow.addEventListener('resize', scrollAndResizeEventHandler);
|
|
30
50
|
return function () {
|
|
31
|
-
|
|
32
|
-
|
|
51
|
+
externalWindow.removeEventListener('scroll', scrollAndResizeEventHandler);
|
|
52
|
+
externalWindow.removeEventListener('resize', scrollAndResizeEventHandler);
|
|
33
53
|
};
|
|
34
|
-
}, [
|
|
54
|
+
}, [scrollAndResizeEventHandler, customScrollParent, externalWindow]);
|
|
35
55
|
return callbackRef;
|
|
36
56
|
}
|
|
37
57
|
exports.default = useWindowViewportRectRef;
|