@depict-ai/portal-components 2.7.27 → 2.7.29

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/dist/index.d.ts CHANGED
@@ -4,7 +4,7 @@ import { SearchFilter } from "@depict-ai/types/api/SearchResponse";
4
4
  import { Locale } from "@depict-ai/react-ui/locales/latest";
5
5
  import { ReactNode } from "react";
6
6
  import { FeaturedInDisplay } from "@depict-ai/types/api/FeaturedInResponseV3";
7
- export const version = "2.7.27";
7
+ export const version = "2.7.29";
8
8
  type TextOptions = {
9
9
  /** Enabled */
10
10
  enabled: boolean;
package/dist/main.js CHANGED
@@ -20,7 +20,7 @@ $parcel$export(module.exports, "ExpandingSection", () => $2214dc111b9e2866$expor
20
20
  $parcel$export(module.exports, "ReactLookCard", () => $35bab9ff48bfe404$export$48787da2a5568bc);
21
21
  $parcel$export(module.exports, "version", () => $0a017be3a74fcc94$export$83d89fbfd8236492);
22
22
  /*! Depict.ai portal components */ // This is where the actual source of your React stuff should live
23
- const $0a017be3a74fcc94$export$83d89fbfd8236492 = "2.7.27";
23
+ const $0a017be3a74fcc94$export$83d89fbfd8236492 = "2.7.29";
24
24
 
25
25
 
26
26
 
@@ -213,7 +213,8 @@ function $3375ddd88f77967d$export$f11681c54c860912(display, info, configuredOpti
213
213
  video_: ()=>variantToShow()?.video,
214
214
  configuredOptions_: configuredOptions_,
215
215
  cardIsHovered_: ()=>showVariantIndex() === display()?.variant_index && cardIsHovered(),
216
- aspectRatio_: aspectRatio_
216
+ aspectRatio_: aspectRatio_,
217
+ noHoverSupport_: noHoverSupport_
217
218
  });
218
219
  }
219
220
  }), null);
@@ -628,7 +629,7 @@ function $3375ddd88f77967d$var$setStyleForTextOptions({ style: style }, options)
628
629
  (0, $7jsgb$solidjs.createEffect)(()=>$3375ddd88f77967d$var$setPropertyIfExists(style, "--color", options().color));
629
630
  (0, $7jsgb$solidjs.createEffect)(()=>$3375ddd88f77967d$var$setPropertyIfExists(style, "--background", options().bg_color));
630
631
  }
