JezK
Edit File: product-gallery.js
(()=>{"use strict";var e,t,o,r={7817:(e,t,o)=>{const r=window.wp.blocks,i=window.wp.data,l=window.wp.editor,n=window.wc.wcTypes;class s{blocks=new Map;initialized=!1;attemptedRegisteredBlocks=new Set;constructor(){this.initializeSubscriptions()}static getInstance(){return s.instance||(s.instance=new s),s.instance}initializeSubscriptions(){if(this.initialized)return;const e=(0,i.subscribe)(()=>{const t=(0,i.select)(l.store);if(!t)return;const o=t.getCurrentPostType();if(o)if("post"===o||"page"===o)e(),this.blocks.forEach(e=>{if(e.isAvailableOnPostEditor){const t=e.variationName||e.blockName;this.hasAttemptedRegistration(t)||this.registerBlock(e)}}),this.initialized=!0;else{e();const o=String(t.getEditedPostSlug());this.currentTemplateId=o,this.handleTemplateChange(void 0),(0,i.subscribe)(()=>{const e=this.currentTemplateId;this.currentTemplateId=String(t.getEditedPostSlug()),e!==this.currentTemplateId&&this.handleTemplateChange(e)},l.store),this.initialized=!0}})}handleTemplateChange(e){(this.currentTemplateId?.includes("single-product")||e?.includes("single-product"))&&this.blocks.forEach(e=>{this.unregisterBlock(e),this.registerBlock(e)})}hasAttemptedRegistration(e){return this.attemptedRegisteredBlocks.has(e)}unregisterBlock(e){const{blockName:t,isVariationBlock:o,variationName:i}=e;try{o&&i?((0,r.unregisterBlockVariation)(t,i),this.attemptedRegisteredBlocks.delete(i)):((0,r.unregisterBlockType)(t),this.attemptedRegisteredBlocks.delete(t))}catch(e){console.debug(`Failed to unregister block ${t}:`,e)}}registerBlock(e){const{blockName:t,settings:o,isVariationBlock:l,variationName:s,isAvailableOnPostEditor:c}=e;try{const e=s||t;if(this.hasAttemptedRegistration(e))return;const a=(0,i.select)("core/edit-site");if(!a&&!c)return;if(l)(0,r.registerBlockVariation)(t,o);else{const e=(0,n.isEmpty)(o?.ancestor)?["woocommerce/single-product"]:o?.ancestor,i=a&&this.currentTemplateId?.includes("single-product");(0,r.registerBlockType)(t,{...o,ancestor:i?void 0:e})}this.attemptedRegisteredBlocks.add(e)}catch(e){console.error(`Failed to register block ${t}:`,e)}}registerBlockConfig(e){const t=e.variationName||e.blockName;this.blocks.set(t,e),this.registerBlock(e)}}const c=JSON.parse('{"$schema":"https://schemas.wp.org/trunk/block.json","apiVersion":3,"name":"woocommerce/product-gallery","title":"Product Gallery","description":"Showcase your products relevant images and media.","category":"woocommerce","keywords":["WooCommerce"],"supports":{"align":true,"interactivity":true,"layout":{"default":{"type":"flex","flexWrap":"nowrap","orientation":"horizontal"},"allowOrientation":true,"allowEditing":true,"allowJustification":false},"email":true},"textdomain":"woocommerce","usesContext":["postId"],"providesContext":{"hoverZoom":"hoverZoom","fullScreenOnClick":"fullScreenOnClick"},"ancestor":["woocommerce/single-product"],"attributes":{"hoverZoom":{"type":"boolean","default":true},"fullScreenOnClick":{"type":"boolean","default":true}},"viewScript":"wc-product-gallery-frontend","example":{},"viewScriptModule":"woocommerce/product-gallery","editorStyle":"file:../woocommerce/product-gallery-editor.css","style":"file:../woocommerce/product-gallery-style.css"}'),a=window.wp.blockEditor,d=window.wc.wcBlocksSharedHocs,u=window.wc.wcBlocksSharedContext;var p=o(4921),h=o(7723);const m=window.wp.components;var g=o(790);const w=({attributes:e,setAttributes:t})=>{const{hoverZoom:o,fullScreenOnClick:r}=e;return(0,g.jsx)(a.InspectorControls,{children:(0,g.jsxs)(m.__experimentalToolsPanel,{label:(0,h.__)("Media Settings","woocommerce"),resetAll:()=>{t({hoverZoom:!0,fullScreenOnClick:!0})},children:[(0,g.jsx)(m.__experimentalToolsPanelItem,{hasValue:()=>!0!==o,label:(0,h.__)("Zoom while hovering","woocommerce"),onDeselect:()=>t({hoverZoom:!0}),isShownByDefault:!0,children:(0,g.jsx)(m.ToggleControl,{label:(0,h.__)("Zoom while hovering","woocommerce"),help:(0,h.__)("While hovering the image in the viewer will zoom in by 30%.","woocommerce"),checked:o,onChange:()=>t({hoverZoom:!o})})}),(0,g.jsx)(m.__experimentalToolsPanelItem,{hasValue:()=>!0!==r,label:(0,h.__)("Open pop-up when clicked","woocommerce"),onDeselect:()=>t({fullScreenOnClick:!0}),isShownByDefault:!0,children:(0,g.jsx)(m.ToggleControl,{label:(0,h.__)("Open pop-up when clicked","woocommerce"),help:(0,h.__)("Clicking on the image in the viewer will open a full-screen gallery experience.","woocommerce"),checked:r,onChange:()=>t({fullScreenOnClick:!r})})})]})})},b=[["woocommerce/product-gallery-thumbnails"],["woocommerce/product-gallery-large-image",{},[["woocommerce/product-image",{showProductLink:!1,showSaleBadge:!1}],["woocommerce/product-sale-badge",{align:"right"}],["woocommerce/product-gallery-large-image-next-previous"]]]];(e=>{const t=e.name;if(!t)return void console.error("registerProductBlockType: Block name is required for registration");const o=(({name:e,...t})=>t)(e),{isVariationBlock:r,variationName:i,isAvailableOnPostEditor:l,...n}={...o,...{isAvailableOnPostEditor:!0}||{}},c={blockName:t,settings:{...n},isVariationBlock:r??!1,variationName:i??void 0,isAvailableOnPostEditor:l??!1};s.getInstance().registerBlockConfig(c)})({...c,icon:()=>(0,g.jsxs)("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[(0,g.jsx)("path",{d:"M19 3H5C4.4 3 4 3.4 4 4V11C4 11.5 4.4 12 5 12H19C19.5 12 20 11.6 20 11V4C20 3.4 19.6 3 19 3ZM5.5 10.5V10.1L7.3 8.8L8.6 9.6C8.9 9.8 9.3 9.8 9.5 9.5L11 8.1L13.4 10.5H5.5ZM18.5 10.5H15.6L11.6 6.5C11.3 6.2 10.8 6.2 10.5 6.5L8.9 8L7.7 7.2C7.4 7 7.1 7 6.8 7.2L5.5 8.2V4.5H18.5V10.5Z",fill:"currentColor"}),(0,g.jsx)("rect",{x:"4.75",y:"15.5",width:"5",height:"4.5",rx:"1",stroke:"currentColor",strokeWidth:"1.5",fill:"none"}),(0,g.jsx)("rect",{x:"12.25",y:"15.5",width:"5",height:"4.5",rx:"1",stroke:"currentColor",strokeWidth:"1.5",fill:"none"})]}),edit:(0,d.withProductDataContext)(({attributes:e,setAttributes:t,context:o})=>{const{product:r,isLoading:i}=(0,u.useProductDataContext)(),l=r?.images||[],n=Boolean(o?.postId&&r?.id)&&!i&&l.length<=1,s=(0,a.useBlockProps)({className:(0,p.A)("wc-block-product-gallery",{"wc-block-product-gallery--has-one-or-no-images":n})});return(0,g.jsxs)("div",{...s,children:[(0,g.jsx)(a.InspectorControls,{children:(0,g.jsx)(w,{attributes:e,setAttributes:t})}),(0,g.jsx)(a.InnerBlocks,{allowedBlocks:["woocommerce/product-gallery-large-image","woocommerce/product-gallery-thumbnails"],template:b})]})}),save:()=>{const e=a.useBlockProps.save({className:"wc-block-product-gallery"}),t=a.useInnerBlocksProps.save(e);return(0,g.jsx)("div",{...t})}})},790:e=>{e.exports=window.ReactJSXRuntime},7723:e=>{e.exports=window.wp.i18n}},i={};function l(e){var t=i[e];if(void 0!==t)return t.exports;var o=i[e]={exports:{}};return r[e](o,o.exports,l),o.exports}l.m=r,e=[],l.O=(t,o,r,i)=>{if(!o){var n=1/0;for(d=0;d<e.length;d++){for(var[o,r,i]=e[d],s=!0,c=0;c<o.length;c++)(!1&i||n>=i)&&Object.keys(l.O).every(e=>l.O[e](o[c]))?o.splice(c--,1):(s=!1,i<n&&(n=i));if(s){e.splice(d--,1);var a=r();void 0!==a&&(t=a)}}return t}i=i||0;for(var d=e.length;d>0&&e[d-1][2]>i;d--)e[d]=e[d-1];e[d]=[o,r,i]},l.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return l.d(t,{a:t}),t},o=Object.getPrototypeOf?e=>Object.getPrototypeOf(e):e=>e.__proto__,l.t=function(e,r){if(1&r&&(e=this(e)),8&r)return e;if("object"==typeof e&&e){if(4&r&&e.__esModule)return e;if(16&r&&"function"==typeof e.then)return e}var i=Object.create(null);l.r(i);var n={};t=t||[null,o({}),o([]),o(o)];for(var s=2&r&&e;"object"==typeof s&&!~t.indexOf(s);s=o(s))Object.getOwnPropertyNames(s).forEach(t=>n[t]=()=>e[t]);return n.default=()=>e,l.d(i,n),i},l.d=(e,t)=>{for(var o in t)l.o(t,o)&&!l.o(e,o)&&Object.defineProperty(e,o,{enumerable:!0,get:t[o]})},l.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(e){if("object"==typeof window)return window}}(),l.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),l.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},l.j=6749,(()=>{var e={6749:0};l.O.j=t=>0===e[t];var t=(t,o)=>{var r,i,[n,s,c]=o,a=0;if(n.some(t=>0!==e[t])){for(r in s)l.o(s,r)&&(l.m[r]=s[r]);if(c)var d=c(l)}for(t&&t(o);a<n.length;a++)i=n[a],l.o(e,i)&&e[i]&&e[i][0](),e[i]=0;return l.O(d)},o=globalThis.webpackChunkwebpackWcBlocksMainJsonp=globalThis.webpackChunkwebpackWcBlocksMainJsonp||[];o.forEach(t.bind(null,0)),o.push=t.bind(null,o.push.bind(o))})();var n=l.O(void 0,[94],()=>l(7817));n=l.O(n),((this.wc=this.wc||{}).blocks=this.wc.blocks||{})["product-gallery"]=n})();