← Back
Editing: product-reviews.js
(()=>{"use strict";const e=window.wp.blocks,t=window.wp.data,o="core/editor",i=window.wc.wcTypes;class r{blocks=new Map;initialized=!1;attemptedRegisteredBlocks=new Set;constructor(){this.initializeSubscriptions()}static getInstance(){return r.instance||(r.instance=new r),r.instance}initializeSubscriptions(){if(this.initialized)return;const e=(0,t.subscribe)(()=>{const i=(0,t.select)(o);if(!i)return;const r=i.getCurrentPostType();if(r)if("post"===r||"page"===r)e(),this.blocks.forEach(e=>{if(e.isAvailableOnPostEditor){const t=e.variationName||e.metadata.name;this.hasAttemptedRegistration(t)||this.registerBlock(e)}}),this.initialized=!0;else{e();const r=String(i.getEditedPostSlug());this.currentTemplateId=r,this.handleTemplateChange(void 0),(0,t.subscribe)(()=>{const e=this.currentTemplateId;this.currentTemplateId=String(i.getEditedPostSlug()),e!==this.currentTemplateId&&this.handleTemplateChange(e)},o),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{metadata:o,isVariationBlock:i,variationName:r}=t;try{i&&r?((0,e.unregisterBlockVariation)(o.name,r),this.attemptedRegisteredBlocks.delete(r)):((0,e.unregisterBlockType)(o.name),this.attemptedRegisteredBlocks.delete(o.name))}catch(e){console.debug(`Failed to unregister block ${o.name}:`,e)}}registerBlock(o){const{metadata:r,isVariationBlock:n,variationName:s,isAvailableOnPostEditor:a}=o;try{const c=s||r.name;if(this.hasAttemptedRegistration(c))return;const l=(0,t.select)("core/edit-site");if(!l&&!a)return;if(n)(0,e.registerBlockVariation)(r.name,{...r,name:s||r.name});else{const t=(0,i.isEmpty)(r?.ancestor)?["woocommerce/single-product"]:r?.ancestor,n=l&&this.currentTemplateId?.includes("single-product"),{title:s,description:a,keywords:d,styles:m,variations:u,...p}=r,h=(0,e.registerBlockType)(r,{...p,ancestor:n?void 0:t});this.blocks.set(c,{...o,metadata:{...r,title:h?.title??r.title,description:h?.description??r.description}})}this.attemptedRegisteredBlocks.add(c)}catch(e){console.error(`Failed to register block ${r.name}:`,e)}}registerBlockConfig(e){const t=e.variationName||e.metadata.name;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-reviews","icon":"admin-comments","title":"Product Reviews","description":"Display a product\'s reviews","category":"woocommerce","textdomain":"woocommerce","attributes":{"tagName":{"type":"string","default":"div"}},"supports":{"interactivity":true,"align":["wide","full"],"html":false,"color":{"gradients":true,"heading":true,"link":true,"__experimentalDefaultControls":{"background":true,"text":true,"link":true}},"spacing":{"margin":true,"padding":true},"typography":{"fontSize":true,"lineHeight":true,"__experimentalFontFamily":true,"__experimentalFontWeight":true,"__experimentalFontStyle":true,"__experimentalTextTransform":true,"__experimentalTextDecoration":true,"__experimentalLetterSpacing":true,"__experimentalDefaultControls":{"fontSize":true}},"__experimentalBorder":{"radius":true,"color":true,"width":true,"style":true,"__experimentalDefaultControls":{"radius":true,"color":true,"width":true,"style":true}}},"usesContext":["postId","postType"],"viewScriptModule":"woocommerce/product-reviews"}'),s=window.wp.blockEditor,a=window.ReactJSXRuntime,c=window.wp.components,l=window.wp.i18n,d=[["woocommerce/product-reviews-title"],["woocommerce/product-review-template",{},[["core/columns",{},[["core/column",{width:"40px"},[["core/avatar",{size:40,style:{border:{radius:"20px"}}}]]],["core/column",{},[["core/group",{tagName:"div",layout:{type:"flex",flexWrap:"nowrap",justifyContent:"space-between"}},[["woocommerce/product-review-author-name",{fontSize:"small"}],["woocommerce/product-review-rating"]]],["core/group",{layout:{type:"flex"},style:{spacing:{margin:{top:"0px",bottom:"0px"}}}},[["woocommerce/product-review-date",{fontSize:"small"}]]],["woocommerce/product-review-content"]]]]]]],["woocommerce/product-reviews-pagination"],["woocommerce/product-review-form"]],m={article:(0,l.__)("The <article> element should represent a self-contained, syndicatable portion of the document.","woocommerce"),aside:(0,l.__)("The <aside> element should represent a portion of a document whose content is only indirectly related to the document's main content.","woocommerce"),div:(0,l.__)("The <div> element should only be used if the block is a design element with no semantic meaning.","woocommerce"),footer:(0,l.__)("The <footer> element should represent a footer for its nearest sectioning element (e.g.: <section>, <article>, <main> etc.).","woocommerce"),header:(0,l.__)("The <header> element should represent introductory content, typically a group of introductory or navigational aids.","woocommerce"),main:(0,l.__)("The <main> element should be used for the primary content of your document only.","woocommerce"),nav:(0,l.__)("The <nav> element should be used to identify groups of links that are intended to be used for website or page content navigation.","woocommerce"),section:(0,l.__)("The <section> element should represent a standalone portion of the document that can't be better represented by another element.","woocommerce")};((e,t)=>{if(!(e=>"string"==typeof e?.name)(e))return void console.error("registerProductBlockType: Block name is required for registration");const o={metadata:e,isVariationBlock:t?.isVariationBlock??!1,variationName:t?.variationName??void 0,isAvailableOnPostEditor:t?.isAvailableOnPostEditor??!1};r.getInstance().registerBlockConfig(o)})({...n,edit:({attributes:e,setAttributes:o,clientId:i,context:r})=>{const{tagName:n="div"}=e,u=(0,s.useBlockProps)(),p=(0,s.useInnerBlocksProps)(u,{template:d}),{hasInvalidContext:h,warningElement:g}=(({clientId:e,postType:o,blockName:i})=>({hasInvalidContext:(0,t.useSelect)(t=>t(s.store).getBlockParentsByBlockName(e,"core/post-template").length>0&&"product"!==o,[e,o]),warningElement:(0,a.jsx)("div",{...(0,s.useBlockProps)(),children:(0,a.jsx)(s.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:r.postType,blockName:(0,l.__)("Product Reviews","woocommerce")});return h?g:(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(s.InspectorControls,{group:"advanced",children:(0,a.jsx)(c.SelectControl,{__nextHasNoMarginBottom:!0,__next40pxDefaultSize:!0,label:(0,l.__)("HTML element","woocommerce"),options:[{label:(0,l.__)("Default (<div>)","woocommerce"),value:"div"},{label:"<section>",value:"section"},{label:"<aside>",value:"aside"}],value:n,onChange:e=>o({tagName:e}),help:m[n]})}),(0,a.jsx)(n,{...p})]})},save:function({attributes:{tagName:e="div"}}){const t=s.useBlockProps.save(),o=s.useInnerBlocksProps.save(t);return(0,a.jsx)(e,{...o})},deprecated:[{save:()=>null}]},{isAvailableOnPostEditor:!0}),((this.wc=this.wc||{}).blocks=this.wc.blocks||{})["product-reviews"]={}})();
Save File
Cancel