@gem-sdk/components 2.1.13-staging.21 → 2.1.13-staging.22

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.
@@ -20,12 +20,20 @@ const ProductFeaturedImageCarousel = ({ productImages, imgRef, onHandleClick, on
20
20
  const { onListener, ref } = core.useInteraction();
21
21
  let delayTimeout;
22
22
  const mode = core.useEditorMode();
23
- const imageActiveIndex = React.useMemo(()=>{
23
+ const getImageActiveIndex = React.useCallback(()=>{
24
24
  const index = productImages?.findIndex((item)=>item.id === featuredImageGlobal?.id);
25
- return index;
25
+ return index ?? 0;
26
26
  }, [
27
- productImages,
28
- featuredImageGlobal
27
+ featuredImageGlobal?.id,
28
+ productImages
29
+ ]);
30
+ const [imageActiveIndex, setImageActiveIndex] = React.useState(getImageActiveIndex());
31
+ React.useEffect(()=>{
32
+ setImageActiveIndex(getImageActiveIndex());
33
+ }, [
34
+ featuredImageGlobal,
35
+ getImageActiveIndex,
36
+ productImages
29
37
  ]);
30
38
  const imageActive = React.useMemo(()=>{
31
39
  if (productImages?.length) return featuredImageGlobal || productImages?.[0];
@@ -6,7 +6,7 @@ import { getAspectRatio } from '../../common/common.js';
6
6
  import { checkRenderFeaturedCarousel, getDotSettingByLayout } from '../../common/productFeaturedImage.js';
7
7
  import { handleMouseMove, handleMouseOut } from '../../common/hoverAction.js';
8
8
  import ProductFeaturedImageOnly from './ProductFeaturedImageOnly.js';
9
- import { memo, useMemo, useCallback, useEffect, createRef } from 'react';
9
+ import { memo, useCallback, useState, useEffect, useMemo, createRef } from 'react';
10
10
  import { handleSetSrcForFeatureProductImage } from '../../../../../image/helpers/getSrcSet.js';
11
11
 
12
12
  const ProductFeaturedImageCarousel = ({ productImages, imgRef, onHandleClick, onClickArrow, onHandleLoaded, onHandleUpdateActiveIndex, builderPropUID, builderPropsClass, children, parentUid, ...setting })=>{
@@ -16,12 +16,20 @@ const ProductFeaturedImageCarousel = ({ productImages, imgRef, onHandleClick, on
16
16
  const { onListener, ref } = useInteraction();
17
17
  let delayTimeout;
18
18
  const mode = useEditorMode();
19
- const imageActiveIndex = useMemo(()=>{
19
+ const getImageActiveIndex = useCallback(()=>{
20
20
  const index = productImages?.findIndex((item)=>item.id === featuredImageGlobal?.id);
21
- return index;
21
+ return index ?? 0;
22
22
  }, [
23
- productImages,
24
- featuredImageGlobal
23
+ featuredImageGlobal?.id,
24
+ productImages
25
+ ]);
26
+ const [imageActiveIndex, setImageActiveIndex] = useState(getImageActiveIndex());
27
+ useEffect(()=>{
28
+ setImageActiveIndex(getImageActiveIndex());
29
+ }, [
30
+ featuredImageGlobal,
31
+ getImageActiveIndex,
32
+ productImages
25
33
  ]);
26
34
  const imageActive = useMemo(()=>{
27
35
  if (productImages?.length) return featuredImageGlobal || productImages?.[0];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gem-sdk/components",
3
- "version": "2.1.13-staging.21",
3
+ "version": "2.1.13-staging.22",
4
4
  "license": "MIT",
5
5
  "sideEffects": false,
6
6
  "main": "dist/cjs/index.js",