@salla.sa/twilight-components
Version:
Salla Web Component
5 lines • 3.62 kB
JavaScript
/*!
* Crafted with ❤ by Salla
*/
import{r as s,h as t,H as i,g as e}from"./p-bdd00808.js";import{H as r}from"./p-cff377ac.js";import"./p-5a803ecc.js";const d="";const l=class{constructor(t){s(this,t);this.blockTitle=undefined;this.subTitle=undefined;this.sliderId=undefined;this.displayAllUrl=undefined;this.autoplay=undefined;this.source=undefined;this.sourceValue=undefined;this.limit=undefined;this.sliderConfig=undefined;this.productCardComponent="custom-salla-product-card";this.includes=undefined;this.productsData=undefined;this.isReady=undefined;this.sourceValueIsValid=undefined;this.hasCustomComponent=undefined;this.apiUrl="";this.parsedSourceValue=undefined}componentWillLoad(){return salla.onReady().then((()=>{this.includes=r.parseJson(this.includes||this.host.getAttribute("includes"));if(!Array.isArray(this.includes)){this.includes=null}r.setIncludes(this.includes);this.sourceValueIsValid=!!(this.getSourceValue()||this.isSourceWithoutValue());if(!this.sourceValueIsValid){salla.logger.warn(`source-value prop is required for source [${this.getSource()}]`);return}this.hasCustomComponent=!!customElements.get(this.productCardComponent);if(this.source==="json"){this.productsData=this.getSourceValue();this.isReady=true;return}if(this.getSource()=="related"&&!salla.config.get("store.settings.product.related_products_enabled")){this.isReady=false;return}return salla.product.api.fetch({source:this.getSource(),source_value:this.getSourceValue(),limit:this.limit}).then((s=>r.injectExtraFieldsToResponse(s))).then((s=>{this.productsData=s.data;this.isReady=true;salla.event.emit("salla-products-slider::products.fetched",s.data)}))}))}componentDidRender(){let s=0;const t=setInterval((()=>{var i;(i=this.host.querySelectorAll('[loading="lazy"]'))===null||i===void 0?void 0:i.forEach((s=>s.removeAttribute("loading")));s++;if(s>=10){clearInterval(t)}}),1e3)}isSourceWithoutValue(){return["offers","latest","sales","top-rated"].includes(this.getSource())}getItemHTML(s){this.getSource()==="landing-page"&&(s.url="");if(this.hasCustomComponent&&this.productCardComponent.toLowerCase()=="custom-salla-product-card"){return t("div",{class:"s-products-slider-card"},t("custom-salla-product-card",{product:s,source:this.getSource(),"source-value":this.getSourceValue()}))}if(this.hasCustomComponent){const i=document.createElement(this.productCardComponent);i.setAttribute("product",JSON.stringify(s));i.setAttribute("source",this.getSource());i.setAttribute("source-value",this.getSourceValue());return t("div",{class:"s-products-slider-card",innerHTML:i.outerHTML})}return t("div",{class:"s-products-slider-card"},t("salla-product-card",{"show-quantity":this.getSource()=="landing-page","hide-add-btn":this.getSource()=="landing-page","shadow-on-hover":true,product:s}))}canRender(){return this.sourceValueIsValid&&this.isReady}getSource(){return r.getProductsSource(this.source)}getSourceValue(){return r.getProductsSourceValue(this.source,this.sourceValue)}render(){var s;if(!this.canRender()){return}return t(i,{class:"s-products-slider-wrapper"},t("salla-slider",{class:"s-products-slider-slider",id:this.sliderId||`s-products-slider-${Math.random().toString(36).substr(2,9)}`,"auto-play":this.autoplay,type:"carousel","block-title":this.blockTitle,"block-subTitle":this.subTitle,"display-all-url":this.displayAllUrl,sliderConfig:this.sliderConfig?this.sliderConfig:null},t("div",{slot:"items"},(s=this.productsData)===null||s===void 0?void 0:s.map((s=>this.getItemHTML(s))))))}get host(){return e(this)}};l.style=d;export{l as salla_products_slider};
//# sourceMappingURL=p-3c2d05e3.entry.js.map