@crystaldesign/widget-library 25.8.0-beta.12 → 25.8.0-beta.14

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.
@@ -417,7 +417,10 @@ function useProductData(_ref) {
417
417
  fetchProducts(normalizedProductIds).then(function (variants) {
418
418
  LOG.debug("[".concat(widgetType, ":").concat(widgetId, "] Successfully loaded ").concat(variants.length, " product variants"));
419
419
  setProductVariants(variants);
420
- setSelectedProduct(variants[0]);
420
+ var variantToUse = variants.find(function (v) {
421
+ return v._id === normalizedProductIds[0];
422
+ });
423
+ setSelectedProduct(variantToUse !== null && variantToUse !== void 0 ? variantToUse : variants[0]);
421
424
  setLoading(false);
422
425
  })["catch"](function (error) {
423
426
  LOG.error(new DivaError("[".concat(widgetType, ":").concat(widgetId, "] Error loading products"), {
@@ -434,6 +437,13 @@ function useProductData(_ref) {
434
437
  return _regeneratorRuntime.wrap(function _callee4$(_context4) {
435
438
  while (1) switch (_context4.prev = _context4.next) {
436
439
  case 0:
440
+ if (!((selectedProduct === null || selectedProduct === void 0 ? void 0 : selectedProduct._id) === productId)) {
441
+ _context4.next = 3;
442
+ break;
443
+ }
444
+ LOG.debug("[".concat(widgetType, ":").concat(widgetId, "] Product ").concat(productId, " already selected, skipping"));
445
+ return _context4.abrupt("return");
446
+ case 3:
437
447
  LOG.debug("[".concat(widgetType, ":").concat(widgetId, "] setSelectedProductId called with productId: ").concat(productId));
438
448
 
439
449
  // If a product is selected that is not in the productVariants list,
@@ -442,21 +452,21 @@ function useProductData(_ref) {
442
452
  return p._id === productId;
443
453
  });
444
454
  if (!product) {
445
- _context4.next = 7;
455
+ _context4.next = 10;
446
456
  break;
447
457
  }
448
458
  LOG.debug("[".concat(widgetType, ":").concat(widgetId, "] Product ").concat(productId, " found in current variants, setting as selected"));
449
459
  setSelectedProduct(product);
450
460
  notifyProductChanged(product);
451
461
  return _context4.abrupt("return");
452
- case 7:
462
+ case 10:
453
463
  LOG.debug("[".concat(widgetType, ":").concat(widgetId, "] Product ").concat(productId, " not found in current variants, fetching variants for it"));
454
- _context4.prev = 8;
464
+ _context4.prev = 11;
455
465
  setError(false);
456
466
  setLoading(true);
457
- _context4.next = 13;
467
+ _context4.next = 16;
458
468
  return fetchProducts([productId]);
459
- case 13:
469
+ case 16:
460
470
  _variants2 = _context4.sent;
461
471
  setProductVariants(_variants2);
462
472
  LOG.debug("[".concat(widgetType, ":").concat(widgetId, "] New ").concat(_variants2.length, " variants to productVariants"));
@@ -464,40 +474,40 @@ function useProductData(_ref) {
464
474
  return p._id === productId;
465
475
  });
466
476
  if (!_product) {
467
- _context4.next = 23;
477
+ _context4.next = 26;
468
478
  break;
469
479
  }
470
480
  LOG.debug("[".concat(widgetType, ":").concat(widgetId, "] Setting product ").concat(productId, " as selected after fetching"));
471
481
  setSelectedProduct(_product);
472
482
  notifyProductChanged(_product);
473
- _context4.next = 24;
483
+ _context4.next = 27;
474
484
  break;
475
- case 23:
485
+ case 26:
476
486
  throw new DivaError("[".concat(widgetType, ":").concat(widgetId, "] Product ").concat(productId, " not found"));
477
- case 24:
478
- _context4.next = 30;
487
+ case 27:
488
+ _context4.next = 33;
479
489
  break;
480
- case 26:
481
- _context4.prev = 26;
482
- _context4.t0 = _context4["catch"](8);
490
+ case 29:
491
+ _context4.prev = 29;
492
+ _context4.t0 = _context4["catch"](11);
483
493
  LOG.error(new DivaError("[".concat(widgetType, ":").concat(widgetId, "] Error loading product"), {
484
494
  cause: _context4.t0
485
495
  }));
486
496
  setError(true);
487
- case 30:
488
- _context4.prev = 30;
489
- setLoading(false);
490
- return _context4.finish(30);
491
497
  case 33:
498
+ _context4.prev = 33;
499
+ setLoading(false);
500
+ return _context4.finish(33);
501
+ case 36:
492
502
  case "end":
493
503
  return _context4.stop();
494
504
  }
495
- }, _callee4, null, [[8, 26, 30, 33]]);
505
+ }, _callee4, null, [[11, 29, 33, 36]]);
496
506
  }));
