mealz-components 2.9.1 → 2.9.2
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.
|
@@ -4,4 +4,4 @@ import{N as n}from"../assets/no-shadow-element-DZc32M1D.js";import{m as a}from".
|
|
|
4
4
|
`,this.addToBasketContent=`
|
|
5
5
|
<img alt="add ingredients to basket icon" src="https://storage.googleapis.com/assets.miam.tech/generic/icons/Basket.svg"/>
|
|
6
6
|
<span class="mealz-ds-text weight-l">Acheter les ingrédients</span>
|
|
7
|
-
`}static get observedAttributes(){return[...super.observedAttributes,"guests"]}attributeChangedCallback(t,
|
|
7
|
+
`}static get observedAttributes(){return[...super.observedAttributes,"guests"]}attributeChangedCallback(t,s,e){if(super.attributeChangedCallback(t,s,e),t!=="guests"||s===e)return;const i=Number(e);this.guests=Number.isFinite(i)?i:void 0}disconnectedCallback(){super.disconnectedCallback(),this.observer&&this.ctaBtn&&(this.observer.unobserve(this.ctaBtn),this.observer.disconnect()),this.subscriptions.forEach(t=>t.unsubscribe())}render(){this.ctaBtn=this.querySelector(".mealz-no-supplier-add-to-cart-cta.mealz-no-supplier-add-to-cart-cta--static"),this.fixedCtaBtn=this.querySelector(".mealz-no-supplier-add-to-cart-cta.mealz-no-supplier-add-to-cart-cta--fixed"),!(!this.ctaBtn||!this.fixedCtaBtn)&&(this.getInitialStatus(),this.listenToRecipeInBasket(),this.listenToGuestsChange(),this.setupEventListeners(),this.setupIntersectionObserver())}getInitialStatus(){const t=this.getAttribute("starting-data");if(t){const{recipeId:s,inBasket:e,guests:i}=JSON.parse(t);this.recipeId=s,this.inBasket=e!==void 0?e:!1,this.guests=typeof i=="number"?i:void 0,this.removeAttribute("starting-data")}else this.inBasket=this.getAttribute("in-basket")==="true";this.syncHostInBasketState()}syncHostInBasketState(){this.setAttribute("in-basket",String(this.inBasket)),this.classList.toggle("in-basket",this.inBasket)}setupEventListeners(){this.ctaBtn.addEventListener("click",t=>{t.stopPropagation(),this.handleCtaClick()}),this.fixedCtaBtn.addEventListener("click",t=>{t.stopPropagation(),this.handleCtaClick()})}setupIntersectionObserver(){this.observer=new IntersectionObserver(([t])=>{this.showFixedButton=!t.isIntersecting,this.fixedCtaBtn.style.display=this.showFixedButton?"flex":"none",this.showFixedButton&&(this.fixedCtaBtn.style.animation="slideUp 300ms cubic-bezier(.25,.8,.25,1)")},{threshold:0}),this.observer.observe(this.ctaBtn)}updateDOM(){this.updateButtonState(this.ctaBtn),this.updateButtonState(this.fixedCtaBtn)}updateButtonState(t){t&&(this.inBasket?(t.className=t.className.replace("primary","secondary"),t.innerHTML=this.inBasketContent):(t.className=t.className.replace("secondary","primary"),t.innerHTML=this.addToBasketContent))}handleCtaClick(){var t,s;if(this.inBasket){const e=(s=(t=a.basket)==null?void 0:t.guestsForRecipe)==null?void 0:s.call(t,this.recipeId),i=this.guests??e??null;a.recipes.openDetails(this.recipeId,i,0,"",!0)}else a.noSupplier.addRecipeToBasketFromIdAndOpenPreview(this.recipeId,this.guests)}listenToRecipeInBasket(){this.subscriptions.push(a.recipes.isRecipeInBasket(this.recipeId).subscribe(t=>{this.setInBasket(t)}))}setInBasket(t){this.inBasket!==t&&(this.inBasket=t,this.syncHostInBasketState(),this.updateDOM(),this.dispatchEvent(new CustomEvent("inBasketStatus",{bubbles:!0,composed:!0,detail:t})))}listenToGuestsChange(){this.subscriptions.push(this.guestObserverService.guests$.subscribe(t=>{this.guests=t}))}}customElements.get("mealz-no-supplier-add-to-cart-cta")||customElements.define("mealz-no-supplier-add-to-cart-cta",c);
|