@gem-sdk/components 2.0.0-dev.369 → 2.0.0-dev.371

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