@gem-sdk/components 2.0.0-dev.622 → 2.0.0-dev.624

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 (180) hide show
  1. package/dist/cjs/builder.js +12 -6
  2. package/dist/cjs/collection/components/collection-paginator/common/styles.js +3 -4
  3. package/dist/cjs/collection/components/collection-paginator/components/CollectionPaginator.liquid.js +2 -1
  4. package/dist/cjs/collection/setting/collection-paginator/configs/settings.js +2 -3
  5. package/dist/cjs/index.js +34 -32
  6. package/dist/cjs/index.liquid.js +16 -10
  7. package/dist/cjs/next.js +3 -1
  8. package/dist/cjs/product/components/ProductImagesV3/common/common.js +360 -0
  9. package/dist/cjs/product/components/ProductImagesV3/common/getAttr.js +192 -0
  10. package/dist/cjs/product/components/ProductImagesV3/common/getBorderActiveCss.js +26 -0
  11. package/dist/cjs/product/components/ProductImagesV3/common/getClasses.js +94 -0
  12. package/dist/cjs/product/components/ProductImagesV3/common/getStyle.js +303 -0
  13. package/dist/cjs/product/components/ProductImagesV3/common/hoverAction.js +95 -0
  14. package/dist/cjs/product/components/ProductImagesV3/common/productFeaturedImage.js +59 -0
  15. package/dist/cjs/product/components/ProductImagesV3/common/productGallery.js +266 -0
  16. package/dist/cjs/product/components/ProductImagesV3/components/child/MediaIcon.js +63 -0
  17. package/dist/cjs/product/components/ProductImagesV3/components/child/ProductFeatureVideo.js +36 -0
  18. package/dist/cjs/product/components/ProductImagesV3/components/child/ProductFeaturedImageCarousel.js +109 -0
  19. package/dist/cjs/product/components/ProductImagesV3/components/child/ProductFeaturedImageOnly.js +139 -0
  20. package/dist/cjs/product/components/ProductImagesV3/components/child/ProductGalleryGrid.js +100 -0
  21. package/dist/cjs/product/components/ProductImagesV3/components/feature-gallery/FeatureImageWithGallery.js +77 -0
  22. package/dist/cjs/product/components/ProductImagesV3/components/feature-gallery/FeatureImageWithGallery.liquid.js +300 -0
  23. package/dist/cjs/product/components/ProductImagesV3/components/feature-only/OnlyFeatureImage.js +44 -0
  24. package/dist/cjs/product/components/ProductImagesV3/components/gallery-carousel/GalleryCarousel.js +83 -0
  25. package/dist/cjs/product/components/ProductImagesV3/components/gallery-carousel/GalleryCarousel.liquid.js +182 -0
  26. package/dist/cjs/product/components/ProductImagesV3/components/gallery-grid/GalleryGrid.js +30 -0
  27. package/dist/cjs/product/components/ProductImagesV3/components/gallery-grid/GalleryGrid.liquid.js +239 -0
  28. package/dist/cjs/product/components/ProductImagesV3/components/lightbox/ButtonOpenLightBox.js +28 -0
  29. package/dist/cjs/product/components/ProductImagesV3/components/lightbox/ProductImagesLightBox.js +144 -0
  30. package/dist/cjs/product/components/ProductImagesV3/composables/getProductImagesAttr.js +14 -0
  31. package/dist/cjs/product/components/ProductImagesV3/composables/getProductImagesClassName.js +54 -0
  32. package/dist/cjs/product/components/ProductImagesV3/composables/getProductImagesStyles.js +53 -0
  33. package/dist/cjs/product/components/ProductImagesV3/hooks/useFeatureImageWithGallery.js +55 -0
  34. package/dist/cjs/product/components/ProductImagesV3/hooks/useFilterImagesByVariant.js +41 -0
  35. package/dist/cjs/product/components/ProductImagesV3/hooks/useGalleryCarousel.js +134 -0
  36. package/dist/cjs/product/components/ProductImagesV3/hooks/useProductFeaturedImageCarousel.js +203 -0
  37. package/dist/cjs/product/components/ProductImagesV3/hooks/useProductGalleryGrid.js +87 -0
  38. package/dist/cjs/product/components/ProductImagesV3/index.js +291 -0
  39. package/dist/cjs/product/components/ProductImagesV3/index.liquid.js +153 -0
  40. package/dist/cjs/product/index.js +6 -4
  41. package/dist/cjs/product/next.js +4 -0
  42. package/dist/cjs/product/setting/product-image-v3/ProductFeatureImage.js +252 -0
  43. package/dist/cjs/product/setting/product-image-v3/ProductGalleryImage.js +251 -0
  44. package/dist/cjs/product/setting/product-image-v3/ProductImages.js +74 -0
  45. package/dist/cjs/product/setting/product-image-v3/configs/setting-v2/ProductFeatureImage.js +388 -0
  46. package/dist/cjs/product/setting/product-image-v3/configs/setting-v2/ProductGalleryImage.js +518 -0
  47. package/dist/cjs/product/setting/product-image-v3/configs/setting-v2/index.js +336 -0
  48. package/dist/cjs/product/setting/product-image-v3/configs/ui/FeatureNavigation.js +118 -0
  49. package/dist/cjs/product/setting/product-image-v3/configs/ui/ImageListNavigation.js +119 -0
  50. package/dist/cjs/product/setting/product-image-v3/configs/uiV1.js +237 -0
  51. package/dist/cjs/product/setting/product-image-v3/configs/uiV2.js +491 -0
  52. package/dist/cjs/setting.js +97 -95
  53. package/dist/cjs/swiper-carousel/arrow/Arrow.js +52 -0
  54. package/dist/cjs/swiper-carousel/arrow/Arrow.liquid.js +46 -0
  55. package/dist/cjs/swiper-carousel/arrow/common/common.js +119 -0
  56. package/dist/cjs/swiper-carousel/arrow/common/getClass.js +50 -0
  57. package/dist/cjs/swiper-carousel/arrow/common/getStyle.js +84 -0
  58. package/dist/cjs/swiper-carousel/carousel-item/SwiperItem.js +34 -0
  59. package/dist/cjs/swiper-carousel/carousel-item/SwiperItem.liquid.js +38 -0
  60. package/dist/cjs/swiper-carousel/carousel-item/common/getClass.js +29 -0
  61. package/dist/cjs/swiper-carousel/carousel-item/common/getStyle.js +79 -0
  62. package/dist/cjs/swiper-carousel/carousel-item/hook/useCarouseItem.js +22 -0
  63. package/dist/cjs/swiper-carousel/components/common/carousel.js +98 -0
  64. package/dist/cjs/swiper-carousel/components/const/index.js +5 -0
  65. package/dist/cjs/swiper-carousel/components/hooks/useTrackPreviewPause.js +34 -0
  66. package/dist/cjs/swiper-carousel/components/plugins/AnimationPlugin.js +42 -0
  67. package/dist/cjs/swiper-carousel/components/plugins/AutoPlayPlugin.js +105 -0
  68. package/dist/cjs/swiper-carousel/components/plugins/FixSliderMoveBackwards.js +15 -0
  69. package/dist/cjs/swiper-carousel/components/plugins/MutationPlugin.js +45 -0
  70. package/dist/cjs/swiper-carousel/dots/Dots.js +51 -0
  71. package/dist/cjs/swiper-carousel/dots/Dots.liquid.js +26 -0
  72. package/dist/cjs/swiper-carousel/dots/common/common.js +28 -0
  73. package/dist/cjs/swiper-carousel/dots/common/getClass.js +40 -0
  74. package/dist/cjs/swiper-carousel/dots/common/getStyle.js +33 -0
  75. package/dist/cjs/swiper-carousel/dots/hook/useDotsSetting.js +21 -0
  76. package/dist/cjs/swiper-carousel/index.js +17 -0
  77. package/dist/cjs/swiper-carousel/next.js +22 -0
  78. package/dist/cjs/swiper-carousel/root/Swiper.js +128 -0
  79. package/dist/cjs/swiper-carousel/root/Swiper.liquid.js +104 -0
  80. package/dist/cjs/swiper-carousel/root/common/getAttr.js +25 -0
  81. package/dist/cjs/swiper-carousel/root/common/getClass.js +135 -0
  82. package/dist/cjs/swiper-carousel/root/common/getData.js +56 -0
  83. package/dist/cjs/swiper-carousel/root/common/getStyle.js +64 -0
  84. package/dist/cjs/swiper-carousel/root/hook/useCarousel.js +482 -0
  85. package/dist/cjs/swiper-carousel/setting/Swiper.js +42 -0
  86. package/dist/cjs/swiper-carousel/setting/SwiperItem.js +40 -0
  87. package/dist/cjs/swiper-carousel/setting/configs/presets.js +87 -0
  88. package/dist/cjs/swiper-carousel/setting/configs/settingV2.js +819 -0
  89. package/dist/cjs/swiper-carousel/setting/configs/uiV2.js +718 -0
  90. package/dist/esm/builder.js +6 -0
  91. package/dist/esm/collection/components/collection-paginator/common/styles.js +3 -4
  92. package/dist/esm/collection/components/collection-paginator/components/CollectionPaginator.liquid.js +2 -1
  93. package/dist/esm/collection/setting/collection-paginator/configs/settings.js +2 -3
  94. package/dist/esm/index.js +1 -0
  95. package/dist/esm/index.liquid.js +3 -0
  96. package/dist/esm/next.js +3 -1
  97. package/dist/esm/product/components/ProductImagesV3/common/common.js +344 -0
  98. package/dist/esm/product/components/ProductImagesV3/common/getAttr.js +189 -0
  99. package/dist/esm/product/components/ProductImagesV3/common/getBorderActiveCss.js +24 -0
  100. package/dist/esm/product/components/ProductImagesV3/common/getClasses.js +83 -0
  101. package/dist/esm/product/components/ProductImagesV3/common/getStyle.js +292 -0
  102. package/dist/esm/product/components/ProductImagesV3/common/hoverAction.js +92 -0
  103. package/dist/esm/product/components/ProductImagesV3/common/productFeaturedImage.js +53 -0
  104. package/dist/esm/product/components/ProductImagesV3/common/productGallery.js +251 -0
  105. package/dist/esm/product/components/ProductImagesV3/components/child/MediaIcon.js +59 -0
  106. package/dist/esm/product/components/ProductImagesV3/components/child/ProductFeatureVideo.js +32 -0
  107. package/dist/esm/product/components/ProductImagesV3/components/child/ProductFeaturedImageCarousel.js +105 -0
  108. package/dist/esm/product/components/ProductImagesV3/components/child/ProductFeaturedImageOnly.js +135 -0
  109. package/dist/esm/product/components/ProductImagesV3/components/child/ProductGalleryGrid.js +96 -0
  110. package/dist/esm/product/components/ProductImagesV3/components/feature-gallery/FeatureImageWithGallery.js +73 -0
  111. package/dist/esm/product/components/ProductImagesV3/components/feature-gallery/FeatureImageWithGallery.liquid.js +296 -0
  112. package/dist/esm/product/components/ProductImagesV3/components/feature-only/OnlyFeatureImage.js +40 -0
  113. package/dist/esm/product/components/ProductImagesV3/components/gallery-carousel/GalleryCarousel.js +79 -0
  114. package/dist/esm/product/components/ProductImagesV3/components/gallery-carousel/GalleryCarousel.liquid.js +178 -0
  115. package/dist/esm/product/components/ProductImagesV3/components/gallery-grid/GalleryGrid.js +26 -0
  116. package/dist/esm/product/components/ProductImagesV3/components/gallery-grid/GalleryGrid.liquid.js +235 -0
  117. package/dist/esm/product/components/ProductImagesV3/components/lightbox/ButtonOpenLightBox.js +24 -0
  118. package/dist/esm/product/components/ProductImagesV3/components/lightbox/ProductImagesLightBox.js +140 -0
  119. package/dist/esm/product/components/ProductImagesV3/composables/getProductImagesAttr.js +12 -0
  120. package/dist/esm/product/components/ProductImagesV3/composables/getProductImagesClassName.js +52 -0
  121. package/dist/esm/product/components/ProductImagesV3/composables/getProductImagesStyles.js +51 -0
  122. package/dist/esm/product/components/ProductImagesV3/hooks/useFeatureImageWithGallery.js +53 -0
  123. package/dist/esm/product/components/ProductImagesV3/hooks/useFilterImagesByVariant.js +39 -0
  124. package/dist/esm/product/components/ProductImagesV3/hooks/useGalleryCarousel.js +132 -0
  125. package/dist/esm/product/components/ProductImagesV3/hooks/useProductFeaturedImageCarousel.js +201 -0
  126. package/dist/esm/product/components/ProductImagesV3/hooks/useProductGalleryGrid.js +85 -0
  127. package/dist/esm/product/components/ProductImagesV3/index.js +287 -0
  128. package/dist/esm/product/components/ProductImagesV3/index.liquid.js +149 -0
  129. package/dist/esm/product/index.js +26 -24
  130. package/dist/esm/product/next.js +4 -0
  131. package/dist/esm/product/setting/product-image-v3/ProductFeatureImage.js +248 -0
  132. package/dist/esm/product/setting/product-image-v3/ProductGalleryImage.js +248 -0
  133. package/dist/esm/product/setting/product-image-v3/ProductImages.js +70 -0
  134. package/dist/esm/product/setting/product-image-v3/configs/setting-v2/ProductFeatureImage.js +384 -0
  135. package/dist/esm/product/setting/product-image-v3/configs/setting-v2/ProductGalleryImage.js +515 -0
  136. package/dist/esm/product/setting/product-image-v3/configs/setting-v2/index.js +334 -0
  137. package/dist/esm/product/setting/product-image-v3/configs/ui/FeatureNavigation.js +116 -0
  138. package/dist/esm/product/setting/product-image-v3/configs/ui/ImageListNavigation.js +117 -0
  139. package/dist/esm/product/setting/product-image-v3/configs/uiV1.js +235 -0
  140. package/dist/esm/product/setting/product-image-v3/configs/uiV2.js +489 -0
  141. package/dist/esm/setting.js +2 -0
  142. package/dist/esm/swiper-carousel/arrow/Arrow.js +48 -0
  143. package/dist/esm/swiper-carousel/arrow/Arrow.liquid.js +42 -0
  144. package/dist/esm/swiper-carousel/arrow/common/common.js +111 -0
  145. package/dist/esm/swiper-carousel/arrow/common/getClass.js +48 -0
  146. package/dist/esm/swiper-carousel/arrow/common/getStyle.js +82 -0
  147. package/dist/esm/swiper-carousel/carousel-item/SwiperItem.js +30 -0
  148. package/dist/esm/swiper-carousel/carousel-item/SwiperItem.liquid.js +34 -0
  149. package/dist/esm/swiper-carousel/carousel-item/common/getClass.js +27 -0
  150. package/dist/esm/swiper-carousel/carousel-item/common/getStyle.js +77 -0
  151. package/dist/esm/swiper-carousel/carousel-item/hook/useCarouseItem.js +20 -0
  152. package/dist/esm/swiper-carousel/components/common/carousel.js +93 -0
  153. package/dist/esm/swiper-carousel/components/const/index.js +3 -0
  154. package/dist/esm/swiper-carousel/components/hooks/useTrackPreviewPause.js +30 -0
  155. package/dist/esm/swiper-carousel/components/plugins/AnimationPlugin.js +35 -0
  156. package/dist/esm/swiper-carousel/components/plugins/AutoPlayPlugin.js +103 -0
  157. package/dist/esm/swiper-carousel/components/plugins/FixSliderMoveBackwards.js +13 -0
  158. package/dist/esm/swiper-carousel/components/plugins/MutationPlugin.js +43 -0
  159. package/dist/esm/swiper-carousel/dots/Dots.js +47 -0
  160. package/dist/esm/swiper-carousel/dots/Dots.liquid.js +22 -0
  161. package/dist/esm/swiper-carousel/dots/common/common.js +26 -0
  162. package/dist/esm/swiper-carousel/dots/common/getClass.js +38 -0
  163. package/dist/esm/swiper-carousel/dots/common/getStyle.js +31 -0
  164. package/dist/esm/swiper-carousel/dots/hook/useDotsSetting.js +19 -0
  165. package/dist/esm/swiper-carousel/index.js +15 -0
  166. package/dist/esm/swiper-carousel/next.js +18 -0
  167. package/dist/esm/swiper-carousel/root/Swiper.js +124 -0
  168. package/dist/esm/swiper-carousel/root/Swiper.liquid.js +100 -0
  169. package/dist/esm/swiper-carousel/root/common/getAttr.js +23 -0
  170. package/dist/esm/swiper-carousel/root/common/getClass.js +133 -0
  171. package/dist/esm/swiper-carousel/root/common/getData.js +54 -0
  172. package/dist/esm/swiper-carousel/root/common/getStyle.js +62 -0
  173. package/dist/esm/swiper-carousel/root/hook/useCarousel.js +480 -0
  174. package/dist/esm/swiper-carousel/setting/Swiper.js +38 -0
  175. package/dist/esm/swiper-carousel/setting/SwiperItem.js +36 -0
  176. package/dist/esm/swiper-carousel/setting/configs/presets.js +85 -0
  177. package/dist/esm/swiper-carousel/setting/configs/settingV2.js +815 -0
  178. package/dist/esm/swiper-carousel/setting/configs/uiV2.js +713 -0
  179. package/dist/types/index.d.ts +551 -116
  180. package/package.json +2 -2
