oont-contents/plugins/woocommerce/assets/client/blocks/product-stock-indicator-frontend.js
2025-04-06 08:34:48 +02:00

1 line
No EOL
4.6 KiB
JavaScript

(self.webpackChunkwebpackWcBlocksFrontendJsonp=self.webpackChunkwebpackWcBlocksFrontendJsonp||[]).push([[345],{5916:(t,e,o)=>{"use strict";o.r(e),o.d(e,{Block:()=>h,default:()=>w});var r=o(1609),s=o(7723),n=o(851),c=o(2796),l=o(4487),i=o(1616),u=o(5703),a=o(7143);const d="woocommerce/product-type-template-state",p="SWITCH_PRODUCT_TYPE",y="SET_PRODUCT_TYPES",g="REGISTER_LISTENER",m="UNREGISTER_LISTENER",k=(0,u.getSetting)("productTypes",{});var v;const f=Object.keys(k).map((t=>({slug:t,label:k[t]}))),T={productTypes:{list:f,current:null===(v=f[0])||void 0===v?void 0:v.slug},listeners:[]},b={switchProductType:t=>({type:p,current:t}),setProductTypes:t=>({type:y,productTypes:t}),registerListener:t=>({type:g,listener:t}),unregisterListener:t=>({type:m,listener:t})},S=(0,a.createReduxStore)(d,{reducer:(t=T,e)=>{switch(e.type){case y:return{...t,productTypes:{...t.productTypes,list:e.productTypes||[]}};case p:return{...t,productTypes:{...t.productTypes,current:e.current}};case g:return{...t,listeners:[...t.listeners,e.listener||""]};case m:return{...t,listeners:t.listeners.filter((t=>t!==e.listener))};default:return t}},actions:b,selectors:{getProductTypes:t=>t.productTypes.list,getCurrentProductType:t=>t.productTypes.list.find((e=>e.slug===t.productTypes.current)),getRegisteredListeners:t=>t.listeners}});(0,a.select)(d)||(0,a.register)(S),o(9644);const h=t=>{const{className:e}=t,o=(0,l.p)(t),{parentClassName:i}=(0,c.useInnerBlockLayoutContext)(),{product:d}=(0,c.useProductDataContext)(),{text:p,class:y}=d.stock_availability,{selectedProductType:g}=(0,a.useSelect)((t=>{const{getCurrentProductType:e}=t(S);return{selectedProductType:e()}}),[]);if(!((t,e,o)=>{if(0!==t.id)return""!==e;const r=(0,u.getSetting)("productTypesWithoutStockIndicator",["external","grouped","variable"]),s=o||(null==t?void 0:t.type);return!r.includes(s)})(d,p,null==g?void 0:g.slug))return null;const m=0===d.id,k=d.low_stock_remaining;return(0,r.createElement)("div",{className:(0,n.A)(e,{[`${i}__stock-indicator`]:i,[`wc-block-components-product-stock-indicator--${y}`]:y,"wc-block-components-product-stock-indicator--in-stock":m,"wc-block-components-product-stock-indicator--low-stock":!!k,...t.isDescendantOfAllProducts&&{[o.className]:o.className,"wc-block-components-product-stock-indicator wp-block-woocommerce-product-stock-indicator":!0}}),...t.isDescendantOfAllProducts&&{style:o.style}},m?(0,s.__)("In stock","woocommerce"):p)},w=t=>{const{product:e}=(0,c.useProductDataContext)();return 0===e.id?(0,r.createElement)(h,{...t}):(0,i.withProductDataContext)(h)(t)}},4487:(t,e,o)=>{"use strict";o.d(e,{p:()=>u});var r=o(851),s=o(3993),n=o(1194),c=o(9786);function l(t={}){const e={};return(0,c.getCSSRules)(t,{selector:""}).forEach((t=>{e[t.key]=t.value})),e}function i(t,e){return t&&e?`has-${(0,n.c)(e)}-${t}`:""}const u=t=>{const e=(t=>{const e=(0,s.isObject)(t)?t:{style:{}};let o=e.style;return(0,s.isString)(o)&&(o=JSON.parse(o)||{}),(0,s.isObject)(o)||(o={}),{...e,style:o}})(t),o=function(t){var e,o,n,c,u,a,d;const{backgroundColor:p,textColor:y,gradient:g,style:m}=t,k=i("background-color",p),v=i("color",y),f=function(t){if(t)return`has-${t}-gradient-background`}(g),T=f||(null==m||null===(e=m.color)||void 0===e?void 0:e.gradient);return{className:(0,r.A)(v,f,{[k]:!T&&!!k,"has-text-color":y||(null==m||null===(o=m.color)||void 0===o?void 0:o.text),"has-background":p||(null==m||null===(n=m.color)||void 0===n?void 0:n.background)||g||(null==m||null===(c=m.color)||void 0===c?void 0:c.gradient),"has-link-color":(0,s.isObject)(null==m||null===(u=m.elements)||void 0===u?void 0:u.link)?null==m||null===(a=m.elements)||void 0===a||null===(d=a.link)||void 0===d?void 0:d.color:void 0}),style:l({color:(null==m?void 0:m.color)||{}})}}(e),n=function(t){var e;const o=(null===(e=t.style)||void 0===e?void 0:e.border)||{};return{className:function(t){var e;const{borderColor:o,style:s}=t,n=o?i("border-color",o):"";return(0,r.A)({"has-border-color":!!o||!(null==s||null===(e=s.border)||void 0===e||!e.color),[n]:!!n})}(t),style:l({border:o})}}(e),c=function(t){var e;return{className:void 0,style:l({spacing:(null===(e=t.style)||void 0===e?void 0:e.spacing)||{}})}}(e),u=(t=>{const e=(0,s.isObject)(t.style.typography)?t.style.typography:{},o=(0,s.isString)(e.fontFamily)?e.fontFamily:"";return{className:t.fontFamily?`has-${t.fontFamily}-font-family`:o,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}}})(e);return{className:(0,r.A)(u.className,o.className,n.className,c.className),style:{...u.style,...o.style,...n.style,...c.style}}}},9644:()=>{}}]);