@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
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
var _a;
|
|
2
|
+
import { __assign, __read, __spread } from "tslib";
|
|
3
|
+
import * as React from 'react';
|
|
4
|
+
import { createElement } from 'react';
|
|
5
|
+
import { systemToComponent } from '@virtuoso.dev/react-urx';
|
|
6
|
+
import { compose, distinctUntilChanged, map, noop, pipe, statefulStream, statefulStreamFromEmitter, system, tup, } from '@virtuoso.dev/urx';
|
|
7
|
+
import useChangedListContentsSizes from './hooks/useChangedChildSizes';
|
|
8
|
+
import useSize from './hooks/useSize';
|
|
9
|
+
import useWindowViewportRectRef from './hooks/useWindowViewportRect';
|
|
10
|
+
import { buildScroller, buildWindowScroller, contextPropIfNotDomElement, identity, viewportStyle, } from './List';
|
|
11
|
+
import { listSystem } from './listSystem';
|
|
12
|
+
import { correctItemSize } from './utils/correctItemSize';
|
|
13
|
+
var tableComponentPropsSystem = system(function () {
|
|
14
|
+
var itemContent = statefulStream(function (index) { return React.createElement("td", null,
|
|
15
|
+
"Item $",
|
|
16
|
+
index); });
|
|
17
|
+
var context = statefulStream(null);
|
|
18
|
+
var fixedHeaderContent = statefulStream(null);
|
|
19
|
+
var components = statefulStream({});
|
|
20
|
+
var computeItemKey = statefulStream(identity);
|
|
21
|
+
var scrollerRef = statefulStream(noop);
|
|
22
|
+
var distinctProp = function (propName, defaultValue) {
|
|
23
|
+
if (defaultValue === void 0) { defaultValue = null; }
|
|
24
|
+
return statefulStreamFromEmitter(pipe(components, map(function (components) { return components[propName]; }), distinctUntilChanged()), defaultValue);
|
|
25
|
+
};
|
|
26
|
+
return {
|
|
27
|
+
context: context,
|
|
28
|
+
itemContent: itemContent,
|
|
29
|
+
fixedHeaderContent: fixedHeaderContent,
|
|
30
|
+
components: components,
|
|
31
|
+
computeItemKey: computeItemKey,
|
|
32
|
+
scrollerRef: scrollerRef,
|
|
33
|
+
TableComponent: distinctProp('Table', 'table'),
|
|
34
|
+
TableHeadComponent: distinctProp('TableHead', 'thead'),
|
|
35
|
+
TableBodyComponent: distinctProp('TableBody', 'tbody'),
|
|
36
|
+
TableRowComponent: distinctProp('TableRow', 'tr'),
|
|
37
|
+
ScrollerComponent: distinctProp('Scroller', 'div'),
|
|
38
|
+
EmptyPlaceholder: distinctProp('EmptyPlaceholder'),
|
|
39
|
+
ScrollSeekPlaceholder: distinctProp('ScrollSeekPlaceholder'),
|
|
40
|
+
};
|
|
41
|
+
});
|
|
42
|
+
var combinedSystem = system(function (_a) {
|
|
43
|
+
var _b = __read(_a, 2), listSystem = _b[0], propsSystem = _b[1];
|
|
44
|
+
return __assign(__assign({}, listSystem), propsSystem);
|
|
45
|
+
}, tup(listSystem, tableComponentPropsSystem));
|
|
46
|
+
var DefaultScrollSeekPlaceholder = function (_a) {
|
|
47
|
+
var height = _a.height;
|
|
48
|
+
return (React.createElement("tr", null,
|
|
49
|
+
React.createElement("td", { style: { height: height } })));
|
|
50
|
+
};
|
|
51
|
+
var FillerRow = function (_a) {
|
|
52
|
+
var height = _a.height;
|
|
53
|
+
return (React.createElement("tr", null,
|
|
54
|
+
React.createElement("td", { style: { height: height, padding: 0, border: 0 } })));
|
|
55
|
+
};
|
|
56
|
+
export var Items = React.memo(function VirtuosoItems() {
|
|
57
|
+
var listState = useEmitterValue('listState');
|
|
58
|
+
var deviation = useEmitterValue('deviation');
|
|
59
|
+
var sizeRanges = usePublisher('sizeRanges');
|
|
60
|
+
var useWindowScroll = useEmitterValue('useWindowScroll');
|
|
61
|
+
var customScrollParent = useEmitterValue('customScrollParent');
|
|
62
|
+
var windowScrollContainerStateCallback = usePublisher('windowScrollContainerState');
|
|
63
|
+
var _scrollContainerStateCallback = usePublisher('scrollContainerState');
|
|
64
|
+
var scrollContainerStateCallback = customScrollParent || useWindowScroll
|
|
65
|
+
? windowScrollContainerStateCallback
|
|
66
|
+
: _scrollContainerStateCallback;
|
|
67
|
+
var itemContent = useEmitterValue('itemContent');
|
|
68
|
+
var trackItemSizes = useEmitterValue('trackItemSizes');
|
|
69
|
+
var itemSize = useEmitterValue('itemSize');
|
|
70
|
+
var log = useEmitterValue('log');
|
|
71
|
+
var ref = useChangedListContentsSizes(sizeRanges, itemSize, trackItemSizes, scrollContainerStateCallback, log, customScrollParent);
|
|
72
|
+
var EmptyPlaceholder = useEmitterValue('EmptyPlaceholder');
|
|
73
|
+
var ScrollSeekPlaceholder = useEmitterValue('ScrollSeekPlaceholder') || DefaultScrollSeekPlaceholder;
|
|
74
|
+
var TableBodyComponent = useEmitterValue('TableBodyComponent');
|
|
75
|
+
var TableRowComponent = useEmitterValue('TableRowComponent');
|
|
76
|
+
var computeItemKey = useEmitterValue('computeItemKey');
|
|
77
|
+
var isSeeking = useEmitterValue('isSeeking');
|
|
78
|
+
var paddingTopAddition = useEmitterValue('paddingTopAddition');
|
|
79
|
+
var firstItemIndex = useEmitterValue('firstItemIndex');
|
|
80
|
+
var statefulTotalCount = useEmitterValue('statefulTotalCount');
|
|
81
|
+
var context = useEmitterValue('context');
|
|
82
|
+
if (statefulTotalCount === 0 && EmptyPlaceholder) {
|
|
83
|
+
return createElement(EmptyPlaceholder, contextPropIfNotDomElement(EmptyPlaceholder, context));
|
|
84
|
+
}
|
|
85
|
+
var paddingTop = listState.offsetTop + paddingTopAddition + deviation;
|
|
86
|
+
var paddingBottom = listState.offsetBottom;
|
|
87
|
+
var paddingTopEl = paddingTop > 0 ? React.createElement(FillerRow, { height: paddingTop, key: "padding-top" }) : null;
|
|
88
|
+
var paddingBottomEl = paddingBottom > 0 ? (React.createElement(FillerRow, { height: paddingBottom, key: "padding-bottom" })) : null;
|
|
89
|
+
var items = listState.items.map(function (item) {
|
|
90
|
+
var index = item.originalIndex;
|
|
91
|
+
var key = computeItemKey(index + firstItemIndex, item.data, context);
|
|
92
|
+
if (isSeeking) {
|
|
93
|
+
return createElement(ScrollSeekPlaceholder, __assign(__assign({}, contextPropIfNotDomElement(ScrollSeekPlaceholder, context)), { key: key, index: item.index, height: item.size, type: item.type || 'item' }));
|
|
94
|
+
}
|
|
95
|
+
return createElement(TableRowComponent, __assign(__assign({}, contextPropIfNotDomElement(TableRowComponent, context)), { key: key, 'data-index': index, 'data-known-size': item.size, 'data-item-index': item.index, style: { overflowAnchor: 'none' } }), itemContent(item.index, item.data, context));
|
|
96
|
+
});
|
|
97
|
+
return createElement(TableBodyComponent, __assign({ ref: ref, 'data-test-id': 'virtuoso-item-list' }, contextPropIfNotDomElement(TableBodyComponent, context)), __spread([paddingTopEl], items, [paddingBottomEl]));
|
|
98
|
+
});
|
|
99
|
+
var Viewport = function (_a) {
|
|
100
|
+
var children = _a.children;
|
|
101
|
+
var viewportHeight = usePublisher('viewportHeight');
|
|
102
|
+
var viewportRef = useSize(compose(viewportHeight, function (el) { return correctItemSize(el, 'height'); }));
|
|
103
|
+
return (React.createElement("div", { style: viewportStyle, ref: viewportRef, "data-viewport-type": "element" }, children));
|
|
104
|
+
};
|
|
105
|
+
var WindowViewport = function (_a) {
|
|
106
|
+
var children = _a.children;
|
|
107
|
+
var windowViewportRect = usePublisher('windowViewportRect');
|
|
108
|
+
var customScrollParent = useEmitterValue('customScrollParent');
|
|
109
|
+
var viewportRef = useWindowViewportRectRef(windowViewportRect, customScrollParent);
|
|
110
|
+
return (React.createElement("div", { ref: viewportRef, style: viewportStyle, "data-viewport-type": "window" }, children));
|
|
111
|
+
};
|
|
112
|
+
var TableRoot = React.memo(function TableVirtuosoRoot(props) {
|
|
113
|
+
var useWindowScroll = useEmitterValue('useWindowScroll');
|
|
114
|
+
var customScrollParent = useEmitterValue('customScrollParent');
|
|
115
|
+
var fixedHeaderHeight = usePublisher('fixedHeaderHeight');
|
|
116
|
+
var fixedHeaderContent = useEmitterValue('fixedHeaderContent');
|
|
117
|
+
var context = useEmitterValue('context');
|
|
118
|
+
var theadRef = useSize(compose(fixedHeaderHeight, function (el) { return correctItemSize(el, 'height'); }));
|
|
119
|
+
var TheScroller = customScrollParent || useWindowScroll ? WindowScroller : Scroller;
|
|
120
|
+
var TheViewport = customScrollParent || useWindowScroll ? WindowViewport : Viewport;
|
|
121
|
+
var TheTable = useEmitterValue('TableComponent');
|
|
122
|
+
var TheTHead = useEmitterValue('TableHeadComponent');
|
|
123
|
+
var theHead = fixedHeaderContent
|
|
124
|
+
? React.createElement(TheTHead, __assign({ key: 'TableHead', style: { zIndex: 1, position: 'sticky', top: 0 }, ref: theadRef }, contextPropIfNotDomElement(TheTHead, context)), fixedHeaderContent())
|
|
125
|
+
: null;
|
|
126
|
+
return (React.createElement(TheScroller, __assign({}, props),
|
|
127
|
+
React.createElement(TheViewport, null, React.createElement(TheTable, __assign({ style: { borderSpacing: 0 } }, contextPropIfNotDomElement(TheTable, context)), [theHead, React.createElement(Items, { key: "TableBody" })]))));
|
|
128
|
+
});
|
|
129
|
+
export var Table = (_a = systemToComponent(combinedSystem, {
|
|
130
|
+
required: {},
|
|
131
|
+
optional: {
|
|
132
|
+
context: 'context',
|
|
133
|
+
followOutput: 'followOutput',
|
|
134
|
+
firstItemIndex: 'firstItemIndex',
|
|
135
|
+
itemContent: 'itemContent',
|
|
136
|
+
fixedHeaderContent: 'fixedHeaderContent',
|
|
137
|
+
overscan: 'overscan',
|
|
138
|
+
increaseViewportBy: 'increaseViewportBy',
|
|
139
|
+
totalCount: 'totalCount',
|
|
140
|
+
topItemCount: 'topItemCount',
|
|
141
|
+
initialTopMostItemIndex: 'initialTopMostItemIndex',
|
|
142
|
+
components: 'components',
|
|
143
|
+
groupCounts: 'groupCounts',
|
|
144
|
+
atBottomThreshold: 'atBottomThreshold',
|
|
145
|
+
computeItemKey: 'computeItemKey',
|
|
146
|
+
defaultItemHeight: 'defaultItemHeight',
|
|
147
|
+
fixedItemHeight: 'fixedItemHeight',
|
|
148
|
+
itemSize: 'itemSize',
|
|
149
|
+
scrollSeekConfiguration: 'scrollSeekConfiguration',
|
|
150
|
+
data: 'data',
|
|
151
|
+
initialItemCount: 'initialItemCount',
|
|
152
|
+
initialScrollTop: 'initialScrollTop',
|
|
153
|
+
alignToBottom: 'alignToBottom',
|
|
154
|
+
useWindowScroll: 'useWindowScroll',
|
|
155
|
+
customScrollParent: 'customScrollParent',
|
|
156
|
+
scrollerRef: 'scrollerRef',
|
|
157
|
+
logLevel: 'logLevel',
|
|
158
|
+
},
|
|
159
|
+
methods: {
|
|
160
|
+
scrollToIndex: 'scrollToIndex',
|
|
161
|
+
scrollIntoView: 'scrollIntoView',
|
|
162
|
+
scrollTo: 'scrollTo',
|
|
163
|
+
scrollBy: 'scrollBy',
|
|
164
|
+
},
|
|
165
|
+
events: {
|
|
166
|
+
isScrolling: 'isScrolling',
|
|
167
|
+
endReached: 'endReached',
|
|
168
|
+
startReached: 'startReached',
|
|
169
|
+
rangeChanged: 'rangeChanged',
|
|
170
|
+
atBottomStateChange: 'atBottomStateChange',
|
|
171
|
+
atTopStateChange: 'atTopStateChange',
|
|
172
|
+
totalListHeightChanged: 'totalListHeightChanged',
|
|
173
|
+
itemsRendered: 'itemsRendered',
|
|
174
|
+
groupIndices: 'groupIndices',
|
|
175
|
+
},
|
|
176
|
+
}, TableRoot), _a.Component), usePublisher = _a.usePublisher, useEmitterValue = _a.useEmitterValue, useEmitter = _a.useEmitter;
|
|
177
|
+
var Scroller = buildScroller({ usePublisher: usePublisher, useEmitterValue: useEmitterValue, useEmitter: useEmitter });
|
|
178
|
+
var WindowScroller = buildWindowScroller({
|
|
179
|
+
usePublisher: usePublisher,
|
|
180
|
+
useEmitterValue: useEmitterValue,
|
|
181
|
+
useEmitter: useEmitter,
|
|
182
|
+
});
|
|
@@ -1,37 +1,40 @@
|
|
|
1
|
+
import { __read } from "tslib";
|
|
1
2
|
import * as u from '@virtuoso.dev/urx';
|
|
2
|
-
export var UP = 'up';
|
|
3
|
-
export var DOWN = 'down';
|
|
4
3
|
export var domIOSystem = u.system(function () {
|
|
4
|
+
var scrollContainerState = u.stream();
|
|
5
5
|
var scrollTop = u.stream();
|
|
6
6
|
var deviation = u.statefulStream(0);
|
|
7
7
|
var smoothScrollTargetReached = u.stream();
|
|
8
8
|
var statefulScrollTop = u.statefulStream(0);
|
|
9
9
|
var viewportHeight = u.stream();
|
|
10
|
+
var scrollHeight = u.stream();
|
|
10
11
|
var headerHeight = u.statefulStream(0);
|
|
11
12
|
var footerHeight = u.statefulStream(0);
|
|
12
13
|
var scrollTo = u.stream();
|
|
13
14
|
var scrollBy = u.stream();
|
|
14
15
|
var scrollingInProgress = u.statefulStream(false);
|
|
16
|
+
u.connect(u.pipe(scrollContainerState, u.map(function (_a) {
|
|
17
|
+
var _b = __read(_a, 1), scrollTop = _b[0];
|
|
18
|
+
return scrollTop;
|
|
19
|
+
})), scrollTop);
|
|
20
|
+
u.connect(u.pipe(scrollContainerState, u.map(function (_a) {
|
|
21
|
+
var _b = __read(_a, 2), scrollHeight = _b[1];
|
|
22
|
+
return scrollHeight;
|
|
23
|
+
})), scrollHeight);
|
|
15
24
|
u.connect(scrollTop, statefulScrollTop);
|
|
16
|
-
var scrollDirection = u.statefulStream(DOWN);
|
|
17
|
-
u.connect(u.pipe(scrollTop, u.scan(function (acc, scrollTop) {
|
|
18
|
-
return {
|
|
19
|
-
direction: scrollTop < acc.prevScrollTop ? UP : DOWN,
|
|
20
|
-
prevScrollTop: scrollTop,
|
|
21
|
-
};
|
|
22
|
-
}, { direction: DOWN, prevScrollTop: 0 }), u.map(function (value) { return value.direction; })), scrollDirection);
|
|
23
25
|
return {
|
|
24
26
|
// input
|
|
27
|
+
scrollContainerState: scrollContainerState,
|
|
25
28
|
scrollTop: scrollTop,
|
|
26
29
|
viewportHeight: viewportHeight,
|
|
27
30
|
headerHeight: headerHeight,
|
|
28
31
|
footerHeight: footerHeight,
|
|
32
|
+
scrollHeight: scrollHeight,
|
|
29
33
|
smoothScrollTargetReached: smoothScrollTargetReached,
|
|
30
34
|
// signals
|
|
31
35
|
scrollTo: scrollTo,
|
|
32
36
|
scrollBy: scrollBy,
|
|
33
37
|
// state
|
|
34
|
-
scrollDirection: scrollDirection,
|
|
35
38
|
statefulScrollTop: statefulScrollTop,
|
|
36
39
|
deviation: deviation,
|
|
37
40
|
scrollingInProgress: scrollingInProgress,
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { __read } from "tslib";
|
|
2
2
|
import * as u from '@virtuoso.dev/urx';
|
|
3
|
+
import { domIOSystem } from './domIOSystem';
|
|
3
4
|
import { initialTopMostItemIndexSystem } from './initialTopMostItemIndexSystem';
|
|
5
|
+
import { loggerSystem, LogLevel } from './loggerSystem';
|
|
4
6
|
import { propsReadySystem } from './propsReadySystem';
|
|
5
7
|
import { scrollToIndexSystem } from './scrollToIndexSystem';
|
|
6
8
|
import { sizeSystem } from './sizeSystem';
|
|
@@ -18,21 +20,24 @@ var behaviorFromFollowOutput = function (follow, isAtBottom) {
|
|
|
18
20
|
return isAtBottom && normalizeFollowOutput(follow);
|
|
19
21
|
};
|
|
20
22
|
export var followOutputSystem = u.system(function (_a) {
|
|
21
|
-
var _b = __read(_a,
|
|
23
|
+
var _b = __read(_a, 7), _c = _b[0], totalCount = _c.totalCount, listRefresh = _c.listRefresh, _d = _b[1], isAtBottom = _d.isAtBottom, atBottomState = _d.atBottomState, scrollToIndex = _b[2].scrollToIndex, scrolledToInitialItem = _b[3].scrolledToInitialItem, _e = _b[4], propsReady = _e.propsReady, didMount = _e.didMount, log = _b[5].log, scrollingInProgress = _b[6].scrollingInProgress;
|
|
22
24
|
var followOutput = u.statefulStream(false);
|
|
23
|
-
|
|
25
|
+
var pendingScrollHandle = null;
|
|
26
|
+
function scrollToBottom(followOutputBehavior) {
|
|
24
27
|
u.publish(scrollToIndex, {
|
|
25
|
-
index:
|
|
28
|
+
index: 'LAST',
|
|
26
29
|
align: 'end',
|
|
27
30
|
behavior: followOutputBehavior,
|
|
28
31
|
});
|
|
29
32
|
}
|
|
30
|
-
u.subscribe(u.pipe(u.combineLatest(u.duc(totalCount), didMount), u.withLatestFrom(u.duc(followOutput), isAtBottom, scrolledToInitialItem), u.map(function (_a) {
|
|
31
|
-
var _b = __read(_a,
|
|
33
|
+
u.subscribe(u.pipe(u.combineLatest(u.pipe(u.duc(totalCount), u.skip(1)), didMount), u.withLatestFrom(u.duc(followOutput), isAtBottom, scrolledToInitialItem, scrollingInProgress), u.map(function (_a) {
|
|
34
|
+
var _b = __read(_a, 5), _c = __read(_b[0], 2), totalCount = _c[0], didMount = _c[1], followOutput = _b[1], isAtBottom = _b[2], scrolledToInitialItem = _b[3], scrollingInProgress = _b[4];
|
|
32
35
|
var shouldFollow = didMount && scrolledToInitialItem;
|
|
33
36
|
var followOutputBehavior = 'auto';
|
|
34
37
|
if (shouldFollow) {
|
|
35
|
-
|
|
38
|
+
// if scrolling to index is in progress,
|
|
39
|
+
// assume that a previous followOutput response is going
|
|
40
|
+
followOutputBehavior = behaviorFromFollowOutput(followOutput, isAtBottom || scrollingInProgress);
|
|
36
41
|
shouldFollow = shouldFollow && !!followOutputBehavior;
|
|
37
42
|
}
|
|
38
43
|
return { totalCount: totalCount, shouldFollow: shouldFollow, followOutputBehavior: followOutputBehavior };
|
|
@@ -41,8 +46,14 @@ export var followOutputSystem = u.system(function (_a) {
|
|
|
41
46
|
return shouldFollow;
|
|
42
47
|
})), function (_a) {
|
|
43
48
|
var totalCount = _a.totalCount, followOutputBehavior = _a.followOutputBehavior;
|
|
44
|
-
|
|
45
|
-
|
|
49
|
+
if (pendingScrollHandle) {
|
|
50
|
+
pendingScrollHandle();
|
|
51
|
+
pendingScrollHandle = null;
|
|
52
|
+
}
|
|
53
|
+
pendingScrollHandle = u.handleNext(listRefresh, function () {
|
|
54
|
+
u.getValue(log)('following output to ', { totalCount: totalCount }, LogLevel.DEBUG);
|
|
55
|
+
scrollToBottom(followOutputBehavior);
|
|
56
|
+
pendingScrollHandle = null;
|
|
46
57
|
});
|
|
47
58
|
});
|
|
48
59
|
u.subscribe(u.pipe(u.combineLatest(u.duc(followOutput), totalCount, propsReady), u.filter(function (_a) {
|
|
@@ -56,23 +67,25 @@ export var followOutputSystem = u.system(function (_a) {
|
|
|
56
67
|
var refreshed = _a.refreshed;
|
|
57
68
|
return refreshed;
|
|
58
69
|
}), u.withLatestFrom(followOutput, totalCount)), function (_a) {
|
|
59
|
-
var _b = __read(_a,
|
|
70
|
+
var _b = __read(_a, 2), followOutput = _b[1];
|
|
60
71
|
var cancel = u.handleNext(atBottomState, function (state) {
|
|
61
72
|
if (followOutput &&
|
|
62
73
|
!state.atBottom &&
|
|
63
|
-
state.notAtBottomBecause === 'SIZE_INCREASED'
|
|
64
|
-
|
|
74
|
+
state.notAtBottomBecause === 'SIZE_INCREASED' &&
|
|
75
|
+
!pendingScrollHandle) {
|
|
76
|
+
u.getValue(log)('scrolling to bottom due to increased size', {}, LogLevel.DEBUG);
|
|
77
|
+
scrollToBottom('auto');
|
|
65
78
|
}
|
|
66
79
|
});
|
|
67
80
|
setTimeout(cancel, 100);
|
|
68
81
|
});
|
|
69
|
-
u.subscribe(u.
|
|
70
|
-
var _b = __read(_a, 2),
|
|
82
|
+
u.subscribe(u.combineLatest(u.duc(followOutput), atBottomState), function (_a) {
|
|
83
|
+
var _b = __read(_a, 2), followOutput = _b[0], state = _b[1];
|
|
71
84
|
if (followOutput &&
|
|
72
85
|
!state.atBottom &&
|
|
73
86
|
state.notAtBottomBecause === 'VIEWPORT_HEIGHT_DECREASING') {
|
|
74
|
-
scrollToBottom(
|
|
87
|
+
scrollToBottom('auto');
|
|
75
88
|
}
|
|
76
89
|
});
|
|
77
90
|
return { followOutput: followOutput };
|
|
78
|
-
}, u.tup(sizeSystem, stateFlagsSystem, scrollToIndexSystem, initialTopMostItemIndexSystem, propsReadySystem));
|
|
91
|
+
}, u.tup(sizeSystem, stateFlagsSystem, scrollToIndexSystem, initialTopMostItemIndexSystem, propsReadySystem, loggerSystem, domIOSystem));
|
|
@@ -26,15 +26,12 @@ var PROBE_GRID_STATE = {
|
|
|
26
26
|
itemHeight: 0,
|
|
27
27
|
itemWidth: 0,
|
|
28
28
|
};
|
|
29
|
-
var ceil = Math.ceil, floor = Math.floor, min = Math.min, max = Math.max;
|
|
30
|
-
function hackFloor(val) {
|
|
31
|
-
return ceil(val) - val < 0.03 ? ceil(val) : floor(val);
|
|
32
|
-
}
|
|
29
|
+
var round = Math.round, ceil = Math.ceil, floor = Math.floor, min = Math.min, max = Math.max;
|
|
33
30
|
function buildItems(startIndex, endIndex) {
|
|
34
31
|
return Array.from({ length: endIndex - startIndex + 1 }).map(function (_, i) { return ({ index: i + startIndex }); });
|
|
35
32
|
}
|
|
36
33
|
export var gridSystem = u.system(function (_a) {
|
|
37
|
-
var _b = __read(_a, 6), _c = _b[0], overscan = _c.overscan, visibleRange = _c.visibleRange, listBoundary = _c.listBoundary, _d = _b[1], scrollTop = _d.scrollTop, viewportHeight = _d.viewportHeight, scrollBy = _d.scrollBy, scrollTo = _d.scrollTo, smoothScrollTargetReached = _d.smoothScrollTargetReached, stateFlags = _b[2], scrollSeek = _b[3], _e = _b[4], propsReady = _e.propsReady, didMount = _e.didMount, _f = _b[5], windowViewportRect = _f.windowViewportRect, windowScrollTo = _f.windowScrollTo, useWindowScroll = _f.useWindowScroll,
|
|
34
|
+
var _b = __read(_a, 6), _c = _b[0], overscan = _c.overscan, visibleRange = _c.visibleRange, listBoundary = _c.listBoundary, _d = _b[1], scrollTop = _d.scrollTop, viewportHeight = _d.viewportHeight, scrollBy = _d.scrollBy, scrollTo = _d.scrollTo, smoothScrollTargetReached = _d.smoothScrollTargetReached, scrollContainerState = _d.scrollContainerState, stateFlags = _b[2], scrollSeek = _b[3], _e = _b[4], propsReady = _e.propsReady, didMount = _e.didMount, _f = _b[5], windowViewportRect = _f.windowViewportRect, windowScrollTo = _f.windowScrollTo, useWindowScroll = _f.useWindowScroll, customScrollParent = _f.customScrollParent, windowScrollContainerState = _f.windowScrollContainerState;
|
|
38
35
|
var totalCount = u.statefulStream(0);
|
|
39
36
|
var initialItemCount = u.statefulStream(0);
|
|
40
37
|
var gridState = u.statefulStream(INITIAL_GRID_STATE);
|
|
@@ -47,6 +44,8 @@ export var gridSystem = u.system(function (_a) {
|
|
|
47
44
|
width: 0,
|
|
48
45
|
});
|
|
49
46
|
var scrollToIndex = u.stream();
|
|
47
|
+
var scrollHeight = u.stream();
|
|
48
|
+
var deviation = u.statefulStream(0);
|
|
50
49
|
u.connect(u.pipe(didMount, u.withLatestFrom(initialItemCount), u.filter(function (_a) {
|
|
51
50
|
var _b = __read(_a, 2), count = _b[1];
|
|
52
51
|
return count !== 0;
|
|
@@ -74,7 +73,7 @@ export var gridSystem = u.system(function (_a) {
|
|
|
74
73
|
if (itemWidth === 0) {
|
|
75
74
|
return PROBE_GRID_STATE;
|
|
76
75
|
}
|
|
77
|
-
var perRow =
|
|
76
|
+
var perRow = itemsPerRow(viewportWidth, itemWidth);
|
|
78
77
|
var startIndex = perRow * floor(startOffset / itemHeight);
|
|
79
78
|
var endIndex = perRow * ceil(endOffset / itemHeight) - 1;
|
|
80
79
|
endIndex = min(totalCount - 1, endIndex);
|
|
@@ -102,10 +101,6 @@ export var gridSystem = u.system(function (_a) {
|
|
|
102
101
|
var _c = gridLayout(viewportDimensions, item, items), top = _c.top, bottom = _c.bottom;
|
|
103
102
|
return [top, bottom];
|
|
104
103
|
}), u.distinctUntilChanged(tupleComparator)), listBoundary);
|
|
105
|
-
u.connect(u.pipe(listBoundary, u.withLatestFrom(gridState), u.map(function (_a) {
|
|
106
|
-
var _b = __read(_a, 2), _c = __read(_b[0], 2), bottom = _c[1], offsetBottom = _b[1].offsetBottom;
|
|
107
|
-
return { bottom: bottom, offsetBottom: offsetBottom };
|
|
108
|
-
})), stateFlags.listStateListener);
|
|
109
104
|
var endReached = u.streamFromEmitter(u.pipe(u.duc(gridState), u.filter(function (_a) {
|
|
110
105
|
var items = _a.items;
|
|
111
106
|
return items.length > 0;
|
|
@@ -136,13 +131,16 @@ export var gridSystem = u.system(function (_a) {
|
|
|
136
131
|
var normalLocation = normalizeIndexLocation(location);
|
|
137
132
|
var align = normalLocation.align, behavior = normalLocation.behavior, offset = normalLocation.offset;
|
|
138
133
|
var index = normalLocation.index;
|
|
139
|
-
|
|
134
|
+
if (index === 'LAST') {
|
|
135
|
+
index = totalCount - 1;
|
|
136
|
+
}
|
|
137
|
+
index = max(0, index, min(totalCount - 1, index));
|
|
140
138
|
var top = itemTop(viewport, item, index);
|
|
141
139
|
if (align === 'end') {
|
|
142
|
-
top =
|
|
140
|
+
top = round(top - viewport.height + item.height);
|
|
143
141
|
}
|
|
144
142
|
else if (align === 'center') {
|
|
145
|
-
top =
|
|
143
|
+
top = round(top - viewport.height / 2 + item.height / 2);
|
|
146
144
|
}
|
|
147
145
|
if (offset) {
|
|
148
146
|
top += offset;
|
|
@@ -162,6 +160,7 @@ export var gridSystem = u.system(function (_a) {
|
|
|
162
160
|
viewportDimensions: viewportDimensions,
|
|
163
161
|
itemDimensions: itemDimensions,
|
|
164
162
|
scrollTop: scrollTop,
|
|
163
|
+
scrollHeight: scrollHeight,
|
|
165
164
|
overscan: overscan,
|
|
166
165
|
scrollBy: scrollBy,
|
|
167
166
|
scrollTo: scrollTo,
|
|
@@ -170,7 +169,10 @@ export var gridSystem = u.system(function (_a) {
|
|
|
170
169
|
windowViewportRect: windowViewportRect,
|
|
171
170
|
windowScrollTo: windowScrollTo,
|
|
172
171
|
useWindowScroll: useWindowScroll,
|
|
173
|
-
|
|
172
|
+
customScrollParent: customScrollParent,
|
|
173
|
+
windowScrollContainerState: windowScrollContainerState,
|
|
174
|
+
deviation: deviation,
|
|
175
|
+
scrollContainerState: scrollContainerState,
|
|
174
176
|
initialItemCount: initialItemCount }, scrollSeek), {
|
|
175
177
|
// output
|
|
176
178
|
gridState: gridState,
|
|
@@ -193,5 +195,5 @@ function itemTop(viewport, item, index) {
|
|
|
193
195
|
return floor(index / perRow) * item.height;
|
|
194
196
|
}
|
|
195
197
|
function itemsPerRow(viewportWidth, itemWidth) {
|
|
196
|
-
return
|
|
198
|
+
return max(1, floor(viewportWidth / itemWidth));
|
|
197
199
|
}
|
|
@@ -1,13 +1,37 @@
|
|
|
1
|
+
/* eslint-disable no-continue */
|
|
2
|
+
import { useRcPortalWindowContext } from '../../../../foundation';
|
|
3
|
+
import { LogLevel } from '../loggerSystem';
|
|
1
4
|
import useSize from './useSize';
|
|
2
|
-
export default function
|
|
5
|
+
export default function useChangedListContentsSizes(callback, itemSize, enabled, scrollContainerStateCallback, log, customScrollParent) {
|
|
6
|
+
var _a = useRcPortalWindowContext().externalWindow, externalWindow = _a === void 0 ? window : _a;
|
|
3
7
|
return useSize(function (el) {
|
|
4
|
-
var ranges = getChangedChildSizes(el.children, itemSize, 'offsetHeight');
|
|
8
|
+
var ranges = getChangedChildSizes(el.children, itemSize, 'offsetHeight', log);
|
|
9
|
+
var scrollableElement = el.parentElement;
|
|
10
|
+
while (!scrollableElement.dataset['virtuosoScroller']) {
|
|
11
|
+
scrollableElement = scrollableElement.parentElement;
|
|
12
|
+
}
|
|
13
|
+
var scrollTop = customScrollParent
|
|
14
|
+
? customScrollParent.scrollTop
|
|
15
|
+
: // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
16
|
+
scrollableElement.firstElementChild.dataset['viewportType'] === 'window'
|
|
17
|
+
? externalWindow.pageYOffset ||
|
|
18
|
+
externalWindow.document.documentElement.scrollTop
|
|
19
|
+
: scrollableElement.scrollTop;
|
|
20
|
+
customScrollParent
|
|
21
|
+
? scrollContainerStateCallback([
|
|
22
|
+
Math.max(scrollTop, 0),
|
|
23
|
+
customScrollParent.scrollHeight,
|
|
24
|
+
])
|
|
25
|
+
: scrollContainerStateCallback([
|
|
26
|
+
Math.max(scrollTop, 0),
|
|
27
|
+
scrollableElement.scrollHeight,
|
|
28
|
+
]);
|
|
5
29
|
if (ranges !== null) {
|
|
6
30
|
callback(ranges);
|
|
7
31
|
}
|
|
8
32
|
}, enabled);
|
|
9
33
|
}
|
|
10
|
-
function getChangedChildSizes(children, itemSize, field) {
|
|
34
|
+
function getChangedChildSizes(children, itemSize, field, log) {
|
|
11
35
|
var length = children.length;
|
|
12
36
|
if (length === 0) {
|
|
13
37
|
return null;
|
|
@@ -18,11 +42,12 @@ function getChangedChildSizes(children, itemSize, field) {
|
|
|
18
42
|
if (!child || child.dataset.index === undefined) {
|
|
19
43
|
continue;
|
|
20
44
|
}
|
|
21
|
-
|
|
22
|
-
var
|
|
45
|
+
// eslint-disable-next-line radix
|
|
46
|
+
var index = parseInt(child.dataset.index);
|
|
47
|
+
var knownSize = parseFloat(child.dataset.knownSize);
|
|
23
48
|
var size = itemSize(child, field);
|
|
24
49
|
if (size === 0) {
|
|
25
|
-
|
|
50
|
+
log('Zero-sized element, this should not happen', { child: child }, LogLevel.ERROR);
|
|
26
51
|
}
|
|
27
52
|
if (size === knownSize) {
|
|
28
53
|
continue;
|
|
@@ -1,22 +1,31 @@
|
|
|
1
1
|
import { useCallback, useEffect, useRef } from 'react';
|
|
2
2
|
import * as u from '@virtuoso.dev/urx';
|
|
3
|
-
|
|
3
|
+
import { correctItemSize } from '../utils/correctItemSize';
|
|
4
|
+
import { useRcPortalWindowContext } from '../../../../foundation';
|
|
5
|
+
function approximatelyEqual(num1, num2) {
|
|
6
|
+
return Math.abs(num1 - num2) < 1.01;
|
|
7
|
+
}
|
|
8
|
+
export default function useScrollTop(scrollContainerStateCallback, smoothScrollTargetReached, scrollerElement, scrollerRefCallback, customScrollParent) {
|
|
4
9
|
if (scrollerRefCallback === void 0) { scrollerRefCallback = u.noop; }
|
|
5
|
-
if (customWindow === void 0) { customWindow = window; }
|
|
6
10
|
var scrollerRef = useRef(null);
|
|
7
11
|
var scrollTopTarget = useRef(null);
|
|
8
12
|
var timeoutRef = useRef(null);
|
|
9
|
-
var
|
|
13
|
+
var _a = useRcPortalWindowContext().externalWindow, externalWindow = _a === void 0 ? window : _a;
|
|
10
14
|
var handler = useCallback(function (ev) {
|
|
11
15
|
var el = ev.target;
|
|
12
|
-
var scrollTop = el ===
|
|
13
|
-
|
|
16
|
+
var scrollTop = el === externalWindow ||
|
|
17
|
+
el === externalWindow.document
|
|
18
|
+
? externalWindow.pageYOffset ||
|
|
19
|
+
externalWindow.document.documentElement.scrollTop
|
|
14
20
|
: el.scrollTop;
|
|
15
|
-
|
|
21
|
+
var scrollHeight = el === externalWindow
|
|
22
|
+
? externalWindow.document.documentElement.scrollHeight
|
|
23
|
+
: el.scrollHeight;
|
|
24
|
+
scrollContainerStateCallback([Math.max(scrollTop, 0), scrollHeight]);
|
|
16
25
|
if (scrollTopTarget.current !== null) {
|
|
17
26
|
if (scrollTop === scrollTopTarget.current ||
|
|
18
27
|
scrollTop <= 0 ||
|
|
19
|
-
scrollTop === el.scrollHeight - el
|
|
28
|
+
scrollTop === el.scrollHeight - correctItemSize(el, 'height')) {
|
|
20
29
|
scrollTopTarget.current = null;
|
|
21
30
|
smoothScrollTargetReached(true);
|
|
22
31
|
if (timeoutRef.current) {
|
|
@@ -25,54 +34,59 @@ export default function useScrollTop(scrollTopCallback, smoothScrollTargetReache
|
|
|
25
34
|
}
|
|
26
35
|
}
|
|
27
36
|
}
|
|
28
|
-
}, [
|
|
29
|
-
customDocument,
|
|
30
|
-
customWindow,
|
|
31
|
-
scrollTopCallback,
|
|
32
|
-
smoothScrollTargetReached,
|
|
33
|
-
]);
|
|
37
|
+
}, [externalWindow, scrollContainerStateCallback, smoothScrollTargetReached]);
|
|
34
38
|
useEffect(function () {
|
|
35
|
-
var localRef =
|
|
36
|
-
|
|
39
|
+
var localRef = customScrollParent
|
|
40
|
+
? customScrollParent
|
|
41
|
+
: scrollerRef.current;
|
|
42
|
+
scrollerRefCallback(customScrollParent ? customScrollParent : scrollerRef.current);
|
|
37
43
|
handler({ target: localRef });
|
|
38
44
|
localRef.addEventListener('scroll', handler, { passive: true });
|
|
39
45
|
return function () {
|
|
40
46
|
scrollerRefCallback(null);
|
|
41
47
|
localRef.removeEventListener('scroll', handler);
|
|
42
48
|
};
|
|
43
|
-
}, [
|
|
49
|
+
}, [
|
|
50
|
+
scrollerRef,
|
|
51
|
+
handler,
|
|
52
|
+
scrollerElement,
|
|
53
|
+
scrollerRefCallback,
|
|
54
|
+
customScrollParent,
|
|
55
|
+
]);
|
|
44
56
|
function scrollToCallback(location) {
|
|
45
57
|
var scrollerElement = scrollerRef.current;
|
|
46
|
-
if (!scrollerElement
|
|
58
|
+
if (!scrollerElement ||
|
|
59
|
+
('offsetHeight' in scrollerElement && scrollerElement.offsetHeight === 0)) {
|
|
47
60
|
return;
|
|
48
61
|
}
|
|
49
62
|
var isSmooth = location.behavior === 'smooth';
|
|
50
63
|
var offsetHeight;
|
|
51
64
|
var scrollHeight;
|
|
52
65
|
var scrollTop;
|
|
53
|
-
if (scrollerElement ===
|
|
66
|
+
if (scrollerElement === externalWindow) {
|
|
54
67
|
// this is not a mistake
|
|
55
|
-
scrollHeight = Math.max(
|
|
56
|
-
offsetHeight =
|
|
57
|
-
scrollTop =
|
|
68
|
+
scrollHeight = Math.max(correctItemSize(externalWindow.document.documentElement, 'height'), externalWindow.document.documentElement.scrollHeight);
|
|
69
|
+
offsetHeight = externalWindow.window.innerHeight;
|
|
70
|
+
scrollTop = externalWindow.document.documentElement.scrollTop;
|
|
58
71
|
}
|
|
59
72
|
else {
|
|
60
73
|
scrollHeight = scrollerElement.scrollHeight;
|
|
61
|
-
offsetHeight = scrollerElement
|
|
74
|
+
offsetHeight = correctItemSize(scrollerElement, 'height');
|
|
62
75
|
scrollTop = scrollerElement.scrollTop;
|
|
63
76
|
}
|
|
77
|
+
var maxScrollTop = scrollHeight - offsetHeight;
|
|
78
|
+
location.top = Math.ceil(Math.max(Math.min(maxScrollTop, location.top), 0));
|
|
64
79
|
// avoid system hanging because the DOM never called back
|
|
65
80
|
// with the scrollTop
|
|
66
81
|
// scroller is already at this location
|
|
67
|
-
if (offsetHeight
|
|
68
|
-
|
|
82
|
+
if (approximatelyEqual(offsetHeight, scrollHeight) ||
|
|
83
|
+
location.top === scrollTop) {
|
|
84
|
+
scrollContainerStateCallback([scrollTop, scrollHeight]);
|
|
69
85
|
if (isSmooth) {
|
|
70
86
|
smoothScrollTargetReached(true);
|
|
71
87
|
}
|
|
72
88
|
return;
|
|
73
89
|
}
|
|
74
|
-
var maxScrollTop = scrollHeight - offsetHeight;
|
|
75
|
-
location.top = Math.max(Math.min(maxScrollTop, location.top), 0);
|
|
76
90
|
if (isSmooth) {
|
|
77
91
|
scrollTopTarget.current = location.top;
|
|
78
92
|
if (timeoutRef.current) {
|