JezK
Edit File: sc-custom-order-price-input.entry.js.map
{"file":"sc-custom-order-price-input.entry.js","mappings":";;;;;;;AAAA,MAAM,0BAA0B,GAAG,4CAA4C,CAAC;AAChF,sCAAe,0BAA0B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;4FC0F9B,UAAE;;;;;;;;;;;;;;;;;;AAwCb;;;;;","names":[],"sources":["src/components/controllers/checkout-form/custom-order-price-input/sc-custom-order-price-input.css?tag=sc-custom-order-price-input","src/components/controllers/checkout-form/custom-order-price-input/sc-custom-order-price-input.tsx"],"sourcesContent":["sc-custom-order-price-input {\n display: block;\n}\n","import { Component, Event, EventEmitter, h, Host, Listen, Prop, State, Watch } from '@stencil/core';\nimport { LineItem, LineItemData, Price } from '../../../../types';\nimport apiFetch from '../../../../functions/fetch';\nimport { openWormhole } from 'stencil-wormhole';\nimport { __ } from '@wordpress/i18n';\n\n@Component({\n tag: 'sc-custom-order-price-input',\n styleUrl: 'sc-custom-order-price-input.css',\n shadow: false,\n})\nexport class ScCustomOrderPriceInput {\n /** Id of the price. */\n @Prop({ reflect: true }) priceId: string;\n\n /** Stores the price */\n @Prop({ mutable: true }) price: Price;\n\n /** Is this loading */\n @Prop() loading: boolean = false;\n\n /** Is this busy */\n @Prop() busy: boolean = false;\n\n /** Label for the field. */\n @Prop() label: string;\n\n /** Input placeholder. */\n @Prop() placeholder: string;\n\n /** Is this required? */\n @Prop() required: boolean;\n\n /** Help text. */\n @Prop() help: string;\n\n /** Show the currency code? */\n @Prop({ reflect: true }) showCode: boolean;\n\n /** Label for the choice. */\n @Prop() lineItems: LineItem[] = [];\n\n /** Internal fetching state. */\n @State() fetching: boolean = false;\n\n /** Holds the line item for this component. */\n @State() lineItem: LineItem;\n\n /** Toggle line item event */\n @Event() scUpdateLineItem: EventEmitter<LineItemData>;\n\n @Listen('scBlur')\n handleBlur(e) {\n const ad_hoc_amount = parseInt(e.target.value);\n if (isNaN(ad_hoc_amount)) return;\n if (this.lineItem?.ad_hoc_amount === ad_hoc_amount) return;\n\n this.scUpdateLineItem.emit({ price_id: this.priceId, quantity: 1, ad_hoc_amount });\n }\n\n /** Store current line item in state. */\n @Watch('lineItems')\n handleLineItemsChange() {\n if (!this.lineItems?.length) return;\n this.lineItem = (this.lineItems || []).find(lineItem => lineItem.price.id === this.priceId);\n }\n\n componentDidLoad() {\n if (!this.price) {\n this.fetchPrice();\n }\n }\n\n /** Fetch prices and products */\n async fetchPrice() {\n if (!this.priceId) return;\n try {\n this.fetching = true;\n this.price = (await apiFetch({\n path: `surecart/v1/prices/${this.priceId}`,\n })) as Price;\n } catch (err) {\n } finally {\n this.fetching = false;\n }\n }\n\n renderEmpty() {\n if (window?.wp?.blocks) {\n return (\n <sc-alert type=\"danger\" open style={{ margin: '0px' }}>\n {__('This price has been archived.', 'surecart')}\n </sc-alert>\n );\n }\n return <Host style={{ display: 'none' }}></Host>;\n }\n\n render() {\n if (this.loading || this.fetching) {\n return (\n <div>\n <sc-skeleton style={{ width: '20%', marginBottom: '0.75em' }}></sc-skeleton>\n <sc-skeleton style={{ width: '100%' }}></sc-skeleton>\n </div>\n );\n }\n\n // Price needs to be active.\n if (!this?.price?.id || this.price?.archived) return this.renderEmpty();\n\n return (\n <div class=\"sc-custom-order-price-input\">\n <sc-price-input\n currency-code={this.price?.currency || 'usd'}\n label={this.label}\n min={this?.price?.ad_hoc_min_amount}\n max={this?.price?.ad_hoc_max_amount}\n placeholder={this.placeholder}\n required={this.required}\n value={this.lineItem?.ad_hoc_amount.toString()}\n show-code={this.showCode}\n help={this.help}\n ></sc-price-input>\n\n {this.busy && <sc-block-ui style={{ zIndex: '9' }}></sc-block-ui>}\n </div>\n );\n }\n}\n\nopenWormhole(ScCustomOrderPriceInput, ['busy', 'lineItems'], false);\n"],"version":3}