@depict-ai/portal-components 2.7.28 → 2.7.30

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.30";
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.28";
23
+ const $0a017be3a74fcc94$export$83d89fbfd8236492 = "2.7.30";
24
24
 
25
25
 
26
26
 
@@ -631,15 +631,18 @@ function $3375ddd88f77967d$var$setStyleForTextOptions({ style: style }, options)
631
631
  }
632
632
  function $3375ddd88f77967d$var$ImagesAndVideos({ image_urls_: image_urls_, video_: video_, configuredOptions_: configuredOptions_, cardIsHovered_: cardIsHovered_, aspectRatio_: aspectRatio_, noHoverSupport_: noHoverSupport_ }) {
633
633
  const PLPLayout = (0, $7jsgb$depictaiuilatest.usePLPLayout)();
634
- const isAlreadyInSlider = (0, $7jsgb$solidjs.createMemo)(()=>!!((0, $7jsgb$depictaiuilatest.useSlidableInformation)() || PLPLayout?.()?.startsWith("slider")));
635
634
  const containerClasses = ()=>[
636
635
  "image-video",
637
636
  "border-radius-" + configuredOptions_().image_radius
638
637
  ];
639
- // Don't make cards swipable inside of sliders (PLP slider or recs slider)
640
- const slidable = (0, $7jsgb$solidjs.createMemo)(()=>!isAlreadyInSlider() && configuredOptions_().image_carousel);
638
+ const productCardIsVisible = (0, $7jsgb$depictaiuilatest.useProductCardIsVisible)();
639
+ const hasBeenVisible = (0, $7jsgb$solidjs.createMemo)((prev)=>prev || productCardIsVisible());
640
+ const slidable = (0, $7jsgb$solidjs.createMemo)(()=>// Don't make cards swipable inside of sliders (PLP slider or recs slider)
641
+ !((0, $7jsgb$depictaiuilatest.useSlidableInformation)() || PLPLayout?.()?.startsWith("slider")) && configuredOptions_().image_carousel && // Delay creation of slider until card has been visible. We can't do it until the user interacts with it because it sometimes glitches the hover effect, but initialising the slider takes some time (need to compute if the buttons should be shown, there's a Mutationobserver, etc) so it's good to not initialise all at once (for example when going back)
642
+ hasBeenVisible());
641
643
  const hoverImageDisabled = (0, $7jsgb$solidjs.createMemo)(()=>!configuredOptions_().use_hover_image || noHoverSupport_());
642
644
  const video_urls = ()=>video_()?.video_urls;
645
+ const [userTriedSliding, setUserTriedSliding] = (0, $7jsgb$solidjs.createSignal)(false);
643
646
  const Container = (props)=>{
644
647
  const resolved = (0, $7jsgb$solidjs.children)(()=>props.children);
645
648
  return (0, $7jsgb$solidjsweb.createComponent)((0, $7jsgb$solidjs.Show), {
@@ -655,32 +658,78 @@ function $3375ddd88f77967d$var$ImagesAndVideos({ image_urls_: image_urls_, video
655
658
  })();
656
659
  },
657
660
  get children () {
658
- return (0, $7jsgb$solidjsweb.createComponent)((0, $7jsgb$depictaiuilatest.SlidableItems), {
659
- arrow_height_: 25,
660
- arrow_width_: 12.5,
661
- disable_fading_: true,
662
- slider_ref_: (slider)=>{
663
- const { container: container, insert_here: insert_here } = slider;
664
- slider.stepstoslide = 1; // In case anyone enables the hidden buttons using css
665
- (0, $7jsgb$solidjs.createRenderEffect)((previous)=>(0, $7jsgb$solidjsweb.classList)(container, {
666
- products: true,
667
- ...Object.fromEntries(containerClasses().map((cls)=>[
668
- cls,
669
- true
670
- ]))
671
- }, previous));
672
- // Scroll to beginning when changing what variant we're showing
673
- (0, $7jsgb$solidjs.createEffect)((0, $7jsgb$solidjs.on)(image_urls_, ()=>insert_here.scrollTo({
674
- left: 0,
675
- behavior: "auto"
676
- }), {
677
- defer: true
678
- }));
679
- },
680
- get children () {
681
- return resolved();
682
- }
683
- });
661
+ return (()=>{
662
+ const [userHoveredImage, setUserHoveredImage] = (0, $7jsgb$solidjs.createSignal)(false);
663
+ const allowPromotingToLayer = (0, $7jsgb$solidjs.createMemo)(()=>{
664
+ 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
665
+ return productCardIsVisible();
666
+ return userHoveredImage();
667
+ });
668
+ return (0, $7jsgb$solidjsweb.createComponent)((0, $7jsgb$depictaiuilatest.SlidableItems), {
669
+ arrow_height_: 25,
670
+ arrow_width_: 12.5,
671
+ disable_fading_: true,
672
+ slider_ref_: (slider)=>{
673
+ const { container: container, insert_here: insert_here } = slider;
674
+ slider.stepstoslide = 1; // In case anyone enables the hidden buttons using css
675
+ (0, $7jsgb$solidjs.createRenderEffect)((previous)=>(0, $7jsgb$solidjsweb.classList)(container, {
676
+ products: true,
677
+ ...Object.fromEntries(containerClasses().map((cls)=>[
678
+ cls,
679
+ true
680
+ ]))
681
+ }, previous));
682
+ // 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
683
+ // -> this is for rendering performance
684
+ // See https://depictaiworkspace.slack.com/archives/C02BASM9X5J/p1714038914867749?thread_ts=1714038547.501939&cid=C02BASM9X5J
685
+ (0, $7jsgb$solidjs.createRenderEffect)(()=>insert_here.style.overflow = allowPromotingToLayer() ? "" : "hidden");
686
+ // If hovered, remove overflow: hidden so user can try swiping
687
+ container.addEventListener("pointerenter", ()=>setUserHoveredImage(true), {
688
+ once: true
689
+ });
690
+ // Scroll to beginning when changing what variant we're showing
691
+ (0, $7jsgb$solidjs.createEffect)((0, $7jsgb$solidjs.on)(image_urls_, ()=>insert_here.scrollTo({
692
+ left: 0,
693
+ behavior: "auto"
694
+ }), {
695
+ defer: true
696
+ }));
697
+ },
698
+ get children () {
699
+ return (()=>{
700
+ const slidableInformation = (0, $7jsgb$depictaiuilatest.useSlidableInformation)();
701
+ (0, $7jsgb$solidjs.createEffect)(()=>{
702
+ // Actually render (and load) the other images when the slider gets swiped
703
+ slidableInformation.intersectionEntries_(); // Re-check when intersecting entries change
704
+ const intersectingsObject = slidableInformation?.slider_.intersecting_items_object;
705
+ // If intersection observers haven't started yet or we aren't in a slider, we count as visible for faster playback
706
+ if (1 in intersectingsObject) setUserTriedSliding(true);
707
+ });
708
+ return resolved;
709
+ })();
710
+ }
711
+ });
712
+ })();
713
+ }
714
+ });
715
+ };
716
+ const [itemsWantingToBeRendered, setItemsWantingToBeRendered] = (0, $7jsgb$solidjs.createSignal)([], {
717
+ equals: false
718
+ });
719
+ // When slidable, only render items (and therefore fetch images) when the user actually tried swiping -> this is for better network performance
720
+ const MaybeShowLazily = (props)=>{
721
+ const us = Symbol();
722
+ setItemsWantingToBeRendered((prev)=>{
723
+ prev.push(us);
724
+ return prev;
725
+ });
726
+ (0, $7jsgb$solidjs.onCleanup)(()=>setItemsWantingToBeRendered((prev)=>prev.filter((item)=>item !== us)));
727
+ return (0, $7jsgb$solidjsweb.createComponent)((0, $7jsgb$solidjs.Show), {
728
+ get when () {
729
+ return !slidable() || itemsWantingToBeRendered()[0] === us || userTriedSliding();
730
+ },
731
+ get children () {
732
+ return props.children;
684
733
  }
685
734
  });
686
735
  };