@@ -0,0 +1,480 @@
1
+ import { useKeenSlider } from '@gem-sdk/keen-slider/react';
2
+ import { AutoPlayPlugin } from '../../components/plugins/AutoPlayPlugin.js';
3
+ import { CAROUSEL_ANIMATION, DEFAULT_PLAY_SPEED, AnimationPlugin } from '../../components/plugins/AnimationPlugin.js';
4
+ import { useState, useRef, useCallback, useMemo, useImperativeHandle, useEffect } from 'react';
5
+ import { useCurrentDevice, useEditorMode, useInteraction, DEVICES, getResponsiveValueByScreen } from '@gem-sdk/core';
6
+ import { MutationPlugin } from '../../components/plugins/MutationPlugin.js';
7
+ import { FixSliderMoveBackwards } from '../../components/plugins/FixSliderMoveBackwards.js';
8
+ import useTrackPreviewPause from '../../components/hooks/useTrackPreviewPause.js';
9
+ import { getData } from '../common/getData.js';
10
+
11
+ const useCarousel = (props, ref)=>{
12
+ const { builderProps, moveToIdx, styles, setting, isHiddenArrowWhenDisabled = true, elmRef, onChangeActive, onLoaded, onUpdated, onCreated, onClickArrow, onHandleChangeSlideByInteraction } = props;
13
+ const { loop, navigationEnable = {
14
+ desktop: true
15
+ }, navigationStyle } = setting ?? {};
16
+ const [isInfinity, setIsInfinity] = useState(false);
17
+ const [totalSlideItem, setTotalSlideItem] = useState(0);
18
+ const [slideMaxIndex, setSlideMaxIndex] = useState(0);
19
+ const [currentSlide, setCurrentSlide] = useState(setting?.defaultCurrentSlider ?? 0);
20
+ const [loaded, setLoaded] = useState(false);
21
+ const [slider, setSlider] = useState();
22
+ const { sliderSelector } = getData(props);
23
+ const localRef = useRef();
24
+ const isRunningAnimation = useRef(false);
25
+ const previousIndex = useRef(moveToIdx ?? 0);
26
+ let delayTimeout;
27
+ const currentDevice = useCurrentDevice();
28
+ const mode = useEditorMode();
29
+ const { isFirstPreviewClicked } = useTrackPreviewPause(setting?.runPreview);
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 slidesToShow = useMemo(()=>{
54
+ const oldData = getSlideToShowFromOldData();
55
+ if (oldData) {
56
+ return oldData;
57
+ }
58
+ const result = {};
59
+ DEVICES.forEach((device)=>{
60
+ const enableSneakPeak = getResponsiveValueByScreen(setting?.sneakPeak, device);
61
+ const offset = enableSneakPeak ? getResponsiveValueByScreen(setting?.sneakPeakType, device) === 'center' ? getResponsiveValueByScreen(setting?.sneakPeakOffsetCenter, device) ?? 0 : getResponsiveValueByScreen(setting?.sneakPeakOffsetForward, device) ?? 0 : 0;
62
+ const rx = getResponsiveValueByScreen(setting?.sneakPeakType, device) === 'center' ? -2 : -1;
63
+ const itemNumberByDevice = getResponsiveValueByScreen(setting?.itemNumber, device);
64
+ result[device] = typeof itemNumberByDevice === 'number' ? itemNumberByDevice + offset / 100 * rx : 'auto';
65
+ });
66
+ return result;
67
+ }, [
68
+ getSlideToShowFromOldData,
69
+ setting?.itemNumber,
70
+ setting?.sneakPeak,
71
+ setting?.sneakPeakOffsetCenter,
72
+ setting?.sneakPeakOffsetForward,
73
+ setting?.sneakPeakType
74
+ ]);
75
+ const itemNumber = useMemo(()=>{
76
+ const oldData = getItemNumberFromOldData();
77
+ return oldData || setting?.itemNumber;
78
+ }, [
79
+ getItemNumberFromOldData,
80
+ setting?.itemNumber
81
+ ]);
82
+ const getNumberOfFullWidthShow = useCallback((device)=>{
83
+ const sneakPeekTypeByNumber = getResponsiveValueByScreen(setting?.sneakPeakType, device) === 'center' ? 2 : 1;
84
+ return typeof getResponsiveValueByScreen(itemNumber, device, 4) === 'number' ? getResponsiveValueByScreen(itemNumber, device, 4) - sneakPeekTypeByNumber : undefined;
85
+ }, [
86
+ setting?.sneakPeakType,
87
+ itemNumber
88
+ ]);
89
+ const getOriginCarousel = useMemo(()=>(device)=>{
90
+ const origin = getResponsiveValueByScreen(setting?.sneakPeakType, device) === 'center' && getResponsiveValueByScreen(setting?.sneakPeak, device) ? 'center' : 'auto';
91
+ return origin;
92
+ }, [
93
+ setting?.sneakPeak,
94
+ setting?.sneakPeakType
95
+ ]);
96
+ const getMaxNavigationWhenSneak = useMemo(()=>(device)=>{
97
+ if (getOriginCarousel(device) !== 'center') return {};
98
+ const totalItems = setting?.childItem?.length || 1;
99
+ let itemShow = Number(getResponsiveValueByScreen(slidesToShow, device, 1)) || 1 + 1;
100
+ if (setting?.sneakPeak?.[currentDevice]) {
101
+ itemShow = Math.trunc(Number(getNumberOfFullWidthShow(device)));
102
+ }
103
+ const max = totalItems - itemShow;
104
+ const isLoopByDevice = getResponsiveValueByScreen(loop, device, false);
105
+ if (isLoopByDevice) return {
106
+ max: undefined
107
+ };
108
+ return {
109
+ max
110
+ };
111
+ }, [
112
+ setting?.childItem,
113
+ slidesToShow,
114
+ getOriginCarousel,
115
+ loop,
116
+ currentDevice,
117
+ setting?.sneakPeak,
118
+ getNumberOfFullWidthShow
119
+ ]);
120
+ const removeInitialCarouselGap = ()=>{
121
+ const sliderElm = document.querySelectorAll(`.${sliderSelector}`);
122
+ if (!sliderElm) return;
123
+ sliderElm.forEach((selector)=>{
124
+ selector?.style.removeProperty('--cg');
125
+ selector?.style.removeProperty('--cg-tablet');
126
+ selector?.style.removeProperty('--cg-mobile');
127
+ selector?.style.removeProperty('--rg');
128
+ selector?.style.removeProperty('--rg-tablet');
129
+ selector?.style.removeProperty('--rg-mobile');
130
+ });
131
+ };
132
+ const [sliderRef, instanceRef] = useKeenSlider({
133
+ selector: `.gem-slider-item-${builderProps?.uid}`,
134
+ optionsChanged: (slider)=>{
135
+ if (slider?.track?.details?.maxIdx === Infinity) {
136
+ setIsInfinity(true);
137
+ } else {
138
+ setIsInfinity(false);
139
+ }
140
+ setTotalSlideItem(Math.ceil(slider.slides.length));
141
+ setSlideMaxIndex(slider?.track?.details?.maxIdx);
142
+ },
143
+ defaultAnimation: {
144
+ duration: styles?.playSpeed === 0 ? 1 : styles?.playSpeed ?? 500,
145
+ easing: (t)=>{
146
+ switch(setting?.animationMode){
147
+ case CAROUSEL_ANIMATION.EASE_IN.value:
148
+ return CAROUSEL_ANIMATION.EASE_IN.formula(t);
149
+ case CAROUSEL_ANIMATION.EASE_OUT.value:
150
+ return CAROUSEL_ANIMATION.EASE_OUT.formula(t);
151
+ case CAROUSEL_ANIMATION.EASE_IN_OUT.value:
152
+ return CAROUSEL_ANIMATION.EASE_IN_OUT.formula(t);
153
+ default:
154
+ return CAROUSEL_ANIMATION.DEFAULT.formula(t);
155
+ }
156
+ }
157
+ },
158
+ dragSpeed: 2,
159
+ renderMode: 'precision',
160
+ mode: 'snap',
161
+ loop: getResponsiveValueByScreen(loop, 'desktop', false),
162
+ vertical: getResponsiveValueByScreen(setting?.vertical, 'desktop'),
163
+ rtl: setting?.rtl,
164
+ breakpoints: {
165
+ '(max-width: 9999px)': {
166
+ slides: {
167
+ perView: getResponsiveValueByScreen(slidesToShow, 'desktop', 4) ?? 1,
168
+ spacing: getResponsiveValueByScreen(styles?.spacing, 'desktop'),
169
+ origin: getOriginCarousel('desktop'),
170
+ numberOfFullWidthShow: getNumberOfFullWidthShow('desktop')
171
+ },
172
+ loop: getResponsiveValueByScreen(loop, 'desktop', false),
173
+ vertical: getResponsiveValueByScreen(setting?.vertical, 'desktop'),
174
+ drag: getResponsiveValueByScreen(mode == 'edit' ? {
175
+ desktop: false
176
+ } : setting?.enableDrag, 'desktop'),
177
+ initial: moveToIdx ?? 0,
178
+ range: getMaxNavigationWhenSneak('desktop')
179
+ },
180
+ '(max-width: 1024px)': {
181
+ slides: {
182
+ perView: getResponsiveValueByScreen(slidesToShow, 'tablet', 4),
183
+ spacing: getResponsiveValueByScreen(styles?.spacing, 'tablet'),
184
+ origin: getOriginCarousel('tablet'),
185
+ numberOfFullWidthShow: getNumberOfFullWidthShow('tablet')
186
+ },
187
+ loop: getResponsiveValueByScreen(loop, 'tablet', false),
188
+ vertical: getResponsiveValueByScreen(setting?.vertical, 'tablet'),
189
+ drag: getResponsiveValueByScreen(mode == 'edit' ? {
190
+ tablet: false
191
+ } : setting?.enableDrag, 'tablet'),
192
+ initial: moveToIdx || 0,
193
+ range: getMaxNavigationWhenSneak('tablet')
194
+ },
195
+ '(max-width: 767px)': {
196
+ slides: {
197
+ perView: getResponsiveValueByScreen(slidesToShow, 'mobile', 4),
198
+ spacing: getResponsiveValueByScreen(styles?.spacing, 'mobile'),
199
+ origin: getOriginCarousel('mobile'),
200
+ numberOfFullWidthShow: getNumberOfFullWidthShow('mobile')
201
+ },
202
+ loop: getResponsiveValueByScreen(loop, 'mobile', false),
203
+ vertical: getResponsiveValueByScreen(setting?.vertical, 'mobile'),
204
+ drag: getResponsiveValueByScreen(mode == 'edit' ? {
205
+ mobile: false
206
+ } : setting?.enableDrag, 'mobile'),
207
+ initial: moveToIdx ?? 0,
208
+ range: getMaxNavigationWhenSneak('mobile')
209
+ }
210
+ },
211
+ slideChanged: (slider)=>{
212
+ setCurrentSlide(slider.track.details.rel);
213
+ previousIndex.current = slider.track.details.rel;
214
+ onChangeActive && onChangeActive(slider.track.details.rel);
215
+ },
216
+ created: (slider)=>{
217
+ setLoaded(true);
218
+ setSlider(slider);
219
+ setCurrentSlide(slider.track?.details?.rel ?? 0);
220
+ onCreated && onCreated(slider);
221
+ removeInitialCarouselGap();
222
+ },
223
+ updated: (slider)=>{
224
+ onLoaded && onLoaded(true);
225
+ onUpdated && onUpdated(slider);
226
+ },
227
+ autoplay: {
228
+ delay: (setting?.autoplayTimeout ?? 1) * 1000,
229
+ pauseOnHover: setting?.pauseOnHover,
230
+ enable: mode === 'edit' ? isFirstPreviewClicked ? setting?.runPreview && setting?.autoplay : false : setting?.autoplay
231
+ },
232
+ animation: {
233
+ type: setting?.animationMode,
234
+ speed: styles?.playSpeed === 0 ? 1 : styles?.playSpeed ?? 500
235
+ },
236
+ dragStarted: (slider)=>{
237
+ slider.container.style.cursor = 'grabbing';
238
+ },
239
+ dragEnded: (slider)=>{
240
+ slider.container.style.cursor = 'auto';
241
+ },
242
+ animationStarted: (slider)=>{
243
+ // This code used to handle when user click next/prev button constantly
244
+ if (!isRunningAnimation.current) {
245
+ isRunningAnimation.current = true;
246
+ } else {
247
+ slider.options.defaultAnimation = {
248
+ duration: DEFAULT_PLAY_SPEED,
249
+ easing: (t)=>CAROUSEL_ANIMATION.DEFAULT.formula(t)
250
+ };
251
+ }
252
+ },
253
+ animationEnded: (slider)=>{
254
+ isRunningAnimation.current = false;
255
+ slider.options.defaultAnimation = {
256
+ duration: styles?.playSpeed === 0 ? 1 : styles?.playSpeed ?? 500,
257
+ easing (t) {
258
+ switch(setting?.animationMode){
259
+ case CAROUSEL_ANIMATION.EASE_IN.value:
260
+ return CAROUSEL_ANIMATION.EASE_IN.formula(t);
261
+ case CAROUSEL_ANIMATION.EASE_OUT.value:
262
+ return CAROUSEL_ANIMATION.EASE_OUT.formula(t);
263
+ case CAROUSEL_ANIMATION.EASE_IN_OUT.value:
264
+ return CAROUSEL_ANIMATION.EASE_IN_OUT.formula(t);
265
+ default:
266
+ return CAROUSEL_ANIMATION.EASE_IN.formula(t);
267
+ }
268
+ }
269
+ };
270
+ }
271
+ }, [
272
+ MutationPlugin,
273
+ AutoPlayPlugin,
274
+ AnimationPlugin,
275
+ FixSliderMoveBackwards
276
+ ]);
277
+ const isRenderDots = useMemo(()=>loaded && !!totalSlideItem && instanceRef.current && getResponsiveValueByScreen(setting?.dot), [
278
+ instanceRef,
279
+ loaded,
280
+ setting?.dot,
281
+ totalSlideItem
282
+ ]);
283
+ const showNavigation = useMemo(()=>{
284
+ const navigationEnableByDevice = getResponsiveValueByScreen(navigationEnable, currentDevice);
285
+ const navigationStyleByDevice = getResponsiveValueByScreen(navigationStyle, currentDevice);
286
+ return loaded && instanceRef.current && navigationEnableByDevice && navigationStyleByDevice !== 'none';
287
+ }, [
288
+ currentDevice,
289
+ instanceRef,
290
+ loaded,
291
+ navigationEnable,
292
+ navigationStyle
293
+ ]);
294
+ const getItemsPerPage = ()=>{
295
+ const items = getResponsiveValueByScreen(slidesToShow, currentDevice, 1) === 'auto' ? 1 : getResponsiveValueByScreen(slidesToShow, currentDevice, 1);
296
+ return items ?? 1;
297
+ };
298
+ const getIndexSlideItemBy = (pageIdx)=>{
299
+ let indexPage = pageIdx * getItemsPerPage();
300
+ if (indexPage >= totalSlideItem - getItemsPerPage()) {
301
+ indexPage = totalSlideItem - getItemsPerPage();
302
+ }
303
+ return indexPage;
304
+ };
305
+ const handleDotClick = (idx, isLoop)=>{
306
+ const index = setting?.sneakPeak?.[currentDevice] ? idx : isLoop ? idx : getIndexSlideItemBy(idx);
307
+ instanceRef.current?.moveToIdx(index);
308
+ previousIndex.current = index;
309
+ };
310
+ const handleNextAndPrevSlide = (action)=>{
311
+ action === 'next' ? instanceRef.current?.next() : instanceRef.current?.prev();
312
+ if (onClickArrow) {
313
+ delayTimeout && clearTimeout(delayTimeout);
314
+ delayTimeout = setTimeout(()=>onClickArrow && onClickArrow(), 500);
315
+ }
316
+ };
317
+ useImperativeHandle(ref, ()=>({
318
+ nextSlideInteraction,
319
+ previousSlideInteraction,
320
+ moveToSlideInteraction
321
+ }));
322
+ const dispatchEventSelectSlide = (index)=>{
323
+ trigger({
324
+ event: 'gp:rollback:select-slide',
325
+ selector: `[data-id="${builderProps?.uid}"]`,
326
+ element: elmRef?.current
327
+ });
328
+ trigger({
329
+ event: 'gp:select-slide',
330
+ selector: `[data-id="${builderProps?.uid}"]`,
331
+ data: index,
332
+ element: elmRef?.current
333
+ });
334
+ };
335
+ const moveToIdxInteraction = (idx)=>{
336
+ instanceRef.current?.moveToIdx(idx);
337
+ onHandleChangeSlideByInteraction && onHandleChangeSlideByInteraction(idx);
338
+ };
339
+ const handleDirectionalSlide = (params, direction)=>{
340
+ const { key, data, isRollback, element } = params;
341
+ const currentIndex = Math.max(instanceRef.current?.track?.details?.rel ?? 0, 0);
342
+ if (isRollback && data === undefined) {
343
+ return;
344
+ }
345
+ if (isRollback) {
346
+ if (direction === 'specific') {
347
+ const { previousData } = getInteractionPreviousData(element, key);
348
+ moveToIdxInteraction(Number(previousData));
349
+ } else {
350
+ // For next/previous, move in opposite direction during rollback
351
+ const newIndex = direction === 'next' ? currentIndex - 1 : currentIndex + 1;
352
+ moveToIdxInteraction(newIndex);
353
+ }
354
+ return;
355
+ }
356
+ // Save current state and move to new position
357
+ const indexToSave = direction === 'specific' ? Math.max(previousIndex.current, 0) : currentIndex;
358
+ saveToElementInteractionData(element, key, indexToSave.toString());
359
+ const targetIndex = direction === 'specific' ? Number(data) : direction === 'next' ? currentIndex + 1 : currentIndex - 1;
360
+ moveToIdxInteraction(targetIndex);
361
+ };
362
+ const nextSlideInteraction = (params)=>{
363
+ handleDirectionalSlide(params, 'next');
364
+ };
365
+ const previousSlideInteraction = (params)=>{
366
+ handleDirectionalSlide(params, 'previous');
367
+ };
368
+ const moveToSlideInteraction = (params)=>{
369
+ handleDirectionalSlide(params, 'specific');
370
+ };
371
+ useEffect(()=>{
372
+ const selector = `[data-id="${builderProps?.uid}"]`;
373
+ onListener({
374
+ event: 'gp:change-next-slide',
375
+ selector,
376
+ elementRef: localRef
377
+ }, (params)=>{
378
+ const { data, isRollback, uniqueStorageKey } = params || {};
379
+ nextSlideInteraction({
380
+ element: localRef.current,
381
+ data,
382
+ isRollback,
383
+ key: uniqueStorageKey
384
+ });
385
+ });
386
+ onListener({
387
+ event: 'gp:change-previous-slide',
388
+ selector,
389
+ elementRef: localRef
390
+ }, (params)=>{
391
+ const { data, isRollback, uniqueStorageKey } = params || {};
392
+ previousSlideInteraction({
393
+ element: localRef.current,
394
+ data,
395
+ isRollback,
396
+ key: uniqueStorageKey
397
+ });
398
+ });
399
+ onListener({
400
+ event: 'gp:change-image-step',
401
+ selector,
402
+ elementRef: localRef
403
+ }, (params)=>{
404
+ const { data, isRollback, uniqueStorageKey } = params || {};
405
+ moveToSlideInteraction({
406
+ element: localRef.current,
407
+ data,
408
+ isRollback,
409
+ key: uniqueStorageKey
410
+ });
411
+ });
412
+ onListener({
413
+ event: 'gp:change-index-slide',
414
+ selector
415
+ }, (params)=>{
416
+ const element = document.querySelector(selector);
417
+ const { data, isRollback, uniqueStorageKey } = params || {};
418
+ moveToSlideInteraction({
419
+ element,
420
+ data,
421
+ isRollback,
422
+ key: uniqueStorageKey
423
+ });
424
+ });
425
+ }, []);
426
+ // Update slider when size change
427
+ useEffect(()=>{
428
+ instanceRef.current?.update(instanceRef.current?.options);
429
+ }, [
430
+ instanceRef,
431
+ setting
432
+ ]);
433
+ useEffect(()=>{
434
+ const moveToIndexListenEvent = (event)=>{
435
+ if (builderProps?.uid !== event?.detail.componentUid) return;
436
+ const maxIndexSlideTo = instanceRef?.current?.track.details.maxIdx;
437
+ let indexFinal = event?.detail.index || 0;
438
+ if (maxIndexSlideTo && indexFinal > maxIndexSlideTo) indexFinal = maxIndexSlideTo;
439
+ instanceRef.current?.moveToIdx(indexFinal);
440
+ previousIndex.current = indexFinal;
441
+ };
442
+ window.addEventListener('move-to-idx', moveToIndexListenEvent);
443
+ return ()=>window.removeEventListener('move-to-idx', moveToIndexListenEvent);
444
+ }, [
445
+ instanceRef,
446
+ builderProps?.uid
447
+ ]);
448
+ // change slider when receive prop move to idx
449
+ useEffect(()=>{
450
+ if (typeof moveToIdx == 'number') {
451
+ previousIndex.current = moveToIdx;
452
+ instanceRef?.current?.moveToIdx(moveToIdx);
453
+ }
454
+ }, [
455
+ instanceRef,
456
+ moveToIdx,
457
+ isHiddenArrowWhenDisabled
458
+ ]);
459
+ return {
460
+ isInfinity,
461
+ totalSlideItem,
462
+ slideMaxIndex,
463
+ currentSlide,
464
+ loaded,
465
+ slider,
466
+ previousIndex,
467
+ localRef,
468
+ instanceRef,
469
+ showNavigation,
470
+ isRenderDots,
471
+ sliderRef,
472
+ handleDotClick,
473
+ getItemsPerPage,
474
+ handleNextAndPrevSlide,
475
+ dispatchEventSelectSlide,
476
+ getNumberOfFullWidthShow
477
+ };
478
+ };
479
+
480
+ export { useCarousel };
@@ -0,0 +1,38 @@
1
+ import { CarouselSettingsV2 } from './configs/settingV2.js';
2
+ import { SettingUIV2 } from './configs/uiV2.js';
3
+ import { SwiperCarouselPreset } from './configs/presets.js';
4
+
5
+ const config = {
6
+ tag: 'SwiperCarousel',
7
+ label: 'Swiper Carousel',
8
+ icon: `
9
+ <svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
10
+ <path fill-rule="evenodd" clip-rule="evenodd" d="M4.96586 7.25C4.96586 6.14543 5.86129 5.25 6.96586 5.25H17.0346C18.1391 5.25 19.0346 6.14543 19.0346 7.25V16.7484C19.0346 17.853 18.1391 18.7484 17.0346 18.7484H6.96586C5.86129 18.7484 4.96586 17.853 4.96586 16.7484V7.25ZM9.36039 6.25H6.96586C6.41357 6.25 5.96586 6.69772 5.96586 7.25V16.7484C5.96586 17.3007 6.41357 17.7484 6.96586 17.7484H9.36039L9.36039 6.25ZM10.3604 17.7484V6.25H14.1455V17.7484H10.3604ZM15.1455 17.7484H17.0346C17.5869 17.7484 18.0346 17.3007 18.0346 16.7484V7.25C18.0346 6.69771 17.5869 6.25 17.0346 6.25H15.1455V17.7484ZM3.31666 10.5447C3.51708 10.7346 3.52555 11.0511 3.33558 11.2515L2.61349 12.0133L3.33449 12.7691C3.52509 12.969 3.51762 13.2854 3.31781 13.4761C3.118 13.6667 2.8015 13.6592 2.6109 13.4594L1.693 12.4971C1.43561 12.2273 1.43493 11.803 1.69148 11.5324L2.60981 10.5636C2.79978 10.3632 3.11625 10.3547 3.31666 10.5447ZM20.6827 10.5458C20.8825 10.3552 21.199 10.3627 21.3896 10.5625L22.3075 11.5247C22.5649 11.7946 22.5656 12.2188 22.309 12.4894L21.3907 13.4583C21.2007 13.6587 20.8843 13.6672 20.6839 13.4772C20.4834 13.2872 20.475 12.9707 20.6649 12.7703L21.387 12.0085L20.666 11.2527C20.4754 11.0529 20.4829 10.7364 20.6827 10.5458ZM21.5839 12.215C21.5838 12.2149 21.584 12.2151 21.5839 12.215V12.215Z" fill="white"/>
11
+ </svg>
12
+ `,
13
+ settings: CarouselSettingsV2,
14
+ ui: [],
15
+ uiV2: SettingUIV2,
16
+ presets: SwiperCarouselPreset,
17
+ editorConfigs: {
18
+ slots: {
19
+ children: false
20
+ },
21
+ placeholder: {
22
+ // notAppendBeforeAfter: true,
23
+ notAppendTags: [
24
+ 'MarqueeItem',
25
+ 'Marquee'
26
+ ]
27
+ }
28
+ },
29
+ locales: {
30
+ editor: {
31
+ en: {
32
+ no_slider: 'No Slider'
33
+ }
34
+ }
35
+ }
36
+ };
37
+
38
+ export { config as default };
@@ -0,0 +1,36 @@
1
+ const config = {
2
+ tag: 'SwiperCarouselItem',
3
+ label: 'Swiper Carousel Item',
4
+ settings: [
5
+ {
6
+ id: 'setting',
7
+ controls: []
8
+ },
9
+ {
10
+ id: 'style',
11
+ controls: []
12
+ }
13
+ ],
14
+ editorConfigs: {
15
+ component: {
16
+ noSetting: true,
17
+ noDelete: true,
18
+ noDuplicate: true,
19
+ noDragDrop: true
20
+ },
21
+ slots: {
22
+ children: true
23
+ },
24
+ sideBar: {
25
+ hide: true
26
+ },
27
+ toolbar: {
28
+ hide: true
29
+ },
30
+ placeholder: {
31
+ notAppendBeforeAfter: true
32
+ }
33
+ }
34
+ };
35
+
36
+ export { config as default };
@@ -0,0 +1,85 @@
1
+ const SwiperCarouselPreset = [
2
+ {
3
+ id: 'swiper-carousel',
4
+ name: {
5
+ en: 'Swiper Carousel'
6
+ },
7
+ icon: {
8
+ desktop: `
9
+ <svg width="96" height="48" viewBox="0 0 96 48" fill="none" xmlns="http://www.w3.org/2000/svg">
10
+ <rect width="96" height="48" rx="3" fill="#424242"/>
11
+ <path fill-rule="evenodd" clip-rule="evenodd" d="M13.8828 18.1302C14.0391 18.3037 14.0391 18.5851 13.8828 18.7587L10.9657 22L13.8828 25.2413C14.0391 25.4149 14.0391 25.6963 13.8828 25.8698C13.7266 26.0434 13.4734 26.0434 13.3172 25.8698L10.1172 22.3143C9.96095 22.1407 9.96095 21.8593 10.1172 21.6857L13.3172 18.1302C13.4734 17.9566 13.7266 17.9566 13.8828 18.1302Z" fill="#F9F9F9"/>
12
+ <path fill-rule="evenodd" clip-rule="evenodd" d="M82.1172 18.1302C82.2734 17.9566 82.5266 17.9566 82.6828 18.1302L85.8828 21.6857C86.0391 21.8593 86.0391 22.1407 85.8828 22.3143L82.6828 25.8698C82.5266 26.0434 82.2734 26.0434 82.1172 25.8698C81.9609 25.6963 81.9609 25.4149 82.1172 25.2413L85.0343 22L82.1172 18.7587C81.9609 18.5851 81.9609 18.3037 82.1172 18.1302Z" fill="#F9F9F9"/>
13
+ <circle cx="40" cy="38" r="2" fill="#F9F9F9"/>
14
+ <circle cx="48" cy="38" r="2" fill="#757575"/>
15
+ <circle cx="56" cy="38" r="2" fill="#757575"/>
16
+ </svg>
17
+ `
18
+ },
19
+ components: [
20
+ {
21
+ tag: 'SwiperCarousel',
22
+ label: 'Swiper Carousel',
23
+ settings: {
24
+ childItem: [
25
+ 'Item 1',
26
+ 'Item 2',
27
+ 'Item 3',
28
+ 'Item 4',
29
+ 'Item 5'
30
+ ],
31
+ itemNumber: {
32
+ desktop: 1,
33
+ tablet: 1,
34
+ mobile: 1
35
+ }
36
+ },
37
+ styles: {
38
+ sizeSetting: {
39
+ desktop: {
40
+ width: '100%'
41
+ }
42
+ }
43
+ },
44
+ advanced: {
45
+ 'spacing-setting': {
46
+ desktop: {
47
+ margin: {
48
+ bottom: 'var(--g-s-l)'
49
+ }
50
+ }
51
+ }
52
+ },
53
+ childrens: [
54
+ {
55
+ tag: 'SwiperCarouselItem',
56
+ label: 'Swiper Carousel Item',
57
+ childrens: []
58
+ },
59
+ {
60
+ tag: 'SwiperCarouselItem',
61
+ label: 'Swiper Carousel Item',
62
+ childrens: []
63
+ },
64
+ {
65
+ tag: 'SwiperCarouselItem',
66
+ label: 'Swiper Carousel Item',
67
+ childrens: []
68
+ },
69
+ {
70
+ tag: 'SwiperCarouselItem',
71
+ label: 'Swiper Carousel Item',
72
+ childrens: []
73
+ },
74
+ {
75
+ tag: 'SwiperCarouselItem',
76
+ label: 'Swiper Carousel Item',
77
+ childrens: []
78
+ }
79
+ ]
80
+ }
81
+ ]
82
+ }
83
+ ];
84
+
85
+ export { SwiperCarouselPreset };