631
- function $3375ddd88f77967d$var$ImagesAndVideos({ image_urls_: image_urls_, video_: video_, configuredOptions_: configuredOptions_, cardIsHovered_: cardIsHovered_, aspectRatio_: aspectRatio_ }) {
632
+ function $3375ddd88f77967d$var$ImagesAndVideos({ image_urls_: image_urls_, video_: video_, configuredOptions_: configuredOptions_, cardIsHovered_: cardIsHovered_, aspectRatio_: aspectRatio_, noHoverSupport_: noHoverSupport_ }) {
632
633
  const PLPLayout = (0, $7jsgb$depictaiuilatest.usePLPLayout)();
633
634
  const isAlreadyInSlider = (0, $7jsgb$solidjs.createMemo)(()=>!!((0, $7jsgb$depictaiuilatest.useSlidableInformation)() || PLPLayout?.()?.startsWith("slider")));
634
635
  const containerClasses = ()=>[
@@ -637,8 +638,9 @@ function $3375ddd88f77967d$var$ImagesAndVideos({ image_urls_: image_urls_, video
637
638
  ];
638
639
  // Don't make cards swipable inside of sliders (PLP slider or recs slider)
639
640
  const slidable = (0, $7jsgb$solidjs.createMemo)(()=>!isAlreadyInSlider() && configuredOptions_().image_carousel);
640
- const hoverImageDisabled = (0, $7jsgb$solidjs.createMemo)(()=>!configuredOptions_().use_hover_image);
641
+ const hoverImageDisabled = (0, $7jsgb$solidjs.createMemo)(()=>!configuredOptions_().use_hover_image || noHoverSupport_());
641
642
  const video_urls = ()=>video_()?.video_urls;
643
+ const [userTriedSliding, setUserTriedSliding] = (0, $7jsgb$solidjs.createSignal)(false);
642
644
  const Container = (props)=>{
643
645
  const resolved = (0, $7jsgb$solidjs.children)(()=>props.children);
644
646
  return (0, $7jsgb$solidjsweb.createComponent)((0, $7jsgb$solidjs.Show), {
@@ -654,32 +656,79 @@ function $3375ddd88f77967d$var$ImagesAndVideos({ image_urls_: image_urls_, video
654
656
  })();
655
657
  },
656
658
  get children () {
657
- return (0, $7jsgb$solidjsweb.createComponent)((0, $7jsgb$depictaiuilatest.SlidableItems), {
658
- arrow_height_: 25,
659
- arrow_width_: 12.5,
660
- disable_fading_: true,
661
- slider_ref_: (slider)=>{
662
- const { container: container, insert_here: insert_here } = slider;
663
- slider.stepstoslide = 1; // In case anyone enables the hidden buttons using css
664
- (0, $7jsgb$solidjs.createRenderEffect)((previous)=>(0, $7jsgb$solidjsweb.classList)(container, {
665
- products: true,
666
- ...Object.fromEntries(containerClasses().map((cls)=>[
667
- cls,
668
- true
669
- ]))
670
- }, previous));
671
- // Scroll to beginning when changing what variant we're showing
672
- (0, $7jsgb$solidjs.createEffect)((0, $7jsgb$solidjs.on)(image_urls_, ()=>insert_here.scrollTo({
673
- left: 0,
674
- behavior: "auto"
675
- }), {
676
- defer: true
677
- }));
678
- },
679
- get children () {
680
- return resolved();
681
- }
682
- });
659
+ return (()=>{
660
+ const [userHoveredImage, setUserHoveredImage] = (0, $7jsgb$solidjs.createSignal)(false);
661
+ const productCardIsVisible = (0, $7jsgb$depictaiuilatest.useProductCardIsVisible)();
662
+ const allowPromotingToLayer = (0, $7jsgb$solidjs.createMemo)(()=>{
663
+ if (noHoverSupport_()) // It's not possible to swipe a container that gets an overflow due to the same touch in iOS safari, but to still not have shit performance (especially when going back) we set overflow: hidden on all images that on product cards that are not within the viewport
664
+ return productCardIsVisible();
665
+ return userHoveredImage();
666
+ });
667
+ return (0, $7jsgb$solidjsweb.createComponent)((0, $7jsgb$depictaiuilatest.SlidableItems), {
668
+ arrow_height_: 25,
669
+ arrow_width_: 12.5,
670
+ disable_fading_: true,
671
+ slider_ref_: (slider)=>{
672
+ const { container: container, insert_here: insert_here } = slider;
673
+ slider.stepstoslide = 1; // In case anyone enables the hidden buttons using css
674
+ (0, $7jsgb$solidjs.createRenderEffect)((previous)=>(0, $7jsgb$solidjsweb.classList)(container, {
675
+ products: true,
676
+ ...Object.fromEntries(containerClasses().map((cls)=>[
677
+ cls,
678
+ true
679
+ ]))
680
+ }, previous));
681
+ // Prevent the browser from promoting our slider to its own layer, which is terrible for performance, until the user actually has tried to interact with the swipability
682
+ // -> this is for rendering performance
683
+ // See https://depictaiworkspace.slack.com/archives/C02BASM9X5J/p1714038914867749?thread_ts=1714038547.501939&cid=C02BASM9X5J
684
+ (0, $7jsgb$solidjs.createRenderEffect)(()=>insert_here.style.overflow = allowPromotingToLayer() ? "" : "hidden");
685
+ // If hovered, remove overflow: hidden so user can try swiping
686
+ container.addEventListener("pointerenter", ()=>setUserHoveredImage(true), {
687
+ once: true
688
+ });
689
+ // Scroll to beginning when changing what variant we're showing
690
+ (0, $7jsgb$solidjs.createEffect)((0, $7jsgb$solidjs.on)(image_urls_, ()=>insert_here.scrollTo({
691
+ left: 0,
692
+ behavior: "auto"
693
+ }), {
694
+ defer: true
695
+ }));
696
+ },
697
+ get children () {
698
+ return (()=>{
699
+ const slidableInformation = (0, $7jsgb$depictaiuilatest.useSlidableInformation)();
700
+ (0, $7jsgb$solidjs.createEffect)(()=>{
701
+ // Actually render (and load) the other images when the slider gets swiped
702
+ slidableInformation.intersectionEntries_(); // Re-check when intersecting entries change
703
+ const intersectingsObject = slidableInformation?.slider_.intersecting_items_object;
704
+ // If intersection observers haven't started yet or we aren't in a slider, we count as visible for faster playback
705
+ if (1 in intersectingsObject) setUserTriedSliding(true);
706
+ });
707
+ return resolved;
708
+ })();
709
+ }
710
+ });
711
+ })();
712
+ }
713
+ });
714
+ };
715
+ const [itemsWantingToBeRendered, setItemsWantingToBeRendered] = (0, $7jsgb$solidjs.createSignal)([], {
716
+ equals: false
717
+ });
718
+ // When slidable, only render items (and therefore fetch images) when the user actually tried swiping -> this is for better network performance
719
+ const MaybeShowLazily = (props)=>{
720
+ const us = Symbol();
721
+ setItemsWantingToBeRendered((prev)=>{
722
+ prev.push(us);
723
+ return prev;
724
+ });
725
+ (0, $7jsgb$solidjs.onCleanup)(()=>setItemsWantingToBeRendered((prev)=>prev.filter((item)=>item !== us)));
726
+ return (0, $7jsgb$solidjsweb.createComponent)((0, $7jsgb$solidjs.Show), {
727
+ get when () {
728
+ return !slidable() || itemsWantingToBeRendered()[0] === us || userTriedSliding();
729
+ },
730
+ get children () {
731
+ return props.children;
683
732
  }
684
733
  });
685
734
  };
@@ -703,23 +752,27 @@ function $3375ddd88f77967d$var$ImagesAndVideos({ image_urls_: image_urls_, video
703
752
  return video_urls()?.length;
704
753
  },
705
754
  get children () {
706
- var _el$15 = $3375ddd88f77967d$var$_tmpl$12();
707
- (0, $7jsgb$solidjsweb.insert)(_el$15, (0, $7jsgb$solidjsweb.createComponent)((0, $7jsgb$depictaiuilatest.ImageContainer), {
708
- get aspectRatio () {
709
- return aspectRatio_();
710
- },
755
+ return (0, $7jsgb$solidjsweb.createComponent)(MaybeShowLazily, {
711
756
  get children () {
712
- return (0, $7jsgb$solidjsweb.createComponent)($3375ddd88f77967d$var$Video, {
713
- get video_sources_ () {
714
- return video_urls();
757
+ var _el$15 = $3375ddd88f77967d$var$_tmpl$12();
758
+ (0, $7jsgb$solidjsweb.insert)(_el$15, (0, $7jsgb$solidjsweb.createComponent)((0, $7jsgb$depictaiuilatest.ImageContainer), {
759
+ get aspectRatio () {
760
+ return aspectRatio_();
715
761
  },
716
- get poster_ () {
717
- return video_()?.preview_image_url || image_urls_()?.[0];
762
+ get children () {
763
+ return (0, $7jsgb$solidjsweb.createComponent)($3375ddd88f77967d$var$Video, {
764
+ get video_sources_ () {
765
+ return video_urls();
766
+ },
767
+ get poster_ () {
768
+ return video_()?.preview_image_url || image_urls_()?.[0];
769
+ }
770
+ });
718
771
  }
719
- });
772
+ }));
773
+ return _el$15;
720
774
  }
721
- }));
722
- return _el$15;
775
+ });
723
776
  }
724
777
  }),
725
778
  (0, $7jsgb$solidjsweb.createComponent)((0, $7jsgb$solidjs.Show), {
@@ -736,42 +789,57 @@ function $3375ddd88f77967d$var$ImagesAndVideos({ image_urls_: image_urls_, video
736
789
  return hoverImageDisabled() || index() !== 1;
737
790
  },
738
791
  get children () {
739
- var _el$16 = $3375ddd88f77967d$var$_tmpl$13();
740
- (0, $7jsgb$solidjsweb.insert)(_el$16, (0, $7jsgb$solidjsweb.createComponent)((0, $7jsgb$depictaiuilatest.ShopifyContainedImage), {
741
- src: image_url,
742
- get aspectRatio () {
743
- return aspectRatio_();
744
- },
745
- imgProps: {
746
- alt: "Product image"
747
- }
748
- }), null);
749
- (0, $7jsgb$solidjsweb.insert)(_el$16, (0, $7jsgb$solidjsweb.createComponent)((0, $7jsgb$solidjs.Show), {
750
- get when () {
751
- return (0, $7jsgb$solidjsweb.memo)(()=>!!(!index() && image_urls_()?.[1]))() && !hoverImageDisabled();
752
- },
792
+ return (0, $7jsgb$solidjsweb.createComponent)(MaybeShowLazily, {
753
793
  get children () {
754
- return (0, $7jsgb$solidjsweb.createComponent)((0, $7jsgb$depictaiuilatest.ShopifyContainedImage), {
755
- get src () {
756
- return image_urls_()[1];
757
- },
794
+ var _el$16 = $3375ddd88f77967d$var$_tmpl$13();
795
+ (0, $7jsgb$solidjsweb.insert)(_el$16, (0, $7jsgb$solidjsweb.createComponent)((0, $7jsgb$depictaiuilatest.ShopifyContainedImage), {
796
+ src: image_url,
758
797
  get aspectRatio () {
759
798
  return aspectRatio_();
760
799
  },
761
800
  imgProps: {
762
801
  alt: "Product image"
802
+ }
803
+ }), null);
804
+ (0, $7jsgb$solidjsweb.insert)(_el$16, (0, $7jsgb$solidjsweb.createComponent)((0, $7jsgb$solidjs.Show), {
805
+ get when () {
806
+ return (0, $7jsgb$solidjsweb.memo)(()=>!!(!index() && image_urls_()?.[1]))() && !hoverImageDisabled();
763
807
  },
764
- get ["class"] () {
765
- return `hover${cardIsHovered_() ? " visible" : ""}`;
808
+ get children () {
809
+ return (0, $7jsgb$solidjsweb.createComponent)((0, $7jsgb$depictaiuilatest.ShopifyContainedImage), {
810
+ get src () {
811
+ return image_urls_()[1];
812
+ },
813
+ get aspectRatio () {
814
+ return aspectRatio_();
815
+ },
816
+ imgProps: {
817
+ alt: "Product image"
818
+ },
819
+ get ["class"] () {
820
+ return `hover${cardIsHovered_() ? " visible" : ""}`;
821
+ }
822
+ });
766
823
  }
767
- });
824
+ }), null);
825
+ return _el$16;
768
826
  }
769
- }), null);
770
- return _el$16;
827
+ });
771
828
  }
772
829
  })
773
830
  });
774
831
  }
832
+ }),
833
+ (0, $7jsgb$solidjsweb.createComponent)((0, $7jsgb$solidjs.Show), {
834
+ get when () {
835
+ return (0, $7jsgb$solidjsweb.memo)(()=>!!(slidable() && itemsWantingToBeRendered().length > 1))() && !userTriedSliding();
836
+ },
837
+ get children () {
838
+ return (0, $7jsgb$solidjsweb.createComponent)((0, $7jsgb$depictaiuilatest.ImagePlaceholder), {
839
+ width: "100%",
840
+ height: ""
841
+ });
842
+ }
775
843
  })
776
844
  ];