497
507
  return function (_x4) {
498
508
  return _ref5.apply(this, arguments);
499
509
  };
500
- }(), [productVariants, fetchProducts, setSelectedProduct, widgetId, widgetType]);
510
+ }(), [selectedProduct, productVariants, fetchProducts, setSelectedProduct, widgetId, widgetType]);
501
511
  function getProductsByDivaNrs(_x5) {
502
512
  return _getProductsByDivaNrs.apply(this, arguments);
503
513
  }
@@ -515,6 +525,10 @@ function useProductData(_ref) {
515
525
  id: 'divaNr',
516
526
  op: 'in',
517
527
  value: divaNrs.join(',').replaceAll('"', '')
528
+ }, {
529
+ id: 'baseProduct',
530
+ op: 'eq',
531
+ value: false
518
532
  }], 1000, false);
519
533
  });
520
534
  case 3:
@@ -541,6 +555,10 @@ function useProductData(_ref) {
541
555
  id: 'divaNr',
542
556
  op: 'eq',
543
557
  value: divaNr
558
+ }, {
559
+ id: 'baseProduct',
560
+ op: 'eq',
561
+ value: false
544
562
  }];
545
563
  if (variantId) {
546
564
  filter.push({
@@ -686,8 +704,8 @@ function useGallery(_ref) {
686
704
  functionTypes = _ref$config.functionTypes,
687
705
  add2DImage = _ref$config.add2DImage,
688
706
  add3DImageAsFallback = _ref$config.add3DImageAsFallback,
689
- currentProductIndex = _ref.currentProductIndex,
690
- setCurrentProductIndex = _ref.setCurrentProductIndex;
707
+ currentProductId = _ref.currentProductId,
708
+ setCurrentProductId = _ref.setCurrentProductId;
691
709
  var _useDivaCore = useDivaCore(),
692
710
  baseSirvUrls = _useDivaCore.state.apiConfig.baseSirvUrls;
693
711
  var _useState = useState(null),
@@ -708,24 +726,22 @@ function useGallery(_ref) {
708
726
  add2DImage: add2DImage,
709
727
  add3DImageAsFallback: add3DImageAsFallback
710
728
  });
711
- var userTriggeredRef = useRef(false);
729
+ useRef(false);
730
+
712
731
  // Update currentMediaIndex when currentProductIndex changes from outside
713
732
  useEffect(function () {
714
733
  var _medias$currentMediaI;
715
- if (currentProductIndex !== undefined && ((_medias$currentMediaI = medias[currentMediaIndex]) === null || _medias$currentMediaI === void 0 ? void 0 : _medias$currentMediaI.productIndex) !== currentProductIndex) {
734
+ if (currentProductId !== undefined && ((_medias$currentMediaI = medias[currentMediaIndex]) === null || _medias$currentMediaI === void 0 ? void 0 : _medias$currentMediaI.productId) !== currentProductId) {
716
735
  // Find the first media index that corresponds to this product index
717
736
  var mediaIndex = medias.findIndex(function (media) {
718
- return media.productIndex === currentProductIndex;
737
+ return media.productId === currentProductId;
719
738
  });
720
739
  if (mediaIndex !== -1 && mediaIndex !== currentMediaIndex) {
721
740
  setCurrentMediaIndex(mediaIndex);
722
- swiper === null || swiper === void 0 || swiper.slideTo(mediaIndex);
741
+ swiper === null || swiper === void 0 || swiper.slideTo(mediaIndex, 0, false);
723
742
  }
724
743
  }
725
- }, [currentProductIndex]);
726
- var markUserInteraction = function markUserInteraction() {
727
- userTriggeredRef.current = true;
728
- };
744
+ }, [currentProductId]);
729
745
  var hasSirvMedia = useMemo(function () {
730
746
  var _loop = function _loop(i) {
731
747
  if (medias.find(function (m) {
@@ -748,35 +764,26 @@ function useGallery(_ref) {
748
764
  }),
749
765
  sirvLoaded = _useSirv.sirvLoaded;
750
766
  var onSlideChange = function onSlideChange(swiper) {
751
- if (!userTriggeredRef.current) return;
767
+ if (swiper.isBeginning) return;
752
768
  var newMediaIndex = swiper.realIndex;
753
- setCurrentMediaIndex(newMediaIndex);
754
-
755
- // Get the product index corresponding to this media index
756
769
  var media = medias[newMediaIndex];
757
-
758
- // Call the external setCurrentProductIndex if provided
759
- if (setCurrentProductIndex && media) {
760
- setCurrentProductIndex(media.productIndex);
770
+ setCurrentMediaIndex(newMediaIndex);
771
+ if (setCurrentProductId && media) {
772
+ setCurrentProductId(media.productId);
761
773
  }
762
- userTriggeredRef.current = false;
763
774
  };
764
775
 
765
776
  // Get the current product index based on the current media index
766
- var currentMedia = medias[currentMediaIndex];
767
- var derivedCurrentProductIndex = currentMedia === null || currentMedia === void 0 ? void 0 : currentMedia.productIndex;
777
+ medias[currentMediaIndex];
768
778
  return {
769
779
  medias: medias,
770
780
  sirvLoaded: sirvLoaded,
771
781
  thumbsSwiper: thumbsSwiper,
772
782
  swiper: swiper,
773
783
  currentIndex: currentMediaIndex,
774
- currentProductIndex: currentProductIndex !== null && currentProductIndex !== void 0 ? currentProductIndex : derivedCurrentProductIndex,
775
- setCurrentProductIndex: setCurrentProductIndex,
776
784
  setThumbsSwiper: setThumbsSwiper,
777
785
  setSwiper: setSwiper,
778
- onSlideChange: onSlideChange,
779
- markUserInteraction: markUserInteraction
786
+ onSlideChange: onSlideChange
780
787
  };
781
788
  }
782
789
 
@@ -1070,8 +1077,7 @@ var Gallery = function Gallery(props) {
1070
1077
  onSlideChange = _useGallery.onSlideChange,
1071
1078
  setThumbsSwiper = _useGallery.setThumbsSwiper,
1072
1079
  setSwiper = _useGallery.setSwiper,
1073
- currentIndex = _useGallery.currentIndex,
1074
- markUserInteraction = _useGallery.markUserInteraction;
1080
+ currentIndex = _useGallery.currentIndex;
1075
1081
  useEffect(function () {
1076
1082
  if (props.setCurrentMedia) {
1077
1083
  props.setCurrentMedia(medias[currentIndex]);
@@ -1090,9 +1096,6 @@ var Gallery = function Gallery(props) {
1090
1096
  htmlArElement: htmlArElement === null || htmlArElement === void 0 ? void 0 : htmlArElement.current
1091
1097
  }), /*#__PURE__*/jsx(Swiper, _objectSpread(_objectSpread({
1092
1098
  onSwiper: setSwiper,
1093
- onTouchStart: markUserInteraction,
1094
- onNavigationNext: markUserInteraction,
1095
- onNavigationPrev: markUserInteraction,
1096
1099
  resizeObserver: false,
1097
1100
  onSlideChange: onSlideChange,
1098
1101
  focusableElements: focusable,
@@ -1108,6 +1111,7 @@ var Gallery = function Gallery(props) {
1108
1111
  children: medias.map(function (media, i) {
1109
1112
  return /*#__PURE__*/jsx(SwiperSlide, {
1110
1113
  id: 'gallery media index ' + i,
1114
+ "data-product-id": props.currentProductId,
1111
1115
  children: /*#__PURE__*/jsx(MediaItem, {
1112
1116
  media: media,
1113
1117
  config: props.config,
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../src/components/Gallery/index.tsx"],"names":[],"mappings":"AAEA,OAAO,KAA4B,MAAM,OAAO,CAAC;AACjD,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AASvC,cAAc,SAAS,CAAC;AAKxB,eAAO,MAAM,OAAO,UAAW,YAAY,sBAyD1C,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../src/components/Gallery/index.tsx"],"names":[],"mappings":"AAEA,OAAO,KAA4B,MAAM,OAAO,CAAC;AACjD,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AASvC,cAAc,SAAS,CAAC;AAKxB,eAAO,MAAM,OAAO,UAAW,YAAY,sBAsD1C,CAAC"}
@@ -19,8 +19,8 @@ export interface ArActionIconConfig extends BaseElementConfig {
19
19
  export interface GalleryProps {
20
20
  config: GalleryConfig;
21
21
  products: ProductData[];
22
- currentProductIndex?: number;
23
- setCurrentProductIndex?: (index: number) => void;
22
+ currentProductId?: string;
23
+ setCurrentProductId?: (id: string) => void;
24
24
  disableAnimation?: boolean;
25
25
  setCurrentMedia?: (m: MediaWithProductIndex) => void;
26
26
  }
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../../../src/components/Gallery/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAC9D,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAErD,MAAM,WAAW,aAAc,SAAQ,iBAAiB,EAAE,eAAe;IACvE,aAAa,EAAE,MAAM,EAAE,CAAC;IACxB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAC/B,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,UAAU,CAA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CAAC,EAAE,WAAW,CAAC;IAC9B,WAAW,CAAC,EAAE,kBAAkB,CAAC;CAClC;AAED,MAAM,WAAW,kBAAmB,SAAQ,iBAAiB;IAC3D,IAAI,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;IACxB,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,EAAE,CAAC,EAAE,MAAM,CAAC;CACb;AAED,MAAM,WAAW,YAAY;IAC3B,MAAM,EAAE,aAAa,CAAC;IACtB,QAAQ,EAAE,WAAW,EAAE,CAAC;IACxB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,mBAAmB,CAAC,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,IAAI,CAAC;IAC3C,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,eAAe,CAAC,EAAE,CAAC,CAAC,EAAE,qBAAqB,KAAK,IAAI,CAAC;CACtD;AAED,MAAM,WAAW,qBAAsB,SAAQ,KAAK;IAClD,YAAY,EAAE,MAAM,CAAC;IACrB,SAAS,EAAE,MAAM,CAAC;CACnB"}
@@ -1,16 +1,13 @@
1
1
  import { GalleryProps, MediaWithProductIndex } from './types';
2
2
  import { SwiperClass } from 'swiper/react';
3
- export default function useGallery({ products, config: { functionTypes, add2DImage, add3DImageAsFallback }, currentProductIndex, setCurrentProductIndex, }: GalleryProps): {
3
+ export default function useGallery({ products, config: { functionTypes, add2DImage, add3DImageAsFallback }, currentProductId, setCurrentProductId, }: GalleryProps): {
4
4
  medias: MediaWithProductIndex[];
5
5
  sirvLoaded: boolean;
6
6
  thumbsSwiper: SwiperClass | null;
7
7
  swiper: SwiperClass | null;
8
8
  currentIndex: number;
9
- currentProductIndex: number;
10
- setCurrentProductIndex: ((index: number) => void) | undefined;
11
9
  setThumbsSwiper: import("react").Dispatch<import("react").SetStateAction<SwiperClass | null>>;
12
10
  setSwiper: import("react").Dispatch<import("react").SetStateAction<SwiperClass | null>>;
13
11
  onSlideChange: (swiper: SwiperClass) => void;
14
- markUserInteraction: () => void;
15
12
  };
16
13
  //# 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,mBAAmB,EACnB,sBAAsB,GACvB,EAAE,YAAY;;;;;;;;;;4BAmCkB,WAAW;;EAgC3C"}
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;;;;;;;;4BAiCkB,WAAW;EAyB3C"}
@@ -1 +1 @@
1
- {"version":3,"file":"useProductData.d.ts","sourceRoot":"","sources":["../../../../../src/hooks/useProductData.ts"],"names":[],"mappings":"AACA,OAAO,EAAa,WAAW,EAA0B,MAAM,0BAA0B,CAAC;AAM1F,MAAM,WAAW,mBAAmB;IAClC,UAAU,CAAC,EAAE,MAAM,EAAE,GAAG,MAAM,CAAC;IAC/B,QAAQ,CAAC,EAAE,WAAW,EAAE,CAAC;IACzB;;OAEG;IACH,UAAU,EAAE,MAAM,CAAC;CACpB;AAKD,wBAAgB,cAAc,CAAC,EAAE,UAAU,EAAE,QAAQ,EAAE,UAAU,EAAE,EAAE,mBAAmB;;;;oCAqJzC,MAAM,EAAE,KAAG,OAAO,CAAC,GAAG,CAAC;6CAoBd,MAAM,cAAc,MAAM,KAAG,OAAO,CAAC,GAAG,CAAC;;sCA9D3E,MAAM;2BAoFI,MAAM,QAAQ,GAAG;EAiBhD"}
1
+ {"version":3,"file":"useProductData.d.ts","sourceRoot":"","sources":["../../../../../src/hooks/useProductData.ts"],"names":[],"mappings":"AACA,OAAO,EAAa,WAAW,EAA0B,MAAM,0BAA0B,CAAC;AAM1F,MAAM,WAAW,mBAAmB;IAClC,UAAU,CAAC,EAAE,MAAM,EAAE,GAAG,MAAM,CAAC;IAC/B,QAAQ,CAAC,EAAE,WAAW,EAAE,CAAC;IACzB;;OAEG;IACH,UAAU,EAAE,MAAM,CAAC;CACpB;AAKD,wBAAgB,cAAc,CAAC,EAAE,UAAU,EAAE,QAAQ,EAAE,UAAU,EAAE,EAAE,mBAAmB;;;;oCA2JzC,MAAM,EAAE,KAAG,OAAO,CAAC,GAAG,CAAC;6CAyBd,MAAM,cAAc,MAAM,KAAG,OAAO,CAAC,GAAG,CAAC;;sCAxE3E,MAAM;2BAmGI,MAAM,QAAQ,GAAG;EAiBhD"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@crystaldesign/widget-library",
3
- "version": "25.8.0-beta.12",
3
+ "version": "25.8.0-beta.14",
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": "7647e534c46de9e7cf0cee8f77dd08d7a00b58b3"
39
+ "gitHead": "41f0c4eed82da5949fda291e326827816913d2bc"
40
40
  }