@liquidcommercedev/rmn-sdk 1.5.0-beta.6 → 1.5.0-beta.8

Sign up to get free protection for your applications and to get access to all the features.
package/dist/index.esm.js CHANGED
@@ -15558,11 +15558,13 @@ const CAROUSEL_COMPONENT_STYLE = ({ width, height, fluid }) => `
15558
15558
  position: relative;
15559
15559
  height: 100%;
15560
15560
  width: 100%;
15561
+ display: flex;
15562
+ transition: transform 0.5s ease-in-out;
15561
15563
  }
15562
15564
 
15563
15565
  .slide {
15564
- display: none;
15565
-
15566
+ flex: 0 0 100%;
15567
+ display: flex;
15566
15568
  justify-content: center;
15567
15569
  align-items: center;
15568
15570
  height: 100%;
@@ -15867,9 +15869,9 @@ if (typeof window !== 'undefined' && typeof window.customElements !== 'undefined
15867
15869
  renderSlides() {
15868
15870
  const slidesContainer = document.createElement('div');
15869
15871
  slidesContainer.className = 'slides';
15870
- this.slides.forEach((slide, index) => {
15872
+ this.slides.forEach((slide) => {
15871
15873
  const slideElement = document.createElement('div');
15872
- slideElement.className = `slide ${index === this.currentSlide ? 'active' : ''}`;
15874
+ slideElement.className = 'slide';
15873
15875
  if (slide instanceof HTMLElement) {
15874
15876
  slideElement.appendChild(slide);
15875
15877
  }
@@ -15948,10 +15950,9 @@ if (typeof window !== 'undefined' && typeof window.customElements !== 'undefined
15948
15950
  updateCarousel() {
15949
15951
  if (!this.slidesContainer)
15950
15952
  return;
15951
- const slides = Array.from(this.slidesContainer.children);
15952
- slides.forEach((slide, index) => {
15953
- slide.classList.toggle('active', index === this.currentSlide);
15954
- });
15953
+ // Calculate the translation distance based on current slide
15954
+ const translateX = -this.currentSlide * 100;
15955
+ this.slidesContainer.style.transform = `translateX(${translateX}%)`;
15955
15956
  this.updateDots();
15956
15957
  }
15957
15958
  updateDots() {
@@ -16375,12 +16376,13 @@ function spotHtmlStringToElement(htmlString) {
16375
16376
  spot.className = 'spot';
16376
16377
  spot.innerHTML = htmlString;
16377
16378
  Object.assign(spot.style, {
16378
- position: 'relative',
16379
16379
  display: 'block',
16380
16380
  width: '100%',
16381
16381
  height: '100%',
16382
16382
  margin: '0',
16383
16383
  padding: '0',
16384
+ containerType: 'inline-size',
16385
+ position: 'relative',
16384
16386
  });
16385
16387
  return spot;
16386
16388
  }
@@ -17250,7 +17252,6 @@ const STYLES$6 = ({ textColor = '#ffffff', ctaTextColor = textColor, ctaBorderCo
17250
17252
  box-sizing: border-box;
17251
17253
  color: ${textColor};
17252
17254
  cursor: pointer;
17253
- container-type: inline-size;
17254
17255
  }
17255
17256
 
17256
17257
  .${prefix}__text {
@@ -17266,7 +17267,7 @@ const STYLES$6 = ({ textColor = '#ffffff', ctaTextColor = textColor, ctaBorderCo
17266
17267
  .${prefix}__header {
17267
17268
  font-size: 24px;
17268
17269
  margin: 0;
17269
- font-family: "Cormorant";
17270
+ font-family: "Cormorant", system-ui;
17270
17271
  font-style: normal;
17271
17272
  font-weight: 300;
17272
17273
  line-height: normal;
@@ -17385,7 +17386,6 @@ const STYLES$5 = ({ textColor = '#212121', backgroundColor = '#e8e6de', ctaTextC
17385
17386
  height: 100%;
17386
17387
  display: block;
17387
17388
  position: relative;
17388
- container-type: inline-size;
17389
17389
  }
17390
17390
 
17391
17391
  .${prefix}__content {
@@ -17576,15 +17576,20 @@ function rbHomepageHeroThreeTileTemplate(spot, config) {
17576
17576
  const STYLES$4 = ({ textColor = '#212121', backgroundColor = '#e8e6de', ctaTextColor = textColor, primaryImage, mobilePrimaryImage = primaryImage, }, { prefix }) => `
