Current File : /home/mdkeenpw/www/wp-content/plugins/woocommerce/assets/client/blocks/product-specifications.js
(()=>{var e={9164:()=>{}},t={};function i(o){var s=t[o];if(void 0!==s)return s.exports;var n=t[o]={exports:{}};return e[o](n,n.exports,i),n.exports}(()=>{"use strict";const e=window.wp.blocks,t=window.wp.data,o=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}parseTemplateId(e){const t=(0,o.isNumber)(e)?void 0:e;return t?.split("//")[1]}initializeSubscriptions(){if(this.initialized)return;const e=(0,t.subscribe)((()=>{const i=(0,t.select)("core/edit-site"),o=(0,t.select)("core/edit-post");if(i||o)if(i){const o=i.getEditedPostId();e(),this.currentTemplateId="string"==typeof o?this.parseTemplateId(o):void 0,(0,t.subscribe)((()=>{const e=this.currentTemplateId;this.currentTemplateId=this.parseTemplateId(i.getEditedPostId()),e!==this.currentTemplateId&&this.handleTemplateChange(e)}),"core/edit-site"),this.initialized=!0}else o&&(e(),this.blocks.forEach((e=>{if(e.isAvailableOnPostEditor){const t=e.variationName||e.blockName;this.hasAttemptedRegistration(t)||this.registerBlock(e)}})),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:i,isVariationBlock:o,variationName:s}=t;try{o&&s?((0,e.unregisterBlockVariation)(i,s),this.attemptedRegisteredBlocks.delete(s)):((0,e.unregisterBlockType)(i),this.attemptedRegisteredBlocks.delete(i))}catch(e){console.debug(`Failed to unregister block ${i}:`,e)}}registerBlock(i){const{blockName:s,settings:n,isVariationBlock:r,variationName:c,isAvailableOnPostEditor:l}=i;try{const i=c||s;if(this.hasAttemptedRegistration(i))return;const a=(0,t.select)("core/edit-site");if(!a&&!l)return;if(r)(0,e.registerBlockVariation)(s,n);else{const t=(0,o.isEmpty)(n?.ancestor)?["woocommerce/single-product"]:n?.ancestor,i=a&&this.currentTemplateId?.includes("single-product");(0,e.registerBlockType)(s,{...n,ancestor:i?void 0:t})}this.attemptedRegisteredBlocks.add(i)}catch(e){console.error(`Failed to register block ${s}:`,e)}}registerBlockConfig(e){const t=e.variationName||e.blockName;this.blocks.set(t,e),this.registerBlock(e)}}const n=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}}}'),r=window.wp.blockEditor,c=window.wp.i18n,l=window.ReactJSXRuntime,a=window.wc.data,d=window.wp.components,u={product:null,isLoadingProduct:!1},p=window.wp.primitives,m=(0,l.jsxs)(p.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",children:[(0,l.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,l.jsx)("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M8 13.25V11.75H16V13.25L8 13.25Z"}),(0,l.jsx)("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M8 16.25V14.75H16V16.25H8Z"})]});i(9164),(e=>{const t=e.name;if(!t)return void console.error("registerProductBlockType: Block name is required for registration");const i=(({name:e,...t})=>t)(e),{isVariationBlock:o,variationName:n,isAvailableOnPostEditor:r,...c}={...i,...{isAvailableOnPostEditor:!0}||{}},l={blockName:t,settings:{...c},isVariationBlock:null!=o&&o,variationName:null!=n?n:void 0,isAvailableOnPostEditor:null!=r&&r};s.getInstance().registerBlockConfig(l)})({...n,icon:m,edit:({context:{postId:e,postType:i},clientId:o,attributes:s,setAttributes:n})=>{const{showWeight:p,showDimensions:m,showAttributes:h}=s,g=(0,r.useBlockProps)({className:"wp-block-table"}),w=!(!e||"product"!==i),{dimensionUnit:b,weightUnit:k,isLoadingUnits:f}=(0,t.useSelect)((e=>{const{getOption:t}=e(a.optionsStore);return{dimensionUnit:t("woocommerce_dimension_unit"),weightUnit:t("woocommerce_weight_unit"),isLoadingUnits:!e(a.optionsStore).hasFinishedResolution("getOption",["woocommerce_dimension_unit"])||!e(a.optionsStore).hasFinishedResolution("getOption",["woocommerce_weight_unit"])}}),[]),{product:v,isLoadingProduct:_}=(0,t.useSelect)((t=>{if(!e)return u;const{getProduct:i}=t(a.productsStore);return{product:i(Number(e)),isLoadingProduct:!t(a.productsStore).hasFinishedResolution("getProduct",[Number(e)])}}),[e]),{hasInvalidContext:C,warningElement:x}=(({clientId:e,postType:i,blockName:o})=>({hasInvalidContext:(0,t.useSelect)((t=>t(r.store).getBlockParentsByBlockName(e,"core/post-template").length>0&&"product"!==i),[e,i]),warningElement:(0,l.jsx)("div",{...(0,r.useBlockProps)(),children:(0,l.jsx)(r.Warning,{children:(0,c.sprintf)(/* translators: %s: block name */ /* translators: %s: block name */
(0,c.__)("The %s block requires a product context. When used in a Query Loop, the Query Loop must be configured to display products.","woocommerce"),o)})})}))({clientId:o,postType:i,blockName:(0,c.__)("Product Specifications","woocommerce")});if(C)return x;if(f||_&&w)return(0,l.jsx)("div",{...g,children:(0,l.jsx)("span",{className:"wc-product-specifications__loading",children:(0,c.__)("Loading…","woocommerce")})});if(e&&!v)return(0,l.jsx)("div",{...g,children:(0,l.jsx)("p",{children:(0,c.__)("No product found","woocommerce")})});const j={};return p&&(j.weight={label:(0,c.__)("Weight","woocommerce"),value:""},j.weight.value=w?v?.weight?`${v.weight} ${k}`:"":`10 ${k}`),m&&(j.dimensions={label:(0,c.__)("Dimensions","woocommerce"),value:""},j.dimensions.value=w?v?.dimensions?((e,t)=>{if(!e)return"";const i=["length","width","height"].map((t=>e[t])).filter((e=>"string"==typeof e&&e.length>0));return 0===i.length?"":`${i.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,c.__)("Test Attribute","woocommerce"),value:(0,c.__)("First, Second, Third","woocommerce")}),(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)(r.InspectorControls,{children:(0,l.jsxs)(d.PanelBody,{title:(0,c.__)("Display Settings","woocommerce"),children:[(0,l.jsx)(d.ToggleControl,{label:(0,c.__)("Show Weight","woocommerce"),checked:p,onChange:()=>n({showWeight:!p})}),(0,l.jsx)(d.ToggleControl,{label:(0,c.__)("Show Dimensions","woocommerce"),checked:m,onChange:()=>n({showDimensions:!m})}),(0,l.jsx)(d.ToggleControl,{label:(0,c.__)("Show Attributes","woocommerce"),checked:h,onChange:()=>n({showAttributes:!h})})]})}),(0,l.jsx)("figure",{...g,children:(0,l.jsxs)("table",{children:[(0,l.jsx)("thead",{className:"screen-reader-text",children:(0,l.jsxs)("tr",{children:[(0,l.jsx)("th",{children:(0,c.__)("Attributes","woocommerce")}),(0,l.jsx)("th",{children:(0,c.__)("Value","woocommerce")})]})}),(0,l.jsx)("tbody",{children:Object.entries(j).map((([e,t])=>t.value&&(0,l.jsxs)("tr",{className:`wp-block-product-specifications-item wc-block-product-specifications-item-${e}`,children:[(0,l.jsx)("th",{scope:"row",className:"wp-block-product-specifications-item__label",children:t.label}),(0,l.jsx)("td",{className:"wp-block-product-specifications-item__value",children:t.value})]},e)))})]})})]})}})})(),((this.wc=this.wc||{}).blocks=this.wc.blocks||{})["product-specifications"]={}})();