mealz-components 2.0.1 → 2.0.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.
@@ -1 +1 @@
1
- import{N as h,q as m,S as f}from"../../assets/no-shadow-element-DlGA0h9b.js";import{t as S}from"../../assets/custom-element-BhZVzxrc.js";import{m as p}from"../../assets/mealz-sdk-DWLzEfKz.js";import{d as b}from"../../assets/debounceTime-CIA2MWDj.js";import{o as R}from"../../assets/of-CH-D5SN9.js";import{t as g}from"../../assets/take-BmqRVy-3.js";import{t as v}from"../../assets/tap-C4xC1M3N.js";import"../../assets/async-H-Co76Oa.js";import"../../assets/OperatorSubscriber-z_a6lCKk.js";import"../../assets/from-Btz8AgkO.js";import"../../assets/executeSchedule-CTqB8mra.js";import"../../assets/innerFrom-CVMPVEmB.js";import"../../assets/empty-DGYYDWIm.js";class L{constructor(){this.attributes={title:"","ext-id":"","ext-link":"",description:"","number-of-guests":"","preparation-time":"","preheating-time":"","cooking-time":"","resting-time":"","media-url":"",source:"","informational-page-html":"","filigrane-logo-url":"","informational-sentence":"","order-history":"",difficulty:1,cost:1,suggested:!1,popularity:0,"video-id":"",promoted:!1,editable:!1,position:-1},this.ttl=3600,this.finalTimer=this.attributes["preparation-time"]+this.attributes["preheating-time"]+this.attributes["cooking-time"]+this.attributes["resting-time"]}get title(){return this.attributes.title}get promoted(){return this.attributes.promoted}get guests(){return this.attributes["number-of-guests"]}set guests(t){this.attributes["number-of-guests"]=t}get filigraneLogoUrl(){return this.attributes["filigrane-logo-url"]?this.attributes["filigrane-logo-url"]:null}get sponsorName(){return this.relationships.sponsors.length>0?this.relationships.sponsors[0].attributes.name:null}get sponsorLogoUrl(){var t;return this.relationships.sponsors.data.length>0&&((t=this.included)!=null&&t.length)?this.included.find(s=>s.id===this.relationships.sponsors.data[0].id&&s.type==="sponsors").attributes["logo-url"]:null}get informationalSentence(){return this.attributes["informational-sentence"]}get costLabel(){switch(this.attributes.cost){case 1:return"faible";case 2:return"moyen";case 3:return"élevé";default:return"moyen"}}get orderHistory(){return this.attributes["order-history"]}get preparationTime(){}get cookingTime(){}get restingTime(){}get difficulty(){return this.attributes.difficulty}set difficulty(t){this.attributes.difficulty=t}}var w=Object.getOwnPropertyDescriptor,C=(e,t,s,i)=>{for(var n=i>1?void 0:i?w(t,s):t,r=e.length-1,o;r>=0;r--)(o=e[r])&&(n=o(n)||n);return n};let d=class extends h{constructor(){super(...arguments),this.recipeId="",this.isDragging=!1,this.dragStartX=0,this.initialScrollLeft=0,this.layoutObserver=null,this.menuRecipes=[],this.suggestedRecipes=[],this.buttonClickHandlers=new Map,this.swapRecipeCount=0,this.swapRecipeClick$=new m,this.analyticsPath="/meals-planner/current",this.preferencesSubscription=new f,this.lastShownRecipeId=null}get selectors(){return{buttonsContainer:".mealz-planner-recipe-suggestion__meals-count",title:".mealz-planner-current-menu__recipe-title",removeButtons:".mealz-planner-recipe-suggestion__actions-remove",removeButton:".mealz-planner-recipe-suggestion__actions-remove-button",swapButton:".mealz-planner-recipe-suggestion__actions-swap-button",addButton:".mealz-planner-recipe-suggestion__actions-add-button",seeRecipe:".mealz-planner-recipe-suggestion__see-recipe",promotion:".mealz-planner-recipe-suggestion__recipe-badges-promotion",sponsor:".mealz-planner-recipe-suggestion__recipe-sponsor",addAndSwapButtons:".mealz-planner-recipe-suggestion__actions-add-and-swap",buttons:[".mealz-planner-recipe-suggestion__meals-count-button"],activeButton:".mealz-planner-recipe-suggestion__meals-count-button.primary",pictureContainer:".mealz-planner-recipe-suggestion__picture",picture:".mealz-planner-recipe-suggestion__picture img",sponsorImg:".mealz-planner-recipe-suggestion__recipe-sponsor img"}}connectedCallback(){super.connectedCallback(),this.initSelectors(),this.addEventListeners(),this.swapRecipeClick$.pipe(b(300)).subscribe(()=>this.swapRecipe()),this.subscribeToPreferencesChanges()}disconnectedCallback(){super.disconnectedCallback(),this.layoutObserver&&this.layoutObserver.disconnect(),this.swapRecipeClick$.complete(),this.preferencesSubscription.unsubscribe()}render(){const{buttonsContainer:e,buttons:t}=this.elements;!e||!t.length||this.mealsCountButtonsListener(t)}firstUpdated(){var i,n;const{buttonsContainer:e,buttons:t}=this.elements;if(!e||!t.length)return;this.initScrolling(e,t),this.initDragScrolling(e);const s=(i=this.attributes["starting-data"])==null?void 0:i.value;s&&(Object.assign(this,JSON.parse(s)),this.recipeId=(n=this.recipeDisplayed)==null?void 0:n.id,t.length===1&&this.recipeId&&this.suggestionShownEvent(),this.removeAttribute("starting-data"))}addEventListeners(){this.addClickListener("removeButton",()=>this.removeRecipe().subscribe()),this.addClickListener("swapButton",()=>this.swapRecipeClick$.next()),this.addClickListener("addButton",()=>this.addRecipe()),this.addClickListener("title",()=>this.openRecipeDetails()),this.addClickListener("seeRecipe",()=>this.openRecipeDetails()),this.addClickListener("pictureContainer",()=>this.openRecipeDetails())}mealsCountButtonsListener(e){e.forEach((t,s)=>{const i=this.buttonClickHandlers.get(t);i&&t.removeEventListener("click",i);const n=()=>this.handleRecipeSelect(e,t,s);this.buttonClickHandlers.set(t,n),t.addEventListener("click",n)})}handleRecipeSelect(e,t,s){e.forEach(i=>i.classList.remove("primary")),t.classList.add("primary"),this.updateDisplayedRecipe(!1,s),s+1===e.length&&this.suggestionShownEvent(),this.scrollToButton(t)}updateDisplayedRecipe(e=!1,t){const{title:s,promotion:i,sponsor:n,addAndSwapButtons:r,removeButtons:o,picture:c,sponsorImg:l}=this.elements;if(!c||!s||!i||!n||!l||!r||!o)return;const a=this.getRecipeToDisplay(e,t);if(!a)return;const u=new L;Object.assign(u,a),this.recipeId=a.id,this.initializeUIState(c,i,n),this.setupImageHandlers(c,l,n,u,s,i,r,o,t)}getRecipeToDisplay(e,t){return e?this.suggestedRecipes[0]:this.menuRecipes[t]||this.suggestedRecipes[0]}initializeUIState(e,t,s){e.classList.add("loading"),t.classList.add("hidden"),s.classList.add("hidden")}setupImageHandlers(e,t,s,i,n,r,o,c,l){let a=null;const u=()=>{a&&(clearTimeout(a),a=null),this.updateRecipeUI(e,s,n,r,o,c,i,l)};if(e.onload=u,e.onerror=u,i.attributes["media-url"])e.src=i.attributes["media-url"];else{u();return}i.sponsorLogoUrl&&(t.src=i.sponsorLogoUrl),a=window.setTimeout(u,1e3)}updateRecipeUI(e,t,s,i,n,r,o,c){e.classList.remove("loading"),o.sponsorLogoUrl&&t.classList.remove("hidden"),s.textContent=o.attributes.title||"",i.classList.toggle("hidden",!o.discounted);const l=!!this.menuRecipes[c];n.classList.toggle("hidden",l),r.classList.toggle("hidden",!l)}addRecipe(){this.toggleLoadingButton(!0);const e=document.querySelector("mealz-planner-current-menu");if(!e){this.toggleLoadingButton(!1);return}e.addRecipe(this.recipeId,this.guests,"ai_suggestion","meals-planner-dashboard").subscribe({next:()=>{this.addAndSelectNewSuggestion(),this.toggleLoadingButton(!1)},error:()=>{this.toggleLoadingButton(!1)}})}toggleLoadingButton(e){const t=this.selectors.addButton,s=this.querySelector(t);s&&s.classList.toggle("loading",e)}addAndSelectNewSuggestion(e){!e||this.suggestedRecipes[0].id===e.id?(this.menuRecipes.push(this.suggestedRecipes[0]),this.removeSuggestedRecipe()):this.menuRecipes.push(e),this.addNewMealCountButton(),this.selectNewSuggestion(),this.addCheckIconToButton(),this.requestUpdate()}addNewMealCountButton(){var n;const{buttons:e}=this.elements;if(!e.length)return;const t=e[e.length-1],s=t.cloneNode(!0);s.classList.remove("primary");const i=s.querySelector("span");if(i){const r=(n=i.textContent)==null?void 0:n.match(/\d+/);if(r){const o=parseInt(r[0],10)+1;i.textContent=i.textContent.replace(/\d+/,o.toString())}}t.after(s)}selectNewSuggestion(){this.initSelectors("buttons");const{buttons:e}=this.elements;if(!e.length)return;const t=e[e.length-1];this.handleRecipeSelect(e,t,e.length-1)}addCheckIconToButton(){this.initSelectors("buttons");const{buttons:e}=this.elements;if(!e.length)return;const t=e[e.length-2],s=document.createElement("img");s.src="https://storage.googleapis.com/assets.miam.tech/generic/icons/Check.svg",s.alt="check icon",t.appendChild(s)}removeRecipe(e){const t=e||this.recipeId,s=document.querySelector("mealz-planner-current-menu");return!s||!t?R():s.removeRecipe(t).pipe(g(1),v(()=>{const i=this.menuRecipes.findIndex(n=>n.id===t);i!==-1&&(this.removeRecipeFromMenu(i),this.removeButtonFromContainer(i),this.updateButtonsCount())}))}removeButtonFromContainer(e){const{buttonsContainer:t,buttons:s}=this.elements;if(!t||!s.length)return;const i=s[e];if(i.classList.contains("primary")){const n=+e+1,r=s[n];this.handleRecipeSelect(s,r,e)}i.remove()}removeRecipeFromMenu(e){this.menuRecipes.splice(e,1)}updateButtonsCount(){this.initSelectors("buttons");const{buttons:e}=this.elements;e.forEach((t,s)=>{var n;const i=t.querySelector("span");if(i&&((n=i.textContent)==null?void 0:n.match(/\d+/))){const o=s+1;i.textContent=i.textContent.replace(/\d+/,o.toString())}}),this.requestUpdate()}swapRecipe(){p.planner.rejectRecipe(this.recipeId).pipe(g(1)).subscribe(),this.recipeSwappedEvent(),this.swapRecipeCount++,!sessionStorage.getItem("_miam/selectFromCatalogSuggestion")&&this.swapRecipeCount>3&&(sessionStorage.setItem("_miam/selectFromCatalogSuggestion","true"),this.openCatalogModal()),this.removeSuggestedRecipe(),this.updateDisplayedRecipe(!0),this.suggestionShownEvent()}removeSuggestedRecipe(){this.suggestedRecipes.shift(),this.suggestedRecipes.length<2&&p.planner.getSuggestedRecipes().pipe(g(1)).subscribe(e=>{const t=new Set(this.suggestedRecipes.map(i=>i.id)),s=e.filter(i=>!t.has(i.id));this.suggestedRecipes=[...this.suggestedRecipes,...s]})}openCatalogModal(){const e=document.querySelector("mealz-planner-current-menu");this.promptCatalogEvent(),e==null||e.openCatalogModal()}openRecipeDetails(){p.recipes.openDetails(this.recipeId,this.guests,0,"",!0)}initScrolling(e,t){t.length>0&&t[0].offsetWidth>0?this.centerActiveButton(e,t):this.waitForButtonLayout(e,t)}centerActiveButton(e,t){this.initSelectors("activeButton");const{activeButton:s}=this.elements;this.setPadding(e,t),s&&this.scrollToButton(s,"instant")}waitForButtonLayout(e,t){const s=new ResizeObserver(()=>{t.length>0&&t[0].offsetWidth>0&&(this.centerActiveButton(e,t),s.disconnect())});t.forEach(i=>s.observe(i))}initDragScrolling(e){e.addEventListener("mousedown",t=>this.startDrag(t,e)),e.addEventListener("mouseleave",()=>this.stopDrag()),e.addEventListener("mouseup",()=>this.stopDrag()),e.addEventListener("mousemove",t=>this.onDrag(t,e))}refreshSuggestions(){p.planner.getSuggestedRecipes().pipe(g(1)).subscribe(e=>{var n;this.suggestedRecipes=e,this.initSelectors("buttons","activeButton");const{buttons:t,activeButton:s}=this.elements;if(!!(t!=null&&t.length)&&s===t[t.length-1]&&this.suggestedRecipes.length>0){const r=this.suggestedRecipes[0];((n=this.recipeDisplayed)==null?void 0:n.id)!==r.id&&(this.recipeDisplayed=r,this.updateDisplayedRecipe(!0),this.requestUpdate())}})}subscribeToPreferencesChanges(){this.preferencesSubscription.add(p.preferences.preferencesChanged$().subscribe(()=>this.refreshSuggestions()))}setPadding(e,t){const s=t[0].offsetWidth,i=t[t.length-1].offsetWidth;e.style.paddingLeft=`calc(50% - ${s/2}px)`,e.style.paddingRight=`calc(50% - ${i/2}px)`}scrollToButton(e,t="smooth"){if(!e||!e.parentElement)return;const s=e.parentElement,n=Array.from(this.elements.buttons).indexOf(e);if(n===-1)return;const r=window.getComputedStyle(s),o=parseFloat(r.paddingLeft||"0"),c=window.getComputedStyle(e),l=parseFloat(c.marginRight||"0");let a=e.offsetLeft-o;a+=l*n,s.scrollTo({left:a,behavior:t})}startDrag(e,t){this.isDragging=!0,this.dragStartX=e.pageX-t.offsetLeft,this.initialScrollLeft=t.scrollLeft}stopDrag(){this.isDragging=!1}onDrag(e,t){if(!this.isDragging)return;e.preventDefault();const s=e.pageX-t.offsetLeft;t.scrollLeft=this.initialScrollLeft-(s-this.dragStartX)}recipeSwappedEvent(){p.analytics.sendEvent("planner.recipe.swap",this.analyticsPath,{recipe_id:this.recipeId})}promptCatalogEvent(){p.analytics.sendEvent("planner.recipe.catalog-prompt",this.analyticsPath,{})}suggestionShownEvent(){this.recipeId&&this.recipeId!==this.lastShownRecipeId&&(p.analytics.sendEvent("planner.suggestion.show",this.analyticsPath,{recipe_id:this.recipeId}),this.lastShownRecipeId=this.recipeId)}};d=C([S("mealz-planner-recipe-suggestion")],d);
1
+ import{N as h,q as m,S as f}from"../../assets/no-shadow-element-DlGA0h9b.js";import{t as S}from"../../assets/custom-element-BhZVzxrc.js";import{m as p}from"../../assets/mealz-sdk-DWLzEfKz.js";import{d as R}from"../../assets/debounceTime-CIA2MWDj.js";import{o as b}from"../../assets/of-CH-D5SN9.js";import{t as g}from"../../assets/take-BmqRVy-3.js";import{t as v}from"../../assets/tap-C4xC1M3N.js";import"../../assets/async-H-Co76Oa.js";import"../../assets/OperatorSubscriber-z_a6lCKk.js";import"../../assets/from-Btz8AgkO.js";import"../../assets/executeSchedule-CTqB8mra.js";import"../../assets/innerFrom-CVMPVEmB.js";import"../../assets/empty-DGYYDWIm.js";class w{constructor(){this.attributes={title:"","ext-id":"","ext-link":"",description:"","number-of-guests":"","preparation-time":"","preheating-time":"","cooking-time":"","resting-time":"","media-url":"",source:"","informational-page-html":"","filigrane-logo-url":"","informational-sentence":"","order-history":"",difficulty:1,cost:1,suggested:!1,popularity:0,"video-id":"",promoted:!1,editable:!1,position:-1},this.ttl=3600,this.finalTimer=this.attributes["preparation-time"]+this.attributes["preheating-time"]+this.attributes["cooking-time"]+this.attributes["resting-time"]}get title(){return this.attributes.title}get promoted(){return this.attributes.promoted}get guests(){return this.attributes["number-of-guests"]}set guests(t){this.attributes["number-of-guests"]=t}get filigraneLogoUrl(){return this.attributes["filigrane-logo-url"]?this.attributes["filigrane-logo-url"]:null}get sponsorName(){return this.relationships.sponsors.length>0?this.relationships.sponsors[0].attributes.name:null}get sponsorLogoUrl(){var t;return this.relationships.sponsors.data.length>0&&((t=this.included)!=null&&t.length)?this.included.find(s=>s.id===this.relationships.sponsors.data[0].id&&s.type==="sponsors").attributes["logo-url"]:null}get informationalSentence(){return this.attributes["informational-sentence"]}get costLabel(){switch(this.attributes.cost){case 1:return"faible";case 2:return"moyen";case 3:return"élevé";default:return"moyen"}}get orderHistory(){return this.attributes["order-history"]}get preparationTime(){}get cookingTime(){}get restingTime(){}get difficulty(){return this.attributes.difficulty}set difficulty(t){this.attributes.difficulty=t}}var L=Object.getOwnPropertyDescriptor,y=(e,t,s,i)=>{for(var n=i>1?void 0:i?L(t,s):t,r=e.length-1,o;r>=0;r--)(o=e[r])&&(n=o(n)||n);return n};let d=class extends h{constructor(){super(...arguments),this.recipeId="",this.isDragging=!1,this.dragStartX=0,this.initialScrollLeft=0,this.layoutObserver=null,this.menuRecipes=[],this.suggestedRecipes=[],this.buttonClickHandlers=new Map,this.swapRecipeCount=0,this.swapRecipeClick$=new m,this.analyticsPath="/meals-planner/current",this.preferencesSubscription=new f,this.lastShownRecipeId=null}get selectors(){return{buttonsContainer:".mealz-planner-recipe-suggestion__meals-count",title:".mealz-planner-current-menu__recipe-title",removeButtons:".mealz-planner-recipe-suggestion__actions-remove",removeButton:".mealz-planner-recipe-suggestion__actions-remove-button",swapButton:".mealz-planner-recipe-suggestion__actions-swap-button",addButton:".mealz-planner-recipe-suggestion__actions-add-button",seeRecipe:".mealz-planner-recipe-suggestion__see-recipe",promotion:".mealz-planner-recipe-suggestion__recipe-badges-promotion",sponsor:".mealz-planner-recipe-suggestion__recipe-sponsor",addAndSwapButtons:".mealz-planner-recipe-suggestion__actions-add-and-swap",buttons:[".mealz-planner-recipe-suggestion__meals-count-button"],activeButton:".mealz-planner-recipe-suggestion__meals-count-button.primary",pictureContainer:".mealz-planner-recipe-suggestion__picture",picture:".mealz-planner-recipe-suggestion__picture img",sponsorImg:".mealz-planner-recipe-suggestion__recipe-sponsor img"}}connectedCallback(){super.connectedCallback(),this.initSelectors(),this.addEventListeners(),this.swapRecipeClick$.pipe(R(300)).subscribe(()=>this.swapRecipe()),this.subscribeToPreferencesChanges()}disconnectedCallback(){super.disconnectedCallback(),this.layoutObserver&&this.layoutObserver.disconnect(),this.swapRecipeClick$.complete(),this.preferencesSubscription.unsubscribe()}render(){const{buttonsContainer:e,buttons:t}=this.elements;!e||!t.length||this.mealsCountButtonsListener(t)}firstUpdated(){var i,n;const{buttonsContainer:e,buttons:t}=this.elements;if(!e||!t.length)return;this.initScrolling(e,t),this.initDragScrolling(e);const s=(i=this.attributes["starting-data"])==null?void 0:i.value;s&&(Object.assign(this,JSON.parse(s)),this.recipeId=(n=this.recipeDisplayed)==null?void 0:n.id,t.length===1&&this.recipeId&&this.suggestionShownEvent(),this.removeAttribute("starting-data"))}addEventListeners(){this.addClickListener("removeButton",()=>this.removeRecipe().subscribe()),this.addClickListener("swapButton",()=>this.swapRecipeClick$.next()),this.addClickListener("addButton",()=>this.addRecipe()),this.addClickListener("title",()=>this.openRecipeDetails()),this.addClickListener("seeRecipe",()=>this.openRecipeDetails()),this.addClickListener("pictureContainer",()=>this.openRecipeDetails())}mealsCountButtonsListener(e){e.forEach((t,s)=>{const i=this.buttonClickHandlers.get(t);i&&t.removeEventListener("click",i);const n=()=>this.handleRecipeSelect(e,t,s);this.buttonClickHandlers.set(t,n),t.addEventListener("click",n)})}handleRecipeSelect(e,t,s){e.forEach(i=>i.classList.remove("primary")),t.classList.add("primary"),this.updateDisplayedRecipe(!1,s),s+1===e.length&&this.suggestionShownEvent(),this.scrollToButton(t)}updateDisplayedRecipe(e=!1,t){const{title:s,promotion:i,sponsor:n,addAndSwapButtons:r,removeButtons:o,picture:c,sponsorImg:l}=this.elements;if(!c||!s||!i||!n||!l||!r||!o)return;const a=this.getRecipeToDisplay(e,t);if(!a)return;const u=new w;Object.assign(u,a),this.recipeId=a.id,this.initializeUIState(c,i,n),this.setupImageHandlers(c,l,n,u,s,i,r,o,t)}getRecipeToDisplay(e,t){return e?this.suggestedRecipes[0]:this.menuRecipes[t]||this.suggestedRecipes[0]}initializeUIState(e,t,s){e.classList.add("loading"),t.classList.add("hidden"),s.classList.add("hidden")}setupImageHandlers(e,t,s,i,n,r,o,c,l){let a=null;const u=()=>{a&&(clearTimeout(a),a=null),this.updateRecipeUI(e,s,n,r,o,c,i,l)};if(e.onload=u,e.onerror=u,i.attributes["media-url"])e.src=i.attributes["media-url"];else{u();return}i.sponsorLogoUrl&&(t.src=i.sponsorLogoUrl),a=window.setTimeout(u,1e3)}updateRecipeUI(e,t,s,i,n,r,o,c){e.classList.remove("loading"),o.sponsorLogoUrl&&t.classList.remove("hidden"),s.textContent=o.attributes.title||"",i.classList.toggle("hidden",!o.discounted);const l=!!this.menuRecipes[c];n.classList.toggle("hidden",l),r.classList.toggle("hidden",!l)}addRecipe(){this.toggleLoadingButton(!0);const e=document.querySelector("mealz-planner-current-menu");if(!e){this.toggleLoadingButton(!1);return}e.addRecipe(this.recipeId,this.guests,"ai_suggestion","meals-planner-dashboard").subscribe({next:()=>{this.addAndSelectNewSuggestion(),this.toggleLoadingButton(!1)},error:()=>{this.toggleLoadingButton(!1)}})}toggleLoadingButton(e){const t=this.selectors.addButton,s=this.querySelector(t);s&&s.classList.toggle("loading",e)}addAndSelectNewSuggestion(e){!e||this.suggestedRecipes[0].id===e.id?(this.menuRecipes.push(this.suggestedRecipes[0]),this.removeSuggestedRecipe()):this.menuRecipes.push(e),this.addNewMealCountButton(),this.selectNewSuggestion(),this.addCheckIconToButton(),this.requestUpdate()}addNewMealCountButton(){var n;const{buttons:e}=this.elements;if(!e.length)return;const t=e[e.length-1],s=t.cloneNode(!0);s.classList.remove("primary");const i=s.querySelector("span");if(i){const r=(n=i.textContent)==null?void 0:n.match(/\d+/);if(r){const o=parseInt(r[0],10)+1;i.textContent=i.textContent.replace(/\d+/,o.toString())}}t.after(s)}selectNewSuggestion(){this.initSelectors("buttons");const{buttons:e}=this.elements;if(!e.length)return;const t=e[e.length-1];this.handleRecipeSelect(e,t,e.length-1)}addCheckIconToButton(){this.initSelectors("buttons");const{buttons:e}=this.elements;if(!e.length)return;const t=e[e.length-2],s=document.createElement("img");s.src="https://storage.googleapis.com/assets.miam.tech/generic/icons/Check.svg",s.alt="check icon",t.appendChild(s)}removeRecipe(e){const t=e||this.recipeId,s=document.querySelector("mealz-planner-current-menu");return!s||!t?b():s.removeRecipe(t).pipe(g(1),v(()=>{const i=this.menuRecipes.findIndex(n=>n.id===t);i!==-1&&(this.removeRecipeFromMenu(i),this.removeButtonFromContainer(i),this.updateButtonsCount())}))}removeButtonFromContainer(e){const{buttonsContainer:t,buttons:s}=this.elements;if(!t||!s.length)return;const i=s[e];if(i.classList.contains("primary")){const n=+e+1,r=s[n];this.handleRecipeSelect(s,r,e)}i.remove()}removeRecipeFromMenu(e){this.menuRecipes.splice(e,1)}updateButtonsCount(){this.initSelectors("buttons");const{buttons:e}=this.elements;e.forEach((t,s)=>{var n;const i=t.querySelector("span");if(i&&((n=i.textContent)==null?void 0:n.match(/\d+/))){const o=s+1;i.textContent=i.textContent.replace(/\d+/,o.toString())}}),this.requestUpdate()}swapRecipe(){this.suggestedRecipes.shift(),p.planner.rejectRecipe(this.recipeId).pipe(g(1)).subscribe({next:()=>{this.suggestedRecipes.length<1&&this.getNewSuggestedRecipes()}}),this.recipeSwappedEvent(),this.swapRecipeCount++,!sessionStorage.getItem("_miam/selectFromCatalogSuggestion")&&this.swapRecipeCount>3&&(sessionStorage.setItem("_miam/selectFromCatalogSuggestion","true"),this.openCatalogModal()),this.updateDisplayedRecipe(!0),this.suggestionShownEvent()}removeSuggestedRecipe(){this.suggestedRecipes.shift(),this.suggestedRecipes.length<1&&this.getNewSuggestedRecipes()}getNewSuggestedRecipes(){p.planner.getSuggestedRecipes().pipe(g(1)).subscribe(e=>{const t=new Set(this.suggestedRecipes.map(i=>i.id)),s=e.filter(i=>!t.has(i.id));this.suggestedRecipes=[...this.suggestedRecipes,...s],this.updateDisplayedRecipe(!0),this.suggestionShownEvent()})}openCatalogModal(){const e=document.querySelector("mealz-planner-current-menu");this.promptCatalogEvent(),e==null||e.openCatalogModal()}openRecipeDetails(){p.recipes.openDetails(this.recipeId,this.guests,0,"",!0)}initScrolling(e,t){t.length>0&&t[0].offsetWidth>0?this.centerActiveButton(e,t):this.waitForButtonLayout(e,t)}centerActiveButton(e,t){this.initSelectors("activeButton");const{activeButton:s}=this.elements;this.setPadding(e,t),s&&this.scrollToButton(s,"instant")}waitForButtonLayout(e,t){const s=new ResizeObserver(()=>{t.length>0&&t[0].offsetWidth>0&&(this.centerActiveButton(e,t),s.disconnect())});t.forEach(i=>s.observe(i))}initDragScrolling(e){e.addEventListener("mousedown",t=>this.startDrag(t,e)),e.addEventListener("mouseleave",()=>this.stopDrag()),e.addEventListener("mouseup",()=>this.stopDrag()),e.addEventListener("mousemove",t=>this.onDrag(t,e))}refreshSuggestions(){p.planner.getSuggestedRecipes().pipe(g(1)).subscribe(e=>{var n;this.suggestedRecipes=e,this.initSelectors("buttons","activeButton");const{buttons:t,activeButton:s}=this.elements;if(!!(t!=null&&t.length)&&s===t[t.length-1]&&this.suggestedRecipes.length>0){const r=this.suggestedRecipes[0];((n=this.recipeDisplayed)==null?void 0:n.id)!==r.id&&(this.recipeDisplayed=r,this.updateDisplayedRecipe(!0),this.requestUpdate())}})}subscribeToPreferencesChanges(){this.preferencesSubscription.add(p.preferences.preferencesChanged$().subscribe(()=>this.refreshSuggestions()))}setPadding(e,t){const s=t[0].offsetWidth,i=t[t.length-1].offsetWidth;e.style.paddingLeft=`calc(50% - ${s/2}px)`,e.style.paddingRight=`calc(50% - ${i/2}px)`}scrollToButton(e,t="smooth"){if(!e||!e.parentElement)return;const s=e.parentElement,n=Array.from(this.elements.buttons).indexOf(e);if(n===-1)return;const r=window.getComputedStyle(s),o=parseFloat(r.paddingLeft||"0"),c=window.getComputedStyle(e),l=parseFloat(c.marginRight||"0");let a=e.offsetLeft-o;a+=l*n,s.scrollTo({left:a,behavior:t})}startDrag(e,t){this.isDragging=!0,this.dragStartX=e.pageX-t.offsetLeft,this.initialScrollLeft=t.scrollLeft}stopDrag(){this.isDragging=!1}onDrag(e,t){if(!this.isDragging)return;e.preventDefault();const s=e.pageX-t.offsetLeft;t.scrollLeft=this.initialScrollLeft-(s-this.dragStartX)}recipeSwappedEvent(){p.analytics.sendEvent("planner.recipe.swap",this.analyticsPath,{recipe_id:this.recipeId})}promptCatalogEvent(){p.analytics.sendEvent("planner.recipe.catalog-prompt",this.analyticsPath,{})}suggestionShownEvent(){this.recipeId&&this.recipeId!==this.lastShownRecipeId&&(p.analytics.sendEvent("planner.suggestion.show",this.analyticsPath,{recipe_id:this.recipeId}),this.lastShownRecipeId=this.recipeId)}};d=y([S("mealz-planner-recipe-suggestion")],d);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "mealz-components",
3
3
  "type": "module",
4
- "version": "2.0.1",
4
+ "version": "2.0.2",
5
5
  "main": "./dist/mealz-components.js",
6
6
  "module": "./dist/mealz-components.js",
7
7
  "scripts": {