JezK
Edit File: sc-form-components-validator2.js.map
{"file":"sc-form-components-validator2.js","mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;mCAsL6B,UAAE;;;;oCAGD,UAAE;;;;;;;;;;;;;;;;;;;8BAoBN,UAAE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","names":[],"sources":["src/components/providers/form-components-validator/sc-form-components-validator.tsx"],"sourcesContent":["import { Component, Element, h, Prop, State, Watch } from '@stencil/core';\nimport { __ } from '@wordpress/i18n';\nimport { state as checkoutState, onChange as onCheckoutChange } from '@store/checkout';\nimport { TaxProtocol } from '../../../types';\nimport { fullShippingAddressRequired, shippingAddressRequired } from '@store/checkout/getters';\nimport { getAvailableProcessor } from '@store/processors/getters';\n\n@Component({\n tag: 'sc-form-components-validator',\n shadow: true,\n})\nexport class ScFormComponentsValidator {\n @Element() el: HTMLScFormComponentsValidatorElement;\n\n private removeCheckoutListener: () => void;\n private removePaymentRequiresShippingListener: () => void;\n\n /** Disable validation? */\n @Prop() disabled: boolean;\n\n /** The tax protocol */\n @Prop() taxProtocol: TaxProtocol;\n\n /** Is there an address field? */\n @State() hasAddress: boolean;\n\n /** Is there a tax id field? */\n @State() hasTaxIDField: boolean;\n\n /** Is there a bumps field? */\n @State() hasBumpsField: boolean;\n\n /** Is there a tax line? */\n @State() hasTaxLine: boolean;\n\n /** Is there a bump line? */\n @State() hasBumpLine: boolean;\n\n /** Is there shipping choices */\n @State() hasShippingChoices: boolean;\n\n /** Is there a shipping amount */\n @State() hasShippingAmount: boolean;\n\n /** Is there an invoice details */\n @State() hasInvoiceDetails: boolean;\n\n /** Is there an invoice memo */\n @State() hasInvoiceMemo: boolean;\n\n /** Is there a trial line item */\n @State() hasTrialLineItem: boolean;\n\n /** Is there a customer phone field? */\n @State() hasCustomerPhone: boolean;\n\n handleOrderChange() {\n // bail if we don't have address invalid error or disabled.\n if (this.disabled) return;\n\n // make sure to add the address field if it's not there.\n if (shippingAddressRequired()) {\n this.addAddressField();\n }\n\n // add order bumps.\n if (checkoutState.checkout?.recommended_bumps?.data?.length) {\n this.addBumps();\n }\n if (!!checkoutState.checkout?.tax_amount) {\n this.addTaxLine();\n }\n\n // add shipping choices.\n if (checkoutState.checkout?.shipping_enabled && checkoutState.checkout?.selected_shipping_choice_required) {\n this.addShippingChoices();\n }\n\n if (!!checkoutState.checkout?.shipping_amount) {\n this.addShippingAmount();\n }\n\n // automatically add invoice details if we have an invoice.\n if (!!checkoutState.checkout?.invoice) {\n this.addInvoiceDetails();\n this.addInvoiceMemo();\n }\n\n // automatically add trial line item if we have a trial amount.\n if (!!checkoutState.checkout?.trial_amount) {\n this.addTrialLineItem();\n }\n }\n\n @Watch('hasAddress')\n handleHasAddressChange() {\n if (!this.hasAddress) return;\n this.handleShippingAddressRequired();\n }\n\n componentWillLoad() {\n this.hasAddress = !!this.el.querySelector('sc-order-shipping-address');\n this.hasTaxIDField = !!this.el.querySelector('sc-order-tax-id-input');\n this.hasBumpsField = !!this.el.querySelector('sc-order-bumps');\n this.hasTaxLine = !!this.el.querySelector('sc-line-item-tax');\n this.hasShippingChoices = !!this.el.querySelector('sc-shipping-choices');\n this.hasShippingAmount = !!this.el.querySelector('sc-line-item-shipping');\n this.hasInvoiceDetails = !!this.el.querySelector('sc-invoice-details');\n this.hasInvoiceMemo = !!this.el.querySelector('sc-invoice-memo');\n this.hasTrialLineItem = !!this.el.querySelector('sc-line-item-trial');\n this.hasCustomerPhone = !!this.el.querySelector('sc-customer-phone');\n\n // if eu vat is required, add the tax id field.\n if (this.taxProtocol?.tax_enabled && this.taxProtocol?.eu_vat_required) {\n this.addTaxIDField();\n }\n\n // if razorpay is available, add the customer phone field.\n if (getAvailableProcessor('razorpay')) {\n this.addCustomerPhone();\n }\n\n this.handleOrderChange();\n\n this.removeCheckoutListener = onCheckoutChange('checkout', () => this.handleOrderChange());\n this.removePaymentRequiresShippingListener = onCheckoutChange('paymentMethodRequiresShipping', () => this.handleOrderChange());\n }\n\n disconnectedCallback() {\n this.removeCheckoutListener();\n this.removePaymentRequiresShippingListener();\n }\n\n handleShippingAddressRequired() {\n if (!checkoutState.checkout?.shipping_address_required) return;\n\n // get the address\n const address = this.el.querySelector('sc-order-shipping-address');\n if (!address) return;\n\n // require the address.\n address.required = true;\n\n // if we have a customer name field, require that.\n const customerName = this.el.querySelector('sc-customer-name');\n if (!!customerName) {\n customerName.required = true;\n return;\n }\n\n // if we have a customer first name field, require that.\n const customerFirstName = this.el.querySelector('sc-customer-firstname');\n const customerLastName = this.el.querySelector('sc-customer-lastname');\n\n // if we have a customer first name field, require that.\n if (!!customerFirstName) {\n customerFirstName.required = true;\n\n // if we have a customer last name field, require that.\n if (!!customerLastName) {\n customerLastName.required = true;\n }\n\n return; // we're done here.\n }\n\n // require the name and show the name input.\n address.requireName = true;\n address.showName = true;\n }\n\n addAddressField() {\n if (this.hasAddress) {\n return;\n }\n\n const payment = this.el.querySelector('sc-payment');\n const shippingAddress = document.createElement('sc-order-shipping-address');\n payment.parentNode.insertBefore(shippingAddress, payment);\n\n if (fullShippingAddressRequired()) {\n const billingAddress = document.createElement('sc-order-billing-address');\n billingAddress.label = __('Billing Address', 'surecart');\n payment.parentNode.insertBefore(billingAddress, payment);\n } else {\n shippingAddress.label = __('Address', 'surecart');\n }\n\n this.hasAddress = true;\n }\n\n addTaxIDField() {\n if (this.hasTaxIDField) return;\n const payment = this.el.querySelector('sc-payment');\n const taxInput = document.createElement('sc-order-tax-id-input');\n payment.parentNode.insertBefore(taxInput, payment);\n this.hasTaxIDField = true;\n }\n\n addCustomerPhone() {\n if (this.hasCustomerPhone) return;\n const payment = this.el.querySelector('sc-payment');\n if (!payment) return;\n\n const customerPhone = document.createElement('sc-customer-phone');\n customerPhone.label = __('Phone', 'surecart');\n customerPhone.required = true;\n payment.parentNode.insertBefore(customerPhone, payment);\n this.hasCustomerPhone = true;\n }\n\n addBumps() {\n if (this.hasBumpsField) return;\n const attachReferenceElement = this.el.querySelector('sc-order-billing-address') || this.el.querySelector('sc-payment');\n const bumps = document.createElement('sc-order-bumps');\n attachReferenceElement?.parentNode.insertBefore(bumps, attachReferenceElement.nextSibling);\n this.hasBumpsField = true;\n }\n\n addTaxLine() {\n if (this.hasTaxLine) return;\n const total = this.el.querySelector('sc-line-item-total[total=total]');\n const tax = document.createElement('sc-line-item-tax');\n\n if (!total) return;\n\n if (total?.previousElementSibling?.tagName === 'SC-DIVIDER') {\n total.parentNode.insertBefore(tax, total.previousElementSibling);\n } else {\n total.parentNode.insertBefore(tax, total);\n }\n this.hasTaxLine = true;\n }\n\n addShippingChoices() {\n if (this.hasShippingChoices) return;\n\n const payment = this.el.querySelector('sc-payment');\n const shippingChoices = document.createElement('sc-shipping-choices');\n payment.parentNode.insertBefore(shippingChoices, payment);\n this.hasShippingChoices = true;\n }\n\n addShippingAmount() {\n if (this.hasShippingAmount) return;\n\n let insertBeforeElement: Element = this.el.querySelector('sc-line-item-tax');\n const total = this.el.querySelector('sc-line-item-total[total=total]');\n\n if (!total) return;\n\n if (!insertBeforeElement) {\n insertBeforeElement = total?.previousElementSibling?.tagName === 'SC-DIVIDER' ? total.previousElementSibling : total;\n }\n\n const shippingAmount = document.createElement('sc-line-item-shipping');\n insertBeforeElement.parentNode.insertBefore(shippingAmount, insertBeforeElement);\n this.hasShippingAmount = true;\n }\n\n addInvoiceDetails() {\n if (this.hasInvoiceDetails) return;\n\n let lineItems: Element = this.el.querySelector('sc-line-items');\n const invoiceDetails = document.createElement('sc-invoice-details');\n lineItems.parentNode.insertBefore(invoiceDetails, lineItems);\n\n // Add sc-line-item-invoice-number inside sc-invoice-details.\n const invoiceNumber = document.createElement('sc-line-item-invoice-number');\n invoiceDetails.appendChild(invoiceNumber);\n\n // Add sc-line-item-invoice-due-date inside sc-invoice-details.\n const invoiceDueDate = document.createElement('sc-line-item-invoice-due-date');\n invoiceDetails.appendChild(invoiceDueDate);\n\n // Add invoice sc-line-item-invoice-receipt-download inside sc-invoice-details.\n const invoiceReceiptDownload = document.createElement('sc-line-item-invoice-receipt-download');\n invoiceDetails.appendChild(invoiceReceiptDownload);\n\n // Add sc-divider inside sc-invoice-details.\n const divider = document.createElement('sc-divider');\n invoiceDetails.appendChild(divider);\n\n this.hasInvoiceDetails = true;\n }\n\n addInvoiceMemo() {\n if (this.hasInvoiceMemo) return;\n\n const orderSummary = this.el.querySelector('sc-order-summary');\n\n const invoiceDetails = document.createElement('sc-invoice-details');\n\n // Add sc-divider inside sc-invoice-details.\n orderSummary.parentNode.insertBefore(invoiceDetails, orderSummary.nextSibling);\n\n // Add sc-invoice-memo inside sc-invoice-details.\n const invoiceMemo = document.createElement('sc-invoice-memo');\n invoiceDetails.appendChild(invoiceMemo);\n\n this.hasInvoiceMemo = true;\n }\n\n addTrialLineItem() {\n if (this.hasTrialLineItem) return;\n\n const subtotal = this.el.querySelector('sc-line-item-total[total=subtotal]');\n const trialItem = document.createElement('sc-line-item-trial');\n\n if (!subtotal) return;\n\n // Insert the trial item before the coupon form.\n subtotal.parentNode.insertBefore(trialItem, subtotal.nextSibling);\n\n this.hasTrialLineItem = true;\n }\n\n render() {\n return <slot />;\n }\n}\n"],"version":3}