geno/wp-content/plugins/woocommerce/packages/woocommerce-blocks/build/product-button-frontend.js
2024-02-01 11:54:18 +00:00

3 lines
No EOL
13 KiB
JavaScript

(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.receiveCartContents)?n.receiveCartContents:()=>{}};const o=t(a.CART_STORE_KEY),s=o.getCartData(),c=o.getCartErrors(),d=o.getCartTotals(),u=!o.hasFinishedResolution("getCartData"),p=o.isCustomerDataUpdating(),{receiveCart:_,receiveCartContents:m}=r(a.CART_STORE_KEY),g=f(s.billingAddress),E=s.needsShipping?f(s.shippingAddress):g,h=s.fees.length>0?s.fees.map((t=>f(t))):a.EMPTY_CART_FEES;return{cartCoupons:s.coupons.length>0?s.coupons.map((t=>({...t,label:t.code}))):a.EMPTY_CART_COUPONS,cartItems:s.items,crossSellsProducts:s.crossSells,cartFees:h,cartItemsCount:s.itemsCount,cartItemsWeight:s.itemsWeight,cartNeedsPayment:s.needsPayment,cartNeedsShipping:s.needsShipping,cartItemErrors:s.errors,cartTotals:d,cartIsLoading:u,cartErrors:c,billingData:(0,l.QI)(g),billingAddress:(0,l.QI)(g),shippingAddress:(0,l.QI)(E),extensions:s.extensions,shippingRates:s.shippingRates,isLoadingRates:p,cartHasCalculatedShipping:s.hasCalculatedShipping,paymentRequirements:s.paymentRequirements,receiveCart:_,receiveCartContents:m}}),[i]);return g.current&&o()(g.current,E)||(g.current=E),g.current}},3775:(t,e,r)=>{"use strict";r.d(e,{c:()=>l});var n=r(9307),o=r(9818),s=r(4801),a=r(2629),c=r(4055);const i=(t,e)=>{const r=t.find((({id:t})=>t===e));return r?r.quantity:0},l=t=>{const{addItemToCart:e}=(0,o.useDispatch)(s.CART_STORE_KEY),{cartItems:r,cartIsLoading:l}=(0,c.b)(),{createErrorNotice:d,removeNotice:u}=(0,o.useDispatch)("core/notices"),[p,_]=(0,n.useState)(!1),m=(0,n.useRef)(i(r,t));return(0,n.useEffect)((()=>{const e=i(r,t);e!==m.current&&(m.current=e)}),[r,t]),{cartQuantity:Number.isFinite(m.current)?m.current:0,addingToCart:p,cartIsLoading:l,addToCart:(r=1)=>(_(!0),e(t,r).then((()=>{u("add-to-cart")})).catch((t=>{d((0,a.decodeEntities)(t.message),{id:"add-to-cart",context:"wc/all-products",isDismissible:!0})})).finally((()=>{_(!1)})))}}},8832:(t,e,r)=>{"use strict";r.d(e,{_:()=>s}),r(9196);var n=r(9307);r(9818);const o=(0,n.createContext)({isEditor:!1,currentPostId:0,currentView:"",previewData:{},getPreviewData:()=>({})}),s=()=>(0,n.useContext)(o)},3611:(t,e,r)=>{"use strict";r.d(e,{F:()=>l});var n=r(4184),o=r.n(n),s=r(7884),a=r(2646),c=r(1473),i=r(2661);const l=t=>{const e=(t=>{const e=(0,s.Kn)(t)?t:{style:{}};let r=e.style;return(0,a.H)(r)&&(r=JSON.parse(r)||{}),(0,s.Kn)(r)||(r={}),{...e,style:r}})(t),r=(0,i.vc)(e),n=(0,i.l8)(e),l=(0,i.su)(e),d=(0,c.f)(e);return{className:o()(d.className,r.className,n.className,l.className),style:{...d.style,...r.style,...n.style,...l.style}}}},1473:(t,e,r)=>{"use strict";r.d(e,{f:()=>s});var n=r(7884),o=r(2646);const s=t=>{const e=(0,n.Kn)(t.style.typography)?t.style.typography:{},r=(0,o.H)(e.fontFamily)?e.fontFamily:"";return{className:t.fontFamily?`has-${t.fontFamily}-font-family`:r,style:{fontSize:t.fontSize?`var(--wp--preset--font-size--${t.fontSize})`:e.fontSize,fontStyle:e.fontStyle,fontWeight:e.fontWeight,letterSpacing:e.letterSpacing,lineHeight:e.lineHeight,textDecoration:e.textDecoration,textTransform:e.textTransform}}}},3881:(t,e,r)=>{"use strict";r.d(e,{QI:()=>s});var n=r(3340),o=(r(6483),r(4617));r(2629),r(5271);const s=t=>{const e=Object.keys(o.defaultAddressFields),r=(0,n.Z)(e,{},t.country),s=Object.assign({},t);return r.forEach((({key:e="",hidden:r=!1})=>{r&&((t,e)=>t in e)(e,t)&&(s[e]="")})),s}},2661:(t,e,r)=>{"use strict";r.d(e,{l8:()=>u,su:()=>p,vc:()=>d});var n=r(4184),o=r.n(n),s=r(9784),a=r(2289),c=r(7884);function i(t={}){const e={};return(0,a.getCSSRules)(t,{selector:""}).forEach((t=>{e[t.key]=t.value})),e}function l(t,e){return t&&e?`has-${(0,s.o)(e)}-${t}`:""}function d(t){var e,r,n,s,a,d,u;const{backgroundColor:p,textColor:_,gradient:m,style:v}=t,b=l("background-color",p),g=l("color",_),f=function(t){if(t)return`has-${t}-gradient-background`}(m),y=f||(null==v||null===(e=v.color)||void 0===e?void 0:e.gradient);return{className:o()(g,f,{[b]:!y&&!!b,"has-text-color":_||(null==v||null===(r=v.color)||void 0===r?void 0:r.text),"has-background":p||(null==v||null===(n=v.color)||void 0===n?void 0:n.background)||m||(null==v||null===(s=v.color)||void 0===s?void 0:s.gradient),"has-link-color":(0,c.Kn)(null==v||null===(a=v.elements)||void 0===a?void 0:a.link)?null==v||null===(d=v.elements)||void 0===d||null===(u=d.link)||void 0===u?void 0:u.color:void 0}),style:i({color:(null==v?void 0:v.color)||{}})}}function u(t){var e;const r=(null===(e=t.style)||void 0===e?void 0:e.border)||{};return{className:function(t){var e;const{borderColor:r,style:n}=t,s=r?l("border-color",r):"";return o()({"has-border-color":!!r||!(null==n||null===(e=n.border)||void 0===e||!e.color),[s]:!!s})}(t),style:i({border:r})}}function p(t){var e;return{className:void 0,style:i({spacing:(null===(e=t.style)||void 0===e?void 0:e.spacing)||{}})}}},9456:(t,e,r)=>{"use strict";r.d(e,{Es:()=>a,Q9:()=>s});const n=window.CustomEvent||null,o=(t,{bubbles:e=!1,cancelable:r=!1,element:o,detail:s={}})=>{if(!n)return;o||(o=document.body);const a=new n(t,{bubbles:e,cancelable:r,detail:s});o.dispatchEvent(a)},s=({preserveCartData:t=!1})=>{o("wc-blocks_added_to_cart",{bubbles:!0,cancelable:!0,detail:{preserveCartData:t}})},a=(t,e,r=!1,n=!1)=>{if("function"!=typeof jQuery)return()=>{};const s=()=>{o(e,{bubbles:r,cancelable:n})};return jQuery(document).on(t,s),()=>jQuery(document).off(t,s)}},8519:(t,e,r)=>{"use strict";r.d(e,{F:()=>n});const n=t=>null===t},1478:(t,e,r)=>{"use strict";r.d(e,{h:()=>n});const n=t=>"number"==typeof t},7884:(t,e,r)=>{"use strict";r.d(e,{$n:()=>s,Kn:()=>o});var n=r(8519);const o=t=>!(0,n.F)(t)&&t instanceof Object&&t.constructor===Object;function s(t,e){return o(t)&&e in t}},2646:(t,e,r)=>{"use strict";r.d(e,{H:()=>n});const n=t=>"string"==typeof t},1290:(t,e,r)=>{"use strict";r.d(e,{$:()=>s});var n=r(7582),o=r(307);function s(t,e){return void 0===e&&(e={}),(0,o.B)(t,(0,n.pi)({delimiter:"."},e))}},1464:()=>{},9562:(t,e,r)=>{"use strict";function n(t){return t.toLowerCase()}r.d(e,{U:()=>n})},307:(t,e,r)=>{"use strict";r.d(e,{B:()=>a});var n=r(9562),o=[/([a-z0-9])([A-Z])/g,/([A-Z])([A-Z][a-z])/g],s=/[^A-Z0-9]+/gi;function a(t,e){void 0===e&&(e={});for(var r=e.splitRegexp,a=void 0===r?o:r,i=e.stripRegexp,l=void 0===i?s:i,d=e.transform,u=void 0===d?n.U:d,p=e.delimiter,_=void 0===p?" ":p,m=c(c(t,a,"$1\0$2"),l,"\0"),v=0,b=m.length;"\0"===m.charAt(v);)v++;for(;"\0"===m.charAt(b-1);)b--;return m.slice(v,b).split("\0").map(u).join(_)}function c(t,e,r){return e instanceof RegExp?t.replace(e,r):e.reduce((function(t,e){return t.replace(e,r)}),t)}},9784:(t,e,r)=>{"use strict";r.d(e,{o:()=>s});var n=r(7582),o=r(1290);function s(t,e){return void 0===e&&(e={}),(0,o.$)(t,(0,n.pi)({delimiter:"-"},e))}},7582:(t,e,r)=>{"use strict";r.d(e,{pi:()=>n});var n=function(){return n=Object.assign||function(t){for(var e,r=1,n=arguments.length;r<n;r++)for(var o in e=arguments[r])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},n.apply(this,arguments)};Object.create,Object.create,"function"==typeof SuppressedError&&SuppressedError}}]);