UNPKG

@salla.sa/twilight-components

Version:
4 lines 2.31 kB
/*! * Crafted with ❤ by Salla */ import{r as t,h as a,H as i,a as s}from"./p-BHYtfMwX.js";const e=class{constructor(a){t(this,a),this.loading=!1,this.hasError=!1,this.productData=null}async componentWillLoad(){await salla.onReady(),await this.fetchProduct()}componentDidLoad(){this.ensureParentContainsFloats()}componentDidRender(){this.renderCardNode()}ensureParentContainsFloats(){if("left"!==this.align&&"right"!==this.align)return;const t=this.hostEl?.parentElement;if(!t)return;const a=getComputedStyle(t);"block"===a.display&&"visible"===a.overflow&&"none"===a.float&&(t.style.display="flow-root")}fetchProduct(){return this.productId?(this.loading=!0,this.hasError=!1,salla.api.withoutNotifier((()=>salla.product.api.getDetails(this.productId))).then((t=>{const a=t.data;this.productData=a??null,this.hasError=!a})).catch((()=>{this.productData=null,this.hasError=!0})).finally((()=>{this.loading=!1}))):(this.productData=null,this.loading=!1,void(this.hasError=!1))}renderCardNode(){if(!this.cardContainer)return;if(this.cardContainer.textContent="",!this.productData||this.loading||this.hasError)return;const t=window.customElements.get("custom-salla-product-card")?"custom-salla-product-card":"salla-product-card",a=document.createElement(t);a.product=this.productData,this.cardContainer.appendChild(a)}render(){const t={"s-product-card-embed-card":!0,"s-product-card-embed-card-align-left":"left"===this.align,"s-product-card-embed-card-align-right":"right"===this.align,"s-product-card-embed-card-align-center":"center"===this.align};return a(i,{key:"4fcd0b6e5da26ac976b0f3c5c031b614dc9d04b1"},this.hasError&&a("span",{key:"55b4a2649d4912b61f6b75e3c2437bfaee7863e0",class:"s-product-card-embed-fallback"}),a("div",{key:"ac5882e5dd36ac28cc6e5a24186156c7cadda820",class:t,ref:t=>{this.cardContainer=t}}))}get hostEl(){return s(this)}};e.style='@charset "UTF-8";:host{display:inline-block;vertical-align:top;max-width:12rem}:host([align=left]){float:inline-start;margin-block-end:1em;margin-inline-end:1em;shape-outside:margin-box}:host([align=right]){float:inline-end;margin-block-end:1em;margin-inline-start:1em;shape-outside:margin-box}:host([align=center]){display:block;clear:both;margin-block:1em;margin-inline:auto}.s-product-card-embed-card{display:block}';export{e as salla_product_card_embed}