@cleartrip/ct-design-scroll-container 5.26.0-SNAPSHOT-native-main.0 → 5.26.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/dist/ScrollContainer.d.ts.map +1 -1
- package/dist/ScrollContainer.native.d.ts.map +1 -1
- package/dist/ct-design-scroll-container.browser.cjs.js +1 -1
- package/dist/ct-design-scroll-container.browser.cjs.js.map +1 -1
- package/dist/ct-design-scroll-container.browser.esm.js +1 -1
- package/dist/ct-design-scroll-container.browser.esm.js.map +1 -1
- package/dist/ct-design-scroll-container.cjs.js +9 -1
- package/dist/ct-design-scroll-container.cjs.js.map +1 -1
- package/dist/ct-design-scroll-container.esm.js +9 -1
- package/dist/ct-design-scroll-container.esm.js.map +1 -1
- package/dist/ct-design-scroll-container.umd.js +493 -800
- package/dist/ct-design-scroll-container.umd.js.map +1 -1
- package/dist/type.d.ts +8 -0
- package/dist/type.d.ts.map +1 -1
- package/package.json +9 -8
- package/src/ScrollContainer.native.tsx +115 -25
- package/src/ScrollContainer.tsx +11 -1
- package/src/ScrollContext.tsx +1 -1
- package/src/ScrollEvent.ts +2 -2
- package/src/type.ts +23 -0
- package/src/useHandleScroll/index.native.ts +1 -1
- package/src/useHandleScroll/index.ts +1 -1
|
@@ -1,823 +1,516 @@
|
|
|
1
1
|
(function (global, factory) {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
})(this, (function (exports, jsxRuntime, react, ctDesignStyleManager, ctDesignCommonUtils) { 'use strict';
|
|
2
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('react/jsx-runtime'), require('react'), require('@cleartrip/ct-design-style-manager'), require('eventemitter3'), require('@cleartrip/ct-design-common-utils')) :
|
|
3
|
+
typeof define === 'function' && define.amd ? define(['exports', 'react/jsx-runtime', 'react', '@cleartrip/ct-design-style-manager', 'eventemitter3', '@cleartrip/ct-design-common-utils'], factory) :
|
|
4
|
+
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.CTDesignSystemScrollContainer = {}, global.jsxRuntime, global.React, global.ctDesignStyleManager, global.EventEmitter, global.ctDesignCommonUtils));
|
|
5
|
+
})(this, (function (exports, jsxRuntime, react, ctDesignStyleManager, EventEmitter, ctDesignCommonUtils) { 'use strict';
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
var eventemitter3 = {
|
|
9
|
-
get exports(){ return eventemitter3Exports; },
|
|
10
|
-
set exports(v){ eventemitter3Exports = v; },
|
|
11
|
-
};
|
|
7
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
12
8
|
|
|
13
|
-
|
|
9
|
+
var EventEmitter__default = /*#__PURE__*/_interopDefault(EventEmitter);
|
|
14
10
|
|
|
15
|
-
|
|
16
|
-
|
|
11
|
+
exports.EVENT_NAMES = void 0;
|
|
12
|
+
(function (EVENT_NAMES) {
|
|
13
|
+
EVENT_NAMES["SCROLL_VIEW"] = "scroll-view";
|
|
14
|
+
EVENT_NAMES["SCROLL_INTO_VIEW"] = "scroll-into-view";
|
|
15
|
+
})(exports.EVENT_NAMES || (exports.EVENT_NAMES = {}));
|
|
17
16
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
this.context = context;
|
|
56
|
-
this.once = once || false;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
* Add a listener for a given event.
|
|
61
|
-
*
|
|
62
|
-
* @param {EventEmitter} emitter Reference to the `EventEmitter` instance.
|
|
63
|
-
* @param {(String|Symbol)} event The event name.
|
|
64
|
-
* @param {Function} fn The listener function.
|
|
65
|
-
* @param {*} context The context to invoke the listener with.
|
|
66
|
-
* @param {Boolean} once Specify if the listener is a one-time listener.
|
|
67
|
-
* @returns {EventEmitter}
|
|
68
|
-
* @private
|
|
69
|
-
*/
|
|
70
|
-
function addListener(emitter, event, fn, context, once) {
|
|
71
|
-
if (typeof fn !== 'function') {
|
|
72
|
-
throw new TypeError('The listener must be a function');
|
|
73
|
-
}
|
|
74
|
-
var listener = new EE(fn, context || emitter, once),
|
|
75
|
-
evt = prefix ? prefix + event : event;
|
|
76
|
-
if (!emitter._events[evt]) emitter._events[evt] = listener, emitter._eventsCount++;else if (!emitter._events[evt].fn) emitter._events[evt].push(listener);else emitter._events[evt] = [emitter._events[evt], listener];
|
|
77
|
-
return emitter;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
/**
|
|
81
|
-
* Clear event by name.
|
|
82
|
-
*
|
|
83
|
-
* @param {EventEmitter} emitter Reference to the `EventEmitter` instance.
|
|
84
|
-
* @param {(String|Symbol)} evt The Event name.
|
|
85
|
-
* @private
|
|
86
|
-
*/
|
|
87
|
-
function clearEvent(emitter, evt) {
|
|
88
|
-
if (--emitter._eventsCount === 0) emitter._events = new Events();else delete emitter._events[evt];
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
/**
|
|
92
|
-
* Minimal `EventEmitter` interface that is molded against the Node.js
|
|
93
|
-
* `EventEmitter` interface.
|
|
94
|
-
*
|
|
95
|
-
* @constructor
|
|
96
|
-
* @public
|
|
97
|
-
*/
|
|
98
|
-
function EventEmitter() {
|
|
99
|
-
this._events = new Events();
|
|
100
|
-
this._eventsCount = 0;
|
|
17
|
+
class CustomDocumentEvent {
|
|
18
|
+
constructor() {
|
|
19
|
+
this.eventMap = new Map();
|
|
20
|
+
this.emitter = new EventEmitter__default.default();
|
|
21
|
+
}
|
|
22
|
+
addEventListener(event, listener) {
|
|
23
|
+
if (event === exports.EVENT_NAMES.SCROLL_VIEW) {
|
|
24
|
+
const _listener = listener;
|
|
25
|
+
const eventHandler = () => {
|
|
26
|
+
_listener([{ x: window.scrollX, y: window.scrollY }]);
|
|
27
|
+
};
|
|
28
|
+
window.addEventListener('scroll', eventHandler);
|
|
29
|
+
this.eventMap.set(listener, eventHandler);
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
this.emitter.addListener(event, listener);
|
|
33
|
+
this.eventMap.set(listener, listener);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
removeEventListener(event, listener) {
|
|
37
|
+
if (event === exports.EVENT_NAMES.SCROLL_VIEW) {
|
|
38
|
+
const eventHandler = this.eventMap.get(listener);
|
|
39
|
+
if (eventHandler) {
|
|
40
|
+
window.removeEventListener('scroll', eventHandler);
|
|
41
|
+
this.eventMap.delete(listener);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
this.emitter.removeListener(event, listener);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
dispose() {
|
|
49
|
+
this.emitter.removeAllListeners();
|
|
50
|
+
}
|
|
51
|
+
emit(event, data) {
|
|
52
|
+
return this.emitter.emit(event, data);
|
|
53
|
+
}
|
|
101
54
|
}
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
55
|
+
const scrollEvent = new CustomDocumentEvent();
|
|
56
|
+
|
|
57
|
+
const staticScrollStyles = ctDesignStyleManager.makeStyles(() => ({
|
|
58
|
+
viewport: {
|
|
59
|
+
display: 'flex',
|
|
60
|
+
flexDirection: 'column',
|
|
61
|
+
minHeight: 0,
|
|
62
|
+
minWidth: 0,
|
|
63
|
+
width: '100%',
|
|
64
|
+
position: 'relative',
|
|
65
|
+
WebkitOverflowScrolling: 'touch',
|
|
66
|
+
},
|
|
67
|
+
viewportVertical: {
|
|
68
|
+
flex: 1,
|
|
69
|
+
overflowX: 'hidden',
|
|
70
|
+
overflowY: 'auto',
|
|
71
|
+
overscrollBehavior: 'contain',
|
|
72
|
+
},
|
|
73
|
+
viewportHorizontal: {
|
|
74
|
+
flex: 1,
|
|
75
|
+
minWidth: 0,
|
|
76
|
+
overflowX: 'auto',
|
|
77
|
+
overflowY: 'hidden',
|
|
78
|
+
alignItems: 'flex-start',
|
|
79
|
+
},
|
|
80
|
+
contentVertical: {
|
|
81
|
+
display: 'flex',
|
|
82
|
+
flexDirection: 'column',
|
|
83
|
+
flexShrink: 0,
|
|
84
|
+
width: '100%',
|
|
85
|
+
},
|
|
86
|
+
contentHorizontal: {
|
|
87
|
+
display: 'flex',
|
|
88
|
+
flexDirection: 'row',
|
|
89
|
+
flexWrap: 'nowrap',
|
|
90
|
+
flexShrink: 0,
|
|
91
|
+
width: 'max-content',
|
|
92
|
+
minWidth: '100%',
|
|
93
|
+
},
|
|
94
|
+
hideScrollbar: {
|
|
95
|
+
scrollbarWidth: 'none',
|
|
96
|
+
msOverflowStyle: 'none',
|
|
97
|
+
'&::-webkit-scrollbar': {
|
|
98
|
+
display: 'none',
|
|
99
|
+
},
|
|
100
|
+
},
|
|
101
|
+
pagingSnapVertical: { scrollSnapType: 'y mandatory' },
|
|
102
|
+
pagingSnapHorizontal: { scrollSnapType: 'x mandatory' },
|
|
103
|
+
viewportVerticalNested: {
|
|
104
|
+
flex: 1,
|
|
105
|
+
minHeight: 0,
|
|
106
|
+
height: '100%',
|
|
107
|
+
maxHeight: '100%',
|
|
108
|
+
overflowX: 'hidden',
|
|
109
|
+
overflowY: 'auto',
|
|
110
|
+
overscrollBehavior: 'auto',
|
|
111
|
+
},
|
|
112
|
+
}));
|
|
113
|
+
const getScrollableParent = (node) => {
|
|
114
|
+
var _a;
|
|
115
|
+
let parent = (_a = node === null || node === void 0 ? void 0 : node.parentElement) !== null && _a !== void 0 ? _a : null;
|
|
116
|
+
while (parent) {
|
|
117
|
+
const { overflowY } = getComputedStyle(parent);
|
|
118
|
+
if (/(auto|scroll|overlay)/.test(overflowY) && parent.scrollHeight > parent.clientHeight + 1) {
|
|
119
|
+
return parent;
|
|
120
|
+
}
|
|
121
|
+
parent = parent.parentElement;
|
|
122
|
+
}
|
|
123
|
+
return null;
|
|
140
124
|
};
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
125
|
+
const emitScrollEvent = (target) => ({
|
|
126
|
+
nativeEvent: {
|
|
127
|
+
contentOffset: {
|
|
128
|
+
x: target.scrollLeft,
|
|
129
|
+
y: target.scrollTop,
|
|
130
|
+
},
|
|
131
|
+
layoutMeasurement: {
|
|
132
|
+
height: target.clientHeight,
|
|
133
|
+
width: target.clientWidth,
|
|
134
|
+
},
|
|
135
|
+
contentSize: {
|
|
136
|
+
height: target.scrollHeight,
|
|
137
|
+
width: target.scrollWidth,
|
|
138
|
+
},
|
|
139
|
+
},
|
|
140
|
+
});
|
|
141
|
+
const ScrollContainer = react.forwardRef(({ children, styleConfig, onScroll, horizontal = false, scrollEventThrottle = 0, showsVerticalScrollIndicator = false, showsHorizontalScrollIndicator = true, width, onIndexChange, currentActiveIndex, pagingEnabled = false, snapToOffsets, totalItemsLength, contentContainerStyle, onLayout, attachScrollEvent = false, nestedScrollEnabled = false, stickyHeaderIndices: _stickyHeaderIndices, removeClippedSubviews: _removeClippedSubviews, isVisible: _isVisible, keyboardShouldPersistTaps: _keyboardShouldPersistTaps, bounces: _bounces, id, onClick, onMouseEnter, onMouseLeave, onTransitionEnd, onTouchStart, onTouchEnd, onTouchCancel, onTouchMove, }, ref) => {
|
|
142
|
+
const localRef = react.useRef(null);
|
|
143
|
+
const lastScrollEventTimeRef = react.useRef(0);
|
|
144
|
+
const handleFocus = react.useCallback(() => {
|
|
145
|
+
var _a;
|
|
146
|
+
(_a = localRef.current) === null || _a === void 0 ? void 0 : _a.focus();
|
|
147
|
+
}, []);
|
|
148
|
+
const handleGetBoundingRect = react.useCallback((callback) => {
|
|
149
|
+
var _a;
|
|
150
|
+
const rect = (_a = localRef.current) === null || _a === void 0 ? void 0 : _a.getBoundingClientRect();
|
|
151
|
+
if (rect) {
|
|
152
|
+
callback === null || callback === void 0 ? void 0 : callback({
|
|
153
|
+
x: rect.x,
|
|
154
|
+
y: rect.y,
|
|
155
|
+
width: rect.width,
|
|
156
|
+
height: rect.height,
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
}, []);
|
|
160
|
+
const handleAddEventListener = react.useCallback((type, listener, options) => {
|
|
161
|
+
var _a;
|
|
162
|
+
(_a = localRef.current) === null || _a === void 0 ? void 0 : _a.addEventListener(type, listener, options);
|
|
163
|
+
}, []);
|
|
164
|
+
const handleRemoveEventListener = react.useCallback((type, listener, options) => {
|
|
165
|
+
var _a;
|
|
166
|
+
(_a = localRef.current) === null || _a === void 0 ? void 0 : _a.removeEventListener(type, listener, options);
|
|
167
|
+
}, []);
|
|
168
|
+
react.useImperativeHandle(ref, () => {
|
|
169
|
+
var _a;
|
|
170
|
+
return ({
|
|
171
|
+
getScrollableNode: () => null,
|
|
172
|
+
focus: handleFocus,
|
|
173
|
+
getBoundingRectWithCallback: handleGetBoundingRect,
|
|
174
|
+
getElementRef: () => localRef,
|
|
175
|
+
measure: (callback) => {
|
|
176
|
+
var _a;
|
|
177
|
+
const rect = (_a = localRef.current) === null || _a === void 0 ? void 0 : _a.getBoundingClientRect();
|
|
178
|
+
if (!rect)
|
|
179
|
+
return;
|
|
180
|
+
callback(rect.x, rect.y, rect.width, rect.height, rect.x, rect.y);
|
|
181
|
+
},
|
|
182
|
+
classList: {
|
|
183
|
+
add: (className) => {
|
|
184
|
+
var _a;
|
|
185
|
+
(_a = localRef.current) === null || _a === void 0 ? void 0 : _a.classList.add(className);
|
|
186
|
+
},
|
|
187
|
+
},
|
|
188
|
+
addEventListener: handleAddEventListener,
|
|
189
|
+
removeEventListener: handleRemoveEventListener,
|
|
190
|
+
style: (((_a = localRef.current) === null || _a === void 0 ? void 0 : _a.style) || {}),
|
|
191
|
+
scrollTo: (x, y) => {
|
|
192
|
+
const node = localRef.current;
|
|
193
|
+
if (!node)
|
|
194
|
+
return;
|
|
195
|
+
node.scrollTo({ left: x, top: y, behavior: 'auto' });
|
|
196
|
+
},
|
|
197
|
+
scrollToEnd: () => {
|
|
198
|
+
const node = localRef.current;
|
|
199
|
+
if (!node)
|
|
200
|
+
return;
|
|
201
|
+
if (horizontal) {
|
|
202
|
+
node.scrollTo({
|
|
203
|
+
left: node.scrollWidth - node.clientWidth,
|
|
204
|
+
top: 0,
|
|
205
|
+
behavior: 'auto',
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
else {
|
|
209
|
+
node.scrollTo({
|
|
210
|
+
left: 0,
|
|
211
|
+
top: node.scrollHeight - node.clientHeight,
|
|
212
|
+
behavior: 'auto',
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
},
|
|
216
|
+
scrollById: (id, animated = true) => {
|
|
217
|
+
const target = document.getElementById(id);
|
|
218
|
+
target === null || target === void 0 ? void 0 : target.scrollIntoView({ behavior: animated ? 'smooth' : 'auto', block: 'nearest', inline: 'nearest' });
|
|
219
|
+
},
|
|
220
|
+
get scrollLeft() {
|
|
221
|
+
var _a, _b;
|
|
222
|
+
return (_b = (_a = localRef.current) === null || _a === void 0 ? void 0 : _a.scrollLeft) !== null && _b !== void 0 ? _b : 0;
|
|
223
|
+
},
|
|
224
|
+
set scrollLeft(value) {
|
|
225
|
+
if (localRef.current) {
|
|
226
|
+
localRef.current.scrollLeft = value;
|
|
227
|
+
}
|
|
228
|
+
},
|
|
229
|
+
get scrollTop() {
|
|
230
|
+
var _a, _b;
|
|
231
|
+
return (_b = (_a = localRef.current) === null || _a === void 0 ? void 0 : _a.scrollTop) !== null && _b !== void 0 ? _b : 0;
|
|
232
|
+
},
|
|
233
|
+
set scrollTop(value) {
|
|
234
|
+
if (localRef.current) {
|
|
235
|
+
localRef.current.scrollTop = value;
|
|
236
|
+
}
|
|
237
|
+
},
|
|
238
|
+
});
|
|
239
|
+
}, [handleFocus, handleGetBoundingRect, handleAddEventListener, handleRemoveEventListener, horizontal]);
|
|
240
|
+
const { root: rootStyles = [] } = styleConfig || {};
|
|
241
|
+
const contentStyles = contentContainerStyle !== null && contentContainerStyle !== void 0 ? contentContainerStyle : [];
|
|
242
|
+
const hideHorizontalScrollbar = horizontal && showsHorizontalScrollIndicator === false;
|
|
243
|
+
const hideVerticalScrollbar = !horizontal && showsVerticalScrollIndicator === false;
|
|
244
|
+
const viewportClassName = ctDesignStyleManager.useWebMergeStyles([
|
|
245
|
+
staticScrollStyles.viewport,
|
|
246
|
+
horizontal
|
|
247
|
+
? staticScrollStyles.viewportHorizontal
|
|
248
|
+
: nestedScrollEnabled
|
|
249
|
+
? staticScrollStyles.viewportVerticalNested
|
|
250
|
+
: staticScrollStyles.viewportVertical,
|
|
251
|
+
...(hideHorizontalScrollbar || hideVerticalScrollbar ? [staticScrollStyles.hideScrollbar] : []),
|
|
252
|
+
...(pagingEnabled
|
|
253
|
+
? [horizontal ? staticScrollStyles.pagingSnapHorizontal : staticScrollStyles.pagingSnapVertical]
|
|
254
|
+
: []),
|
|
255
|
+
...rootStyles,
|
|
256
|
+
], [horizontal, nestedScrollEnabled, hideHorizontalScrollbar, hideVerticalScrollbar, pagingEnabled, rootStyles]);
|
|
257
|
+
const contentClassName = ctDesignStyleManager.useWebMergeStyles([horizontal ? staticScrollStyles.contentHorizontal : staticScrollStyles.contentVertical, ...contentStyles], [horizontal, contentStyles]);
|
|
258
|
+
const fireScroll = react.useCallback((target) => {
|
|
259
|
+
const event = emitScrollEvent(target);
|
|
260
|
+
if (scrollEventThrottle > 0) {
|
|
261
|
+
const now = Date.now();
|
|
262
|
+
if (now - lastScrollEventTimeRef.current < scrollEventThrottle) {
|
|
263
|
+
return;
|
|
264
|
+
}
|
|
265
|
+
lastScrollEventTimeRef.current = now;
|
|
266
|
+
}
|
|
267
|
+
if (attachScrollEvent) {
|
|
268
|
+
scrollEvent.emit('scroll-view', [event.nativeEvent.contentOffset]);
|
|
269
|
+
}
|
|
270
|
+
onScroll === null || onScroll === void 0 ? void 0 : onScroll(event);
|
|
271
|
+
if (horizontal && width && totalItemsLength && onIndexChange) {
|
|
272
|
+
const offsetX = target.scrollLeft;
|
|
273
|
+
const visibleWidth = target.clientWidth;
|
|
274
|
+
const tolerance = 2;
|
|
275
|
+
let index;
|
|
276
|
+
if (offsetX <= tolerance) {
|
|
277
|
+
index = 0;
|
|
278
|
+
}
|
|
279
|
+
else {
|
|
280
|
+
const centerX = offsetX + visibleWidth / 2;
|
|
281
|
+
index = Math.max(0, Math.min(totalItemsLength - 1, Math.round((centerX - width / 2) / width)));
|
|
282
|
+
}
|
|
283
|
+
onIndexChange(index);
|
|
284
|
+
}
|
|
285
|
+
}, [attachScrollEvent, horizontal, onIndexChange, onScroll, scrollEventThrottle, totalItemsLength, width]);
|
|
286
|
+
const handleScroll = react.useCallback((e) => {
|
|
287
|
+
fireScroll(e.currentTarget);
|
|
288
|
+
}, [fireScroll]);
|
|
289
|
+
const handleNestedWheel = react.useCallback((e) => {
|
|
290
|
+
if (!nestedScrollEnabled || horizontal) {
|
|
291
|
+
return;
|
|
292
|
+
}
|
|
293
|
+
const node = e.currentTarget;
|
|
294
|
+
const hasOverflow = node.scrollHeight > node.clientHeight + 1;
|
|
295
|
+
const maxScrollTop = node.scrollHeight - node.clientHeight;
|
|
296
|
+
const atTop = node.scrollTop <= 0;
|
|
297
|
+
const atBottom = node.scrollTop >= maxScrollTop - 1;
|
|
298
|
+
const scrollingUp = e.deltaY < 0;
|
|
299
|
+
const scrollingDown = e.deltaY > 0;
|
|
300
|
+
const shouldForward = !hasOverflow || (scrollingUp && atTop) || (scrollingDown && atBottom);
|
|
301
|
+
if (!shouldForward) {
|
|
302
|
+
return;
|
|
303
|
+
}
|
|
304
|
+
const scrollableParent = getScrollableParent(node);
|
|
305
|
+
if (!scrollableParent) {
|
|
306
|
+
return;
|
|
307
|
+
}
|
|
308
|
+
e.preventDefault();
|
|
309
|
+
scrollableParent.scrollTop += e.deltaY;
|
|
310
|
+
}, [horizontal, nestedScrollEnabled]);
|
|
311
|
+
react.useLayoutEffect(() => {
|
|
312
|
+
const node = localRef.current;
|
|
313
|
+
if (!node || !onLayout)
|
|
314
|
+
return;
|
|
315
|
+
onLayout({
|
|
316
|
+
layout: {
|
|
317
|
+
height: node.clientHeight,
|
|
318
|
+
width: node.clientWidth,
|
|
319
|
+
x: node.getBoundingClientRect().x,
|
|
320
|
+
y: node.getBoundingClientRect().y,
|
|
321
|
+
},
|
|
322
|
+
});
|
|
323
|
+
}, [onLayout]);
|
|
324
|
+
react.useEffect(() => {
|
|
325
|
+
const node = localRef.current;
|
|
326
|
+
if (!node || typeof currentActiveIndex !== 'number' || currentActiveIndex < 0 || !width) {
|
|
327
|
+
return;
|
|
328
|
+
}
|
|
329
|
+
node.scrollTo({
|
|
330
|
+
left: horizontal ? currentActiveIndex * (width + 16) : 0,
|
|
331
|
+
top: horizontal ? 0 : currentActiveIndex * (width + 16),
|
|
332
|
+
behavior: 'smooth',
|
|
333
|
+
});
|
|
334
|
+
}, [currentActiveIndex, horizontal, width]);
|
|
335
|
+
react.useEffect(() => {
|
|
336
|
+
if (!(snapToOffsets === null || snapToOffsets === void 0 ? void 0 : snapToOffsets.length) || !localRef.current)
|
|
337
|
+
return;
|
|
338
|
+
}, [snapToOffsets]);
|
|
339
|
+
return (jsxRuntime.jsx("div", { ref: localRef, id: id, className: viewportClassName, onScroll: handleScroll, onWheel: nestedScrollEnabled && !horizontal ? handleNestedWheel : undefined, onClick: (event) => onClick === null || onClick === void 0 ? void 0 : onClick({
|
|
340
|
+
stopPropagation: () => event.stopPropagation(),
|
|
341
|
+
preventDefault: () => event.preventDefault(),
|
|
342
|
+
nativeEvent: {
|
|
343
|
+
locationX: event.clientX,
|
|
344
|
+
locationY: event.clientY,
|
|
345
|
+
},
|
|
346
|
+
}), onMouseEnter: onMouseEnter, onMouseLeave: onMouseLeave, onTransitionEnd: onTransitionEnd, onTouchStart: onTouchStart, onTouchEnd: onTouchEnd, onTouchCancel: onTouchCancel, onTouchMove: onTouchMove, children: jsxRuntime.jsx("div", { className: contentClassName, children: children }) }));
|
|
347
|
+
});
|
|
348
|
+
ScrollContainer.displayName = 'ScrollContainer';
|
|
349
|
+
|
|
350
|
+
const ScrollContext = react.createContext({
|
|
351
|
+
isScrolling: false,
|
|
352
|
+
refs: {},
|
|
353
|
+
observableChildRefs: [],
|
|
354
|
+
parentScrollAvailable: false,
|
|
355
|
+
horizontal: false,
|
|
356
|
+
scrollToBottom: () => {
|
|
357
|
+
},
|
|
358
|
+
});
|
|
359
|
+
const ScrollContextProvider = ({ children, isScrolling, refs, scrollTo, scrollToSkip, isScrollToScrolling, observableChildRefs, horizontal, scrollToBottom, }) => {
|
|
360
|
+
return (jsxRuntime.jsx(ScrollContext.Provider, { value: {
|
|
361
|
+
observableChildRefs,
|
|
362
|
+
isScrolling,
|
|
363
|
+
refs,
|
|
364
|
+
scrollTo,
|
|
365
|
+
scrollToSkip,
|
|
366
|
+
isScrollToScrolling,
|
|
367
|
+
parentScrollAvailable: true,
|
|
368
|
+
horizontal,
|
|
369
|
+
scrollToBottom,
|
|
370
|
+
}, children: children }));
|
|
155
371
|
};
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
* @param {(String|Symbol)} event The event name.
|
|
161
|
-
* @returns {Boolean} `true` if the event had listeners, else `false`.
|
|
162
|
-
* @public
|
|
163
|
-
*/
|
|
164
|
-
EventEmitter.prototype.emit = function emit(event, a1, a2, a3, a4, a5) {
|
|
165
|
-
var evt = prefix ? prefix + event : event;
|
|
166
|
-
if (!this._events[evt]) return false;
|
|
167
|
-
var listeners = this._events[evt],
|
|
168
|
-
len = arguments.length,
|
|
169
|
-
args,
|
|
170
|
-
i;
|
|
171
|
-
if (listeners.fn) {
|
|
172
|
-
if (listeners.once) this.removeListener(event, listeners.fn, undefined, true);
|
|
173
|
-
switch (len) {
|
|
174
|
-
case 1:
|
|
175
|
-
return listeners.fn.call(listeners.context), true;
|
|
176
|
-
case 2:
|
|
177
|
-
return listeners.fn.call(listeners.context, a1), true;
|
|
178
|
-
case 3:
|
|
179
|
-
return listeners.fn.call(listeners.context, a1, a2), true;
|
|
180
|
-
case 4:
|
|
181
|
-
return listeners.fn.call(listeners.context, a1, a2, a3), true;
|
|
182
|
-
case 5:
|
|
183
|
-
return listeners.fn.call(listeners.context, a1, a2, a3, a4), true;
|
|
184
|
-
case 6:
|
|
185
|
-
return listeners.fn.call(listeners.context, a1, a2, a3, a4, a5), true;
|
|
372
|
+
const useGetScrolling = () => {
|
|
373
|
+
const context = react.useContext(ScrollContext);
|
|
374
|
+
if (!context) {
|
|
375
|
+
return { isScrolling: false, isScrollToScrolling: false, scrollParentAvailable: false, horizontal: false };
|
|
186
376
|
}
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
for (i = 0; i < length; i++) {
|
|
195
|
-
if (listeners[i].once) this.removeListener(event, listeners[i].fn, undefined, true);
|
|
196
|
-
switch (len) {
|
|
197
|
-
case 1:
|
|
198
|
-
listeners[i].fn.call(listeners[i].context);
|
|
199
|
-
break;
|
|
200
|
-
case 2:
|
|
201
|
-
listeners[i].fn.call(listeners[i].context, a1);
|
|
202
|
-
break;
|
|
203
|
-
case 3:
|
|
204
|
-
listeners[i].fn.call(listeners[i].context, a1, a2);
|
|
205
|
-
break;
|
|
206
|
-
case 4:
|
|
207
|
-
listeners[i].fn.call(listeners[i].context, a1, a2, a3);
|
|
208
|
-
break;
|
|
209
|
-
default:
|
|
210
|
-
if (!args) for (j = 1, args = new Array(len - 1); j < len; j++) {
|
|
211
|
-
args[j - 1] = arguments[j];
|
|
212
|
-
}
|
|
213
|
-
listeners[i].fn.apply(listeners[i].context, args);
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
return true;
|
|
377
|
+
return {
|
|
378
|
+
isScrolling: context.isScrolling,
|
|
379
|
+
isScrollToScrolling: context.isScrollToScrolling,
|
|
380
|
+
scrollParentAvailable: context.parentScrollAvailable,
|
|
381
|
+
horizontal: context.horizontal,
|
|
382
|
+
isList: context.isList,
|
|
383
|
+
};
|
|
218
384
|
};
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
385
|
+
const useGetRefMaps = () => {
|
|
386
|
+
const { refs } = react.useContext(ScrollContext);
|
|
387
|
+
return refs;
|
|
388
|
+
};
|
|
389
|
+
const useGetScrollToLast = () => {
|
|
390
|
+
const { scrollToBottom } = react.useContext(ScrollContext);
|
|
391
|
+
return {
|
|
392
|
+
scrollToBottom,
|
|
393
|
+
};
|
|
394
|
+
};
|
|
395
|
+
const useAddObservableChild = (observableChildMethod) => {
|
|
396
|
+
const context = react.useContext(ScrollContext);
|
|
397
|
+
const insideScrollParent = !!context;
|
|
398
|
+
const { observableChildRefs } = context || { observableChildRefs: [] };
|
|
399
|
+
react.useEffect(() => {
|
|
400
|
+
const observableChild = observableChildMethod();
|
|
401
|
+
const index = insideScrollParent ? observableChildRefs.push(observableChild) : 0;
|
|
402
|
+
return () => {
|
|
403
|
+
if (insideScrollParent) {
|
|
404
|
+
observableChildRefs.splice(index - 1, 1);
|
|
405
|
+
}
|
|
406
|
+
};
|
|
407
|
+
}, [observableChildRefs, insideScrollParent]);
|
|
408
|
+
};
|
|
409
|
+
const useObserver = () => {
|
|
410
|
+
const { observableChildRefs } = react.useContext(ScrollContext);
|
|
411
|
+
return observableChildRefs;
|
|
231
412
|
};
|
|
232
413
|
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
414
|
+
const useHandleScroll = ({ threshold = 140, animated = false } = {}) => {
|
|
415
|
+
const [isAtTop, setIsAtTop] = react.useState(false);
|
|
416
|
+
const handleScroll = react.useCallback((_event) => {
|
|
417
|
+
const position = window.scrollY > threshold;
|
|
418
|
+
setIsAtTop(position);
|
|
419
|
+
}, [threshold]);
|
|
420
|
+
const handleWindowScroll = react.useCallback((_event) => {
|
|
421
|
+
handleScroll({
|
|
422
|
+
nativeEvent: {
|
|
423
|
+
contentOffset: { x: 0, y: window.scrollY },
|
|
424
|
+
layoutMeasurement: { height: 0, width: 0 },
|
|
425
|
+
contentSize: { height: 0, width: 0 },
|
|
426
|
+
},
|
|
427
|
+
});
|
|
428
|
+
}, [handleScroll]);
|
|
429
|
+
react.useEffect(() => {
|
|
430
|
+
if (ctDesignCommonUtils.isServer() || !animated)
|
|
431
|
+
return;
|
|
432
|
+
window.addEventListener('scroll', handleWindowScroll);
|
|
433
|
+
return () => {
|
|
434
|
+
window.removeEventListener('scroll', handleWindowScroll);
|
|
435
|
+
};
|
|
436
|
+
}, [handleWindowScroll, animated]);
|
|
437
|
+
const scrollManager = react.useMemo(() => ({ isAtTop, handleScroll, scrollY: window.scrollY }), [isAtTop, handleScroll]);
|
|
438
|
+
return scrollManager;
|
|
244
439
|
};
|
|
245
440
|
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
if (listeners.fn === fn && (!once || listeners.once) && (!context || listeners.context === context)) {
|
|
266
|
-
clearEvent(this, evt);
|
|
267
|
-
}
|
|
268
|
-
} else {
|
|
269
|
-
for (var i = 0, events = [], length = listeners.length; i < length; i++) {
|
|
270
|
-
if (listeners[i].fn !== fn || once && !listeners[i].once || context && listeners[i].context !== context) {
|
|
271
|
-
events.push(listeners[i]);
|
|
272
|
-
}
|
|
441
|
+
const AnimatedScrollContext = react.createContext({
|
|
442
|
+
isAtTop: false,
|
|
443
|
+
handleScroll: () => {
|
|
444
|
+
},
|
|
445
|
+
scrollY: 0,
|
|
446
|
+
});
|
|
447
|
+
const AnimatedScrollContextProvider = ({ children, threshold = 0, }) => {
|
|
448
|
+
const scrollManager = useHandleScroll({ threshold });
|
|
449
|
+
return jsxRuntime.jsx(AnimatedScrollContext.Provider, { value: scrollManager, children: children });
|
|
450
|
+
};
|
|
451
|
+
const useAnimatedScroll = () => {
|
|
452
|
+
const context = react.useContext(AnimatedScrollContext);
|
|
453
|
+
if (!context) {
|
|
454
|
+
return {
|
|
455
|
+
isAtTop: false,
|
|
456
|
+
handleScroll: () => {
|
|
457
|
+
},
|
|
458
|
+
scrollY: 0,
|
|
459
|
+
};
|
|
273
460
|
}
|
|
274
|
-
|
|
275
|
-
//
|
|
276
|
-
// Reset the array, or remove it completely if we have no more listeners.
|
|
277
|
-
//
|
|
278
|
-
if (events.length) this._events[evt] = events.length === 1 ? events[0] : events;else clearEvent(this, evt);
|
|
279
|
-
}
|
|
280
|
-
return this;
|
|
461
|
+
return context;
|
|
281
462
|
};
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
*
|
|
286
|
-
* @param {(String|Symbol)} [event] The event name.
|
|
287
|
-
* @returns {EventEmitter} `this`.
|
|
288
|
-
* @public
|
|
289
|
-
*/
|
|
290
|
-
EventEmitter.prototype.removeAllListeners = function removeAllListeners(event) {
|
|
291
|
-
var evt;
|
|
292
|
-
if (event) {
|
|
293
|
-
evt = prefix ? prefix + event : event;
|
|
294
|
-
if (this._events[evt]) clearEvent(this, evt);
|
|
295
|
-
} else {
|
|
296
|
-
this._events = new Events();
|
|
297
|
-
this._eventsCount = 0;
|
|
298
|
-
}
|
|
299
|
-
return this;
|
|
463
|
+
const useAnimatedScrollValue = () => {
|
|
464
|
+
const { scrollY, isAtTop } = useAnimatedScroll();
|
|
465
|
+
return { scrollY, isAtTop };
|
|
300
466
|
};
|
|
301
467
|
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
//
|
|
319
|
-
// Expose the module.
|
|
320
|
-
//
|
|
321
|
-
{
|
|
322
|
-
module.exports = EventEmitter;
|
|
323
|
-
}
|
|
324
|
-
})(eventemitter3);
|
|
325
|
-
|
|
326
|
-
exports.EVENT_NAMES = void 0;
|
|
327
|
-
(function (EVENT_NAMES) {
|
|
328
|
-
EVENT_NAMES["SCROLL_VIEW"] = "scroll-view";
|
|
329
|
-
EVENT_NAMES["SCROLL_INTO_VIEW"] = "scroll-into-view";
|
|
330
|
-
})(exports.EVENT_NAMES || (exports.EVENT_NAMES = {}));
|
|
331
|
-
|
|
332
|
-
class CustomDocumentEvent {
|
|
333
|
-
constructor() {
|
|
334
|
-
this.eventMap = new Map();
|
|
335
|
-
this.emitter = new eventemitter3Exports();
|
|
336
|
-
}
|
|
337
|
-
addEventListener(event, listener) {
|
|
338
|
-
if (event === exports.EVENT_NAMES.SCROLL_VIEW) {
|
|
339
|
-
const _listener = listener;
|
|
340
|
-
const eventHandler = () => {
|
|
341
|
-
_listener([{ x: window.scrollX, y: window.scrollY }]);
|
|
342
|
-
};
|
|
343
|
-
window.addEventListener('scroll', eventHandler);
|
|
344
|
-
this.eventMap.set(listener, eventHandler);
|
|
345
|
-
}
|
|
346
|
-
else {
|
|
347
|
-
this.emitter.addListener(event, listener);
|
|
348
|
-
this.eventMap.set(listener, listener);
|
|
349
|
-
}
|
|
350
|
-
}
|
|
351
|
-
removeEventListener(event, listener) {
|
|
352
|
-
if (event === exports.EVENT_NAMES.SCROLL_VIEW) {
|
|
353
|
-
const eventHandler = this.eventMap.get(listener);
|
|
354
|
-
if (eventHandler) {
|
|
355
|
-
window.removeEventListener('scroll', eventHandler);
|
|
356
|
-
this.eventMap.delete(listener);
|
|
357
|
-
}
|
|
358
|
-
}
|
|
359
|
-
else {
|
|
360
|
-
this.emitter.removeListener(event, listener);
|
|
361
|
-
}
|
|
362
|
-
}
|
|
363
|
-
dispose() {
|
|
364
|
-
this.emitter.removeAllListeners();
|
|
365
|
-
}
|
|
366
|
-
emit(event, data) {
|
|
367
|
-
return this.emitter.emit(event, data);
|
|
368
|
-
}
|
|
369
|
-
}
|
|
370
|
-
const scrollEvent = new CustomDocumentEvent();
|
|
371
|
-
|
|
372
|
-
const staticScrollStyles = ctDesignStyleManager.makeStyles(() => ({
|
|
373
|
-
viewport: {
|
|
374
|
-
display: 'flex',
|
|
375
|
-
flexDirection: 'column',
|
|
376
|
-
minHeight: 0,
|
|
377
|
-
minWidth: 0,
|
|
378
|
-
width: '100%',
|
|
379
|
-
position: 'relative',
|
|
380
|
-
WebkitOverflowScrolling: 'touch',
|
|
381
|
-
},
|
|
382
|
-
viewportVertical: {
|
|
383
|
-
flex: 1,
|
|
384
|
-
overflowX: 'hidden',
|
|
385
|
-
overflowY: 'auto',
|
|
386
|
-
overscrollBehavior: 'contain',
|
|
387
|
-
},
|
|
388
|
-
viewportHorizontal: {
|
|
389
|
-
flex: 1,
|
|
390
|
-
minWidth: 0,
|
|
391
|
-
overflowX: 'auto',
|
|
392
|
-
overflowY: 'hidden',
|
|
393
|
-
alignItems: 'flex-start',
|
|
394
|
-
},
|
|
395
|
-
contentVertical: {
|
|
396
|
-
display: 'flex',
|
|
397
|
-
flexDirection: 'column',
|
|
398
|
-
flexShrink: 0,
|
|
399
|
-
width: '100%',
|
|
400
|
-
},
|
|
401
|
-
contentHorizontal: {
|
|
402
|
-
display: 'flex',
|
|
403
|
-
flexDirection: 'row',
|
|
404
|
-
flexWrap: 'nowrap',
|
|
405
|
-
flexShrink: 0,
|
|
406
|
-
width: 'max-content',
|
|
407
|
-
minWidth: '100%',
|
|
408
|
-
},
|
|
409
|
-
hideScrollbar: {
|
|
410
|
-
scrollbarWidth: 'none',
|
|
411
|
-
msOverflowStyle: 'none',
|
|
412
|
-
'&::-webkit-scrollbar': {
|
|
413
|
-
display: 'none',
|
|
414
|
-
},
|
|
415
|
-
},
|
|
416
|
-
pagingSnapVertical: { scrollSnapType: 'y mandatory' },
|
|
417
|
-
pagingSnapHorizontal: { scrollSnapType: 'x mandatory' },
|
|
418
|
-
viewportVerticalNested: {
|
|
419
|
-
flex: 1,
|
|
420
|
-
minHeight: 0,
|
|
421
|
-
height: '100%',
|
|
422
|
-
maxHeight: '100%',
|
|
423
|
-
overflowX: 'hidden',
|
|
424
|
-
overflowY: 'auto',
|
|
425
|
-
overscrollBehavior: 'auto',
|
|
426
|
-
},
|
|
427
|
-
}));
|
|
428
|
-
const getScrollableParent = (node) => {
|
|
429
|
-
var _a;
|
|
430
|
-
let parent = (_a = node === null || node === void 0 ? void 0 : node.parentElement) !== null && _a !== void 0 ? _a : null;
|
|
431
|
-
while (parent) {
|
|
432
|
-
const { overflowY } = getComputedStyle(parent);
|
|
433
|
-
if (/(auto|scroll|overlay)/.test(overflowY) && parent.scrollHeight > parent.clientHeight + 1) {
|
|
434
|
-
return parent;
|
|
435
|
-
}
|
|
436
|
-
parent = parent.parentElement;
|
|
437
|
-
}
|
|
438
|
-
return null;
|
|
439
|
-
};
|
|
440
|
-
const emitScrollEvent = (target) => ({
|
|
441
|
-
nativeEvent: {
|
|
442
|
-
contentOffset: {
|
|
443
|
-
x: target.scrollLeft,
|
|
444
|
-
y: target.scrollTop,
|
|
445
|
-
},
|
|
446
|
-
layoutMeasurement: {
|
|
447
|
-
height: target.clientHeight,
|
|
448
|
-
width: target.clientWidth,
|
|
449
|
-
},
|
|
450
|
-
contentSize: {
|
|
451
|
-
height: target.scrollHeight,
|
|
452
|
-
width: target.scrollWidth,
|
|
453
|
-
},
|
|
454
|
-
},
|
|
455
|
-
});
|
|
456
|
-
const ScrollContainer = react.forwardRef(({ children, styleConfig, onScroll, horizontal = false, scrollEventThrottle = 0, showsVerticalScrollIndicator = false, showsHorizontalScrollIndicator = true, width, onIndexChange, currentActiveIndex, pagingEnabled = false, snapToOffsets, totalItemsLength, contentContainerStyle, onLayout, attachScrollEvent = false, nestedScrollEnabled = false, stickyHeaderIndices: _stickyHeaderIndices, removeClippedSubviews: _removeClippedSubviews, isVisible: _isVisible, keyboardShouldPersistTaps: _keyboardShouldPersistTaps, bounces: _bounces, id, onClick, onMouseEnter, onMouseLeave, onTransitionEnd, onTouchStart, onTouchEnd, onTouchCancel, onTouchMove, }, ref) => {
|
|
457
|
-
const localRef = react.useRef(null);
|
|
458
|
-
const lastScrollEventTimeRef = react.useRef(0);
|
|
459
|
-
const handleFocus = react.useCallback(() => {
|
|
460
|
-
var _a;
|
|
461
|
-
(_a = localRef.current) === null || _a === void 0 ? void 0 : _a.focus();
|
|
462
|
-
}, []);
|
|
463
|
-
const handleGetBoundingRect = react.useCallback((callback) => {
|
|
464
|
-
var _a;
|
|
465
|
-
const rect = (_a = localRef.current) === null || _a === void 0 ? void 0 : _a.getBoundingClientRect();
|
|
466
|
-
if (rect) {
|
|
467
|
-
callback === null || callback === void 0 ? void 0 : callback({
|
|
468
|
-
x: rect.x,
|
|
469
|
-
y: rect.y,
|
|
470
|
-
width: rect.width,
|
|
471
|
-
height: rect.height,
|
|
472
|
-
});
|
|
473
|
-
}
|
|
474
|
-
}, []);
|
|
475
|
-
const handleAddEventListener = react.useCallback((type, listener, options) => {
|
|
476
|
-
var _a;
|
|
477
|
-
(_a = localRef.current) === null || _a === void 0 ? void 0 : _a.addEventListener(type, listener, options);
|
|
478
|
-
}, []);
|
|
479
|
-
const handleRemoveEventListener = react.useCallback((type, listener, options) => {
|
|
480
|
-
var _a;
|
|
481
|
-
(_a = localRef.current) === null || _a === void 0 ? void 0 : _a.removeEventListener(type, listener, options);
|
|
482
|
-
}, []);
|
|
483
|
-
react.useImperativeHandle(ref, () => {
|
|
484
|
-
var _a;
|
|
485
|
-
return ({
|
|
486
|
-
focus: handleFocus,
|
|
487
|
-
getBoundingRectWithCallback: handleGetBoundingRect,
|
|
488
|
-
getElementRef: () => localRef,
|
|
489
|
-
measure: (callback) => {
|
|
490
|
-
var _a;
|
|
491
|
-
const rect = (_a = localRef.current) === null || _a === void 0 ? void 0 : _a.getBoundingClientRect();
|
|
492
|
-
if (!rect)
|
|
493
|
-
return;
|
|
494
|
-
callback(rect.x, rect.y, rect.width, rect.height, rect.x, rect.y);
|
|
495
|
-
},
|
|
496
|
-
classList: {
|
|
497
|
-
add: (className) => {
|
|
498
|
-
var _a;
|
|
499
|
-
(_a = localRef.current) === null || _a === void 0 ? void 0 : _a.classList.add(className);
|
|
500
|
-
},
|
|
501
|
-
},
|
|
502
|
-
addEventListener: handleAddEventListener,
|
|
503
|
-
removeEventListener: handleRemoveEventListener,
|
|
504
|
-
style: (((_a = localRef.current) === null || _a === void 0 ? void 0 : _a.style) || {}),
|
|
505
|
-
scrollTo: (x, y) => {
|
|
506
|
-
const node = localRef.current;
|
|
507
|
-
if (!node)
|
|
508
|
-
return;
|
|
509
|
-
node.scrollTo({ left: x, top: y, behavior: 'auto' });
|
|
510
|
-
},
|
|
511
|
-
scrollToEnd: () => {
|
|
512
|
-
const node = localRef.current;
|
|
513
|
-
if (!node)
|
|
514
|
-
return;
|
|
515
|
-
if (horizontal) {
|
|
516
|
-
node.scrollTo({
|
|
517
|
-
left: node.scrollWidth - node.clientWidth,
|
|
518
|
-
top: 0,
|
|
519
|
-
behavior: 'auto',
|
|
520
|
-
});
|
|
521
|
-
}
|
|
522
|
-
else {
|
|
523
|
-
node.scrollTo({
|
|
524
|
-
left: 0,
|
|
525
|
-
top: node.scrollHeight - node.clientHeight,
|
|
526
|
-
behavior: 'auto',
|
|
527
|
-
});
|
|
528
|
-
}
|
|
529
|
-
},
|
|
530
|
-
scrollById: (id, animated = true) => {
|
|
531
|
-
const target = document.getElementById(id);
|
|
532
|
-
target === null || target === void 0 ? void 0 : target.scrollIntoView({ behavior: animated ? 'smooth' : 'auto', block: 'nearest', inline: 'nearest' });
|
|
533
|
-
},
|
|
534
|
-
get scrollLeft() {
|
|
535
|
-
var _a, _b;
|
|
536
|
-
return (_b = (_a = localRef.current) === null || _a === void 0 ? void 0 : _a.scrollLeft) !== null && _b !== void 0 ? _b : 0;
|
|
537
|
-
},
|
|
538
|
-
set scrollLeft(value) {
|
|
539
|
-
if (localRef.current) {
|
|
540
|
-
localRef.current.scrollLeft = value;
|
|
541
|
-
}
|
|
542
|
-
},
|
|
543
|
-
get scrollTop() {
|
|
544
|
-
var _a, _b;
|
|
545
|
-
return (_b = (_a = localRef.current) === null || _a === void 0 ? void 0 : _a.scrollTop) !== null && _b !== void 0 ? _b : 0;
|
|
546
|
-
},
|
|
547
|
-
set scrollTop(value) {
|
|
548
|
-
if (localRef.current) {
|
|
549
|
-
localRef.current.scrollTop = value;
|
|
550
|
-
}
|
|
551
|
-
},
|
|
552
|
-
});
|
|
553
|
-
}, [handleFocus, handleGetBoundingRect, handleAddEventListener, handleRemoveEventListener, horizontal]);
|
|
554
|
-
const { root: rootStyles = [] } = styleConfig || {};
|
|
555
|
-
const contentStyles = contentContainerStyle !== null && contentContainerStyle !== void 0 ? contentContainerStyle : [];
|
|
556
|
-
const hideHorizontalScrollbar = horizontal && showsHorizontalScrollIndicator === false;
|
|
557
|
-
const hideVerticalScrollbar = !horizontal && showsVerticalScrollIndicator === false;
|
|
558
|
-
const viewportClassName = ctDesignStyleManager.useWebMergeStyles([
|
|
559
|
-
staticScrollStyles.viewport,
|
|
560
|
-
horizontal
|
|
561
|
-
? staticScrollStyles.viewportHorizontal
|
|
562
|
-
: nestedScrollEnabled
|
|
563
|
-
? staticScrollStyles.viewportVerticalNested
|
|
564
|
-
: staticScrollStyles.viewportVertical,
|
|
565
|
-
...(hideHorizontalScrollbar || hideVerticalScrollbar ? [staticScrollStyles.hideScrollbar] : []),
|
|
566
|
-
...(pagingEnabled
|
|
567
|
-
? [horizontal ? staticScrollStyles.pagingSnapHorizontal : staticScrollStyles.pagingSnapVertical]
|
|
568
|
-
: []),
|
|
569
|
-
...rootStyles,
|
|
570
|
-
], [horizontal, nestedScrollEnabled, hideHorizontalScrollbar, hideVerticalScrollbar, pagingEnabled, rootStyles]);
|
|
571
|
-
const contentClassName = ctDesignStyleManager.useWebMergeStyles([horizontal ? staticScrollStyles.contentHorizontal : staticScrollStyles.contentVertical, ...contentStyles], [horizontal, contentStyles]);
|
|
572
|
-
const fireScroll = react.useCallback((target) => {
|
|
573
|
-
const event = emitScrollEvent(target);
|
|
574
|
-
if (scrollEventThrottle > 0) {
|
|
575
|
-
const now = Date.now();
|
|
576
|
-
if (now - lastScrollEventTimeRef.current < scrollEventThrottle) {
|
|
577
|
-
return;
|
|
578
|
-
}
|
|
579
|
-
lastScrollEventTimeRef.current = now;
|
|
580
|
-
}
|
|
581
|
-
if (attachScrollEvent) {
|
|
582
|
-
scrollEvent.emit('scroll-view', [event.nativeEvent.contentOffset]);
|
|
583
|
-
}
|
|
584
|
-
onScroll === null || onScroll === void 0 ? void 0 : onScroll(event);
|
|
585
|
-
if (horizontal && width && totalItemsLength && onIndexChange) {
|
|
586
|
-
const offsetX = target.scrollLeft;
|
|
587
|
-
const visibleWidth = target.clientWidth;
|
|
588
|
-
const tolerance = 2;
|
|
589
|
-
let index;
|
|
590
|
-
if (offsetX <= tolerance) {
|
|
591
|
-
index = 0;
|
|
592
|
-
}
|
|
593
|
-
else {
|
|
594
|
-
const centerX = offsetX + visibleWidth / 2;
|
|
595
|
-
index = Math.max(0, Math.min(totalItemsLength - 1, Math.round((centerX - width / 2) / width)));
|
|
596
|
-
}
|
|
597
|
-
onIndexChange(index);
|
|
598
|
-
}
|
|
599
|
-
}, [attachScrollEvent, horizontal, onIndexChange, onScroll, scrollEventThrottle, totalItemsLength, width]);
|
|
600
|
-
const handleScroll = react.useCallback((e) => {
|
|
601
|
-
fireScroll(e.currentTarget);
|
|
602
|
-
}, [fireScroll]);
|
|
603
|
-
const handleNestedWheel = react.useCallback((e) => {
|
|
604
|
-
if (!nestedScrollEnabled || horizontal) {
|
|
605
|
-
return;
|
|
606
|
-
}
|
|
607
|
-
const node = e.currentTarget;
|
|
608
|
-
const hasOverflow = node.scrollHeight > node.clientHeight + 1;
|
|
609
|
-
const maxScrollTop = node.scrollHeight - node.clientHeight;
|
|
610
|
-
const atTop = node.scrollTop <= 0;
|
|
611
|
-
const atBottom = node.scrollTop >= maxScrollTop - 1;
|
|
612
|
-
const scrollingUp = e.deltaY < 0;
|
|
613
|
-
const scrollingDown = e.deltaY > 0;
|
|
614
|
-
const shouldForward = !hasOverflow || (scrollingUp && atTop) || (scrollingDown && atBottom);
|
|
615
|
-
if (!shouldForward) {
|
|
616
|
-
return;
|
|
617
|
-
}
|
|
618
|
-
const scrollableParent = getScrollableParent(node);
|
|
619
|
-
if (!scrollableParent) {
|
|
620
|
-
return;
|
|
621
|
-
}
|
|
622
|
-
e.preventDefault();
|
|
623
|
-
scrollableParent.scrollTop += e.deltaY;
|
|
624
|
-
}, [horizontal, nestedScrollEnabled]);
|
|
625
|
-
react.useLayoutEffect(() => {
|
|
626
|
-
const node = localRef.current;
|
|
627
|
-
if (!node || !onLayout)
|
|
628
|
-
return;
|
|
629
|
-
onLayout({
|
|
630
|
-
layout: {
|
|
631
|
-
height: node.clientHeight,
|
|
632
|
-
width: node.clientWidth,
|
|
633
|
-
x: node.getBoundingClientRect().x,
|
|
634
|
-
y: node.getBoundingClientRect().y,
|
|
635
|
-
},
|
|
636
|
-
});
|
|
637
|
-
}, [onLayout]);
|
|
638
|
-
react.useEffect(() => {
|
|
639
|
-
const node = localRef.current;
|
|
640
|
-
if (!node || typeof currentActiveIndex !== 'number' || currentActiveIndex < 0 || !width) {
|
|
641
|
-
return;
|
|
642
|
-
}
|
|
643
|
-
node.scrollTo({
|
|
644
|
-
left: horizontal ? currentActiveIndex * (width + 16) : 0,
|
|
645
|
-
top: horizontal ? 0 : currentActiveIndex * (width + 16),
|
|
646
|
-
behavior: 'smooth',
|
|
647
|
-
});
|
|
648
|
-
}, [currentActiveIndex, horizontal, width]);
|
|
649
|
-
react.useEffect(() => {
|
|
650
|
-
if (!(snapToOffsets === null || snapToOffsets === void 0 ? void 0 : snapToOffsets.length) || !localRef.current)
|
|
651
|
-
return;
|
|
652
|
-
}, [snapToOffsets]);
|
|
653
|
-
return (jsxRuntime.jsx("div", { ref: localRef, id: id, className: viewportClassName, onScroll: handleScroll, onWheel: nestedScrollEnabled && !horizontal ? handleNestedWheel : undefined, onClick: onClick, onMouseEnter: onMouseEnter, onMouseLeave: onMouseLeave, onTransitionEnd: onTransitionEnd, onTouchStart: onTouchStart, onTouchEnd: onTouchEnd, onTouchCancel: onTouchCancel, onTouchMove: onTouchMove, children: jsxRuntime.jsx("div", { className: contentClassName, children: children }) }));
|
|
654
|
-
});
|
|
655
|
-
ScrollContainer.displayName = 'ScrollContainer';
|
|
656
|
-
|
|
657
|
-
const ScrollContext = react.createContext({
|
|
658
|
-
isScrolling: false,
|
|
659
|
-
refs: {},
|
|
660
|
-
observableChildRefs: [],
|
|
661
|
-
parentScrollAvailable: false,
|
|
662
|
-
horizontal: false,
|
|
663
|
-
scrollToBottom: () => {
|
|
664
|
-
},
|
|
665
|
-
});
|
|
666
|
-
const ScrollContextProvider = ({ children, isScrolling, refs, scrollTo, scrollToSkip, isScrollToScrolling, observableChildRefs, horizontal, scrollToBottom, }) => {
|
|
667
|
-
return (jsxRuntime.jsx(ScrollContext.Provider, { value: {
|
|
668
|
-
observableChildRefs,
|
|
669
|
-
isScrolling,
|
|
670
|
-
refs,
|
|
671
|
-
scrollTo,
|
|
672
|
-
scrollToSkip,
|
|
673
|
-
isScrollToScrolling,
|
|
674
|
-
parentScrollAvailable: true,
|
|
675
|
-
horizontal,
|
|
676
|
-
scrollToBottom,
|
|
677
|
-
}, children: children }));
|
|
678
|
-
};
|
|
679
|
-
const useGetScrolling = () => {
|
|
680
|
-
const context = react.useContext(ScrollContext);
|
|
681
|
-
if (!context) {
|
|
682
|
-
return { isScrolling: false, isScrollToScrolling: false, scrollParentAvailable: false, horizontal: false };
|
|
683
|
-
}
|
|
684
|
-
return {
|
|
685
|
-
isScrolling: context.isScrolling,
|
|
686
|
-
isScrollToScrolling: context.isScrollToScrolling,
|
|
687
|
-
scrollParentAvailable: context.parentScrollAvailable,
|
|
688
|
-
horizontal: context.horizontal,
|
|
689
|
-
isList: context.isList,
|
|
690
|
-
};
|
|
691
|
-
};
|
|
692
|
-
const useGetRefMaps = () => {
|
|
693
|
-
const { refs } = react.useContext(ScrollContext);
|
|
694
|
-
return refs;
|
|
695
|
-
};
|
|
696
|
-
const useGetScrollToLast = () => {
|
|
697
|
-
const { scrollToBottom } = react.useContext(ScrollContext);
|
|
698
|
-
return {
|
|
699
|
-
scrollToBottom,
|
|
700
|
-
};
|
|
701
|
-
};
|
|
702
|
-
const useAddObservableChild = (observableChildMethod) => {
|
|
703
|
-
const context = react.useContext(ScrollContext);
|
|
704
|
-
const insideScrollParent = !!context;
|
|
705
|
-
const { observableChildRefs } = context || { observableChildRefs: [] };
|
|
706
|
-
react.useEffect(() => {
|
|
707
|
-
const observableChild = observableChildMethod();
|
|
708
|
-
const index = insideScrollParent ? observableChildRefs.push(observableChild) : 0;
|
|
709
|
-
return () => {
|
|
710
|
-
if (insideScrollParent) {
|
|
711
|
-
observableChildRefs.splice(index - 1, 1);
|
|
712
|
-
}
|
|
713
|
-
};
|
|
714
|
-
}, [observableChildRefs, insideScrollParent]);
|
|
715
|
-
};
|
|
716
|
-
const useObserver = () => {
|
|
717
|
-
const { observableChildRefs } = react.useContext(ScrollContext);
|
|
718
|
-
return observableChildRefs;
|
|
719
|
-
};
|
|
720
|
-
|
|
721
|
-
const useHandleScroll = ({ threshold = 140, animated = false } = {}) => {
|
|
722
|
-
const [isAtTop, setIsAtTop] = react.useState(false);
|
|
723
|
-
const handleScroll = react.useCallback((_event) => {
|
|
724
|
-
const position = window.scrollY > threshold;
|
|
725
|
-
setIsAtTop(position);
|
|
726
|
-
}, [threshold]);
|
|
727
|
-
const handleWindowScroll = react.useCallback((_event) => {
|
|
728
|
-
handleScroll({
|
|
729
|
-
nativeEvent: {
|
|
730
|
-
contentOffset: { x: 0, y: window.scrollY },
|
|
731
|
-
layoutMeasurement: { height: 0, width: 0 },
|
|
732
|
-
contentSize: { height: 0, width: 0 },
|
|
733
|
-
},
|
|
734
|
-
});
|
|
735
|
-
}, [handleScroll]);
|
|
736
|
-
react.useEffect(() => {
|
|
737
|
-
if (ctDesignCommonUtils.isServer() || !animated)
|
|
738
|
-
return;
|
|
739
|
-
window.addEventListener('scroll', handleWindowScroll);
|
|
740
|
-
return () => {
|
|
741
|
-
window.removeEventListener('scroll', handleWindowScroll);
|
|
742
|
-
};
|
|
743
|
-
}, [handleWindowScroll, animated]);
|
|
744
|
-
const scrollManager = react.useMemo(() => ({ isAtTop, handleScroll, scrollY: window.scrollY }), [isAtTop, handleScroll]);
|
|
745
|
-
return scrollManager;
|
|
746
|
-
};
|
|
747
|
-
|
|
748
|
-
const AnimatedScrollContext = react.createContext({
|
|
749
|
-
isAtTop: false,
|
|
750
|
-
handleScroll: () => {
|
|
751
|
-
},
|
|
752
|
-
scrollY: 0,
|
|
753
|
-
});
|
|
754
|
-
const AnimatedScrollContextProvider = ({ children, threshold = 0, }) => {
|
|
755
|
-
const scrollManager = useHandleScroll({ threshold });
|
|
756
|
-
return jsxRuntime.jsx(AnimatedScrollContext.Provider, { value: scrollManager, children: children });
|
|
757
|
-
};
|
|
758
|
-
const useAnimatedScroll = () => {
|
|
759
|
-
const context = react.useContext(AnimatedScrollContext);
|
|
760
|
-
if (!context) {
|
|
761
|
-
return {
|
|
762
|
-
isAtTop: false,
|
|
763
|
-
handleScroll: () => {
|
|
764
|
-
},
|
|
765
|
-
scrollY: 0,
|
|
766
|
-
};
|
|
767
|
-
}
|
|
768
|
-
return context;
|
|
769
|
-
};
|
|
770
|
-
const useAnimatedScrollValue = () => {
|
|
771
|
-
const { scrollY, isAtTop } = useAnimatedScroll();
|
|
772
|
-
return { scrollY, isAtTop };
|
|
773
|
-
};
|
|
774
|
-
|
|
775
|
-
const StickyContext = react.createContext({ stickyIndex: -1 });
|
|
776
|
-
const StickyProvider = ({ children, stickyIndex }) => {
|
|
777
|
-
return jsxRuntime.jsx(StickyContext.Provider, { value: { stickyIndex }, children: children });
|
|
778
|
-
};
|
|
779
|
-
const ParentStickyContext = react.createContext({});
|
|
780
|
-
const ParentStickyProvider = ({ children, addStickyIndices, removeStickIndices, }) => {
|
|
781
|
-
return (jsxRuntime.jsx(ParentStickyContext.Provider, { value: { addStickyIndices, removeStickIndices }, children: children }));
|
|
782
|
-
};
|
|
783
|
-
const useStickyContext = () => {
|
|
784
|
-
const { stickyIndex } = react.useContext(StickyContext);
|
|
785
|
-
return stickyIndex;
|
|
786
|
-
};
|
|
787
|
-
const useParentStickyContext = () => {
|
|
788
|
-
const { addStickyIndices, removeStickIndices } = react.useContext(ParentStickyContext);
|
|
789
|
-
return [addStickyIndices, removeStickIndices];
|
|
790
|
-
};
|
|
468
|
+
const StickyContext = react.createContext({ stickyIndex: -1 });
|
|
469
|
+
const StickyProvider = ({ children, stickyIndex }) => {
|
|
470
|
+
return jsxRuntime.jsx(StickyContext.Provider, { value: { stickyIndex }, children: children });
|
|
471
|
+
};
|
|
472
|
+
const ParentStickyContext = react.createContext({});
|
|
473
|
+
const ParentStickyProvider = ({ children, addStickyIndices, removeStickIndices, }) => {
|
|
474
|
+
return (jsxRuntime.jsx(ParentStickyContext.Provider, { value: { addStickyIndices, removeStickIndices }, children: children }));
|
|
475
|
+
};
|
|
476
|
+
const useStickyContext = () => {
|
|
477
|
+
const { stickyIndex } = react.useContext(StickyContext);
|
|
478
|
+
return stickyIndex;
|
|
479
|
+
};
|
|
480
|
+
const useParentStickyContext = () => {
|
|
481
|
+
const { addStickyIndices, removeStickIndices } = react.useContext(ParentStickyContext);
|
|
482
|
+
return [addStickyIndices, removeStickIndices];
|
|
483
|
+
};
|
|
791
484
|
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
485
|
+
const useScrollById = () => {
|
|
486
|
+
const { refs, scrollTo: _scrollTo } = react.useContext(ScrollContext);
|
|
487
|
+
const scrollTo = react.useCallback((id, { x: _x, y: _y }) => {
|
|
488
|
+
var _a, _b, _c;
|
|
489
|
+
(_c = (_b = (_a = refs[id]) === null || _a === void 0 ? void 0 : _a.current) === null || _b === void 0 ? void 0 : _b.getBoundingRectWithCallback) === null || _c === void 0 ? void 0 : _c.call(_b, ({ x, y }) => {
|
|
490
|
+
_scrollTo === null || _scrollTo === void 0 ? void 0 : _scrollTo(y - _y, x - _x);
|
|
491
|
+
});
|
|
492
|
+
}, [_scrollTo, refs]);
|
|
493
|
+
return { scrollTo };
|
|
494
|
+
};
|
|
802
495
|
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
496
|
+
exports.AnimatedScrollContextProvider = AnimatedScrollContextProvider;
|
|
497
|
+
exports.ParentStickyProvider = ParentStickyProvider;
|
|
498
|
+
exports.ScrollContainer = ScrollContainer;
|
|
499
|
+
exports.ScrollContext = ScrollContext;
|
|
500
|
+
exports.ScrollContextProvider = ScrollContextProvider;
|
|
501
|
+
exports.StickyProvider = StickyProvider;
|
|
502
|
+
exports.scrollEvent = scrollEvent;
|
|
503
|
+
exports.useAddObservableChild = useAddObservableChild;
|
|
504
|
+
exports.useAnimatedScroll = useAnimatedScroll;
|
|
505
|
+
exports.useAnimatedScrollValue = useAnimatedScrollValue;
|
|
506
|
+
exports.useGetRefMaps = useGetRefMaps;
|
|
507
|
+
exports.useGetScrollToLast = useGetScrollToLast;
|
|
508
|
+
exports.useGetScrolling = useGetScrolling;
|
|
509
|
+
exports.useHandleScroll = useHandleScroll;
|
|
510
|
+
exports.useObserver = useObserver;
|
|
511
|
+
exports.useParentStickyContext = useParentStickyContext;
|
|
512
|
+
exports.useScrollById = useScrollById;
|
|
513
|
+
exports.useStickyContext = useStickyContext;
|
|
821
514
|
|
|
822
515
|
}));
|
|
823
516
|
//# sourceMappingURL=ct-design-scroll-container.umd.js.map
|