@gem-sdk/components 2.0.0-dev.370 → 2.0.0-dev.372

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 (132) hide show
  1. package/dist/cjs/article/setting/configs/ArticleDate/presets.js +1 -1
  2. package/dist/cjs/article/setting/configs/ArticleDate/settings.js +3 -0
  3. package/dist/cjs/article/setting/configs/ArticleReadMore/settings.js +20 -1
  4. package/dist/cjs/article/setting/configs/ArticleReadMore/uiV2.js +10 -10
  5. package/dist/cjs/builder.js +2 -2
  6. package/dist/cjs/button/setting/configs/settings.js +0 -14
  7. package/dist/cjs/carousel/arrow/Arrow.js +52 -0
  8. package/dist/cjs/carousel/arrow/Arrow.liquid.js +46 -0
  9. package/dist/cjs/carousel/{components/common/arrow.js → arrow/common/common.js} +13 -11
  10. package/dist/cjs/carousel/arrow/common/getClass.js +50 -0
  11. package/dist/cjs/carousel/arrow/common/getStyle.js +84 -0
  12. package/dist/cjs/carousel/carousel-item/CarouselItem.js +32 -0
  13. package/dist/cjs/carousel/carousel-item/CarouselItem.liquid.js +38 -0
  14. package/dist/cjs/carousel/carousel-item/common/getClass.js +29 -0
  15. package/dist/cjs/carousel/{components/CarouselItem.liquid.js → carousel-item/common/getStyle.js} +30 -47
  16. package/dist/cjs/carousel/carousel-item/hook/useCarouseItem.js +14 -0
  17. package/dist/cjs/carousel/components/const/index.js +5 -0
  18. package/dist/cjs/carousel/dots/Dots.js +51 -0
  19. package/dist/cjs/carousel/dots/Dots.liquid.js +26 -0
  20. package/dist/cjs/carousel/dots/common/common.js +46 -0
  21. package/dist/cjs/carousel/dots/common/getClass.js +40 -0
  22. package/dist/cjs/carousel/dots/common/getStyle.js +33 -0
  23. package/dist/cjs/carousel/dots/hook/useDotsSetting.js +21 -0
  24. package/dist/cjs/carousel/index.js +1 -2
  25. package/dist/cjs/carousel/next.js +2 -2
  26. package/dist/cjs/carousel/root/Carousel.js +129 -0
  27. package/dist/cjs/carousel/root/Carousel.liquid.js +104 -0
  28. package/dist/cjs/carousel/root/common/getAttr.js +25 -0
  29. package/dist/cjs/carousel/root/common/getClass.js +135 -0
  30. package/dist/cjs/carousel/root/common/getData.js +56 -0
  31. package/dist/cjs/carousel/root/common/getStyle.js +64 -0
  32. package/dist/cjs/carousel/{components/Carousel.js → root/hook/useCarousel.js} +153 -321
  33. package/dist/cjs/carousel/setting/Carousel.js +8 -1555
  34. package/dist/cjs/carousel/setting/configs/presets.js +380 -0
  35. package/dist/cjs/carousel/setting/configs/settingV2.js +771 -0
  36. package/dist/cjs/carousel/setting/configs/uiV1.js +434 -0
  37. package/dist/cjs/carousel/setting/configs/uiV2.js +627 -0
  38. package/dist/cjs/common/components/NoDataState.js +5 -5
  39. package/dist/cjs/grid/row/commons/common.js +3 -3
  40. package/dist/cjs/index.js +2 -2
  41. package/dist/cjs/index.liquid.js +2 -2
  42. package/dist/cjs/product/components/ProductImages/ProductGalleryCarousel.js +2 -2
  43. package/dist/cjs/product/components/ProductImages/ProductImagesLightBox.js +2 -2
  44. package/dist/cjs/product/components/ProductImages/liquid/ProductGalleryCarousel.liquid.js +5 -3
  45. package/dist/cjs/product/components/ProductImagesV2/common/getAttr.js +1 -0
  46. package/dist/cjs/product/components/ProductImagesV2/common/productFeaturedImage.js +1 -1
  47. package/dist/cjs/product/components/ProductImagesV2/common/productGallery.js +1 -1
  48. package/dist/cjs/product/components/ProductImagesV2/components/child/ProductFeaturedImageCarousel.js +5 -5
  49. package/dist/cjs/product/components/ProductImagesV2/components/feature-gallery/FeatureImageWithGallery.liquid.js +8 -4
  50. package/dist/cjs/product/components/ProductImagesV2/components/gallery-carousel/GalleryCarousel.js +2 -2
  51. package/dist/cjs/product/components/ProductImagesV2/components/gallery-carousel/GalleryCarousel.liquid.js +6 -3
  52. package/dist/cjs/product/components/ProductImagesV2/components/lightbox/ProductImagesLightBox.js +2 -2
  53. package/dist/cjs/product/components/ProductImagesV2/hooks/useProductFeaturedImageCarousel.js +3 -3
  54. package/dist/cjs/product/components/ProductList/ProductListCarouselLayout.js +2 -2
  55. package/dist/cjs/product/components/ProductList/ProductListCarouselLayout.liquid.js +5 -3
  56. package/dist/cjs/product/components/ProductList/common/index.js +5 -5
  57. package/dist/cjs/product/components/ProductVariants/common/main/getAttr.js +1 -1
  58. package/dist/cjs/text/components/Text.js +3 -3
  59. package/dist/esm/article/setting/configs/ArticleDate/presets.js +1 -1
  60. package/dist/esm/article/setting/configs/ArticleDate/settings.js +3 -0
  61. package/dist/esm/article/setting/configs/ArticleReadMore/settings.js +20 -1
  62. package/dist/esm/article/setting/configs/ArticleReadMore/uiV2.js +10 -10
  63. package/dist/esm/builder.js +2 -2
  64. package/dist/esm/button/setting/configs/settings.js +0 -14
  65. package/dist/esm/carousel/arrow/Arrow.js +48 -0
  66. package/dist/esm/carousel/arrow/Arrow.liquid.js +42 -0
  67. package/dist/esm/carousel/{components/common/arrow.js → arrow/common/common.js} +12 -10
  68. package/dist/esm/carousel/arrow/common/getClass.js +48 -0
  69. package/dist/esm/carousel/arrow/common/getStyle.js +82 -0
  70. package/dist/esm/carousel/carousel-item/CarouselItem.js +28 -0
  71. package/dist/esm/carousel/carousel-item/CarouselItem.liquid.js +34 -0
  72. package/dist/esm/carousel/carousel-item/common/getClass.js +27 -0
  73. package/dist/esm/carousel/{components/CarouselItem.liquid.js → carousel-item/common/getStyle.js} +31 -46
  74. package/dist/esm/carousel/carousel-item/hook/useCarouseItem.js +12 -0
  75. package/dist/esm/carousel/components/const/index.js +3 -0
  76. package/dist/esm/carousel/dots/Dots.js +47 -0
  77. package/dist/esm/carousel/dots/Dots.liquid.js +22 -0
  78. package/dist/esm/carousel/dots/common/common.js +43 -0
  79. package/dist/esm/carousel/dots/common/getClass.js +38 -0
  80. package/dist/esm/carousel/dots/common/getStyle.js +31 -0
  81. package/dist/esm/carousel/dots/hook/useDotsSetting.js +19 -0
  82. package/dist/esm/carousel/index.js +1 -2
  83. package/dist/esm/carousel/next.js +2 -2
  84. package/dist/esm/carousel/root/Carousel.js +125 -0
  85. package/dist/esm/carousel/root/Carousel.liquid.js +100 -0
  86. package/dist/esm/carousel/root/common/getAttr.js +23 -0
  87. package/dist/esm/carousel/root/common/getClass.js +133 -0
  88. package/dist/esm/carousel/root/common/getData.js +54 -0
  89. package/dist/esm/carousel/root/common/getStyle.js +62 -0
  90. package/dist/esm/carousel/{components/Carousel.js → root/hook/useCarousel.js} +150 -316
  91. package/dist/esm/carousel/setting/Carousel.js +8 -1555
  92. package/dist/esm/carousel/setting/configs/presets.js +378 -0
  93. package/dist/esm/carousel/setting/configs/settingV2.js +769 -0
  94. package/dist/esm/carousel/setting/configs/uiV1.js +432 -0
  95. package/dist/esm/carousel/setting/configs/uiV2.js +625 -0
  96. package/dist/esm/common/components/NoDataState.js +6 -6
  97. package/dist/esm/grid/row/commons/common.js +1 -1
  98. package/dist/esm/index.js +2 -2
  99. package/dist/esm/index.liquid.js +2 -2
  100. package/dist/esm/product/components/ProductImages/ProductGalleryCarousel.js +2 -2
  101. package/dist/esm/product/components/ProductImages/ProductImagesLightBox.js +2 -2
  102. package/dist/esm/product/components/ProductImages/liquid/ProductGalleryCarousel.liquid.js +5 -3
  103. package/dist/esm/product/components/ProductImagesV2/common/getAttr.js +1 -0
  104. package/dist/esm/product/components/ProductImagesV2/common/productFeaturedImage.js +1 -1
  105. package/dist/esm/product/components/ProductImagesV2/common/productGallery.js +1 -1
  106. package/dist/esm/product/components/ProductImagesV2/components/child/ProductFeaturedImageCarousel.js +5 -5
  107. package/dist/esm/product/components/ProductImagesV2/components/feature-gallery/FeatureImageWithGallery.liquid.js +8 -4
  108. package/dist/esm/product/components/ProductImagesV2/components/gallery-carousel/GalleryCarousel.js +2 -2
  109. package/dist/esm/product/components/ProductImagesV2/components/gallery-carousel/GalleryCarousel.liquid.js +6 -3
  110. package/dist/esm/product/components/ProductImagesV2/components/lightbox/ProductImagesLightBox.js +2 -2
  111. package/dist/esm/product/components/ProductImagesV2/hooks/useProductFeaturedImageCarousel.js +3 -3
  112. package/dist/esm/product/components/ProductList/ProductListCarouselLayout.js +2 -2
  113. package/dist/esm/product/components/ProductList/ProductListCarouselLayout.liquid.js +5 -3
  114. package/dist/esm/product/components/ProductList/common/index.js +3 -3
  115. package/dist/esm/product/components/ProductVariants/common/main/getAttr.js +1 -1
  116. package/dist/esm/text/components/Text.js +4 -4
  117. package/dist/types/index.d.ts +164 -67
  118. package/package.json +3 -3
  119. package/dist/cjs/carousel/components/Arrow.js +0 -110
  120. package/dist/cjs/carousel/components/Arrow.liquid.js +0 -103
  121. package/dist/cjs/carousel/components/Carousel.liquid.js +0 -256
  122. package/dist/cjs/carousel/components/CarouselItem.js +0 -88
  123. package/dist/cjs/carousel/components/Dots.js +0 -69
  124. package/dist/cjs/carousel/components/Dots.liquid.js +0 -23
  125. package/dist/cjs/carousel/components/common/dots.js +0 -57
  126. package/dist/esm/carousel/components/Arrow.js +0 -106
  127. package/dist/esm/carousel/components/Arrow.liquid.js +0 -99
  128. package/dist/esm/carousel/components/Carousel.liquid.js +0 -252
  129. package/dist/esm/carousel/components/CarouselItem.js +0 -84
  130. package/dist/esm/carousel/components/Dots.js +0 -65
  131. package/dist/esm/carousel/components/Dots.liquid.js +0 -19
  132. package/dist/esm/carousel/components/common/dots.js +0 -53
