@gem-sdk/components 2.0.0-dev.739 → 2.0.0-dev.741
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/builder.js +2 -2
- package/dist/cjs/carousel/components/item/CarouselItem.js +1 -2
- package/dist/cjs/carousel/components/root/Carousel.liquid.js +3 -3
- package/dist/cjs/carousel/components/root/common/classes.js +2 -2
- package/dist/cjs/carousel/components/root/common/styles.js +0 -2
- package/dist/cjs/carousel/index.js +3 -3
- package/dist/cjs/hero-banner/settings/configs/settings.js +1 -1
- package/dist/cjs/index.js +2 -2
- package/dist/cjs/product/components/product-images/ProductGalleryCarousel.js +2 -2
- package/dist/cjs/product/components/product-images/ProductImagesLightBox.js +2 -2
- package/dist/cjs/product/components/product-images-v2/ProductImagesV2.liquid.js +3 -3
- package/dist/cjs/product/components/product-images-v2/components/child/ProductFeaturedImageCarousel.js +2 -2
- package/dist/cjs/product/components/product-images-v2/components/gallery-carousel/GalleryCarousel.js +2 -2
- package/dist/cjs/product/components/product-images-v2/components/lightbox/ProductImagesLightBox.js +2 -2
- package/dist/cjs/product/components/product-list/ProductListCarouselLayout.js +2 -2
- package/dist/cjs/product/index.js +1 -1
- package/dist/esm/builder.js +2 -2
- package/dist/esm/carousel/components/item/CarouselItem.js +1 -2
- package/dist/esm/carousel/components/root/Carousel.liquid.js +3 -3
- package/dist/esm/carousel/components/root/common/classes.js +2 -2
- package/dist/esm/carousel/components/root/common/styles.js +0 -2
- package/dist/esm/carousel/index.js +1 -1
- package/dist/esm/hero-banner/settings/configs/settings.js +1 -1
- package/dist/esm/index.js +1 -1
- package/dist/esm/product/components/product-images/ProductGalleryCarousel.js +2 -2
- package/dist/esm/product/components/product-images/ProductImagesLightBox.js +2 -2
- package/dist/esm/product/components/product-images-v2/ProductImagesV2.liquid.js +3 -3
- package/dist/esm/product/components/product-images-v2/components/child/ProductFeaturedImageCarousel.js +2 -2
- package/dist/esm/product/components/product-images-v2/components/gallery-carousel/GalleryCarousel.js +2 -2
- package/dist/esm/product/components/product-images-v2/components/lightbox/ProductImagesLightBox.js +2 -2
- package/dist/esm/product/components/product-list/ProductListCarouselLayout.js +2 -2
- package/dist/esm/product/index.js +1 -1
- package/dist/types/index.d.ts +2 -2
- package/package.json +1 -1
- package/dist/cjs/carousel/components/root/CarouselWithSwiper.js +0 -131
- package/dist/cjs/carousel/components/root/CustomSwiper.js +0 -59
- package/dist/cjs/carousel/hooks/useCarouselWithSwiper.js +0 -343
- package/dist/esm/carousel/components/root/CarouselWithSwiper.js +0 -127
- package/dist/esm/carousel/components/root/CustomSwiper.js +0 -56
- package/dist/esm/carousel/hooks/useCarouselWithSwiper.js +0 -341
|
@@ -1,127 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
3
|
-
import { useCurrentDevice, isEmptyChildren, filterToolbarPreview } from '@gem-sdk/core';
|
|
4
|
-
import { forwardRef, useState, useCallback, Children, isValidElement } from 'react';
|
|
5
|
-
import { mappingNavigationCarousel } from '../arrow/common/helpers.js';
|
|
6
|
-
import { useCarouselWithSwiper } from '../../hooks/useCarouselWithSwiper.js';
|
|
7
|
-
import { getData } from './common/helpers.js';
|
|
8
|
-
import { getClass } from './common/classes.js';
|
|
9
|
-
import { getStyle } from './common/styles.js';
|
|
10
|
-
import { getAttr } from './common/attrs.js';
|
|
11
|
-
import Arrow from '../arrow/Arrow.js';
|
|
12
|
-
import Dots from '../dot/Dots.js';
|
|
13
|
-
import { Swiper } from './CustomSwiper.js';
|
|
14
|
-
|
|
15
|
-
const CarouselWithSwiper = /*#__PURE__*/ forwardRef((props, ref)=>{
|
|
16
|
-
const { children, builderAttrs, builderProps, styles, isHiddenArrowWhenDisabled = true, hiddenDotWhenOnlyOne, elmRef } = props;
|
|
17
|
-
const setting = mappingNavigationCarousel(props.setting);
|
|
18
|
-
const renderData = {
|
|
19
|
-
...props,
|
|
20
|
-
setting
|
|
21
|
-
};
|
|
22
|
-
const [swiperInstance, setSwiperInstance] = useState(null);
|
|
23
|
-
const { arrowButtonSize, arrowBackgroundColor, arrowGapToEachSide = '16', roundedArrow, arrowIconSize, arrowCustomColor, arrowBorder, arrowShadow, showWhenHover } = setting ?? {};
|
|
24
|
-
const { isInfinity, localRef, sliderSettings, totalSlideItem, currentSlide, isRenderDots, showNavigation, handleDotClick, getItemsPerPage, handleNextAndPrevSlide, dispatchEventSelectSlide, getNumberOfFullWidthShow } = useCarouselWithSwiper(renderData, ref, swiperInstance);
|
|
25
|
-
const { loopConfig, arrowShowConfig } = getData(renderData);
|
|
26
|
-
const { rootClassRender, wrapperClassRender, wrapperInnerClass, sliderClass } = getClass(renderData);
|
|
27
|
-
const { rootStyleRender, wrapperStyleRender, wrapperInnerStyle } = getStyle(renderData);
|
|
28
|
-
const { rootAttrRender, sliderAttr } = getAttr(renderData);
|
|
29
|
-
const currentDevice = useCurrentDevice();
|
|
30
|
-
const enabledSneakPeak = setting?.sneakPeak?.[currentDevice];
|
|
31
|
-
const renderArrow = (position)=>{
|
|
32
|
-
const isNext = position === 'next';
|
|
33
|
-
const slidesPerView = getItemsPerPage();
|
|
34
|
-
const isDisable = isNext ? !isInfinity && currentSlide >= totalSlideItem - Math.floor(slidesPerView) : !isInfinity && currentSlide === 0;
|
|
35
|
-
return /*#__PURE__*/ jsx(Arrow, {
|
|
36
|
-
uid: builderProps?.uid,
|
|
37
|
-
custom: setting?.arrowCustom ?? '',
|
|
38
|
-
showArrow: arrowShowConfig,
|
|
39
|
-
arrowButtonSize: arrowButtonSize || {},
|
|
40
|
-
arrowIconSize: arrowIconSize || {},
|
|
41
|
-
arrowBackgroundColor: arrowBackgroundColor || '',
|
|
42
|
-
arrowCustomColor: arrowCustomColor,
|
|
43
|
-
gapToEachSize: arrowGapToEachSide,
|
|
44
|
-
showWhenHover: showWhenHover,
|
|
45
|
-
arrowBorder: arrowBorder || {},
|
|
46
|
-
arrowCorner: roundedArrow || {},
|
|
47
|
-
arrowShadow: arrowShadow || {},
|
|
48
|
-
onClick: (e)=>{
|
|
49
|
-
e.stopPropagation();
|
|
50
|
-
handleNextAndPrevSlide(position);
|
|
51
|
-
},
|
|
52
|
-
left: !isNext,
|
|
53
|
-
disabled: isDisable,
|
|
54
|
-
vertical: setting?.vertical,
|
|
55
|
-
isHiddenWhenDisabled: isHiddenArrowWhenDisabled,
|
|
56
|
-
rootId: props?.parentClass
|
|
57
|
-
});
|
|
58
|
-
};
|
|
59
|
-
const handleSliderReady = useCallback((swiper)=>{
|
|
60
|
-
setSwiperInstance(swiper);
|
|
61
|
-
}, []);
|
|
62
|
-
return /*#__PURE__*/ jsx("div", {
|
|
63
|
-
ref: elmRef,
|
|
64
|
-
...rootAttrRender,
|
|
65
|
-
className: rootClassRender,
|
|
66
|
-
style: rootStyleRender,
|
|
67
|
-
children: /*#__PURE__*/ jsxs("div", {
|
|
68
|
-
ref: localRef,
|
|
69
|
-
...builderAttrs,
|
|
70
|
-
className: wrapperClassRender,
|
|
71
|
-
style: wrapperStyleRender,
|
|
72
|
-
children: [
|
|
73
|
-
/*#__PURE__*/ jsxs("div", {
|
|
74
|
-
className: wrapperInnerClass,
|
|
75
|
-
style: wrapperInnerStyle,
|
|
76
|
-
children: [
|
|
77
|
-
showNavigation && renderArrow('prev'),
|
|
78
|
-
/*#__PURE__*/ jsx(Swiper, {
|
|
79
|
-
...sliderAttr,
|
|
80
|
-
...sliderSettings,
|
|
81
|
-
sliderClass: sliderClass,
|
|
82
|
-
onSwiperReady: handleSliderReady,
|
|
83
|
-
totalSlides: totalSlideItem,
|
|
84
|
-
children: isEmptyChildren(children) ? /*#__PURE__*/ jsx("div", {
|
|
85
|
-
children: "No Slider"
|
|
86
|
-
}) : Children.map(filterToolbarPreview(children), (child)=>{
|
|
87
|
-
if (/*#__PURE__*/ isValidElement(child)) {
|
|
88
|
-
return /*#__PURE__*/ jsx(child.type, {
|
|
89
|
-
...child.props,
|
|
90
|
-
parentSettings: setting,
|
|
91
|
-
parentStyle: styles,
|
|
92
|
-
background: setting?.background,
|
|
93
|
-
parentUid: builderProps?.uid,
|
|
94
|
-
dispatchEventSelectSlide: dispatchEventSelectSlide
|
|
95
|
-
});
|
|
96
|
-
}
|
|
97
|
-
return null;
|
|
98
|
-
})
|
|
99
|
-
}),
|
|
100
|
-
showNavigation && renderArrow('next')
|
|
101
|
-
]
|
|
102
|
-
}),
|
|
103
|
-
isRenderDots && /*#__PURE__*/ jsx(Dots, {
|
|
104
|
-
dotStyle: setting?.dotStyle,
|
|
105
|
-
dotGapToCarousel: setting?.dotGapToCarousel,
|
|
106
|
-
vertical: setting?.vertical,
|
|
107
|
-
showDots: setting?.dot,
|
|
108
|
-
slideItemsPerPage: getItemsPerPage(),
|
|
109
|
-
enabledSneakPeak: enabledSneakPeak,
|
|
110
|
-
dotColor: setting?.dotColor,
|
|
111
|
-
dotActiveColor: setting?.dotActiveColor,
|
|
112
|
-
dotSize: setting?.dotSize,
|
|
113
|
-
sneakPeakType: setting?.sneakPeakType,
|
|
114
|
-
totalSlideItem: totalSlideItem,
|
|
115
|
-
hiddenWhenOnlyOne: hiddenDotWhenOnlyOne,
|
|
116
|
-
currentSlide: currentSlide,
|
|
117
|
-
loop: loopConfig,
|
|
118
|
-
numberOfFullWidthShow: getNumberOfFullWidthShow(currentDevice),
|
|
119
|
-
onHandleClick: handleDotClick
|
|
120
|
-
}),
|
|
121
|
-
filterToolbarPreview(children, true)
|
|
122
|
-
]
|
|
123
|
-
})
|
|
124
|
-
});
|
|
125
|
-
});
|
|
126
|
-
|
|
127
|
-
export { CarouselWithSwiper as default };
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
import { jsx } from 'react/jsx-runtime';
|
|
2
|
-
import { useRef, useEffect } from 'react';
|
|
3
|
-
import { register } from 'swiper/element/bundle';
|
|
4
|
-
|
|
5
|
-
function Swiper(props) {
|
|
6
|
-
const swiperRef = useRef(null);
|
|
7
|
-
const { children, totalSlides, onSwiperReady, sliderClass, ...sliderSetting } = props;
|
|
8
|
-
const pauseOnMouseEnter = typeof props.autoplay === 'object' && props.autoplay !== null ? props.autoplay.pauseOnMouseEnter : undefined;
|
|
9
|
-
useEffect(()=>{
|
|
10
|
-
register();
|
|
11
|
-
Object.assign(swiperRef.current, sliderSetting);
|
|
12
|
-
swiperRef.current.initialize();
|
|
13
|
-
const instance = swiperRef.current.swiper;
|
|
14
|
-
onSwiperReady?.(instance);
|
|
15
|
-
}, []);
|
|
16
|
-
useEffect(()=>{
|
|
17
|
-
if (swiperRef.current?.swiper) {
|
|
18
|
-
const swiperInstance = swiperRef.current.swiper;
|
|
19
|
-
swiperInstance.destroy(true, true);
|
|
20
|
-
Object.assign(swiperRef.current, sliderSetting);
|
|
21
|
-
swiperRef.current.initialize();
|
|
22
|
-
onSwiperReady?.(swiperRef.current.swiper);
|
|
23
|
-
}
|
|
24
|
-
}, [
|
|
25
|
-
sliderSetting.dir,
|
|
26
|
-
sliderSetting.loop,
|
|
27
|
-
pauseOnMouseEnter,
|
|
28
|
-
sliderSetting.slidesPerView,
|
|
29
|
-
onSwiperReady,
|
|
30
|
-
totalSlides
|
|
31
|
-
]);
|
|
32
|
-
useEffect(()=>{
|
|
33
|
-
const swiperInstance = swiperRef.current?.swiper;
|
|
34
|
-
if (!swiperInstance) return;
|
|
35
|
-
Object.assign(swiperInstance.params, sliderSetting);
|
|
36
|
-
swiperInstance.update();
|
|
37
|
-
}, [
|
|
38
|
-
sliderSetting
|
|
39
|
-
]);
|
|
40
|
-
return /*#__PURE__*/ jsx("swiper-container", {
|
|
41
|
-
init: false,
|
|
42
|
-
className: sliderClass,
|
|
43
|
-
ref: swiperRef,
|
|
44
|
-
children: children
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
function SwiperSlide(props) {
|
|
48
|
-
const { children, className, ...rest } = props;
|
|
49
|
-
return /*#__PURE__*/ jsx("swiper-slide", {
|
|
50
|
-
...rest,
|
|
51
|
-
className: className,
|
|
52
|
-
children: children
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
export { Swiper, SwiperSlide };
|
|
@@ -1,341 +0,0 @@
|
|
|
1
|
-
import { useState, useMemo, useRef, useCallback, useImperativeHandle, useEffect } from 'react';
|
|
2
|
-
import { getResponsiveValueByScreen, useCurrentDevice, useEditorMode, useInteraction, DEVICES } from '@gem-sdk/core';
|
|
3
|
-
import useTrackPreviewPause from './useTrackPreviewPause.js';
|
|
4
|
-
|
|
5
|
-
const useCarouselWithSwiper = (props, ref, swiperInstance)=>{
|
|
6
|
-
const { builderProps, moveToIdx, styles, setting, isHiddenArrowWhenDisabled = true, elmRef, onClickArrow, onHandleChangeSlideByInteraction } = props;
|
|
7
|
-
const { loop, navigationEnable = {
|
|
8
|
-
desktop: true
|
|
9
|
-
}, navigationStyle } = setting ?? {};
|
|
10
|
-
const [totalSlideItem, setTotalSlideItem] = useState(0);
|
|
11
|
-
const [currentSlide, setCurrentSlide] = useState(setting?.defaultCurrentSlider ?? 0);
|
|
12
|
-
const isInfinity = useMemo(()=>{
|
|
13
|
-
return getResponsiveValueByScreen(loop, 'desktop', false);
|
|
14
|
-
}, [
|
|
15
|
-
loop
|
|
16
|
-
]);
|
|
17
|
-
const { isFirstPreviewClicked } = useTrackPreviewPause(setting?.runPreview);
|
|
18
|
-
// const { sliderSelector } = getData(props);
|
|
19
|
-
const localRef = useRef();
|
|
20
|
-
// const isRunningAnimation = useRef(false);
|
|
21
|
-
const previousIndex = useRef(moveToIdx ?? 0);
|
|
22
|
-
const isRenderDots = useMemo(()=>!!totalSlideItem && swiperInstance && getResponsiveValueByScreen(setting?.dot), [
|
|
23
|
-
swiperInstance,
|
|
24
|
-
setting?.dot,
|
|
25
|
-
totalSlideItem
|
|
26
|
-
]);
|
|
27
|
-
let delayTimeout;
|
|
28
|
-
const currentDevice = useCurrentDevice();
|
|
29
|
-
const mode = useEditorMode();
|
|
30
|
-
const { onListener, saveToElementInteractionData, getInteractionPreviousData, trigger } = useInteraction();
|
|
31
|
-
const getItemNumberFromOldData = useCallback(()=>{
|
|
32
|
-
if (!setting?.slidesToShow) return null;
|
|
33
|
-
const result = {};
|
|
34
|
-
DEVICES.forEach((device)=>{
|
|
35
|
-
const value = getResponsiveValueByScreen(setting?.slidesToShow, device);
|
|
36
|
-
result[device] = value ? value === 'auto' ? 4 : Math.floor(value) : 0;
|
|
37
|
-
});
|
|
38
|
-
return result;
|
|
39
|
-
}, [
|
|
40
|
-
setting?.slidesToShow
|
|
41
|
-
]);
|
|
42
|
-
const getSlideToShowFromOldData = useCallback(()=>{
|
|
43
|
-
if (!setting?.slidesToShow) return null;
|
|
44
|
-
const result = {};
|
|
45
|
-
DEVICES.forEach((device)=>{
|
|
46
|
-
const value = getResponsiveValueByScreen(setting?.slidesToShow, device);
|
|
47
|
-
result[device] = value ? value === 'auto' ? 4 : value : 0;
|
|
48
|
-
});
|
|
49
|
-
return result;
|
|
50
|
-
}, [
|
|
51
|
-
setting?.slidesToShow
|
|
52
|
-
]);
|
|
53
|
-
const showNavigation = useMemo(()=>{
|
|
54
|
-
const navigationEnableByDevice = getResponsiveValueByScreen(navigationEnable, currentDevice);
|
|
55
|
-
const navigationStyleByDevice = getResponsiveValueByScreen(navigationStyle, currentDevice);
|
|
56
|
-
return swiperInstance && navigationEnableByDevice && navigationStyleByDevice !== 'none';
|
|
57
|
-
}, [
|
|
58
|
-
swiperInstance,
|
|
59
|
-
navigationEnable,
|
|
60
|
-
navigationStyle,
|
|
61
|
-
currentDevice
|
|
62
|
-
]);
|
|
63
|
-
const slidesToShow = useMemo(()=>{
|
|
64
|
-
const oldData = getSlideToShowFromOldData();
|
|
65
|
-
if (oldData) {
|
|
66
|
-
return oldData;
|
|
67
|
-
}
|
|
68
|
-
const result = {};
|
|
69
|
-
DEVICES.forEach((device)=>{
|
|
70
|
-
const enableSneakPeak = getResponsiveValueByScreen(setting?.sneakPeak, device);
|
|
71
|
-
const offset = enableSneakPeak ? getResponsiveValueByScreen(setting?.sneakPeakType, device) === 'center' ? getResponsiveValueByScreen(setting?.sneakPeakOffsetCenter, device) ?? 0 : getResponsiveValueByScreen(setting?.sneakPeakOffsetForward, device) ?? 0 : 0;
|
|
72
|
-
const rx = getResponsiveValueByScreen(setting?.sneakPeakType, device) === 'center' ? -2 : -1;
|
|
73
|
-
const itemNumberByDevice = getResponsiveValueByScreen(setting?.itemNumber, device);
|
|
74
|
-
result[device] = typeof itemNumberByDevice === 'number' ? itemNumberByDevice + offset / 100 * rx : 'auto';
|
|
75
|
-
});
|
|
76
|
-
return result;
|
|
77
|
-
}, [
|
|
78
|
-
getSlideToShowFromOldData,
|
|
79
|
-
setting?.itemNumber,
|
|
80
|
-
setting?.sneakPeak,
|
|
81
|
-
setting?.sneakPeakOffsetCenter,
|
|
82
|
-
setting?.sneakPeakOffsetForward,
|
|
83
|
-
setting?.sneakPeakType
|
|
84
|
-
]);
|
|
85
|
-
const itemNumber = useMemo(()=>{
|
|
86
|
-
const oldData = getItemNumberFromOldData();
|
|
87
|
-
return oldData || setting?.itemNumber;
|
|
88
|
-
}, [
|
|
89
|
-
getItemNumberFromOldData,
|
|
90
|
-
setting?.itemNumber
|
|
91
|
-
]);
|
|
92
|
-
const getNumberOfFullWidthShow = useCallback((device)=>{
|
|
93
|
-
const sneakPeekTypeByNumber = getResponsiveValueByScreen(setting?.sneakPeakType, device) === 'center' ? 2 : 1;
|
|
94
|
-
return typeof getResponsiveValueByScreen(itemNumber, device, 4) === 'number' ? getResponsiveValueByScreen(itemNumber, device, 4) - sneakPeekTypeByNumber : undefined;
|
|
95
|
-
}, [
|
|
96
|
-
setting?.sneakPeakType,
|
|
97
|
-
itemNumber
|
|
98
|
-
]);
|
|
99
|
-
const getItemsPerPage = ()=>{
|
|
100
|
-
const items = getResponsiveValueByScreen(slidesToShow, currentDevice, 1) === 'auto' ? 1 : getResponsiveValueByScreen(slidesToShow, currentDevice, 1);
|
|
101
|
-
return items ?? 1;
|
|
102
|
-
};
|
|
103
|
-
const getIndexSlideItemBy = (pageIdx)=>{
|
|
104
|
-
let indexPage = pageIdx * getItemsPerPage();
|
|
105
|
-
if (indexPage >= totalSlideItem - getItemsPerPage()) {
|
|
106
|
-
indexPage = totalSlideItem - getItemsPerPage();
|
|
107
|
-
}
|
|
108
|
-
return indexPage;
|
|
109
|
-
};
|
|
110
|
-
const getAllowTouchMove = (screen)=>{
|
|
111
|
-
const value = mode === 'edit' ? {
|
|
112
|
-
[screen]: false
|
|
113
|
-
} : setting?.enableDrag;
|
|
114
|
-
return getResponsiveValueByScreen(value, screen);
|
|
115
|
-
};
|
|
116
|
-
const handleDotClick = (idx, isLoop)=>{
|
|
117
|
-
const index = setting?.sneakPeak?.[currentDevice] ? idx : isLoop ? idx : getIndexSlideItemBy(idx);
|
|
118
|
-
swiperInstance?.slideToLoop(index);
|
|
119
|
-
previousIndex.current = index;
|
|
120
|
-
};
|
|
121
|
-
useImperativeHandle(ref, ()=>({
|
|
122
|
-
nextSlideInteraction,
|
|
123
|
-
previousSlideInteraction,
|
|
124
|
-
moveToSlideInteraction
|
|
125
|
-
}));
|
|
126
|
-
const dispatchEventSelectSlide = (index)=>{
|
|
127
|
-
trigger({
|
|
128
|
-
event: 'gp:rollback:select-slide',
|
|
129
|
-
selector: `[data-id="${builderProps?.uid}"]`,
|
|
130
|
-
element: elmRef?.current
|
|
131
|
-
});
|
|
132
|
-
trigger({
|
|
133
|
-
event: 'gp:select-slide',
|
|
134
|
-
selector: `[data-id="${builderProps?.uid}"]`,
|
|
135
|
-
data: index,
|
|
136
|
-
element: elmRef?.current
|
|
137
|
-
});
|
|
138
|
-
};
|
|
139
|
-
const moveToIdxInteraction = (idx)=>{
|
|
140
|
-
swiperInstance?.slideTo(idx);
|
|
141
|
-
onHandleChangeSlideByInteraction && onHandleChangeSlideByInteraction(idx);
|
|
142
|
-
};
|
|
143
|
-
const handleDirectionalSlide = (params, direction)=>{
|
|
144
|
-
const { key, data, isRollback, element } = params;
|
|
145
|
-
const currentIndex = Math.max(swiperInstance?.activeIndex ?? 0, 0);
|
|
146
|
-
if (isRollback && data === undefined) {
|
|
147
|
-
return;
|
|
148
|
-
}
|
|
149
|
-
if (isRollback) {
|
|
150
|
-
if (direction === 'specific') {
|
|
151
|
-
const { previousData } = getInteractionPreviousData(element, key);
|
|
152
|
-
moveToIdxInteraction(Number(previousData));
|
|
153
|
-
} else {
|
|
154
|
-
// For next/previous, move in opposite direction during rollback
|
|
155
|
-
const newIndex = direction === 'next' ? currentIndex - 1 : currentIndex + 1;
|
|
156
|
-
moveToIdxInteraction(newIndex);
|
|
157
|
-
}
|
|
158
|
-
return;
|
|
159
|
-
}
|
|
160
|
-
// Save current state and move to new position
|
|
161
|
-
const indexToSave = direction === 'specific' ? Math.max(previousIndex.current, 0) : currentIndex;
|
|
162
|
-
saveToElementInteractionData(element, key, indexToSave.toString());
|
|
163
|
-
const targetIndex = direction === 'specific' ? Number(data) : direction === 'next' ? currentIndex + 1 : currentIndex - 1;
|
|
164
|
-
moveToIdxInteraction(targetIndex);
|
|
165
|
-
};
|
|
166
|
-
const nextSlideInteraction = (params)=>{
|
|
167
|
-
handleDirectionalSlide(params, 'next');
|
|
168
|
-
};
|
|
169
|
-
const previousSlideInteraction = (params)=>{
|
|
170
|
-
handleDirectionalSlide(params, 'previous');
|
|
171
|
-
};
|
|
172
|
-
const moveToSlideInteraction = (params)=>{
|
|
173
|
-
handleDirectionalSlide(params, 'specific');
|
|
174
|
-
};
|
|
175
|
-
const slidesPerView = getItemsPerPage();
|
|
176
|
-
const sliderSettings = useMemo(()=>{
|
|
177
|
-
return {
|
|
178
|
-
speed: styles?.playSpeed === 0 ? 1 : styles?.playSpeed ?? 500,
|
|
179
|
-
dir: setting?.rtl ? 'rtl' : 'ltr',
|
|
180
|
-
slidesPerView,
|
|
181
|
-
spaceBetween: getResponsiveValueByScreen(styles?.spacing, currentDevice),
|
|
182
|
-
loop: getResponsiveValueByScreen(loop, currentDevice, false),
|
|
183
|
-
breakpoints: {
|
|
184
|
-
0: {
|
|
185
|
-
allowTouchMove: getAllowTouchMove('mobile'),
|
|
186
|
-
centeredSlides: getResponsiveValueByScreen(setting?.sneakPeakType, 'mobile') === 'center'
|
|
187
|
-
},
|
|
188
|
-
768: {
|
|
189
|
-
allowTouchMove: getAllowTouchMove('tablet'),
|
|
190
|
-
centeredSlides: getResponsiveValueByScreen(setting?.sneakPeakType, 'tablet') === 'center'
|
|
191
|
-
},
|
|
192
|
-
1025: {
|
|
193
|
-
allowTouchMove: getAllowTouchMove('desktop'),
|
|
194
|
-
centeredSlides: getResponsiveValueByScreen(setting?.sneakPeakType, 'desktop') === 'center'
|
|
195
|
-
}
|
|
196
|
-
},
|
|
197
|
-
autoplay: {
|
|
198
|
-
delay: (setting?.autoplayTimeout ?? 1) * 1000,
|
|
199
|
-
pauseOnMouseEnter: setting?.pauseOnHover
|
|
200
|
-
}
|
|
201
|
-
};
|
|
202
|
-
}, [
|
|
203
|
-
styles?.playSpeed,
|
|
204
|
-
setting?.rtl,
|
|
205
|
-
styles?.spacing,
|
|
206
|
-
currentDevice,
|
|
207
|
-
loop,
|
|
208
|
-
slidesPerView,
|
|
209
|
-
setting?.sneakPeakType,
|
|
210
|
-
setting?.pauseOnHover,
|
|
211
|
-
setting?.autoplayTimeout
|
|
212
|
-
]);
|
|
213
|
-
useEffect(()=>{
|
|
214
|
-
const selector = `[data-id="${builderProps?.uid}"]`;
|
|
215
|
-
onListener({
|
|
216
|
-
event: 'gp:change-next-slide',
|
|
217
|
-
selector,
|
|
218
|
-
elementRef: localRef
|
|
219
|
-
}, (params)=>{
|
|
220
|
-
const { data, isRollback, uniqueStorageKey } = params || {};
|
|
221
|
-
nextSlideInteraction({
|
|
222
|
-
element: localRef.current,
|
|
223
|
-
data,
|
|
224
|
-
isRollback,
|
|
225
|
-
key: uniqueStorageKey
|
|
226
|
-
});
|
|
227
|
-
});
|
|
228
|
-
onListener({
|
|
229
|
-
event: 'gp:change-previous-slide',
|
|
230
|
-
selector,
|
|
231
|
-
elementRef: localRef
|
|
232
|
-
}, (params)=>{
|
|
233
|
-
const { data, isRollback, uniqueStorageKey } = params || {};
|
|
234
|
-
previousSlideInteraction({
|
|
235
|
-
element: localRef.current,
|
|
236
|
-
data,
|
|
237
|
-
isRollback,
|
|
238
|
-
key: uniqueStorageKey
|
|
239
|
-
});
|
|
240
|
-
});
|
|
241
|
-
onListener({
|
|
242
|
-
event: 'gp:change-image-step',
|
|
243
|
-
selector,
|
|
244
|
-
elementRef: localRef
|
|
245
|
-
}, (params)=>{
|
|
246
|
-
const { data, isRollback, uniqueStorageKey } = params || {};
|
|
247
|
-
moveToSlideInteraction({
|
|
248
|
-
element: localRef.current,
|
|
249
|
-
data,
|
|
250
|
-
isRollback,
|
|
251
|
-
key: uniqueStorageKey
|
|
252
|
-
});
|
|
253
|
-
});
|
|
254
|
-
onListener({
|
|
255
|
-
event: 'gp:change-index-slide',
|
|
256
|
-
selector
|
|
257
|
-
}, (params)=>{
|
|
258
|
-
const element = document.querySelector(selector);
|
|
259
|
-
const { data, isRollback, uniqueStorageKey } = params || {};
|
|
260
|
-
moveToSlideInteraction({
|
|
261
|
-
element,
|
|
262
|
-
data,
|
|
263
|
-
isRollback,
|
|
264
|
-
key: uniqueStorageKey
|
|
265
|
-
});
|
|
266
|
-
});
|
|
267
|
-
}, []);
|
|
268
|
-
const handleNextAndPrevSlide = (action)=>{
|
|
269
|
-
action === 'next' ? swiperInstance?.slideNext() : swiperInstance?.slidePrev();
|
|
270
|
-
if (onClickArrow) {
|
|
271
|
-
delayTimeout && clearTimeout(delayTimeout);
|
|
272
|
-
delayTimeout = setTimeout(()=>onClickArrow && onClickArrow(), 500);
|
|
273
|
-
}
|
|
274
|
-
};
|
|
275
|
-
useEffect(()=>{
|
|
276
|
-
if (typeof moveToIdx == 'number') {
|
|
277
|
-
previousIndex.current = moveToIdx;
|
|
278
|
-
swiperInstance?.slideTo(moveToIdx);
|
|
279
|
-
}
|
|
280
|
-
}, [
|
|
281
|
-
swiperInstance,
|
|
282
|
-
moveToIdx,
|
|
283
|
-
isHiddenArrowWhenDisabled
|
|
284
|
-
]);
|
|
285
|
-
useEffect(()=>{
|
|
286
|
-
if (!swiperInstance) return;
|
|
287
|
-
const updateState = ()=>{
|
|
288
|
-
const { realIndex, slides } = swiperInstance;
|
|
289
|
-
setCurrentSlide(realIndex);
|
|
290
|
-
setTotalSlideItem(slides?.length);
|
|
291
|
-
};
|
|
292
|
-
updateState();
|
|
293
|
-
swiperInstance.on('slideChange', updateState);
|
|
294
|
-
return ()=>{
|
|
295
|
-
swiperInstance?.off('slideChange', updateState);
|
|
296
|
-
};
|
|
297
|
-
}, [
|
|
298
|
-
swiperInstance
|
|
299
|
-
]);
|
|
300
|
-
useEffect(()=>{
|
|
301
|
-
if (swiperInstance?.wrapperEl) {
|
|
302
|
-
swiperInstance.wrapperEl.style.transitionTimingFunction = setting?.animationMode ?? 'ease';
|
|
303
|
-
}
|
|
304
|
-
}, [
|
|
305
|
-
swiperInstance,
|
|
306
|
-
setting?.animationMode
|
|
307
|
-
]);
|
|
308
|
-
useEffect(()=>{
|
|
309
|
-
if (!swiperInstance) return;
|
|
310
|
-
if (swiperInstance.autoplay) {
|
|
311
|
-
const shouldRunAutoplay = mode === 'edit' ? isFirstPreviewClicked ? setting?.runPreview && setting?.autoplay : false : setting?.autoplay;
|
|
312
|
-
if (shouldRunAutoplay) {
|
|
313
|
-
swiperInstance.autoplay.start();
|
|
314
|
-
} else {
|
|
315
|
-
swiperInstance.autoplay.stop();
|
|
316
|
-
}
|
|
317
|
-
}
|
|
318
|
-
}, [
|
|
319
|
-
swiperInstance,
|
|
320
|
-
setting?.autoplay,
|
|
321
|
-
mode,
|
|
322
|
-
isFirstPreviewClicked,
|
|
323
|
-
setting?.runPreview
|
|
324
|
-
]);
|
|
325
|
-
return {
|
|
326
|
-
isInfinity,
|
|
327
|
-
sliderSettings,
|
|
328
|
-
totalSlideItem,
|
|
329
|
-
currentSlide,
|
|
330
|
-
localRef,
|
|
331
|
-
isRenderDots,
|
|
332
|
-
showNavigation,
|
|
333
|
-
handleDotClick,
|
|
334
|
-
getItemsPerPage,
|
|
335
|
-
handleNextAndPrevSlide,
|
|
336
|
-
dispatchEventSelectSlide,
|
|
337
|
-
getNumberOfFullWidthShow
|
|
338
|
-
};
|
|
339
|
-
};
|
|
340
|
-
|
|
341
|
-
export { useCarouselWithSwiper };
|