← Back
Editing: product-gallery-thumbnails.js
(()=>{"use strict";var e,t,o,l={5976:(e,t,o)=>{const l=window.wp.blocks;var r=o(10790);const a=window.wc.wcSettings,i=window.wp.blockEditor;var c=o(86087);const n=window.wc.wcEntities;var s=o(4921),u=o(27723);const m=window.wp.components;let b=function(e){return e.OVERLAY="overlay",e.OUTLINE="outline",e}({});const h=({attributes:e,setAttributes:t})=>{const{thumbnailSize:o,aspectRatio:l,activeThumbnailStyle:a}=e,i=[{value:"",label:(0,u.__)("Select Aspect Ratio","woocommerce"),disabled:!0},{value:"auto",label:(0,u.__)("Auto","woocommerce")},{value:"1",label:(0,u.__)("Square - 1:1","woocommerce")},{value:"4/3",label:(0,u.__)("Standard - 4:3","woocommerce")},{value:"3/4",label:(0,u.__)("Portrait - 3:4","woocommerce")},{value:"3/2",label:(0,u.__)("Classic - 3:2","woocommerce")},{value:"2/3",label:(0,u.__)("Classic Portrait - 2:3","woocommerce")},{value:"16/9",label:(0,u.__)("Wide - 16:9","woocommerce")},{value:"9/16",label:(0,u.__)("Tall - 9:16","woocommerce")}],c=[{value:b.OVERLAY,label:(0,u.__)("Overlay","woocommerce")},{value:b.OUTLINE,label:(0,u.__)("Outline","woocommerce")}];return(0,r.jsxs)(m.__experimentalToolsPanel,{label:(0,u.__)("Settings","woocommerce"),resetAll:()=>{t({thumbnailSize:"25%",aspectRatio:"1",activeThumbnailStyle:b.OVERLAY})},children:[(0,r.jsx)(m.__experimentalToolsPanelItem,{hasValue:()=>"25%"!==o,label:(0,u.__)("Thumbnail Size","woocommerce"),onDeselect:()=>t({thumbnailSize:"25%"}),isShownByDefault:!0,children:(0,r.jsx)(m.__experimentalUnitControl,{label:(0,u.__)("Thumbnail Size","woocommerce"),value:o,onChange:e=>{const o=Number(e?.replace("%","")||25),l=Math.min(Math.max(o,10),50);t({thumbnailSize:l+"%"})},units:[{value:"%",label:"%"}],min:10,max:50,step:1,size:"default",__next40pxDefaultSize:!0,help:(0,u.__)("Choose the size of each thumbnail in respect to the product image. If thumbnails container size gets bigger than the product image, thumbnails will turn to slider.","woocommerce")})}),(0,r.jsx)(m.__experimentalToolsPanelItem,{hasValue:()=>"1"!==l,label:(0,u.__)("Aspect Ratio","woocommerce"),onDeselect:()=>t({aspectRatio:"1"}),isShownByDefault:!0,children:(0,r.jsx)(m.SelectControl,{__next40pxDefaultSize:!0,multiple:!1,value:l,options:i,label:(0,u.__)("Aspect Ratio","woocommerce"),onChange:e=>{t({aspectRatio:e})},help:(0,u.__)("Applies the selected aspect ratio to product thumbnails.","woocommerce")})}),(0,r.jsx)(m.__experimentalToolsPanelItem,{hasValue:()=>a!==b.OVERLAY,label:(0,u.__)("Active Thumbnail Style","woocommerce"),onDeselect:()=>t({activeThumbnailStyle:b.OVERLAY}),isShownByDefault:!0,children:(0,r.jsx)(m.SelectControl,{__next40pxDefaultSize:!0,multiple:!1,value:a,options:c,label:(0,u.__)("Active Thumbnail Style","woocommerce"),onChange:e=>{e!==b.OVERLAY&&e!==b.OUTLINE||t({activeThumbnailStyle:e})},help:(0,u.__)("Choose how the active thumbnail is highlighted.","woocommerce")})})]})},p=JSON.parse('{"$schema":"https://schemas.wp.org/trunk/block.json","apiVersion":3,"name":"woocommerce/product-gallery-thumbnails","title":"Thumbnails","description":"Display the Thumbnails of a product.","category":"woocommerce","keywords":["WooCommerce"],"usesContext":["postId"],"textdomain":"woocommerce","ancestor":["woocommerce/product-gallery"],"attributes":{"thumbnailSize":{"type":"string","default":"25%"},"aspectRatio":{"type":"string","default":"1"},"activeThumbnailStyle":{"type":"string","default":"overlay"}},"supports":{"spacing":{"margin":true},"interactivity":true},"editorStyle":"file:../woocommerce/product-gallery-thumbnails-editor.css"}');(0,l.registerBlockType)(p,{icon:()=>(0,r.jsx)("svg",{width:"19",height:"19",viewBox:"0 0 19 19",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:(0,r.jsx)("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M13.375 1.5H1.625C1.55596 1.5 1.5 1.55596 1.5 1.625V9.87895L4.35871 8.33965C4.5696 8.22609 4.82204 8.22009 5.03808 8.3235L7.42329 9.46513L10.3126 7.39076C10.574 7.20308 10.926 7.20308 11.1874 7.39076L13.5 9.05108V1.625C13.5 1.55596 13.444 1.5 13.375 1.5ZM13.5 10.8976L10.75 8.92328L7.93741 10.9426C7.71497 11.1023 7.42319 11.1281 7.1762 11.0098L4.73428 9.84105L1.5 11.5826V13.375C1.5 13.444 1.55596 13.5 1.625 13.5H13.375C13.444 13.5 13.5 13.444 13.5 13.375V10.8976ZM1.625 0C0.727537 0 0 0.727538 0 1.625V13.375C0 14.2725 0.727538 15 1.625 15H13.375C14.2725 15 15 14.2725 15 13.375V1.625C15 0.727537 14.2725 0 13.375 0H1.625ZM17.25 5V16C17.25 16.6909 16.6909 17.25 16.0011 17.25H3V18.75H16.0011C17.5204 18.75 18.75 17.5183 18.75 16V5H17.25Z",fill:"#1E1E1E"})}),edit:({attributes:e,setAttributes:t,context:o})=>{const{thumbnailSize:l,aspectRatio:u,activeThumbnailStyle:m}=e,{product:b}=(0,n.useProduct)(o.postId),p=b?.images||[],d=p.length<=1,w=!Boolean(o.postId&&b?.id),_=p.length>0?(e=>e.slice(0,10).map(e=>({src:e?.src,alt:e?.alt})))(p):Array(10).fill({src:a.PLACEHOLDER_IMG_SRC,alt:""}),f=w||!d,v=(0,c.useRef)(null),[g,y]=(0,c.useState)({bottom:!1,right:!1});(0,c.useEffect)(()=>{if(!f)return;const e=v.current;if(!e)return;const t=new ResizeObserver(()=>{const t=(e=>{if(!e)return{top:!1,bottom:!1,left:!1,right:!1};const{scrollTop:t,scrollHeight:o,clientHeight:l,scrollLeft:r,scrollWidth:a,clientWidth:i}=e;return{top:t>3,bottom:t+l<o-3,left:r>3,right:r+i<a-3}})(e);y(t)});return t.observe(e),e.parentElement&&t.observe(e.parentElement),()=>{t.disconnect()}},[f,l]);const x=Number(l.replace("%","")),S=(0,s.A)("wc-block-product-gallery-thumbnails",`wc-block-product-gallery-thumbnails--active-${m}`,{"wc-block-product-gallery-thumbnails--overflow-right":g.right,"wc-block-product-gallery-thumbnails--overflow-bottom":g.bottom}),O=(0,i.useBlockProps)({className:S,style:{"--wc-block-product-gallery-thumbnails-size":x}}),j={aspectRatio:u};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(i.InspectorControls,{children:(0,r.jsx)(h,{attributes:e,setAttributes:t})}),f&&(0,r.jsx)("div",{...O,children:(0,r.jsx)("div",{ref:v,className:"wc-block-product-gallery-thumbnails__scrollable",children:_.map(({src:e,alt:t},o)=>{const l=(0,s.A)("wc-block-product-gallery-thumbnails__thumbnail__image",{"wc-block-product-gallery-thumbnails__thumbnail__image--is-active":0===o});return(0,r.jsx)("div",{className:"wc-block-product-gallery-thumbnails__thumbnail",children:(0,r.jsx)("img",{className:l,src:e,alt:t,loading:"lazy",style:j})},o)})})})]})},save:()=>null})},10790:e=>{e.exports=window.ReactJSXRuntime},86087:e=>{e.exports=window.wp.element},27723:e=>{e.exports=window.wp.i18n}},r={};function a(e){var t=r[e];if(void 0!==t)return t.exports;var o=r[e]={exports:{}};return l[e](o,o.exports,a),o.exports}a.m=l,e=[],a.O=(t,o,l,r)=>{if(!o){var i=1/0;for(u=0;u<e.length;u++){for(var[o,l,r]=e[u],c=!0,n=0;n<o.length;n++)(!1&r||i>=r)&&Object.keys(a.O).every(e=>a.O[e](o[n]))?o.splice(n--,1):(c=!1,r<i&&(i=r));if(c){e.splice(u--,1);var s=l();void 0!==s&&(t=s)}}return t}r=r||0;for(var u=e.length;u>0&&e[u-1][2]>r;u--)e[u]=e[u-1];e[u]=[o,l,r]},a.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return a.d(t,{a:t}),t},o=Object.getPrototypeOf?e=>Object.getPrototypeOf(e):e=>e.__proto__,a.t=function(e,l){if(1&l&&(e=this(e)),8&l)return e;if("object"==typeof e&&e){if(4&l&&e.__esModule)return e;if(16&l&&"function"==typeof e.then)return e}var r=Object.create(null);a.r(r);var i={};t=t||[null,o({}),o([]),o(o)];for(var c=2&l&&e;"object"==typeof c&&!~t.indexOf(c);c=o(c))Object.getOwnPropertyNames(c).forEach(t=>i[t]=()=>e[t]);return i.default=()=>e,a.d(r,i),r},a.d=(e,t)=>{for(var o in t)a.o(t,o)&&!a.o(e,o)&&Object.defineProperty(e,o,{enumerable:!0,get:t[o]})},a.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(e){if("object"==typeof window)return window}}(),a.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),a.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},a.j=6565,(()=>{var e={6565:0};a.O.j=t=>0===e[t];var t=(t,o)=>{var l,r,[i,c,n]=o,s=0;if(i.some(t=>0!==e[t])){for(l in c)a.o(c,l)&&(a.m[l]=c[l]);if(n)var u=n(a)}for(t&&t(o);s<i.length;s++)r=i[s],a.o(e,r)&&e[r]&&e[r][0](),e[r]=0;return a.O(u)},o=globalThis.webpackChunkwebpackWcBlocksMainJsonp=globalThis.webpackChunkwebpackWcBlocksMainJsonp||[];o.forEach(t.bind(null,0)),o.push=t.bind(null,o.push.bind(o))})();var i=a.O(void 0,[94],()=>a(5976));i=a.O(i),((this.wc=this.wc||{}).blocks=this.wc.blocks||{})["product-gallery-thumbnails"]=i})();
Save File
Cancel