@gem-sdk/components 2.0.0-dev.693 → 2.0.0-dev.694

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 (176) hide show
  1. package/dist/cjs/builder.js +6 -12
  2. package/dist/cjs/index.js +32 -34
  3. package/dist/cjs/index.liquid.js +10 -16
  4. package/dist/cjs/next.js +1 -3
  5. package/dist/cjs/product/components/ProductImagesV2/common/common.js +2 -1
  6. package/dist/cjs/product/index.js +4 -6
  7. package/dist/cjs/product/next.js +0 -4
  8. package/dist/cjs/setting.js +76 -78
  9. package/dist/esm/builder.js +0 -6
  10. package/dist/esm/index.js +0 -1
  11. package/dist/esm/index.liquid.js +0 -3
  12. package/dist/esm/next.js +1 -3
  13. package/dist/esm/product/components/ProductImagesV2/common/common.js +2 -1
  14. package/dist/esm/product/index.js +24 -26
  15. package/dist/esm/product/next.js +0 -4
  16. package/dist/esm/setting.js +0 -2
  17. package/dist/types/index.d.ts +116 -551
  18. package/package.json +1 -1
  19. package/dist/cjs/product/components/ProductImagesV3/common/common.js +0 -360
  20. package/dist/cjs/product/components/ProductImagesV3/common/getAttr.js +0 -192
  21. package/dist/cjs/product/components/ProductImagesV3/common/getBorderActiveCss.js +0 -26
  22. package/dist/cjs/product/components/ProductImagesV3/common/getClasses.js +0 -94
  23. package/dist/cjs/product/components/ProductImagesV3/common/getStyle.js +0 -303
  24. package/dist/cjs/product/components/ProductImagesV3/common/hoverAction.js +0 -95
  25. package/dist/cjs/product/components/ProductImagesV3/common/productFeaturedImage.js +0 -59
  26. package/dist/cjs/product/components/ProductImagesV3/common/productGallery.js +0 -266
  27. package/dist/cjs/product/components/ProductImagesV3/components/child/MediaIcon.js +0 -63
  28. package/dist/cjs/product/components/ProductImagesV3/components/child/ProductFeatureVideo.js +0 -36
  29. package/dist/cjs/product/components/ProductImagesV3/components/child/ProductFeaturedImageCarousel.js +0 -109
  30. package/dist/cjs/product/components/ProductImagesV3/components/child/ProductFeaturedImageOnly.js +0 -139
  31. package/dist/cjs/product/components/ProductImagesV3/components/child/ProductGalleryGrid.js +0 -100
  32. package/dist/cjs/product/components/ProductImagesV3/components/feature-gallery/FeatureImageWithGallery.js +0 -77
  33. package/dist/cjs/product/components/ProductImagesV3/components/feature-gallery/FeatureImageWithGallery.liquid.js +0 -300
  34. package/dist/cjs/product/components/ProductImagesV3/components/feature-only/OnlyFeatureImage.js +0 -44
  35. package/dist/cjs/product/components/ProductImagesV3/components/gallery-carousel/GalleryCarousel.js +0 -83
  36. package/dist/cjs/product/components/ProductImagesV3/components/gallery-carousel/GalleryCarousel.liquid.js +0 -182
  37. package/dist/cjs/product/components/ProductImagesV3/components/gallery-grid/GalleryGrid.js +0 -30
  38. package/dist/cjs/product/components/ProductImagesV3/components/gallery-grid/GalleryGrid.liquid.js +0 -239
  39. package/dist/cjs/product/components/ProductImagesV3/components/lightbox/ButtonOpenLightBox.js +0 -28
  40. package/dist/cjs/product/components/ProductImagesV3/components/lightbox/ProductImagesLightBox.js +0 -144
  41. package/dist/cjs/product/components/ProductImagesV3/composables/getProductImagesAttr.js +0 -14
  42. package/dist/cjs/product/components/ProductImagesV3/composables/getProductImagesClassName.js +0 -54
  43. package/dist/cjs/product/components/ProductImagesV3/composables/getProductImagesStyles.js +0 -53
  44. package/dist/cjs/product/components/ProductImagesV3/hooks/useFeatureImageWithGallery.js +0 -55
  45. package/dist/cjs/product/components/ProductImagesV3/hooks/useFilterImagesByVariant.js +0 -41
  46. package/dist/cjs/product/components/ProductImagesV3/hooks/useGalleryCarousel.js +0 -134
  47. package/dist/cjs/product/components/ProductImagesV3/hooks/useProductFeaturedImageCarousel.js +0 -203
  48. package/dist/cjs/product/components/ProductImagesV3/hooks/useProductGalleryGrid.js +0 -87
  49. package/dist/cjs/product/components/ProductImagesV3/index.js +0 -291
  50. package/dist/cjs/product/components/ProductImagesV3/index.liquid.js +0 -153
  51. package/dist/cjs/product/setting/product-image-v3/ProductFeatureImage.js +0 -252
  52. package/dist/cjs/product/setting/product-image-v3/ProductGalleryImage.js +0 -251
  53. package/dist/cjs/product/setting/product-image-v3/ProductImages.js +0 -74
  54. package/dist/cjs/product/setting/product-image-v3/configs/setting-v2/ProductFeatureImage.js +0 -388
  55. package/dist/cjs/product/setting/product-image-v3/configs/setting-v2/ProductGalleryImage.js +0 -519
  56. package/dist/cjs/product/setting/product-image-v3/configs/setting-v2/index.js +0 -337
  57. package/dist/cjs/product/setting/product-image-v3/configs/ui/FeatureNavigation.js +0 -118
  58. package/dist/cjs/product/setting/product-image-v3/configs/ui/ImageListNavigation.js +0 -119
  59. package/dist/cjs/product/setting/product-image-v3/configs/uiV1.js +0 -237
  60. package/dist/cjs/product/setting/product-image-v3/configs/uiV2.js +0 -491
  61. package/dist/cjs/swiper-carousel/arrow/Arrow.js +0 -52
  62. package/dist/cjs/swiper-carousel/arrow/Arrow.liquid.js +0 -46
  63. package/dist/cjs/swiper-carousel/arrow/common/common.js +0 -119
  64. package/dist/cjs/swiper-carousel/arrow/common/getClass.js +0 -50
  65. package/dist/cjs/swiper-carousel/arrow/common/getStyle.js +0 -84
  66. package/dist/cjs/swiper-carousel/carousel-item/SwiperItem.js +0 -34
  67. package/dist/cjs/swiper-carousel/carousel-item/SwiperItem.liquid.js +0 -38
  68. package/dist/cjs/swiper-carousel/carousel-item/common/getClass.js +0 -29
  69. package/dist/cjs/swiper-carousel/carousel-item/common/getStyle.js +0 -79
  70. package/dist/cjs/swiper-carousel/carousel-item/hook/useCarouseItem.js +0 -22
  71. package/dist/cjs/swiper-carousel/components/common/carousel.js +0 -98
  72. package/dist/cjs/swiper-carousel/components/const/index.js +0 -5
  73. package/dist/cjs/swiper-carousel/components/hooks/useTrackPreviewPause.js +0 -34
  74. package/dist/cjs/swiper-carousel/components/plugins/AnimationPlugin.js +0 -42
  75. package/dist/cjs/swiper-carousel/components/plugins/AutoPlayPlugin.js +0 -105
  76. package/dist/cjs/swiper-carousel/components/plugins/FixSliderMoveBackwards.js +0 -15
  77. package/dist/cjs/swiper-carousel/components/plugins/MutationPlugin.js +0 -45
  78. package/dist/cjs/swiper-carousel/dots/Dots.js +0 -51
  79. package/dist/cjs/swiper-carousel/dots/Dots.liquid.js +0 -26
  80. package/dist/cjs/swiper-carousel/dots/common/common.js +0 -28
  81. package/dist/cjs/swiper-carousel/dots/common/getClass.js +0 -40
  82. package/dist/cjs/swiper-carousel/dots/common/getStyle.js +0 -33
  83. package/dist/cjs/swiper-carousel/dots/hook/useDotsSetting.js +0 -21
  84. package/dist/cjs/swiper-carousel/index.js +0 -17
  85. package/dist/cjs/swiper-carousel/next.js +0 -22
  86. package/dist/cjs/swiper-carousel/root/Swiper.js +0 -128
  87. package/dist/cjs/swiper-carousel/root/Swiper.liquid.js +0 -104
  88. package/dist/cjs/swiper-carousel/root/common/getAttr.js +0 -25
  89. package/dist/cjs/swiper-carousel/root/common/getClass.js +0 -135
  90. package/dist/cjs/swiper-carousel/root/common/getData.js +0 -56
  91. package/dist/cjs/swiper-carousel/root/common/getStyle.js +0 -66
  92. package/dist/cjs/swiper-carousel/root/hook/useCarousel.js +0 -482
  93. package/dist/cjs/swiper-carousel/setting/Swiper.js +0 -42
  94. package/dist/cjs/swiper-carousel/setting/SwiperItem.js +0 -40
  95. package/dist/cjs/swiper-carousel/setting/configs/presets.js +0 -87
  96. package/dist/cjs/swiper-carousel/setting/configs/settingV2.js +0 -822
  97. package/dist/cjs/swiper-carousel/setting/configs/uiV2.js +0 -718
  98. package/dist/esm/product/components/ProductImagesV3/common/common.js +0 -344
  99. package/dist/esm/product/components/ProductImagesV3/common/getAttr.js +0 -189
  100. package/dist/esm/product/components/ProductImagesV3/common/getBorderActiveCss.js +0 -24
  101. package/dist/esm/product/components/ProductImagesV3/common/getClasses.js +0 -83
  102. package/dist/esm/product/components/ProductImagesV3/common/getStyle.js +0 -292
  103. package/dist/esm/product/components/ProductImagesV3/common/hoverAction.js +0 -92
  104. package/dist/esm/product/components/ProductImagesV3/common/productFeaturedImage.js +0 -53
  105. package/dist/esm/product/components/ProductImagesV3/common/productGallery.js +0 -251
  106. package/dist/esm/product/components/ProductImagesV3/components/child/MediaIcon.js +0 -59
  107. package/dist/esm/product/components/ProductImagesV3/components/child/ProductFeatureVideo.js +0 -32
  108. package/dist/esm/product/components/ProductImagesV3/components/child/ProductFeaturedImageCarousel.js +0 -105
  109. package/dist/esm/product/components/ProductImagesV3/components/child/ProductFeaturedImageOnly.js +0 -135
  110. package/dist/esm/product/components/ProductImagesV3/components/child/ProductGalleryGrid.js +0 -96
  111. package/dist/esm/product/components/ProductImagesV3/components/feature-gallery/FeatureImageWithGallery.js +0 -73
  112. package/dist/esm/product/components/ProductImagesV3/components/feature-gallery/FeatureImageWithGallery.liquid.js +0 -296
  113. package/dist/esm/product/components/ProductImagesV3/components/feature-only/OnlyFeatureImage.js +0 -40
  114. package/dist/esm/product/components/ProductImagesV3/components/gallery-carousel/GalleryCarousel.js +0 -79
  115. package/dist/esm/product/components/ProductImagesV3/components/gallery-carousel/GalleryCarousel.liquid.js +0 -178
  116. package/dist/esm/product/components/ProductImagesV3/components/gallery-grid/GalleryGrid.js +0 -26
  117. package/dist/esm/product/components/ProductImagesV3/components/gallery-grid/GalleryGrid.liquid.js +0 -235
  118. package/dist/esm/product/components/ProductImagesV3/components/lightbox/ButtonOpenLightBox.js +0 -24
  119. package/dist/esm/product/components/ProductImagesV3/components/lightbox/ProductImagesLightBox.js +0 -140
  120. package/dist/esm/product/components/ProductImagesV3/composables/getProductImagesAttr.js +0 -12
  121. package/dist/esm/product/components/ProductImagesV3/composables/getProductImagesClassName.js +0 -52
  122. package/dist/esm/product/components/ProductImagesV3/composables/getProductImagesStyles.js +0 -51
  123. package/dist/esm/product/components/ProductImagesV3/hooks/useFeatureImageWithGallery.js +0 -53
  124. package/dist/esm/product/components/ProductImagesV3/hooks/useFilterImagesByVariant.js +0 -39
  125. package/dist/esm/product/components/ProductImagesV3/hooks/useGalleryCarousel.js +0 -132
  126. package/dist/esm/product/components/ProductImagesV3/hooks/useProductFeaturedImageCarousel.js +0 -201
  127. package/dist/esm/product/components/ProductImagesV3/hooks/useProductGalleryGrid.js +0 -85
  128. package/dist/esm/product/components/ProductImagesV3/index.js +0 -287
  129. package/dist/esm/product/components/ProductImagesV3/index.liquid.js +0 -149
  130. package/dist/esm/product/setting/product-image-v3/ProductFeatureImage.js +0 -248
  131. package/dist/esm/product/setting/product-image-v3/ProductGalleryImage.js +0 -248
  132. package/dist/esm/product/setting/product-image-v3/ProductImages.js +0 -70
  133. package/dist/esm/product/setting/product-image-v3/configs/setting-v2/ProductFeatureImage.js +0 -384
  134. package/dist/esm/product/setting/product-image-v3/configs/setting-v2/ProductGalleryImage.js +0 -516
  135. package/dist/esm/product/setting/product-image-v3/configs/setting-v2/index.js +0 -335
  136. package/dist/esm/product/setting/product-image-v3/configs/ui/FeatureNavigation.js +0 -116
  137. package/dist/esm/product/setting/product-image-v3/configs/ui/ImageListNavigation.js +0 -117
  138. package/dist/esm/product/setting/product-image-v3/configs/uiV1.js +0 -235
  139. package/dist/esm/product/setting/product-image-v3/configs/uiV2.js +0 -489
  140. package/dist/esm/swiper-carousel/arrow/Arrow.js +0 -48
  141. package/dist/esm/swiper-carousel/arrow/Arrow.liquid.js +0 -42
  142. package/dist/esm/swiper-carousel/arrow/common/common.js +0 -111
  143. package/dist/esm/swiper-carousel/arrow/common/getClass.js +0 -48
  144. package/dist/esm/swiper-carousel/arrow/common/getStyle.js +0 -82
  145. package/dist/esm/swiper-carousel/carousel-item/SwiperItem.js +0 -30
  146. package/dist/esm/swiper-carousel/carousel-item/SwiperItem.liquid.js +0 -34
  147. package/dist/esm/swiper-carousel/carousel-item/common/getClass.js +0 -27
  148. package/dist/esm/swiper-carousel/carousel-item/common/getStyle.js +0 -77
  149. package/dist/esm/swiper-carousel/carousel-item/hook/useCarouseItem.js +0 -20
  150. package/dist/esm/swiper-carousel/components/common/carousel.js +0 -93
  151. package/dist/esm/swiper-carousel/components/const/index.js +0 -3
  152. package/dist/esm/swiper-carousel/components/hooks/useTrackPreviewPause.js +0 -30
  153. package/dist/esm/swiper-carousel/components/plugins/AnimationPlugin.js +0 -35
  154. package/dist/esm/swiper-carousel/components/plugins/AutoPlayPlugin.js +0 -103
  155. package/dist/esm/swiper-carousel/components/plugins/FixSliderMoveBackwards.js +0 -13
  156. package/dist/esm/swiper-carousel/components/plugins/MutationPlugin.js +0 -43
  157. package/dist/esm/swiper-carousel/dots/Dots.js +0 -47
  158. package/dist/esm/swiper-carousel/dots/Dots.liquid.js +0 -22
  159. package/dist/esm/swiper-carousel/dots/common/common.js +0 -26
  160. package/dist/esm/swiper-carousel/dots/common/getClass.js +0 -38
  161. package/dist/esm/swiper-carousel/dots/common/getStyle.js +0 -31
  162. package/dist/esm/swiper-carousel/dots/hook/useDotsSetting.js +0 -19
  163. package/dist/esm/swiper-carousel/index.js +0 -15
  164. package/dist/esm/swiper-carousel/next.js +0 -18
  165. package/dist/esm/swiper-carousel/root/Swiper.js +0 -124
  166. package/dist/esm/swiper-carousel/root/Swiper.liquid.js +0 -100
  167. package/dist/esm/swiper-carousel/root/common/getAttr.js +0 -23
  168. package/dist/esm/swiper-carousel/root/common/getClass.js +0 -133
  169. package/dist/esm/swiper-carousel/root/common/getData.js +0 -54
  170. package/dist/esm/swiper-carousel/root/common/getStyle.js +0 -64
  171. package/dist/esm/swiper-carousel/root/hook/useCarousel.js +0 -480
  172. package/dist/esm/swiper-carousel/setting/Swiper.js +0 -38
  173. package/dist/esm/swiper-carousel/setting/SwiperItem.js +0 -36
  174. package/dist/esm/swiper-carousel/setting/configs/presets.js +0 -85
  175. package/dist/esm/swiper-carousel/setting/configs/settingV2.js +0 -818
  176. package/dist/esm/swiper-carousel/setting/configs/uiV2.js +0 -713