@@ -704,23 +753,27 @@ function $3375ddd88f77967d$var$ImagesAndVideos({ image_urls_: image_urls_, video
704
753
  return video_urls()?.length;
705
754
  },
706
755
  get children () {
707
- var _el$15 = $3375ddd88f77967d$var$_tmpl$12();
708
- (0, $7jsgb$solidjsweb.insert)(_el$15, (0, $7jsgb$solidjsweb.createComponent)((0, $7jsgb$depictaiuilatest.ImageContainer), {
709
- get aspectRatio () {
710
- return aspectRatio_();
711
- },
756
+ return (0, $7jsgb$solidjsweb.createComponent)(MaybeShowLazily, {
712
757
  get children () {
713
- return (0, $7jsgb$solidjsweb.createComponent)($3375ddd88f77967d$var$Video, {
714
- get video_sources_ () {
715
- return video_urls();
758
+ var _el$15 = $3375ddd88f77967d$var$_tmpl$12();
759
+ (0, $7jsgb$solidjsweb.insert)(_el$15, (0, $7jsgb$solidjsweb.createComponent)((0, $7jsgb$depictaiuilatest.ImageContainer), {
760
+ get aspectRatio () {
761
+ return aspectRatio_();
716
762
  },
717
- get poster_ () {
718
- return video_()?.preview_image_url || image_urls_()?.[0];
763
+ get children () {
764
+ return (0, $7jsgb$solidjsweb.createComponent)($3375ddd88f77967d$var$Video, {
765
+ get video_sources_ () {
766
+ return video_urls();
767
+ },
768
+ get poster_ () {
769
+ return video_()?.preview_image_url || image_urls_()?.[0];
770
+ }
771
+ });
719
772
  }
720
- });
773
+ }));
774
+ return _el$15;
721
775
  }
722
- }));
723
- return _el$15;
776
+ });
724
777
  }
725
778
  }),
726
779
  (0, $7jsgb$solidjsweb.createComponent)((0, $7jsgb$solidjs.Show), {
@@ -737,42 +790,57 @@ function $3375ddd88f77967d$var$ImagesAndVideos({ image_urls_: image_urls_, video
737
790
  return hoverImageDisabled() || index() !== 1;
738
791
  },
739
792
  get children () {
740
- var _el$16 = $3375ddd88f77967d$var$_tmpl$13();
741
- (0, $7jsgb$solidjsweb.insert)(_el$16, (0, $7jsgb$solidjsweb.createComponent)((0, $7jsgb$depictaiuilatest.ShopifyContainedImage), {
742
- src: image_url,
743
- get aspectRatio () {
744
- return aspectRatio_();
745
- },
746
- imgProps: {
747
- alt: "Product image"
748
- }
749
- }), null);
750
- (0, $7jsgb$solidjsweb.insert)(_el$16, (0, $7jsgb$solidjsweb.createComponent)((0, $7jsgb$solidjs.Show), {
751
- get when () {
752
- return (0, $7jsgb$solidjsweb.memo)(()=>!!(!index() && image_urls_()?.[1]))() && !hoverImageDisabled();
753
- },
793
+ return (0, $7jsgb$solidjsweb.createComponent)(MaybeShowLazily, {
754
794
  get children () {
755
- return (0, $7jsgb$solidjsweb.createComponent)((0, $7jsgb$depictaiuilatest.ShopifyContainedImage), {
756
- get src () {
757
- return image_urls_()[1];
758
- },
795
+ var _el$16 = $3375ddd88f77967d$var$_tmpl$13();
796
+ (0, $7jsgb$solidjsweb.insert)(_el$16, (0, $7jsgb$solidjsweb.createComponent)((0, $7jsgb$depictaiuilatest.ShopifyContainedImage), {
797
+ src: image_url,
759
798
  get aspectRatio () {
760
799
  return aspectRatio_();
761
800
  },
762
801
  imgProps: {
763
802
  alt: "Product image"
803
+ }
804
+ }), null);
805
+ (0, $7jsgb$solidjsweb.insert)(_el$16, (0, $7jsgb$solidjsweb.createComponent)((0, $7jsgb$solidjs.Show), {
806
+ get when () {
807
+ return (0, $7jsgb$solidjsweb.memo)(()=>!!(!index() && image_urls_()?.[1]))() && !hoverImageDisabled();
764
808
  },
765
- get ["class"] () {
766
- return `hover${cardIsHovered_() ? " visible" : ""}`;
809
+ get children () {
810
+ return (0, $7jsgb$solidjsweb.createComponent)((0, $7jsgb$depictaiuilatest.ShopifyContainedImage), {
811
+ get src () {
812
+ return image_urls_()[1];
813
+ },
814
+ get aspectRatio () {
815
+ return aspectRatio_();
816
+ },
817
+ imgProps: {
818
+ alt: "Product image"
819
+ },
820
+ get ["class"] () {
821
+ return `hover${cardIsHovered_() ? " visible" : ""}`;
822
+ }
823
+ });
767
824
  }
768
- });
825
+ }), null);
826
+ return _el$16;
769
827
  }
770
- }), null);
771
- return _el$16;
828
+ });
772
829
  }
773
830
  })
774
831
  });
775
832
  }
