@gem-sdk/components 2.0.0-dev.727 → 2.0.0-dev.729

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.
Files changed (30) hide show
  1. package/dist/cjs/builder.js +2 -2
  2. package/dist/cjs/carousel/carousel-item/CarouselItem.js +2 -1
  3. package/dist/cjs/carousel/index.js +3 -3
  4. package/dist/cjs/carousel/root/CarouselWithSwiper.js +131 -0
  5. package/dist/cjs/carousel/root/CustomSwiper.js +59 -0
  6. package/dist/cjs/carousel/root/hook/useCarouselWithSwiper.js +343 -0
  7. package/dist/cjs/index.js +2 -2
  8. package/dist/cjs/product/components/ProductImages/ProductGalleryCarousel.js +2 -2
  9. package/dist/cjs/product/components/ProductImages/ProductImagesLightBox.js +2 -2
  10. package/dist/cjs/product/components/ProductImagesV2/components/child/ProductFeaturedImageCarousel.js +2 -2
  11. package/dist/cjs/product/components/ProductImagesV2/components/gallery-carousel/GalleryCarousel.js +2 -2
  12. package/dist/cjs/product/components/ProductImagesV2/components/lightbox/ProductImagesLightBox.js +2 -2
  13. package/dist/cjs/product/components/ProductList/ProductListCarouselLayout.js +2 -2
  14. package/dist/cjs/product/index.js +1 -1
  15. package/dist/esm/builder.js +2 -2
  16. package/dist/esm/carousel/carousel-item/CarouselItem.js +2 -1
  17. package/dist/esm/carousel/index.js +1 -1
  18. package/dist/esm/carousel/root/CarouselWithSwiper.js +127 -0
  19. package/dist/esm/carousel/root/CustomSwiper.js +56 -0
  20. package/dist/esm/carousel/root/hook/useCarouselWithSwiper.js +341 -0
  21. package/dist/esm/index.js +1 -1
  22. package/dist/esm/product/components/ProductImages/ProductGalleryCarousel.js +2 -2
  23. package/dist/esm/product/components/ProductImages/ProductImagesLightBox.js +2 -2
  24. package/dist/esm/product/components/ProductImagesV2/components/child/ProductFeaturedImageCarousel.js +2 -2
  25. package/dist/esm/product/components/ProductImagesV2/components/gallery-carousel/GalleryCarousel.js +2 -2
  26. package/dist/esm/product/components/ProductImagesV2/components/lightbox/ProductImagesLightBox.js +2 -2
  27. package/dist/esm/product/components/ProductList/ProductListCarouselLayout.js +2 -2
  28. package/dist/esm/product/index.js +1 -1
  29. package/dist/types/index.d.ts +2 -2
  30. package/package.json +1 -1
@@ -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 Carousel = require('../../../../../carousel/root/Carousel.js');
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(Carousel.default, {
30
+ children: isDisplay && /*#__PURE__*/ jsxRuntime.jsx(CarouselWithSwiper.default, {
31
31
  parentClass: builderPropsClass,
32
32
  rootClass: builderPropsClass,
33
33
  setting: galleryCarouselSettingAttrs,
@@ -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 Carousel = require('../../../../../carousel/root/Carousel.js');
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(Carousel.default, {
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 Carousel = require('../../../carousel/root/Carousel.js');
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(Carousel.default, {
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('@gem-sdk/keen-slider/react');
14
+ require('swiper/element');
15
15
  require('react-dom');
16
16
  require('../modal/components/confirm.js');
17
17
  require('../video/components/Video.js');
@@ -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 Carousel from './carousel/root/Carousel.js';
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("div", {
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 '@gem-sdk/keen-slider/react';
5
+ import 'swiper/element';
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,127 @@
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/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
+ 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 };
@@ -0,0 +1,56 @@
1
+ import { jsx } from 'react/jsx-runtime';
2
+ import { useRef, useEffect } from 'react';
3
+ import { register } from 'swiper/element';
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 };
@@ -0,0 +1,341 @@
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 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 };
package/dist/esm/index.js CHANGED
@@ -81,7 +81,7 @@ export { default as ArticleReadMore } from './article/components/ArticleReadMore
81
81
  export { default as HeroBanner } from './banner/components/HeroBanner.js';
82
82
  export { default as Breadcrumb } from './breadcrumb/components/Breadcrumb.js';
83
83
  export { default as Button } from './button/components/Button.js';
84
- export { default as Carousel } from './carousel/root/Carousel.js';
84
+ export { default as Carousel } from './carousel/root/CarouselWithSwiper.js';
85
85
  export { default as CarouselItem } from './carousel/carousel-item/CarouselItem.js';
86
86
  export { default as Cart } from './cart/components/Cart.js';
87
87
  export { default as CartList } from './cart/components/CartList.js';
@@ -1,7 +1,7 @@
1
1
  'use client';
2
2
  import { jsx, jsxs } from 'react/jsx-runtime';
3
3
  import { useMemo } from 'react';
4
- import Carousel from '../../../carousel/root/Carousel.js';
4
+ import CarouselWithSwiper from '../../../carousel/root/CarouselWithSwiper.js';
5
5
  import CarouselItem from '../../../carousel/carousel-item/CarouselItem.js';
6
6
  import { useCurrentDevice, useFeaturedImageGlobal, getResponsiveValueByScreen, makeAspectRatio, cls, makeStyleResponsive, makeWidth } from '@gem-sdk/core';
7
7
  import { convertSpacing } from './common/common.js';
@@ -59,7 +59,7 @@ const ProductGalleryCarousel = ({ builderPropUID, productImages, onHandleClick,
59
59
  setting?.aspectRatio,
60
60
  aspectHeight
61
61
  ]);
62
- return /*#__PURE__*/ jsx(Carousel, {
62
+ return /*#__PURE__*/ jsx(CarouselWithSwiper, {
63
63
  setting: {
64
64
  loop: setting?.loop,
65
65
  slidesToShow: slidePerShow,