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-description.js |
(()=>{"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 o=(0,t.select)("core/edit-site"),s=(0,t.select)("core/edit-post");if(o||s)if(o){const s=o.getEditedPostId();e(),this.currentTemplateId="string"==typeof s?this.parseTemplateId(s):void 0,(0,t.subscribe)((()=>{const e=this.currentTemplateId;this.currentTemplateId=this.parseTemplateId(o.getEditedPostId()),e!==this.currentTemplateId&&this.handleTemplateChange(e)}),"core/edit-site"),this.initialized=!0}else s&&(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:o,isVariationBlock:s,variationName:i}=t;try{s&&i?((0,e.unregisterBlockVariation)(o,i),this.attemptedRegisteredBlocks.delete(i)):((0,e.unregisterBlockType)(o),this.attemptedRegisteredBlocks.delete(o))}catch(e){console.debug(`Failed to unregister block ${o}:`,e)}}registerBlock(s){const{blockName:i,settings:r,isVariationBlock:n,variationName:a,isAvailableOnPostEditor:c}=s;try{const s=a||i;if(this.hasAttemptedRegistration(s))return;const l=(0,t.select)("core/edit-site");if(!l&&!c)return;if(n)(0,e.registerBlockVariation)(i,r);else{const t=(0,o.isEmpty)(r?.ancestor)?["woocommerce/single-product"]:r?.ancestor,s=l&&this.currentTemplateId?.includes("single-product");(0,e.registerBlockType)(i,{...r,ancestor:s?void 0:t})}this.attemptedRegisteredBlocks.add(s)}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 i=JSON.parse('{"$schema":"https://schemas.wp.org/trunk/block.json","apiVersion":3,"name":"woocommerce/product-description","title":"Product Description","description":"Displays the description of the product.","category":"woocommerce","textdomain":"woocommerce","usesContext":["postId","postType","queryId"],"ancestor":["woocommerce/single-product","woocommerce/product-template","core/post-template"],"supports":{"interactivity":{"clientNavigation":true},"align":["wide","full"],"html":false,"layout":true,"background":{"backgroundImage":true,"backgroundSize":true,"__experimentalDefaultControls":{"backgroundImage":true}},"dimensions":{"minHeight":true},"spacing":{"blockGap":true,"padding":true,"margin":true,"__experimentalDefaultControls":{"margin":false,"padding":false}},"color":{"gradients":true,"heading":true,"link":true,"__experimentalDefaultControls":{"background":false,"text":false}},"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}}}}'),r=window.wp.i18n,n=window.wp.blockEditor,a=window.wp.coreData,c=window.wp.element,l=window.ReactJSXRuntime;function d({parentLayout:t,layoutClassNames:o,userCanEdit:s,postType:i,postId:d}){const[,,p]=(0,a.useEntityProp)("postType",i,"content",d),u=(0,n.useBlockProps)({className:o}),m=(0,c.useMemo)((()=>p?.raw?(0,e.parse)(p.raw):[]),[p?.raw]),h=(0,n.__experimentalUseBlockPreview)({blocks:m,props:u,layout:t});return s?(0,l.jsx)("div",{...h}):p?.protected?(0,l.jsx)("div",{...u,children:(0,l.jsx)(n.Warning,{children:(0,r.__)("This content is password protected.","woocommerce")})}):(0,l.jsx)("div",{...u,dangerouslySetInnerHTML:{__html:p?.rendered}})}function p({layoutClassNames:e}){const t=(0,n.useBlockProps)({className:e});return(0,l.jsx)("div",{...t,children:(0,l.jsx)("p",{children:(0,r.__)("This block displays the product description. When viewing a product page, the description content will automatically appear here.","woocommerce")})})}function u({context:e={}}){const{postType:o,postId:s}=e,i=(0,n.useBlockProps)({className:"product-description__editable-content"}),[r,c,d]=(0,a.useEntityBlockEditor)("postType",o,{id:s}),u=(0,t.useSelect)((e=>e(a.store).getEntityRecord("postType",o,s)),[o,s]),m=!!u?.content?.raw||r?.length,h=(0,n.useInnerBlocksProps)(i,{value:r,onInput:c,onChange:d,template:m?void 0:[["core/paragraph"]]});return u?(0,l.jsx)("div",{...h}):(0,l.jsx)(p,{layoutClassNames:i.className})}function m(e){const{context:{postType:o,postId:s}={},layoutClassNames:i}=e,r=(n="postType",c=o,p=s,(0,t.useSelect)((e=>e(a.store).canUser("update",{kind:n,name:c,id:p})),[n,c,p]));var n,c,p;return void 0===r?null:r?(0,l.jsx)(u,{...e}):(0,l.jsx)(d,{parentLayout:e.parentLayout,layoutClassNames:i,userCanEdit:r,postType:o,postId:s})}function h(){const e=(0,n.useBlockProps)();return(0,l.jsx)("div",{...e,children:(0,l.jsx)(n.Warning,{children:(0,r.__)("Block cannot be rendered inside itself.","woocommerce")})})}const g=window.wp.primitives;(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:r,isAvailableOnPostEditor:n,...a}={...o,...{isAvailableOnPostEditor:!0}||{}},c={blockName:t,settings:{...a},isVariationBlock:null!=i&&i,variationName:null!=r?r:void 0,isAvailableOnPostEditor:null!=n&&n};s.getInstance().registerBlockConfig(c)})({...i,icon:(0,l.jsxs)(g.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"})]}),edit:function({context:e,__unstableLayoutClassNames:o,__unstableParentLayout:s,clientId:i}){const{postId:a,postType:c}=e,d=(0,n.useHasRecursion)(a),{hasInvalidContext:u,warningElement:g}=(({clientId:e,postType:o,blockName:s})=>({hasInvalidContext:(0,t.useSelect)((t=>t(n.store).getBlockParentsByBlockName(e,"core/post-template").length>0&&"product"!==o),[e,o]),warningElement:(0,l.jsx)("div",{...(0,n.useBlockProps)(),children:(0,l.jsx)(n.Warning,{children:(0,r.sprintf)(/* translators: %s: block name */ /* translators: %s: block name */ (0,r.__)("The %s block requires a product context. When used in a Query Loop, the Query Loop must be configured to display products.","woocommerce"),s)})})}))({clientId:i,postType:c,blockName:(0,r.__)("Product Description","woocommerce")});return u?g:a&&c&&d?(0,l.jsx)(h,{}):(0,l.jsx)(n.RecursionProvider,{uniqueId:a,children:a&&c?(0,l.jsx)(m,{context:e,parentLayout:s,layoutClassNames:o}):(0,l.jsx)(p,{layoutClassNames:o})})}}),((this.wc=this.wc||{}).blocks=this.wc.blocks||{})["product-description"]={}})();