777
845
  }
package/dist/module.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import {add_to_version_info as $2MCgq$add_to_version_info, standard_price_format as $2MCgq$standard_price_format, catchify as $2MCgq$catchify, dlog as $2MCgq$dlog, dwarn as $2MCgq$dwarn} from "@depict-ai/utilishared/latest";
2
- import {RecommendationGrid as $2MCgq$RecommendationGrid, defaultColsAtSize as $2MCgq$defaultColsAtSize, defaultGridSpacing as $2MCgq$defaultGridSpacing, media_query_to_accessor as $2MCgq$media_query_to_accessor, TextPlaceholder as $2MCgq$TextPlaceholder, useListing as $2MCgq$useListing, shopifyContainedImageContextSymbol as $2MCgq$shopifyContainedImageContextSymbol, usePLPLayout as $2MCgq$usePLPLayout, useSlidableInformation as $2MCgq$useSlidableInformation, SlidableItems as $2MCgq$SlidableItems, ImagePlaceholder as $2MCgq$ImagePlaceholder, ImageContainer as $2MCgq$ImageContainer, ShopifyContainedImage as $2MCgq$ShopifyContainedImage, useVisibilityState as $2MCgq$useVisibilityState, useProductCardIndex as $2MCgq$useProductCardIndex, useProductCardIsVisible as $2MCgq$useProductCardIsVisible, RecommendationSlider as $2MCgq$RecommendationSlider, accessor_of_object_to_object_with_accessor_values as $2MCgq$accessor_of_object_to_object_with_accessor_values, create_modified_filters as $2MCgq$create_modified_filters, SelectedFilters as $2MCgq$SelectedFilters, FilterBody as $2MCgq$FilterBody, ExpandingDetails as $2MCgq$ExpandingDetails, ListingProvider as $2MCgq$ListingProvider, PseudoRouter as $2MCgq$PseudoRouter, LookCard as $2MCgq$LookCard} from "@depict-ai/ui/latest";
2
+ import {RecommendationGrid as $2MCgq$RecommendationGrid, defaultColsAtSize as $2MCgq$defaultColsAtSize, defaultGridSpacing as $2MCgq$defaultGridSpacing, media_query_to_accessor as $2MCgq$media_query_to_accessor, TextPlaceholder as $2MCgq$TextPlaceholder, useListing as $2MCgq$useListing, shopifyContainedImageContextSymbol as $2MCgq$shopifyContainedImageContextSymbol, usePLPLayout as $2MCgq$usePLPLayout, useSlidableInformation as $2MCgq$useSlidableInformation, useProductCardIsVisible as $2MCgq$useProductCardIsVisible, SlidableItems as $2MCgq$SlidableItems, ImagePlaceholder as $2MCgq$ImagePlaceholder, ImageContainer as $2MCgq$ImageContainer, ShopifyContainedImage as $2MCgq$ShopifyContainedImage, useVisibilityState as $2MCgq$useVisibilityState, useProductCardIndex as $2MCgq$useProductCardIndex, RecommendationSlider as $2MCgq$RecommendationSlider, accessor_of_object_to_object_with_accessor_values as $2MCgq$accessor_of_object_to_object_with_accessor_values, create_modified_filters as $2MCgq$create_modified_filters, SelectedFilters as $2MCgq$SelectedFilters, FilterBody as $2MCgq$FilterBody, ExpandingDetails as $2MCgq$ExpandingDetails, ListingProvider as $2MCgq$ListingProvider, PseudoRouter as $2MCgq$PseudoRouter, LookCard as $2MCgq$LookCard} from "@depict-ai/ui/latest";
3
3
  import {render as $2MCgq$render, template as $2MCgq$template, createComponent as $2MCgq$createComponent, addEventListener as $2MCgq$addEventListener, use as $2MCgq$use, insert as $2MCgq$insert, effect as $2MCgq$effect, className as $2MCgq$className, setAttribute as $2MCgq$setAttribute, memo as $2MCgq$memo, style as $2MCgq$style, classList as $2MCgq$classList, spread as $2MCgq$spread, mergeProps as $2MCgq$mergeProps, delegateEvents as $2MCgq$delegateEvents} from "solid-js/web";
