File: /var/www/html/wp-content/plugins/woocommerce/assets/client/blocks/product-specifications.js
(()=>{var e={9164:()=>{}},t={};function o(i){var s=t[i];if(void 0!==s)return s.exports;var n=t[i]={exports:{}};return e[i](n,n.exports,o),n.exports}(()=>{"use strict";const e=window.wp.blocks,t=window.wp.data,i=window.wp.editor,s=window.wc.wcTypes;class n{blocks=new Map;initialized=!1;attemptedRegisteredBlocks=new Set;constructor(){this.initializeSubscriptions()}static getInstance(){return n.instance||(n.instance=new n),n.instance}initializeSubscriptions(){if(this.initialized)return;const e=(0,t.subscribe)((()=>{const o=(0,t.select)(i.store);if(!o)return;const s=o.getCurrentPostType();if(s)if("post"===s||"page"===s)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 s=String(o.getEditedPostSlug());this.currentTemplateId=s,this.handleTemplateChange(void 0),(0,t.subscribe)((()=>{const e=this.currentTemplateId;this.currentTemplateId=String(o.getEditedPostSlug()),e!==this.currentTemplateId&&this.handleTemplateChange(e)}),i.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(t){const{blockName:o,isVariationBlock:i,variationName:s}=t;try{i&&s?((0,e.unregisterBlockVariation)(o,s),this.attemptedRegisteredBlocks.delete(s)):((0,e.unregisterBlockType)(o),this.attemptedRegisteredBlocks.delete(o))}catch(e){console.debug(`Failed to unregister block ${o}:`,e)}}registerBlock(o){const{blockName:i,settings:n,isVariationBlock:r,variationName:c,isAvailableOnPostEditor:l}=o;try{const o=c||i;if(this.hasAttemptedRegistration(o))return;const a=(0,t.select)("core/edit-site");if(!a&&!l)return;if(r)(0,e.registerBlockVariation)(i,n);else{const t=(0,s.isEmpty)(n?.ancestor)?["woocommerce/single-product"]:n?.ancestor,o=a&&this.currentTemplateId?.includes("single-product");(0,e.registerBlockType)(i,{...n,ancestor:o?void 0:t})}this.attemptedRegisteredBlocks.add(o)}catch(e){console.error(`Failed to register block ${i}:`,e)}}registerBlockConfig(e){const t=e.variationName||e.blockName;this.blocks.set(t,e),this.registerBlock(e)}}const r=JSON.parse('{"$schema":"https://schemas.wp.org/trunk/block.json","apiVersion":3,"name":"woocommerce/product-specifications","version":"1.0.0","title":"Product Specifications","description":"Display product weight, dimensions, and attributes.","category":"woocommerce","keywords":["attributes","weight","dimensions","additional information"],"textdomain":"woocommerce","ancestor":["woocommerce/single-product","woocommerce/product-template","core/post-template"],"attributes":{"showWeight":{"type":"boolean","default":true},"showDimensions":{"type":"boolean","default":true},"showAttributes":{"type":"boolean","default":true}},"usesContext":["postId","postType"],"supports":{"html":false,"align":["wide","full"],"spacing":{"margin":true,"padding":true},"typography":{"fontSize":true,"lineHeight":true}}}'),c=window.wp.blockEditor,l=window.wp.i18n,a=window.ReactJSXRuntime,d=window.wc.data,u=window.wp.components,p={product:null,isLoadingProduct:!1},m=window.wp.primitives,h=(0,a.jsxs)(m.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",children:[(0,a.jsx)("path",{fillRule:"evenodd",clipRule:"evenodd",fill:"currentColor",d:"M5 5.5H19C19.1326 5.5 19.2598 5.55268 19.3536 5.64645C19.4473 5.74021 19.5 5.86739 19.5 6V7.5C19.5 7.63261 19.4473 7.75979 19.3536 7.85355C19.2598 7.94732 19.1326 8 19 8H5C4.86739 8 4.74021 7.94732 4.64645 7.85355C4.55268 7.75979 4.5 7.63261 4.5 7.5V6C4.5 5.86739 4.55268 5.74021 4.64645 5.64645C4.74021 5.55268 4.86739 5.5 5 5.5V5.5ZM4 9.232C3.69597 9.05647 3.4435 8.804 3.26796 8.49997C3.09243 8.19594 3.00001 7.85106 3 7.5V6C3 5.46957 3.21071 4.96086 3.58579 4.58579C3.96086 4.21071 4.46957 4 5 4H19C19.5304 4 20.0391 4.21071 20.4142 4.58579C20.7893 4.96086 21 5.46957 21 6V7.5C21 7.85106 20.9076 8.19594 20.732 8.49997C20.5565 8.804 20.304 9.05647 20 9.232V18C20 18.5304 19.7893 19.0391 19.4142 19.4142C19.0391 19.7893 18.5304 20 18 20H6C5.46957 20 4.96086 19.7893 4.58579 19.4142C4.21071 19.0391 4 18.5304 4 18V9.232ZM5.5 9.5V18C5.5 18.1326 5.55268 18.2598 5.64645 18.3536C5.74021 18.4473 5.86739 18.5 6 18.5H18C18.1326 18.5 18.2598 18.4473 18.3536 18.3536C18.4473 18.2598 18.5 18.1326 18.5 18V9.5H5.5Z"}),(0,a.jsx)("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M8 13.25V11.75H16V13.25L8 13.25Z"}),(0,a.jsx)("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M8 16.25V14.75H16V16.25H8Z"})]});o(9164),(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:i,variationName:s,isAvailableOnPostEditor:r,...c}={...o,...{isAvailableOnPostEditor:!0}||{}},l={blockName:t,settings:{...c},isVariationBlock:null!=i&&i,variationName:null!=s?s:void 0,isAvailableOnPostEditor:null!=r&&r};n.getInstance().registerBlockConfig(l)})({...r,icon:h,edit:({context:{postId:e,postType:o},clientId:i,attributes:s,setAttributes:n})=>{const{showWeight:r,showDimensions:m,showAttributes:h}=s,g=(0,c.useBlockProps)({className:"wp-block-table"}),w=!(!e||"product"!==o),{dimensionUnit:b,weightUnit:k,isLoadingUnits:f}=(0,t.useSelect)((e=>{const{getOption:t}=e(d.optionsStore);return{dimensionUnit:t("woocommerce_dimension_unit"),weightUnit:t("woocommerce_weight_unit"),isLoadingUnits:!e(d.optionsStore).hasFinishedResolution("getOption",["woocommerce_dimension_unit"])||!e(d.optionsStore).hasFinishedResolution("getOption",["woocommerce_weight_unit"])}}),[]),{product:v,isLoadingProduct:_}=(0,t.useSelect)((t=>{if(!e)return p;const{getProduct:o}=t(d.productsStore);return{product:o(Number(e)),isLoadingProduct:!t(d.productsStore).hasFinishedResolution("getProduct",[Number(e)])}}),[e]),{hasInvalidContext:C,warningElement:x}=(({clientId:e,postType:o,blockName:i})=>({hasInvalidContext:(0,t.useSelect)((t=>t(c.store).getBlockParentsByBlockName(e,"core/post-template").length>0&&"product"!==o),[e,o]),warningElement:(0,a.jsx)("div",{...(0,c.useBlockProps)(),children:(0,a.jsx)(c.Warning,{children:(0,l.sprintf)(/* translators: %s: block name */ /* translators: %s: block name */
(0,l.__)("The %s block requires a product context. When used in a Query Loop, the Query Loop must be configured to display products.","woocommerce"),i)})})}))({clientId:i,postType:o,blockName:(0,l.__)("Product Specifications","woocommerce")});if(C)return x;if(f||_&&w)return(0,a.jsx)("div",{...g,children:(0,a.jsx)("span",{className:"wc-product-specifications__loading",children:(0,l.__)("Loading…","woocommerce")})});if(e&&!v)return(0,a.jsx)("div",{...g,children:(0,a.jsx)("p",{children:(0,l.__)("No product found","woocommerce")})});const j={};return r&&(j.weight={label:(0,l.__)("Weight","woocommerce"),value:""},j.weight.value=w?v?.weight?`${v.weight} ${k}`:"":`10 ${k}`),m&&(j.dimensions={label:(0,l.__)("Dimensions","woocommerce"),value:""},j.dimensions.value=w?v?.dimensions?((e,t)=>{if(!e)return"";const o=["length","width","height"].map((t=>e[t])).filter((e=>"string"==typeof e&&e.length>0));return 0===o.length?"":`${o.join(" × ")} ${t}`})(v.dimensions,b):"":`10 × 10 × 10 ${b}`),h&&(w?v?.attributes&&v.attributes.forEach((e=>{j[e.name.toLowerCase()]={label:e.name,value:e.options.join(", ")}})):j.test_attribute={label:(0,l.__)("Test Attribute","woocommerce"),value:(0,l.__)("First, Second, Third","woocommerce")}),(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(c.InspectorControls,{children:(0,a.jsxs)(u.PanelBody,{title:(0,l.__)("Display Settings","woocommerce"),children:[(0,a.jsx)(u.ToggleControl,{label:(0,l.__)("Show Weight","woocommerce"),checked:r,onChange:()=>n({showWeight:!r})}),(0,a.jsx)(u.ToggleControl,{label:(0,l.__)("Show Dimensions","woocommerce"),checked:m,onChange:()=>n({showDimensions:!m})}),(0,a.jsx)(u.ToggleControl,{label:(0,l.__)("Show Attributes","woocommerce"),checked:h,onChange:()=>n({showAttributes:!h})})]})}),(0,a.jsx)("figure",{...g,children:(0,a.jsxs)("table",{children:[(0,a.jsx)("thead",{className:"screen-reader-text",children:(0,a.jsxs)("tr",{children:[(0,a.jsx)("th",{children:(0,l.__)("Attributes","woocommerce")}),(0,a.jsx)("th",{children:(0,l.__)("Value","woocommerce")})]})}),(0,a.jsx)("tbody",{children:Object.entries(j).map((([e,t])=>t.value&&(0,a.jsxs)("tr",{className:`wp-block-product-specifications-item wc-block-product-specifications-item-${e}`,children:[(0,a.jsx)("th",{scope:"row",className:"wp-block-product-specifications-item__label",children:t.label}),(0,a.jsx)("td",{className:"wp-block-product-specifications-item__value",children:t.value})]},e)))})]})})]})}})})(),((this.wc=this.wc||{}).blocks=this.wc.blocks||{})["product-specifications"]={}})();