geno/wp-content/plugins/woocommerce/packages/woocommerce-blocks/build/single-product.js

8 lines
34 KiB
JavaScript
Raw Normal View History

2024-02-01 17:24:18 +05:30
(()=>{var e,t,r,o={9252:(e,t,r)=>{"use strict";r.d(t,{R:()=>o});let o=function(e){return e.SINGLE="single",e.THUMBNAIL="thumbnail",e}({})},8916:(e,t,r)=>{"use strict";r.d(t,{V:()=>o});const o=(e,t)=>e.reduce(((e,r)=>(e[String(t?r[t]:r)]=r,e)),{})},4649:(e,t,r)=>{"use strict";r.r(t);var o=r(4981),n=r(9196),c=r(1984),s=r(5795);const a=window.wc.wcBlocksRegistry;var l=r(9307),i=r(5271);r.p=i.VF,(0,a.registerBlockComponent)({blockName:"woocommerce/product-price",component:(0,l.lazy)((()=>Promise.all([r.e(2869),r.e(5579)]).then(r.bind(r,6669))))}),(0,a.registerBlockComponent)({blockName:"woocommerce/product-image",component:(0,l.lazy)((()=>Promise.all([r.e(2869),r.e(3706)]).then(r.bind(r,2097))))}),(0,a.registerBlockComponent)({blockName:"woocommerce/product-title",component:(0,l.lazy)((()=>Promise.all([r.e(2869),r.e(6925)]).then(r.bind(r,9136))))}),(0,a.registerBlockComponent)({blockName:"woocommerce/product-rating",component:(0,l.lazy)((()=>Promise.all([r.e(2869),r.e(7385)]).then(r.bind(r,1382))))}),(0,a.registerBlockComponent)({blockName:"woocommerce/product-rating-stars",component:(0,l.lazy)((()=>Promise.all([r.e(2869),r.e(118)]).then(r.bind(r,89))))}),(0,a.registerBlockComponent)({blockName:"woocommerce/product-rating-counter",component:(0,l.lazy)((()=>Promise.all([r.e(2869),r.e(2918)]).then(r.bind(r,5042))))}),(0,a.registerBlockComponent)({blockName:"woocommerce/product-average-rating",component:(0,l.lazy)((()=>Promise.all([r.e(2869),r.e(3037)]).then(r.bind(r,2043))))}),(0,a.registerBlockComponent)({blockName:"woocommerce/product-button",component:(0,l.lazy)((()=>Promise.all([r.e(2869),r.e(8771)]).then(r.bind(r,4113))))}),(0,a.registerBlockComponent)({blockName:"woocommerce/product-summary",component:(0,l.lazy)((()=>Promise.all([r.e(2869),r.e(8185)]).then(r.bind(r,8281))))}),(0,a.registerBlockComponent)({blockName:"woocommerce/product-sale-badge",component:(0,l.lazy)((()=>Promise.all([r.e(2869),r.e(5432)]).then(r.bind(r,4498))))}),(0,a.registerBlockComponent)({blockName:"woocommerce/product-sku",component:(0,l.lazy)((()=>Promise.all([r.e(2869),r.e(9870)]).then(r.bind(r,8130))))}),(0,a.registerBlockComponent)({blockName:"woocommerce/product-stock-indicator",component:(0,l.lazy)((()=>Promise.all([r.e(2869),r.e(5445)]).then(r.bind(r,789))))}),(0,a.registerBlockComponent)({blockName:"woocommerce/product-add-to-cart",component:(0,l.lazy)((()=>Promise.all([r.e(2869),r.e(5800)]).then(r.bind(r,6996))))});const d=JSON.parse('{"name":"woocommerce/single-product","version":"1.0.0","icon":"info","title":"Single Product","description":"Display a single product.","category":"woocommerce","keywords":["WooCommerce"],"supports":{"align":["wide","full"]},"attributes":{"isPreview":{"type":"boolean","default":false},"productId":{"type":"number"}},"example":{"attributes":{"isPreview":true}},"usesContext":["postId","postType","queryId"],"textdomain":"woocommerce","apiVersion":2,"$schema":"https://schemas.wp.org/trunk/block.json"}');var u=r(5609),m=r(5736),p=r(229);const g=(0,m.__)("Product Title","woocommerce");function b(e,{blockDescription:t,blockIcon:r,blockTitle:n,variationName:c,scope:s}){(0,o.registerBlockVariation)(e,{description:t,name:c,title:n,isActive:e=>e.__woocommerceNamespace===c,icon:{src:r},attributes:{__woocommerceNamespace:c},scope:s})}(0,n.createElement)(c.Z,{icon:p.Z,className:"wc-block-editor-components-block-icon"});const h="woocommerce/product-query/product-title";b("core/post-title",{blockDescription:(0,m.__)("Display the title of a product.","woocommerce"),blockIcon:(0,n.createElement)(u.Icon,{icon:p.Z}),blockTitle:g,variationName:h,scope:["block"]});var w=r(897);const v=(0,m.__)("Product Summary","woocommerce"),k=((0,n.createElement)(c.Z,{icon:w.Z,className:"wc-block-editor-components-block-icon"}),"woocommerce/product-query/product-summary");b("core/post-excerpt",{blockDescription:(0,m.__)("Display a short description about a product.","woocommerce"),blockIcon:(0,n.createElement)(u.Icon,{icon:w.Z}),blockTitle:v,variationName:k,scope:["block"]});var E=r(9252);const _=(0,n.createElement)(c.Z,{icon:s.Z,className:"wc-
/* Translators: %s search term */
noResults:(0,m.__)("No results for %s","woocommerce"),search:(0,m.__)("Search for items","woocommerce"),selected:e=>(0,m.sprintf)(/* translators: Number of items selected from list. */
(0,m._n)("%d item selected","%d items selected",e,"woocommerce"),e),updated:(0,m.__)("Search results updated.","woocommerce")},ee=(e,t=e)=>{const r=e.reduce(((e,t)=>{const r=t.parent||0;return e[r]||(e[r]=[]),e[r].push(t),e}),{}),o=(0,Y.V)(t,"id"),n=["0"],c=(e={})=>e.parent?[...c(o[e.parent]),e.name]:e.name?[e.name]:[],s=e=>e.map((e=>{const t=r[e.id];return n.push(""+e.id),{...e,breadcrumbs:c(o[e.parent]),children:t&&t.length?s(t):[]}})),a=s(r[0]||[]);return Object.entries(r).forEach((([e,t])=>{n.includes(e)||a.push(...s(t||[]))})),a},te=(e,t)=>{if(!t)return e;const r=new RegExp(`(${t.replace(/[-\/\\^$*+?.()|[\]{}]/g,"\\$&")})`,"ig");return e.split(r).map(((e,t)=>r.test(e)?(0,n.createElement)("strong",{key:t},e):(0,n.createElement)(l.Fragment,{key:t},e)))},re=({label:e})=>(0,n.createElement)("span",{className:"woocommerce-search-list__item-count"},e),oe=e=>{const{item:t,search:r}=e,o=t.breadcrumbs&&t.breadcrumbs.length;return(0,n.createElement)("span",{className:"woocommerce-search-list__item-label"},o?(0,n.createElement)("span",{className:"woocommerce-search-list__item-prefix"},1===(c=t.breadcrumbs).length?c.slice(0,1).toString():2===c.length?c.slice(0,1).toString()+" "+c.slice(-1).toString():c.slice(0,1).toString()+" … "+c.slice(-1).toString()):null,(0,n.createElement)("span",{className:"woocommerce-search-list__item-name"},te((0,K.decodeEntities)(t.name),r)));var c},ne=({countLabel:e,className:t,depth:r=0,controlId:o="",item:c,isSelected:s,isSingle:a,onSelect:i,search:d="",selected:m,useExpandedPanelId:p,...g})=>{var b,h;const[w,v]=p,k=null!=e&&void 0!==c.count&&null!==c.count,E=!(null===(b=c.breadcrumbs)||void 0===b||!b.length),_=!(null===(h=c.children)||void 0===h||!h.length),f=w===c.id,y=z()(["woocommerce-search-list__item",`depth-${r}`,t],{"has-breadcrumbs":E,"has-children":_,"has-count":k,"is-expanded":f,"is-radio-button":a}),S=g.name||`search-list-item-${o}`,P=`${S}-${c.id}`,N=(0,l.useCallback)((()=>{v(f?-1:Number(c.id))}),[f,c.id,v]);return _?(0,n.createElement)("div",{className:y,onClick:N,onKeyDown:e=>"Enter"===e.key||" "===e.key?N():null,role:"treeitem",tabIndex:0},a?(0,n.createElement)(n.Fragment,null,(0,n.createElement)("input",{type:"radio",id:P,name:S,value:c.value,onChange:i(c),onClick:e=>e.stopPropagation(),checked:s,className:"woocommerce-search-list__item-input",...g}),(0,n.createElement)(oe,{item:c,search:d}),k?(0,n.createElement)(re,{label:e||c.count}):null):(0,n.createElement)(n.Fragment,null,(0,n.createElement)(u.CheckboxControl,{className:"woocommerce-search-list__item-input",checked:s,...!s&&c.children.some((e=>m.find((t=>t.id===e.id))))?{indeterminate:!0}:{},label:te((0,K.decodeEntities)(c.name),d),onChange:()=>{s?i(Q(m,c.children,"id"))():i(function(e,t,r){const o=Q(t,e,"id");return[...e,...o]}(m,c.children))()},onClick:e=>e.stopPropagation()}),k?(0,n.createElement)(re,{label:e||c.count}):null)):(0,n.createElement)("label",{htmlFor:P,className:y},a?(0,n.createElement)(n.Fragment,null,(0,n.createElement)("input",{...g,type:"radio",id:P,name:S,value:c.value,onChange:i(c),checked:s,className:"woocommerce-search-list__item-input"}),(0,n.createElement)(oe,{item:c,search:d})):(0,n.createElement)(u.CheckboxControl,{...g,id:P,name:S,className:"woocommerce-search-list__item-input",value:(0,K.decodeEntities)(c.value),label:te((0,K.decodeEntities)(c.name),d),onChange:i(c),checked:s}),k?(0,n.createElement)(re,{label:e||c.count}):null)},ce=ne;var se=r(5430),ae=r(906);r(5932);const le=({id:e,label:t,popoverContents:r,remove:o,screenReaderLabel:s,className:a=""})=>{const[i,d]=(0,l.useState)(!1),p=(0,N.useInstanceId)(le);if(s=s||t,!t)return null;t=(0,K.decodeEntities)(t);const g=z()("woocommerce-tag",a,{"has-remove":!!o}),b=`woocommerce-tag__label-${p}`,h=(0,n.createElement)(n.Fragment,null,(0,n.createElement)("span",{className:"screen-reader-text"},s),(0,n.createElement)("span",{"aria-hidden":"true"},t));return(0,n.createElement)("span",{className:g},r?(0,n.createElement)(u.Button,{className:"woocommerce-tag__text",id:b,onClick:()=>d(!0)},h):(0,n.createElement)("span",{className:"woocommerce-tag__tex
// Translators: %s label.
(0,m.__)("Remove %s","woocommerce"),t),"aria-describedby":b},(0,n.createElement)(c.Z,{icon:ae.Z,size:20,className:"clear-icon",role:"img"})))},ie=le;r(8462);const de=e=>(0,n.createElement)(ce,{...e}),ue=e=>{const{list:t,selected:r,renderItem:o,depth:c=0,onSelect:s,instanceId:a,isSingle:i,search:d,useExpandedPanelId:u}=e,[m]=u;return t?(0,n.createElement)(l.Fragment,null,t.map((t=>{var p,g;const b=null!==(p=t.children)&&void 0!==p&&p.length&&!i?t.children.every((({id:e})=>r.find((t=>t.id===e)))):!!r.find((({id:e})=>e===t.id)),h=(null===(g=t.children)||void 0===g?void 0:g.length)&&m===t.id;return(0,n.createElement)(l.Fragment,{key:t.id},(0,n.createElement)("li",null,o({item:t,isSelected:b,onSelect:s,isSingle:i,selected:r,search:d,depth:c,useExpandedPanelId:u,controlId:a})),h?(0,n.createElement)(ue,{...e,list:t.children,depth:c+1}):null)}))):null},me=({isLoading:e,isSingle:t,selected:r,messages:o,onChange:c,onRemove:s})=>{if(e||t||!r)return null;const a=r.length;return(0,n.createElement)("div",{className:"woocommerce-search-list__selected"},(0,n.createElement)("div",{className:"woocommerce-search-list__selected-header"},(0,n.createElement)("strong",null,o.selected(a)),a>0?(0,n.createElement)(u.Button,{isLink:!0,isDestructive:!0,onClick:()=>c([]),"aria-label":o.clear},(0,m.__)("Clear all","woocommerce")):null),a>0?(0,n.createElement)("ul",null,r.map(((e,t)=>(0,n.createElement)("li",{key:t},(0,n.createElement)(ie,{label:e.name,id:e.id,remove:s}))))):null)},pe=({filteredList:e,search:t,onSelect:r,instanceId:o,useExpandedPanelId:s,...a})=>{const{messages:l,renderItem:i,selected:d,isSingle:u}=a,p=i||de;return 0===e.length?(0,n.createElement)("div",{className:"woocommerce-search-list__list is-not-found"},(0,n.createElement)("span",{className:"woocommerce-search-list__not-found-icon"},(0,n.createElement)(c.Z,{icon:se.Z,role:"img"})),(0,n.createElement)("span",{className:"woocommerce-search-list__not-found-text"},t?(0,m.sprintf)(l.noResults,t):l.noItems)):(0,n.createElement)("ul",{className:"woocommerce-search-list__list"},(0,n.createElement)(ue,{useExpandedPanelId:s,list:e,selected:d,renderItem:p,onSelect:r,instanceId:o,isSingle:u,search:t}))},ge=e=>{const{className:t="",isCompact:r,isHierarchical:o,isLoading:c,isSingle:s,list:a,messages:i=X,onChange:d,onSearch:p,selected:g,type:b="text",debouncedSpeak:h}=e,[w,v]=(0,l.useState)(""),k=(0,l.useState)(-1),E=(0,N.useInstanceId)(ge),_=(0,l.useMemo)((()=>({...X,...i})),[i]),f=(0,l.useMemo)((()=>((e,t,r)=>{if(!t)return r?ee(e):e;const o=new RegExp(t.replace(/[-\/\\^$*+?.()|[\]{}]/g,"\\$&"),"i"),n=e.map((e=>!!o.test(e.name)&&e)).filter(Boolean);return r?ee(n,e):n})(a,w,o)),[a,w,o]);(0,l.useEffect)((()=>{h&&h(_.updated)}),[h,_]),(0,l.useEffect)((()=>{"function"==typeof p&&p(w)}),[w,p]);const y=(0,l.useCallback)((e=>()=>{s&&d([]);const t=g.findIndex((({id:t})=>t===e));d([...g.slice(0,t),...g.slice(t+1)])}),[s,g,d]),S=(0,l.useCallback)((e=>()=>{Array.isArray(e)?d(e):-1===g.findIndex((({id:t})=>t===e.id))?d(s?[e]:[...g,e]):y(e.id)()}),[s,y,d,g]),P=(0,l.useCallback)((e=>{const[t]=g.filter((t=>!e.find((e=>t.id===e.id))));y(t.id)()}),[y,g]);return(0,n.createElement)("div",{className:z()("woocommerce-search-list",t,{"is-compact":r,"is-loading":c,"is-token":"token"===b})},"text"===b&&(0,n.createElement)(me,{...e,onRemove:y,messages:_}),(0,n.createElement)("div",{className:"woocommerce-search-list__search"},"text"===b?(0,n.createElement)(u.TextControl,{label:_.search,type:"search",value:w,onChange:e=>v(e)}):(0,n.createElement)(u.FormTokenField,{disabled:c,label:_.search,onChange:P,onInputChange:e=>v(e),suggestions:[],__experimentalValidateInput:()=>!1,value:c?[(0,m.__)("Loading…","woocommerce")]:g.map((e=>({...e,value:e.name}))),__experimentalShowHowTo:!1})),c?(0,n.createElement)("div",{className:"woocommerce-search-list__list"},(0,n.createElement)(u.Spinner,null)):(0,n.createElement)(pe,{...e,search:w,filteredList:f,messages:_,onSelect:S,instanceId:E,useExpandedPanelId:k}))},be=((0,u.withSpokenMessages)(ge),e=>t=>{let{selected:r}=t;r=void 0===r?null:r;const o=null===r;return Array.isArray(r)?(0
(0,m.__)("%1$d variations","woocommerce"),null===(v=l.details)||void 0===v?void 0:v.variations.length):null,name:`products-${o}`,"aria-label":t?(0,m.sprintf)(/* translators: %1$s is the product name, %2$d is the number of variations of that product. */
(0,m._n)("%1$s, has %2$d variation","%1$s, has %2$d variations",null===(k=l.details)||void 0===k||null===(E=k.variations)||void 0===E?void 0:E.length,"woocommerce"),l.name,null===(_=l.details)||void 0===_?void 0:_.variations.length):void 0})}const f=(0,W.x)(null===(r=l.details)||void 0===r?void 0:r.variation)?e:{...e,item:{...e.item,name:null===(c=l.details)||void 0===c?void 0:c.variation},"aria-label":`${l.breadcrumbs[0]}: ${null===(a=l.details)||void 0===a?void 0:a.variation}`};return(0,n.createElement)(ne,{...f,className:h,name:`variations-${o}`})}:()=>null),onSearch:l,messages:fe,isHierarchical:!0})}))),({selected:e,...t})=>{const[r,o]=(0,l.useState)(!0),[c,s]=(0,l.useState)(null),[a,d]=(0,l.useState)([]),u=i.Cm.productCount>100,m=async e=>{const t=await L(e);s(t),o(!1)},p=(0,l.useRef)(e);(0,l.useEffect)((()=>{O({selected:p.current}).then((e=>{d(e),o(!1)})).catch(m)}),[p]);const g=(0,he.y1)((t=>{O({selected:e,search:t}).then((e=>{d(e),o(!1)})).catch(m)}),400),b=(0,l.useCallback)((e=>{o(!0),g(e)}),[o,g]);return(0,n.createElement)(Ce,{...t,selected:e,error:c,products:a,isLoading:r,onSearch:u?b:null})})),Se=({attributes:e,setAttributes:t})=>(0,n.createElement)(ye,{selected:e.productId||0,showVariations:!0,onChange:(e=[])=>{const r=e[0]?e[0].id:0;t({productId:r})}}),Pe=({isEditing:e,setIsEditing:t})=>(0,n.createElement)(M.BlockControls,null,(0,n.createElement)(u.ToolbarGroup,{controls:[{icon:"edit",title:(0,m.__)("Edit selected product","woocommerce"),onClick:()=>t(!e),isActive:e}]})),Ne=e=>e.map((([e,t={},r=[]])=>{const n=r?Ne(r):[];return(0,o.createBlock)(e,t,n)}));var Ce,xe=r(7968);const Ie=({isLoading:e,product:t,clientId:r})=>{const o=".wc-block-editor-single-product .wc-block-editor-layout",{replaceInnerBlocks:c}=(0,J.useDispatch)("core/block-editor"),s=(0,l.useCallback)((()=>{c(r,Ne(f),!1)}),[r,c]);return(0,n.createElement)(D.InnerBlockLayoutContextProvider,{parentName:d.name,parentClassName:o},(0,n.createElement)(D.ProductDataContextProvider,{product:t,isLoading:e},(0,n.createElement)(M.InspectorControls,null,(0,n.createElement)(u.PanelBody,{title:(0,m.__)("Layout","woocommerce"),initialOpen:!0},(0,n.createElement)(u.Button,{label:(0,m.__)("Reset layout to default","woocommerce"),onClick:s,isTertiary:!0,className:"wc-block-editor-single-product__reset-layout",icon:xe.Z},(0,m.__)("Reset layout","woocommerce")))),(0,n.createElement)("div",{className:o},(0,n.createElement)(M.BlockContextProvider,{value:{postId:null==t?void 0:t.id,postType:"product"}},(0,n.createElement)(M.InnerBlocks,{template:f,allowedBlocks:y,templateLock:!1})))))},Be=T((({attributes:e,setAttributes:t,error:r,getProduct:o,product:c,isLoading:s,clientId:a})=>{const{productId:i,isPreview:p}=e,[g,b]=(0,l.useState)(!i),h=(0,M.useBlockProps)(),w=(0,J.useSelect)((e=>p?e(H.PRODUCTS_STORE_NAME).getProducts({per_page:1}):null));return(0,l.useEffect)((()=>{var r;const o=w?null===(r=w[0])||void 0===r?void 0:r.id:null;o&&(t({...e,productId:o}),b(!1))}),[e,w,t]),r?(0,n.createElement)(q,{className:"wc-block-editor-single-product-error",error:r,isLoading:s,onRetry:o}):(0,n.createElement)("div",{...h},(0,n.createElement)(j,{header:(0,m.__)("Single Product Block Error","woocommerce")},(0,n.createElement)(Pe,{setIsEditing:b,isEditing:g}),g?(0,n.createElement)(u.Placeholder,{icon:_,label:d.title,className:"wc-block-editor-single-product"},d.description,(0,n.createElement)("div",{className:"wc-block-editor-single-product__selection"},(0,n.createElement)(Se,{attributes:e,setAttributes:t}),(0,n.createElement)(u.Button,{isSecondary:!0,onClick:()=>{b(!1)}},(0,m.__)("Done","woocommerce")))):(0,n.createElement)("div",null,(0,n.createElement)(M.InspectorControls,null,(0,n.createElement)(u.PanelBody,{title:(0,m.__)("Product","woocommerce"),initialOpen:!1},(0,n.createElement)(Se,{attributes:e,setAttributes:t}))),(0,n.createElement)(Z,{productId:i}),(0,n.createElement)(Ie,{clientId:a,product:c,isLoading:s}))))}));(0,o.registerBlockType)(d,{icon:_,edit:Be,save:()=>{const e=M.useBlockProps.save();return(0,n.createElement)("div",{...e},(0,n.createElement)(M.InnerBlocks.Content,n