JezK
Edit File: sc-order-billing-address2.js.map
{"file":"sc-order-billing-address2.js","mappings":";;;;;;;;;;;;;;;;;;;;;;AAAA,MAAM,wBAAwB,GAAG,wHAAwH,CAAC;AAC1J,oCAAe,wBAAwB;;;;;;;;;+BCyBH,UAAE;;2BAMN,UAAE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;oCAiFD,UAAE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","names":[],"sources":["src/components/controllers/checkout-form/sc-order-billing-address/sc-order-billing-address.scss?tag=sc-order-billing-address&encapsulation=shadow","src/components/controllers/checkout-form/sc-order-billing-address/sc-order-billing-address.tsx"],"sourcesContent":[":host {\n display: block;\n}\n\n.order-billing-address {\n &__toggle {\n margin-bottom: var(--sc-form-row-spacing, var(--sc-spacing-medium));\n }\n}\n","import { Component, Fragment, h, Method, Prop, State } from '@stencil/core';\nimport { __ } from '@wordpress/i18n';\nimport { Address, Checkout } from '../../../../types';\nimport { state as checkoutState, onChange } from '@store/checkout';\nimport { formLoading } from '@store/form/getters';\nimport { lockCheckout, unLockCheckout } from '@store/checkout/mutations';\nimport { createOrUpdateCheckout } from '@services/session';\nimport { ScCheckboxCustomEvent } from 'src/components';\nimport { isAddressEmpty } from '../../../../services/customer-address';\n\n@Component({\n tag: 'sc-order-billing-address',\n styleUrl: 'sc-order-billing-address.scss',\n shadow: true,\n})\nexport class ScOrderBillingAddress {\n /** The input */\n private input: HTMLScAddressElement | HTMLScCompactAddressElement;\n\n /** Label for the field */\n @Prop() label: string;\n\n /** Show the name field */\n @Prop({ reflect: true }) showName: boolean;\n\n /** Name placeholder */\n @Prop() namePlaceholder: string = __('Name or Company Name', 'surecart');\n\n /** Default country for address */\n @Prop() defaultCountry: string;\n\n /** Toggle label */\n @Prop() toggleLabel: string = __('Billing address is same as shipping', 'surecart');\n\n /** Address to pass to the component */\n @State() address: Partial<Address> = {\n country: null,\n city: null,\n line_1: null,\n line_2: null,\n postal_code: null,\n state: null,\n };\n\n @Method()\n async reportValidity() {\n if (!this.input) return true;\n return this.input?.reportValidity?.();\n }\n\n prefillAddress() {\n // Autofill is handled by sc-checkout-autofill-provider which patches checkoutState.checkout with any logged-in customer profile data.\n if (isAddressEmpty(this.address)) {\n this.address = { ...this.address, ...(checkoutState.checkout?.billing_address as Address) };\n }\n }\n\n componentWillLoad() {\n if (this.defaultCountry && !this.address?.country) {\n this.address.country = this.defaultCountry;\n }\n\n this.prefillAddress();\n onChange('checkout', () => this.prefillAddress());\n }\n\n async updateAddressState(address: Partial<Address>) {\n if (JSON.stringify(address) === JSON.stringify(this.address)) return; // no change, don't update.\n this.address = address;\n try {\n lockCheckout('billing-address');\n checkoutState.checkout = (await createOrUpdateCheckout({\n id: checkoutState?.checkout?.id,\n data: {\n billing_matches_shipping: checkoutState.checkout?.billing_matches_shipping,\n billing_address: this.address as Address,\n },\n })) as Checkout;\n } catch (e) {\n console.error(e);\n } finally {\n unLockCheckout('billing-address');\n }\n }\n\n async onToggleBillingMatchesShipping(e: ScCheckboxCustomEvent<void>) {\n checkoutState.checkout = {\n ...checkoutState.checkout,\n billing_matches_shipping: e.target.checked,\n };\n }\n\n shippingAddressFieldExists() {\n return !!document.querySelector('sc-order-shipping-address');\n }\n\n render() {\n return (\n <Fragment>\n {/* Only display this toggle if there is a shipping address. */}\n {this.shippingAddressFieldExists() && (\n <sc-checkbox class=\"order-billing-address__toggle\" onScChange={e => this.onToggleBillingMatchesShipping(e)} checked={checkoutState.checkout?.billing_matches_shipping}>\n {this.toggleLabel}\n </sc-checkbox>\n )}\n\n {/* If the shipping address field does not exist, always display this field. */}\n {(!this.shippingAddressFieldExists() || !checkoutState.checkout?.billing_matches_shipping) && (\n <sc-address\n exportparts=\"label, help-text, form-control, input__base, select__base, columns, search__base, menu__base\"\n ref={el => {\n this.input = el;\n }}\n label={this.label || __('Billing Address', 'surecart')}\n names={{\n name: 'billing_name',\n country: 'billing_country',\n city: 'billing_city',\n line_1: 'billing_line_1',\n line_2: 'billing_line_2',\n postal_code: 'billing_postal_code',\n state: 'billing_state',\n }}\n required={true}\n loading={formLoading()}\n address={this.address}\n show-name={this.showName}\n onScChangeAddress={e => this.updateAddressState(e.detail)}\n />\n )}\n </Fragment>\n );\n }\n}\n"],"version":3}