mealz-components 1.2.5 → 1.2.7
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{t as
|
|
1
|
+
import{t as u}from"../../assets/custom-element-BhZVzxrc.js";import"../../assets/lit-element-4gw3YGga.js";import{C as p}from"../catalog-load-more.min.js";import{h as g}from"../../assets/session-handler-BPS5vj92.js";import{o as h,c as m}from"../../assets/OperatorSubscriber-BPZabEAm.js";import"../../assets/no-shadow-element-CaVIVF-o.js";import"../../assets/mapOneOrManyArgs-2FiDGdaS.js";import"../../assets/async-B_IhBgzg.js";function f(e,t){return h(function(i,a){var s=0;i.subscribe(m(a,function(r){return e.call(t,r,s++)&&a.next(r)}))})}function v(e){return f(function(t,i){return e<=i})}var _=Object.defineProperty,b=Object.getOwnPropertyDescriptor,L=(e,t,i,a)=>{for(var s=a>1?void 0:a?b(t,i):t,r=e.length-1,o;r>=0;r--)(o=e[r])&&(s=(a?o(t,i,s):o(s))||s);return a&&s&&_(t,i,s),s};let n=class extends p{constructor(){super(...arguments),this.retryCount=0,this.maxRetries=30}connectedCallback(){super.connectedCallback(),this.subscriptions.push(window.mealzInternal.user.isAuthenticated().pipe(v(1)).subscribe(e=>{this.isLogged=e,this.updateDOM()}),this.handleLikedRecipe())}disconnectedCallback(){super.disconnectedCallback()}render(){var c;const e=(c=this.attributes["starting-data"])==null?void 0:c.value;if(!e||(this.favorites=this.querySelector(".mealz-catalog-favorites__list"),!this.favorites))return;const t=this.querySelector(".mealz-catalog__list");if(!t)return;const{pageSize:i,storeId:a,loadMoreURL:s,displayRecipeVariant:r,search:o,sessionId:l,path:d}=JSON.parse(e);g(l),this.analyticsPath=d,this.sendPageViewEvent(),this.loadMoreRecipesOnScroll({displayRecipeVariant:r,loadMoreURL:s,sessionId:l,pageSize:i,storeId:a,packageId:null,search:o,listHTML:t}),this.removeAttribute("starting-data")}updateDOM(){const e=this.querySelector(".mealz-catalog-favorites__list__not-logged"),t=this.querySelector(".mealz-catalog-favorites__list__logged");!e||!t||(e.classList.toggle("hidden",this.isLogged),t.classList.toggle("hidden",!this.isLogged))}sendPageViewEvent(){window.mealzInternal?(window.mealzInternal.analytics.sendEvent("pageview",this.analyticsPath,{}),this.retryCount=0):this.retryCount<this.maxRetries&&(this.retryCount++,setTimeout(()=>this.sendPageViewEvent(),10))}handleLikedRecipe(){return window.mealzInternal.recipes.recipeLikeUpdated().subscribe(({id:e,isPast:t})=>{const i=document.getElementById("mealz-recipe-card-"+e);i&&i.classList.toggle("hidden",t),this.requestUpdate()})}};n=L([u("mealz-catalog-favorites")],n);customElements.get("mealz-catalog-favorites")||customElements.define("mealz-catalog-favorites",n);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{N as
|
|
1
|
+
import{N as k}from"../assets/no-shadow-element-CaVIVF-o.js";import{c as E,i as h,o as b,_ as x,O as _}from"../assets/OperatorSubscriber-BPZabEAm.js";import{i as L,m as I,a as T,b as D,c as H}from"../assets/mapOneOrManyArgs-2FiDGdaS.js";import{a as z,b as O}from"../assets/async-B_IhBgzg.js";import"../assets/lit-element-4gw3YGga.js";function A(i){return i instanceof Date&&!isNaN(i)}function S(i,e,t,n,o,l,u,c){var d=[],s=0,a=0,r=!1,f=function(){r&&!d.length&&!s&&e.complete()},w=function(p){return s<n?g(p):d.push(p)},g=function(p){s++;var v=!1;L(t(p,a++)).subscribe(E(e,function(m){e.next(m)},function(){v=!0},void 0,function(){if(v)try{s--;for(var m=function(){var y=d.shift();u||g(y)};d.length&&s<n;)m();f()}catch(y){e.error(y)}}))};return i.subscribe(E(e,w,function(){r=!0,f()})),function(){}}function R(i,e,t){return t===void 0&&(t=1/0),h(e)?R(function(n,o){return I(function(l,u){return e(n,l,o,u)})(L(i(n,o)))},t):(typeof e=="number"&&(t=e),b(function(n,o){return S(n,o,i,t)}))}var N=["addListener","removeListener"],$=["addEventListener","removeEventListener"],q=["on","off"];function M(i,e,t,n){if(h(t)&&(n=t,t=void 0),n)return M(i,e,t).pipe(T(n));var o=x(V(i)?$.map(function(c){return function(d){return i[c](e,d,t)}}):B(i)?N.map(C(i,e)):F(i)?q.map(C(i,e)):[],2),l=o[0],u=o[1];if(!l&&D(i))return R(function(c){return M(c,e,t)})(L(i));if(!l)throw new TypeError("Invalid event target");return new _(function(c){var d=function(){for(var s=[],a=0;a<arguments.length;a++)s[a]=arguments[a];return c.next(1<s.length?s:s[0])};return l(d),function(){return u(d)}})}function C(i,e){return function(t){return function(n){return i[t](e,n)}}}function B(i){return h(i.addListener)&&h(i.removeListener)}function F(i){return h(i.on)&&h(i.off)}function V(i){return h(i.addEventListener)&&h(i.removeEventListener)}function j(i,e,t){t===void 0&&(t=z);var n=-1;return e!=null&&(H(e)?t=e:n=e),new _(function(o){var l=A(i)?+i-t.now():i;l<0&&(l=0);var u=0;return t.schedule(function(){o.closed||(o.next(u++),0<=n?this.schedule(void 0,n):o.complete())},l)})}function G(i,e){return b(function(t,n){var o=e??{},l=o.leading,u=l===void 0?!0:l,c=o.trailing,d=c===void 0?!1:c,s=!1,a=null,r=null,f=!1,w=function(){r==null||r.unsubscribe(),r=null,d&&(v(),f&&n.complete())},g=function(){r=null,f&&n.complete()},p=function(m){return r=L(i(m)).subscribe(E(n,w,g))},v=function(){if(s){s=!1;var m=a;a=null,n.next(m),!f&&p(m)}};t.subscribe(E(n,function(m){s=!0,a=m,!(r&&!r.closed)&&(u?v():p(m))},function(){f=!0,!(d&&s&&r&&!r.closed)&&n.complete()}))})}function J(i,e,t){e===void 0&&(e=O);var n=j(i,e);return G(function(){return n},t)}const P=300;class Z extends k{constructor(){super(...arguments),this.noMoreData=!1,this.isLoading=!1,this.page=2,this.loaderElement=null,this.subscriptions=[]}connectedCallback(){super.connectedCallback(),this.createLoader()}disconnectedCallback(){super.disconnectedCallback(),this.subscriptions.forEach(e=>e.unsubscribe()),this.removeLoader()}loadMoreRecipesOnScroll({displayRecipeVariant:e,loadMoreURL:t,sessionId:n,pageSize:o,storeId:l,packageId:u,search:c,listHTML:d,promotions:s=!1}){const a=M(window,"scroll");this.subscriptions.push(a.pipe(J(100)).subscribe(()=>{const r=this.getBoundingClientRect(),f=r.bottom>0&&r.bottom<=window.innerHeight+P;!this.noMoreData&&!this.isLoading&&f&&this.getMoreRecipes({loadMoreURL:t,sessionId:n,pageSize:o,storeId:l,displayRecipeVariant:e,packageId:u,search:c,promotions:s,listHTML:d})}))}buildHeaders(e){const t={"language-id":window.mealzInternal.user.getLanguage(),"supplier-token":window.mealzInternal.supplier.getToken(),"session-id":e},n=localStorage.getItem("_miam/userId");return n?t.authorization=`user_id ${n}`:t["authless-id"]=localStorage.getItem("_miam/authlessId"),t}async getMoreRecipes({loadMoreURL:e,sessionId:t,pageSize:n,storeId:o,displayRecipeVariant:l,packageId:u,search:c,promotions:d,listHTML:s}){if(this.checkIfMoreRecipes(s.innerHTML,n),this.noMoreData||this.isLoading)return;this.isLoading=!0,this.toggleLoader(!0);const a=new URLSearchParams;a.append("size",n.toString()),a.append("page",this.page.toString()),l&&a.append("display_recipe_variant",l),u&&a.append("category_id",u),o&&a.append("store_id",o),c&&a.append("search",c),d&&a.append("promotions",d);try{const r=await fetch(e+"?"+a,{method:"GET",headers:this.buildHeaders(t)});if(!r.ok)throw new Error(`Load more request failed with status: ${r.status}`);const f=await r.text();this.appendRecipesToList(f,s,n)}catch(r){console.error(r),this.isLoading=!1}}appendRecipesToList(e,t,n){this.checkIfMoreRecipes(e,n),t.insertAdjacentHTML("beforeend",e),this.isLoading=!1,this.toggleLoader(!1),this.page++}checkIfMoreRecipes(e,t){const n=e.match(/<mealz-recipe-card(?=\s|>)/gi)||e.match(/<mealz-history-order(?=\s|>)/gi);(n?n.length:0)<t&&(this.noMoreData=!0)}createLoader(){const e=this.querySelector(".mealz-catalog__content");!this.loaderElement&&e&&(this.loaderElement=document.createElement("div"),this.loaderElement.className="miam-ds-loader",this.loaderElement.style.display="none",e.appendChild(this.loaderElement))}removeLoader(){this.loaderElement&&this.loaderElement.parentElement&&(this.loaderElement.parentElement.removeChild(this.loaderElement),this.loaderElement=null)}toggleLoader(e){this.loaderElement&&(this.loaderElement.style.display=e?"block":"none")}}export{Z as C};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{t as l}from"../../assets/custom-element-BhZVzxrc.js";import"../../assets/lit-element-4gw3YGga.js";import{N as c}from"../../assets/no-shadow-element-CaVIVF-o.js";var h=Object.defineProperty,d=Object.getOwnPropertyDescriptor,p=(t,e,s,r)=>{for(var a=r>1?void 0:r?d(e,s):e,o=t.length-1,i;o>=0;o--)(i=t[o])&&(a=(r?i(e,s,a):i(a))||a);return r&&a&&h(e,s,a),a};let n=class extends c{constructor(){super(...arguments),this.subscriptions=[],this.supplierHeaderHeight=0,this.searchUrl="",this.path=""}connectedCallback(){super.connectedCallback(),this.subscriptions.push(window.mealzInternal.getStickyHeaderHeight().subscribe(t=>{this.supplierHeaderHeight=t,this.setStickyObserver()}),window.mealzInternal.catalog.preferencesModalChanged().subscribe(()=>{const t=this.preferencesButton.querySelector(".mealz-catalog-toolbar__controls__filter-badge"),e=this.preferencesButton.querySelector(".mealz-catalog-toolbar__loader");t&&t.classList.add("hidden"),e&&e.classList.remove("hidden")}))}disconnectedCallback(){super.disconnectedCallback(),this.subscriptions.forEach(t=>t.unsubscribe()),this.toolbarObserver.unobserve(this.anchorElement)}render(){var r;const t=(r=this.attributes["starting-data"])==null?void 0:r.value;if(!t)return;const{searchUrl:e,path:s}=JSON.parse(t);this.searchUrl=e,this.path=s,this.findElementsInDocument(),this.addEveryEventListeners(),this.removeAttribute("starting-data")}firstUpdated(){this.setStickyObserver()}setStickyObserver(){var e;if(this.toolbar=document.querySelector(".mealz-catalog-toolbar"),this.anchorElement=document.querySelector(".mealz-catalog-toolbar__anchor"),!this.anchorElement||!this.toolbar)return;const t={rootMargin:`-${this.supplierHeaderHeight}px 0px 0px 0px`,threshold:1};(e=this.toolbarObserver)==null||e.unobserve(this),setTimeout(()=>this.setStickyToolbarStyle(),50),this.toolbarObserver=new IntersectionObserver(()=>{this.setStickyToolbarStyle()},t),this.toolbarObserver.observe(this.anchorElement)}setStickyToolbarStyle(){const e=this.anchorElement.getBoundingClientRect().top<this.supplierHeaderHeight;this.anchorElement.style.height=e?this.toolbar.clientHeight+"px":"0px",this.toolbar.classList.toggle("sticking",e),this.toolbar.style.top=(e?this.supplierHeaderHeight:0)+"px",this.updateDOM(e)}findElementsInDocument(){this.preferencesButton=this.querySelector(".mealz-catalog-toolbar__controls__preferences"),this.favoritesButton=this.querySelector(".mealz-catalog-toolbar__controls__favorites"),this.searchButton=this.querySelector(".mealz-catalog-toolbar__searchbar-button"),this.searchInput=this.querySelector(".mealz-catalog-toolbar__searchbar-input"),this.backButton=this.querySelector(".mealz-recipe-toolbar__return-button")}addEveryEventListeners(){var t;this.addClickListener(this.preferencesButton,this.openPreferences.bind(this)),this.addClickListener(this.searchButton,this.performSearch.bind(this)),this.addClickListener(this.favoritesButton,this.sendFavoritesDisplay.bind(this)),
|
|
1
|
+
import{t as l}from"../../assets/custom-element-BhZVzxrc.js";import"../../assets/lit-element-4gw3YGga.js";import{N as c}from"../../assets/no-shadow-element-CaVIVF-o.js";var h=Object.defineProperty,d=Object.getOwnPropertyDescriptor,p=(t,e,s,r)=>{for(var a=r>1?void 0:r?d(e,s):e,o=t.length-1,i;o>=0;o--)(i=t[o])&&(a=(r?i(e,s,a):i(a))||a);return r&&a&&h(e,s,a),a};let n=class extends c{constructor(){super(...arguments),this.subscriptions=[],this.supplierHeaderHeight=0,this.searchUrl="",this.path=""}connectedCallback(){super.connectedCallback(),this.subscriptions.push(window.mealzInternal.getStickyHeaderHeight().subscribe(t=>{this.supplierHeaderHeight=t,this.setStickyObserver()}),window.mealzInternal.catalog.preferencesModalChanged().subscribe(()=>{const t=this.preferencesButton.querySelector(".mealz-catalog-toolbar__controls__filter-badge"),e=this.preferencesButton.querySelector(".mealz-catalog-toolbar__loader");t&&t.classList.add("hidden"),e&&e.classList.remove("hidden")}))}disconnectedCallback(){super.disconnectedCallback(),this.subscriptions.forEach(t=>t.unsubscribe()),this.toolbarObserver.unobserve(this.anchorElement)}render(){var r;const t=(r=this.attributes["starting-data"])==null?void 0:r.value;if(!t)return;const{searchUrl:e,path:s}=JSON.parse(t);this.searchUrl=e,this.path=s,this.findElementsInDocument(),this.addEveryEventListeners(),this.removeAttribute("starting-data")}firstUpdated(){this.setStickyObserver()}setStickyObserver(){var e;if(this.toolbar=document.querySelector(".mealz-catalog-toolbar"),this.anchorElement=document.querySelector(".mealz-catalog-toolbar__anchor"),!this.anchorElement||!this.toolbar)return;const t={rootMargin:`-${this.supplierHeaderHeight}px 0px 0px 0px`,threshold:1};(e=this.toolbarObserver)==null||e.unobserve(this),setTimeout(()=>this.setStickyToolbarStyle(),50),this.toolbarObserver=new IntersectionObserver(()=>{this.setStickyToolbarStyle()},t),this.toolbarObserver.observe(this.anchorElement)}setStickyToolbarStyle(){const e=this.anchorElement.getBoundingClientRect().top<this.supplierHeaderHeight;this.anchorElement.style.height=e?this.toolbar.clientHeight+"px":"0px",this.toolbar.classList.toggle("sticking",e),this.toolbar.style.top=(e?this.supplierHeaderHeight:0)+"px",this.updateDOM(e)}findElementsInDocument(){this.preferencesButton=this.querySelector(".mealz-catalog-toolbar__controls__preferences"),this.favoritesButton=this.querySelector(".mealz-catalog-toolbar__controls__favorites"),this.searchButton=this.querySelector(".mealz-catalog-toolbar__searchbar-button"),this.searchInput=this.querySelector(".mealz-catalog-toolbar__searchbar-input"),this.backButton=this.querySelector(".mealz-recipe-toolbar__return-button")}addEveryEventListeners(){var t;this.addClickListener(this.preferencesButton,this.openPreferences.bind(this)),this.addClickListener(this.searchButton,this.performSearch.bind(this)),this.addClickListener(this.favoritesButton,this.sendFavoritesDisplay.bind(this)),(t=this.searchInput)==null||t.addEventListener("keypress",e=>{e.key==="Enter"&&this.performSearch()})}addClickListener(t,e){t==null||t.addEventListener("click",s=>{s.stopPropagation(),e()})}performSearch(){const t=this.searchInput.value.trim();if(!t)return;window.mealzInternal.analytics.sendEvent("search",this.path,{search_term:t});const e=this.searchUrl.includes("?")?"&":"?";window.location.href=`${this.searchUrl}${e}search=${encodeURIComponent(t)}`}updateDOM(t){var r;const e=t?["ghost","square"]:["full"],s=t?["full"]:["ghost","square"];this.toggleClasses(this.favoritesButton,e,s),this.toggleClasses(this.preferencesButton,e,s),(r=this.backButton)==null||r.classList.toggle("hidden",!t)}toggleClasses(t,e,s){t==null||t.classList.remove(...s),t==null||t.classList.add(...e)}openPreferences(){window.mealzInternal.analytics.sendEvent("preferences.display",this.path,{}),window.mealzInternal.catalog.openPreferences()}sendFavoritesDisplay(){window.mealzInternal.analytics.sendEvent("liked.display",this.path,{})}};n=p([l("mealz-catalog-toolbar")],n);customElements.get("mealz-catalog-toolbar")||customElements.define("mealz-catalog-toolbar",n);
|