@@ -1,132 +0,0 @@
1
- import { useCurrentDevice, useFeaturedImageGlobal, useEditorMode, getResponsiveValueByScreen } from '@gem-sdk/core';
2
- import { useState, useEffect, useMemo, useCallback } from 'react';
3
- import { useFilterImagesByVariant } from './useFilterImagesByVariant.js';
4
- import { handleSetSrcForProductImageList } from '../../../../image/helpers/getSrcSet.js';
5
- import { getShapeByLayout, checkDisplayGalleryByWidth } from '../common/productGallery.js';
6
-
7
- const useGalleryCarousel = (props)=>{
8
- const { builderPropUID, productImages, onHandleClick, activeIndexFormFeatureImage, onClickFeatureArrow, builderPropsClass, arrow, priorityFeatureImage, ...setting } = props;
9
- const currentDevice = useCurrentDevice();
10
- const featuredImageGlobal = useFeaturedImageGlobal();
11
- const [hasClickFeatureArrow, setHasClickFeatureArrow] = useState(onClickFeatureArrow || '');
12
- const mode = useEditorMode();
13
- const [moveToIdx, setMoveToIdx] = useState(0);
14
- const { filteredProductImages } = useFilterImagesByVariant({
15
- productImages,
16
- displayByVariant: setting?.displayByVariant,
17
- variantSelect: setting?.variantSelect
18
- });
19
- useEffect(()=>{
20
- setHasClickFeatureArrow(onClickFeatureArrow || '');
21
- // eslint-disable-next-line react-hooks/exhaustive-deps
22
- }, [
23
- onClickFeatureArrow
24
- ]);
25
- useEffect(()=>{
26
- if (hasClickFeatureArrow) {
27
- setMoveToIdx(activeIndexFormFeatureImage || 0);
28
- setHasClickFeatureArrow('');
29
- }
30
- // eslint-disable-next-line react-hooks/exhaustive-deps
31
- }, [
32
- activeIndexFormFeatureImage
33
- ]);
34
- useEffect(()=>{
35
- if (priorityFeatureImage) {
36
- const indexPriorityFeatureImage = filteredProductImages?.findIndex((item)=>item.id === priorityFeatureImage.id) || 0;
37
- setMoveToIdx(indexPriorityFeatureImage);
38
- setHasClickFeatureArrow('');
39
- }
40
- }, [
41
- priorityFeatureImage,
42
- filteredProductImages
43
- ]);
44
- useEffect(()=>{
45
- const index = filteredProductImages?.findIndex((item)=>item.id === featuredImageGlobal?.id);
46
- setMoveToIdx(index || 0);
47
- setHasClickFeatureArrow('');
48
- }, [
49
- featuredImageGlobal,
50
- filteredProductImages
51
- ]);
52
- const shapeByLayout = useMemo(()=>{
53
- return getShapeByLayout({
54
- shape: setting.shape,
55
- shapeForBottom: setting.shapeForBottom,
56
- shapeFor1Col: setting.shapeFor1Col,
57
- shapeFor2Col: setting.shapeFor2Col,
58
- shapeForFtOnly: setting.shapeForFtOnly,
59
- shapeForInsideBottom: setting.shapeForInsideBottom,
60
- shapeForInside: setting.shapeForInside
61
- }, setting.position);
62
- }, [
63
- setting.shape,
64
- setting.shapeForBottom,
65
- setting.shapeFor1Col,
66
- setting.shapeFor2Col,
67
- setting.shapeForFtOnly,
68
- setting.position,
69
- setting.shapeForInsideBottom,
70
- setting.shapeForInside
71
- ]);
72
- const handleSetSrc = useCallback(()=>{
73
- handleSetSrcForProductImageList({
74
- builderPropUID,
75
- shapeByLayout,
76
- qualityType: setting.qualityType,
77
- qualityPercent: setting.qualityPercent
78
- });
79
- }, [
80
- shapeByLayout,
81
- setting.qualityPercent,
82
- setting.qualityType,
83
- builderPropUID
84
- ]);
85
- useEffect(()=>{
86
- if (mode === 'edit') return;
87
- const $galleryImageGrid = document?.querySelector(`.gem-slider-item-${builderPropUID} .product-list-image`);
88
- if (!$galleryImageGrid) return;
89
- handleSetSrc();
90
- const observer = new ResizeObserver(()=>{
91
- handleSetSrc();
92
- });
93
- observer?.observe($galleryImageGrid, {});
94
- return ()=>{
95
- observer?.disconnect();
96
- };
97
- }, [
98
- handleSetSrc,
99
- builderPropUID,
100
- mode
101
- ]);
102
- const enableOpenLightBox = getResponsiveValueByScreen(setting.clickOpenLightBox, currentDevice);
103
- const isDisplay = useMemo(()=>{
104
- const isDisplayByWidth = checkDisplayGalleryByWidth({
105
- shapeByLayout
106
- });
107
- return getResponsiveValueByScreen(isDisplayByWidth, currentDevice);
108
- }, [
109
- shapeByLayout,
110
- currentDevice
111
- ]);
112
- const isEnableBorderActive = useMemo(()=>{
113
- return setting?.borderActive?.border !== 'none';
114
- }, [
115
- setting?.borderActive?.border
116
- ]);
117
- const isShowButtonLightbox = getResponsiveValueByScreen(setting?.clickOpenLightBox, currentDevice);
118
- const handleClickCarouselItem = (imageId)=>{
119
- onHandleClick && onHandleClick(imageId || '', enableOpenLightBox);
120
- };
121
- return {
122
- moveToIdx,
123
- isDisplay,
124
- shapeByLayout,
125
- isEnableBorderActive,
126
- isShowButtonLightbox,
127
- filteredProductImages,
128
- handleClickCarouselItem
129
- };
130
- };
131
-
132
- export { useGalleryCarousel };
@@ -1,201 +0,0 @@
1
- import { useFeaturedImageGlobal, useCurrentDevice, useInteraction, useEditorMode, getResponsiveValueByScreen } from '@gem-sdk/core';
2
- import { createRef, useMemo, useCallback, useEffect } from 'react';
3
- import { handleSetSrcForFeatureProductImage } from '../../../../image/helpers/getSrcSet.js';
4
- import { getAspectRatio } from '../common/common.js';
5
- import { checkRenderFeaturedCarousel } from '../common/productFeaturedImage.js';
6
- import { useFilterImagesByVariant } from './useFilterImagesByVariant.js';
7
-
8
- const useProductFeaturedImageCarousel = (props)=>{
9
- const { productImages, imgRef, onHandleClick, onClickArrow, onHandleLoaded, onHandleUpdateActiveIndex, builderPropUID, builderPropsClass, children, parentUid, ...setting } = props;
10
- const featuredImageGlobal = useFeaturedImageGlobal();
11
- const currentDevice = useCurrentDevice();
12
- const carouselRef = createRef();
13
- const { onListener, ref } = useInteraction();
14
- let delayTimeout;
15
- const mode = useEditorMode();
16
- const { filteredProductImages } = useFilterImagesByVariant({
17
- productImages,
18
- displayByVariant: setting?.displayByVariant,
19
- variantSelect: setting?.variantSelect
20
- });
21
- const imageActiveIndex = useMemo(()=>{
22
- const index = filteredProductImages?.findIndex((item)=>item.id === featuredImageGlobal?.id);
23
- return index;
24
- }, [
25
- filteredProductImages,
26
- featuredImageGlobal
27
- ]);
28
- const isRenderFeatureCarousel = useMemo(()=>checkRenderFeaturedCarousel(setting), [
29
- setting
30
- ]);
31
- const imageActive = useMemo(()=>{
32
- if (filteredProductImages?.length) return featuredImageGlobal || filteredProductImages?.[0];
33
- }, [
34
- filteredProductImages,
35
- featuredImageGlobal
36
- ]);
37
- const enableOpenLightBox = useMemo(()=>{
38
- return getResponsiveValueByScreen(setting.ftClickOpenLightBox, currentDevice) === 'popup';
39
- }, [
40
- setting.ftClickOpenLightBox,
41
- currentDevice
42
- ]);
43
- const indexHover = useMemo(()=>{
44
- if (!setting?.otherImage) {
45
- return 0;
46
- }
47
- if (filteredProductImages && setting.otherImage >= filteredProductImages.length - 1) {
48
- return filteredProductImages.length - 1;
49
- }
50
- if (filteredProductImages && setting.otherImage === -1) {
51
- return filteredProductImages.length - 1;
52
- }
53
- return setting.otherImage;
54
- }, [
55
- setting?.otherImage,
56
- filteredProductImages
57
- ]);
58
- const imageShowWhenHover = useMemo(()=>{
59
- return setting?.hoverEffect === 'other' ? filteredProductImages?.[indexHover] : filteredProductImages?.find((item)=>item.id === featuredImageGlobal?.id) || filteredProductImages?.[0];
60
- }, [
61
- featuredImageGlobal?.id,
62
- indexHover,
63
- filteredProductImages,
64
- setting?.hoverEffect
65
- ]);
66
- const genRandomKey = function() {
67
- return Math.random().toString(36).substr(2, 5);
68
- };
69
- const emitUpdateActiveIndex = (index)=>{
70
- delayTimeout && clearTimeout(delayTimeout);
71
- delayTimeout = setTimeout(()=>onHandleUpdateActiveIndex && onHandleUpdateActiveIndex(index), 500);
72
- };
73
- const getDefaultAspectRatio = (image)=>{
74
- let result = '1/1';
75
- let ratio = 0;
76
- if (image) {
77
- if (image.width && image.height) {
78
- result = `${image.width}/${image.height}`;
79
- }
80
- } else {
81
- filteredProductImages?.forEach((item)=>{
82
- if (item.width && item.height) {
83
- const r = item.height / item.width;
84
- if (r > ratio) {
85
- ratio = r;
86
- result = `${item.width}/${item.height}`;
87
- }
88
- }
89
- });
90
- }
91
- return result;
92
- };
93
- const getAspectRatioFinal = (image)=>{
94
- const result = getAspectRatio(setting.ftShape);
95
- const defaultRatio = getDefaultAspectRatio(image);
96
- return {
97
- desktop: result.desktop ?? defaultRatio,
98
- tablet: result.tablet ?? defaultRatio,
99
- mobile: result.mobile ?? defaultRatio
100
- };
101
- };
102
- const handleSetSrc = useCallback(()=>{
103
- handleSetSrcForFeatureProductImage({
104
- builderPropUID,
105
- ftShape: setting.ftShape,
106
- qualityType: setting.qualityType,
107
- qualityPercent: setting.qualityPercent
108
- });
109
- }, [
110
- setting.ftShape,
111
- setting.qualityPercent,
112
- setting.qualityType,
113
- builderPropUID
114
- ]);
115
- const onListenerInteraction = ()=>{
116
- const eventName = 'gp:change-image-step';
117
- const selector = `[data-id="${builderPropUID}"]`;
118
- onListener({
119
- event: eventName,
120
- selector
121
- }, (params)=>{
122
- const element = (ref.current || document).querySelector(selector);
123
- const { data, isRollback, uniqueStorageKey } = params || {};
124
- carouselRef?.current?.moveToSlideInteraction({
125
- element,
126
- data,
127
- isRollback,
128
- key: uniqueStorageKey
129
- });
130
- });
131
- onListener({
132
- event: 'gp:change-next-slide',
133
- selector
134
- }, (params)=>{
135
- const element = (ref.current || document).querySelector(selector);
136
- const { data, isRollback, uniqueStorageKey } = params || {};
137
- carouselRef?.current?.nextSlideInteraction({
138
- element,
139
- data,
140
- isRollback,
141
- key: uniqueStorageKey
142
- });
143
- });
144
- onListener({
145
- event: 'gp:change-previous-slide',
146
- selector
147
- }, (params)=>{
148
- const element = (ref.current || document).querySelector(selector);
149
- const { data, isRollback, uniqueStorageKey } = params || {};
150
- carouselRef?.current?.previousSlideInteraction({
151
- element,
152
- data,
153
- isRollback,
154
- key: uniqueStorageKey
155
- });
156
- });
157
- };
158
- useEffect(()=>{
159
- if (mode === 'edit') return;
160
- const $featuredImage = document?.querySelector(`.gem-slider-item-${builderPropUID} .featured-image-only`);
161
- if (!$featuredImage) return;
162
- handleSetSrc();
163
- const observer = new ResizeObserver(()=>{
164
- handleSetSrc();
165
- });
166
- observer?.observe($featuredImage, {});
167
- return ()=>{
168
- observer?.disconnect();
169
- };
170
- }, [
171
- handleSetSrc,
172
- builderPropUID,
173
- mode
174
- ]);
175
- useEffect(()=>{
176
- onListenerInteraction();
177
- // eslint-disable-next-line react-hooks/exhaustive-deps
178
- }, []);
179
- useEffect(()=>{
180
- if (!isRenderFeatureCarousel) {
181
- onHandleLoaded && onHandleLoaded(true, 0);
182
- }
183
- }, [
184
- isRenderFeatureCarousel,
185
- onHandleLoaded
186
- ]);
187
- return {
188
- ref,
189
- imageActive,
190
- imageActiveIndex,
191
- imageShowWhenHover,
192
- enableOpenLightBox,
193
- filteredProductImages,
194
- isRenderFeatureCarousel,
195
- genRandomKey,
196
- getAspectRatioFinal,
197
- emitUpdateActiveIndex
198
- };
199
- };
200
-
201
- export { useProductFeaturedImageCarousel };
@@ -1,85 +0,0 @@
1
- import { useCurrentDevice, useFeaturedImageGlobal, useEditorMode, getResponsiveValueByScreen } from '@gem-sdk/core';
2
- import { useState, useCallback, useEffect } from 'react';
3
- import { handleSetSrcForProductImageList } from '../../../../image/helpers/getSrcSet.js';
4
- import { getShapeByLayout, checkDisplayGalleryByWidth } from '../common/productGallery.js';
5
- import { useFilterImagesByVariant } from './useFilterImagesByVariant.js';
6
-
7
- const useProductGalleryGrid = (props)=>{
8
- const { builderPropUID, productImages, activeIndexFormFeatureImage, children, isHiddenInteraction, ...setting } = props;
9
- const currentDevice = useCurrentDevice();
10
- const featuredImageGlobal = useFeaturedImageGlobal();
11
- const [imageActiveIndex, setImageActiveIndex] = useState(0);
12
- const mode = useEditorMode();
13
- const { filteredProductImages } = useFilterImagesByVariant({
14
- productImages,
15
- displayByVariant: setting?.displayByVariant,
16
- variantSelect: setting?.variantSelect
17
- });
18
- const shapeByLayout = getShapeByLayout({
19
- shape: setting.shape,
20
- shapeForBottom: setting.shapeForBottom,
21
- shapeFor1Col: setting.shapeFor1Col,
22
- shapeFor2Col: setting.shapeFor2Col,
23
- shapeForFtOnly: setting.shapeForFtOnly,
24
- shapeForInsideBottom: setting.shapeForInsideBottom,
25
- shapeForInside: setting.shapeForInside
26
- }, setting.position);
27
- const enableOpenLightBox = getResponsiveValueByScreen(setting.clickOpenLightBox, currentDevice);
28
- const isDisplayByWidth = checkDisplayGalleryByWidth({
29
- shapeByLayout
30
- });
31
- const isDisplay = getResponsiveValueByScreen(isDisplayByWidth, currentDevice);
32
- const isEnableBorderActive = setting?.borderActive?.border !== 'none';
33
- const handleSetSrc = useCallback(()=>{
34
- handleSetSrcForProductImageList({
35
- builderPropUID,
36
- shapeByLayout,
37
- qualityType: setting.qualityType,
38
- qualityPercent: setting.qualityPercent
39
- });
40
- }, [
41
- shapeByLayout,
42
- setting.qualityPercent,
43
- setting.qualityType,
44
- builderPropUID
45
- ]);
46
- useEffect(()=>{
47
- setImageActiveIndex(activeIndexFormFeatureImage || 0);
48
- }, [
49
- activeIndexFormFeatureImage
50
- ]);
51
- useEffect(()=>{
52
- const index = filteredProductImages?.findIndex((item)=>item.id === featuredImageGlobal?.id);
53
- setImageActiveIndex(index && index > 0 ? index : 0);
54
- }, [
55
- featuredImageGlobal,
56
- filteredProductImages
57
- ]);
58
- useEffect(()=>{
59
- if (mode === 'edit') return;
60
- const $galleryImageGrid = document?.querySelector('.grid-gallery');
61
- if (!$galleryImageGrid) return;
62
- handleSetSrc();
63
- const observer = new ResizeObserver(()=>{
64
- handleSetSrc();
65
- });
66
- observer?.observe($galleryImageGrid, {});
67
- return ()=>{
68
- observer?.disconnect();
69
- };
70
- }, [
71
- handleSetSrc,
72
- builderPropUID,
73
- mode
74
- ]);
75
- return {
76
- isDisplay,
77
- shapeByLayout,
78
- imageActiveIndex,
79
- enableOpenLightBox,
80
- isEnableBorderActive,
81
- filteredProductImages
82
- };
83
- };
84
-
85
- export { useProductGalleryGrid };