mealz-components 1.3.18 → 1.3.19
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
|
|
1
|
+
import{N as I}from"../assets/no-shadow-element-hPtyoDlQ.js";import{V as w}from"../assets/viewport-listener-Ci9Ivhrq.js";import{t as m}from"../assets/custom-element-BhZVzxrc.js";import{h as g}from"../assets/session-handler-BPS5vj92.js";import"../assets/async--NeWdP3z.js";const h="__mealzRecipeCardShowTracker__",r=class r{constructor(){this.trackedRecipes=new Map,this.hasScrolled=!1,this.scrollListener=null,this.cleanupInterval=null,this.MAX_RECIPES=1e3,this.CLEANUP_INTERVAL=5*60*1e3,this.handlePageUnload=()=>{this.destroy()},this.setupScrollListener(),this.startAutoCleanup(),this.setupPageUnloadListener()}static getInstance(){const e=typeof window<"u"?window:void 0,i=e==null?void 0:e[h];return i?(r.instance=i,i):(r.instance||(r.instance=new r,e&&(e[h]=r.instance)),r.instance)}trackRecipeShow(e,i,n){var o,u;const s=Date.now(),a=!this.trackedRecipes.get(e),l=this.hasScrolled;!a&&!l||(this.trackedRecipes.size>=this.MAX_RECIPES&&this.cleanOldRecipes(),this.trackedRecipes.set(e,s),(u=(o=window.mealzInternal)==null?void 0:o.analytics)==null||u.sendEvent("recipe.show",i,{recipe_id:e,category_id:n}))}cleanOldRecipes(){const i=Date.now()-60*60*1e3;for(const[n,s]of this.trackedRecipes.entries())s<i&&this.trackedRecipes.delete(n)}clearAllRecipes(){this.trackedRecipes.clear()}destroy(){this.scrollListener&&(document.removeEventListener("scroll",this.scrollListener,!0),this.scrollListener=null),window.removeEventListener("beforeunload",this.handlePageUnload),this.cleanupInterval&&(clearInterval(this.cleanupInterval),this.cleanupInterval=null),this.trackedRecipes.clear(),this.hasScrolled=!1,r.instance=null,typeof window<"u"&&delete window[h]}setupScrollListener(){let e;this.scrollListener=()=>{this.hasScrolled=!0,clearTimeout(e),e=window.setTimeout(()=>{this.hasScrolled=!1},2e3)},document.addEventListener("scroll",this.scrollListener,{passive:!0,capture:!0})}startAutoCleanup(){this.cleanupInterval=window.setInterval(()=>{this.cleanOldRecipes()},this.CLEANUP_INTERVAL)}setupPageUnloadListener(){window.addEventListener("beforeunload",this.handlePageUnload)}};r.instance=null;let d=r;function C(t){const{element:e,recipeId:i,analyticsPath:n="",categoryId:s="",visibilityThreshold:c,debounceMs:a}=t,l=new w(e,()=>{d.getInstance().trackRecipeShow(i,n,s)},{threshold:c,debounce:a});return{disconnect:()=>l.disconnect()}}const f=.8,S=1e3;var v=Object.defineProperty,T=Object.getOwnPropertyDescriptor,k=(t,e,i,n)=>{for(var s=n>1?void 0:n?T(e,i):e,c=t.length-1,a;c>=0;c--)(a=t[c])&&(s=(n?a(e,i,s):a(s))||s);return n&&s&&v(e,i,s),s};let p=class extends I{constructor(){super(...arguments),this.subscriptions=[],this.handleTopClick=()=>this.recipeCardTopClick(),this.handleCtaClick=()=>this.recipeCardCtaClick()}connectedCallback(){super.connectedCallback(),this.getInitialStatus(),this.listenInView(),this.subscriptions.push(window.mealzInternal.basket.recipeDataInBasket$().subscribe(t=>{const e=t.find(i=>i.id===this.recipeId);e&&(this.updatedRecipeId=e.id,this.updatedGuests=e.guests,this.updateDOM())}),window.mealzInternal.recipes.guestsUpdated().subscribe(t=>{t.recipeId===this.recipeId&&(this.updatedGuests=t.guests,this.updatedRecipeId=this.recipeId,this.updateDOM())}))}disconnectedCallback(){var e;super.disconnectedCallback(),this.subscriptions.forEach(i=>i.unsubscribe()),(e=this.recipeShowTracking)==null||e.disconnect(),d.getInstance().cleanOldRecipes()}render(){this.recipeCardTop=this.querySelector(".mealz-recipe-card__top"),this.recipeCardCta=this.querySelector(".mealz-recipe-card__cta"),this.recipeCardTop&&(this.recipeCardTop.removeEventListener("click",this.handleTopClick),this.recipeCardTop.addEventListener("click",this.handleTopClick),this.recipeCardCta&&(this.recipeCardCta.removeEventListener("click",this.handleCtaClick),this.recipeCardCta.addEventListener("click",this.handleCtaClick)))}listenInView(){var t;(t=this.recipeShowTracking)==null||t.disconnect(),this.recipeShowTracking=C({element:this,recipeId:this.recipeId,analyticsPath:this.analyticsPath,categoryId:this.categoryId,visibilityThreshold:f,debounceMs:S})}getInitialStatus(){var l;const t=(l=this.attributes["starting-data"])==null?void 0:l.value;if(!t)return;const{id:e,guests:i,path:n,categoryId:s,initialTabIndex:c,sessionId:a}=JSON.parse(t);if(this.recipeId=e,this.analyticsPath=n,this.categoryId=s,this.guests=i,this.initialTabIndex=c,g(a),!i){this.guests=this.getGuests();const o=this.querySelector(".mealz-recipe-card__counter p");o&&(o.innerHTML=this.guests.toString())}this.removeAttribute("starting-data")}recipeCardTopClick(){window.mealzInternal.recipes.openDetails(this.recipeId,this.guests,this.initialTabIndex,this.analyticsPath,this.categoryId)}recipeCardCtaClick(){window.mealzInternal.recipes.openDetails(this.recipeId,this.guests,this.initialTabIndex,this.analyticsPath,this.categoryId)}getGuests(){const t=localStorage.getItem("_miam/preferences/guests");if(t){const e=+t;if(!isNaN(e)&&e>0&&e<=30)return e}return 4}updateDOM(){if(this.recipeId!==this.updatedRecipeId)return;const t=this.querySelector(".mealz-recipe-card__counter p");t&&(this.guests=this.updatedGuests??this.getGuests(),t.innerHTML=this.guests.toString())}};p=k([m("mealz-recipe-card")],p);customElements.get("mealz-recipe-card")||customElements.define("mealz-recipe-card",p);
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mealz-components",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.3.
|
|
4
|
+
"version": "1.3.19",
|
|
5
5
|
"main": "./dist/mealz-components.js",
|
|
6
6
|
"module": "./dist/mealz-components.js",
|
|
7
7
|
"scripts": {
|
|
8
|
-
"build": "vite build",
|
|
8
|
+
"build": "vite build && vite build --config vite-config/vite.config.recipe-card-show-tracking.js",
|
|
9
9
|
"build:watch": "vite build --watch",
|
|
10
10
|
"lint": "eslint"
|
|
11
11
|
},
|
|
@@ -21,7 +21,8 @@
|
|
|
21
21
|
"./like-button": {
|
|
22
22
|
"import": "./dist/like-button/like-button.js",
|
|
23
23
|
"require": "./dist/like-button/like-button.cjs"
|
|
24
|
-
}
|
|
24
|
+
},
|
|
25
|
+
"./recipe-card-show-tracking": "./dist/integrations/recipe-card-show-tracking.min.js"
|
|
25
26
|
},
|
|
26
27
|
"files": [
|
|
27
28
|
"package.json",
|