gw-customer-accounts 1.2.2 → 1.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gw-customer-accounts",
3
- "version": "1.2.2",
3
+ "version": "1.2.3",
4
4
  "description": "",
5
5
  "main": "gw-customer-accounts.js",
6
6
  "type": "module",
@@ -402,10 +402,10 @@ customElements.define(
402
402
  * Renders the specified tab.
403
403
  */
404
404
  _renderTab(tabId) {
405
+ this.tabGroup.show(tabId || GWUtils.tabId);
405
406
  console.log('Rendering tab:', tabId || GWUtils.tabId);
406
407
  console.log('sl-tab-group', customElements.get('sl-tab-group'));
407
408
  console.log('sl-tab-panel', customElements.get('sl-tab-panel'));
408
- this.tabGroup.show(tabId || GWUtils.tabId);
409
409
  }
410
410
 
411
411
  /**
@@ -1 +0,0 @@
1
- import{G as a,a as i}from"./assets/index-DI2a6rRk.js";customElements.define("gw-address-form",class extends HTMLElement{constructor(){super(),this.form=this.querySelector("form"),this.type=this.getAttribute("type"),this.addressId=this.getAttribute("address-id")}connectedCallback(){if(this._handleFormSubmit(),this.type==="edit"){const e=this.querySelector("[data-delete-address]");if(!e)return;e.addEventListener("click",()=>{this._deleteAddress()})}this.type}async _handleFormSubmit(){await Promise.all([customElements.whenDefined("sl-input")]).then(()=>{this.form.addEventListener("sl-invalid",e=>{e.preventDefault(),this._clearErrorMessages(),this.form.querySelectorAll("sl-input").forEach(t=>{if(t.hasAttribute("data-invalid")){const r=document.createElement("div");r.slot="help-text",r.classList.add("gw-error-message"),r.textContent=t.validationMessage,t.appendChild(r)}}),e.target.focus()},{capture:!0}),this.form.addEventListener("submit",e=>{e.preventDefault();const t=new FormData(this.form),r=Object.fromEntries(t.entries());this._submitAddressForm(r)})})}async _submitAddressForm(e){try{this._clearErrorMessages(),this.form.querySelector("[data-loader]").hidden=!1,e.province&&(e.province=e.province.replaceAll("_"," ")),e.country=e.country.replaceAll("_"," ");let t=e.isDefault;delete e.isDefault;let r=null;if(this.type==="edit"?r=await a.request(i.ENDPOINTS.ADDRESS.EDIT,{address:e,addrID:this.addressId,isDefault:t}):r=await a.request(i.ENDPOINTS.ADDRESS.ADD,{address:e,isDefault:t}),r.error)throw new Error(r.error);this.form.closest("sl-drawer").hide(),a.updateAjaxContent(["[data-gw-addresses-list]","[data-gw-addresses-carousel]"])}catch(t){console.error(t)}finally{this.form.querySelector("[data-loader]").hidden=!0}}async _deleteAddress(){try{this.querySelector("[data-delete-address]").querySelector("[data-loader]").hidden=!1;let e=await a.request(i.ENDPOINTS.ADDRESS.REMOVE,{addrID:this.addressId});if(e.error)throw new Error(e.error);this.form.closest("sl-drawer").hide(),await a.app.updateContent(["[data-gw-addresses-list]","[data-gw-addresses-carousel]"])}catch(e){console.error(e)}}_handleSubmitButton(){const e=this.form.querySelectorAll("sl-input, sl-select, sl-checkbox"),t=this.form.querySelector('button[type="submit"]'),r=()=>Array.from(e).some(s=>{if(s.tagName==="SL-CHECKBOX"){const n=s.getAttribute("defaultChecked"),c=s.getAttribute("checked");return n!==c}const d=s.getAttribute("value"),l=s.value;return d!==l});e.forEach(o=>{o.addEventListener("sl-input",()=>{r()?t.hidden=!1:t.hidden=!0})})}_clearErrorMessages(){this.form.querySelectorAll(".gw-error-message").forEach(e=>e.remove())}});
@@ -1 +0,0 @@
1
- const i=Object.freeze({MAP:{"#my-account":"dashboard","#my-orders":"orders","#my-profile":"profile","#my-favorites":"dashboard##favorites"},STORAGE_KEYS:{TOKEN:"i-shsgi--u0mihh3co1e3y9sns",EMAIL:"gw-customer-accounts-email",RECENTLY_VIEWED:"gw-recently-viewed",RECENTLY_VIEWED_COLLECTION:"gw-recently-viewed-collection",LOYALTY_POINTS:"gw-loyalty-points",YOTPO_POINTS:"gw-yotpo-points",WISHLIST_PRODUCT_IDS:"gw-wishlist-product-ids",RISE_POINTS:"gw-rise-points",REDIRECT_URL:"gw-customer-accounts-login-redirect",TEMP_WISHLIST_PRODUCTS:"gw-temp-wishlist-products",TEMP_CART_PRODUCTS:"gw-temp-cart-products",TEMP_RECENTLY_VIEWED_ITEMS:"gw-temp-recently-viewed-items",TEMP_PRODUCTS_UPDATED:"gw-temp-products-updated"},ENDPOINTS:{AUTH:{SIGN_IN:"/email-sign",VERIFY_CODE:"/code-sign",GET_TOKEN:"/logged-sign",CUSTOMER_LOGGED:"/customer-logged"},FAVORITES:{GET_ALL_IDS:"/get-all-favorites",GET:"/get-favorites",ADD:"/add-favorite",REMOVE:"/remove-favorite",ADD_BULK:"/add-favorites"},VIEWED_PRODUCTS:{GET:"/get-viewed-products",ADD:"/add-viewed-product",ADD_BULK:"/add-viewed-products"},CART:{GET:"/get-cart-products",ADD:"/add-cart-product",ADD_BULK:"/add-cart-products",REMOVE:"/remove-cart"},ADDRESS:{ADD:"/add-address",EDIT:"/edit-address",REMOVE:"/remove-address"},CUSTOMER:{UPDATE:"/update-customer"},LOYALTY:{GET_LL:"/get-ll-customer",GET_YOTPO_CUSTOMER:"/get-youtpo-customer",GET_RISE_CREDIT:"/get-rise-customer"},MISC:{GET_MALOMO_ORDER:"/get-malomo-order"}},TAGS_TO_HIDE:["accounts:hidden"],TEMPLATE_IDS:{PRODUCT_CARD:"gw-standard-product-card-template",FORM_PRODUCT_CARD:"gw-form-product-card-template"},CUSTOM_EVENTS:{FAVORITES_STORAGE_UPDATED:"gw:favorites-storage-updated",SAVED_ITEMS_FROM_CART:"gw:saved-items-from-cart"},DRAWER_IDS:{favorites:"#Drawer-Favorites"}});class u{constructor(){}get componentData(){const e=document.querySelector("gw-customer-accounts").shadowRoot.querySelector("[data-component-data]");return JSON.parse(e.textContent)}get customerId(){var t,e;return(e=(t=this.componentData)==null?void 0:t.customer)==null?void 0:e.id}get customerFirstName(){var t,e;return(e=(t=this.componentData)==null?void 0:t.customer)==null?void 0:e.firstName}get customerEmail(){return localStorage.getItem(i.STORAGE_KEYS.EMAIL)}get hasCustomer(){var t,e;return!!((e=(t=this.componentData)==null?void 0:t.customer)!=null&&e.id)}get customerToken(){return localStorage.getItem(i.STORAGE_KEYS.TOKEN)}get baseURL(){return this.componentData.baseUrl}get app(){return document.querySelector("gw-customer-accounts")}get appShadow(){return this.app.shadowRoot}get dashboard(){return this.appShadow.querySelector("gw-customer-accounts-dashboard")}get tabId(){return i.MAP[window.location.hash]||"dashboard"}async request(t,e={},s="POST"){const a=()=>{const o={method:s,mode:"cors",cache:"no-cache",headers:{"Content-Type":"application/json"}};return s==="POST"&&(o.body=JSON.stringify(e)),o};if(s==="GET"){const o=new URLSearchParams(e);t=`${t}?${o}`}return s==="POST"&&(e.token=this.customerToken,e.email=this.customerEmail,e.customerID=this.customerId),await(await fetch(this.baseURL+t,a())).json()}notify(t,e="success",s=3e3){const a=document.querySelector("gw-customer-accounts"),r=a.shadowRoot.querySelector("[data-notification-alert]"),o=a.shadowRoot.querySelector("[data-notification-message]");o.innerHTML=t,r.open=!0}async updateAjaxContent(t){return await this.app.updateContent(t)}parseVariantId(t){return String(t).split("/").pop()}formatMoney(t){return(t/100).toLocaleString("en-US",{style:"currency",currency:"USD"})}addToStorage({key:t,values:e,storageType:s="local",position:a="start"}){const r=s==="local"?localStorage:sessionStorage,o=JSON.parse(r.getItem(t))||[];a==="start"?r.setItem(t,JSON.stringify([...e,...o])):r.setItem(t,JSON.stringify([...o,...e]))}removeFromStorage({key:t,values:e,storageType:s="local",nestedKey:a}){const r=s==="local"?localStorage:sessionStorage,o=JSON.parse(r.getItem(t))||[];if(a){const n=o.map(c=>e.includes(c[a])?null:c);r.setItem(t,JSON.stringify(n.filter(Boolean)))}else{const n=o.filter(c=>!e.includes(c));r.setItem(t,JSON.stringify(n))}}}const g=new u;export{g as G,i as a};
@@ -1 +0,0 @@
1
- import{G as i,a as e}from"./index-DI2a6rRk.js";class l extends HTMLElement{constructor(){var a;super(),this.tabData=this._parseTabData(),this.tabId=(a=this.tabData)==null?void 0:a.id,this.tabGroup=this.closest("sl-tab-group"),this.tabPanel=this.closest("sl-tab-panel"),this.mainDrawerLabel=i.appShadow.querySelector("[data-main-drawer-label]")}connectedCallback(){if(this._addAnimations(),this.tabGroup.addEventListener("sl-tab-show",n=>{n.detail.name===this.tabId?(this._playFadeInAnimations(),this._updateMainDrawerLabel(),this._updateSignInBlockHeading(),this._updateHash(),i.app.reinitializeCarousels()):this._resetAnimations()}),!e.MAP[window.location.hash])return;const a=window.location.hash===this.tabId,t=e.MAP[window.location.hash].includes(this.tabId);(a||t)&&this._playFadeInAnimations()}get animationElements(){const t=[...this.querySelectorAll("sl-animation")],n=i.appShadow.querySelector("[gw-sign-in-block-animation]");return n&&t.unshift(n),t}_parseTabData(){const a=this.querySelector("[data-tab-panel-data]");return a?JSON.parse(a.textContent):{}}_updateHash(){var n,s;const a=window.location.hash;(n=e.MAP[a])!=null&&n.includes("##")||(window.location.hash=(s=this.tabData)==null?void 0:s.hash)}_updateMainDrawerLabel(){var t;const a=(t=this.tabData)==null?void 0:t.label;a&&this.mainDrawerLabel&&(this.mainDrawerLabel.textContent=a)}_updateSignInBlockHeading(){var n;const a=(n=this.tabData)==null?void 0:n.signInBlockHeading,t=i.appShadow.querySelector("[data-sign-in-block-heading]");a&&t&&(t.textContent=a)}_playFadeInAnimations(){this.animationElements.forEach(a=>a.play=!0)}_addAnimations(){this.animationElements.forEach((a,t)=>{a.keyframes=[{offset:0,opacity:"0",transform:"translate3d(0, -10px, 0)",easing:"ease-in-out"},{offset:1,opacity:"1",transform:"translate3d(0, 0, 0)",easing:"ease-in-out"}],a.delay=t*80})}_resetAnimations(){this.animationElements.forEach(a=>{a.currentTime>0&&(a.currentTime=0)})}}export{l as G};
@@ -1 +0,0 @@
1
- customElements.define("gw-customer-accounts-country-selector",class extends HTMLElement{constructor(){super(),this.countrySelector=this.querySelector('sl-select[name="country"]')}connectedCallback(){this.countrySelector.addEventListener("sl-change",()=>{const e=this.countrySelector.selectedOptions[0];this._renderProvinces(e)}),Promise.all([customElements.whenDefined("sl-select")]).then(()=>{setTimeout(()=>{const e=this.countrySelector.selectedOptions[0];this._renderProvinces(e)},1e3)}),this._updateOptionElements()}_renderProvinces(e){this.closest("form").querySelectorAll('sl-select[name="province"]').forEach(o=>o.remove());const c=JSON.parse(e.getAttribute("data-provinces"));if(!c||!c.length)return;const t=document.createElement("sl-select");t.setAttribute("name","province"),t.label="State",t.required=!0,c.forEach(o=>{const r=document.createElement("sl-option");r.value=o[0].replaceAll(" ","_"),r.textContent=o[1],t.appendChild(r)}),t.setAttribute("value",c[0][0]),this.after(t)}_updateOptionElements(){this.countrySelector.querySelectorAll("option").forEach(e=>{e.value=e.value.replaceAll(" ","_"),e.outerHTML=e.outerHTML.replace(/option/g,"sl-option")})}});
package/dist/dashboard.js DELETED
@@ -1,17 +0,0 @@
1
- import{G as i,a as m}from"./assets/index-DI2a6rRk.js";import{G as h}from"./assets/tab-B7UDegaP.js";customElements.define("gw-customer-accounts-dashboard",class extends h{constructor(){super()}connectedCallback(){super.connectedCallback(),this._initDashboard()}async _initDashboard(){i.hasCustomer&&this._renderRecentlyViewedCollections(),this.loadSavedCartItems(),this.loadFavoriteItems(),this.loadRecentlyViewedItems()}async loadRecentlyViewedItems(t={}){const{preventDrawerRender:a=!1,preventCarouselRender:r=!1,page:e=1,limit:o=8}=t;try{const n=await this._getRecentlyViewedItems(e,o);this._renderRecentlyViewedItems(n,{preventDrawerRender:a,preventCarouselRender:r,page:e,limit:o})}catch(n){console.error("Error rendering recently viewed items:",n)}}async _getRecentlyViewedItems(t,a){if(!i.hasCustomer)return JSON.parse(localStorage.getItem(m.STORAGE_KEYS.TEMP_RECENTLY_VIEWED_ITEMS))||[];const r=await i.request(m.ENDPOINTS.VIEWED_PRODUCTS.GET,{customerID:i.customerId,limit:a,page:t},"GET");if(r.error)throw new Error(r.error);return r.products||[]}_renderRecentlyViewedItems(t,a){const r="[data-recently-viewed-container]",e="[data-recently-viewed-drawer-container]";if(i.appShadow.querySelector(r)){if(!t.length){this._renderEmptyState(r,e);return}a.preventCarouselRender||this._renderProductsToCarousel(t,r),a.preventDrawerRender||this._renderProductsToDrawer({products:t,containerSelector:e,productTemplateId:m.TEMPLATE_IDS.PRODUCT_CARD,currentPage:a.page,nextPage:null})}}async _getSavedCartItems(t,a){if(!i.customerId)return JSON.parse(localStorage.getItem(m.STORAGE_KEYS.TEMP_CART_PRODUCTS))||[];const r=await i.request(m.ENDPOINTS.CART.GET,{customerEmail:i.customerEmail,limit:a,page:t},"GET");if(r.error)throw new Error(r.error);return r.products||[]}_renderSavedCartItems(t,a){const r="[data-saved-from-cart-items-container]",e="[data-saved-from-cart-drawer-container]";if(!this.querySelector(r))return;if(!t.length){this._renderEmptyState(r,e);return}const n=this._calculateNextPage({totalItems:t.length,currentPage:a.page,limit:a.limit});a.preventCarouselRender||this._renderProductsToCarousel(t,r),a.preventDrawerRender||this._renderProductsToDrawer({products:t,containerSelector:e,removeButtonAction:"data-saved-from-cart-remove",productTemplateId:m.TEMPLATE_IDS.FORM_PRODUCT_CARD,currentPage:a.page,nextPage:n})}async loadSavedCartItems(t={}){const{preventDrawerRender:a=!1,preventCarouselRender:r=!1,page:e=1,limit:o=10}=t;try{const n=await this._getSavedCartItems(e,o);this._renderSavedCartItems(n,{preventDrawerRender:a,preventCarouselRender:r,page:e,limit:o})}catch(n){console.error("Error rendering saved items from cart:",n)}}async _getFavoriteItems(t,a){if(!i.hasCustomer)return JSON.parse(localStorage.getItem(m.STORAGE_KEYS.TEMP_WISHLIST_PRODUCTS))||[];const r=await i.request(m.ENDPOINTS.FAVORITES.GET,{limit:a,page:t,customerID:i.customerId},"GET");if(r.error)throw new Error(r.error);return r.products||[]}_renderFavoriteItems(t,a){const r="[data-favorites-container]",e="[data-favorites-drawer-container]";if(!i.appShadow.querySelector(r))return;if(!t.length){this._renderEmptyState(r,e,"You have no favorite items.");return}const{preventDrawerRender:n=!1,preventCarouselRender:s=!1,page:d=1,limit:u=10}=a;s||this._renderProductsToCarousel(t,r);const c=this._calculateNextPage({totalItems:t.length,currentPage:d,limit:u});n||this._renderProductsToDrawer({products:t,containerSelector:e,removeButtonAction:"data-wishlist-remove",productTemplateId:m.TEMPLATE_IDS.FORM_PRODUCT_CARD,currentPage:d,nextPage:c})}_renderSingleFavoriteItem(t){const a="[data-favorites-container]",r="[data-favorites-drawer-container]",e=i.appShadow.querySelector(a),o=document.getElementById(m.TEMPLATE_IDS.PRODUCT_CARD);if(!o){console.warn("Product card template not found.");return}const n=o.content.cloneNode(!0),s=this._populateCarouselItem(n,t),d=e.querySelector("sl-carousel");if(d)d.prepend(s);else{const c=document.createElement("sl-carousel");c.setAttribute("navigation",""),c.setAttribute("slides-per-page","3"),c.setAttribute("slides-per-move","3"),c.setAttribute("style","--scroll-hint: 5%; --aspect-ratio: none"),c.appendChild(s),e.innerHTML="",e.appendChild(c)}const u=i.appShadow.querySelector(r);if(u){const c=document.getElementById(m.TEMPLATE_IDS.FORM_PRODUCT_CARD);if(!c){console.warn("Drawer product card template not found.");return}const p=this._createProductElement(t,c,"data-wishlist-remove");this._ensureDrawerNotEmpty(e),u.prepend(p)}}_removeFavoriteItem(t){const a="[data-favorites-container]",r="[data-favorites-drawer-container]",e=i.appShadow.querySelector(a),o=i.appShadow.querySelector(r);if(e){const n=e.querySelector(`[data-product-id="${t}"]`);n&&n.remove(),e.querySelector("sl-carousel-item")||this._renderEmptyState(a,r,"You have no favorite items.")}if(o){const n=o.querySelector(`[data-product-id="${t}"]`);n&&n.remove()}}async loadFavoriteItems(t={}){const{page:a=1,limit:r=10}=t;try{const e=await this._getFavoriteItems(a,r);this._renderFavoriteItems(e,t)}catch(e){console.error("Error rendering favorite items:",e)}}_renderRecentlyViewedCollections(){const t=m.STORAGE_KEYS.RECENTLY_VIEWED_COLLECTION,a=JSON.parse(localStorage.getItem(t))||[],r=this.querySelector("[data-recently-viewed-collections-container]");if(!r||(r.innerHTML="",!a.length))return;const e=document.createElement("sl-carousel");e.setAttribute("navigation",""),e.setAttribute("style","--scroll-hint: 5%; --aspect-ratio: none"),a.forEach(o=>{const n=document.createElement("sl-carousel-item");n.innerHTML=`
2
- <a href="${o.url}" class="gw-button-text gw-unstyled-link gw-recently-viewed-collection">
3
- ${o.title}
4
- </a>
5
- `,e.appendChild(n)}),r.appendChild(e)}_renderProductsToCarousel(t,a){const r=i.appShadow.querySelector(a);if(!r)return;r.innerHTML="",this._ensureDrawerNotEmpty(r);const e=document.createElement("sl-carousel");e.setAttribute("navigation",""),e.setAttribute("slides-per-page","3"),e.setAttribute("slides-per-move","3"),e.setAttribute("style","--scroll-hint: 5%; --aspect-ratio: none"),t.length>3&&e.setAttribute("data-has-next",""),e.addEventListener("sl-slide-change",n=>{n.detail.index>0?e.setAttribute("data-has-previous",""):e.removeAttribute("data-has-previous"),n.detail.index+3<t.length?e.setAttribute("data-has-next",""):e.removeAttribute("data-has-next")});const o=document.getElementById(m.TEMPLATE_IDS.PRODUCT_CARD);if(!o){console.warn("Carousel item template not found.");return}t.forEach(n=>{if(this._shouldHideProduct(n))return;const s=o.content.cloneNode(!0),d=this._populateCarouselItem(s,n);e.appendChild(d)}),r.appendChild(e)}_renderProductsToDrawer({products:t,currentPage:a,nextPage:r,containerSelector:e,removeButtonAction:o,productTemplateId:n}){const s=i.appShadow.querySelector(e);if(!s)return;a===1&&(s.innerHTML="");const d=s.querySelector("[data-load-more-button]");d&&d.remove();const u=document.getElementById(n||m.TEMPLATE_IDS.PRODUCT_CARD);if(!u){console.warn("Product card template not found.");return}t.forEach(c=>{if(this._shouldHideProduct(c))return;const p=this._createProductElement(c,u,o);s.appendChild(p)}),r&&this._renderLoadMoreButton(s,r)}_renderEmptyState(t,a,r){const e=i.appShadow.querySelector(t);if(!e)return;const o=e.getAttribute("data-drawer-selector"),n=e.getAttribute("data-empty-state-message")||"No items found.";if(o){const s=i.appShadow.querySelector(`#${o}`);if(s){s.setAttribute("empty","");const d=s.querySelector(a);d&&(d.innerHTML=`
6
- <h2 class="gw-header drawer-empty-message">${r}</h2>
7
- `),s.hasAttribute("open")&&s.hide()}}e.innerHTML=`
8
- <div class="gw-empty-list">
9
- <div class="gw-empty-list-inner">
10
- <p>${n}</p>
11
- </div>
12
- </div>
13
- `}_calculateNextPage({totalItems:t,currentPage:a,limit:r}){const e=Math.ceil(t/r);return a<e?a+1:null}_renderLoadMoreButton(t,a){const r=document.createElement("button");r.textContent="Load More",r.classList.add("gw-button","gw-button--stroke"),r.setAttribute("data-load-more-button",""),r.insertAdjacentHTML("beforeend",`
14
- <span class="gw-loader-container" hidden data-loader>
15
- <span class="gw-loader"></span>
16
- </span>
17
- `),r.addEventListener("click",()=>{r.querySelector("[data-loader]").removeAttribute("hidden"),this.loadFavoriteItems({preventCarouselRender:!0,page:a})}),t.appendChild(r)}_shouldHideProduct(t){var a;return(a=t.tags)==null?void 0:a.some(r=>m.TAGS_TO_HIDE.includes(r))}_createProductElement(t,a,r){var f;const e=a.content.cloneNode(!0),o=e.querySelector("[data-product-title]"),n=e.querySelectorAll("[data-product-link]"),s=e.querySelector("[data-product-image]"),d=e.querySelector("[data-quick-add-to-cart-form]"),u=e.querySelector("[data-product-price-compare]"),c=e.querySelector("[data-product-price]");if(e.querySelector(".gw-product-card").setAttribute("data-product-id",i.parseVariantId(t.id)),n.length&&n.forEach(l=>{l.href=`/products/${t.handle}`}),o&&(o.textContent=t.title),s&&((f=t.featuredImage)!=null&&f.url)&&(s.src=t.featuredImage.url+"&width=300",t.featuredImage.altText&&(s.alt=t.featuredImage.altText)),d){this._populateVariantFields(t,d);const l=document.createElement("input");l.type="hidden",l.name="productId",l.value=i.parseVariantId(t.id),d.prepend(l)}if(this._updatePriceDisplay(t,u,c),r){const l=e.querySelector("[data-remove-button]");l&&(l.setAttribute(r,""),r==="data-saved-from-cart-remove"&&l.setAttribute("aria-label",`Remove ${t.title} from saved items`),r==="data-wishlist-remove"&&l.setAttribute("aria-label",`Remove ${t.title} from favorites`))}const p=e.querySelector("gw-wishlist-button");if(p){p.setAttribute("product-id",i.parseVariantId(t.id));const l=document.createElement("script");l.type="application/json",l.setAttribute("data-product-data",""),l.textContent=JSON.stringify(t),p.appendChild(l)}return e}_populateVariantFields(t,a){var e;const r=((e=t.variants)==null?void 0:e.nodes)||[];if(r.length>1){const o=document.createElement("select");o.name="id",o.classList.add("gw-product-card__variant-selector"),r.forEach(n=>{const s=document.createElement("option"),d=i.parseVariantId(n.id);s.value=d,s.textContent=n.title,d==(t.variant_id||t.variantId)&&(s.selected=!0),o.appendChild(s)}),a.prepend(o)}else if(r.length===1){const o=document.createElement("input");o.type="hidden",o.name="id",o.value=t.variant_id||t.variantId?t.variant_id||t.variantId:i.parseVariantId(r[0].id),a.prepend(o)}}_updatePriceDisplay(t,a,r){var d,u;let e=(d=t.variants)==null?void 0:d.nodes[0];const o=t.variant_id||t.variantId;if(o){const c=(u=t.variants)==null?void 0:u.nodes.find(p=>i.parseVariantId(p.id)==o);c&&(e=c)}const n=(e==null?void 0:e.compareAtPrice)||(e==null?void 0:e.compare_at_price),s=e==null?void 0:e.price;if(a&&n&&(typeof n=="number"?a.textContent=i.formatMoney(n):a.textContent=n.includes("$")?n:`$${n}`),s&&r)if(typeof s=="number")r.textContent=i.formatMoney(s);else{const c="$"+s;r.textContent=s.includes("$")?s:c}n&&s&&(a.removeAttribute("hidden"),r.classList.add("gw-product-card__price--sale"))}_ensureDrawerNotEmpty(t){const a=t.getAttribute("data-drawer-selector");if(a){const r=i.appShadow.querySelector(`#${a}`);r&&r.removeAttribute("empty");const e=r.querySelector(".drawer-empty-message");e&&e.remove()}}_populateCarouselItem(t,a){const r=this._populateProductCard(t,a),e=document.createElement("sl-carousel-item");return e.setAttribute("data-product-id",i.parseVariantId(a.id)),e.appendChild(r),e}_populateProductCard(t,a){var u;const r=t.querySelector("[data-product-title]"),e=t.querySelector("[data-product-link]"),o=t.querySelector("[data-product-image]"),n=t.querySelector("[data-product-price-compare]"),s=t.querySelector("[data-product-price]");r&&(r.textContent=a.title),e&&(e.href=`/products/${a.handle}`),o&&((u=a.featuredImage)!=null&&u.url)&&(o.src=a.featuredImage.url+"&width=300",a.featuredImage.altText&&(o.alt=a.featuredImage.altText)),this._updatePriceDisplay(a,n,s);const d=t.querySelector("gw-wishlist-button");if(d){d.setAttribute("product-id",i.parseVariantId(a.id));const c=document.createElement("script");c.type="application/json",c.setAttribute("data-product-data",""),c.textContent=JSON.stringify(a),d.appendChild(c)}return t}});
@@ -1,29 +0,0 @@
1
- import{a as i,G as r}from"./assets/index-DI2a6rRk.js";customElements.define("gw-integrations-loyalty-points",class extends HTMLElement{constructor(){switch(super(),this.integration=this.getAttribute("integration"),this.loyaltyPageUrl=this.getAttribute("page-url"),this.pointsLabel=this.getAttribute("points-label"),this.linkLabel=this.getAttribute("link-label"),this.innerHTML=`
2
- <a href="${this.loyaltyPageUrl}" class="gw-loyalty-points__link gw-unstyled-link">
3
- <span class="gw-loader" data-loader></span>
4
- <span class="gw-loyalty-points__points-value gw-header" data-points-container></span>
5
- <span class="gw-loyalty-points__points-label" data-points-label hidden>${this.pointsLabel}</span>
6
- <span class="gw-loyalty-points__link-label">
7
- ${this.linkLabel}
8
-
9
- <svg
10
- fill='none'
11
- xmlns='http://www.w3.org/2000/svg'
12
- viewBox='0 0 32 32'
13
- aria-hidden='true'
14
- width='16'
15
- height='16'
16
- >
17
- <path d="m13.333 8 8 8-8 8" stroke="currentColor" stroke-width="3" stroke-linecap="round" stroke-linejoin="round"></path>
18
- </svg>
19
- </span>
20
- </a>
21
- `,this.API=null,this.SESSION_KEY=null,this.GET_POINTS=null,this.integration){case"loyalty-lion":this.API=i.ENDPOINTS.LOYALTY.GET_LL,this.SESSION_KEY=i.STORAGE_KEYS.LOYALTY_POINTS,this.GET_POINTS=t=>t.points_approved;break;case"yotpo":this.API=i.ENDPOINTS.LOYALTY.GET_YOTPO_CUSTOMER,this.SESSION_KEY=i.STORAGE_KEYS.YOTPO_POINTS,this.GET_POINTS=t=>{var e;return(e=t.customer)==null?void 0:e.points_balance};break;case"rise":this.API=i.ENDPOINTS.LOYALTY.GET_RISE_CREDIT,this.SESSION_KEY=i.STORAGE_KEYS.RISE_POINTS,this.GET_POINTS=t=>t.amount?this._formatUSD(t.amount):"$0.00",this.innerHTML+=`
22
- <div class="gw-loyalty-points__id-container" hidden>
23
- <span class="gw-loyalty-points__id" data-points-id></span>
24
- <button class="gw-loyalty-points__copy-button" data-copy-button hidden>
25
- <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 13 12" fill="none" aria-hidden="true"><g clip-path="url(#copy-icon-clip-path)"><path d="M11.203 0h-6C4.383 0 3.72.67 3.72 1.497v1.458H2.176a1.491 1.491 0 0 0-1.489 1.49v6.058A1.495 1.495 0 0 0 2.173 12h6c.82 0 1.484-.67 1.484-1.497V9.045H11.2a1.491 1.491 0 0 0 1.489-1.49V1.497A1.495 1.495 0 0 0 11.203 0ZM8.47 10.5c0 .165-.133.299-.297.299h-6a.303.303 0 0 1-.297-.3V4.444c0-.165.133-.299.297-.299h6a.294.294 0 0 1 .297.3v6.058-.004Zm3.03-2.945c0 .166-.133.3-.296.3H9.661v-3.41a1.49 1.49 0 0 0-1.485-1.497h-3.27V1.497c0-.166.133-.3.297-.3h6a.302.302 0 0 1 .297.3v6.058Z" fill="currentColor"></path></g><defs><clipPath id="copy-icon-clip-path"><path fill="#fff" transform="translate(.5)" d="M0 0h12v12H0z"></path></clipPath></defs></svg>
26
- Copy ID
27
- </button>
28
- </div>
29
- `;break;default:return}}connectedCallback(){this._renderPointsFromSession(),this._initLoyaltyPoints()}_formatUSD(t){return t.toLocaleString("en-US",{style:"currency",currency:"USD"})}_renderPointsFromSession(){const t=sessionStorage.getItem(this.SESSION_KEY);if(t){const e=this.querySelector("[data-loader]"),o=this.querySelector("[data-points-container]"),n=this.querySelector("[data-points-label]");o.textContent=t,n.removeAttribute("hidden"),e.hidden=!0}}async _initLoyaltyPoints(){try{const t=await r.request(this.API);if(t.error)throw new Error(t.error);const e=this.querySelector("[data-loader]");e.hidden=!0;const o=this.querySelector("[data-points-container]"),n=this.querySelector("[data-points-label]"),s=this.GET_POINTS(t);if(s&&o&&(o.textContent=s,n.removeAttribute("hidden"),sessionStorage.setItem(this.SESSION_KEY,s)),this.integration==="rise"){if(t==null?void 0:t.code)this.querySelector(".gw-loyalty-points__id-container").removeAttribute("hidden");else{this.querySelector(".gw-loyalty-points__id-container").remove();return}const l=this.querySelector("[data-points-id]"),a=this.querySelector("[data-copy-button]");a.removeAttribute("hidden"),l.textContent="ID: "+t.code,a.addEventListener("click",()=>{navigator.clipboard.writeText(t==null?void 0:t.code),r.notify("ID copied to clipboard")})}}catch(t){console.error(t)}}});
package/dist/main.js DELETED
@@ -1 +0,0 @@
1
- import{G as n,a as s}from"./assets/index-DI2a6rRk.js";customElements.define("gw-customer-accounts",class extends HTMLElement{constructor(){super(),this.shadow=this.attachShadow({mode:"open"});const t=document.getElementById("gw-customer-accounts-template");this.shadow.appendChild(t.content.cloneNode(!0)),t.remove(),this.drawer=this.shadowRoot.querySelector("sl-drawer"),this.tabGroup=this.shadowRoot.querySelector("sl-tab-group"),this.closeButtons=this.drawer.querySelectorAll("[data-main-drawer-close]")}connectedCallback(){this._checkCustomerStatus(),this._watchSavedItemsFromCart(),n.hasCustomer&&(this._saveTempWishlistProducts(),this._saveTempCartProducts(),this._saveTempRecentlyViewedProducts()),Promise.all([customElements.whenDefined("sl-drawer")]).then(()=>this.init())}init(){this.drawer.removeAttribute("hidden"),window.location.search.includes("my-account-open")&&!window.location.pathname.includes("/account")&&(window.history.replaceState({},document.title,window.location.pathname),window.location.hash="#my-account"),window.addEventListener("hashchange",()=>{this._handleHashChange(),this.reinitializeCarousels()}),this._handleHashChange(),this.closeButtons.forEach(t=>{t.addEventListener("click",()=>{this._closeDrawer()})}),this.drawer.addEventListener("sl-hide",t=>{t.target===this.drawer&&(window.location.hash="")}),this._updateAccountLinks(),this._handleInputElements(),this._addRecentlyViewedProducts(),n.hasCustomer&&this._updateRecentlyViewedCollection(),this.reinitializeCarousels(),this.shadowRoot.addEventListener("click",t=>{if(!t.target.closest("[data-drawer-id]"))return;const o=t.target.closest("[data-drawer-id]").getAttribute("data-drawer-id"),r=this.shadowRoot.querySelector(`#${o}`);r.hasAttribute("empty")||(r.open=!0,navigator.userAgent.indexOf("iPhone")>-1&&setTimeout(()=>{this.drawer.classList.add("inner-drawer-open")},150))}),this.shadowRoot.addEventListener("click",t=>{t.target.closest("[data-inner-drawer-close]")&&(t.target.closest("sl-drawer").open=!1,navigator.userAgent.indexOf("iPhone")>-1&&this.drawer.classList.remove("inner-drawer-open"))}),n.hasCustomer&&this.updateFavoriteItemsStorage(),!n.hasCustomer&&sessionStorage.getItem(s.STORAGE_KEYS.TEMP_PRODUCTS_UPDATED)!=="true"&&this._syncTempProducts()}reinitializeCarousels(){Promise.all([customElements.whenDefined("sl-carousel"),customElements.whenDefined("sl-carousel-item")]).then(()=>{setTimeout(()=>{this.shadowRoot.querySelectorAll("sl-carousel").forEach(t=>{t.initializeSlides()})},1e3)})}_updateAccountLinks(){const t=document.querySelectorAll("a[href]");Array.from(t).filter(r=>r.getAttribute("href").startsWith("/account")||r.getAttribute("href").startsWith("#status")).forEach(r=>{r.hasAttribute("data-ignore-account-link")||(r.getAttribute("href").includes("logout")?r.href="#my-profile":r.href="#my-account",Shopify.designMode&&r.addEventListener("click",()=>{this._openDrawer()}))})}_handleInputElements(){const t=e=>{!e.value&&!e.getAttribute("value")?e.classList.add("input--empty"):e.classList.remove("input--empty")},o=e=>{e.classList.add("input--focus")},r=e=>{e.classList.remove("input--focus")};this.shadowRoot.querySelectorAll("sl-input").forEach(e=>{e.addEventListener("sl-input",()=>t(e)),e.addEventListener("sl-focus",()=>o(e)),e.addEventListener("sl-blur",()=>r(e)),t(e)})}async _handleHashChange(){const t=window.location.hash;if(s.MAP[t]){if(await this._fetchComponents(),s.MAP[t].includes("##")){const[o,r]=s.MAP[t].split("##");this._renderTab(o),setTimeout(()=>{this._renderSubTab(r),this._openDrawer()},100);return}else this.shadowRoot.querySelectorAll("sl-drawer").forEach(o=>{o.open=!1});this._renderTab(),this._openDrawer()}}async _openDrawer(){this.drawer.open||this.drawer.show()}_closeDrawer(){this.drawer.open&&this.drawer.hide()}_fetchComponents(){if(customElements.get("sl-tab-group"))return Promise.resolve();const t="https://cdn.jsdelivr.net/npm/@shoelace-style/shoelace@2.19.1/cdn/components/",r=["tab-group","tab-panel","tab","animation","skeleton","select","input","checkbox","carousel","carousel-item","popup","option","alert"].map(e=>new Promise((i,a)=>{const c=document.createElement("script");c.type="module",c.src=`${t}${e}/${e}.js`,c.onload=i,c.onerror=a,document.body.appendChild(c)}));return Promise.all(r)}async _addRecentlyViewedProducts(){if(!window.location.pathname.includes("/products/"))return;const{product:o}=n.componentData;if(!o||!o.id)return;const{id:r}=o;if(n.hasCustomer)try{const e=await n.request(s.ENDPOINTS.VIEWED_PRODUCTS.ADD,{prodID:r});if(e.error)throw new Error(e.error);return e}catch(e){console.error(e)}else{if(JSON.parse(localStorage.getItem(s.STORAGE_KEYS.TEMP_RECENTLY_VIEWED_ITEMS)||"[]").some(i=>i.id===r))return;n.addToStorage({key:s.STORAGE_KEYS.TEMP_RECENTLY_VIEWED_ITEMS,values:[{...o}]})}}_updateRecentlyViewedCollection(){if(!window.location.pathname.includes("/collections/"))return;const{collection:o}=n.componentData;if(!o)return;const{url:r,title:e}=o,i=localStorage.getItem(s.STORAGE_KEYS.RECENTLY_VIEWED_COLLECTION),c=(JSON.parse(i)||[]).filter(d=>d.url!==r),l=[{url:r,title:e},...c];localStorage.setItem(s.STORAGE_KEYS.RECENTLY_VIEWED_COLLECTION,JSON.stringify(l))}_renderTab(t){console.log("Rendering tab:",t||n.tabId),console.log("sl-tab-group",customElements.get("sl-tab-group")),console.log("sl-tab-panel",customElements.get("sl-tab-panel")),this.tabGroup.show(t||n.tabId)}_renderSubTab(t){const o=s.DRAWER_IDS[t];if(!o)return;const r=this.shadowRoot.querySelector(o);r&&(r.open=!0,navigator.userAgent.indexOf("iPhone")>-1&&setTimeout(()=>{this.drawer.classList.add("inner-drawer-open")},150))}async updateContent(t=[]){const o=this.getAttribute("data-section-id"),r=await this._fetchContent(o);t.forEach(e=>{const i=this.shadow.querySelector(e);if(i){const c=r.querySelector("#gw-customer-accounts-template").content.querySelector(e);i.innerHTML=c.innerHTML}})}async _fetchContent(t){const r=await(await fetch(window.location.pathname+`?section_id=${t}`)).text();return new DOMParser().parseFromString(r,"text/html")}async updateFavoriteItemsStorage(t){const{removeIds:o,addIds:r}=t||{};let e=!1;if(r!=null&&r.length&&(n.addToStorage({key:s.STORAGE_KEYS.WISHLIST_PRODUCT_IDS,values:r,storageType:"session"}),e=!0),o!=null&&o.length&&(n.removeFromStorage({key:s.STORAGE_KEYS.WISHLIST_PRODUCT_IDS,values:o,storageType:"session"}),e=!0),e){this.dispatchEvent(new CustomEvent(s.CUSTOM_EVENTS.FAVORITES_STORAGE_UPDATED));return}try{const i=await n.request(s.ENDPOINTS.FAVORITES.GET_ALL_IDS,{customerID:n.customerId},"GET");if(i.error)throw new Error(i.error);sessionStorage.setItem(s.STORAGE_KEYS.WISHLIST_PRODUCT_IDS,JSON.stringify(i.products)),this.dispatchEvent(new CustomEvent(s.CUSTOM_EVENTS.FAVORITES_STORAGE_UPDATED))}catch(i){console.error("Error initializing wishlist:",i)}}async _checkCustomerStatus(){const t=n.customerToken,{id_sha256:o,email:r,tags:e,id:i}=n.componentData.customer;if(!t&&i)try{const a=await n.request(s.ENDPOINTS.AUTH.GET_TOKEN,{customerEmail:r,encode:o},"POST");if(a.error)throw new Error(a.error);a.token&&(localStorage.setItem(s.STORAGE_KEYS.TOKEN,a.token),localStorage.setItem(s.STORAGE_KEYS.EMAIL,r))}catch(a){console.error("Error checking customer status:",a)}if(e&&!e.includes("gw-customer"))try{const a=await n.request(s.ENDPOINTS.AUTH.CUSTOMER_LOGGED,{});if(a.error)throw new Error(a.error)}catch(a){console.error("Error checking customer status:",a)}}async _saveTempWishlistProducts(){var r;const t=JSON.parse(localStorage.getItem(s.STORAGE_KEYS.TEMP_WISHLIST_PRODUCTS));if(!(t!=null&&t.length))return;const o={products:t.map(e=>{const{id:i,variantId:a}=e;return{prodID:i,varID:a}})};try{const e=await n.request(s.ENDPOINTS.FAVORITES.ADD_BULK,o);if(e.error)throw new Error(e.error);localStorage.removeItem(s.STORAGE_KEYS.TEMP_WISHLIST_PRODUCTS),(r=e.products)!=null&&r.length&&(sessionStorage.setItem(s.STORAGE_KEYS.WISHLIST_PRODUCT_IDS,JSON.stringify(e.products)),this.dispatchEvent(new CustomEvent(s.CUSTOM_EVENTS.FAVORITES_STORAGE_UPDATED))),n.dashboard.loadFavoriteItems()}catch(e){console.error("Error saving temp wishlist products:",e)}}async _saveTempCartProducts(){const t=JSON.parse(localStorage.getItem(s.STORAGE_KEYS.TEMP_CART_PRODUCTS));if(!(t!=null&&t.length))return;const o={products:t.map(r=>{const{id:e,variantId:i}=r;return{prodID:e,varID:i}})};try{const r=await n.request(s.ENDPOINTS.CART.ADD_BULK,o);if(r.error)throw new Error(r.error);localStorage.removeItem(s.STORAGE_KEYS.TEMP_CART_PRODUCTS),n.dashboard.loadSavedCartItems()}catch(r){console.error("Error saving temp cart products:",r)}}async _saveTempRecentlyViewedProducts(){const t=JSON.parse(localStorage.getItem(s.STORAGE_KEYS.TEMP_RECENTLY_VIEWED_ITEMS));if(!(t!=null&&t.length))return;const o={products:t.map(r=>{const{id:e}=r;return{prodID:e}})};try{const r=await n.request(s.ENDPOINTS.VIEWED_PRODUCTS.ADD_BULK,o);if(r.error)throw new Error(r.error);localStorage.removeItem(s.STORAGE_KEYS.TEMP_RECENTLY_VIEWED_ITEMS),console.log("Saved temp recently viewed products:",r),n.dashboard.loadRecentlyViewedItems()}catch(r){console.error("Error saving temp recently viewed products:",r)}}async _watchSavedItemsFromCart(){this.addEventListener(s.CUSTOM_EVENTS.SAVED_ITEMS_FROM_CART,async t=>{n.hasCustomer?await this._handleAuthedCartEvent(t):this._handleGuestCartEvent(t)})}async _handleGuestCartEvent(t){const o=t.detail.extra,r=o.handle,e={};try{const i=await fetch(`/products/${r}.js`);if(!i.ok)throw new Error("Product not found");const a=await i.json();e.variant_id=o.variant_id,e.featuredImage=o.featured_image,e.title=o.title,e.variants={},e.variants.nodes=a.variants,e.id=a.id,e.tags=a.tags,e.handle=a.handle;const l=(JSON.parse(localStorage.getItem(s.STORAGE_KEYS.TEMP_CART_PRODUCTS))||[]).filter(u=>u.id!==a.id),d=[e,...l];localStorage.setItem(s.STORAGE_KEYS.TEMP_CART_PRODUCTS,JSON.stringify(d)),n.dashboard.loadSavedCartItems()}catch(i){console.error("Error adding product to cart:",i)}}async _handleAuthedCartEvent(t){try{const{productId:o,variantId:r}=t.detail||{};if(!o||!r)return;const e=await n.request(s.ENDPOINTS.CART.ADD,{prodID:o,varID:r});if(e.error)throw new Error(e.error);n.dashboard.loadSavedCartItems()}catch(o){console.error("Error adding product to cart:",o)}}async _syncTempProducts(){const t=[s.STORAGE_KEYS.TEMP_WISHLIST_PRODUCTS,s.STORAGE_KEYS.TEMP_CART_PRODUCTS,s.STORAGE_KEYS.TEMP_RECENTLY_VIEWED_ITEMS],o=t.flatMap(a=>(JSON.parse(localStorage.getItem(a))||[]).filter(Boolean)),r=[...new Map(o.map(a=>[a.id,a])).values()];console.log("Unique products:",r);const i=(await Promise.all(r.map(async({id:a,handle:c})=>{try{const l=await fetch(`/products/${c}.js`);return l.ok?await l.json():null}catch{return null}}))).reduce((a,c)=>(c&&c.available&&(a[c.id]=c),a),{});t.forEach(a=>{const l=(JSON.parse(localStorage.getItem(a))||[]).map(d=>{if(!d)return null;const u=i[d.id];return u?(d.variants.nodes=u.variants,d):null}).filter(Boolean);localStorage.setItem(a,JSON.stringify(l))}),sessionStorage.setItem(s.STORAGE_KEYS.TEMP_PRODUCTS_UPDATED,"true")}});
@@ -1 +0,0 @@
1
- import{G as o,a as s}from"./assets/index-DI2a6rRk.js";customElements.define("gw-malomo-button",class extends HTMLElement{constructor(){super(),this.trackingPageUrl=this.getAttribute("tracking-page-url"),this.orderId=this.getAttribute("order-id")}connectedCallback(){this._initMalomoButton()}async _initMalomoButton(){var r;const t=await o.request(s.ENDPOINTS.MISC.GET_MALOMO_ORDER,{orderID:this.orderId});if(t.error){console.error(t.error);return}if((r=t.order)!=null&&r.url){const e=this.querySelector("a");e.href=t.order.url}else this.remove()}});
package/dist/orders.js DELETED
@@ -1 +0,0 @@
1
- import{G as c}from"./assets/tab-B7UDegaP.js";import"./assets/index-DI2a6rRk.js";customElements.define("gw-customer-accounts-orders",class extends c{constructor(){super()}connectedCallback(){super.connectedCallback()}});
@@ -1 +0,0 @@
1
- import{G as a,a as o}from"./assets/index-DI2a6rRk.js";customElements.define("gw-preferences-form",class extends HTMLElement{constructor(){super(),this.form=this.querySelector("form")}connectedCallback(){this._handleFormSubmit()}async _handleFormSubmit(){await Promise.all([customElements.whenDefined("sl-input")]).then(()=>{this.form.addEventListener("sl-invalid",e=>{e.preventDefault(),this._clearErrorMessages(),this.form.querySelectorAll("sl-input").forEach(r=>{if(r.hasAttribute("data-invalid")){const t=document.createElement("div");t.slot="help-text",t.classList.add("gw-error-message"),t.textContent=r.validationMessage,r.appendChild(t)}})},{capture:!0}),this.form.addEventListener("submit",e=>{e.preventDefault();const r=new FormData(this.form),t=Object.fromEntries(r.entries());this._submitPreferencesForm(t)})})}async _submitPreferencesForm(e){try{this._clearErrorMessages(),this.form.querySelector("[data-loader]").hidden=!1;let r=await a.request(o.ENDPOINTS.CUSTOMER.UPDATE,e);if(r.error)throw new Error(r.error);this.form.closest("sl-drawer").hide(),a.updateAjaxContent(["[data-main-drawer-label]","[data-my-preference-fields]"])}catch(r){this._handleErrors(r)}finally{this.form.querySelector("[data-loader]").hidden=!0}}_clearErrorMessages(){this.form.querySelectorAll(".gw-error-message").forEach(e=>e.remove())}_handleErrors(e){e.message.includes("valid phone number")&&this._displayErrorMessage('[name="phone"]',e.message)}_displayErrorMessage(e,r){let t=e;typeof e=="string"&&(t=this.form.querySelector(e));const s=document.createElement("div");s.slot="help-text",s.classList.add("gw-error-message"),s.textContent=r,t.appendChild(s),t.focus()}});
package/dist/profile.js DELETED
@@ -1 +0,0 @@
1
- import{a as o}from"./assets/index-DI2a6rRk.js";import{G as c}from"./assets/tab-B7UDegaP.js";customElements.define("gw-customer-accounts-profile",class extends c{constructor(){super()}connectedCallback(){var e;super.connectedCallback(),(e=this.querySelector("[data-logout-button]"))==null||e.addEventListener("click",function(t){t.preventDefault(),this.querySelector("[data-loader]").hidden=!1,localStorage.removeItem(o.STORAGE_KEYS.TOKEN),localStorage.removeItem(o.STORAGE_KEYS.EMAIL),window.location.href="/account/logout"})}});
@@ -1,4 +0,0 @@
1
- import{G as o,a as s}from"./assets/index-DI2a6rRk.js";customElements.define("gw-quick-add-to-cart-form",class extends HTMLElement{constructor(){super(),this.form=this.querySelector("form"),this.productId=this.getAttribute("product-id")}connectedCallback(){this.form.addEventListener("submit",async e=>{e.preventDefault(),this._handleFormSubmit()}),this.addEventListener("click",e=>{e.target.matches("[data-wishlist-remove]")&&this.closest(".gw-product-card").querySelector("gw-wishlist-button").dispatchEvent(new Event("click")),e.target.matches("[data-saved-from-cart-remove]")&&this._handleRemoveFromSavedItems()})}async _handleFormSubmit(){this.form.querySelector("[data-loader]").hidden=!1;const t={method:"POST",body:new FormData(this.form),headers:{Accept:"application/javascript"}};try{const r=await fetch(routes.cart_add_url,t);if(r.error)throw new Error(r.error);o.notify(`
2
- <span>Product added to cart</span>
3
- <a href="/cart" class="gw-notification__link">View</a>
4
- `)}catch(r){console.error(r)}finally{if(this.form.querySelector("[data-loader]").hidden=!0,!this.closest("[data-favorites-drawer-container]"))return;const r=this.form.querySelector('[name="productId"]').value,a=this.form.querySelector('[name="id"]').value;if(!r||!a)return;const c=new CustomEvent(s.CUSTOM_EVENTS.SAVED_ITEMS_FROM_CART,{detail:{productId:r,variantId:a,target:this}});o.app.dispatchEvent(c)}}async _handleRemoveFromSavedItems(){if(!o.hasCustomer){const t=this.form.querySelector('[name="productId"]').value,a=(JSON.parse(localStorage.getItem(s.STORAGE_KEYS.TEMP_CART_PRODUCTS))||[]).filter(c=>c.id!=t);localStorage.setItem(s.STORAGE_KEYS.TEMP_CART_PRODUCTS,JSON.stringify(a)),o.dashboard.loadSavedCartItems();return}this.form.closest(".gw-product-card").classList.add("gw-product-card--removing");const e={prodID:this.form.querySelector('[name="productId"]').value};try{const t=await o.request(s.ENDPOINTS.CART.REMOVE,e);if(t.error)throw new Error(t.error);await o.dashboard.loadSavedCartItems()}catch(t){console.error(t)}}});
package/dist/sign-in.js DELETED
@@ -1 +0,0 @@
1
- import{G as f,a as s}from"./assets/index-DI2a6rRk.js";customElements.define("gw-customer-accounts-sign-in",class extends HTMLElement{constructor(){super(),this.signInBlock=this.querySelector("[data-sign-in-block]"),this.verifyCodeBlock=this.querySelector("[data-verify-code-block]"),this.tryAnotherEmailButton=this.querySelector("[data-try-another-email]"),this.sendAnotherCodeButton=this.querySelector("[data-send-another-code]"),this.inputtedEmail="",this.inputtedCode=""}connectedCallback(){this._handleEmailSubmitForm(),this._handleInputCodeGroup(),this.tryAnotherEmailButton.addEventListener("click",()=>{this.signInBlock.removeAttribute("hidden"),this.verifyCodeBlock.setAttribute("hidden",""),this.signInBlock.querySelector("sl-input").value="",this.signInBlock.querySelector("sl-input").focus(),this.inputtedEmail="",this.inputtedCode=""}),this.sendAnotherCodeButton.addEventListener("click",()=>{this._submitEmailForm(this.querySelector("[data-sign-in-form]")),f.notify("Another code has been sent to your email.")})}async _handleEmailSubmitForm(){await Promise.all([customElements.whenDefined("sl-input")]).then(()=>{const t=this.querySelector("[data-sign-in-form]"),i=this.querySelector("[data-email-error]");t.addEventListener("sl-invalid",o=>{o.preventDefault(),i.textContent=o.target.validationMessage,i.hidden=!1,o.target.focus()},{capture:!0}),t.addEventListener("submit",o=>{o.preventDefault(),i.hidden=!0,i.textContent="",this._submitEmailForm(t).then(()=>{const e=this.verifyCodeBlock.querySelector(".code-input");e&&e.focus()})})})}async _submitEmailForm(t){const i=t.querySelector('button[type="submit"]');i.disabled=!0,i.querySelector("[data-loader]").hidden=!1;const o=new FormData(t);this.inputtedEmail=o.get("email");try{const e=await this._request({customerEmail:this.inputtedEmail},s.ENDPOINTS.AUTH.SIGN_IN);if(e.error){console.error(e.error);return}const n=this.querySelector("[data-code-sent-to]");return n&&(n.textContent=this.inputtedEmail),this.signInBlock.setAttribute("hidden",""),this.verifyCodeBlock.removeAttribute("hidden"),e}catch(e){console.error(e),alert("An error occurred. Please try again later.")}finally{i.disabled=!1,i.querySelector("[data-loader]").hidden=!0}}async _submitVerificationCode(){var c;const t=this.querySelector(".gw-verify-code__actions"),i=t.querySelectorAll("button, a"),o=t.querySelector("[data-verify-error]"),e=t.querySelector("[data-loader]"),n=this.querySelectorAll("input.code-input");try{n.forEach(l=>{l.disabled=!0}),i.forEach(l=>{l.disabled=!0,l.hidden=!0}),o.hidden=!0,e.hidden=!1;const r=await this._request({customerEmail:this.inputtedEmail,code:this.inputtedCode},s.ENDPOINTS.AUTH.VERIFY_CODE);if(!r.url)throw new Error("Verification failed");localStorage.setItem(s.STORAGE_KEYS.TOKEN,r.token),localStorage.setItem(s.STORAGE_KEYS.EMAIL,this.inputtedEmail);const a=await fetch(r.url);if(a.error)throw new Error(a.error);const u=await(await fetch(window.location.href)).text();document.documentElement.innerHTML=u;const h=sessionStorage.getItem(s.STORAGE_KEYS.REDIRECT_URL);h&&(sessionStorage.removeItem(s.STORAGE_KEYS.REDIRECT_URL),window.location.href=h);const m=(c=new DOMParser().parseFromString(u,"text/html").querySelector("#gw-customer-accounts-template").content)==null?void 0:c.querySelector("gw-integrations-loyalty-points");if(!m)return;const y=window.location.pathname,p=m.getAttribute("page-url");y.includes(p)&&window.location.reload()}catch(r){console.error(r),setTimeout(()=>{n[n.length-1].focus()})}finally{n.forEach(r=>{r.disabled=!1}),i.forEach(r=>{r.disabled=!1,r.hidden=!1}),o.hidden=!1,e.hidden=!0}}async _request(t,i,o="POST"){return await(await fetch(f.baseURL+i,{method:o,body:JSON.stringify(t),mode:"cors",cache:"no-cache",headers:{"Content-Type":"application/json"}})).json()}_handleInputCodeGroup(){const t=[...this.querySelectorAll("input.code-input")];t.forEach((i,o)=>{i.addEventListener("keydown",e=>{(e.ctrlKey||e.metaKey)&&e.keyCode===86||(e.keyCode!==8&&(e.keyCode<48||e.keyCode>57)&&e.preventDefault(),e.keyCode===8&&e.target.value===""&&t[Math.max(0,o-1)].focus())}),i.addEventListener("input",e=>{const[n,...c]=e.target.value;e.target.value=n??"";const r=o===t.length-1,a=n!==void 0;a&&!r&&(t[o+1].focus(),t[o+1].value=c.join(""),t[o+1].dispatchEvent(new Event("input"))),a&&r&&t.every(d=>d.value)&&(this.inputtedCode=t.map(d=>d.value).join(""),this._submitVerificationCode())})})}});
@@ -1,21 +0,0 @@
1
- import{G as s,a as i}from"./assets/index-DI2a6rRk.js";customElements.define("gw-wishlist-button",class extends HTMLElement{constructor(){var o,r;super(),this.shadow=this.attachShadow({mode:"open"}),this.isIconOnly=this.hasAttribute("icon-only");const e=this.querySelector('template[name="icon"]');this.iconEl=this._createIcon(e,"icon");const t=this.querySelector('template[name="filled-icon"]');this.filledIconEl=this._createIcon(t,"filled-icon"),this.hasAttribute("icon-only")?this.shadowRoot.innerHTML=`
2
- <button class="wishlist-button wishlist-button--icon-only" part="button">
3
- ${this.iconEl}
4
- ${this.filledIconEl}
5
- </button>
6
- `:this.shadowRoot.innerHTML=`
7
- <button class="wishlist-button" part="button">
8
- <span class="icon-container" part="icon-container">
9
- ${this.iconEl}
10
- ${this.filledIconEl}
11
- </span>
12
- <span class="" data-button-label></span>
13
- <span class="loader" data-loader></span>
14
- </button>
15
- `,this.productId=this.getAttribute("product-id"),this.variantId=this.getAttribute("variant-id"),this.labels={inactive:((o=s.componentData.wishlist)==null?void 0:o.addToWishlistLabel)||"Add to wishlist",active:((r=s.componentData.wishlist)==null?void 0:r.addedToWishlistLabel)||"Added to wishlist"},this.button=this.shadowRoot.querySelector("button"),this.buttonLabel=this.shadowRoot.querySelector("[data-button-label]"),this.loader=this.shadowRoot.querySelector("[data-loader]"),this.buttonIcon=this.shadowRoot.querySelectorAll("[data-button-icon]")}connectedCallback(){this.addEventListener("click",e=>this._handleFavoriteButtonClick(e)),this._activateButton(this._isProductInFavorites()),s.app.addEventListener(i.CUSTOM_EVENTS.FAVORITES_STORAGE_UPDATED,()=>{this._activateButton(this._isProductInFavorites())})}_createIcon(e,t){if(!e)return"";const r=e.content.cloneNode(!0).querySelector("svg");return r.setAttribute("part",t),r.setAttribute("data-button-icon",""),r.setAttribute("hidden",""),r.outerHTML}_getVariantId(){const t=new URLSearchParams(window.location.search).get("variant");return t||this.variantId}async _handleFavoriteButtonClick(e){if(e.preventDefault(),e.stopPropagation(),this.button.disabled=!0,this.button.setAttribute("aria-disabled","true"),this.setAttribute("processing",""),this.loader&&(this.loader.hidden=!1),this.hasAttribute("saved")){this._activateButton(!1);try{const t=await this._removeFromFavorites();if(t.error)throw new Error(t.error);const o=t.products;if(!o)throw new Error("Product not found");s.dashboard._removeFavoriteItem(s.parseVariantId(o.id)),s.app.updateFavoriteItemsStorage({removeIds:[s.parseVariantId(o.id)]});const r=s.customerFirstName?`${s.customerFirstName}'s`:"Your";s.notify(`
16
- <span>Product removed from ${r} favorites</span>
17
- <a href="#my-favorites" class="gw-notification__link">View</a>
18
- `)}catch(t){console.error(t),this._activateButton(!0),s.notify("An error occurred. Please try again later.")}}else{this._activateButton(!0);try{const t=await this._addToFavorites();if(t.error)throw new Error(t.error);const o=t.products;if(!o)throw new Error("Product not found");s.app.updateFavoriteItemsStorage({addIds:[s.parseVariantId(o.id)]}),s.dashboard._renderSingleFavoriteItem(o);const r=s.customerFirstName?`${s.customerFirstName}'s`:"Your";s.notify(`
19
- <span>Added to ${r} favorites</span>
20
- <a href="#my-favorites" class="gw-notification__link">View</a>
21
- `)}catch(t){console.error(t),this._activateButton(!1),s.notify("An error occurred. Please try again later.")}}this.loader&&(this.loader.hidden=!0),this.button.disabled=!1,this.button.removeAttribute("aria-disabled"),this.removeAttribute("Processing")}async _addToFavorites(){if(!s.hasCustomer){const t=this.querySelector("[data-product-data]"),o=JSON.parse(t.textContent);o.variant_id=this._getVariantId();const r=localStorage.getItem(i.STORAGE_KEYS.TEMP_WISHLIST_PRODUCTS)||"[]",a=JSON.parse(r).filter(c=>c.id!==o.id);return a.push(o),localStorage.setItem(i.STORAGE_KEYS.TEMP_WISHLIST_PRODUCTS,JSON.stringify(a)),{success:!0,products:o}}const e=await s.request(i.ENDPOINTS.FAVORITES.ADD,{prodID:this.productId,varID:this._getVariantId()});if(e.error)throw new Error(e.error);return e}async _removeFromFavorites(){if(!s.hasCustomer){const t=this.querySelector("[data-product-data]"),o=JSON.parse(t.textContent),r=localStorage.getItem(i.STORAGE_KEYS.TEMP_WISHLIST_PRODUCTS)||"[]",a=JSON.parse(r).filter(c=>c.id!==o.id);return localStorage.setItem(i.STORAGE_KEYS.TEMP_WISHLIST_PRODUCTS,JSON.stringify(a)),{success:!0,products:o}}const e=await s.request(i.ENDPOINTS.FAVORITES.REMOVE,{prodID:this.productId});if(e.error)throw new Error(e.error);return e}_activateButton(e){this.buttonIcon.length&&this.buttonIcon.forEach(t=>t.removeAttribute("hidden")),this.loader&&this.loader.setAttribute("hidden",""),e?(this.setAttribute("saved",""),this.button.setAttribute("aria-label",this.labels.active),this.buttonLabel&&(this.buttonLabel.textContent=this.labels.active)):(this.removeAttribute("saved"),this.button.setAttribute("aria-label",this.labels.inactive),this.buttonLabel&&(this.buttonLabel.textContent=this.labels.inactive))}_isProductInFavorites(){if(!s.hasCustomer){const o=localStorage.getItem(i.STORAGE_KEYS.TEMP_WISHLIST_PRODUCTS);return(o?JSON.parse(o):[]).some(n=>n.id===this.productId)}const e=sessionStorage.getItem(i.STORAGE_KEYS.WISHLIST_PRODUCT_IDS);return(e?JSON.parse(e):[]).includes(this.productId)}});