← Back
Editing: product-image.js
(globalThis.webpackChunkwebpackWcBlocksMainJsonp=globalThis.webpackChunkwebpackWcBlocksMainJsonp||[]).push([[4232,4442],{7147:(e,t,o)=>{"use strict";o.d(t,{y:()=>r});var a=o(52619),i=o(47143),s=o(86087);const r=()=>({dispatchStoreEvent:(0,s.useCallback)((e,t={})=>{try{(0,a.doAction)(`experimental__woocommerce_blocks-${e}`,t)}catch(e){console.error(e)}},[]),dispatchCheckoutEvent:(0,s.useCallback)((e,t={})=>{try{(0,a.doAction)(`experimental__woocommerce_blocks-checkout-${e}`,{...t,storeCart:(0,i.select)("wc/store/cart").getCartData()})}catch(e){console.error(e)}},[])})},2374:(e,t,o)=>{"use strict";o.d(t,{p:()=>n});var a=o(4921),i=o(73993),s=o(25028),r=o(63512);const n=e=>{const t=(e=>{const t=(0,i.isObject)(e)?e:{style:{}};let o=t.style;return(0,i.isString)(o)&&(o=JSON.parse(o)||{}),(0,i.isObject)(o)||(o={}),{...t,style:o}})(e),o=(0,r.BK)(t),n=(0,r.aR)(t),c=(0,r.fo)(t),l=(0,s.x)(t);return{className:(0,a.A)(l.className,o.className,n.className,c.className),style:{...l.style,...o.style,...n.style,...c.style}}}},25028:(e,t,o)=>{"use strict";o.d(t,{x:()=>i});var a=o(73993);const i=e=>{const t=(0,a.isObject)(e.style.typography)?e.style.typography:{},o=(0,a.isString)(t.fontFamily)?t.fontFamily:"";return{className:e.fontFamily?`has-${e.fontFamily}-font-family`:o,style:{fontSize:e.fontSize?`var(--wp--preset--font-size--${e.fontSize})`:t.fontSize,fontStyle:t.fontStyle,fontWeight:t.fontWeight,letterSpacing:t.letterSpacing,lineHeight:t.lineHeight,textDecoration:t.textDecoration,textTransform:t.textTransform}}}},63512:(e,t,o)=>{"use strict";o.d(t,{BK:()=>l,aR:()=>d,fo:()=>p});var a=o(4921),i=o(67356),s=o(49786),r=o(73993);function n(e={}){const t={};return(0,s.getCSSRules)(e,{selector:""}).forEach(e=>{t[e.key]=e.value}),t}function c(e,t){return e&&t?`has-${(0,i.c)(t)}-${e}`:""}function l(e){const{backgroundColor:t,textColor:o,gradient:i,style:s}=e,l=c("background-color",t),d=c("color",o),p=function(e){if(e)return`has-${e}-gradient-background`}(i),u=p||s?.color?.gradient;return{className:(0,a.A)(d,p,{[l]:!u&&!!l,"has-text-color":o||s?.color?.text,"has-background":t||s?.color?.background||i||s?.color?.gradient,"has-link-color":(0,r.isObject)(s?.elements?.link)?s?.elements?.link?.color:void 0}),style:n({color:s?.color||{}})}}function d(e){const t=e.style?.border||{};return{className:function(e){const{borderColor:t,style:o}=e,i=t?c("border-color",t):"";return(0,a.A)({"has-border-color":!!t||!!o?.border?.color,[i]:!!i})}(e),style:n({border:t})}}function p(e){return{className:void 0,style:n({spacing:e.style?.spacing||{}})}}},60018:(e,t,o)=>{"use strict";o.d(t,{A:()=>x});var a=o(86087),i=o(27723),s=o(4921),r=o(15703),n=o(62796),c=o(2374),l=o(41616),d=o(7147),p=o(18537),u=o(73993),m=o(72334),g=(o(66222),o(83238)),h=o(10790);const y=e=>{const{aspectRatio:t,height:o,width:a,scale:i}=e;return{height:o,width:a,objectFit:i,aspectRatio:t}},f=({padding:e,paddingTop:t,paddingRight:o,paddingBottom:a,paddingLeft:i})=>{const s={};return void 0!==e&&(s.padding=e),void 0!==t&&(s.paddingTop=t),void 0!==o&&(s.paddingRight=o),void 0!==a&&(s.paddingBottom=a),void 0!==i&&(s.paddingLeft=i),s},b=e=>{const t=(0,r.getSetting)("placeholderImgSrcFullSize",r.PLACEHOLDER_IMG_SRC);return(0,h.jsx)("img",{...e,src:t,alt:"",width:void 0,height:void 0})},w=({image:e,loaded:t,fallbackAlt:o,width:a,scale:i,height:s,aspectRatio:r})=>{const{src:n,srcset:c,sizes:l,alt:d}=e||{},p={alt:d||o,hidden:!t,src:n,srcSet:c,sizes:l},u=y({height:s,width:a,scale:i,aspectRatio:r});return e?(0,h.jsx)("img",{style:u,"data-testid":"product-image",...p}):(0,h.jsx)(b,{style:u})},k=e=>{const{product:t}=e;return!(0,u.isEmpty)(t)&&(0,g.S)(e.showSaleBadge)},x=(0,l.withProductDataContext)(e=>{const{aspectRatio:t,children:o,className:l,height:u,imageId:x,imageSizing:S,scale:_,showProductLink:v=!0,style:C,width:R,isAdmin:N,product:A,isResolving:j,...B}=e,L=(0,c.p)(e),{padding:P,paddingTop:$,paddingRight:z,paddingBottom:E,paddingLeft:I,...D}=L.style,O=(0,a.isValidElement)(o)?(0,a.cloneElement)(o,{style:{...o.props.style,...f({padding:P,paddingTop:$,paddingRight:z,paddingBottom:E,paddingLeft:I})}}):o,{parentClassName:T}=(0,n.useInnerBlockLayoutContext)(),{product:F,isLoading:M}=(0,n.useProductDataContext)({isAdmin:N,product:A,isResolving:j}),{dispatchStoreEvent:H}=(0,d.y)(),W=(0,r.getSetting)("thumbnailAspectRatio",null),J=(0,g.O)(C,t,W,S),U=`wc-block-components-product-image--aspect-ratio-${J?J.replace("/","-"):"auto"}`;if(!F?.id){const e=y({height:u,width:R,scale:_,aspectRatio:J});return(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)("div",{className:(0,s.A)(l,"wc-block-components-product-image",U,{[`${T}__product-image`]:T},L.className),style:D,children:(0,h.jsx)(b,{style:e})}),O]})}const q=((e,t)=>e.images.length?t&&e.images.find(e=>e.id===t)||e.images[0]:null)(F,x);q&&(q.alt=q.alt||(0,p.decodeEntities)(F.name));const G=v?"a":a.Fragment,K=F?.name? // translators: %s is the product name. // translators: %s is the product name. (0,i.sprintf)((0,i.__)("Link to %s","woocommerce"),F.name):"",V={href:v?F?.permalink:void 0,...v&&{"aria-label":K,onClick:()=>{H("product-view-link",{product:F})}}};return(0,h.jsxs)(h.Fragment,{children:[(0,h.jsxs)("div",{className:(0,s.A)(l,"wc-block-components-product-image",U,{[`${T}__product-image`]:T},L.className),style:D,children:[k(e)&&(0,h.jsx)(m.default,{align:e.saleBadgeAlign||"right",...B}),(0,h.jsx)(G,{...!N&&v&&V,children:(0,h.jsx)(w,{fallbackAlt:(0,p.decodeEntities)(F.name),image:q,loaded:!M,width:R,height:u,scale:_,aspectRatio:J})})]}),O]})})},67763:(e,t,o)=>{"use strict";o.r(t),o.d(t,{default:()=>r});var a=o(41616),i=o(60018),s=o(86717);const r=(0,a.withFilteredAttributes)(s.attributes)(i.A)},266:(e,t,o)=>{"use strict";o.d(t,{e:()=>a});let a=function(e){return e.SINGLE="single",e.THUMBNAIL="thumbnail",e.CROPPED="cropped",e}({})},83238:(e,t,o)=>{"use strict";o.d(t,{O:()=>s,S:()=>i});var a=o(266);const i=e=>void 0===e||e,s=(e,t,o,i)=>e&&e.dimensions&&e.dimensions.aspectRatio&&"string"==typeof e.dimensions.aspectRatio?e.dimensions.aspectRatio:t&&"string"==typeof t?t:!i||i!==a.e.THUMBNAIL&&i!==a.e.CROPPED?void 0:o??void 0},72334:(e,t,o)=>{"use strict";o.r(t),o.d(t,{Block:()=>u,default:()=>m});var a=o(27723),i=o(70910),s=o(4921),r=o(14656),n=o(62796),c=o(2374),l=o(41616),d=(o(94324),o(34162)),p=o(10790);const u=e=>{const{className:t,align:o,isDescendentOfSingleProductTemplate:l}=e,u=(0,c.p)(e),{parentClassName:m}=(0,n.useInnerBlockLayoutContext)(),{product:g}=(0,n.useProductDataContext)();if(!(g.id&&g.on_sale||l))return null;const h="amount"===e.badgeContent||"percentage"===e.badgeContent;let y=e.saleText||(0,a.__)("Sale","woocommerce");if(h&&"grouped"!==g.type){const t="prices"in g?g.prices:void 0,o=(0,d.y)(t);if(o){if("percentage"===e.badgeContent&&0===o.percentage)return null;const s="percentage"===e.badgeContent?(0,a.sprintf)(/* translators: %s: discount percentage. %% is the percent sign. */ /* translators: %s: discount percentage. %% is the percent sign. */ (0,a.__)("%s%%","woocommerce"),o.percentage):(0,i.formatPrice)(o.amount,(0,i.getCurrencyFromPriceResponse)(t));y="variable"===g.type?(0,a.sprintf)(/* translators: %s: approximate discount for a variable product in the editor. */ /* translators: %s: approximate discount for a variable product in the editor. */ (0,a.__)("Up to %s","woocommerce"),s):`${e.prefix??""}${s}${e.suffix??""}`}}const f="string"==typeof o?`wc-block-components-product-sale-badge--align-${o}`:"";return(0,p.jsx)("div",{className:(0,s.A)("wc-block-components-product-sale-badge",t,f,{[`${m}__product-onsale`]:m},u.className),style:u.style,children:(0,p.jsx)(r.Label,{label:y,screenReaderLabel:(0,a.sprintf)(/* translators: %s: sale badge text. */ /* translators: %s: sale badge text. */ (0,a.__)("Product on sale: %s","woocommerce"),y)})})},m=(0,l.withProductDataContext)(u)},34162:(e,t,o)=>{"use strict";o.d(t,{y:()=>a});const a=e=>{const t=Number(e?.regular_price),o=t-Number(e?.price);return t>0&&o>0?{amount:o,percentage:Math.round(o/t*100)}:null}},66222:()=>{},94324:()=>{},86717:e=>{"use strict";e.exports=JSON.parse('{"name":"woocommerce/product-image","title":"Product Image","description":"Display the main product image.","category":"woocommerce-product-elements","attributes":{"showProductLink":{"type":"boolean","default":true},"showSaleBadge":{"type":"boolean","default":true},"saleBadgeAlign":{"type":"string","default":"right"},"imageSizing":{"type":"string","default":"single"},"productId":{"type":"number","default":0},"width":{"type":"string"},"height":{"type":"string"},"scale":{"type":"string","default":"cover"},"aspectRatio":{"type":"string"}},"supports":{"interactivity":{"clientNavigation":true},"html":false,"__experimentalBorder":{"color":true,"width":true,"style":true,"radius":true,"__experimentalSkipSerialization":true},"typography":{"fontSize":true,"__experimentalSkipSerialization":true},"spacing":{"margin":true,"padding":true,"__experimentalSkipSerialization":["padding"]},"dimensions":{"aspectRatio":true,"__experimentalSkipSerialization":true},"email":true},"selectors":{"root":".wp-block-woocommerce-product-image.wc-block-components-product-image, .wp-block-woocommerce-product-image .wc-block-components-product-image","spacing":{"padding":".wp-block-woocommerce-product-image .wc-block-components-product-image__inner-container"}},"ancestor":["woocommerce/all-products","woocommerce/single-product","woocommerce/product-template","core/post-template"],"usesContext":["imageId","postId","query","queryId"],"keywords":["WooCommerce"],"textdomain":"woocommerce","apiVersion":3,"$schema":"https://schemas.wp.org/trunk/block.json"}')}}]);
Save File
Cancel