4
4
  import {useRef as $2MCgq$useRef, useState as $2MCgq$useState, useEffect as $2MCgq$useEffect, createElement as $2MCgq$createElement, Fragment as $2MCgq$Fragment} from "react";
5
5
  import {createStore as $2MCgq$createStore, reconcile as $2MCgq$reconcile} from "solid-js/store";
@@ -7,7 +7,7 @@ import {createContext as $2MCgq$createContext, createMemo as $2MCgq$createMemo,
7
7
  import {createPortal as $2MCgq$createPortal} from "react-dom";
8
8
 
9
9
  /*! Depict.ai portal components */ // This is where the actual source of your React stuff should live
10
- const $91c11b750e80ede3$export$83d89fbfd8236492 = "2.7.27";
10
+ const $91c11b750e80ede3$export$83d89fbfd8236492 = "2.7.29";
11
11
 
12
12
 
13
13
 
@@ -200,7 +200,8 @@ function $29535f590238371c$export$f11681c54c860912(display, info, configuredOpti
200
200
  video_: ()=>variantToShow()?.video,
201
201
  configuredOptions_: configuredOptions_,
202
202
  cardIsHovered_: ()=>showVariantIndex() === display()?.variant_index && cardIsHovered(),
203
- aspectRatio_: aspectRatio_
203
+ aspectRatio_: aspectRatio_,
204
+ noHoverSupport_: noHoverSupport_
204
205
  });
205
206
  }
206
207
  }), null);
@@ -615,7 +616,7 @@ function $29535f590238371c$var$setStyleForTextOptions({ style: style }, options)
615
616
  (0, $2MCgq$createEffect)(()=>$29535f590238371c$var$setPropertyIfExists(style, "--color", options().color));
616
617
  (0, $2MCgq$createEffect)(()=>$29535f590238371c$var$setPropertyIfExists(style, "--background", options().bg_color));
617
618
  }