@@ -1,54 +1,60 @@
1
- 'use client';
2
- import { jsx, jsxs } from 'react/jsx-runtime';
3
- import { useInteraction, useCurrentDevice, useEditorMode, getResponsiveValueByScreen, makeStyleResponsive, getHeightByShapeGlobalSize, makeStyleWithDefault, getWidthByShapeGlobalSize, cls, makeContainerWidthOrHeight, isEmptyChildren, filterToolbarPreview } from '@gem-sdk/core';
4
- import { forwardRef, useRef, useState, useCallback, useMemo, useEffect, useImperativeHandle, Children, isValidElement } from 'react';
5
1
  import { useKeenSlider } from '@gem-sdk/keen-slider/react';
6
- import Arrow from './Arrow.js';
7
- import Dots from './Dots.js';
8
- import { AutoPlayPlugin } from './plugins/AutoPlayPlugin.js';
9
- import { MutationPlugin } from './plugins/MutationPlugin.js';
10
- import { DEVICES } from '../../product/components/ProductVariants/index.js';
11
- import { FixSliderMoveBackwards } from './plugins/FixSliderMoveBackwards.js';
12
- import { CAROUSEL_ANIMATION, DEFAULT_PLAY_SPEED, AnimationPlugin } from './plugins/AnimationPlugin.js';
13
- import useTrackPreviewPause from './hooks/useTrackPreviewPause.js';
14
- import { mappingNavigationCarousel } from './common/arrow.js';
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, 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';
15
10
 
