geno/wp-content/plugins/woocommerce/packages/woocommerce-blocks/build/product-button-frontend.js

3 lines
13 KiB
JavaScript
Raw Normal View History

2024-02-01 17:24:18 +05:30
(self.webpackChunkwebpackWcBlocksJsonp=self.webpackChunkwebpackWcBlocksJsonp||[]).push([[8771],{8462:(t,e,r)=>{"use strict";r.r(e),r.d(e,{Block:()=>g,default:()=>f});var n=r(9196),o=r(4184),s=r.n(o),a=r(5736),c=r(5918),i=r(3775),l=r(3611),d=r(2629),u=r(5271),p=r(4617),_=r(2864),m=r(721);r(1464);const v=({product:t,className:e,style:r})=>{const{id:o,permalink:l,add_to_cart:_,has_options:m,is_purchasable:v,is_in_stock:b}=t,{dispatchStoreEvent:g}=(0,c.n)(),{cartQuantity:f,addingToCart:y,addToCart:E}=(0,i.c)(o),h=Number.isFinite(f)&&f>0,C=!m&&v&&b,w=(0,d.decodeEntities)((null==_?void 0:_.description)||""),S=h?(0,a.sprintf)(/* translators: %s number of products in cart. */
(0,a._n)("%d in cart","%d in cart",f,"woocommerce"),f):(0,d.decodeEntities)((null==_?void 0:_.text)||(0,a.__)("Add to cart","woocommerce")),T=C?"button":"a",R={};return C?R.onClick=async()=>{await E(),g("cart-add-item",{product:t});const{cartRedirectAfterAdd:e}=(0,p.getSetting)("productsSettings");e&&(window.location.href=u.fh)}:(R.href=l,R.rel="nofollow",R.onClick=()=>{g("product-view-link",{product:t})}),(0,n.createElement)(T,{...R,"aria-label":w,disabled:y,className:s()(e,"wp-block-button__link","wp-element-button","add_to_cart_button","wc-block-components-product-button__button",{loading:y,added:h}),style:r},S)},b=({className:t,style:e})=>(0,n.createElement)("button",{className:s()("wp-block-button__link","wp-element-button","add_to_cart_button","wc-block-components-product-button__button","wc-block-components-product-button__button--placeholder",t),style:e,disabled:!0}),g=t=>{const{className:e,textAlign:r}=t,o=(0,l.F)(t),{parentClassName:a}=(0,_.useInnerBlockLayoutContext)(),{product:c}=(0,_.useProductDataContext)();return(0,n.createElement)("div",{className:s()(e,"wp-block-button","wc-block-components-product-button",{[`${a}__product-add-to-cart`]:a,[`align-${r}`]:r})},c.id?(0,n.createElement)(v,{product:c,style:o.style,className:o.className}):(0,n.createElement)(b,{style:o.style,className:o.className}))},f=(0,m.withProductDataContext)(g)},3340:(t,e,r)=>{"use strict";r.d(e,{Z:()=>d});var n=r(4617),o=r(5736),s=r(1478),a=r(2646),c=r(5271);const i=t=>{const e={};return void 0!==t.label&&(e.label=t.label),void 0!==t.required&&(e.required=t.required),void 0!==t.hidden&&(e.hidden=t.hidden),void 0===t.label||t.optionalLabel||(e.optionalLabel=(0,o.sprintf)(/* translators: %s Field label. */
(0,o.__)("%s (optional)","woocommerce"),t.label)),t.priority&&((0,s.h)(t.priority)&&(e.index=t.priority),(0,a.H)(t.priority)&&(e.index=parseInt(t.priority,10))),t.hidden&&(e.required=!1),e},l=Object.entries(c.vr).map((([t,e])=>[t,Object.entries(e).map((([t,e])=>[t,i(e)])).reduce(((t,[e,r])=>(t[e]=r,t)),{})])).reduce(((t,[e,r])=>(t[e]=r,t)),{}),d=(t,e,r="")=>{const o=r&&void 0!==l[r]?l[r]:{};return t.map((t=>({key:t,...n.defaultAddressFields[t]||{},...o[t]||{},...e[t]||{}}))).sort(((t,e)=>t.index-e.index))}},4055:(t,e,r)=>{"use strict";r.d(e,{b:()=>E});var n=r(2991),o=r.n(n),s=r(9307),a=r(4801),c=r(9818),i=r(2629),l=r(3881),d=r(8832);var u=r(9456);const p=t=>{const e=null==t?void 0:t.detail;e&&e.preserveCartData||(0,c.dispatch)(a.CART_STORE_KEY).invalidateResolutionForStore()},_=t=>{(null!=t&&t.persisted||"back_forward"===(window.performance&&window.performance.getEntriesByType("navigation").length?window.performance.getEntriesByType("navigation")[0].type:""))&&(0,c.dispatch)(a.CART_STORE_KEY).invalidateResolutionForStore()},m=()=>{1===window.wcBlocksStoreCartListeners.count&&window.wcBlocksStoreCartListeners.remove(),window.wcBlocksStoreCartListeners.count--},v={first_name:"",last_name:"",company:"",address_1:"",address_2:"",city:"",state:"",postcode:"",country:"",phone:""},b={...v,email:""},g={total_items:"",total_items_tax:"",total_fees:"",total_fees_tax:"",total_discount:"",total_discount_tax:"",total_shipping:"",total_shipping_tax:"",total_price:"",total_tax:"",tax_lines:a.EMPTY_TAX_LINES,currency_code:"",currency_symbol:"",currency_minor_unit:2,currency_decimal_separator:"",currency_thousand_separator:"",currency_prefix:"",currency_suffix:""},f=t=>Object.fromEntries(Object.entries(t).map((([t,e])=>[t,(0,i.decodeEntities)(e)]))),y={cartCoupons:a.EMPTY_CART_COUPONS,cartItems:a.EMPTY_CART_ITEMS,cartFees:a.EMPTY_CART_FEES,cartItemsCount:0,cartItemsWeight:0,crossSellsProducts:a.EMPTY_CART_CROSS_SELLS,cartNeedsPayment:!0,cartNeedsShipping:!0,cartItemErrors:a.EMPTY_CART_ITEM_ERRORS,cartTotals:g,cartIsLoading:!0,cartErrors:a.EMPTY_CART_ERRORS,billingAddress:b,shippingAddress:v,shippingRates:a.EMPTY_SHIPPING_RATES,isLoadingRates:!1,cartHasCalculatedShipping:!1,paymentMethods:a.EMPTY_PAYMENT_METHODS,paymentRequirements:a.EMPTY_PAYMENT_REQUIREMENTS,receiveCart:()=>{},receiveCartContents:()=>{},extensions:a.EMPTY_EXTENSIONS},E=(t={shouldSelect:!0})=>{const{isEditor:e,previewData:r}=(0,d._)(),n=null==r?void 0:r.previewCart,{shouldSelect:i}=t,g=(0,s.useRef)();(0,s.useEffect)((()=>((()=>{if(window.wcBlocksStoreCartListeners||(window.wcBlocksStoreCartListeners={count:0,remove:()=>{}}),(null===(t=window.wcBlocksStoreCartListeners)||void 0===t?void 0:t.count)>0)return void window.wcBlocksStoreCartListeners.count++;var t;document.body.addEventListener("wc-blocks_added_to_cart",p),document.body.addEventListener("wc-blocks_removed_from_cart",p),window.addEventListener("pageshow",_);const e=(0,u.Es)("added_to_cart","wc-blocks_added_to_cart"),r=(0,u.Es)("removed_from_cart","wc-blocks_removed_from_cart");window.wcBlocksStoreCartListeners.count=1,window.wcBlocksStoreCartListeners.remove=()=>{document.body.removeEventListener("wc-blocks_added_to_cart",p),document.body.removeEventListener("wc-blocks_removed_from_cart",p),window.removeEventListener("pageshow",_),e(),r()}})(),m)),[]);const E=(0,c.useSelect)(((t,{dispatch:r})=>{if(!i)return y;if(e)return{cartCoupons:n.coupons,cartItems:n.items,crossSellsProducts:n.cross_sells,cartFees:n.fees,cartItemsCount:n.items_count,cartItemsWeight:n.items_weight,cartNeedsPayment:n.needs_payment,cartNeedsShipping:n.needs_shipping,cartItemErrors:a.EMPTY_CART_ITEM_ERRORS,cartTotals:n.totals,cartIsLoading:!1,cartErrors:a.EMPTY_CART_ERRORS,billingData:b,billingAddress:b,shippingAddress:v,extensions:a.EMPTY_EXTENSIONS,shippingRates:n.shipping_rates,isLoadingRates:!1,cartHasCalculatedShipping:n.has_calculated_shipping,paymentRequirements:n.paymentRequirements,receiveCart:"function"==typeof(null==n?void 0:n.receiveCart)?n.receiveCart:()=>{},receiveCartContents:"function"==typeof(null==n?void 0:n.receiveCartContent