833
+ }),
834
+ (0, $7jsgb$solidjsweb.createComponent)((0, $7jsgb$solidjs.Show), {
835
+ get when () {
836
+ return (0, $7jsgb$solidjsweb.memo)(()=>!!(slidable() && itemsWantingToBeRendered().length > 1))() && !userTriedSliding();
837
+ },
838
+ get children () {
839
+ return (0, $7jsgb$solidjsweb.createComponent)((0, $7jsgb$depictaiuilatest.ImagePlaceholder), {
840
+ width: "100%",
841
+ height: ""
842
+ });
843
+ }
776
844
  })
777
845
  ];
778
846
  }
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, useProductCardIsVisible as $2MCgq$useProductCardIsVisible, 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, 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.28";
10
+ const $91c11b750e80ede3$export$83d89fbfd8236492 = "2.7.30";
11
11
 
12
12
 
13
13
 
@@ -618,15 +618,18 @@ function $29535f590238371c$var$setStyleForTextOptions({ style: style }, options)
618
618
  }
619
619
  function $29535f590238371c$var$ImagesAndVideos({ image_urls_: image_urls_, video_: video_, configuredOptions_: configuredOptions_, cardIsHovered_: cardIsHovered_, aspectRatio_: aspectRatio_, noHoverSupport_: noHoverSupport_ }) {
620
620
  const PLPLayout = (0, $2MCgq$usePLPLayout)();
621
- const isAlreadyInSlider = (0, $2MCgq$createMemo)(()=>!!((0, $2MCgq$useSlidableInformation)() || PLPLayout?.()?.startsWith("slider")));
622
621
  const containerClasses = ()=>[
623
622
  "image-video",
624
623
  "border-radius-" + configuredOptions_().image_radius
625
624
  ];
626
- // Don't make cards swipable inside of sliders (PLP slider or recs slider)
627
- const slidable = (0, $2MCgq$createMemo)(()=>!isAlreadyInSlider() && configuredOptions_().image_carousel);
625
+ const productCardIsVisible = (0, $2MCgq$useProductCardIsVisible)();
626
+ const hasBeenVisible = (0, $2MCgq$createMemo)((prev)=>prev || productCardIsVisible());
627
+ const slidable = (0, $2MCgq$createMemo)(()=>// Don't make cards swipable inside of sliders (PLP slider or recs slider)
628
+ !((0, $2MCgq$useSlidableInformation)() || PLPLayout?.()?.startsWith("slider")) && configuredOptions_().image_carousel && // Delay creation of slider until card has been visible. We can't do it until the user interacts with it because it sometimes glitches the hover effect, but initialising the slider takes some time (need to compute if the buttons should be shown, there's a Mutationobserver, etc) so it's good to not initialise all at once (for example when going back)
629
+ hasBeenVisible());
628
630
  const hoverImageDisabled = (0, $2MCgq$createMemo)(()=>!configuredOptions_().use_hover_image || noHoverSupport_());
629
631
  const video_urls = ()=>video_()?.video_urls;
632
+ const [userTriedSliding, setUserTriedSliding] = (0, $2MCgq$createSignal)(false);
630
633
  const Container = (props)=>{
631
634
  const resolved = (0, $2MCgq$children)(()=>props.children);
632
635
  return (0, $2MCgq$createComponent)((0, $2MCgq$Show), {
@@ -642,32 +645,78 @@ function $29535f590238371c$var$ImagesAndVideos({ image_urls_: image_urls_, video
642
645
  })();
643
646
  },
644
647
  get children () {
645
- return (0, $2MCgq$createComponent)((0, $2MCgq$SlidableItems), {
646
- arrow_height_: 25,
647
- arrow_width_: 12.5,
648
- disable_fading_: true,
649
- slider_ref_: (slider)=>{
650
- const { container: container, insert_here: insert_here } = slider;
651
- slider.stepstoslide = 1; // In case anyone enables the hidden buttons using css
652
- (0, $2MCgq$createRenderEffect)((previous)=>(0, $2MCgq$classList)(container, {
653
- products: true,
654
- ...Object.fromEntries(containerClasses().map((cls)=>[
655
- cls,
656
- true
657
- ]))
658
- }, previous));
659
- // Scroll to beginning when changing what variant we're showing
660
- (0, $2MCgq$createEffect)((0, $2MCgq$on)(image_urls_, ()=>insert_here.scrollTo({
661
- left: 0,
662
- behavior: "auto"
663
- }), {
664
- defer: true
665
- }));
666
- },
667
- get children () {
668
- return resolved();
669
- }
670
- });
648
+ return (()=>{
649
+ const [userHoveredImage, setUserHoveredImage] = (0, $2MCgq$createSignal)(false);
650
+ const allowPromotingToLayer = (0, $2MCgq$createMemo)(()=>{
651
+ 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
652
+ return productCardIsVisible();
653
+ return userHoveredImage();
654
+ });
655
+ return (0, $2MCgq$createComponent)((0, $2MCgq$SlidableItems), {
656
+ arrow_height_: 25,
657
+ arrow_width_: 12.5,
658
+ disable_fading_: true,
659
+ slider_ref_: (slider)=>{
660
+ const { container: container, insert_here: insert_here } = slider;
661
+ slider.stepstoslide = 1; // In case anyone enables the hidden buttons using css
662
+ (0, $2MCgq$createRenderEffect)((previous)=>(0, $2MCgq$classList)(container, {
663
+ products: true,
664
+ ...Object.fromEntries(containerClasses().map((cls)=>[
665
+ cls,
666
+ true
667
+ ]))
668
+ }, previous));
669
+ // 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
670
+ // -> this is for rendering performance
671
+ // See https://depictaiworkspace.slack.com/archives/C02BASM9X5J/p1714038914867749?thread_ts=1714038547.501939&cid=C02BASM9X5J
672
+ (0, $2MCgq$createRenderEffect)(()=>insert_here.style.overflow = allowPromotingToLayer() ? "" : "hidden");
673
+ // If hovered, remove overflow: hidden so user can try swiping
674
+ container.addEventListener("pointerenter", ()=>setUserHoveredImage(true), {
675
+ once: true
676
+ });
677
+ // Scroll to beginning when changing what variant we're showing
678
+ (0, $2MCgq$createEffect)((0, $2MCgq$on)(image_urls_, ()=>insert_here.scrollTo({
679
+ left: 0,
680
+ behavior: "auto"
681
+ }), {
682
+ defer: true
683
+ }));
684
+ },
685
+ get children () {
686
+ return (()=>{
687
+ const slidableInformation = (0, $2MCgq$useSlidableInformation)();
688
+ (0, $2MCgq$createEffect)(()=>{
689
+ // Actually render (and load) the other images when the slider gets swiped
690
+ slidableInformation.intersectionEntries_(); // Re-check when intersecting entries change
691
+ const intersectingsObject = slidableInformation?.slider_.intersecting_items_object;
692
+ // If intersection observers haven't started yet or we aren't in a slider, we count as visible for faster playback
693
+ if (1 in intersectingsObject) setUserTriedSliding(true);
694
+ });
695
+ return resolved;
696
+ })();
697
+ }
698
+ });
699
+ })();
700
+ }
701
+ });
702
+ };
703
+ const [itemsWantingToBeRendered, setItemsWantingToBeRendered] = (0, $2MCgq$createSignal)([], {
704
+ equals: false
705
+ });
706
+ // When slidable, only render items (and therefore fetch images) when the user actually tried swiping -> this is for better network performance
707
+ const MaybeShowLazily = (props)=>{
708
+ const us = Symbol();
709
+ setItemsWantingToBeRendered((prev)=>{
710
+ prev.push(us);
711
+ return prev;
712
+ });
713
+ (0, $2MCgq$onCleanup)(()=>setItemsWantingToBeRendered((prev)=>prev.filter((item)=>item !== us)));
714
+ return (0, $2MCgq$createComponent)((0, $2MCgq$Show), {
715
+ get when () {
716
+ return !slidable() || itemsWantingToBeRendered()[0] === us || userTriedSliding();
717
+ },
718
+ get children () {
719
+ return props.children;
671
720
  }
672
721
  });
673
722
  };