618
- function $29535f590238371c$var$ImagesAndVideos({ image_urls_: image_urls_, video_: video_, configuredOptions_: configuredOptions_, cardIsHovered_: cardIsHovered_, aspectRatio_: aspectRatio_ }) {
619
+ function $29535f590238371c$var$ImagesAndVideos({ image_urls_: image_urls_, video_: video_, configuredOptions_: configuredOptions_, cardIsHovered_: cardIsHovered_, aspectRatio_: aspectRatio_, noHoverSupport_: noHoverSupport_ }) {
619
620
  const PLPLayout = (0, $2MCgq$usePLPLayout)();
620
621
  const isAlreadyInSlider = (0, $2MCgq$createMemo)(()=>!!((0, $2MCgq$useSlidableInformation)() || PLPLayout?.()?.startsWith("slider")));
621
622
  const containerClasses = ()=>[
@@ -624,8 +625,9 @@ function $29535f590238371c$var$ImagesAndVideos({ image_urls_: image_urls_, video
624
625
  ];
625
626
  // Don't make cards swipable inside of sliders (PLP slider or recs slider)
626
627
  const slidable = (0, $2MCgq$createMemo)(()=>!isAlreadyInSlider() && configuredOptions_().image_carousel);
627
- const hoverImageDisabled = (0, $2MCgq$createMemo)(()=>!configuredOptions_().use_hover_image);
628
+ const hoverImageDisabled = (0, $2MCgq$createMemo)(()=>!configuredOptions_().use_hover_image || noHoverSupport_());
628
629
  const video_urls = ()=>video_()?.video_urls;
630
+ const [userTriedSliding, setUserTriedSliding] = (0, $2MCgq$createSignal)(false);
629
631
  const Container = (props)=>{
630
632
  const resolved = (0, $2MCgq$children)(()=>props.children);
631
633
  return (0, $2MCgq$createComponent)((0, $2MCgq$Show), {
@@ -641,32 +643,79 @@ function $29535f590238371c$var$ImagesAndVideos({ image_urls_: image_urls_, video
641
643
  })();
642
644
  },
643
645
  get children () {
644
- return (0, $2MCgq$createComponent)((0, $2MCgq$SlidableItems), {
645
- arrow_height_: 25,
646
- arrow_width_: 12.5,
647
- disable_fading_: true,
648
- slider_ref_: (slider)=>{
649
- const { container: container, insert_here: insert_here } = slider;
650
- slider.stepstoslide = 1; // In case anyone enables the hidden buttons using css
651
- (0, $2MCgq$createRenderEffect)((previous)=>(0, $2MCgq$classList)(container, {
652
- products: true,
653
- ...Object.fromEntries(containerClasses().map((cls)=>[
654
- cls,
655
- true
656
- ]))
657
- }, previous));
658
- // Scroll to beginning when changing what variant we're showing
659
- (0, $2MCgq$createEffect)((0, $2MCgq$on)(image_urls_, ()=>insert_here.scrollTo({
660
- left: 0,
661
- behavior: "auto"
662
- }), {
663
- defer: true
664
- }));
665
- },
666
- get children () {
667
- return resolved();
668
- }
669
- });
646
+ return (()=>{
647
+ const [userHoveredImage, setUserHoveredImage] = (0, $2MCgq$createSignal)(false);
648
+ const productCardIsVisible = (0, $2MCgq$useProductCardIsVisible)();
649
+ const allowPromotingToLayer = (0, $2MCgq$createMemo)(()=>{
650
+ if (noHoverSupport_()) // It's not possible to swipe a container that gets an overflow due to the same touch in iOS safari, but to still not have shit performance (especially when going back) we set overflow: hidden on all images that on product cards that are not within the viewport
651
+ return productCardIsVisible();
652
+ return userHoveredImage();
653
+ });
654
+ return (0, $2MCgq$createComponent)((0, $2MCgq$SlidableItems), {
655
+ arrow_height_: 25,
656
+ arrow_width_: 12.5,
657
+ disable_fading_: true,
658
+ slider_ref_: (slider)=>{
659
+ const { container: container, insert_here: insert_here } = slider;
660
+ slider.stepstoslide = 1; // In case anyone enables the hidden buttons using css
661
+ (0, $2MCgq$createRenderEffect)((previous)=>(0, $2MCgq$classList)(container, {
662
+ products: true,
663
+ ...Object.fromEntries(containerClasses().map((cls)=>[
664
+ cls,
665
+ true
666
+ ]))
667
+ }, previous));
668
+ // Prevent the browser from promoting our slider to its own layer, which is terrible for performance, until the user actually has tried to interact with the swipability
669
+ // -> this is for rendering performance
670
+ // See https://depictaiworkspace.slack.com/archives/C02BASM9X5J/p1714038914867749?thread_ts=1714038547.501939&cid=C02BASM9X5J
671
+ (0, $2MCgq$createRenderEffect)(()=>insert_here.style.overflow = allowPromotingToLayer() ? "" : "hidden");
672
+ // If hovered, remove overflow: hidden so user can try swiping
673
+ container.addEventListener("pointerenter", ()=>setUserHoveredImage(true), {
674
+ once: true
675
+ });
676
+ // Scroll to beginning when changing what variant we're showing
677
+ (0, $2MCgq$createEffect)((0, $2MCgq$on)(image_urls_, ()=>insert_here.scrollTo({
678
+ left: 0,
679
+ behavior: "auto"
680
+ }), {
681
+ defer: true
682
+ }));
683
+ },
684
+ get children () {
685
+ return (()=>{
686
+ const slidableInformation = (0, $2MCgq$useSlidableInformation)();
687
+ (0, $2MCgq$createEffect)(()=>{
688
+ // Actually render (and load) the other images when the slider gets swiped
689
+ slidableInformation.intersectionEntries_(); // Re-check when intersecting entries change
690
+ const intersectingsObject = slidableInformation?.slider_.intersecting_items_object;
691
+ // If intersection observers haven't started yet or we aren't in a slider, we count as visible for faster playback
692
+ if (1 in intersectingsObject) setUserTriedSliding(true);
693
+ });
694
+ return resolved;
695
+ })();
696
+ }
697
+ });
698
+ })();
699
+ }
700
+ });
701
+ };
702
+ const [itemsWantingToBeRendered, setItemsWantingToBeRendered] = (0, $2MCgq$createSignal)([], {
703
+ equals: false
704
+ });
705
+ // When slidable, only render items (and therefore fetch images) when the user actually tried swiping -> this is for better network performance
706
+ const MaybeShowLazily = (props)=>{
707
+ const us = Symbol();
708
+ setItemsWantingToBeRendered((prev)=>{
709
+ prev.push(us);
710
+ return prev;
711
+ });
712
+ (0, $2MCgq$onCleanup)(()=>setItemsWantingToBeRendered((prev)=>prev.filter((item)=>item !== us)));
713
+ return (0, $2MCgq$createComponent)((0, $2MCgq$Show), {
714
+ get when () {
715
+ return !slidable() || itemsWantingToBeRendered()[0] === us || userTriedSliding();
716
+ },
717
+ get children () {
718
+ return props.children;
670
719
  }
671
720
  });
672
721
  };
@@ -690,23 +739,27 @@ function $29535f590238371c$var$ImagesAndVideos({ image_urls_: image_urls_, video
690
739
  return video_urls()?.length;
691
740
  },
692
741
  get children () {
693
- var _el$15 = $29535f590238371c$var$_tmpl$12();
694
- (0, $2MCgq$insert)(_el$15, (0, $2MCgq$createComponent)((0, $2MCgq$ImageContainer), {
695
- get aspectRatio () {
696
- return aspectRatio_();
697
- },
742
+ return (0, $2MCgq$createComponent)(MaybeShowLazily, {
698
743
  get children () {
699
- return (0, $2MCgq$createComponent)($29535f590238371c$var$Video, {
700
- get video_sources_ () {
701
- return video_urls();
744
+ var _el$15 = $29535f590238371c$var$_tmpl$12();
745
+ (0, $2MCgq$insert)(_el$15, (0, $2MCgq$createComponent)((0, $2MCgq$ImageContainer), {
746
+ get aspectRatio () {
747
+ return aspectRatio_();
702
748
  },
703
- get poster_ () {
704
- return video_()?.preview_image_url || image_urls_()?.[0];
749
+ get children () {
750
+ return (0, $2MCgq$createComponent)($29535f590238371c$var$Video, {
751
+ get video_sources_ () {
752
+ return video_urls();
753
+ },
754
+ get poster_ () {
755
+ return video_()?.preview_image_url || image_urls_()?.[0];
756
+ }
757
+ });
705
758
  }
706
- });
759
+ }));
760
+ return _el$15;
707
761
  }
708
- }));
709
- return _el$15;
762
+ });
710
763
  }
711
764
  }),
712
765
  (0, $2MCgq$createComponent)((0, $2MCgq$Show), {
@@ -723,42 +776,57 @@ function $29535f590238371c$var$ImagesAndVideos({ image_urls_: image_urls_, video
723
776
  return hoverImageDisabled() || index() !== 1;
724
777
  },
725
778
  get children () {
726
- var _el$16 = $29535f590238371c$var$_tmpl$13();
727
- (0, $2MCgq$insert)(_el$16, (0, $2MCgq$createComponent)((0, $2MCgq$ShopifyContainedImage), {
728
- src: image_url,
729
- get aspectRatio () {
730
- return aspectRatio_();
731
- },
732
- imgProps: {
733
- alt: "Product image"
734
- }
735
- }), null);
736
- (0, $2MCgq$insert)(_el$16, (0, $2MCgq$createComponent)((0, $2MCgq$Show), {
737
- get when () {
738
- return (0, $2MCgq$memo)(()=>!!(!index() && image_urls_()?.[1]))() && !hoverImageDisabled();
739
- },
779
+ return (0, $2MCgq$createComponent)(MaybeShowLazily, {
740
780
  get children () {
741
- return (0, $2MCgq$createComponent)((0, $2MCgq$ShopifyContainedImage), {
742
- get src () {
743
- return image_urls_()[1];
744
- },
781
+ var _el$16 = $29535f590238371c$var$_tmpl$13();
782
+ (0, $2MCgq$insert)(_el$16, (0, $2MCgq$createComponent)((0, $2MCgq$ShopifyContainedImage), {
783
+ src: image_url,
745
784
  get aspectRatio () {
746
785
  return aspectRatio_();
747
786
  },
748
787
  imgProps: {
749
788
  alt: "Product image"
789
+ }
790
+ }), null);
791
+ (0, $2MCgq$insert)(_el$16, (0, $2MCgq$createComponent)((0, $2MCgq$Show), {
792
+ get when () {
793
+ return (0, $2MCgq$memo)(()=>!!(!index() && image_urls_()?.[1]))() && !hoverImageDisabled();
750
794
  },
751
- get ["class"] () {
752
- return `hover${cardIsHovered_() ? " visible" : ""}`;
795
+ get children () {
796
+ return (0, $2MCgq$createComponent)((0, $2MCgq$ShopifyContainedImage), {
797
+ get src () {
798
+ return image_urls_()[1];
799
+ },
800
+ get aspectRatio () {
801
+ return aspectRatio_();
802
+ },
803
+ imgProps: {
804
+ alt: "Product image"
805
+ },
806
+ get ["class"] () {
807
+ return `hover${cardIsHovered_() ? " visible" : ""}`;
808
+ }
809
+ });
753
810
  }
754
- });
811
+ }), null);
812
+ return _el$16;
755
813
  }
756
- }), null);
757
- return _el$16;
814
+ });
758
815
  }
759
816
  })
760
817
  });
761
818
  }
819
+ }),
820
+ (0, $2MCgq$createComponent)((0, $2MCgq$Show), {
821
+ get when () {
822
+ return (0, $2MCgq$memo)(()=>!!(slidable() && itemsWantingToBeRendered().length > 1))() && !userTriedSliding();
823
+ },
824
+ get children () {
825
+ return (0, $2MCgq$createComponent)((0, $2MCgq$ImagePlaceholder), {
826
+ width: "100%",
827
+ height: ""
828
+ });
829
+ }
762
830
  })
763
831
  ];
