1import{Component}from"@theme/component";import{fetchConfig,debounce,onAnimationEnd,prefersReducedMotion,resetShimmer,startViewTransition}from"@theme/utilities";import{morphSection,sectionRenderer}from"@theme/section-renderer";import{ThemeEvents,CartUpdateEvent,DiscountUpdateEvent}from"@theme/events";import{cartPerformance}from"@theme/performance";class CartItemsComponent extends Component{#debouncedOnChange=debounce(this.#onQuantityChange,300).bind(this);connectedCallback(){super.connectedCallback(),document.addEventListener(ThemeEvents.cartUpdate,this.#handleCartUpdate),document.addEventListener(ThemeEvents.discountUpdate,this.handleDiscountUpdate),document.addEventListener(ThemeEvents.quantitySelectorUpdate,this.#debouncedOnChange)}disconnectedCallback(){super.disconnectedCallback(),document.removeEventListener(ThemeEvents.cartUpdate,this.#handleCartUpdate),document.removeEventListener(ThemeEvents.discountUpdate,this.handleDiscountUpdate),document.removeEventListener(ThemeEvents.quantitySelectorUpdate,this.#debouncedOnChange)}#onQuantityChange(event){if(!(event.target instanceof Node)||!this.contains(event.target))return;const{quantity,cartLine:line}=event.detail;if(!line)return;if(quantity===0)return this.onLineItemRemove(line);this.updateQuantity({line,quantity,action:"change"});const lineItemRow=this.refs.cartItemRows[line-1];if(!lineItemRow)return;lineItemRow.querySelector("text-component")?.shimmer()}onLineItemRemove(line){this.updateQuantity({line,quantity:0,action:"clear"});const cartItemRowToRemove=this.refs.cartItemRows[line-1];if(!cartItemRowToRemove)return;const rowsToRemove=[cartItemRowToRemove,...this.refs.cartItemRows.filter(row=>row.dataset.parentKey===cartItemRowToRemove.dataset.key)],isEmptyCart=rowsToRemove.length==this.refs.cartItemRows.length,template=document.getElementById("empty-cart-template");if(isEmptyCart&&template instanceof HTMLTemplateElement){const clone=document.importNode(template.content,!0);startViewTransition(()=>{this.replaceChildren(clone)},[this.isDrawer?"empty-cart-drawer":"empty-cart-page"]);return}rowsToRemove.forEach(row=>{const remove=()=>row.remove();if(prefersReducedMotion())return remove();row.style.setProperty("--row-height",`${row.clientHeight}px`),row.classList.add("removing"),onAnimationEnd(row,remove)})}updateQuantity(config){const cartPerformaceUpdateMarker=cartPerformance.createStartingMarker(`${config.action}:user-action`);this.#disableCartItems();const{line,quantity}=config,{cartTotal}=this.refs,cartItemsComponents=document.querySelectorAll("cart-items-component"),sectionsToUpdate=new Set([this.sectionId]);cartItemsComponents.forEach(item=>{item instanceof HTMLElement&&item.dataset.sectionId&§ionsToUpdate.add(item.dataset.sectionId)});const body=JSON.stringify({line,quantity,sections:Array.from(sectionsToUpdate).join(","),sections_url:window.location.pathname});cartTotal?.shimmer(),fetch(`${Theme.routes.cart_change_url}`,fetchConfig("json",{body})).then(response=>response.text()).then(responseText=>{const parsedResponseText=JSON.parse(responseText);if(resetShimmer(this),parsedResponseText.errors){this.#handleCartError(line,parsedResponseText);return}const newCartHiddenItemCount=new DOMParser().parseFromString(parsedResponseText.sections[this.sectionId],"text/html").querySelector('[ref="cartItemCount"]')?.textContent,newCartItemCount=newCartHiddenItemCount?parseInt(newCartHiddenItemCount,10):0;this.#updateQuantitySelectors(parsedResponseText),this.dispatchEvent(new CartUpdateEvent(parsedResponseText,this.sectionId,{itemCount:newCartItemCount,source:"cart-items-component",sections:parsedResponseText.sections})),morphSection(this.sectionId,parsedResponseText.sections[this.sectionId],{mode:this.isDrawer?"hydration":"full"}),this.#updateCartQuantitySelectorButtonStates()}).catch(error=>{console.error(error)}).finally(()=>{this.#enableCartItems(),cartPerformance.measureFromMarker(cartPerformaceUpdateMarker)})}handleDiscountUpdate=event=>{this.#handleCartUpdate(event)};#handleCartError=(line,parsedResponseText)=>{const quantityInput=this.refs.quantitySelectors[line-1]?.querySelector("input");if(!quantityInput)throw new Error("Quantity input not found");quantityInput.value=quantityInput.defaultValue;const cartItemError=this.refs[`cartItemError-${line}`],cartItemErrorContainer=this.refs[`cartItemErrorContainer-${line}`];if(!(cartItemError instanceof HTMLElement))throw new Error("Cart item error not found");if(!(cartItemErrorContainer instanceof HTMLElement))throw new Error("Cart item error container not found");cartItemError.textContent=parsedResponseText.errors,cartItemErrorContainer.classList.remove("hidden")};#handleCartUpdate=event=>{if(event instanceof DiscountUpdateEvent){sectionRenderer.renderSection(this.sectionId,{cache:!1});return}if(event.target===this)return;const cartItemsHtml=event.detail.data.sections?.[this.sectionId];cartItemsHtml?(morphSection(this.sectionId,cartItemsHtml),this.#updateCartQuantitySelectorButtonStates()):sectionRenderer.renderSection(this.sectionId,{cache:!1})};#disableCartItems(){this.classList.add("cart-items-disabled")}#enableCartItems(){this.classList.remove("cart-items-disabled")}#updateQuantitySelectors(updatedCart){if(updatedCart.items)for(const item of updatedCart.items){const variantId=item.variant_id.toString(),selectors=document.querySelectorAll(`quantity-selector-component[data-variant-id="${variantId}"]`);for(const selector of selectors){const input=selector.querySelector("input[data-cart-quantity]");input&&(input.setAttribute("data-cart-quantity",item.quantity.toString()),"updateCartQuantity"in selector&&typeof selector.updateCartQuantity=="function"&&selector.updateCartQuantity())}}}#updateCartQuantitySelectorButtonStates(){for(const selector of document.querySelectorAll("cart-quantity-selector-component"))selector.updateButtonStates?.()}get sectionId(){const{sectionId}=this.dataset;if(!sectionId)throw new Error("Section id missing");return sectionId}get isDrawer(){return this.dataset.drawer!==void 0}}customElements.get("cart-items-component")||customElements.define("cart-items-component",CartItemsComponent); 2//# sourceMappingURL=/cdn/shop/t/378/assets/component-cart-items.js.map?v=165440327125931659001787069265
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.