@gem-sdk/components 2.0.0-dev.726 → 2.0.0-dev.728
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/carousel-item/CarouselItem.js +2 -1
- package/dist/cjs/carousel/index.js +3 -3
- package/dist/cjs/carousel/root/CarouselWithSwiper.js +129 -0
- package/dist/cjs/carousel/root/CustomSwiper.js +65 -0
- package/dist/cjs/carousel/root/hook/useCarouselWithSwiper.js +331 -0
- package/dist/cjs/grid/row/commons/getStyle.js +3 -1
- package/dist/cjs/grid/row/setting/configs/settings.js +1 -1
- package/dist/cjs/grid/section/setting/configs/settings.js +1 -1
- package/dist/cjs/index.js +2 -2
- package/dist/cjs/product/components/ProductImages/ProductGalleryCarousel.js +2 -2
- package/dist/cjs/product/components/ProductImages/ProductImagesLightBox.js +2 -2
- package/dist/cjs/product/components/ProductImagesV2/components/child/ProductFeaturedImageCarousel.js +2 -2
- package/dist/cjs/product/components/ProductImagesV2/components/gallery-carousel/GalleryCarousel.js +2 -2
- package/dist/cjs/product/components/ProductImagesV2/components/lightbox/ProductImagesLightBox.js +2 -2
- package/dist/cjs/product/components/ProductList/ProductListCarouselLayout.js +2 -2
- package/dist/cjs/product/index.js +1 -1
- package/dist/cjs/product/setting/product-image-v2/configs/setting-v2/index.js +1 -0
- package/dist/esm/builder.js +2 -2
- package/dist/esm/carousel/carousel-item/CarouselItem.js +2 -1
- package/dist/esm/carousel/index.js +1 -1
- package/dist/esm/carousel/root/CarouselWithSwiper.js +125 -0
- package/dist/esm/carousel/root/CustomSwiper.js +62 -0
- package/dist/esm/carousel/root/hook/useCarouselWithSwiper.js +329 -0
- package/dist/esm/grid/row/commons/getStyle.js +3 -1
- package/dist/esm/grid/row/setting/configs/settings.js +1 -1
- package/dist/esm/grid/section/setting/configs/settings.js +1 -1
- package/dist/esm/index.js +1 -1
- package/dist/esm/product/components/ProductImages/ProductGalleryCarousel.js +2 -2
- package/dist/esm/product/components/ProductImages/ProductImagesLightBox.js +2 -2
- package/dist/esm/product/components/ProductImagesV2/components/child/ProductFeaturedImageCarousel.js +2 -2
- package/dist/esm/product/components/ProductImagesV2/components/gallery-carousel/GalleryCarousel.js +2 -2
- package/dist/esm/product/components/ProductImagesV2/components/lightbox/ProductImagesLightBox.js +2 -2
- package/dist/esm/product/components/ProductList/ProductListCarouselLayout.js +2 -2
- package/dist/esm/product/index.js +1 -1
- package/dist/esm/product/setting/product-image-v2/configs/setting-v2/index.js +1 -0
- package/dist/types/index.d.ts +2 -2
- package/package.json +1 -1
package/dist/cjs/product/components/ProductImagesV2/components/child/ProductFeaturedImageCarousel.js
CHANGED
|
@@ -11,7 +11,7 @@ var getProductImagesClassName = require('../../composables/getProductImagesClass
|
|
|
11
11
|
var getProductImagesAttr = require('../../composables/getProductImagesAttr.js');
|
|
12
12
|
var system = require('@gem-sdk/system');
|
|
13
13
|
var getStyle = require('../../common/getStyle.js');
|
|
14
|
-
var
|
|
14
|
+
var CarouselWithSwiper = require('../../../../../carousel/root/CarouselWithSwiper.js');
|
|
15
15
|
var CarouselItem = require('../../../../../carousel/carousel-item/CarouselItem.js');
|
|
16
16
|
var ProductFeaturedImageOnly = require('./ProductFeaturedImageOnly.js');
|
|
17
17
|
var useProductFeaturedImageCarousel = require('../../hooks/useProductFeaturedImageCarousel.js');
|
|
@@ -36,7 +36,7 @@ const ProductFeaturedImageCarousel = (props)=>{
|
|
|
36
36
|
ref: ref,
|
|
37
37
|
"data-slot": "children",
|
|
38
38
|
className: "product-feature-image",
|
|
39
|
-
children: isRenderFeatureCarousel ? /*#__PURE__*/ jsxRuntime.jsxs(
|
|
39
|
+
children: isRenderFeatureCarousel ? /*#__PURE__*/ jsxRuntime.jsxs(CarouselWithSwiper.default, {
|
|
40
40
|
parentClass: builderPropsClass,
|
|
41
41
|
elmRef: imgRef,
|
|
42
42
|
setting: featuredImageCarouselSettingAttrs,
|
package/dist/cjs/product/components/ProductImagesV2/components/gallery-carousel/GalleryCarousel.js
CHANGED
|
@@ -13,7 +13,7 @@ var productFeaturedImage = require('../../common/productFeaturedImage.js');
|
|
|
13
13
|
var MediaIcon = require('../child/MediaIcon.js');
|
|
14
14
|
var ButtonOpenLightBox = require('../lightbox/ButtonOpenLightBox.js');
|
|
15
15
|
var NextImage = require('../../../../../image/components/NextImage.js');
|
|
16
|
-
var
|
|
16
|
+
var CarouselWithSwiper = require('../../../../../carousel/root/CarouselWithSwiper.js');
|
|
17
17
|
var CarouselItem = require('../../../../../carousel/carousel-item/CarouselItem.js');
|
|
18
18
|
var useGalleryCarousel = require('../../hooks/useGalleryCarousel.js');
|
|
19
19
|
var system = require('@gem-sdk/system');
|
|
@@ -27,7 +27,7 @@ const ProductGalleryCarousel = (props)=>{
|
|
|
27
27
|
const { galleryCarouselStyle, galleryCarouselItemStyle } = getProductImagesStyles.getProductImagesStyles(setting);
|
|
28
28
|
const { moveToIdx, isDisplay, shapeByLayout, isEnableBorderActive, isShowButtonLightbox, filteredProductImages, handleClickCarouselItem } = useGalleryCarousel.useGalleryCarousel(props);
|
|
29
29
|
return /*#__PURE__*/ jsxRuntime.jsx(jsxRuntime.Fragment, {
|
|
30
|
-
children: isDisplay && /*#__PURE__*/ jsxRuntime.jsx(
|
|
30
|
+
children: isDisplay && /*#__PURE__*/ jsxRuntime.jsx(CarouselWithSwiper.default, {
|
|
31
31
|
parentClass: builderPropsClass,
|
|
32
32
|
rootClass: builderPropsClass,
|
|
33
33
|
setting: galleryCarouselSettingAttrs,
|
package/dist/cjs/product/components/ProductImagesV2/components/lightbox/ProductImagesLightBox.js
CHANGED
|
@@ -5,7 +5,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
5
5
|
|
|
6
6
|
var jsxRuntime = require('react/jsx-runtime');
|
|
7
7
|
var core = require('@gem-sdk/core');
|
|
8
|
-
var
|
|
8
|
+
var CarouselWithSwiper = require('../../../../../carousel/root/CarouselWithSwiper.js');
|
|
9
9
|
var CarouselItem = require('../../../../../carousel/carousel-item/CarouselItem.js');
|
|
10
10
|
var NextImage = require('../../../../../image/components/NextImage.js');
|
|
11
11
|
var Modal = require('../../../../../modal/components/Modal.js');
|
|
@@ -53,7 +53,7 @@ const ProductImagesLightBox = ({ builderPropUID, productImages, open, imageRatio
|
|
|
53
53
|
},
|
|
54
54
|
disableIframeClickEvent: true,
|
|
55
55
|
contentClass: "mobile:!gp-w-[100%] gp-px-2 gp-pb-10",
|
|
56
|
-
children: /*#__PURE__*/ jsxRuntime.jsx(
|
|
56
|
+
children: /*#__PURE__*/ jsxRuntime.jsx(CarouselWithSwiper.default, {
|
|
57
57
|
setting: {
|
|
58
58
|
loop: loopControl,
|
|
59
59
|
slidesToShow: {
|
|
@@ -4,7 +4,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
4
4
|
|
|
5
5
|
var jsxRuntime = require('react/jsx-runtime');
|
|
6
6
|
var core = require('@gem-sdk/core');
|
|
7
|
-
var
|
|
7
|
+
var CarouselWithSwiper = require('../../../carousel/root/CarouselWithSwiper.js');
|
|
8
8
|
var CarouselItem = require('../../../carousel/carousel-item/CarouselItem.js');
|
|
9
9
|
var ChildrenDroppable = require('../../../grid/components/ChildrenDroppable.js');
|
|
10
10
|
var index = require('./common/index.js');
|
|
@@ -19,7 +19,7 @@ const ProductListCarouselLayout = (props)=>{
|
|
|
19
19
|
const { productListAttr, getAttrProductItemEditor } = getAttr.getAttr(props);
|
|
20
20
|
const { carouselItemStyle } = getStyle.getStyle(props);
|
|
21
21
|
const { carouselClass, productItemClass } = getClass.getClass(props);
|
|
22
|
-
return /*#__PURE__*/ jsxRuntime.jsx(
|
|
22
|
+
return /*#__PURE__*/ jsxRuntime.jsx(CarouselWithSwiper.default, {
|
|
23
23
|
advanced: advanced,
|
|
24
24
|
builderProps: {
|
|
25
25
|
uid: builderProps?.uid
|
|
@@ -11,7 +11,7 @@ require('../notification/components/Notice.js');
|
|
|
11
11
|
require('./components/ProductButton/common/types.js');
|
|
12
12
|
require('./components/ProductVariants/components/variants/index.js');
|
|
13
13
|
require('next/image');
|
|
14
|
-
require('
|
|
14
|
+
require('swiper/element/bundle');
|
|
15
15
|
require('react-dom');
|
|
16
16
|
require('../modal/components/confirm.js');
|
|
17
17
|
require('../video/components/Video.js');
|
package/dist/esm/builder.js
CHANGED
|
@@ -132,7 +132,7 @@ import ArticleReadMore from './article/components/ArticleReadMore.js';
|
|
|
132
132
|
import HeroBanner from './banner/components/HeroBanner.js';
|
|
133
133
|
import Breadcrumb from './breadcrumb/components/Breadcrumb.js';
|
|
134
134
|
import Button from './button/components/Button.js';
|
|
135
|
-
import
|
|
135
|
+
import CarouselWithSwiper from './carousel/root/CarouselWithSwiper.js';
|
|
136
136
|
import CarouselItem from './carousel/carousel-item/CarouselItem.js';
|
|
137
137
|
import Cart from './cart/components/Cart.js';
|
|
138
138
|
import CartList from './cart/components/CartList.js';
|
|
@@ -278,7 +278,7 @@ var builder = {
|
|
|
278
278
|
HeroBanner,
|
|
279
279
|
Breadcrumb,
|
|
280
280
|
Button,
|
|
281
|
-
Carousel,
|
|
281
|
+
Carousel: CarouselWithSwiper,
|
|
282
282
|
CarouselItem,
|
|
283
283
|
Cart,
|
|
284
284
|
CartList,
|
|
@@ -5,13 +5,14 @@ import ChildrenDroppable from '../../grid/components/ChildrenDroppable.js';
|
|
|
5
5
|
import { getStyle } from './common/getStyle.js';
|
|
6
6
|
import { getClass } from './common/getClass.js';
|
|
7
7
|
import { useCarouselItem } from './hook/useCarouseItem.js';
|
|
8
|
+
import { SwiperSlide } from '../root/CustomSwiper.js';
|
|
8
9
|
|
|
9
10
|
const CarouselItem = (props)=>{
|
|
10
11
|
const { children, builderAttrs } = props;
|
|
11
12
|
const { handleClick, handleMouseMove, handleMouseOut } = useCarouselItem(props);
|
|
12
13
|
const { carouselItemStyle, carouselItemInnerStyle } = getStyle(props);
|
|
13
14
|
const { carouselItemClass, carouselItemInnerClass } = getClass(props);
|
|
14
|
-
return /*#__PURE__*/ jsx(
|
|
15
|
+
return /*#__PURE__*/ jsx(SwiperSlide, {
|
|
15
16
|
...builderAttrs,
|
|
16
17
|
"aria-hidden": true,
|
|
17
18
|
className: carouselItemClass,
|
|
@@ -2,7 +2,7 @@ import 'react/jsx-runtime';
|
|
|
2
2
|
import '@gem-sdk/core';
|
|
3
3
|
import 'react';
|
|
4
4
|
import '@gem-sdk/system';
|
|
5
|
-
import '
|
|
5
|
+
import 'swiper/element/bundle';
|
|
6
6
|
import 'next/link';
|
|
7
7
|
import config from './setting/Carousel.js';
|
|
8
8
|
import config$1 from './setting/CarouselItem.js';
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
3
|
+
import { useCurrentDevice, isEmptyChildren, filterToolbarPreview } from '@gem-sdk/core';
|
|
4
|
+
import { forwardRef, useState, Children, isValidElement } from 'react';
|
|
5
|
+
import { mappingNavigationCarousel } from '../arrow/common/common.js';
|
|
6
|
+
import { getClass } from './common/getClass.js';
|
|
7
|
+
import { getStyle } from './common/getStyle.js';
|
|
8
|
+
import { getAttr } from './common/getAttr.js';
|
|
9
|
+
import { getData } from './common/getData.js';
|
|
10
|
+
import { Swiper } from './CustomSwiper.js';
|
|
11
|
+
import Arrow from '../arrow/Arrow.js';
|
|
12
|
+
import { useCarouselWithSwiper } from './hook/useCarouselWithSwiper.js';
|
|
13
|
+
import Dots from '../dots/Dots.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
|
+
return /*#__PURE__*/ jsx("div", {
|
|
60
|
+
ref: elmRef,
|
|
61
|
+
...rootAttrRender,
|
|
62
|
+
className: rootClassRender,
|
|
63
|
+
style: rootStyleRender,
|
|
64
|
+
children: /*#__PURE__*/ jsxs("div", {
|
|
65
|
+
ref: localRef,
|
|
66
|
+
...builderAttrs,
|
|
67
|
+
className: wrapperClassRender,
|
|
68
|
+
style: wrapperStyleRender,
|
|
69
|
+
children: [
|
|
70
|
+
/*#__PURE__*/ jsxs("div", {
|
|
71
|
+
className: wrapperInnerClass,
|
|
72
|
+
style: wrapperInnerStyle,
|
|
73
|
+
children: [
|
|
74
|
+
showNavigation && renderArrow('prev'),
|
|
75
|
+
/*#__PURE__*/ jsx(Swiper, {
|
|
76
|
+
...sliderAttr,
|
|
77
|
+
...sliderSettings,
|
|
78
|
+
sliderClass: sliderClass,
|
|
79
|
+
onSwiperReady: (swiper)=>{
|
|
80
|
+
setSwiperInstance(swiper);
|
|
81
|
+
},
|
|
82
|
+
children: isEmptyChildren(children) ? /*#__PURE__*/ jsx("div", {
|
|
83
|
+
children: "No Slider"
|
|
84
|
+
}) : Children.map(filterToolbarPreview(children), (child)=>{
|
|
85
|
+
if (/*#__PURE__*/ isValidElement(child)) {
|
|
86
|
+
return /*#__PURE__*/ jsx(child.type, {
|
|
87
|
+
...child.props,
|
|
88
|
+
parentSettings: setting,
|
|
89
|
+
parentStyle: styles,
|
|
90
|
+
background: setting?.background,
|
|
91
|
+
parentUid: builderProps?.uid,
|
|
92
|
+
dispatchEventSelectSlide: dispatchEventSelectSlide
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
return null;
|
|
96
|
+
})
|
|
97
|
+
}),
|
|
98
|
+
showNavigation && renderArrow('next')
|
|
99
|
+
]
|
|
100
|
+
}),
|
|
101
|
+
isRenderDots && /*#__PURE__*/ jsx(Dots, {
|
|
102
|
+
dotStyle: setting?.dotStyle,
|
|
103
|
+
dotGapToCarousel: setting?.dotGapToCarousel,
|
|
104
|
+
vertical: setting?.vertical,
|
|
105
|
+
showDots: setting?.dot,
|
|
106
|
+
slideItemsPerPage: getItemsPerPage(),
|
|
107
|
+
enabledSneakPeak: enabledSneakPeak,
|
|
108
|
+
dotColor: setting?.dotColor,
|
|
109
|
+
dotActiveColor: setting?.dotActiveColor,
|
|
110
|
+
dotSize: setting?.dotSize,
|
|
111
|
+
sneakPeakType: setting?.sneakPeakType,
|
|
112
|
+
totalSlideItem: totalSlideItem,
|
|
113
|
+
hiddenWhenOnlyOne: hiddenDotWhenOnlyOne,
|
|
114
|
+
currentSlide: currentSlide,
|
|
115
|
+
loop: loopConfig,
|
|
116
|
+
numberOfFullWidthShow: getNumberOfFullWidthShow(currentDevice),
|
|
117
|
+
onHandleClick: handleDotClick
|
|
118
|
+
}),
|
|
119
|
+
filterToolbarPreview(children, true)
|
|
120
|
+
]
|
|
121
|
+
})
|
|
122
|
+
});
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
export { CarouselWithSwiper as default };
|
|
@@ -0,0 +1,62 @@
|
|
|
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, onSwiperReady, sliderClass, ...otherProps } = props;
|
|
8
|
+
const pauseOnMouseEnter = typeof props.autoplay === 'object' && props.autoplay !== null ? props.autoplay.pauseOnMouseEnter : undefined;
|
|
9
|
+
useEffect(()=>{
|
|
10
|
+
register();
|
|
11
|
+
Object.assign(swiperRef.current, otherProps);
|
|
12
|
+
swiperRef.current.initialize();
|
|
13
|
+
const instance = swiperRef.current.swiper;
|
|
14
|
+
onSwiperReady?.(instance);
|
|
15
|
+
}, [
|
|
16
|
+
otherProps,
|
|
17
|
+
onSwiperReady
|
|
18
|
+
]);
|
|
19
|
+
useEffect(()=>{
|
|
20
|
+
if (swiperRef.current?.swiper) {
|
|
21
|
+
const swiperInstance = swiperRef.current.swiper;
|
|
22
|
+
swiperInstance.params.spaceBetween = props.spaceBetween ?? swiperInstance.params.spaceBetween;
|
|
23
|
+
swiperInstance.params.slidesPerView = props.slidesPerView ?? swiperInstance.params.slidesPerView;
|
|
24
|
+
swiperInstance.update();
|
|
25
|
+
}
|
|
26
|
+
}, [
|
|
27
|
+
props.spaceBetween,
|
|
28
|
+
props.slidesPerView
|
|
29
|
+
]);
|
|
30
|
+
useEffect(()=>{
|
|
31
|
+
if (swiperRef.current?.swiper) {
|
|
32
|
+
const swiperInstance = swiperRef.current.swiper;
|
|
33
|
+
swiperInstance.destroy(true, true);
|
|
34
|
+
swiperRef.current.loop = props.loop;
|
|
35
|
+
swiperRef.current.centeredSlides = props.centeredSlides;
|
|
36
|
+
swiperRef.current.dir = props.dir;
|
|
37
|
+
swiperRef.current.initialize();
|
|
38
|
+
onSwiperReady?.(swiperRef.current.swiper);
|
|
39
|
+
}
|
|
40
|
+
}, [
|
|
41
|
+
props.dir,
|
|
42
|
+
props.loop,
|
|
43
|
+
props.centeredSlides,
|
|
44
|
+
pauseOnMouseEnter
|
|
45
|
+
]);
|
|
46
|
+
return /*#__PURE__*/ jsx("swiper-container", {
|
|
47
|
+
init: false,
|
|
48
|
+
className: sliderClass,
|
|
49
|
+
ref: swiperRef,
|
|
50
|
+
children: children
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
function SwiperSlide(props) {
|
|
54
|
+
const { children, className, ...rest } = props;
|
|
55
|
+
return /*#__PURE__*/ jsx("swiper-slide", {
|
|
56
|
+
...rest,
|
|
57
|
+
className: className,
|
|
58
|
+
children: children
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export { Swiper, SwiperSlide };
|
|
@@ -0,0 +1,329 @@
|
|
|
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 '../../components/hooks/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 sliderSettings = {
|
|
176
|
+
speed: styles?.playSpeed === 0 ? 1 : styles?.playSpeed ?? 500,
|
|
177
|
+
dir: setting?.rtl ? 'rtl' : 'ltr',
|
|
178
|
+
slidesPerView: getItemsPerPage(),
|
|
179
|
+
spaceBetween: getResponsiveValueByScreen(styles?.spacing, currentDevice),
|
|
180
|
+
loop: getResponsiveValueByScreen(loop, currentDevice, false),
|
|
181
|
+
breakpoints: {
|
|
182
|
+
0: {
|
|
183
|
+
allowTouchMove: getAllowTouchMove('mobile'),
|
|
184
|
+
centeredSlides: getResponsiveValueByScreen(setting?.sneakPeakType, 'mobile') === 'center'
|
|
185
|
+
},
|
|
186
|
+
768: {
|
|
187
|
+
allowTouchMove: getAllowTouchMove('tablet'),
|
|
188
|
+
centeredSlides: getResponsiveValueByScreen(setting?.sneakPeakType, 'tablet') === 'center'
|
|
189
|
+
},
|
|
190
|
+
1025: {
|
|
191
|
+
allowTouchMove: getAllowTouchMove('desktop'),
|
|
192
|
+
centeredSlides: getResponsiveValueByScreen(setting?.sneakPeakType, 'desktop') === 'center'
|
|
193
|
+
}
|
|
194
|
+
},
|
|
195
|
+
centeredSlides: getResponsiveValueByScreen(setting?.sneakPeakType, currentDevice) === 'center',
|
|
196
|
+
autoplay: {
|
|
197
|
+
delay: (setting?.autoplayTimeout ?? 1) * 1000,
|
|
198
|
+
pauseOnMouseEnter: setting?.pauseOnHover
|
|
199
|
+
}
|
|
200
|
+
};
|
|
201
|
+
useEffect(()=>{
|
|
202
|
+
const selector = `[data-id="${builderProps?.uid}"]`;
|
|
203
|
+
onListener({
|
|
204
|
+
event: 'gp:change-next-slide',
|
|
205
|
+
selector,
|
|
206
|
+
elementRef: localRef
|
|
207
|
+
}, (params)=>{
|
|
208
|
+
const { data, isRollback, uniqueStorageKey } = params || {};
|
|
209
|
+
nextSlideInteraction({
|
|
210
|
+
element: localRef.current,
|
|
211
|
+
data,
|
|
212
|
+
isRollback,
|
|
213
|
+
key: uniqueStorageKey
|
|
214
|
+
});
|
|
215
|
+
});
|
|
216
|
+
onListener({
|
|
217
|
+
event: 'gp:change-previous-slide',
|
|
218
|
+
selector,
|
|
219
|
+
elementRef: localRef
|
|
220
|
+
}, (params)=>{
|
|
221
|
+
const { data, isRollback, uniqueStorageKey } = params || {};
|
|
222
|
+
previousSlideInteraction({
|
|
223
|
+
element: localRef.current,
|
|
224
|
+
data,
|
|
225
|
+
isRollback,
|
|
226
|
+
key: uniqueStorageKey
|
|
227
|
+
});
|
|
228
|
+
});
|
|
229
|
+
onListener({
|
|
230
|
+
event: 'gp:change-image-step',
|
|
231
|
+
selector,
|
|
232
|
+
elementRef: localRef
|
|
233
|
+
}, (params)=>{
|
|
234
|
+
const { data, isRollback, uniqueStorageKey } = params || {};
|
|
235
|
+
moveToSlideInteraction({
|
|
236
|
+
element: localRef.current,
|
|
237
|
+
data,
|
|
238
|
+
isRollback,
|
|
239
|
+
key: uniqueStorageKey
|
|
240
|
+
});
|
|
241
|
+
});
|
|
242
|
+
onListener({
|
|
243
|
+
event: 'gp:change-index-slide',
|
|
244
|
+
selector
|
|
245
|
+
}, (params)=>{
|
|
246
|
+
const element = document.querySelector(selector);
|
|
247
|
+
const { data, isRollback, uniqueStorageKey } = params || {};
|
|
248
|
+
moveToSlideInteraction({
|
|
249
|
+
element,
|
|
250
|
+
data,
|
|
251
|
+
isRollback,
|
|
252
|
+
key: uniqueStorageKey
|
|
253
|
+
});
|
|
254
|
+
});
|
|
255
|
+
}, []);
|
|
256
|
+
const handleNextAndPrevSlide = (action)=>{
|
|
257
|
+
action === 'next' ? swiperInstance?.slideNext() : swiperInstance?.slidePrev();
|
|
258
|
+
if (onClickArrow) {
|
|
259
|
+
delayTimeout && clearTimeout(delayTimeout);
|
|
260
|
+
delayTimeout = setTimeout(()=>onClickArrow && onClickArrow(), 500);
|
|
261
|
+
}
|
|
262
|
+
};
|
|
263
|
+
useEffect(()=>{
|
|
264
|
+
if (typeof moveToIdx == 'number') {
|
|
265
|
+
previousIndex.current = moveToIdx;
|
|
266
|
+
swiperInstance?.slideTo(moveToIdx);
|
|
267
|
+
}
|
|
268
|
+
}, [
|
|
269
|
+
swiperInstance,
|
|
270
|
+
moveToIdx,
|
|
271
|
+
isHiddenArrowWhenDisabled
|
|
272
|
+
]);
|
|
273
|
+
useEffect(()=>{
|
|
274
|
+
if (!swiperInstance) return;
|
|
275
|
+
const updateState = ()=>{
|
|
276
|
+
const { realIndex, slides } = swiperInstance;
|
|
277
|
+
setCurrentSlide(realIndex);
|
|
278
|
+
setTotalSlideItem(slides?.length);
|
|
279
|
+
};
|
|
280
|
+
updateState();
|
|
281
|
+
swiperInstance.on('slideChange', updateState);
|
|
282
|
+
return ()=>{
|
|
283
|
+
swiperInstance?.off('slideChange', updateState);
|
|
284
|
+
};
|
|
285
|
+
}, [
|
|
286
|
+
swiperInstance
|
|
287
|
+
]);
|
|
288
|
+
useEffect(()=>{
|
|
289
|
+
if (swiperInstance?.wrapperEl) {
|
|
290
|
+
swiperInstance.wrapperEl.style.transitionTimingFunction = setting?.animationMode ?? 'ease';
|
|
291
|
+
}
|
|
292
|
+
}, [
|
|
293
|
+
swiperInstance,
|
|
294
|
+
setting?.animationMode
|
|
295
|
+
]);
|
|
296
|
+
useEffect(()=>{
|
|
297
|
+
if (!swiperInstance) return;
|
|
298
|
+
if (swiperInstance.autoplay) {
|
|
299
|
+
const shouldRunAutoplay = mode === 'edit' ? isFirstPreviewClicked ? setting?.runPreview && setting?.autoplay : false : setting?.autoplay;
|
|
300
|
+
if (shouldRunAutoplay) {
|
|
301
|
+
swiperInstance.autoplay.start();
|
|
302
|
+
} else {
|
|
303
|
+
swiperInstance.autoplay.stop();
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
}, [
|
|
307
|
+
swiperInstance,
|
|
308
|
+
setting?.autoplay,
|
|
309
|
+
mode,
|
|
310
|
+
isFirstPreviewClicked,
|
|
311
|
+
setting?.runPreview
|
|
312
|
+
]);
|
|
313
|
+
return {
|
|
314
|
+
isInfinity,
|
|
315
|
+
sliderSettings,
|
|
316
|
+
totalSlideItem,
|
|
317
|
+
currentSlide,
|
|
318
|
+
localRef,
|
|
319
|
+
isRenderDots,
|
|
320
|
+
showNavigation,
|
|
321
|
+
handleDotClick,
|
|
322
|
+
getItemsPerPage,
|
|
323
|
+
handleNextAndPrevSlide,
|
|
324
|
+
dispatchEventSelectSlide,
|
|
325
|
+
getNumberOfFullWidthShow
|
|
326
|
+
};
|
|
327
|
+
};
|
|
328
|
+
|
|
329
|
+
export { useCarouselWithSwiper };
|
|
@@ -100,8 +100,10 @@ const getRowStyle = (rowProps)=>{
|
|
|
100
100
|
});
|
|
101
101
|
const embedVideoStyle = createStyle({
|
|
102
102
|
...bgVideoAspectRatioStyle,
|
|
103
|
-
|
|
103
|
+
'pointer-events': 'none',
|
|
104
104
|
transform: 'translateY(-50%)',
|
|
105
|
+
height: '100%',
|
|
106
|
+
'object-fit': 'cover',
|
|
105
107
|
top: '50%'
|
|
106
108
|
});
|
|
107
109
|
const sectionPagePaddingStyle = {
|