FileMaster
Search
Toggle Dark Mode
Home
/
.
/
wp-content
/
plugins
/
surecart
/
dist
/
components
/
components
Edit File: sc-product-selected-price.js
import{proxyCustomElement,HTMLElement,createEvent,h,Host,Fragment}from"@stencil/core/internal/client";import{i as intervalString}from"./price.js";import{g as getLineItemByProductId}from"./getters2.js";import{f as formBusy}from"./getters3.js";import{o as onChange}from"./mutations2.js";import{d as defineCustomElement$9}from"./sc-button2.js";import{d as defineCustomElement$8}from"./sc-form2.js";import{d as defineCustomElement$7}from"./sc-form-control2.js";import{d as defineCustomElement$6}from"./sc-icon2.js";import{d as defineCustomElement$5}from"./sc-input2.js";import{d as defineCustomElement$4}from"./sc-price-input2.js";import{d as defineCustomElement$3}from"./sc-spinner2.js";import{d as defineCustomElement$2}from"./sc-visually-hidden2.js";const scProductSelectedPriceCss=":host{display:block}sc-form{width:100%}.selected-price{display:flex;align-items:center;gap:var(--sc-spacing-small);flex-wrap:wrap}.selected-price__wrap{display:flex;align-items:baseline;flex-wrap:wrap;gap:var(--sc-spacing-xx-small);color:var(--sc-selected-price-color, var(--sc-color-gray-800));line-height:1}.selected-price__price{font-size:var(--sc-font-size-xxx-large);font-weight:var(--sc-font-weight-bold);white-space:nowrap}.selected-price__interval{font-weight:var(--sc-font-weight-bold);opacity:0.65;white-space:nowrap}.selected-price__scratch-price{opacity:0.65;font-weight:var(--sc-font-weight-normal);text-decoration:line-through}",ScProductSelectedPriceStyle0=scProductSelectedPriceCss,ScProductSelectedPrice$1=proxyCustomElement(class extends HTMLElement{constructor(){super(),this.__registerHost(),this.__attachShadow(),this.scUpdateLineItem=createEvent(this,"scUpdateLineItem",7),this.productId=void 0,this.showInput=void 0,this.adHocAmount=void 0}lineItem(){return getLineItemByProductId(this.productId)}componentWillLoad(){onChange("checkout",(()=>{var e,t,i;this.adHocAmount=(null===(e=this.lineItem())||void 0===e?void 0:e.ad_hoc_amount)||(null===(i=null===(t=this.lineItem())||void 0===t?void 0:t.price)||void 0===i?void 0:i.amount)}))}updatePrice(){var e,t,i;this.showInput=!1,(this.adHocAmount||0===this.adHocAmount)&&this.adHocAmount!==(null===(e=this.lineItem())||void 0===e?void 0:e.ad_hoc_amount)&&this.scUpdateLineItem.emit({price_id:null===(i=null===(t=this.lineItem())||void 0===t?void 0:t.price)||void 0===i?void 0:i.id,quantity:1,ad_hoc_amount:this.adHocAmount})}handleShowInputChange(e){e&&setTimeout((()=>{this.input.triggerFocus()}),50)}onSubmit(e){e.preventDefault(),e.stopImmediatePropagation(),this.updatePrice()}render(){var e,t,i,s,o,n;const c=null===(e=this.lineItem())||void 0===e?void 0:e.price,r=null===(t=this.lineItem())||void 0===t?void 0:t.variant;return c?h("div",{class:{"selected-price":!0}},this.showInput?h("sc-form",{onScSubmit:e=>this.onSubmit(e),onScFormSubmit:e=>{e.preventDefault(),e.stopImmediatePropagation()}},h("sc-price-input",{ref:e=>this.input=e,size:"large","currency-code":(null==c?void 0:c.currency)||"usd",min:null==c?void 0:c.ad_hoc_min_amount,max:null==c?void 0:c.ad_hoc_max_amount,placeholder:"0.00",required:!0,value:null===(s=null===(i=this.adHocAmount)||void 0===i?void 0:i.toString)||void 0===s?void 0:s.call(i),onScInput:e=>this.adHocAmount=parseFloat(e.target.value),onKeyDown:e=>{"Enter"===e.key&&this.onSubmit(e)}},h("sc-button",{slot:"suffix",type:"link",submit:!0},wp.i18n.__("Update","surecart")))):h(Fragment,null,h("div",{class:"selected-price__wrap"},h("span",{class:"selected-price__price","aria-label":wp.i18n.__("Product price","surecart")},(null==c?void 0:c.scratch_amount)>c.amount&&h(Fragment,null,h("span",{class:"selected-price__scratch-price",part:"price__scratch"},null==c?void 0:c.scratch_display_amount," ")),null!==(null===(o=this.lineItem())||void 0===o?void 0:o.ad_hoc_amount)?null===(n=this.lineItem())||void 0===n?void 0:n.ad_hoc_display_amount:(null==r?void 0:r.display_amount)||(null==c?void 0:c.display_amount)),h("span",{class:"selected-price__interval","aria-label":wp.i18n.__("Price interval","surecart")},intervalString(c,{labels:{interval:"/",period: /** translators: used as in time period: "for 3 months" */ wp.i18n.__("for","surecart")}}))),(null==c?void 0:c.ad_hoc)&&!formBusy()&&h("sc-button",{class:"selected-price__change-amount",type:"primary",size:"small",onClick:()=>this.showInput=!0},h("sc-icon",{name:"edit",slot:"prefix"}),wp.i18n.__("Change Amount","surecart")))):h(Host,{style:{display:"none"}})}static get watchers(){return{showInput:["handleShowInputChange"]}}static get style(){return ScProductSelectedPriceStyle0}},[1,"sc-product-selected-price",{productId:[1,"product-id"],showInput:[32],adHocAmount:[32]},void 0,{showInput:["handleShowInputChange"]}]);function defineCustomElement$1(){"undefined"!=typeof customElements&&["sc-product-selected-price","sc-button","sc-form","sc-form-control","sc-icon","sc-input","sc-price-input","sc-spinner","sc-visually-hidden"].forEach((e=>{switch(e){case"sc-product-selected-price":customElements.get(e)||customElements.define(e,ScProductSelectedPrice$1);break;case"sc-button":customElements.get(e)||defineCustomElement$9();break;case"sc-form":customElements.get(e)||defineCustomElement$8();break;case"sc-form-control":customElements.get(e)||defineCustomElement$7();break;case"sc-icon":customElements.get(e)||defineCustomElement$6();break;case"sc-input":customElements.get(e)||defineCustomElement$5();break;case"sc-price-input":customElements.get(e)||defineCustomElement$4();break;case"sc-spinner":customElements.get(e)||defineCustomElement$3();break;case"sc-visually-hidden":customElements.get(e)||defineCustomElement$2()}}))}const ScProductSelectedPrice=ScProductSelectedPrice$1,defineCustomElement=defineCustomElement$1;export{ScProductSelectedPrice,defineCustomElement};
Save
Back