764
832
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@depict-ai/portal-components",
3
- "version": "2.7.27",
3
+ "version": "2.7.29",
4
4
  "packageManager": "yarn@3.2.2",
5
5
  "source": "src/index.ts",
6
6
  "main": "dist/main.js",
@@ -104,7 +104,7 @@
104
104
  "@depict-ai/plp-styling": "^4.4.20",
105
105
  "@depict-ai/react-ui": "^4.8.7",
106
106
  "@depict-ai/types": "^5.4.5",
107
- "@depict-ai/ui": "^4.8.20",
107
+ "@depict-ai/ui": "^4.8.21",
108
108
  "@depict-ai/utilishared": "^2.4.7",
109
109
  "parcel": "^2.10.3",
110
110
  "solid-js": "^1.8.16"
@@ -267,6 +267,7 @@ export function DefaultSolidProductCard(
267
267
  configuredOptions_={configuredOptions_}
268
268
  cardIsHovered_={() => showVariantIndex() === display()?.variant_index && cardIsHovered()}
269
269
  aspectRatio_={aspectRatio_}
270
+ noHoverSupport_={noHoverSupport_}
270
271
  />
271
272
  </LinkWrapped>
272
273
 
@@ -677,63 +678,119 @@ function ImagesAndVideos({
677
678
  configuredOptions_,
678
679
  cardIsHovered_,
679
680
  aspectRatio_,
681
+ noHoverSupport_,
680
682
  }: {
681
683
  image_urls_: Accessor<undefined | string[]>;
682
684
  video_: Accessor<undefined | { preview_image_url: string; video_urls: string[] }>;
683
685
  configuredOptions_: Accessor<ProductCardSchema>;
684
686
  cardIsHovered_: Accessor<boolean>;
685
687
  aspectRatio_: Accessor<number>;
688
+ noHoverSupport_: Accessor<boolean>;
686
689
  }) {
687
690
  const PLPLayout = usePLPLayout();
688
691
  const isAlreadyInSlider = createMemo(() => !!(useSlidableInformation() || PLPLayout?.()?.startsWith("slider")));
689
692
  const containerClasses = () => ["image-video", "border-radius-" + configuredOptions_().image_radius] as const;
690
693
  // Don't make cards swipable inside of sliders (PLP slider or recs slider)
691
694
  const slidable = createMemo(() => !isAlreadyInSlider() && configuredOptions_().image_carousel);
692
- const hoverImageDisabled = createMemo(() => !configuredOptions_().use_hover_image);
695
+ const hoverImageDisabled = createMemo(() => !configuredOptions_().use_hover_image || noHoverSupport_());
693
696
  const video_urls = () => video_()?.video_urls;
697
+ const [userTriedSliding, setUserTriedSliding] = createSignal(false);
694
698
 
695
699
  const Container = (props: { children: JSX.Element }) => {
696
700
  const resolved = children(() => props.children);
697
701
  return (
698
702
  <Show when={slidable()} fallback={<div class={containerClasses().join(" ")}>{resolved()}</div>}>
699
- <SlidableItems
700
- arrow_height_={25}
701
- arrow_width_={12.5}
702
- disable_fading_={true}
703
- slider_ref_={slider => {
704
- const { container, insert_here } = slider;
705
- slider.stepstoslide = 1; // In case anyone enables the hidden buttons using css
703
+ {(() => {
704
+ const [userHoveredImage, setUserHoveredImage] = createSignal(false);
705
+ const productCardIsVisible = useProductCardIsVisible();
706
+ const allowPromotingToLayer = createMemo(() => {
707
+ if (noHoverSupport_()) {
708
+ // It's not possible to swipe a container that gets an overflow due to the same touch in iOS safari, but to still not have shit performance (especially when going back) we set overflow: hidden on all images that on product cards that are not within the viewport
709
+ return productCardIsVisible();
710
+ }
711
+ return userHoveredImage();
712
+ });
706
713
 
707
- createRenderEffect<{ [k: string]: boolean } | undefined>(previous =>
708
- classList(
709
- container,
710
- { products: true, ...Object.fromEntries(containerClasses().map(cls => [cls, true])) },
711
- previous
712
- )
713
- );
714
+ return (
715
+ <SlidableItems
716
+ arrow_height_={25}
717
+ arrow_width_={12.5}
718
+ disable_fading_={true}
719
+ slider_ref_={slider => {
720
+ const { container, insert_here } = slider;
721
+ slider.stepstoslide = 1; // In case anyone enables the hidden buttons using css
722
+
723
+ createRenderEffect<{ [k: string]: boolean } | undefined>(previous =>
724
+ classList(
725
+ container,
726
+ { products: true, ...Object.fromEntries(containerClasses().map(cls => [cls, true])) },
727
+ previous
728
+ )
729
+ );
730
+
731
+ // Prevent the browser from promoting our slider to its own layer, which is terrible for performance, until the user actually has tried to interact with the swipability
732
+ // -> this is for rendering performance
733
+ // See https://depictaiworkspace.slack.com/archives/C02BASM9X5J/p1714038914867749?thread_ts=1714038547.501939&cid=C02BASM9X5J
734
+ createRenderEffect(() => (insert_here.style.overflow = allowPromotingToLayer() ? "" : "hidden"));
735
+
736
+ // If hovered, remove overflow: hidden so user can try swiping
737
+ container.addEventListener("pointerenter", () => setUserHoveredImage(true), { once: true });
738
+
739
+ // Scroll to beginning when changing what variant we're showing
740
+ createEffect(
741
+ on(image_urls_, () => insert_here.scrollTo({ left: 0, behavior: "auto" }), { defer: true })
742
+ );
743
+ }}
744
+ >
745
+ {(() => {
746
+ const slidableInformation = useSlidableInformation();
747
+
748
+ createEffect(() => {
749
+ // Actually render (and load) the other images when the slider gets swiped
750
+ slidableInformation!.intersectionEntries_(); // Re-check when intersecting entries change
751
+ const intersectingsObject = slidableInformation?.slider_.intersecting_items_object;
752
+ // If intersection observers haven't started yet or we aren't in a slider, we count as visible for faster playback
753
+ if (1 in intersectingsObject!) {
754
+ setUserTriedSliding(true);
755
+ }
756
+ });
714
757
 
715
- // Scroll to beginning when changing what variant we're showing
716
- createEffect(on(image_urls_, () => insert_here.scrollTo({ left: 0, behavior: "auto" }), { defer: true }));
717
- }}
718
- >
719
- {resolved()}
720
- </SlidableItems>
758
+ return resolved as unknown as JSX.Element;
759
+ })()}
760
+ </SlidableItems>
761
+ );
762
+ })()}
721
763
  </Show>
722
764
  );
723
765
  };
766
+ const [itemsWantingToBeRendered, setItemsWantingToBeRendered] = createSignal<symbol[]>([], { equals: false });
767
+ // When slidable, only render items (and therefore fetch images) when the user actually tried swiping -> this is for better network performance
768
+ const MaybeShowLazily = (props: { children: JSX.Element }) => {
769
+ const us = Symbol();
770
+ setItemsWantingToBeRendered(prev => {
771
+ prev.push(us);
772
+ return prev;
773
+ });
774
+ onCleanup(() => setItemsWantingToBeRendered(prev => prev.filter(item => item !== us)));
775
+ return (
776
+ <Show when={!slidable() || itemsWantingToBeRendered()[0] === us || userTriedSliding()}>{props.children}</Show>
777
+ );
778
+ };
724
779
 
725
780
  return (
726
781
  <Show when={image_urls_()} fallback={<ImagePlaceholder aspectRatio={aspectRatio_()} />}>
727
782
  <Container>
728
783
  <Show when={video_urls()?.length}>
729
- <div class="media-item video">
730
- <ImageContainer aspectRatio={aspectRatio_()}>
731
- <Video
732
- video_sources_={video_urls() as [string, ...string[]]}
733
- poster_={video_()?.preview_image_url || image_urls_()?.[0]}
734
- />
735
- </ImageContainer>
736
- </div>
784
+ <MaybeShowLazily>
785
+ <div class="media-item video">
786
+ <ImageContainer aspectRatio={aspectRatio_()}>
787
+ <Video
788
+ video_sources_={video_urls() as [string, ...string[]]}
789
+ poster_={video_()?.preview_image_url || image_urls_()?.[0]}
790
+ />
791
+ </ImageContainer>
792
+ </div>
793
+ </MaybeShowLazily>
737
794
  </Show>
738
795
  <Show when={!video_urls()?.length || slidable()}>
739
796
  <For each={slidable() ? image_urls_() : image_urls_()?.slice(0, 1)}>
@@ -741,26 +798,31 @@ function ImagesAndVideos({
741
798
  <Show when={hoverImageDisabled() || index() !== 1}>
742
799
  {/* The image with index 1 will already be shown as hover image if hover is supported, so hide it in the slider
743
800
  (We assume people don't discover the slider can be slided on desktop) */}
744
- <div class="media-item image">
745
- {/* Hover to see JSDOc for ShopifyContainedImage */}
746
- <ShopifyContainedImage
747
- src={image_url}
748
- aspectRatio={aspectRatio_()}
749
- imgProps={{ alt: "Product image" }}
750
- />
751
- <Show when={!index() && image_urls_()?.[1] && !hoverImageDisabled()}>
801
+ <MaybeShowLazily>
802
+ <div class="media-item image">
803
+ {/* Hover to see JSDOc for ShopifyContainedImage */}
752
804
  <ShopifyContainedImage
753
- src={image_urls_()![1]}
805
+ src={image_url}
754
806
  aspectRatio={aspectRatio_()}
755
807
  imgProps={{ alt: "Product image" }}
756
- class={`hover${cardIsHovered_() ? " visible" : ""}`}
757
808
  />
758
- </Show>
759
- </div>
809
+ <Show when={!index() && image_urls_()?.[1] && !hoverImageDisabled()}>
810
+ <ShopifyContainedImage
811
+ src={image_urls_()![1]}
812
+ aspectRatio={aspectRatio_()}
813
+ imgProps={{ alt: "Product image" }}
814
+ class={`hover${cardIsHovered_() ? " visible" : ""}`}
815
+ />
816
+ </Show>
817
+ </div>
818
+ </MaybeShowLazily>
760
819
  </Show>
761
820
  )}
762
821
  </For>
763
822
  </Show>
823
+ <Show when={slidable() && itemsWantingToBeRendered().length > 1 && !userTriedSliding()}>
824
+ <ImagePlaceholder width="100%" height="" />
825
+ </Show>
764
826
  </Container>
765
827
  </Show>
766
828
  );