@@ -691,23 +740,27 @@ function $29535f590238371c$var$ImagesAndVideos({ image_urls_: image_urls_, video
691
740
  return video_urls()?.length;
692
741
  },
693
742
  get children () {
694
- var _el$15 = $29535f590238371c$var$_tmpl$12();
695
- (0, $2MCgq$insert)(_el$15, (0, $2MCgq$createComponent)((0, $2MCgq$ImageContainer), {
696
- get aspectRatio () {
697
- return aspectRatio_();
698
- },
743
+ return (0, $2MCgq$createComponent)(MaybeShowLazily, {
699
744
  get children () {
700
- return (0, $2MCgq$createComponent)($29535f590238371c$var$Video, {
701
- get video_sources_ () {
702
- return video_urls();
745
+ var _el$15 = $29535f590238371c$var$_tmpl$12();
746
+ (0, $2MCgq$insert)(_el$15, (0, $2MCgq$createComponent)((0, $2MCgq$ImageContainer), {
747
+ get aspectRatio () {
748
+ return aspectRatio_();
703
749
  },
704
- get poster_ () {
705
- return video_()?.preview_image_url || image_urls_()?.[0];
750
+ get children () {
751
+ return (0, $2MCgq$createComponent)($29535f590238371c$var$Video, {
752
+ get video_sources_ () {
753
+ return video_urls();
754
+ },
755
+ get poster_ () {
756
+ return video_()?.preview_image_url || image_urls_()?.[0];
757
+ }
758
+ });
706
759
  }
707
- });
760
+ }));
761
+ return _el$15;
708
762
  }
709
- }));
710
- return _el$15;
763
+ });
711
764
  }
712
765
  }),
713
766
  (0, $2MCgq$createComponent)((0, $2MCgq$Show), {
@@ -724,42 +777,57 @@ function $29535f590238371c$var$ImagesAndVideos({ image_urls_: image_urls_, video
724
777
  return hoverImageDisabled() || index() !== 1;
725
778
  },
726
779
  get children () {
727
- var _el$16 = $29535f590238371c$var$_tmpl$13();
728
- (0, $2MCgq$insert)(_el$16, (0, $2MCgq$createComponent)((0, $2MCgq$ShopifyContainedImage), {
729
- src: image_url,
730
- get aspectRatio () {
731
- return aspectRatio_();
732
- },
733
- imgProps: {
734
- alt: "Product image"
735
- }
736
- }), null);
737
- (0, $2MCgq$insert)(_el$16, (0, $2MCgq$createComponent)((0, $2MCgq$Show), {
738
- get when () {
739
- return (0, $2MCgq$memo)(()=>!!(!index() && image_urls_()?.[1]))() && !hoverImageDisabled();
740
- },
780
+ return (0, $2MCgq$createComponent)(MaybeShowLazily, {
741
781
  get children () {
742
- return (0, $2MCgq$createComponent)((0, $2MCgq$ShopifyContainedImage), {
743
- get src () {
744
- return image_urls_()[1];
745
- },
782
+ var _el$16 = $29535f590238371c$var$_tmpl$13();
783
+ (0, $2MCgq$insert)(_el$16, (0, $2MCgq$createComponent)((0, $2MCgq$ShopifyContainedImage), {
784
+ src: image_url,
746
785
  get aspectRatio () {
747
786
  return aspectRatio_();
748
787
  },
749
788
  imgProps: {
750
789
  alt: "Product image"
790
+ }
791
+ }), null);
792
+ (0, $2MCgq$insert)(_el$16, (0, $2MCgq$createComponent)((0, $2MCgq$Show), {
793
+ get when () {
794
+ return (0, $2MCgq$memo)(()=>!!(!index() && image_urls_()?.[1]))() && !hoverImageDisabled();
751
795
  },
752
- get ["class"] () {
753
- return `hover${cardIsHovered_() ? " visible" : ""}`;
796
+ get children () {
797
+ return (0, $2MCgq$createComponent)((0, $2MCgq$ShopifyContainedImage), {
798
+ get src () {
799
+ return image_urls_()[1];
800
+ },
801
+ get aspectRatio () {
802
+ return aspectRatio_();
803
+ },
804
+ imgProps: {
805
+ alt: "Product image"
806
+ },
807
+ get ["class"] () {
808
+ return `hover${cardIsHovered_() ? " visible" : ""}`;
809
+ }
810
+ });
754
811
  }
755
- });
812
+ }), null);
813
+ return _el$16;
756
814
  }
757
- }), null);
758
- return _el$16;
815
+ });
759
816
  }
760
817
  })
761
818
  });
762
819
  }
