react-spring-carousel 3.0.0-beta003 → 3.0.0-beta005
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/cjs/index.js +3840 -128
- package/dist/cjs/index.js.map +1 -1
- package/dist/esm/index.js +2 -2
- package/dist/esm/index2.js +2 -2
- package/dist/esm/useSpringCarousel.js +80 -81
- package/dist/esm/useSpringCarousel.js.map +1 -1
- package/dist/esm/useThumbsModule-dc12dd34.js +3863 -0
- package/dist/esm/useThumbsModule-dc12dd34.js.map +1 -0
- package/dist/types/modules/useEventsModule.d.ts +7 -7
- package/dist/types/modules/useFullscreenModule.d.ts +2 -2
- package/dist/types/modules/useThumbsModule.d.ts +3 -3
- package/dist/types/types/common.d.ts +2 -2
- package/dist/types/types/index.d.ts +1 -1
- package/dist/types/types/internals.d.ts +13 -13
- package/dist/types/useSpringCarousel.d.ts +1 -1
- package/dist/umd/index.js +3841 -129
- package/dist/umd/index.js.map +1 -1
- package/package.json +6 -8
- package/dist/esm/useThumbsModule-12c81348.js +0 -168
- package/dist/esm/useThumbsModule-12c81348.js.map +0 -1
package/dist/esm/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
export { useSpringCarousel, useSpringCarouselContext } from './useSpringCarousel.js';
|
|
2
2
|
import 'react/jsx-runtime';
|
|
3
|
-
import '
|
|
3
|
+
import './useThumbsModule-dc12dd34.js';
|
|
4
4
|
import 'react';
|
|
5
|
-
import './useThumbsModule-12c81348.js';
|
|
6
5
|
import 'screenfull';
|
|
6
|
+
import 'react-dom';
|
|
7
7
|
import '@use-gesture/react';
|
|
8
8
|
//# sourceMappingURL=index.js.map
|
package/dist/esm/index2.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { a as useEventsModule, c as useFullscreenModule, b as useThumbsModule } from './useThumbsModule-dc12dd34.js';
|
|
2
2
|
import 'react';
|
|
3
3
|
import 'screenfull';
|
|
4
4
|
import 'react/jsx-runtime';
|
|
5
|
-
import '
|
|
5
|
+
import 'react-dom';
|
|
6
6
|
//# sourceMappingURL=index2.js.map
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import { jsx } from 'react/jsx-runtime';
|
|
2
|
-
import { useSpring, config } from '
|
|
2
|
+
import { u as useSpring, a as useEventsModule, b as useThumbsModule, c as useFullscreenModule, d as config } from './useThumbsModule-dc12dd34.js';
|
|
3
3
|
import { createContext, useRef, useCallback, useEffect, useLayoutEffect, useContext } from 'react';
|
|
4
|
-
import { u as useEventsModule, a as useThumbsModule, b as useFullscreenModule } from './useThumbsModule-12c81348.js';
|
|
5
4
|
import { useDrag } from '@use-gesture/react';
|
|
6
5
|
import 'screenfull';
|
|
6
|
+
import 'react-dom';
|
|
7
7
|
|
|
8
|
-
function useSpringCarousel({ items, init = true, withThumbs, thumbsSlideAxis =
|
|
8
|
+
function useSpringCarousel({ items, init = true, withThumbs, thumbsSlideAxis = 'x', itemsPerSlide = 1, slideType = 'fixed', gutter = 0, withLoop = false, startEndGutter = 0, carouselSlideAxis = 'x', disableGestures = false, draggingSlideTreshold: _draggingSlideTreshold, slideWhenThresholdIsReached = false, freeScroll, enableFreeScrollDrag, initialStartingPosition, prepareThumbsData, initialActiveItem = 0, }) {
|
|
9
9
|
const prevWindowWidth = useRef(0);
|
|
10
10
|
const draggingSlideTreshold = useRef(_draggingSlideTreshold !== null && _draggingSlideTreshold !== void 0 ? _draggingSlideTreshold : 0);
|
|
11
|
-
const slideActionType = useRef(
|
|
12
|
-
const slideModeType = useRef(
|
|
11
|
+
const slideActionType = useRef('initial');
|
|
12
|
+
const slideModeType = useRef('initial');
|
|
13
13
|
const prevSlidedValue = useRef(0);
|
|
14
14
|
const [spring, setSpring] = useSpring(() => ({
|
|
15
15
|
val: 0,
|
|
@@ -17,7 +17,7 @@ function useSpringCarousel({ items, init = true, withThumbs, thumbsSlideAxis = "
|
|
|
17
17
|
onChange({ value }) {
|
|
18
18
|
if (freeScroll && mainCarouselWrapperRef.current) {
|
|
19
19
|
setStartEndItemReachedOnFreeScroll();
|
|
20
|
-
if (carouselSlideAxis ===
|
|
20
|
+
if (carouselSlideAxis === 'x') {
|
|
21
21
|
mainCarouselWrapperRef.current.scrollLeft = Math.abs(value.val);
|
|
22
22
|
}
|
|
23
23
|
else {
|
|
@@ -25,7 +25,7 @@ function useSpringCarousel({ items, init = true, withThumbs, thumbsSlideAxis = "
|
|
|
25
25
|
}
|
|
26
26
|
}
|
|
27
27
|
else if (carouselTrackWrapperRef.current) {
|
|
28
|
-
if (carouselSlideAxis ===
|
|
28
|
+
if (carouselSlideAxis === 'x') {
|
|
29
29
|
carouselTrackWrapperRef.current.style.transform = `translate3d(${value.val}px, 0px,0px)`;
|
|
30
30
|
}
|
|
31
31
|
else {
|
|
@@ -42,9 +42,9 @@ function useSpringCarousel({ items, init = true, withThumbs, thumbsSlideAxis = "
|
|
|
42
42
|
const getItems = useCallback(() => {
|
|
43
43
|
if (withLoop) {
|
|
44
44
|
return [
|
|
45
|
-
...items.map(
|
|
45
|
+
...items.map(i => (Object.assign(Object.assign({}, i), { id: `prev-repeated-item-${i.id}` }))),
|
|
46
46
|
...items,
|
|
47
|
-
...items.map(
|
|
47
|
+
...items.map(i => (Object.assign(Object.assign({}, i), { id: `next-repeated-item-${i.id}` }))),
|
|
48
48
|
];
|
|
49
49
|
}
|
|
50
50
|
return [...items];
|
|
@@ -63,7 +63,7 @@ function useSpringCarousel({ items, init = true, withThumbs, thumbsSlideAxis = "
|
|
|
63
63
|
handleResize: () => adjustCarouselWrapperPosition(),
|
|
64
64
|
});
|
|
65
65
|
function getItemStyles() {
|
|
66
|
-
if (slideType ===
|
|
66
|
+
if (slideType === 'fixed' && !freeScroll) {
|
|
67
67
|
return {
|
|
68
68
|
marginRight: `${gutter}px`,
|
|
69
69
|
flex: `1 0 calc(100% / ${itemsPerSlide} - ${(gutter * (itemsPerSlide - 1)) / itemsPerSlide}px)`,
|
|
@@ -73,27 +73,27 @@ function useSpringCarousel({ items, init = true, withThumbs, thumbsSlideAxis = "
|
|
|
73
73
|
}
|
|
74
74
|
function getSlideValue() {
|
|
75
75
|
var _a;
|
|
76
|
-
const carouselItem = (_a = mainCarouselWrapperRef.current) === null || _a === void 0 ? void 0 : _a.querySelector(
|
|
76
|
+
const carouselItem = (_a = mainCarouselWrapperRef.current) === null || _a === void 0 ? void 0 : _a.querySelector('.use-spring-carousel-item');
|
|
77
77
|
if (!carouselItem) {
|
|
78
|
-
throw Error(
|
|
78
|
+
throw Error('No carousel items available!');
|
|
79
79
|
}
|
|
80
|
-
return (carouselItem.getBoundingClientRect()[carouselSlideAxis ===
|
|
80
|
+
return (carouselItem.getBoundingClientRect()[carouselSlideAxis === 'x' ? 'width' : 'height'] + gutter);
|
|
81
81
|
}
|
|
82
82
|
function slideToItem({ from, to, nextActiveItem, immediate = false, slideMode, }) {
|
|
83
83
|
slideModeType.current = slideMode;
|
|
84
|
-
if (typeof nextActiveItem ===
|
|
84
|
+
if (typeof nextActiveItem === 'number') {
|
|
85
85
|
if (!freeScroll) {
|
|
86
86
|
activeItem.current = nextActiveItem;
|
|
87
87
|
}
|
|
88
88
|
emitEvent({
|
|
89
|
-
eventName:
|
|
89
|
+
eventName: 'onSlideStartChange',
|
|
90
90
|
slideActionType: slideActionType.current,
|
|
91
91
|
slideMode: slideModeType.current,
|
|
92
92
|
nextItem: {
|
|
93
93
|
startReached: firstItemReached.current,
|
|
94
94
|
endReached: lastItemReached.current,
|
|
95
95
|
index: freeScroll ? -1 : activeItem.current,
|
|
96
|
-
id: freeScroll ?
|
|
96
|
+
id: freeScroll ? '' : items[activeItem.current].id,
|
|
97
97
|
},
|
|
98
98
|
});
|
|
99
99
|
}
|
|
@@ -110,14 +110,14 @@ function useSpringCarousel({ items, init = true, withThumbs, thumbsSlideAxis = "
|
|
|
110
110
|
onRest(value) {
|
|
111
111
|
if (!immediate && value.finished) {
|
|
112
112
|
emitEvent({
|
|
113
|
-
eventName:
|
|
113
|
+
eventName: 'onSlideChange',
|
|
114
114
|
slideActionType: slideActionType.current,
|
|
115
115
|
slideMode: slideModeType.current,
|
|
116
116
|
currentItem: {
|
|
117
117
|
startReached: firstItemReached.current,
|
|
118
118
|
endReached: lastItemReached.current,
|
|
119
119
|
index: freeScroll ? -1 : activeItem.current,
|
|
120
|
-
id: freeScroll ?
|
|
120
|
+
id: freeScroll ? '' : items[activeItem.current].id,
|
|
121
121
|
},
|
|
122
122
|
});
|
|
123
123
|
}
|
|
@@ -132,38 +132,38 @@ function useSpringCarousel({ items, init = true, withThumbs, thumbsSlideAxis = "
|
|
|
132
132
|
if (withLoop) {
|
|
133
133
|
return getSlideValue() * items.length;
|
|
134
134
|
}
|
|
135
|
-
return Math.round(Number((_a = carouselTrackWrapperRef.current) === null || _a === void 0 ? void 0 : _a[carouselSlideAxis ===
|
|
136
|
-
carouselTrackWrapperRef.current.getBoundingClientRect()[carouselSlideAxis ===
|
|
135
|
+
return Math.round(Number((_a = carouselTrackWrapperRef.current) === null || _a === void 0 ? void 0 : _a[carouselSlideAxis === 'x' ? 'scrollWidth' : 'scrollHeight']) -
|
|
136
|
+
carouselTrackWrapperRef.current.getBoundingClientRect()[carouselSlideAxis === 'x' ? 'width' : 'height']);
|
|
137
137
|
}
|
|
138
138
|
function getAnimatedWrapperStyles() {
|
|
139
139
|
const percentValue = `calc(100% - ${startEndGutter * 2}px)`;
|
|
140
140
|
return {
|
|
141
|
-
width: carouselSlideAxis ===
|
|
142
|
-
height: carouselSlideAxis ===
|
|
141
|
+
width: carouselSlideAxis === 'x' ? percentValue : '100%',
|
|
142
|
+
height: carouselSlideAxis === 'y' ? percentValue : '100%',
|
|
143
143
|
};
|
|
144
144
|
}
|
|
145
145
|
function getCarouselItemWidth() {
|
|
146
146
|
var _a;
|
|
147
|
-
const carouselItem = (_a = carouselTrackWrapperRef.current) === null || _a === void 0 ? void 0 : _a.querySelector(
|
|
147
|
+
const carouselItem = (_a = carouselTrackWrapperRef.current) === null || _a === void 0 ? void 0 : _a.querySelector('.use-spring-carousel-item');
|
|
148
148
|
if (!carouselItem) {
|
|
149
|
-
throw Error(
|
|
149
|
+
throw Error('No carousel items available!');
|
|
150
150
|
}
|
|
151
|
-
return (carouselItem.getBoundingClientRect()[carouselSlideAxis ===
|
|
151
|
+
return (carouselItem.getBoundingClientRect()[carouselSlideAxis === 'x' ? 'width' : 'height'] + gutter);
|
|
152
152
|
}
|
|
153
153
|
function adjustCarouselWrapperPosition() {
|
|
154
|
-
const positionProperty = carouselSlideAxis ===
|
|
154
|
+
const positionProperty = carouselSlideAxis === 'x' ? 'left' : 'top';
|
|
155
155
|
function setPosition(v) {
|
|
156
156
|
const ref = carouselTrackWrapperRef.current;
|
|
157
157
|
if (!ref)
|
|
158
158
|
return;
|
|
159
159
|
if (withLoop) {
|
|
160
|
-
ref.style.top =
|
|
161
|
-
ref.style.left =
|
|
160
|
+
ref.style.top = '0px';
|
|
161
|
+
ref.style.left = '0px';
|
|
162
162
|
ref.style[positionProperty] = `-${v - startEndGutter}px`;
|
|
163
163
|
}
|
|
164
164
|
else {
|
|
165
|
-
ref.style.left =
|
|
166
|
-
ref.style.top =
|
|
165
|
+
ref.style.left = '0px';
|
|
166
|
+
ref.style.top = '0px';
|
|
167
167
|
}
|
|
168
168
|
}
|
|
169
169
|
const currentFromValue = Math.abs(getFromValue());
|
|
@@ -180,18 +180,18 @@ function useSpringCarousel({ items, init = true, withThumbs, thumbsSlideAxis = "
|
|
|
180
180
|
});
|
|
181
181
|
return;
|
|
182
182
|
}
|
|
183
|
-
if (initialStartingPosition ===
|
|
183
|
+
if (initialStartingPosition === 'center') {
|
|
184
184
|
setPosition(getCarouselItemWidth() * items.length -
|
|
185
185
|
getSlideValue() * Math.round((itemsPerSlide - 1) / 2));
|
|
186
186
|
}
|
|
187
|
-
else if (initialStartingPosition ===
|
|
187
|
+
else if (initialStartingPosition === 'end') {
|
|
188
188
|
setPosition(getCarouselItemWidth() * items.length -
|
|
189
189
|
getSlideValue() * Math.round(itemsPerSlide - 1));
|
|
190
190
|
}
|
|
191
191
|
else {
|
|
192
192
|
setPosition(getCarouselItemWidth() * items.length);
|
|
193
193
|
}
|
|
194
|
-
if (!freeScroll && slideType ===
|
|
194
|
+
if (!freeScroll && slideType === 'fixed') {
|
|
195
195
|
const val = -(getSlideValue() * activeItem.current);
|
|
196
196
|
prevSlidedValue.current = val;
|
|
197
197
|
setSpring.start({
|
|
@@ -202,26 +202,26 @@ function useSpringCarousel({ items, init = true, withThumbs, thumbsSlideAxis = "
|
|
|
202
202
|
}
|
|
203
203
|
function getFromValue() {
|
|
204
204
|
if (freeScroll && mainCarouselWrapperRef.current) {
|
|
205
|
-
return mainCarouselWrapperRef.current[carouselSlideAxis ===
|
|
205
|
+
return mainCarouselWrapperRef.current[carouselSlideAxis === 'x' ? 'scrollLeft' : 'scrollTop'];
|
|
206
206
|
}
|
|
207
207
|
return spring.val.get();
|
|
208
208
|
}
|
|
209
209
|
function getToValue(type, index) {
|
|
210
|
-
if (freeScroll && type ===
|
|
210
|
+
if (freeScroll && type === 'next') {
|
|
211
211
|
const next = prevSlidedValue.current + getSlideValue();
|
|
212
212
|
if (next > getTotalScrollValue()) {
|
|
213
213
|
return getTotalScrollValue();
|
|
214
214
|
}
|
|
215
215
|
return next;
|
|
216
216
|
}
|
|
217
|
-
if (freeScroll && type ===
|
|
217
|
+
if (freeScroll && type === 'prev') {
|
|
218
218
|
const next = prevSlidedValue.current - getSlideValue();
|
|
219
219
|
if (next < 0) {
|
|
220
220
|
return 0;
|
|
221
221
|
}
|
|
222
222
|
return next;
|
|
223
223
|
}
|
|
224
|
-
if (type ===
|
|
224
|
+
if (type === 'next') {
|
|
225
225
|
if (index) {
|
|
226
226
|
return -(index * getSlideValue());
|
|
227
227
|
}
|
|
@@ -232,14 +232,14 @@ function useSpringCarousel({ items, init = true, withThumbs, thumbsSlideAxis = "
|
|
|
232
232
|
}
|
|
233
233
|
return prevSlidedValue.current + getSlideValue();
|
|
234
234
|
}
|
|
235
|
-
function slideToPrevItem(type =
|
|
235
|
+
function slideToPrevItem(type = 'click', index) {
|
|
236
236
|
if (!init || (firstItemReached.current && !withLoop))
|
|
237
237
|
return;
|
|
238
|
-
slideActionType.current =
|
|
238
|
+
slideActionType.current = 'prev';
|
|
239
239
|
lastItemReached.current = false;
|
|
240
240
|
const nextItem = index || activeItem.current - 1;
|
|
241
241
|
if (!withLoop) {
|
|
242
|
-
const nextItemWillExceed = getToValue(
|
|
242
|
+
const nextItemWillExceed = getToValue('prev', index) + getSlideValue() / 3 > 0;
|
|
243
243
|
if (firstItemReached.current)
|
|
244
244
|
return;
|
|
245
245
|
if (nextItemWillExceed) {
|
|
@@ -274,19 +274,18 @@ function useSpringCarousel({ items, init = true, withThumbs, thumbsSlideAxis = "
|
|
|
274
274
|
slideToItem({
|
|
275
275
|
slideMode: type,
|
|
276
276
|
from: getFromValue(),
|
|
277
|
-
to: getToValue(
|
|
277
|
+
to: getToValue('prev', index),
|
|
278
278
|
nextActiveItem: nextItem,
|
|
279
279
|
});
|
|
280
280
|
}
|
|
281
|
-
function slideToNextItem(type =
|
|
281
|
+
function slideToNextItem(type = 'click', index) {
|
|
282
282
|
if (!init || (lastItemReached.current && !withLoop))
|
|
283
283
|
return;
|
|
284
|
-
slideActionType.current =
|
|
284
|
+
slideActionType.current = 'next';
|
|
285
285
|
firstItemReached.current = false;
|
|
286
286
|
const nextItem = index || activeItem.current + 1;
|
|
287
287
|
if (!withLoop) {
|
|
288
|
-
const nextItemWillExceed = Math.abs(getToValue(
|
|
289
|
-
getTotalScrollValue() - getSlideValue() / 3;
|
|
288
|
+
const nextItemWillExceed = Math.abs(getToValue('next', index)) > getTotalScrollValue() - getSlideValue() / 3;
|
|
290
289
|
if (lastItemReached.current)
|
|
291
290
|
return;
|
|
292
291
|
if (nextItemWillExceed) {
|
|
@@ -321,7 +320,7 @@ function useSpringCarousel({ items, init = true, withThumbs, thumbsSlideAxis = "
|
|
|
321
320
|
slideToItem({
|
|
322
321
|
slideMode: type,
|
|
323
322
|
from: getFromValue(),
|
|
324
|
-
to: getToValue(
|
|
323
|
+
to: getToValue('next', index),
|
|
325
324
|
nextActiveItem: nextItem,
|
|
326
325
|
});
|
|
327
326
|
}
|
|
@@ -363,28 +362,28 @@ function useSpringCarousel({ items, init = true, withThumbs, thumbsSlideAxis = "
|
|
|
363
362
|
prevWindowWidth.current = window.innerWidth;
|
|
364
363
|
adjustCarouselWrapperPosition();
|
|
365
364
|
}
|
|
366
|
-
window.addEventListener(
|
|
365
|
+
window.addEventListener('resize', handleResize);
|
|
367
366
|
return () => {
|
|
368
|
-
window.removeEventListener(
|
|
367
|
+
window.removeEventListener('resize', handleResize);
|
|
369
368
|
};
|
|
370
369
|
}, []);
|
|
371
|
-
const bindDrag = useDrag(
|
|
370
|
+
const bindDrag = useDrag(state => {
|
|
372
371
|
const isDragging = state.dragging;
|
|
373
|
-
const movement = state.offset[carouselSlideAxis ===
|
|
374
|
-
const currentMovement = state.movement[carouselSlideAxis ===
|
|
375
|
-
const direction = state.direction[carouselSlideAxis ===
|
|
372
|
+
const movement = state.offset[carouselSlideAxis === 'x' ? 0 : 1];
|
|
373
|
+
const currentMovement = state.movement[carouselSlideAxis === 'x' ? 0 : 1];
|
|
374
|
+
const direction = state.direction[carouselSlideAxis === 'x' ? 0 : 1];
|
|
376
375
|
const prevItemTreshold = currentMovement > draggingSlideTreshold.current;
|
|
377
376
|
const nextItemTreshold = currentMovement < -draggingSlideTreshold.current;
|
|
378
377
|
if (isDragging) {
|
|
379
378
|
if (direction > 0) {
|
|
380
|
-
slideActionType.current =
|
|
379
|
+
slideActionType.current = 'prev';
|
|
381
380
|
}
|
|
382
381
|
else {
|
|
383
|
-
slideActionType.current =
|
|
382
|
+
slideActionType.current = 'next';
|
|
384
383
|
}
|
|
385
|
-
emitEvent(Object.assign(Object.assign({}, state), { eventName:
|
|
384
|
+
emitEvent(Object.assign(Object.assign({}, state), { eventName: 'onDrag', slideActionType: slideActionType.current }));
|
|
386
385
|
if (freeScroll) {
|
|
387
|
-
if (slideActionType.current ===
|
|
386
|
+
if (slideActionType.current === 'prev' && movement > 0) {
|
|
388
387
|
state.cancel();
|
|
389
388
|
setSpring.start({
|
|
390
389
|
from: {
|
|
@@ -425,21 +424,21 @@ function useSpringCarousel({ items, init = true, withThumbs, thumbsSlideAxis = "
|
|
|
425
424
|
},
|
|
426
425
|
});
|
|
427
426
|
if (slideWhenThresholdIsReached && nextItemTreshold) {
|
|
428
|
-
slideToNextItem(
|
|
427
|
+
slideToNextItem('drag');
|
|
429
428
|
state.cancel();
|
|
430
429
|
}
|
|
431
430
|
else if (slideWhenThresholdIsReached && prevItemTreshold) {
|
|
432
|
-
slideToPrevItem(
|
|
431
|
+
slideToPrevItem('drag');
|
|
433
432
|
state.cancel();
|
|
434
433
|
}
|
|
435
434
|
return;
|
|
436
435
|
}
|
|
437
436
|
if (state.last && !state.canceled && freeScroll) {
|
|
438
|
-
if (slideActionType.current ===
|
|
439
|
-
slideToPrevItem(
|
|
437
|
+
if (slideActionType.current === 'prev') {
|
|
438
|
+
slideToPrevItem('drag');
|
|
440
439
|
}
|
|
441
|
-
if (slideActionType.current ===
|
|
442
|
-
slideToNextItem(
|
|
440
|
+
if (slideActionType.current === 'next') {
|
|
441
|
+
slideToNextItem('drag');
|
|
443
442
|
}
|
|
444
443
|
}
|
|
445
444
|
if (state.last && !state.canceled && !freeScroll) {
|
|
@@ -451,7 +450,7 @@ function useSpringCarousel({ items, init = true, withThumbs, thumbsSlideAxis = "
|
|
|
451
450
|
});
|
|
452
451
|
}
|
|
453
452
|
else {
|
|
454
|
-
slideToNextItem(
|
|
453
|
+
slideToNextItem('drag');
|
|
455
454
|
}
|
|
456
455
|
}
|
|
457
456
|
else if (prevItemTreshold) {
|
|
@@ -462,7 +461,7 @@ function useSpringCarousel({ items, init = true, withThumbs, thumbsSlideAxis = "
|
|
|
462
461
|
});
|
|
463
462
|
}
|
|
464
463
|
else {
|
|
465
|
-
slideToPrevItem(
|
|
464
|
+
slideToPrevItem('drag');
|
|
466
465
|
}
|
|
467
466
|
}
|
|
468
467
|
else {
|
|
@@ -483,7 +482,7 @@ function useSpringCarousel({ items, init = true, withThumbs, thumbsSlideAxis = "
|
|
|
483
482
|
-mainCarouselWrapperRef.current.scrollTop,
|
|
484
483
|
];
|
|
485
484
|
}
|
|
486
|
-
if (carouselSlideAxis ===
|
|
485
|
+
if (carouselSlideAxis === 'x') {
|
|
487
486
|
return [spring.val.get(), spring.val.get()];
|
|
488
487
|
}
|
|
489
488
|
return [spring.val.get(), spring.val.get()];
|
|
@@ -491,13 +490,13 @@ function useSpringCarousel({ items, init = true, withThumbs, thumbsSlideAxis = "
|
|
|
491
490
|
});
|
|
492
491
|
function getWrapperOverflowStyles() {
|
|
493
492
|
if (freeScroll) {
|
|
494
|
-
if (carouselSlideAxis ===
|
|
493
|
+
if (carouselSlideAxis === 'x') {
|
|
495
494
|
return {
|
|
496
|
-
overflowX:
|
|
495
|
+
overflowX: 'auto',
|
|
497
496
|
};
|
|
498
497
|
}
|
|
499
498
|
return {
|
|
500
|
-
overflowY:
|
|
499
|
+
overflowY: 'auto',
|
|
501
500
|
};
|
|
502
501
|
}
|
|
503
502
|
return {};
|
|
@@ -505,17 +504,17 @@ function useSpringCarousel({ items, init = true, withThumbs, thumbsSlideAxis = "
|
|
|
505
504
|
function setStartEndItemReachedOnFreeScroll() {
|
|
506
505
|
if (mainCarouselWrapperRef.current) {
|
|
507
506
|
prevSlidedValue.current =
|
|
508
|
-
mainCarouselWrapperRef.current[carouselSlideAxis ===
|
|
509
|
-
if (mainCarouselWrapperRef.current[carouselSlideAxis ===
|
|
507
|
+
mainCarouselWrapperRef.current[carouselSlideAxis === 'x' ? 'scrollLeft' : 'scrollTop'];
|
|
508
|
+
if (mainCarouselWrapperRef.current[carouselSlideAxis === 'x' ? 'scrollLeft' : 'scrollTop'] === 0) {
|
|
510
509
|
firstItemReached.current = true;
|
|
511
510
|
lastItemReached.current = false;
|
|
512
511
|
}
|
|
513
|
-
if (mainCarouselWrapperRef.current[carouselSlideAxis ===
|
|
514
|
-
mainCarouselWrapperRef.current[carouselSlideAxis ===
|
|
512
|
+
if (mainCarouselWrapperRef.current[carouselSlideAxis === 'x' ? 'scrollLeft' : 'scrollTop'] > 0 &&
|
|
513
|
+
mainCarouselWrapperRef.current[carouselSlideAxis === 'x' ? 'scrollLeft' : 'scrollTop'] < getTotalScrollValue()) {
|
|
515
514
|
firstItemReached.current = false;
|
|
516
515
|
lastItemReached.current = false;
|
|
517
516
|
}
|
|
518
|
-
if (mainCarouselWrapperRef.current[carouselSlideAxis ===
|
|
517
|
+
if (mainCarouselWrapperRef.current[carouselSlideAxis === 'x' ? 'scrollLeft' : 'scrollTop'] === getTotalScrollValue()) {
|
|
519
518
|
firstItemReached.current = false;
|
|
520
519
|
lastItemReached.current = true;
|
|
521
520
|
}
|
|
@@ -533,12 +532,12 @@ function useSpringCarousel({ items, init = true, withThumbs, thumbsSlideAxis = "
|
|
|
533
532
|
return {};
|
|
534
533
|
}
|
|
535
534
|
function findItemIndex(id) {
|
|
536
|
-
return items.findIndex(
|
|
535
|
+
return items.findIndex(item => item.id === id);
|
|
537
536
|
}
|
|
538
537
|
function findItemIndexById(id, error) {
|
|
539
538
|
let itemIndex = 0;
|
|
540
|
-
if (typeof id ===
|
|
541
|
-
itemIndex = items.findIndex(
|
|
539
|
+
if (typeof id === 'string') {
|
|
540
|
+
itemIndex = items.findIndex(_item => _item.id === id);
|
|
542
541
|
}
|
|
543
542
|
else {
|
|
544
543
|
itemIndex = id;
|
|
@@ -560,10 +559,10 @@ function useSpringCarousel({ items, init = true, withThumbs, thumbsSlideAxis = "
|
|
|
560
559
|
const currentItem = findItemIndex(items[activeItem.current].id);
|
|
561
560
|
const newActiveItem = findItemIndex(items[itemIndex].id);
|
|
562
561
|
if (newActiveItem > currentItem) {
|
|
563
|
-
slideToNextItem(
|
|
562
|
+
slideToNextItem('click', newActiveItem);
|
|
564
563
|
}
|
|
565
564
|
else {
|
|
566
|
-
slideToPrevItem(
|
|
565
|
+
slideToPrevItem('click', newActiveItem);
|
|
567
566
|
}
|
|
568
567
|
}
|
|
569
568
|
function getIsNextItem(id) {
|
|
@@ -582,8 +581,8 @@ function useSpringCarousel({ items, init = true, withThumbs, thumbsSlideAxis = "
|
|
|
582
581
|
}
|
|
583
582
|
return itemIndex === _activeItem - 1;
|
|
584
583
|
}
|
|
585
|
-
const carouselFragment = (jsx("div", Object.assign({ ref: mainCarouselWrapperRef }, getScrollHandlers(), { style: Object.assign({ display:
|
|
586
|
-
return (jsx("div", Object.assign({ className: "use-spring-carousel-item", "data-testid": "use-spring-carousel-item-wrapper", style: Object.assign({ display:
|
|
584
|
+
const carouselFragment = (jsx("div", Object.assign({ ref: mainCarouselWrapperRef }, getScrollHandlers(), { style: Object.assign({ display: 'flex', position: 'relative', width: '100%', height: '100%' }, getWrapperOverflowStyles()) }, { children: jsx("div", Object.assign({ ref: carouselTrackWrapperRef }, bindDrag(), { style: Object.assign({ position: 'relative', display: 'flex', flexDirection: carouselSlideAxis === 'x' ? 'row' : 'column', touchAction: 'none' }, getAnimatedWrapperStyles()) }, { children: internalItems.map((item, index) => {
|
|
585
|
+
return (jsx("div", Object.assign({ className: "use-spring-carousel-item", "data-testid": "use-spring-carousel-item-wrapper", style: Object.assign({ display: 'flex', position: 'relative', flex: '1' }, getItemStyles()) }, { children: item.renderItem }), `${item.id}-${index}`));
|
|
587
586
|
}) })) })));
|
|
588
587
|
return {
|
|
589
588
|
useListenToCustomEvent,
|
|
@@ -607,7 +606,7 @@ const Context = createContext(undefined);
|
|
|
607
606
|
function useSpringCarouselContext() {
|
|
608
607
|
const context = useContext(Context);
|
|
609
608
|
if (!context) {
|
|
610
|
-
throw new Error(
|
|
609
|
+
throw new Error('useSpringCarouselContext must be used within the carousel.');
|
|
611
610
|
}
|
|
612
611
|
return context;
|
|
613
612
|
}
|