17577
17577
  <style>
17578
17578
  .${prefix} {
17579
+ width: 100%;
17580
+ height: 100%;
17581
+ background-color: transparent;
17582
+ cursor: pointer;
17583
+ position: relative;
17584
+ }
17585
+
17586
+ .${prefix}__content {
17579
17587
  width: 100%;
17580
17588
  height: 100%;
17581
17589
  display: flex;
17582
17590
  flex-direction: column-reverse;
17583
17591
  background-color: transparent;
17584
17592
  gap: 6px;
17585
- cursor: pointer;
17586
- container-type: inline-size;
17587
- position: relative;
17588
17593
  }
17589
17594
 
17590
17595
  .${prefix}__image {
@@ -17615,7 +17620,7 @@ const STYLES$4 = ({ textColor = '#212121', backgroundColor = '#e8e6de', ctaTextC
17615
17620
  font-size: 18px;
17616
17621
  margin: 0;
17617
17622
  color: inherit;
17618
- font-family: "Cormorant";
17623
+ font-family: "Cormorant", system-ui;
17619
17624
  font-style: normal;
17620
17625
  font-weight: 700;
17621
17626
  line-height: normal;
@@ -17657,7 +17662,7 @@ const STYLES$4 = ({ textColor = '#212121', backgroundColor = '#e8e6de', ctaTextC
17657
17662
  }
17658
17663
 
17659
17664
  @container (min-width: 768px) {
17660
- .${prefix} {
17665
+ .${prefix}__content {
17661
17666
  flex-direction: row;
17662
17667
  }
17663
17668
  .${prefix}__image {
@@ -17712,12 +17717,14 @@ function rbHomepageHeroTwoTileTemplate(spot, config) {
17712
17717
  ${GFONT_CORMORANT}
17713
17718
  ${STYLES$4(spot, config)}
17714
17719
  <div class="${prefix}">
17715
- <div class="${prefix}__text">
17716
- ${spot.header ? `<h2 class="${prefix}__header">${spot.header}</h2>` : ''}
17717
- ${spot.description ? `<p class="${prefix}__description">${spot.description}</p>` : ''}
17718
- ${spot.ctaText ? `<span class="${prefix}__cta-button">${spot.ctaText}</span>` : ''}
17719
- </div>
17720
- <div class="${prefix}__image"></div>
17720
+ <div class="${prefix}__content">
17721
+ <div class="${prefix}__text">
17722
+ ${spot.header ? `<h2 class="${prefix}__header">${spot.header}</h2>` : ''}
17723
+ ${spot.description ? `<p class="${prefix}__description">${spot.description}</p>` : ''}
17724
+ ${spot.ctaText ? `<span class="${prefix}__cta-button">${spot.ctaText}</span>` : ''}
17725
+ </div>
17726
+ <div class="${prefix}__image"></div>
17727
+ </div>
17721
17728
  </div>
17722
17729
  `;
17723
17730
  }
@@ -17740,12 +17747,10 @@ const STYLES$3 = ({ textColor = '#ffffff', ctaTextColor = textColor, ctaBorderCo
17740
17747
  overflow: hidden;
17741
17748
  cursor: pointer;
17742
17749
  color: ${textColor};
17743
- container-type: inline-size;
17744
17750
  }
17745
17751
 
17746
17752
  .${prefix}__text {
17747
17753
  padding: 20px;
17748
- width: 70%;
17749
17754
  display: flex;
17750
17755
  flex-direction: column;
17751
17756
  justify-content: center;
@@ -17757,7 +17762,7 @@ const STYLES$3 = ({ textColor = '#ffffff', ctaTextColor = textColor, ctaBorderCo
17757
17762
  color: inherit;
17758
17763
  margin: 0;
17759
17764
  font-size: 20px;
17760
- font-family: "Cormorant";
17765
+ font-family: "Cormorant", system-ui;
17761
17766
  font-style: normal;
17762
17767
  font-weight: 300;
17763
17768
  line-height: normal;
@@ -17876,7 +17881,6 @@ const STYLES$2 = ({ textColor = '#ffffff', primaryImage, mobilePrimaryImage = pr
17876
17881
  background-size: cover;
17877
17882
  background-position: center;
17878
17883
  background-repeat: no-repeat;
17879
- container-type: inline-size;
17880
17884
  position: relative;
17881
17885
  }
17882
17886
 
@@ -17946,12 +17950,7 @@ const STYLES$1 = ({ textColor = '#ffffff', primaryImage, mobilePrimaryImage = pr
17946
17950
  border-radius: 5px;
17947
17951
  overflow: hidden;
17948
17952
  cursor: pointer;
17949
- container-type: inline-size;
17950
- }
17951
-
17952
- .${prefix}__text {
17953
- padding: 10px;
17954
- width: 70%;
17953
+ position: relative;
17955
17954
  }
17956
17955
 
17957
17956
  .${prefix}__header {
@@ -17962,6 +17961,7 @@ const STYLES$1 = ({ textColor = '#ffffff', primaryImage, mobilePrimaryImage = pr
17962
17961
  font-style: normal;
17963
17962
  font-weight: 400;
17964
17963
  margin: 0;
17964
+ padding: 10px;
17965
17965
  }
17966
17966
 
17967
17967
  @container (min-width: 640px) {
@@ -17979,9 +17979,7 @@ function rbSmallCategoryImageToutTemplate(spot, config) {
17979
17979
  ${GFONT_CORMORANT}
17980
17980
  ${STYLES$1(spot, config)}
17981
17981
  <div class="${prefix}">
17982
- <div class="${prefix}__text">
17983
- ${spot.header ? `<h2 class="${prefix}__header">${spot.header}</h2>` : ''}
17984
- </div>
17982
+ ${spot.header ? `<h2 class="${prefix}__header">${spot.header}</h2>` : ''}
17985
17983
  </div>
17986
17984
  `;
17987
17985
  }
@@ -17996,7 +17994,6 @@ const STYLES = ({ textColor = '#000000', backgroundColor = 'transparent', primar
17996
17994
  display: flex;
17997
17995
  flex-direction: column;
17998
17996
  border-radius: 5px;
17999
- container-type: inline-size;
18000
17997
  }
18001
17998
 
18002
17999
  .${prefix}__image {
@@ -18386,11 +18383,38 @@ class EventService {
18386
18383
  },
18387
18384
  };
18388
18385
  }
18389
- this.spotStates.set(placementId, { ...currentState, ...updates });
18386
+ const merged = this.deepMerge(currentState, updates);
18387
+ this.spotStates.set(placementId, merged);
18390
18388
  if (publish) {
18391
18389
  this.pubSub.publish(RMN_SPOT_EVENT.LIFECYCLE_STATE, this.spotStates.get(placementId));
18392
18390
  }
18393
18391
  }
18392
+ deepMerge(current, updates) {
18393
+ return {
18394
+ identifier: {
18395
+ ...current.identifier,
18396
+ ...updates.identifier,
18397
+ },
18398
+ dom: updates.dom
18399
+ ? {
18400
+ ...current.dom,
18401
+ ...updates.dom,
18402
+ }
18403
+ : current.dom,
18404
+ state: updates.state
18405
+ ? {
18406
+ ...current.state,
18407
+ ...updates.state,
18408
+ }
18409
+ : current.state,
18410
+ displayConfig: updates.displayConfig
18411
+ ? {
18412
+ ...current.displayConfig,
18413
+ ...updates.displayConfig,
18414
+ }
18415
+ : current.displayConfig,
18416
+ };
18417
+ }
18394
18418
  async handleClick({ placementId, spot, spotElement, }) {
18395
18419
  var _a, _b, _c;
18396
18420
  // Publish click event
@@ -18745,10 +18769,12 @@ class LiquidCommerceRmnClient {
18745
18769
  const config = params.config;
18746
18770
  let inject = params.inject;
18747
18771
  if (!inject.length) {
18772
+ // Handle no spots error state
18748
18773
  this.eventService.handleSpotState('all', {
18749
18774
  state: {
18750
18775
  error: 'No spot elements provided for injection.',
18751
18776
  loading: false,
18777
+ mounted: false,
18752
18778
  },
18753
18779
  });
18754
18780
  return;
@@ -18767,9 +18793,12 @@ class LiquidCommerceRmnClient {
18767
18793
  // const response = await this.useSpotSelectionExample(inject);
18768
18794
  // Handle the response
18769
18795
  if (typeof response === 'object' && 'error' in response) {
18796
+ // Handle request error state
18770
18797
  this.eventService.handleSpotState('all', {
18771
18798
  state: {
18772
18799
  error: response.error,
18800
+ mounted: false,
18801
+ loading: false,
18773
18802
  },
18774
18803
  });
18775
18804
  return;
@@ -18778,9 +18807,11 @@ class LiquidCommerceRmnClient {
18778
18807
  const itemConfig = (_a = item.config) !== null && _a !== void 0 ? _a : config;
18779
18808
  const spots = response[item.placementId];
18780
18809
  if (!(spots === null || spots === void 0 ? void 0 : spots.length)) {
18810
+ // Handle no spots found error state
18781
18811
  this.eventService.handleSpotState(item.placementId, {
18782
18812
  state: {
18783
18813
  error: `No spots found for type "${item.spotType}".`,
18814
+ mounted: false,
18784
18815
  loading: false,
18785
18816
  },
18786
18817
  });
@@ -18789,9 +18820,11 @@ class LiquidCommerceRmnClient {
18789
18820
  const placementId = item.placementId.replace('#', '');
18790
18821
  const placement = document.getElementById(placementId);
18791
18822
  if (!placement) {
18823
+ // Handle placement not found error state
18792
18824
  this.eventService.handleSpotState(item.placementId, {
18793
18825
  state: {
18794
18826
  error: `Placement not found for id "${placementId}".`,
18827
+ mounted: false,
18795
18828
  loading: false,
18796
18829
  },
18797
18830
  });
@@ -18806,12 +18839,14 @@ class LiquidCommerceRmnClient {
18806
18839
  display: 'flex',
18807
18840
  justifyContent: 'center',
18808
18841
  });
18842
+ // Handle single spot
18809
18843
  if (spots.length === 1) {
18810
18844
  const isInjected = this.injectOneSpotElement(item, placement, spots[0], itemConfig);
18811
18845
  if (!isInjected) {
18812
18846
  continue;
18813
18847
  }
18814
18848
  }
18849
+ // Handle multiple spots (carousel)
18815
18850
  if (spots.length > 1) {
18816
18851
  const isInjected = this.injectCarouselSpotElement(placement, spots, itemConfig);
18817
18852
  if (!isInjected) {
@@ -18855,18 +18890,24 @@ class LiquidCommerceRmnClient {
18855
18890
  const carouselSlides = [];
18856
18891
  for (const spotItem of spots) {
18857
18892
  this.eventService.handleSpotState(placement.id, {
18893
+ identifier: {
18894
+ placementId: placement.id,
18895
+ spotType: spotItem.spot,
18896
+ spotId: spotItem.id,
18897
+ },
18858
18898
  displayConfig: {
18899
+ isSingleItem: false,
18859
18900
  isCarousel: true,
18860
18901
  isCarouselItem: true,
18861
- isSingleItem: false,
18862
18902
  },
18863
- }, false);
18903
+ });
18864
18904
  const spot = this.elementService.overrideSpotColors(spotItem, config === null || config === void 0 ? void 0 : config.colors);
18865
18905
  const content = SPOT_TEMPLATE_HTML_ELEMENT(spot, { overlay: config === null || config === void 0 ? void 0 : config.overlay });
18866
18906
  if (!content) {
18867
18907
  this.eventService.handleSpotState(placement.id, {
18868
18908
  state: {
18869
18909
  error: `Failed to inject carousel spot item element. Could not create element for type "${spot.spot}".`,
18910
+ mounted: false,
18870
18911
  loading: false,
18871
18912
  },
18872
18913
  });
@@ -18899,6 +18940,7 @@ class LiquidCommerceRmnClient {
18899
18940
  this.eventService.handleSpotState(placement.id, {
18900
18941
  state: {
18901
18942
  error: `Failed to inject spot carousel element. Could not create spot carousel element.`,
18943
+ mounted: false,
18902
18944
  loading: false,
18903
18945
  },
18904
18946
  });
@@ -18908,10 +18950,12 @@ class LiquidCommerceRmnClient {
18908
18950
  this.eventService.handleSpotState(placement.id, {
18909
18951
  dom: {
18910
18952
  spotElement: carouselElement,
18953
+ visibleOnViewport: false,
18911
18954
  },
18912
18955
  state: {
18913
18956
  mounted: true,
18914
18957
  loading: false,
18958
+ error: undefined,
18915
18959
  },
18916
18960
  });
18917
18961
  return true;
@@ -18928,18 +18972,25 @@ class LiquidCommerceRmnClient {
18928
18972
  */
18929
18973
  injectOneSpotElement(injectItem, placement, spot, config) {
18930
18974
  var _a;
18931
- const spotData = this.elementService.overrideSpotColors(spot, config === null || config === void 0 ? void 0 : config.colors);
18932
18975
  this.eventService.handleSpotState(injectItem.placementId, {
18976
+ identifier: {
18977
+ placementId: injectItem.placementId,
18978
+ spotType: injectItem.spotType,
18979
+ spotId: spot.id,
18980
+ },
18933
18981
  displayConfig: {
18934
18982
  isSingleItem: true,
18983
+ isCarousel: false,
18984
+ isCarouselItem: false,
18935
18985
  },
18936
- }, false);
18937
- // Create the spot template element
18986
+ });
18987
+ const spotData = this.elementService.overrideSpotColors(spot, config === null || config === void 0 ? void 0 : config.colors);
18938
18988
  const content = SPOT_TEMPLATE_HTML_ELEMENT(spotData, { overlay: config === null || config === void 0 ? void 0 : config.overlay });
18939
18989
  if (!content) {
18940
18990
  this.eventService.handleSpotState(injectItem.placementId, {
18941
18991
  state: {
18942
18992
  error: `Failed to inject spot element. Could not create element for type "${injectItem.spotType}".`,
18993
+ mounted: false,
18943
18994
  loading: false,
18944
18995
  },
18945
18996
  });
@@ -18960,6 +19011,7 @@ class LiquidCommerceRmnClient {
18960
19011
  this.eventService.handleSpotState(injectItem.placementId, {
18961
19012
  state: {
18962
19013
  error: `Failed to inject spot element. Could not create element for type "${injectItem.spotType}".`,
19014
+ mounted: false,
18963
19015
  loading: false,
18964
19016
  },
18965
19017
  });
@@ -18974,10 +19026,12 @@ class LiquidCommerceRmnClient {
18974
19026
  this.eventService.handleSpotState(injectItem.placementId, {
18975
19027
  dom: {
18976
19028
  spotElement,
19029
+ visibleOnViewport: false,
18977
19030
  },
18978
19031
  state: {
18979
19032
  mounted: true,
18980
19033
  loading: false,
19034
+ error: undefined,
18981
19035
  },
18982
19036
  });
18983
19037
  return true;
@@ -18998,6 +19052,8 @@ class LiquidCommerceRmnClient {
18998
19052
  this.eventService.handleSpotState(item.placementId, {
18999
19053
  state: {
19000
19054
  error: `Duplicate placement id (${item.placementId}) found. Please provide a unique placement id for each spot element.`,
19055
+ mounted: false,
19056
+ loading: false,
19001
19057
  },
19002
19058
  });
19003
19059
  return false;
@@ -19013,6 +19069,8 @@ class LiquidCommerceRmnClient {
19013
19069
  this.eventService.handleSpotState(item.placementId, {
19014
19070
  state: {
19015
19071
  error: `Invalid spot type (${item.spotType}) found. Please provide a valid spot type for each spot element.`,
19072
+ mounted: false,
19073
+ loading: false,
19016
19074
  },
19017
19075
  });
19018
19076
  continue;
@@ -19021,6 +19079,7 @@ class LiquidCommerceRmnClient {
19021
19079
  }
19022
19080
  return newInject;
19023
19081
  }
19082
+ // Initialize spots with loading state and identifiers
19024
19083
  updateSpotsState(inject) {
19025
19084
  for (const item of inject) {
19026
19085
  this.eventService.handleSpotState(item.placementId, {
@@ -19030,6 +19089,8 @@ class LiquidCommerceRmnClient {
19030
19089
  },
19031
19090
  state: {
19032
19091
  loading: true,
19092
+ mounted: false,
19093
+ error: undefined,
19033
19094
  },
19034
19095
  });
19035
19096
  }
@@ -23,6 +23,7 @@ export declare class EventService {
23
23
  * @returns {void}
24
24
  */
25
25
  handleSpotState(placementId: string, updates: Partial<ILifecycleState>, publish?: boolean): void;
26
+ private deepMerge;
26
27
  private handleClick;
27
28
  private handleIntersectionObserver;
28
29
  private fireImpressionEvent;
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@liquidcommercedev/rmn-sdk",
3
3
  "description": "LiquidCommerce RMN SDK",
4
4
  "author": "LiquidCommerce Tech",
5
- "version": "1.5.0-beta.6",
5
+ "version": "1.5.0-beta.8",
6
6
  "homepage": "https://docs.liquidcommerce.co/rmn-sdk",
7
7
  "main": "./dist/index.cjs",
8
8
  "module": "./dist/index.esm.js",