820
+ }),
821
+ (0, $2MCgq$createComponent)((0, $2MCgq$Show), {
822
+ get when () {
823
+ return (0, $2MCgq$memo)(()=>!!(slidable() && itemsWantingToBeRendered().length > 1))() && !userTriedSliding();
824
+ },
825
+ get children () {
826
+ return (0, $2MCgq$createComponent)((0, $2MCgq$ImagePlaceholder), {
827
+ width: "100%",
828
+ height: ""
829
+ });
830
+ }
763
831
  })
764
832
  ];
765
833
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@depict-ai/portal-components",
3
- "version": "2.7.28",
3
+ "version": "2.7.30",
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"
@@ -688,55 +688,115 @@ function ImagesAndVideos({
688
688
  noHoverSupport_: Accessor<boolean>;
689
689
  }) {
690
690
  const PLPLayout = usePLPLayout();
691
- const isAlreadyInSlider = createMemo(() => !!(useSlidableInformation() || PLPLayout?.()?.startsWith("slider")));
692
691
  const containerClasses = () => ["image-video", "border-radius-" + configuredOptions_().image_radius] as const;
693
- // Don't make cards swipable inside of sliders (PLP slider or recs slider)
694
- const slidable = createMemo(() => !isAlreadyInSlider() && configuredOptions_().image_carousel);
692
+ const productCardIsVisible = useProductCardIsVisible();
693
+ const hasBeenVisible = createMemo<boolean | undefined>(prev => prev || productCardIsVisible());
694
+ const slidable = createMemo(
695
+ () =>
696
+ // Don't make cards swipable inside of sliders (PLP slider or recs slider)
697
+ !(useSlidableInformation() || PLPLayout?.()?.startsWith("slider")) &&
698
+ configuredOptions_().image_carousel &&
699
+ // Delay creation of slider until card has been visible. We can't do it until the user interacts with it because it sometimes glitches the hover effect, but initialising the slider takes some time (need to compute if the buttons should be shown, there's a Mutationobserver, etc) so it's good to not initialise all at once (for example when going back)
700
+ hasBeenVisible()
701
+ );
695
702
  const hoverImageDisabled = createMemo(() => !configuredOptions_().use_hover_image || noHoverSupport_());
696
703
  const video_urls = () => video_()?.video_urls;
704
+ const [userTriedSliding, setUserTriedSliding] = createSignal(false);
697
705
 
698
706
  const Container = (props: { children: JSX.Element }) => {
699
707
  const resolved = children(() => props.children);
700
708
  return (
701
709
  <Show when={slidable()} fallback={<div class={containerClasses().join(" ")}>{resolved()}</div>}>
702
- <SlidableItems
703
- arrow_height_={25}
704
- arrow_width_={12.5}
705
- disable_fading_={true}
706
- slider_ref_={slider => {
707
- const { container, insert_here } = slider;
708
- slider.stepstoslide = 1; // In case anyone enables the hidden buttons using css
710
+ {(() => {
711
+ const [userHoveredImage, setUserHoveredImage] = createSignal(false);
712
+ const allowPromotingToLayer = createMemo(() => {
713
+ if (noHoverSupport_()) {
714
+ // 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
715
+ return productCardIsVisible();
716
+ }
717
+ return userHoveredImage();
718
+ });
709
719
 
710
- createRenderEffect<{ [k: string]: boolean } | undefined>(previous =>
711
- classList(
712
- container,
713
- { products: true, ...Object.fromEntries(containerClasses().map(cls => [cls, true])) },
714
- previous
715
- )
716
- );
720
+ return (
721
+ <SlidableItems
722
+ arrow_height_={25}
723
+ arrow_width_={12.5}
724
+ disable_fading_={true}
725
+ slider_ref_={slider => {
726
+ const { container, insert_here } = slider;
727
+ slider.stepstoslide = 1; // In case anyone enables the hidden buttons using css
728
+
729
+ createRenderEffect<{ [k: string]: boolean } | undefined>(previous =>
730
+ classList(
731
+ container,
732
+ { products: true, ...Object.fromEntries(containerClasses().map(cls => [cls, true])) },
733
+ previous
734
+ )
735
+ );
736
+
737
+ // 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
738
+ // -> this is for rendering performance
739
+ // See https://depictaiworkspace.slack.com/archives/C02BASM9X5J/p1714038914867749?thread_ts=1714038547.501939&cid=C02BASM9X5J
740
+ createRenderEffect(() => (insert_here.style.overflow = allowPromotingToLayer() ? "" : "hidden"));
741
+
742
+ // If hovered, remove overflow: hidden so user can try swiping
743
+ container.addEventListener("pointerenter", () => setUserHoveredImage(true), { once: true });
744
+
745
+ // Scroll to beginning when changing what variant we're showing
746
+ createEffect(
747
+ on(image_urls_, () => insert_here.scrollTo({ left: 0, behavior: "auto" }), { defer: true })
748
+ );
749
+ }}
750
+ >
751
+ {(() => {
752
+ const slidableInformation = useSlidableInformation();
717
753
 
718
- // Scroll to beginning when changing what variant we're showing
719
- createEffect(on(image_urls_, () => insert_here.scrollTo({ left: 0, behavior: "auto" }), { defer: true }));
720
- }}
721
- >
722
- {resolved()}
723
- </SlidableItems>
754
+ createEffect(() => {
755
+ // Actually render (and load) the other images when the slider gets swiped
756
+ slidableInformation!.intersectionEntries_(); // Re-check when intersecting entries change
757
+ const intersectingsObject = slidableInformation?.slider_.intersecting_items_object;
758
+ // If intersection observers haven't started yet or we aren't in a slider, we count as visible for faster playback
759
+ if (1 in intersectingsObject!) {
760
+ setUserTriedSliding(true);
761
+ }
762
+ });
763
+
764
+ return resolved as unknown as JSX.Element;
765
+ })()}
766
+ </SlidableItems>
767
+ );
768
+ })()}
724
769
  </Show>
725
770
  );
726
771
  };
772
+ const [itemsWantingToBeRendered, setItemsWantingToBeRendered] = createSignal<symbol[]>([], { equals: false });
773
+ // When slidable, only render items (and therefore fetch images) when the user actually tried swiping -> this is for better network performance
774
+ const MaybeShowLazily = (props: { children: JSX.Element }) => {
775
+ const us = Symbol();
776
+ setItemsWantingToBeRendered(prev => {
777
+ prev.push(us);
778
+ return prev;
779
+ });
780
+ onCleanup(() => setItemsWantingToBeRendered(prev => prev.filter(item => item !== us)));
781
+ return (
782
+ <Show when={!slidable() || itemsWantingToBeRendered()[0] === us || userTriedSliding()}>{props.children}</Show>
783
+ );
784
+ };
727
785
 
728
786
  return (
729
787
  <Show when={image_urls_()} fallback={<ImagePlaceholder aspectRatio={aspectRatio_()} />}>
730
788
  <Container>
731
789
  <Show when={video_urls()?.length}>
732
- <div class="media-item video">
733
- <ImageContainer aspectRatio={aspectRatio_()}>
734
- <Video
735
- video_sources_={video_urls() as [string, ...string[]]}
736
- poster_={video_()?.preview_image_url || image_urls_()?.[0]}
737
- />
738
- </ImageContainer>
739
- </div>
790
+ <MaybeShowLazily>
791
+ <div class="media-item video">
792
+ <ImageContainer aspectRatio={aspectRatio_()}>
793
+ <Video
794
+ video_sources_={video_urls() as [string, ...string[]]}
795
+ poster_={video_()?.preview_image_url || image_urls_()?.[0]}
796
+ />
797
+ </ImageContainer>
798
+ </div>
799
+ </MaybeShowLazily>
740
800
  </Show>
741
801
  <Show when={!video_urls()?.length || slidable()}>
742
802
  <For each={slidable() ? image_urls_() : image_urls_()?.slice(0, 1)}>
@@ -744,26 +804,31 @@ function ImagesAndVideos({
744
804
  <Show when={hoverImageDisabled() || index() !== 1}>
745
805
  {/* The image with index 1 will already be shown as hover image if hover is supported, so hide it in the slider
746
806
  (We assume people don't discover the slider can be slided on desktop) */}
747
- <div class="media-item image">
748
- {/* Hover to see JSDOc for ShopifyContainedImage */}
749
- <ShopifyContainedImage
750
- src={image_url}
751
- aspectRatio={aspectRatio_()}
752
- imgProps={{ alt: "Product image" }}
753
- />
754
- <Show when={!index() && image_urls_()?.[1] && !hoverImageDisabled()}>
807
+ <MaybeShowLazily>
808
+ <div class="media-item image">
809
+ {/* Hover to see JSDOc for ShopifyContainedImage */}
755
810
  <ShopifyContainedImage
756
- src={image_urls_()![1]}
811
+ src={image_url}
757
812
  aspectRatio={aspectRatio_()}
758
813
  imgProps={{ alt: "Product image" }}
759
- class={`hover${cardIsHovered_() ? " visible" : ""}`}
760
814
  />
761
- </Show>
762
- </div>
815
+ <Show when={!index() && image_urls_()?.[1] && !hoverImageDisabled()}>
816
+ <ShopifyContainedImage
817
+ src={image_urls_()![1]}
818
+ aspectRatio={aspectRatio_()}
819
+ imgProps={{ alt: "Product image" }}
820
+ class={`hover${cardIsHovered_() ? " visible" : ""}`}
821
+ />
822
+ </Show>
823
+ </div>
824
+ </MaybeShowLazily>
763
825
  </Show>
764
826
  )}
765
827
  </For>
766
828
  </Show>
829
+ <Show when={slidable() && itemsWantingToBeRendered().length > 1 && !userTriedSliding()}>
830
+ <ImagePlaceholder width="100%" height="" />
831
+ </Show>
767
832
  </Container>
768
833
  </Show>
769
834
  );