16
- const Carousel = /*#__PURE__*/ forwardRef(({ children, builderAttrs, builderProps, style, styles, moveToIdx, isHiddenArrowWhenDisabled = true, hiddenDotWhenOnlyOne, onLoaded, onChangeActive, onUpdated, onCreated, onClickArrow, onHandleChangeSlideByInteraction, elmRef, rootClass, slidesClass, rootAttrs, fullHeight, ...props }, ref)=>{
17
- const setting = mappingNavigationCarousel(props.setting);
18
- const localRef = useRef();
19
- const previousIndex = useRef(moveToIdx ?? 0);
20
- const isRunningAnimation = useRef(false);
21
- const [loaded, setLoaded] = useState(false);
22
- const [slider, setSlider] = useState();
23
- const [currentSlide, setCurrentSlide] = useState(setting?.defaultCurrentSlider ?? 0);
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);
24
17
  const [totalSlideItem, setTotalSlideItem] = useState(0);
25
18
  const [slideMaxIndex, setSlideMaxIndex] = useState(0);
26
- const [isInfinity, setIsInfinity] = useState(false);
27
- const { isFirstPreviewClicked } = useTrackPreviewPause(setting?.runPreview);
28
- const { onListener, saveToElementInteractionData, getInteractionPreviousData, trigger } = useInteraction();
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 DEVICES = [
28
+ 'desktop',
29
+ 'tablet',
30
+ 'mobile'
31
+ ];
29
32
  const currentDevice = useCurrentDevice();
30
33
  const mode = useEditorMode();
31
- let delayTimeout;
32
- const getSlideToShowFromOldData = useCallback(()=>{
34
+ const { isFirstPreviewClicked } = useTrackPreviewPause(setting?.runPreview);
35
+ const { onListener, saveToElementInteractionData, getInteractionPreviousData, trigger } = useInteraction();
36
+ const getItemNumberFromOldData = useCallback(()=>{
33
37
  if (!setting?.slidesToShow) return null;
34
38
  const result = {};
35
39
  DEVICES.forEach((device)=>{
36
40
  const value = getResponsiveValueByScreen(setting?.slidesToShow, device);
37
- result[device] = value ? value === 'auto' ? 4 : value : 0;
41
+ result[device] = value ? value === 'auto' ? 4 : Math.floor(value) : 0;
38
42
  });
39
43
  return result;
40
44
  }, [
45
+ DEVICES,
41
46
  setting?.slidesToShow
42
47
  ]);
43
- const getItemNumberFromOldData = useCallback(()=>{
48
+ const getSlideToShowFromOldData = useCallback(()=>{
44
49
  if (!setting?.slidesToShow) return null;
45
50
  const result = {};
46
51
  DEVICES.forEach((device)=>{
47
52
  const value = getResponsiveValueByScreen(setting?.slidesToShow, device);
48
- result[device] = value ? value === 'auto' ? 4 : Math.floor(value) : 0;
53
+ result[device] = value ? value === 'auto' ? 4 : value : 0;
49
54
  });
50
55
  return result;
51
56
  }, [
57
+ DEVICES,
52
58
  setting?.slidesToShow
53
59
  ]);
54
60
  const slidesToShow = useMemo(()=>{
@@ -66,6 +72,7 @@ const Carousel = /*#__PURE__*/ forwardRef(({ children, builderAttrs, builderProp
66
72
  });
67
73
  return result;
68
74
  }, [
75
+ DEVICES,
69
76
  getSlideToShowFromOldData,
70
77
  setting?.itemNumber,
71
78
  setting?.sneakPeak,
@@ -80,35 +87,6 @@ const Carousel = /*#__PURE__*/ forwardRef(({ children, builderAttrs, builderProp
80
87
  getItemNumberFromOldData,
81
88
  setting?.itemNumber
82
89
  ]);
83
- const slideItemsPerPage = ()=>{
84
- const items = getResponsiveValueByScreen(slidesToShow, currentDevice, 1) === 'auto' ? 1 : getResponsiveValueByScreen(slidesToShow, currentDevice, 1);
85
- return items ?? 1;
86
- };
87
- const { sizeSetting } = styles ?? {};
88
- const { navigationStyle, navigationEnable = {
89
- desktop: true
90
- }, arrowButtonSize, arrowBackgroundColor, arrowGapToEachSide = '16', arrowBorder, roundedArrow, arrowIconSize, arrowCustomColor, showWhenHover, enableAction = {
91
- desktop: true
92
- } } = setting ?? {};
93
- const loop = useMemo(()=>{
94
- const result = setting?.loop;
95
- DEVICES.forEach((device)=>{
96
- return {
97
- ...result,
98
- [device]: getResponsiveValueByScreen(enableAction) ? result?.[device] : false
99
- };
100
- });
101
- return result;
102
- }, [
103
- enableAction,
104
- setting?.loop
105
- ]);
106
- const styleHeight = makeStyleResponsive('h', getHeightByShapeGlobalSize(sizeSetting));
107
- const styleWidth = makeStyleWithDefault('w', getWidthByShapeGlobalSize(sizeSetting, true), {
108
- desktop: '--g-ct-w',
109
- tablet: '--g-ct-w',
110
- mobile: '--g-ct-w'
111
- });
112
90
  const getNumberOfFullWidthShow = useCallback((device)=>{
113
91
  const sneakPeekTypeByNumber = getResponsiveValueByScreen(setting?.sneakPeakType, device) === 'center' ? 2 : 1;
114
92
  return typeof getResponsiveValueByScreen(itemNumber, device, 4) === 'number' ? getResponsiveValueByScreen(itemNumber, device, 4) - sneakPeekTypeByNumber : undefined;
@@ -116,7 +94,6 @@ const Carousel = /*#__PURE__*/ forwardRef(({ children, builderAttrs, builderProp
116
94
  setting?.sneakPeakType,
117
95
  itemNumber
118
96
  ]);
119
- const enabledSneakPeak = setting?.sneakPeak?.[currentDevice];
120
97
  const getOriginCarousel = useMemo(()=>(device)=>{
121
98
  const origin = getResponsiveValueByScreen(setting?.sneakPeakType, device) === 'center' && getResponsiveValueByScreen(setting?.sneakPeak, device) ? 'center' : 'auto';
122
99
  return origin;
@@ -126,7 +103,7 @@ const Carousel = /*#__PURE__*/ forwardRef(({ children, builderAttrs, builderProp
126
103
  ]);
127
104
  const getMaxNavigationWhenSneak = useMemo(()=>(device)=>{
128
105
  if (getOriginCarousel(device) !== 'center') return {};
129
- const totalItems = setting?.childItem?.length ?? 1;
106
+ const totalItems = setting?.childItem?.length || 1;
130
107
  let itemShow = Number(getResponsiveValueByScreen(slidesToShow, device, 1)) || 1 + 1;
131
108
  if (setting?.sneakPeak?.[currentDevice]) {
132
109
  itemShow = Math.trunc(Number(getNumberOfFullWidthShow(device)));
@@ -148,25 +125,10 @@ const Carousel = /*#__PURE__*/ forwardRef(({ children, builderAttrs, builderProp
148
125
  setting?.sneakPeak,
149
126
  getNumberOfFullWidthShow
150
127
  ]);
151
- const makeSpacing = ()=>{
152
- if (loaded) return;
153
- let result = {};
154
- DEVICES.forEach((device)=>{
155
- const isVertical = getResponsiveValueByScreen(setting?.vertical, device);
156
- const spacing = getResponsiveValueByScreen(styles?.spacing, device);
157
- const devicePrefix = device !== 'desktop' ? `-${device}` : '';
158
- const key = isVertical ? `--rg${devicePrefix}` : `--cg${devicePrefix}`;
159
- result = {
160
- ...result,
161
- [key]: `${spacing}px`
162
- };
163
- });
164
- return result;
165
- };
166
128
  const removeInitialCarouselGap = ()=>{
167
- const sliderSelector = document.querySelectorAll(`.gp-carousel-slider-${builderProps?.uid}`);
168
- if (!sliderSelector) return;
169
- sliderSelector.forEach((selector)=>{
129
+ const sliderElm = document.querySelectorAll(`.${sliderSelector}`);
130
+ if (!sliderElm) return;
131
+ sliderElm.forEach((selector)=>{
170
132
  selector?.style.removeProperty('--cg');
171
133
  selector?.style.removeProperty('--cg-tablet');
172
134
  selector?.style.removeProperty('--cg-mobile');
@@ -187,7 +149,7 @@ const Carousel = /*#__PURE__*/ forwardRef(({ children, builderAttrs, builderProp
187
149
  setSlideMaxIndex(slider?.track?.details?.maxIdx);
188
150
  },
189
151
  defaultAnimation: {
190
- duration: styles?.playSpeed === 0 ? 1 : styles?.playSpeed || 500,
152
+ duration: styles?.playSpeed === 0 ? 1 : styles?.playSpeed ?? 500,
191
153
  easing: (t)=>{
192
154
  switch(setting?.animationMode){
193
155
  case CAROUSEL_ANIMATION.EASE_IN.value:
@@ -210,7 +172,7 @@ const Carousel = /*#__PURE__*/ forwardRef(({ children, builderAttrs, builderProp
210
172
  breakpoints: {
211
173
  '(max-width: 9999px)': {
212
174
  slides: {
213
- perView: getResponsiveValueByScreen(slidesToShow, 'desktop', 4) || 1,
175
+ perView: getResponsiveValueByScreen(slidesToShow, 'desktop', 4) ?? 1,
214
176
  spacing: getResponsiveValueByScreen(styles?.spacing, 'desktop'),
215
177
  origin: getOriginCarousel('desktop'),
216
178
  numberOfFullWidthShow: getNumberOfFullWidthShow('desktop')
@@ -220,7 +182,7 @@ const Carousel = /*#__PURE__*/ forwardRef(({ children, builderAttrs, builderProp
220
182
  drag: getResponsiveValueByScreen(mode == 'edit' ? {
221
183
  desktop: false
222
184
  } : setting?.enableDrag, 'desktop'),
223
- initial: moveToIdx || 0,
185
+ initial: moveToIdx ?? 0,
224
186
  range: getMaxNavigationWhenSneak('desktop')
225
187
  },
226
188
  '(max-width: 1024px)': {
@@ -250,7 +212,7 @@ const Carousel = /*#__PURE__*/ forwardRef(({ children, builderAttrs, builderProp
250
212
  drag: getResponsiveValueByScreen(mode == 'edit' ? {
251
213
  mobile: false
252
214
  } : setting?.enableDrag, 'mobile'),
253
- initial: moveToIdx || 0,
215
+ initial: moveToIdx ?? 0,
254
216
  range: getMaxNavigationWhenSneak('mobile')
255
217
  }
256
218
  },
@@ -277,7 +239,7 @@ const Carousel = /*#__PURE__*/ forwardRef(({ children, builderAttrs, builderProp
277
239
  },
278
240
  animation: {
279
241
  type: setting?.animationMode,
280
- speed: styles?.playSpeed === 0 ? 1 : styles?.playSpeed || 500
242
+ speed: styles?.playSpeed === 0 ? 1 : styles?.playSpeed ?? 500
281
243
  },
282
244
  dragStarted: (slider)=>{
283
245
  slider.container.style.cursor = 'grabbing';
@@ -299,7 +261,7 @@ const Carousel = /*#__PURE__*/ forwardRef(({ children, builderAttrs, builderProp
299
261
  animationEnded: (slider)=>{
300
262
  isRunningAnimation.current = false;
301
263
  slider.options.defaultAnimation = {
302
- duration: styles?.playSpeed === 0 ? 1 : styles?.playSpeed || 500,
264
+ duration: styles?.playSpeed === 0 ? 1 : styles?.playSpeed ?? 500,
303
265
  easing (t) {
304
266
  switch(setting?.animationMode){
305
267
  case CAROUSEL_ANIMATION.EASE_IN.value:
@@ -320,77 +282,69 @@ const Carousel = /*#__PURE__*/ forwardRef(({ children, builderAttrs, builderProp
320
282
  AnimationPlugin,
321
283
  FixSliderMoveBackwards
322
284
  ]);
323
- // Update slider when size change
324
- useEffect(()=>{
325
- instanceRef.current?.update(instanceRef.current?.options);
326
- }, [
327
- instanceRef,
328
- setting
329
- ]);
330
- useEffect(()=>{
331
- const moveToIndexListenEvent = (event)=>{
332
- if (builderProps?.uid !== event?.detail.componentUid) return;
333
- const maxIndexSlideTo = instanceRef?.current?.track.details.maxIdx;
334
- let indexFinal = event?.detail.index || 0;
335
- if (maxIndexSlideTo && indexFinal > maxIndexSlideTo) indexFinal = maxIndexSlideTo;
336
- instanceRef.current?.moveToIdx(indexFinal);
337
- previousIndex.current = indexFinal;
338
- };
339
- window.addEventListener('move-to-idx', moveToIndexListenEvent);
340
- return ()=>window.removeEventListener('move-to-idx', moveToIndexListenEvent);
341
- }, [
285
+ const isRenderDots = useMemo(()=>loaded && !!totalSlideItem && instanceRef.current && getResponsiveValueByScreen(setting?.dot), [
342
286
  instanceRef,
343
- builderProps?.uid
287
+ loaded,
288
+ setting?.dot,
289
+ totalSlideItem
344
290
  ]);
345
- // change slider when receive prop move to idx
346
- useEffect(()=>{
347
- if (typeof moveToIdx == 'number') {
348
- previousIndex.current = moveToIdx;
349
- instanceRef?.current?.moveToIdx(moveToIdx);
350
- }
291
+ const showNavigation = useMemo(()=>{
292
+ const navigationEnableByDevice = getResponsiveValueByScreen(navigationEnable, currentDevice);
293
+ const navigationStyleByDevice = getResponsiveValueByScreen(navigationStyle, currentDevice);
294
+ return loaded && instanceRef.current && navigationEnableByDevice && navigationStyleByDevice !== 'none';
351
295
  }, [
296
+ currentDevice,
352
297
  instanceRef,
353
- moveToIdx,
354
- isHiddenArrowWhenDisabled
298
+ loaded,
299
+ navigationEnable,
300
+ navigationStyle
355
301
  ]);
302
+ const getItemsPerPage = ()=>{
303
+ const items = getResponsiveValueByScreen(slidesToShow, currentDevice, 1) === 'auto' ? 1 : getResponsiveValueByScreen(slidesToShow, currentDevice, 1);
304
+ return items ?? 1;
305
+ };
356
306
  const getIndexSlideItemBy = (pageIdx)=>{
357
- let indexPage = pageIdx * slideItemsPerPage();
358
- if (indexPage >= totalSlideItem - slideItemsPerPage()) {
359
- indexPage = totalSlideItem - slideItemsPerPage();
307
+ let indexPage = pageIdx * getItemsPerPage();
308
+ if (indexPage >= totalSlideItem - getItemsPerPage()) {
309
+ indexPage = totalSlideItem - getItemsPerPage();
360
310
  }
361
311
  return indexPage;
362
312
  };
363
- const sliderNext = ()=>{
364
- instanceRef.current?.next();
313
+ const handleDotClick = (idx, isLoop)=>{
314
+ const index = setting?.sneakPeak?.[currentDevice] ? idx : isLoop ? idx : getIndexSlideItemBy(idx);
315
+ instanceRef.current?.moveToIdx(index);
316
+ previousIndex.current = index;
317
+ };
318
+ const handleNextAndPrevSlide = (action)=>{
319
+ action === 'next' ? instanceRef.current?.next() : instanceRef.current?.prev();
365
320
  if (onClickArrow) {
366
321
  delayTimeout && clearTimeout(delayTimeout);
367
322
  delayTimeout = setTimeout(()=>onClickArrow && onClickArrow(), 500);
368
323
  }
369
324
  };
370
- // eslint-disable-next-line react-hooks/exhaustive-deps
325
+ useImperativeHandle(ref, ()=>({
326
+ nextSlideInteraction,
327
+ previousSlideInteraction,
328
+ moveToSlideInteraction
329
+ }));
330
+ const dispatchEventSelectSlide = (index)=>{
331
+ trigger({
332
+ event: 'gp:rollback:select-slide',
333
+ selector: `[data-id="${builderProps?.uid}"]`,
334
+ element: elmRef?.current
335
+ });
336
+ trigger({
337
+ event: 'gp:select-slide',
338
+ selector: `[data-id="${builderProps?.uid}"]`,
339
+ data: index,
340
+ element: elmRef?.current
341
+ });
342
+ };
371
343
  const moveToIdxInteraction = (idx)=>{
372
344
  instanceRef.current?.moveToIdx(idx);
373
345
  onHandleChangeSlideByInteraction && onHandleChangeSlideByInteraction(idx);
374
346
  };
375
- const sliderPrev = ()=>{
376
- instanceRef.current?.prev();
377
- if (onClickArrow) {
378
- delayTimeout && clearTimeout(delayTimeout);
379
- delayTimeout = setTimeout(()=>onClickArrow && onClickArrow(), 500);
380
- }
381
- };
382
- const showNavigation = useMemo(()=>{
383
- const navigationEnableByDevice = getResponsiveValueByScreen(navigationEnable, currentDevice);
384
- const navigationStyleByDevice = getResponsiveValueByScreen(navigationStyle, currentDevice);
385
- return loaded && instanceRef.current && navigationEnableByDevice && navigationStyleByDevice !== 'none';
386
- }, [
387
- currentDevice,
388
- instanceRef,
389
- loaded,
390
- navigationEnable,
391
- navigationStyle
392
- ]);
393
- const handleDirectionalSlide = useCallback((params, direction)=>{
347
+ const handleDirectionalSlide = (params, direction)=>{
394
348
  const { key, data, isRollback, element } = params;
395
349
  const currentIndex = Math.max(instanceRef.current?.track?.details?.rel ?? 0, 0);
396
350
  if (isRollback && data === undefined) {
@@ -412,27 +366,16 @@ const Carousel = /*#__PURE__*/ forwardRef(({ children, builderAttrs, builderProp
412
366
  saveToElementInteractionData(element, key, indexToSave.toString());
413
367
  const targetIndex = direction === 'specific' ? Number(data) : direction === 'next' ? currentIndex + 1 : currentIndex - 1;
414
368
  moveToIdxInteraction(targetIndex);
415
- }, [
416
- getInteractionPreviousData,
417
- instanceRef,
418
- moveToIdxInteraction,
419
- saveToElementInteractionData
420
- ]);
421
- const nextSlideInteraction = useCallback((params)=>{
369
+ };
370
+ const nextSlideInteraction = (params)=>{
422
371
  handleDirectionalSlide(params, 'next');
423
- }, [
424
- handleDirectionalSlide
425
- ]);
426
- const previousSlideInteraction = useCallback((params)=>{
372
+ };
373
+ const previousSlideInteraction = (params)=>{
427
374
  handleDirectionalSlide(params, 'previous');
428
- }, [
429
- handleDirectionalSlide
430
- ]);
431
- const moveToSlideInteraction = useCallback((params)=>{
375
+ };
376
+ const moveToSlideInteraction = (params)=>{
432
377
  handleDirectionalSlide(params, 'specific');
433
- }, [
434
- handleDirectionalSlide
435
- ]);
378
+ };
436
379
  useEffect(()=>{
437
380
  const selector = `[data-id="${builderProps?.uid}"]`;
438
381
  onListener({
@@ -487,168 +430,59 @@ const Carousel = /*#__PURE__*/ forwardRef(({ children, builderAttrs, builderProp
487
430
  key: uniqueStorageKey
488
431
  });
489
432
  });
433
+ }, []);
434
+ // Update slider when size change
435
+ useEffect(()=>{
436
+ instanceRef.current?.update(instanceRef.current?.options);
490
437
  }, [
491
- builderProps?.uid,
492
- moveToSlideInteraction,
493
- nextSlideInteraction,
494
- onListener,
495
- previousSlideInteraction
438
+ instanceRef,
439
+ setting
496
440
  ]);
497
- useImperativeHandle(ref, ()=>({
498
- nextSlideInteraction,
499
- previousSlideInteraction,
500
- moveToSlideInteraction
501
- }));
502
- const dispatchEventSelectSlide = (index)=>{
503
- trigger({
504
- event: 'gp:rollback:select-slide',
505
- selector: `[data-id="${builderProps?.uid}"]`,
506
- element: elmRef?.current
507
- });
508
- trigger({
509
- event: 'gp:select-slide',
510
- selector: `[data-id="${builderProps?.uid}"]`,
511
- data: index,
512
- element: elmRef?.current
513
- });
441
+ useEffect(()=>{
442
+ const moveToIndexListenEvent = (event)=>{
443
+ if (builderProps?.uid !== event?.detail.componentUid) return;
444
+ const maxIndexSlideTo = instanceRef?.current?.track.details.maxIdx;
445
+ let indexFinal = event?.detail.index || 0;
446
+ if (maxIndexSlideTo && indexFinal > maxIndexSlideTo) indexFinal = maxIndexSlideTo;
447
+ instanceRef.current?.moveToIdx(indexFinal);
448
+ previousIndex.current = indexFinal;
449
+ };
450
+ window.addEventListener('move-to-idx', moveToIndexListenEvent);
451
+ return ()=>window.removeEventListener('move-to-idx', moveToIndexListenEvent);
452
+ }, [
453
+ instanceRef,
454
+ builderProps?.uid
455
+ ]);
456
+ // change slider when receive prop move to idx
457
+ useEffect(()=>{
458
+ if (typeof moveToIdx == 'number') {
459
+ previousIndex.current = moveToIdx;
460
+ instanceRef?.current?.moveToIdx(moveToIdx);
461
+ }
462
+ }, [
463
+ instanceRef,
464
+ moveToIdx,
465
+ isHiddenArrowWhenDisabled
466
+ ]);
467
+ return {
468
+ isInfinity,
469
+ totalSlideItem,
470
+ slideMaxIndex,
471
+ currentSlide,
472
+ loaded,
473
+ slider,
474
+ previousIndex,
475
+ localRef,
476
+ instanceRef,
477
+ showNavigation,
478
+ isRenderDots,
479
+ sliderRef,
480
+ handleDotClick,
481
+ getItemsPerPage,
482
+ handleNextAndPrevSlide,
483
+ dispatchEventSelectSlide,
484
+ getNumberOfFullWidthShow
514
485
  };
515
- return /*#__PURE__*/ jsx("div", {
516
- ref: elmRef,
517
- className: cls('gp-flex gp-w-full', rootClass),
518
- style: {
519
- ...makeStyleResponsive('jc', styles?.align)
520
- },
521
- children: /*#__PURE__*/ jsxs("div", {
522
- ref: localRef,
523
- "data-id": builderProps?.uid,
524
- ...rootAttrs,
525
- ...builderAttrs,
526
- className: cls('gp-group/carousel gp-my-0 gp-h-full gp-max-w-full tablet:gp-px-0 mobile:gp-px-0', {
527
- '!gp-flex': setting?.vertical?.[currentDevice]
528
- }, builderProps?.uid),
529
- style: {
530
- ...style,
531
- ...styleHeight,
532
- ...styleWidth
533
- },
534
- children: [
535
- /*#__PURE__*/ jsxs("div", {
536
- className: "gp-w-full gp-h-full",
537
- children: [
538
- /*#__PURE__*/ jsxs("div", {
539
- className: cls(`gp-relative gp-mx-auto gp-flex gp-items-center gp-justify-between `, {
540
- 'gp-flex-col gp-h-full': setting?.vertical?.[currentDevice],
541
- '!gp-h-full': fullHeight
542
- }),
543
- style: {
544
- ...makeContainerWidthOrHeight({
545
- vertical: setting?.vertical,
546
- dotStyle: setting?.dotStyle
547
- }),
548
- gap: arrowGapToEachSide + 'px'
549
- },
550
- children: [
551
- showNavigation && /*#__PURE__*/ jsx(Arrow, {
552
- uid: builderProps?.uid,
553
- custom: setting?.arrowCustom || '',
554
- showArrow: navigationStyle,
555
- arrowButtonSize: arrowButtonSize || {},
556
- arrowIconSize: arrowIconSize || {},
557
- arrowBackgroundColor: arrowBackgroundColor || '',
558
- arrowCustomColor: arrowCustomColor,
559
- gapToEachSize: arrowGapToEachSide,
560
- showWhenHover: showWhenHover,
561
- arrowBorder: arrowBorder || {},
562
- arrowCorner: roundedArrow || {},
563
- onClick: (e)=>{
564
- e.stopPropagation();
565
- sliderPrev();
566
- },
567
- left: true,
568
- disabled: !isInfinity && slider?.track?.details?.abs === 0,
569
- vertical: setting?.vertical,
570
- isHiddenWhenDisabled: isHiddenArrowWhenDisabled,
571
- className: "gem-slider-previous",
572
- rootId: props?.parentClass
573
- }),
574
- /*#__PURE__*/ jsx("div", {
575
- className: `gp-carousel-slider-${builderProps?.uid} gem-slider gp-h-full gp-overflow-hidden ${slidesClass} ${setting?.vertical?.[currentDevice] ? '!gp-min-h-0' : ''}`,
576
- style: {
577
- ...makeSpacing()
578
- },
579
- ref: sliderRef,
580
- children: isEmptyChildren(children) ? /*#__PURE__*/ jsx("div", {
581
- children: "No Slider"
582
- }) : Children.map(filterToolbarPreview(children), (child, index)=>{
583
- if (/*#__PURE__*/ isValidElement(child)) {
584
- return /*#__PURE__*/ jsx(child.type, {
585
- ...child.props,
586
- className: `gem-slider-item gp-w-full gem-slider-item-${builderProps?.uid} ${child.props?.className || ''}`,
587
- parentStyle: styles,
588
- parentSettings: setting,
589
- background: setting?.background,
590
- "data-index": index,
591
- index: true,
592
- dispatchEventSelectSlide: dispatchEventSelectSlide
593
- });
594
- }
595
- return null;
596
- })
597
- }),
598
- showNavigation && /*#__PURE__*/ jsx(Arrow, {
599
- uid: builderProps?.uid,
600
- custom: setting?.arrowCustom || '',
601
- showArrow: navigationStyle,
602
- arrowIconSize: arrowIconSize || {},
603
- arrowButtonSize: arrowButtonSize || {},
604
- arrowBackgroundColor: arrowBackgroundColor || '',
605
- arrowCustomColor: arrowCustomColor,
606
- gapToEachSize: arrowGapToEachSide,
607
- showWhenHover: showWhenHover,
608
- arrowBorder: arrowBorder || {},
609
- arrowCorner: roundedArrow || {},
610
- onClick: (e)=>{
611
- e.stopPropagation();
612
- sliderNext();
613
- },
614
- left: false,
615
- disabled: !isInfinity && slider?.track?.details?.abs === slideMaxIndex,
616
- vertical: setting?.vertical,
617
- isHiddenWhenDisabled: isHiddenArrowWhenDisabled,
618
- className: "gem-slider-next",
619
- rootId: props?.parentClass
620
- })
621
- ]
622
- }),
623
- loaded && !!totalSlideItem && instanceRef.current && /*#__PURE__*/ jsx(Dots, {
624
- showDots: setting?.dot,
625
- dotStyle: setting?.dotStyle,
626
- onHandleClick: (idx, isLoop)=>{
627
- const index = setting?.sneakPeak?.[currentDevice] ? idx : isLoop ? idx : getIndexSlideItemBy(idx);
628
- instanceRef.current?.moveToIdx(index);
629
- previousIndex.current = index;
630
- },
631
- totalSlideItem: totalSlideItem,
632
- slideItemsPerPage: slideItemsPerPage(),
633
- currentSlide: currentSlide,
634
- enabledSneakPeak: enabledSneakPeak,
635
- vertical: setting?.vertical,
636
- loop: loop,
637
- dotColor: setting?.dotColor,
638
- dotGapToCarousel: setting?.dotGapToCarousel,
639
- dotSize: setting?.dotSize,
640
- dotActiveColor: setting?.dotActiveColor,
641
- hiddenWhenOnlyOne: hiddenDotWhenOnlyOne,
642
- sneakPeakType: setting?.sneakPeakType,
643
- numberOfFullWidthShow: getNumberOfFullWidthShow(currentDevice),
644
- className: "carousel-dots"
645
- })
646
- ]
647
- }),
648
- filterToolbarPreview(children, true)
649
- ]
650
- })
651
- });
652
- });
486
+ };
653
487
 
654
- export { Carousel as default };
488
+ export { useCarousel };