@crystaldesign/widget-library 25.10.0-beta.2 → 25.10.0-beta.20
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.
- package/build/esm/index.js +58 -26
- package/build/types/widget-library/src/components/Gallery/useGallery.d.ts +1 -0
- package/build/types/widget-library/src/components/Gallery/useGallery.d.ts.map +1 -1
- package/build/types/widget-library/src/components/MediaItem/ImageItem/index.d.ts +4 -1
- package/build/types/widget-library/src/components/MediaItem/ImageItem/index.d.ts.map +1 -1
- package/package.json +2 -2
package/build/esm/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { useEffect, useMemo, useCallback, useState,
|
|
1
|
+
import { useEffect, useMemo, useCallback, useState, forwardRef, useRef } from 'react';
|
|
2
2
|
import { useDivaCore, getLogger, DivaError, useTranslation } from '@crystaldesign/diva-core';
|
|
3
3
|
import _asyncToGenerator from '@babel/runtime/helpers/asyncToGenerator';
|
|
4
4
|
import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
|
|
@@ -805,23 +805,23 @@ function useGallery(_ref) {
|
|
|
805
805
|
add2DImage: add2DImage,
|
|
806
806
|
add3DImageAsFallback: add3DImageAsFallback
|
|
807
807
|
});
|
|
808
|
-
useRef(false);
|
|
809
808
|
|
|
810
809
|
// Update currentMediaIndex when currentProductIndex changes from outside
|
|
811
810
|
useEffect(function () {
|
|
812
811
|
var _medias$currentMediaI;
|
|
813
812
|
if (currentProductId !== undefined && ((_medias$currentMediaI = medias[currentMediaIndex]) === null || _medias$currentMediaI === void 0 ? void 0 : _medias$currentMediaI.productId) !== currentProductId) {
|
|
814
|
-
// Find the first media index that corresponds to this product index
|
|
815
813
|
var mediaIndex = medias.findIndex(function (media) {
|
|
816
814
|
return media.productId === currentProductId;
|
|
817
815
|
});
|
|
818
|
-
if (mediaIndex !== -1 && mediaIndex !== currentMediaIndex) {
|
|
819
|
-
var _swiper$params;
|
|
816
|
+
if (mediaIndex !== -1 && mediaIndex !== currentMediaIndex && swiper) {
|
|
820
817
|
setCurrentMediaIndex(mediaIndex);
|
|
821
|
-
if (swiper
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
818
|
+
if (swiper.realIndex !== mediaIndex) {
|
|
819
|
+
var _swiper$params;
|
|
820
|
+
if ((_swiper$params = swiper.params) !== null && _swiper$params !== void 0 && _swiper$params.loop) {
|
|
821
|
+
swiper.slideToLoop(mediaIndex, 0);
|
|
822
|
+
} else {
|
|
823
|
+
swiper.slideTo(mediaIndex, 0);
|
|
824
|
+
}
|
|
825
825
|
}
|
|
826
826
|
}
|
|
827
827
|
}
|
|
@@ -849,23 +849,37 @@ function useGallery(_ref) {
|
|
|
849
849
|
sirvLoaded = _useSirv.sirvLoaded;
|
|
850
850
|
var onSlideChange = function onSlideChange(swiper) {
|
|
851
851
|
if (swiper.el.classList.contains('gallery-main-nested-swiper')) return;
|
|
852
|
-
|
|
853
|
-
|
|
852
|
+
var newMediaIndex = swiper.realIndex;
|
|
853
|
+
var media = medias[newMediaIndex];
|
|
854
854
|
if (!swiperIsInitialized) {
|
|
855
855
|
setSwiperIsInitialized(true);
|
|
856
856
|
return;
|
|
857
857
|
}
|
|
858
|
-
if (
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
858
|
+
if (newMediaIndex !== currentMediaIndex) {
|
|
859
|
+
setCurrentMediaIndex(newMediaIndex);
|
|
860
|
+
if (setCurrentProductId && (media === null || media === void 0 ? void 0 : media.productId) !== currentProductId) {
|
|
861
|
+
setCurrentProductId(media.productId);
|
|
862
|
+
}
|
|
863
|
+
}
|
|
864
|
+
onThumbSlideChange(swiper.realIndex);
|
|
865
|
+
};
|
|
866
|
+
var onThumbSlideChange = function onThumbSlideChange(clickedIndex) {
|
|
867
|
+
if (!(thumbsSwiper !== null && thumbsSwiper !== void 0 && thumbsSwiper.slides)) return;
|
|
868
|
+
if (clickedIndex == null || clickedIndex < 0) return;
|
|
869
|
+
var visibleSlides = Array.from(thumbsSwiper.slides).filter(function (slide) {
|
|
870
|
+
return slide.classList.contains('swiper-slide-visible');
|
|
871
|
+
});
|
|
872
|
+
if (visibleSlides.length === 0) return;
|
|
873
|
+
var firstVisibleIndex = visibleSlides[0].swiperSlideIndex;
|
|
874
|
+
var lastVisibleIndex = visibleSlides[visibleSlides.length - 1].swiperSlideIndex;
|
|
875
|
+
|
|
876
|
+
// if the first or last visible slide is clicked, slide to the previous or next slide
|
|
877
|
+
if (clickedIndex === firstVisibleIndex) {
|
|
878
|
+
thumbsSwiper.slideTo(Math.max(clickedIndex - 1, 0));
|
|
879
|
+
} else if (clickedIndex === lastVisibleIndex) {
|
|
880
|
+
thumbsSwiper.slideTo(Math.min(clickedIndex + 1, thumbsSwiper.slides.length - 1));
|
|
864
881
|
}
|
|
865
882
|
};
|
|
866
|
-
|
|
867
|
-
// Get the current product index based on the current media index
|
|
868
|
-
medias[currentMediaIndex];
|
|
869
883
|
return {
|
|
870
884
|
medias: medias,
|
|
871
885
|
sirvLoaded: sirvLoaded,
|
|
@@ -874,7 +888,8 @@ function useGallery(_ref) {
|
|
|
874
888
|
currentIndex: currentMediaIndex,
|
|
875
889
|
setThumbsSwiper: setThumbsSwiper,
|
|
876
890
|
setSwiper: setSwiper,
|
|
877
|
-
onSlideChange: onSlideChange
|
|
891
|
+
onSlideChange: onSlideChange,
|
|
892
|
+
onThumbSlideChange: onThumbSlideChange
|
|
878
893
|
};
|
|
879
894
|
}
|
|
880
895
|
|
|
@@ -979,7 +994,8 @@ var ArViewer = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
|
979
994
|
var ImageItem = function ImageItem(_ref) {
|
|
980
995
|
var url = _ref.url,
|
|
981
996
|
onClick = _ref.onClick,
|
|
982
|
-
className = _ref.className
|
|
997
|
+
className = _ref.className,
|
|
998
|
+
sirvProps = _ref.sirvProps;
|
|
983
999
|
var _useState = useState(''),
|
|
984
1000
|
_useState2 = _slicedToArray(_useState, 2),
|
|
985
1001
|
loadedMediaUrl = _useState2[0],
|
|
@@ -1017,7 +1033,7 @@ var ImageItem = function ImageItem(_ref) {
|
|
|
1017
1033
|
}();
|
|
1018
1034
|
var preloadAndSet = /*#__PURE__*/function () {
|
|
1019
1035
|
var _ref3 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
|
|
1020
|
-
var success;
|
|
1036
|
+
var success, finalUrl, urlObj;
|
|
1021
1037
|
return _regeneratorRuntime.wrap(function _callee2$(_context2) {
|
|
1022
1038
|
while (1) switch (_context2.prev = _context2.next) {
|
|
1023
1039
|
case 0:
|
|
@@ -1027,7 +1043,18 @@ var ImageItem = function ImageItem(_ref) {
|
|
|
1027
1043
|
case 3:
|
|
1028
1044
|
success = _context2.sent;
|
|
1029
1045
|
if (success) {
|
|
1030
|
-
|
|
1046
|
+
finalUrl = url;
|
|
1047
|
+
if (sirvProps && url) {
|
|
1048
|
+
urlObj = new URL(url);
|
|
1049
|
+
Object.entries(sirvProps).forEach(function (_ref4) {
|
|
1050
|
+
var _ref5 = _slicedToArray(_ref4, 2),
|
|
1051
|
+
key = _ref5[0],
|
|
1052
|
+
value = _ref5[1];
|
|
1053
|
+
urlObj.searchParams.append(key, value);
|
|
1054
|
+
});
|
|
1055
|
+
finalUrl = urlObj.toString();
|
|
1056
|
+
}
|
|
1057
|
+
setLoadedMediaUrl(finalUrl);
|
|
1031
1058
|
setHasError(false);
|
|
1032
1059
|
} else {
|
|
1033
1060
|
setHasError(true);
|
|
@@ -1146,7 +1173,8 @@ var MediaItem = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
|
1146
1173
|
return /*#__PURE__*/jsx(ImageItem, {
|
|
1147
1174
|
url: url,
|
|
1148
1175
|
onClick: onClick,
|
|
1149
|
-
className: classNames('diva-widget-mediaitem', className)
|
|
1176
|
+
className: classNames('diva-widget-mediaitem', className),
|
|
1177
|
+
sirvProps: config.sirvProps
|
|
1150
1178
|
});
|
|
1151
1179
|
});
|
|
1152
1180
|
|
|
@@ -1297,7 +1325,8 @@ var Gallery = function Gallery(props) {
|
|
|
1297
1325
|
onSlideChange = _useGallery.onSlideChange,
|
|
1298
1326
|
setThumbsSwiper = _useGallery.setThumbsSwiper,
|
|
1299
1327
|
setSwiper = _useGallery.setSwiper,
|
|
1300
|
-
currentIndex = _useGallery.currentIndex
|
|
1328
|
+
currentIndex = _useGallery.currentIndex,
|
|
1329
|
+
onThumbSlideChange = _useGallery.onThumbSlideChange;
|
|
1301
1330
|
useEffect(function () {
|
|
1302
1331
|
if (props.setCurrentMedia) {
|
|
1303
1332
|
props.setCurrentMedia(medias[currentIndex]);
|
|
@@ -1356,6 +1385,9 @@ var Gallery = function Gallery(props) {
|
|
|
1356
1385
|
var _media$url;
|
|
1357
1386
|
return /*#__PURE__*/jsx(SwiperSlide, {
|
|
1358
1387
|
id: 'thumb media index ' + i,
|
|
1388
|
+
onClick: function onClick() {
|
|
1389
|
+
return onThumbSlideChange(i);
|
|
1390
|
+
},
|
|
1359
1391
|
children: /*#__PURE__*/jsx(Thumb, {
|
|
1360
1392
|
media: media,
|
|
1361
1393
|
medias: medias
|
|
@@ -9,5 +9,6 @@ export default function useGallery({ products, config: { functionTypes, add2DIma
|
|
|
9
9
|
setThumbsSwiper: import("react").Dispatch<import("react").SetStateAction<SwiperClass | null>>;
|
|
10
10
|
setSwiper: import("react").Dispatch<import("react").SetStateAction<SwiperClass | null>>;
|
|
11
11
|
onSlideChange: (swiper: SwiperClass) => void;
|
|
12
|
+
onThumbSlideChange: (clickedIndex: any) => void;
|
|
12
13
|
};
|
|
13
14
|
//# sourceMappingURL=useGallery.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useGallery.d.ts","sourceRoot":"","sources":["../../../../../../src/components/Gallery/useGallery.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAC;AAI9D,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAE3C,MAAM,CAAC,OAAO,UAAU,UAAU,CAAC,EACjC,QAAQ,EACR,MAAM,EAAE,EAAE,aAAa,EAAE,UAAU,EAAE,oBAAoB,EAAE,EAC3D,gBAAgB,EAChB,mBAAmB,GACpB,EAAE,YAAY;;;;;;;;
|
|
1
|
+
{"version":3,"file":"useGallery.d.ts","sourceRoot":"","sources":["../../../../../../src/components/Gallery/useGallery.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAC;AAI9D,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAE3C,MAAM,CAAC,OAAO,UAAU,UAAU,CAAC,EACjC,QAAQ,EACR,MAAM,EAAE,EAAE,aAAa,EAAE,UAAU,EAAE,oBAAoB,EAAE,EAC3D,gBAAgB,EAChB,mBAAmB,GACpB,EAAE,YAAY;;;;;;;;4BAuCkB,WAAW;uCAoBA,GAAG;EA8B9C"}
|
|
@@ -3,7 +3,10 @@ type Props = {
|
|
|
3
3
|
url?: string;
|
|
4
4
|
onClick?: () => void;
|
|
5
5
|
className: string;
|
|
6
|
+
sirvProps?: {
|
|
7
|
+
[data: string]: string;
|
|
8
|
+
};
|
|
6
9
|
};
|
|
7
|
-
declare const ImageItem: ({ url, onClick, className }: Props) => React.JSX.Element | null;
|
|
10
|
+
declare const ImageItem: ({ url, onClick, className, sirvProps }: Props) => React.JSX.Element | null;
|
|
8
11
|
export default ImageItem;
|
|
9
12
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../../src/components/MediaItem/ImageItem/index.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA8B,MAAM,OAAO,CAAC;AAGnD,KAAK,KAAK,GAAG;IAAE,GAAG,CAAC,EAAE,MAAM,CAAC;IAAC,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;IAAC,SAAS,EAAE,MAAM,CAAA;CAAE,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../../src/components/MediaItem/ImageItem/index.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA8B,MAAM,OAAO,CAAC;AAGnD,KAAK,KAAK,GAAG;IAAE,GAAG,CAAC,EAAE,MAAM,CAAC;IAAC,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;IAAC,SAAS,EAAE,MAAM,CAAC;IAAC,SAAS,CAAC,EAAE;QAAE,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAAA;KAAE,CAAA;CAAE,CAAC;AAE/G,QAAA,MAAM,SAAS,2CAA4C,KAAK,6BA6D/D,CAAC;AAEF,eAAe,SAAS,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@crystaldesign/widget-library",
|
|
3
|
-
"version": "25.10.0-beta.
|
|
3
|
+
"version": "25.10.0-beta.20",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"storybook": "storybook dev -p 6006",
|
|
@@ -36,5 +36,5 @@
|
|
|
36
36
|
"suiteName": "widget-library",
|
|
37
37
|
"outputDirectory": "./test-reports"
|
|
38
38
|
},
|
|
39
|
-
"gitHead": "
|
|
39
|
+
"gitHead": "b9bd02b889d4b770cf5e95923c79027fea6cff47"
|
|
40
40
|
}
|