FileMaster
Search
Toggle Dark Mode
Home
/
.
/
wp-content
/
plugins
/
surecart
/
dist
/
components
/
components
Edit File: sc-order-billing-address2.js
import{proxyCustomElement,HTMLElement,h,Fragment}from"@stencil/core/internal/client";import{s as state,o as onChange}from"./mutations2.js";import{a as formLoading}from"./getters3.js";import{l as lockCheckout,b as unLockCheckout}from"./mutations4.js";import{d as createOrUpdateCheckout}from"./index4.js";import{d as defineCustomElement$d}from"./sc-address2.js";import{d as defineCustomElement$c}from"./sc-block-ui2.js";import{d as defineCustomElement$b}from"./sc-checkbox2.js";import{d as defineCustomElement$a}from"./dropdown.js";import{d as defineCustomElement$9}from"./sc-form-control2.js";import{d as defineCustomElement$8}from"./sc-icon2.js";import{d as defineCustomElement$7}from"./sc-input2.js";import{d as defineCustomElement$6}from"./sc-menu2.js";import{d as defineCustomElement$5}from"./sc-menu-item2.js";import{d as defineCustomElement$4}from"./sc-menu-label2.js";import{d as defineCustomElement$3}from"./sc-select2.js";import{d as defineCustomElement$2}from"./sc-spinner2.js";import{d as defineCustomElement$1}from"./sc-visually-hidden2.js";const scOrderBillingAddressCss=":host{display:block}.order-billing-address__toggle{margin-bottom:var(--sc-form-row-spacing, var(--sc-spacing-medium))}",ScOrderBillingAddressStyle0=scOrderBillingAddressCss,ScOrderBillingAddress=proxyCustomElement(class extends HTMLElement{constructor(){super(),this.__registerHost(),this.__attachShadow(),this.label=void 0,this.showName=void 0,this.namePlaceholder=wp.i18n.__("Name or Company Name","surecart"),this.defaultCountry=void 0,this.toggleLabel=wp.i18n.__("Billing address is same as shipping","surecart"),this.address={country:null,city:null,line_1:null,line_2:null,postal_code:null,state:null}}async reportValidity(){var e,s;return!this.input||(null===(s=null===(e=this.input)||void 0===e?void 0:e.reportValidity)||void 0===s?void 0:s.call(e))}prefillAddress(){var e;const s=Object.keys(this.address).filter((e=>"country"!==e));s.filter((e=>!this.address[e])).length===s.length&&(this.address={...this.address,...null===(e=state.checkout)||void 0===e?void 0:e.billing_address})}componentWillLoad(){var e;this.defaultCountry&&!(null===(e=this.address)||void 0===e?void 0:e.country)&&(this.address.country=this.defaultCountry),this.prefillAddress(),onChange("checkout",(()=>this.prefillAddress()))}async updateAddressState(e){var s,t;if(JSON.stringify(e)!==JSON.stringify(this.address)){this.address=e;try{lockCheckout("billing-address"),state.checkout=await createOrUpdateCheckout({id:null===(s=null==state?void 0:state.checkout)||void 0===s?void 0:s.id,data:{billing_matches_shipping:null===(t=state.checkout)||void 0===t?void 0:t.billing_matches_shipping,billing_address:this.address}})}catch(e){console.error(e)}finally{unLockCheckout("billing-address")}}}async onToggleBillingMatchesShipping(e){state.checkout={...state.checkout,billing_matches_shipping:e.target.checked}}shippingAddressFieldExists(){return!!document.querySelector("sc-order-shipping-address")}render(){var e,s;return h(Fragment,{key:"ac025fb50a179d589c2c96561305b92164fe7e51"},this.shippingAddressFieldExists()&&h("sc-checkbox",{key:"5bd206c5d00aebb934f2361c85bff8f3c8751884",class:"order-billing-address__toggle",onScChange:e=>this.onToggleBillingMatchesShipping(e),checked:null===(e=state.checkout)||void 0===e?void 0:e.billing_matches_shipping},this.toggleLabel),(!this.shippingAddressFieldExists()||!(null===(s=state.checkout)||void 0===s?void 0:s.billing_matches_shipping))&&h("sc-address",{key:"857afdf76f5eba6febf77f7fe9453edc4b7146f7",exportparts:"label, help-text, form-control, input__base, select__base, columns, search__base, menu__base",ref:e=>{this.input=e},label:this.label||wp.i18n.__("Billing Address","surecart"),names:{name:"billing_name",country:"billing_country",city:"billing_city",line_1:"billing_line_1",line_2:"billing_line_2",postal_code:"billing_postal_code",state:"billing_state"},required:!0,loading:formLoading(),address:this.address,"show-name":this.showName,onScChangeAddress:e=>this.updateAddressState(e.detail)}))}static get style(){return ScOrderBillingAddressStyle0}},[1,"sc-order-billing-address",{label:[1],showName:[516,"show-name"],namePlaceholder:[1,"name-placeholder"],defaultCountry:[1,"default-country"],toggleLabel:[1,"toggle-label"],address:[32],reportValidity:[64]}]);function defineCustomElement(){"undefined"!=typeof customElements&&["sc-order-billing-address","sc-address","sc-block-ui","sc-checkbox","sc-dropdown","sc-form-control","sc-icon","sc-input","sc-menu","sc-menu-item","sc-menu-label","sc-select","sc-spinner","sc-visually-hidden"].forEach((e=>{switch(e){case"sc-order-billing-address":customElements.get(e)||customElements.define(e,ScOrderBillingAddress);break;case"sc-address":customElements.get(e)||defineCustomElement$d();break;case"sc-block-ui":customElements.get(e)||defineCustomElement$c();break;case"sc-checkbox":customElements.get(e)||defineCustomElement$b();break;case"sc-dropdown":customElements.get(e)||defineCustomElement$a();break;case"sc-form-control":customElements.get(e)||defineCustomElement$9();break;case"sc-icon":customElements.get(e)||defineCustomElement$8();break;case"sc-input":customElements.get(e)||defineCustomElement$7();break;case"sc-menu":customElements.get(e)||defineCustomElement$6();break;case"sc-menu-item":customElements.get(e)||defineCustomElement$5();break;case"sc-menu-label":customElements.get(e)||defineCustomElement$4();break;case"sc-select":customElements.get(e)||defineCustomElement$3();break;case"sc-spinner":customElements.get(e)||defineCustomElement$2();break;case"sc-visually-hidden":customElements.get(e)||defineCustomElement$1()}}))}export{ScOrderBillingAddress as S,defineCustomElement as d};
Save
Back