← Back
Editing: product-best-sellers.js
(()=>{var e,t,o,r={78220:(e,t,o)=>{"use strict";var r=o(11789),s=o(6626);const i=window.wp.blocks,n=JSON.parse('{"name":"woocommerce/product-best-sellers","title":"Best Selling Products","category":"woocommerce","keywords":["WooCommerce"],"description":"Display a grid of your all-time best selling products.","supports":{"interactivity":{"clientNavigation":false},"align":["wide","full"],"html":false,"inserter":false},"attributes":{"columns":{"type":"number","default":3},"rows":{"type":"number","default":3},"alignButtons":{"type":"boolean","default":false},"contentVisibility":{"type":"object","default":{"image":true,"title":true,"price":true,"rating":true,"button":true},"properties":{"image":{"type":"boolean","default":true},"title":{"type":"boolean","default":true},"price":{"type":"boolean","default":true},"rating":{"type":"boolean","default":true},"button":{"type":"boolean","default":true}}},"categories":{"type":"array","default":[]},"catOperator":{"type":"string","default":"any"},"isPreview":{"type":"boolean","default":false},"stockStatus":{"type":"array"},"editMode":{"type":"boolean","default":true},"orderby":{"type":"string","enum":["date","popularity","price_asc","price_desc","rating","title","menu_order"],"default":"popularity"}},"textdomain":"woocommerce","apiVersion":3,"$schema":"https://schemas.wp.org/trunk/block.json"}'),l=window.wp.blockEditor,c=window.wp.components,a=window.wp.serverSideRender;var d=o.n(a),m=o(10790);const h=(0,m.jsxs)("svg",{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 230 250",style:{width:"100%"},children:[(0,m.jsx)("title",{children:"Grid Block Preview"}),(0,m.jsx)("rect",{width:"65.374",height:"65.374",x:".162",y:".779",fill:"#E1E3E6",rx:"3"}),(0,m.jsx)("rect",{width:"47.266",height:"5.148",x:"9.216",y:"76.153",fill:"#E1E3E6",rx:"2.574"}),(0,m.jsx)("rect",{width:"62.8",height:"15",x:"1.565",y:"101.448",fill:"#E1E3E6",rx:"5"}),(0,m.jsx)("rect",{width:"65.374",height:"65.374",x:".162",y:"136.277",fill:"#E1E3E6",rx:"3"}),(0,m.jsx)("rect",{width:"47.266",height:"5.148",x:"9.216",y:"211.651",fill:"#E1E3E6",rx:"2.574"}),(0,m.jsx)("rect",{width:"62.8",height:"15",x:"1.565",y:"236.946",fill:"#E1E3E6",rx:"5"}),(0,m.jsx)("rect",{width:"65.374",height:"65.374",x:"82.478",y:".779",fill:"#E1E3E6",rx:"3"}),(0,m.jsx)("rect",{width:"47.266",height:"5.148",x:"91.532",y:"76.153",fill:"#E1E3E6",rx:"2.574"}),(0,m.jsx)("rect",{width:"62.8",height:"15",x:"83.882",y:"101.448",fill:"#E1E3E6",rx:"5"}),(0,m.jsx)("rect",{width:"65.374",height:"65.374",x:"82.478",y:"136.277",fill:"#E1E3E6",rx:"3"}),(0,m.jsx)("rect",{width:"47.266",height:"5.148",x:"91.532",y:"211.651",fill:"#E1E3E6",rx:"2.574"}),(0,m.jsx)("rect",{width:"62.8",height:"15",x:"83.882",y:"236.946",fill:"#E1E3E6",rx:"5"}),(0,m.jsx)("rect",{width:"65.374",height:"65.374",x:"164.788",y:".779",fill:"#E1E3E6",rx:"3"}),(0,m.jsx)("rect",{width:"47.266",height:"5.148",x:"173.843",y:"76.153",fill:"#E1E3E6",rx:"2.574"}),(0,m.jsx)("rect",{width:"62.8",height:"15",x:"166.192",y:"101.448",fill:"#E1E3E6",rx:"5"}),(0,m.jsx)("rect",{width:"65.374",height:"65.374",x:"164.788",y:"136.277",fill:"#E1E3E6",rx:"3"}),(0,m.jsx)("rect",{width:"47.266",height:"5.148",x:"173.843",y:"211.651",fill:"#E1E3E6",rx:"2.574"}),(0,m.jsx)("rect",{width:"62.8",height:"15",x:"166.192",y:"236.946",fill:"#E1E3E6",rx:"5"}),(0,m.jsx)("rect",{width:"6.177",height:"6.177",x:"13.283",y:"86.301",fill:"#E1E3E6",rx:"3"}),(0,m.jsx)("rect",{width:"6.177",height:"6.177",x:"21.498",y:"86.301",fill:"#E1E3E6",rx:"3"}),(0,m.jsx)("rect",{width:"6.177",height:"6.177",x:"29.713",y:"86.301",fill:"#E1E3E6",rx:"3"}),(0,m.jsx)("rect",{width:"6.177",height:"6.177",x:"37.927",y:"86.301",fill:"#E1E3E6",rx:"3"}),(0,m.jsx)("rect",{width:"6.177",height:"6.177",x:"46.238",y:"86.301",fill:"#E1E3E6",rx:"3"}),(0,m.jsx)("rect",{width:"6.177",height:"6.177",x:"95.599",y:"86.301",fill:"#E1E3E6",rx:"3"}),(0,m.jsx)("rect",{width:"6.177",height:"6.177",x:"103.814",y:"86.301",fill:"#E1E3E6",rx:"3"}),(0,m.jsx)("rect",{width:"6.177",height:"6.177",x:"112.029",y:"86.301",fill:"#E1E3E6",rx:"3"}),(0,m.jsx)("rect",{width:"6.177",height:"6.177",x:"120.243",y:"86.301",fill:"#E1E3E6",rx:"3"}),(0,m.jsx)("rect",{width:"6.177",height:"6.177",x:"128.554",y:"86.301",fill:"#E1E3E6",rx:"3"}),(0,m.jsx)("rect",{width:"6.177",height:"6.177",x:"177.909",y:"86.301",fill:"#E1E3E6",rx:"3"}),(0,m.jsx)("rect",{width:"6.177",height:"6.177",x:"186.124",y:"86.301",fill:"#E1E3E6",rx:"3"}),(0,m.jsx)("rect",{width:"6.177",height:"6.177",x:"194.339",y:"86.301",fill:"#E1E3E6",rx:"3"}),(0,m.jsx)("rect",{width:"6.177",height:"6.177",x:"202.553",y:"86.301",fill:"#E1E3E6",rx:"3"}),(0,m.jsx)("rect",{width:"6.177",height:"6.177",x:"210.864",y:"86.301",fill:"#E1E3E6",rx:"3"}),(0,m.jsx)("rect",{width:"6.177",height:"6.177",x:"13.283",y:"221.798",fill:"#E1E3E6",rx:"3"}),(0,m.jsx)("rect",{width:"6.177",height:"6.177",x:"21.498",y:"221.798",fill:"#E1E3E6",rx:"3"}),(0,m.jsx)("rect",{width:"6.177",height:"6.177",x:"29.713",y:"221.798",fill:"#E1E3E6",rx:"3"}),(0,m.jsx)("rect",{width:"6.177",height:"6.177",x:"37.927",y:"221.798",fill:"#E1E3E6",rx:"3"}),(0,m.jsx)("rect",{width:"6.177",height:"6.177",x:"46.238",y:"221.798",fill:"#E1E3E6",rx:"3"}),(0,m.jsx)("rect",{width:"6.177",height:"6.177",x:"95.599",y:"221.798",fill:"#E1E3E6",rx:"3"}),(0,m.jsx)("rect",{width:"6.177",height:"6.177",x:"103.814",y:"221.798",fill:"#E1E3E6",rx:"3"}),(0,m.jsx)("rect",{width:"6.177",height:"6.177",x:"112.029",y:"221.798",fill:"#E1E3E6",rx:"3"}),(0,m.jsx)("rect",{width:"6.177",height:"6.177",x:"120.243",y:"221.798",fill:"#E1E3E6",rx:"3"}),(0,m.jsx)("rect",{width:"6.177",height:"6.177",x:"128.554",y:"221.798",fill:"#E1E3E6",rx:"3"}),(0,m.jsx)("rect",{width:"6.177",height:"6.177",x:"177.909",y:"221.798",fill:"#E1E3E6",rx:"3"}),(0,m.jsx)("rect",{width:"6.177",height:"6.177",x:"186.124",y:"221.798",fill:"#E1E3E6",rx:"3"}),(0,m.jsx)("rect",{width:"6.177",height:"6.177",x:"194.339",y:"221.798",fill:"#E1E3E6",rx:"3"}),(0,m.jsx)("rect",{width:"6.177",height:"6.177",x:"202.553",y:"221.798",fill:"#E1E3E6",rx:"3"}),(0,m.jsx)("rect",{width:"6.177",height:"6.177",x:"210.864",y:"221.798",fill:"#E1E3E6",rx:"3"})]});var u=o(27723);const x=(e,t,o)=>o?Math.min(e,t)===e?t:Math.max(e,o)===e?o:e:Math.max(e,t)===t?e:t,g=({columns:e,rows:t,setAttributes:o,alignButtons:r,minColumns:s=1,maxColumns:i=6,minRows:n=1,maxRows:l=6})=>(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)(c.RangeControl,{__next40pxDefaultSize:!0,__nextHasNoMarginBottom:!0,label:(0,u.__)("Columns","woocommerce"),value:e,onChange:e=>{const t=x(e,s,i);o({columns:Number.isNaN(t)?"":t})},min:s,max:i}),(0,m.jsx)(c.RangeControl,{__next40pxDefaultSize:!0,__nextHasNoMarginBottom:!0,label:(0,u.__)("Rows","woocommerce"),value:t,onChange:e=>{const t=x(e,n,l);o({rows:Number.isNaN(t)?"":t})},min:n,max:l}),(0,m.jsx)(c.ToggleControl,{__nextHasNoMarginBottom:!0,label:(0,u.__)("Align the last block to the bottom","woocommerce"),help:r?(0,u.__)("Align the last block to the bottom.","woocommerce"):(0,u.__)("The last inner block will follow other content.","woocommerce"),checked:r,onChange:()=>o({alignButtons:!r})})]}),p=window.wc.wcSettings,w=({onChange:e,settings:t})=>{const{image:o,button:r,price:s,rating:i,title:n}=t,l=!1!==o;return(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)(c.ToggleControl,{label:(0,u.__)("Product image","woocommerce"),checked:l,onChange:()=>e({...t,image:!l})}),(0,m.jsx)(c.ToggleControl,{label:(0,u.__)("Product title","woocommerce"),checked:n,onChange:()=>e({...t,title:!n})}),(0,m.jsx)(c.ToggleControl,{label:(0,u.__)("Product price","woocommerce"),checked:s,onChange:()=>e({...t,price:!s})}),(0,m.jsx)(c.ToggleControl,{label:(0,u.__)("Product rating","woocommerce"),checked:i,onChange:()=>e({...t,rating:!i})}),(0,m.jsx)(c.ToggleControl,{label:(0,u.__)("Add to Cart button","woocommerce"),checked:r,onChange:()=>e({...t,button:!r})})]})};var f=o(4921),b=o(86087);function j(e,t,o){const r=new Set(t.map(e=>e[o]));return e.filter(e=>!r.has(e[o]))}const _=window.wp.htmlEntities,E={clear:(0,u.__)("Clear all selected items","woocommerce"),noItems:(0,u.__)("No items found.","woocommerce"), /* Translators: %s search term */ noResults:(0,u.__)("No results for %s","woocommerce"),search:(0,u.__)("Search for items","woocommerce"),selected:e=>(0,u.sprintf)(/* translators: Number of items selected from list. */ /* translators: Number of items selected from list. */ (0,u._n)("%d item selected","%d items selected",e,"woocommerce"),e),updated:(0,u.__)("Search results updated.","woocommerce")},y=(e,t)=>null!==t&&(e.id===t||!!(Array.isArray(e.children)&&e.children.length>0)&&e.children.some(e=>y(e,t))),v=(e,t=e)=>{const o=e.reduce((e,t)=>{const o=t.parent||0;return e[o]||(e[o]=[]),e[o].push(t),e},{}),r=t.reduce((e,t)=>(e[String(t.id)]=t,e),{});const s=["0"],i=(e={})=>e.parent?[...i(r[e.parent]),e.name]:e.name?[e.name]:[],n=e=>e.map(e=>{const t=o[e.id];return s.push(""+e.id),{...e,breadcrumbs:i(r[e.parent]),children:t&&t.length?n(t):[]}}),l=n(o[0]||[]);return Object.entries(o).forEach(([e,t])=>{s.includes(e)||l.push(...n(t||[]))}),l},C=(e,t)=>{if(!t)return e;const o=new RegExp(`(${t.replace(/[-\/\\^$*+?.()|[\]{}]/g,"\\$&")})`,"ig");return e.split(o).map((e,t)=>o.test(e)?(0,m.jsx)("strong",{children:e},t):(0,m.jsx)(b.Fragment,{children:e},t))},k=e=>{const t=e.children?.map(e=>[e,...k(e)]);return t?t.flat():[]},S=(e,t)=>k(e).some(e=>t.find(t=>t.id===e.id)),N=(e,t)=>k(e).every(e=>t.find(t=>t.id===e.id)),P=({label:e})=>(0,m.jsx)("span",{className:"woocommerce-search-list__item-count",children:e}),O=e=>{const{item:t,search:o}=e,r=t.breadcrumbs&&t.breadcrumbs.length;return(0,m.jsxs)("span",{className:"woocommerce-search-list__item-label",children:[r?(0,m.jsx)("span",{className:"woocommerce-search-list__item-prefix",children:(s=t.breadcrumbs,1===s.length?s.slice(0,1).toString():2===s.length?s.slice(0,1).toString()+" › "+s.slice(-1).toString():s.slice(0,1).toString()+" … "+s.slice(-1).toString())}):null,(0,m.jsx)("span",{className:"woocommerce-search-list__item-name",children:C((0,_.decodeEntities)(t.name),o)})]});var s},I=({countLabel:e,className:t,depth:o=0,controlId:r="",disabled:s=!1,item:i,isSelected:n,isSelectable:l=!0,isSingle:a,onSelect:d,search:h="",selected:u,useExpandedPanelId:x,...g})=>{const[p,w]=x,E=null!=e&&void 0!==i.count&&null!==i.count,v=!!i.breadcrumbs?.length,I=!!i.children?.length,B=y(i,p),M=(0,f.A)(["woocommerce-search-list__item",`depth-${o}`,t],{"has-breadcrumbs":v,"has-children":I,"has-count":E,"is-expanded":B,"is-radio-button":a}),A=g.name||`search-list-item-${r}`,T=`${A}-${i.id}`,R=(0,b.useCallback)(()=>{B||"number"!=typeof i.id&&"string"!=typeof i.id?!i.parent||"number"!=typeof i.parent&&"string"!=typeof i.parent?w(null):w(i.parent):w(i.id)},[B,i.id,i.parent,w]),$=(n||!l)&&N(i,u);return I?(0,m.jsx)("div",{className:M,onClick:R,onKeyDown:e=>"Enter"===e.key||" "===e.key?R():null,role:"treeitem",tabIndex:0,children:a?(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)("input",{type:"radio",id:T,name:A,value:i.value,onChange:()=>{d(i)(),B||w(i.id)},onClick:e=>e.stopPropagation(),checked:n,disabled:s,className:"woocommerce-search-list__item-input",...g}),(0,m.jsx)(O,{item:i,search:h}),E?(0,m.jsx)(P,{label:e||i.count}):null]}):(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)(c.CheckboxControl,{className:"woocommerce-search-list__item-input",checked:$,disabled:s,indeterminate:!$&&(n||S(i,u)),label:C((0,_.decodeEntities)(i.name),h),onClick:e=>e.stopPropagation(),onKeyDown:e=>e.stopPropagation(),onChange:()=>{const e=k(i),t=l?[i,...e]:[...e],o=N(i,u);l&&n||!l&&o?d(j(u,t,"id"))():(d(function(e,t){const o=j(t,e,"id");return[...e,...o]}(u,t))(),B||w(i.id))},__nextHasNoMarginBottom:!0}),E?(0,m.jsx)(P,{label:e||i.count}):null]})}):(0,m.jsxs)("div",{className:M,onClick:s?void 0:d(i),children:[a?(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)("input",{...g,type:"radio",id:T,name:A,value:i.value,onChange:d(i),checked:n,disabled:s,className:"woocommerce-search-list__item-input",onClick:e=>e.stopPropagation()}),(0,m.jsx)("label",{htmlFor:T,children:(0,m.jsx)(O,{item:i,search:h})})]}):(0,m.jsx)(c.CheckboxControl,{...g,id:T,name:A,className:"woocommerce-search-list__item-input",value:(0,_.decodeEntities)(i.value),label:C((0,_.decodeEntities)(i.name),h),onChange:()=>{d(i)(),B||w(i.id)},checked:n,disabled:s,__nextHasNoMarginBottom:!0,onClick:e=>e.stopPropagation()}),E?(0,m.jsx)(P,{label:e||i.count}):null]})},B=I;var M=o(74515),A=o(29491),T=o(13739);o(75022);const R=({id:e,label:t,popoverContents:o,remove:s,screenReaderLabel:i,className:n=""})=>{const[l,a]=(0,b.useState)(!1),d=(0,A.useInstanceId)(R);if(i=i||t,!t)return null;t=(0,_.decodeEntities)(t);const h=(0,f.A)("woocommerce-tag",n,{"has-remove":!!s}),x=`woocommerce-tag__label-${d}`,g=(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)("span",{className:"screen-reader-text",children:i}),(0,m.jsx)("span",{"aria-hidden":"true",children:t})]});return(0,m.jsxs)("span",{className:h,children:[o?(0,m.jsx)(c.Button,{className:"woocommerce-tag__text",id:x,onClick:()=>a(!0),children:g}):(0,m.jsx)("span",{className:"woocommerce-tag__text",id:x,children:g}),o&&l&&(0,m.jsx)(c.Popover,{onClose:()=>a(!1),children:o}),s&&(0,m.jsx)(c.Button,{className:"woocommerce-tag__remove",onClick:s(e),label:(0,u.sprintf)( // Translators: %s label. // Translators: %s label. (0,u.__)("Remove %s","woocommerce"),t),"aria-describedby":x,children:(0,m.jsx)(r.A,{icon:T.A,size:20,className:"clear-icon",role:"img"})})]})},$=R;o(71939);const L=e=>(0,m.jsx)(B,{...e}),F=e=>{const{list:t,selected:o,renderItem:r,depth:s=0,loadMoreChildrenText:i,onLoadMoreChildren:n,totalChildren:l,onSelect:c,instanceId:a,isSingle:d,search:h,useExpandedPanelId:x}=e,[g]=x;return t?(0,m.jsx)(m.Fragment,{children:t.map(t=>{const p=t.children?.length??0,w=!!o.find(({id:e})=>e===t.id),f=y(t,g),j=l?.[t.id],_="number"==typeof j&&p<j;return(0,m.jsxs)(b.Fragment,{children:[(0,m.jsx)("li",{children:r({item:t,isSelected:w,onSelect:c,isSingle:d,selected:o,search:h,depth:s,useExpandedPanelId:x,controlId:a})}),f?(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)(F,{...e,list:t.children,depth:s+1}),n&&_?(0,m.jsx)("li",{children:(0,m.jsx)("button",{type:"button",className:"woocommerce-search-list__item woocommerce-search-list__item-load-more",onClick:()=>n(),children:i||(0,u.__)("Load more","woocommerce")})}):null]}):null]},t.id)})}):null},H=({isLoading:e,isSingle:t,selected:o,messages:r,onChange:s,onRemove:i})=>{if(e||t||!o)return null;const n=o.length;return(0,m.jsxs)("div",{className:"woocommerce-search-list__selected",children:[(0,m.jsxs)("div",{className:"woocommerce-search-list__selected-header",children:[(0,m.jsx)("strong",{children:r.selected(n)}),n>0?(0,m.jsx)(c.Button,{variant:"link",isDestructive:!0,onClick:()=>s([]),"aria-label":r.clear,children:(0,u.__)("Clear all","woocommerce")}):null]}),n>0?(0,m.jsx)("ul",{children:o.map((e,t)=>(0,m.jsx)("li",{children:(0,m.jsx)($,{label:e.name,id:e.id,remove:i})},t))}):null]})},D=({filteredList:e,search:t,onSelect:o,instanceId:s,useExpandedPanelId:i,...n})=>{const{messages:l,renderItem:c,selected:a,isSingle:d,loadMoreChildrenText:h,onLoadMoreChildren:x,totalChildren:g}=n,p=c||L;return 0===e.length?(0,m.jsxs)("div",{className:"woocommerce-search-list__list is-not-found",children:[(0,m.jsx)("span",{className:"woocommerce-search-list__not-found-icon",children:(0,m.jsx)(r.A,{icon:M.A,role:"img"})}),(0,m.jsx)("span",{className:"woocommerce-search-list__not-found-text",children:t?(0,u.sprintf)(l.noResults,t):l.noItems})]}):(0,m.jsx)("ul",{className:"woocommerce-search-list__list",children:(0,m.jsx)(F,{useExpandedPanelId:i,list:e,selected:a,renderItem:p,loadMoreChildrenText:h,onLoadMoreChildren:x,totalChildren:g,onSelect:o,instanceId:s,isSingle:d,search:t})})},V=e=>{const{className:t="",isCompact:o,isHierarchical:r,isLoading:s,isSingle:i,list:n,messages:l=E,onChange:a,onSearch:d,selected:h,type:x="text",debouncedSpeak:g}=e,[p,w]=(0,b.useState)(""),j=(0,b.useState)(null),_=(0,A.useInstanceId)(V),y=(0,b.useMemo)(()=>({...E,...l}),[l]),C=(0,b.useMemo)(()=>((e,t,o)=>{if(!t)return o?v(e):e;const r=new RegExp(t.replace(/[-\/\\^$*+?.()|[\]{}]/g,"\\$&"),"i"),s=e.map(e=>!!r.test(e.name)&&e).filter(Boolean);return o?v(s,e):s})(n,p,r),[n,p,r]);(0,b.useEffect)(()=>{g&&g(y.updated)},[g,y]),(0,b.useEffect)(()=>{"function"==typeof d&&d(p)},[p,d]);const k=(0,b.useCallback)(e=>()=>{i&&a([]);const t=h.findIndex(({id:t})=>t===e);a([...h.slice(0,t),...h.slice(t+1)])},[i,h,a]),S=(0,b.useCallback)(e=>()=>{Array.isArray(e)?a(e):-1===h.findIndex(({id:t})=>t===e.id)?a(i?[e]:[...h,e]):k(e.id)()},[i,k,a,h]),N=(0,b.useCallback)(e=>{const[t]=h.filter(t=>!e.find(e=>t.id===e.id));k(t.id)()},[k,h]);return(0,m.jsxs)("div",{className:(0,f.A)("woocommerce-search-list",t,{"is-compact":o,"is-loading":s,"is-token":"token"===x}),children:["text"===x&&(0,m.jsx)(H,{...e,onRemove:k,messages:y}),(0,m.jsx)("div",{className:"woocommerce-search-list__search",children:"text"===x?(0,m.jsx)(c.TextControl,{__next40pxDefaultSize:!0,__nextHasNoMarginBottom:!0,label:y.search,type:"search",value:p,onChange:e=>w(e)}):(0,m.jsx)(c.FormTokenField,{__next40pxDefaultSize:!0,__nextHasNoMarginBottom:!0,disabled:s,label:y.search,onChange:N,onInputChange:e=>w(e),suggestions:[],__experimentalValidateInput:()=>!1,value:s?[(0,u.__)("Loading…","woocommerce")]:h.map(e=>({...e,value:e.name})),__experimentalShowHowTo:!1})}),s?(0,m.jsx)("div",{className:"woocommerce-search-list__list",children:(0,m.jsx)(c.Spinner,{})}):(0,m.jsx)(D,{...e,search:p,filteredList:C,messages:y,onSelect:S,instanceId:_,useExpandedPanelId:j})]})},z=((0,c.withSpokenMessages)(V),window.wp.url),J=window.wp.apiFetch;var W=o.n(J);const K=window.wp.escapeHtml,G=({message:e,type:t})=>e?"general"===t?(0,m.jsxs)("span",{children:[(0,u.__)("The following error was returned","woocommerce"),(0,m.jsx)("br",{}),(0,m.jsx)("code",{children:(0,K.escapeHTML)(e)})]}):"api"===t?(0,m.jsxs)("span",{children:[(0,u.__)("The following error was returned from the API","woocommerce"),(0,m.jsx)("br",{}),(0,m.jsx)("code",{children:(0,K.escapeHTML)(e)})]}):e:(0,u.__)("An error has prevented the block from being updated.","woocommerce"),Q=({error:e})=>(0,m.jsx)("div",{className:"wc-block-error-message",children:G(e)}),X=e=>{const{id:t,name:o,parent:r,count:s}=e;return{id:t,name:o,parent:r,count:s,breadcrumbs:[],children:[],details:e,value:e.slug}};o(66982);const Y=(ee=({categories:e=[],error:t=null,isLoading:o=!1,onChange:r,onOperatorChange:s,operator:i="any",selected:n,isCompact:l=!1,isSingle:a=!1,showReviewCount:d})=>{const h={clear:(0,u.__)("Clear all product categories","woocommerce"),list:(0,u.__)("Product Categories","woocommerce"),noItems:(0,u.__)("Your store doesn't have any product categories.","woocommerce"),search:(0,u.__)("Search for product categories","woocommerce"),selected:e=>(0,u.sprintf)(/* translators: %d is the count of selected categories. */ /* translators: %d is the count of selected categories. */ (0,u._n)("%d category selected","%d categories selected",e,"woocommerce"),e),updated:(0,u.__)("Category search results updated.","woocommerce")};if(t)return(0,m.jsx)(Q,{error:t});const x=e.map(X);return(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)(V,{className:"woocommerce-product-categories",list:x,isLoading:o,selected:x.filter(({id:e})=>n.includes(Number(e))),onChange:r,renderItem:e=>{const{item:t,search:o,depth:r=0}=e,s=t.breadcrumbs.length?`${t.breadcrumbs.join(", ")}, ${t.name}`:t.name,i=d?(0,u.sprintf)(/* translators: %1$s is the item name, %2$d is the count of reviews for the item. */ /* translators: %1$s is the item name, %2$d is the count of reviews for the item. */ (0,u._n)("%1$s, has %2$d review","%1$s, has %2$d reviews",t.details?.review_count||0,"woocommerce"),s,t.details?.review_count||0):(0,u.sprintf)(/* translators: %1$s is the item name, %2$d is the count of products for the item. */ /* translators: %1$s is the item name, %2$d is the count of products for the item. */ (0,u._n)("%1$s, has %2$d product","%1$s, has %2$d products",t.details?.count||0,"woocommerce"),s,t.details?.count||0),n=d?(0,u.sprintf)(/* translators: %d is the count of reviews. */ /* translators: %d is the count of reviews. */ (0,u._n)("%d review","%d reviews",t.details?.review_count||0,"woocommerce"),t.details?.review_count||0):(0,u.sprintf)(/* translators: %d is the count of products. */ /* translators: %d is the count of products. */ (0,u._n)("%d product","%d products",t.details?.count||0,"woocommerce"),t.details?.count||0);return(0,m.jsx)(I,{className:(0,f.A)("woocommerce-product-categories__item","has-count",{"is-searching":o.length>0,"is-skip-level":0===r&&0!==t.parent}),...e,countLabel:n,"aria-label":i})},messages:h,isCompact:l,isHierarchical:!0,isSingle:a}),!!s&&(0,m.jsx)("div",{hidden:n.length<2,children:(0,m.jsx)(c.SelectControl,{className:"woocommerce-product-categories__operator",label:(0,u.__)("Display products matching","woocommerce"),help:(0,u.__)("Pick at least two categories to use this setting.","woocommerce"),value:i,onChange:s,options:[{label:(0,u.__)("Any selected categories","woocommerce"),value:"any"},{label:(0,u.__)("All selected categories","woocommerce"),value:"all"}]})})]})},({selected:e,...t})=>{const[o,r]=(0,b.useState)(!0),[s,i]=(0,b.useState)(null),[n,l]=(0,b.useState)([]),c=async e=>{const t=await(async e=>{if(!("json"in e))return{code:e.code||"",message:e.message,type:e.type||"general"};try{const t=await e.json();return{code:t.code||"",message:t.message,type:t.type||"api"}}catch(e){return{message:e.message,type:"general"}}})(e);i(t),r(!1)},a=(0,b.useRef)(e);return(0,b.useEffect)(()=>{var e;(e={selected:a.current},W()({path:(0,z.addQueryArgs)("wc/store/v1/products/categories",{per_page:0,...e})})).then(e=>{l(e),r(!1)}).catch(c)},[a]),(0,m.jsx)(ee,{...t,selected:e,error:s,categories:n,isLoading:o})}),q=e=>{const{attributes:t,setAttributes:o}=e,{categories:r,catOperator:s,columns:i,contentVisibility:n,rows:a,alignButtons:d}=t;return(0,m.jsxs)(l.InspectorControls,{children:[(0,m.jsx)(c.PanelBody,{title:(0,u.__)("Layout","woocommerce"),initialOpen:!0,children:(0,m.jsx)(g,{columns:i,rows:a,alignButtons:d,setAttributes:o,minColumns:(0,p.getSetting)("minColumns",1),maxColumns:(0,p.getSetting)("maxColumns",6),minRows:(0,p.getSetting)("minRows",1),maxRows:(0,p.getSetting)("maxRows",6)})}),(0,m.jsx)(c.PanelBody,{title:(0,u.__)("Content","woocommerce"),initialOpen:!0,children:(0,m.jsx)(w,{settings:n,onChange:e=>o({contentVisibility:e})})}),(0,m.jsx)(c.PanelBody,{title:(0,u.__)("Filter by Product Category","woocommerce"),initialOpen:!1,children:(0,m.jsx)(Y,{selected:r,onChange:(e=[])=>{const t=e.map(({id:e})=>e);o({categories:t})},operator:s,onOperatorChange:(e="any")=>o({catOperator:e})})})]},"inspector")},U=e=>{const{attributes:t,name:o}=e;return t.isPreview?h:(0,m.jsxs)("div",{className:"wc-block-product-best-sellers",children:[(0,m.jsx)(q,{...e}),(0,m.jsx)(c.Disabled,{children:(0,m.jsx)(d(),{block:o,attributes:t})})]})},Z={columns:{type:"number",default:(0,p.getSetting)("defaultColumns",3)},rows:{type:"number",default:(0,p.getSetting)("defaultRows",3)},alignButtons:{type:"boolean",default:!1},categories:{type:"array",default:[]},catOperator:{type:"string",default:"any"},contentVisibility:{type:"object",default:{image:!0,title:!0,price:!0,rating:!0,button:!0}},isPreview:{type:"boolean",default:!1},stockStatus:{type:"array",default:Object.keys((0,p.getSetting)("stockStatusOptions",[]))}};var ee;(0,i.registerBlockType)(n,{icon:{src:(0,m.jsx)(r.A,{icon:s.A,className:"wc-block-editor-components-block-icon"})},attributes:{...Z,...n.attributes},transforms:{from:[{type:"block",blocks:["woocommerce/product-best-sellers","woocommerce/product-category","woocommerce/product-new","woocommerce/product-on-sale","woocommerce/product-top-rated"].filter(e=>"woocommerce/product-best-sellers"!==e),transform:e=>(0,i.createBlock)("woocommerce/product-best-sellers",e)}]},edit:e=>{const t=(0,l.useBlockProps)();return(0,m.jsx)("div",{...t,children:(0,m.jsx)(U,{...e})})},save:()=>null})},66982:()=>{},71939:()=>{},75022:()=>{},10790:e=>{"use strict";e.exports=window.ReactJSXRuntime},29491:e=>{"use strict";e.exports=window.wp.compose},86087:e=>{"use strict";e.exports=window.wp.element},27723:e=>{"use strict";e.exports=window.wp.i18n},5573:e=>{"use strict";e.exports=window.wp.primitives}},s={};function i(e){var t=s[e];if(void 0!==t)return t.exports;var o=s[e]={exports:{}};return r[e](o,o.exports,i),o.exports}i.m=r,e=[],i.O=(t,o,r,s)=>{if(!o){var n=1/0;for(d=0;d<e.length;d++){for(var[o,r,s]=e[d],l=!0,c=0;c<o.length;c++)(!1&s||n>=s)&&Object.keys(i.O).every(e=>i.O[e](o[c]))?o.splice(c--,1):(l=!1,s<n&&(n=s));if(l){e.splice(d--,1);var a=r();void 0!==a&&(t=a)}}return t}s=s||0;for(var d=e.length;d>0&&e[d-1][2]>s;d--)e[d]=e[d-1];e[d]=[o,r,s]},i.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return i.d(t,{a:t}),t},o=Object.getPrototypeOf?e=>Object.getPrototypeOf(e):e=>e.__proto__,i.t=function(e,r){if(1&r&&(e=this(e)),8&r)return e;if("object"==typeof e&&e){if(4&r&&e.__esModule)return e;if(16&r&&"function"==typeof e.then)return e}var s=Object.create(null);i.r(s);var n={};t=t||[null,o({}),o([]),o(o)];for(var l=2&r&&e;"object"==typeof l&&!~t.indexOf(l);l=o(l))Object.getOwnPropertyNames(l).forEach(t=>n[t]=()=>e[t]);return n.default=()=>e,i.d(s,n),s},i.d=(e,t)=>{for(var o in t)i.o(t,o)&&!i.o(e,o)&&Object.defineProperty(e,o,{enumerable:!0,get:t[o]})},i.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(e){if("object"==typeof window)return window}}(),i.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),i.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},i.j=2272,(()=>{var e={2272:0};i.O.j=t=>0===e[t];var t=(t,o)=>{var r,s,[n,l,c]=o,a=0;if(n.some(t=>0!==e[t])){for(r in l)i.o(l,r)&&(i.m[r]=l[r]);if(c)var d=c(i)}for(t&&t(o);a<n.length;a++)s=n[a],i.o(e,s)&&e[s]&&e[s][0](),e[s]=0;return i.O(d)},o=globalThis.webpackChunkwebpackWcBlocksMainJsonp=globalThis.webpackChunkwebpackWcBlocksMainJsonp||[];o.forEach(t.bind(null,0)),o.push=t.bind(null,o.push.bind(o))})();var n=i.O(void 0,[94],()=>i(78220));n=i.O(n),((this.wc=this.wc||{}).blocks=this.wc.blocks||{})["product-best-sellers"]=n})();
Save File
Cancel