UNPKG

@salla.sa/twilight-components

Version:
5 lines 4.05 kB
/*! * Crafted with ❤ by Salla */ System.register(["./p-f422bbf9.system.js","./p-8c9d72f2.system.js","./p-8f7b9e36.system.js"],(function(e){"use strict";var t,r,s,u,i;return{setters:[function(e){t=e.r;r=e.h;s=e.H;u=e.g},function(e){i=e.H},function(){}],execute:function(){var o="";var n=e("salla_products_slider",function(){function e(e){t(this,e);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}e.prototype.componentWillLoad=function(){var e=this;return salla.onReady().then((function(){e.includes=i.parseJson(e.includes||e.host.getAttribute("includes"));if(!Array.isArray(e.includes)){e.includes=null}i.setIncludes(e.includes);e.sourceValueIsValid=!!(e.getSourceValue()||e.isSourceWithoutValue());if(!e.sourceValueIsValid){salla.logger.warn("source-value prop is required for source [".concat(e.getSource(),"]"));return}e.hasCustomComponent=!!customElements.get(e.productCardComponent);if(e.source==="json"){e.productsData=e.getSourceValue();e.isReady=true;return}if(e.getSource()=="related"&&!salla.config.get("store.settings.product.related_products_enabled")){e.isReady=false;return}return salla.product.api.fetch({source:e.getSource(),source_value:e.getSourceValue(),limit:e.limit}).then((function(e){return i.injectExtraFieldsToResponse(e)})).then((function(t){e.productsData=t.data;e.isReady=true;salla.event.emit("salla-products-slider::products.fetched",t.data)}))}))};e.prototype.componentDidRender=function(){var e=this;var t=0;var r=setInterval((function(){var s;(s=e.host.querySelectorAll('[loading="lazy"]'))===null||s===void 0?void 0:s.forEach((function(e){return e.removeAttribute("loading")}));t++;if(t>=10){clearInterval(r)}}),1e3)};e.prototype.isSourceWithoutValue=function(){return["offers","latest","sales","top-rated"].includes(this.getSource())};e.prototype.getItemHTML=function(e){this.getSource()==="landing-page"&&(e.url="");if(this.hasCustomComponent&&this.productCardComponent.toLowerCase()=="custom-salla-product-card"){return r("div",{class:"s-products-slider-card"},r("custom-salla-product-card",{product:e,source:this.getSource(),"source-value":this.getSourceValue()}))}if(this.hasCustomComponent){var t=document.createElement(this.productCardComponent);t.setAttribute("product",JSON.stringify(e));t.setAttribute("source",this.getSource());t.setAttribute("source-value",this.getSourceValue());return r("div",{class:"s-products-slider-card",innerHTML:t.outerHTML})}return r("div",{class:"s-products-slider-card"},r("salla-product-card",{"show-quantity":this.getSource()=="landing-page","hide-add-btn":this.getSource()=="landing-page","shadow-on-hover":true,product:e}))};e.prototype.canRender=function(){return this.sourceValueIsValid&&this.isReady};e.prototype.getSource=function(){return i.getProductsSource(this.source)};e.prototype.getSourceValue=function(){return i.getProductsSourceValue(this.source,this.sourceValue)};e.prototype.render=function(){var e=this;var t;if(!this.canRender()){return}return r(s,{class:"s-products-slider-wrapper"},r("salla-slider",{class:"s-products-slider-slider",id:this.sliderId||"s-products-slider-".concat(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},r("div",{slot:"items"},(t=this.productsData)===null||t===void 0?void 0:t.map((function(t){return e.getItemHTML(t)})))))};Object.defineProperty(e.prototype,"host",{get:function(){return u(this)},enumerable:false,configurable:true});return e}());n.style=o}}})); //# sourceMappingURL=p-70f8669e.system.entry.js.map