mealz-components 1.2.4 → 1.2.6

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
- .mealz-catalog-favorites .mealz-catalog-favorites__list__loader{font-size:20px;text-align:center}.mealz-catalog-favorites .hidden{display:none}.mealz-catalog-favorites .mealz-catalog-toolbar:not(.sticking){flex-direction:row;gap:0px}
1
+ .mealz-catalog-favorites .hidden{display:none}.mealz-catalog-favorites .mealz-catalog-toolbar:not(.sticking){flex-direction:row;gap:0px}
@@ -1 +1 @@
1
- import{t as h}from"../../assets/custom-element-BhZVzxrc.js";import"../../assets/lit-element-4gw3YGga.js";import{C as u}from"../catalog-load-more.min.js";import{h as m}from"../../assets/session-handler-BPS5vj92.js";import"../../assets/no-shadow-element-CaVIVF-o.js";import"../../assets/OperatorSubscriber-BPZabEAm.js";import"../../assets/mapOneOrManyArgs-2FiDGdaS.js";import"../../assets/async-B_IhBgzg.js";var p=Object.defineProperty,f=Object.getOwnPropertyDescriptor,v=(t,e,i,a)=>{for(var s=a>1?void 0:a?f(e,i):e,r=t.length-1,o;r>=0;r--)(o=t[r])&&(s=(a?o(e,i,s):o(s))||s);return a&&s&&p(e,i,s),s};let l=class extends u{constructor(){super(...arguments),this.retryCount=0,this.maxRetries=30}connectedCallback(){super.connectedCallback(),this.subscriptions.push(window.mealzInternal.user.isAuthenticated().subscribe(t=>{this.isLogged=t,this.updateDOM()}))}disconnectedCallback(){super.disconnectedCallback()}render(){var c;const t=(c=this.attributes["starting-data"])==null?void 0:c.value;if(!t||(this.favorites=this.querySelector(".mealz-catalog-favorites__list"),!this.favorites))return;this.subscriptions.push(window.mealzInternal.user.isAuthenticated().subscribe(g=>{this.isLogged=g,this.updateDOM()}));const e=this.querySelector(".mealz-catalog__list");if(!e)return;const{pageSize:i,storeId:a,loadMoreURL:s,displayRecipeVariant:r,search:o,sessionId:n,path:d}=JSON.parse(t);m(n),this.analyticsPath=d,this.sendPageViewEvent(),this.loadMoreRecipesOnScroll({displayRecipeVariant:r,loadMoreURL:s,sessionId:n,pageSize:i,storeId:a,packageId:null,search:o,listHTML:e}),this.removeAttribute("starting-data")}updateDOM(){const t=this.querySelector(".mealz-catalog-favorites__list__loader"),e=this.querySelector(".mealz-catalog-favorites__list__not-logged"),i=this.querySelector(".mealz-catalog-favorites__list__logged");!t||!e||!i||(t.classList.add("hidden"),e.classList.toggle("hidden",this.isLogged),i.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))}};l=v([h("mealz-catalog-favorites")],l);customElements.get("mealz-catalog-favorites")||customElements.define("mealz-catalog-favorites",l);
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
- :root{--m-history-order-width: var(--miam-history-order-width, var(--miam-catalog-card-width, 308px))}mealz-catalog-history .mealz-catalog-favorites__list__loader{font-size:20px;text-align:center}mealz-catalog-history .hidden{display:none}mealz-catalog-history .mealz-catalog__list,mealz-catalog-history .mealz-catalog__content .mealz-catalog__list{grid-template-columns:repeat(auto-fill,var(--m-history-order-width, 308px))}@media (min-width: 375px) and (max-width: 712px){mealz-catalog-history .mealz-catalog__list{grid-template-columns:repeat(auto-fill,var(--m-history-order-width, 308px))}}mealz-catalog-history .mealz-catalog-toolbar:not(.sticking){flex-direction:row;gap:0px}
1
+ :root{--m-history-order-width: var(--miam-history-order-width, var(--miam-catalog-card-width, 308px))}mealz-catalog-history .hidden{display:none}mealz-catalog-history .mealz-catalog__list,mealz-catalog-history .mealz-catalog__content .mealz-catalog__list{grid-template-columns:repeat(auto-fill,var(--m-history-order-width, 308px))}@media (min-width: 375px) and (max-width: 712px){mealz-catalog-history .mealz-catalog__list{grid-template-columns:repeat(auto-fill,var(--m-history-order-width, 308px))}}mealz-catalog-history .mealz-catalog-toolbar:not(.sticking){flex-direction:row;gap:0px}
@@ -1 +1 @@
1
- import{N as x}from"../assets/no-shadow-element-CaVIVF-o.js";import{c as E,i as m,o as C,_ as I,O as _}from"../assets/OperatorSubscriber-BPZabEAm.js";import{i as L,m as R,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 S(i){return i instanceof Date&&!isNaN(i)}function A(i,e,t,n,r,l,u,f){var d=[],o=0,a=0,s=!1,h=function(){s&&!d.length&&!o&&e.complete()},w=function(p){return o<n?g(p):d.push(p)},g=function(p){o++;var v=!1;L(t(p,a++)).subscribe(E(e,function(c){e.next(c)},function(){v=!0},void 0,function(){if(v)try{o--;for(var c=function(){var y=d.shift();u||g(y)};d.length&&o<n;)c();h()}catch(y){e.error(y)}}))};return i.subscribe(E(e,w,function(){s=!0,h()})),function(){}}function k(i,e,t){return t===void 0&&(t=1/0),m(e)?k(function(n,r){return R(function(l,u){return e(n,l,r,u)})(L(i(n,r)))},t):(typeof e=="number"&&(t=e),C(function(n,r){return A(n,r,i,t)}))}var N=["addListener","removeListener"],$=["addEventListener","removeEventListener"],q=["on","off"];function M(i,e,t,n){if(m(t)&&(n=t,t=void 0),n)return M(i,e,t).pipe(T(n));var r=I(j(i)?$.map(function(f){return function(d){return i[f](e,d,t)}}):F(i)?N.map(b(i,e)):V(i)?q.map(b(i,e)):[],2),l=r[0],u=r[1];if(!l&&D(i))return k(function(f){return M(f,e,t)})(L(i));if(!l)throw new TypeError("Invalid event target");return new _(function(f){var d=function(){for(var o=[],a=0;a<arguments.length;a++)o[a]=arguments[a];return f.next(1<o.length?o:o[0])};return l(d),function(){return u(d)}})}function b(i,e){return function(t){return function(n){return i[t](e,n)}}}function F(i){return m(i.addListener)&&m(i.removeListener)}function V(i){return m(i.on)&&m(i.off)}function j(i){return m(i.addEventListener)&&m(i.removeEventListener)}function B(i,e,t){t===void 0&&(t=z);var n=-1;return e!=null&&(H(e)?t=e:n=e),new _(function(r){var l=S(i)?+i-t.now():i;l<0&&(l=0);var u=0;return t.schedule(function(){r.closed||(r.next(u++),0<=n?this.schedule(void 0,n):r.complete())},l)})}function G(i,e){return C(function(t,n){var r=e??{},l=r.leading,u=l===void 0?!0:l,f=r.trailing,d=f===void 0?!1:f,o=!1,a=null,s=null,h=!1,w=function(){s==null||s.unsubscribe(),s=null,d&&(v(),h&&n.complete())},g=function(){s=null,h&&n.complete()},p=function(c){return s=L(i(c)).subscribe(E(n,w,g))},v=function(){if(o){o=!1;var c=a;a=null,n.next(c),!h&&p(c)}};t.subscribe(E(n,function(c){o=!0,a=c,!(s&&!s.closed)&&(u?v():p(c))},function(){h=!0,!(d&&o&&s&&!s.closed)&&n.complete()}))})}function J(i,e,t){e===void 0&&(e=O);var n=B(i,e);return G(function(){return n},t)}const P=300;class Z extends x{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:r,storeId:l,packageId:u,search:f,listHTML:d,promotions:o=!1}){const a=M(window,"scroll");this.subscriptions.push(a.pipe(J(100)).subscribe(()=>{!this.noMoreData&&!this.isLoading&&window.innerHeight+Math.round(window.scrollY)+P>=document.body.offsetHeight&&this.getMoreRecipes({loadMoreURL:t,sessionId:n,pageSize:r,storeId:l,displayRecipeVariant:e,packageId:u,search:f,promotions:o,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:r,displayRecipeVariant:l,packageId:u,search:f,promotions:d,listHTML:o}){if(this.checkIfMoreRecipes(o.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),r&&a.append("store_id",r),f&&a.append("search",f),d&&a.append("promotions",d);try{const s=await fetch(e+"?"+a,{method:"GET",headers:this.buildHeaders(t)});if(!s.ok)throw new Error(`Load more request failed with status: ${s.status}`);const h=await s.text();this.appendRecipesToList(h,o,n)}catch(s){console.error(s),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
+ 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};
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "mealz-components",
3
3
  "type": "module",
4
- "version": "1.2.4",
4
+ "version": "1.2.6",
5
5
  "main": "./dist/mealz-components.js",
6
6
  "module": "./dist/mealz-components.js",
7
7
  "scripts": {