PK
Current Path : /home/wallqcyy/www/wp-content/plugins/woocommerce/assets/client/blocks/ |
Current File : //home/wallqcyy/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:a}=i;try{const i=c||s;if(this.hasAttemptedRegistration(i))return;const l=(0,t.select)("core/edit-site");if(!l&&!a)return;if(r)(0,e.registerBlockVariation)(s,n);else{const t=(0,o.isEmpty)(n?.ancestor)?["woocommerce/single-product"]:n?.ancestor,i=l&&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,a=window.ReactJSXRuntime,l=window.wc.data,d=window.wp.components,u=window.wp.primitives,p=(0,a.jsxs)(u.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"})]});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}||{}},a={blockName:t,settings:{...c},isVariationBlock:null!=o&&o,variationName:null!=n?n:void 0,isAvailableOnPostEditor:null!=r&&r};s.getInstance().registerBlockConfig(a)})({...n,icon:p,edit:({context:{postId:e,postType:i},clientId:o,attributes:s,setAttributes:n})=>{const{showWeight:u,showDimensions:p,showAttributes:m}=s,h=(0,r.useBlockProps)({className:"wc-block-product-specifications"}),g=!(!e||"product"!==i),{dimensionUnit:w,weightUnit:b,isLoadingUnits:k}=(0,t.useSelect)((e=>{const{getOption:t}=e(l.optionsStore);return{dimensionUnit:t("woocommerce_dimension_unit"),weightUnit:t("woocommerce_weight_unit"),isLoadingUnits:!e(l.optionsStore).hasFinishedResolution("getOption",["woocommerce_dimension_unit"])||!e(l.optionsStore).hasFinishedResolution("getOption",["woocommerce_weight_unit"])}}),[]),{product:f,isLoadingProduct:v}=(0,t.useSelect)((t=>{const{getProduct:i}=t(l.productsStore);return{product:i(Number(e)),isLoadingProduct:!t(l.productsStore).hasFinishedResolution("getProduct",[Number(e)])}}),[e]),{hasInvalidContext:_,warningElement:C}=(({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,a.jsx)("div",{...(0,r.useBlockProps)(),children:(0,a.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(_)return C;if(k||v&&g)return(0,a.jsx)("div",{...h,children:(0,a.jsx)("span",{className:"wc-product-specifications__loading",children:(0,c.__)("Loading…","woocommerce")})});if(e&&!f)return(0,a.jsx)("div",{...h,children:(0,a.jsx)("p",{children:(0,c.__)("No product found","woocommerce")})});const x={};return u&&(x.weight={label:(0,c.__)("Weight","woocommerce"),value:""},x.weight.value=g?f.weight?`${f.weight} ${b}`:"":`10 ${b}`),p&&(x.dimensions={label:(0,c.__)("Dimensions","woocommerce"),value:""},x.dimensions.value=g?f.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}`})(f.dimensions,w):"":`10 × 10 × 10 ${w}`),m&&(g?f.attributes&&f.attributes.forEach((e=>{x[e.name.toLowerCase()]={label:e.name,value:e.options.join(", ")}})):x.test_attribute={label:(0,c.__)("Test Attribute","woocommerce"),value:(0,c.__)("First, Second, Third","woocommerce")}),(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(r.InspectorControls,{children:(0,a.jsxs)(d.PanelBody,{title:(0,c.__)("Display Settings","woocommerce"),children:[(0,a.jsx)(d.ToggleControl,{label:(0,c.__)("Show Weight","woocommerce"),checked:u,onChange:()=>n({showWeight:!u})}),(0,a.jsx)(d.ToggleControl,{label:(0,c.__)("Show Dimensions","woocommerce"),checked:p,onChange:()=>n({showDimensions:!p})}),(0,a.jsx)(d.ToggleControl,{label:(0,c.__)("Show Attributes","woocommerce"),checked:m,onChange:()=>n({showAttributes:!m})})]})}),(0,a.jsx)("table",{...h,children:(0,a.jsx)("tbody",{children:Object.entries(x).map((([e,t])=>t.value&&(0,a.jsxs)("tr",{className:`wc-block-product-specifications-item wc-block-product-specifications-item__${e}`,children:[(0,a.jsx)("th",{className:"wc-block-product-specifications-item__label",children:t.label}),(0,a.jsx)("td",{className:"wc-block-product-specifications-item__value",children:t.value})]},e)))})})]})}})})(),((this.wc=this.wc||{}).blocks=this.wc.blocks||{})["product-specifications"]={}})();