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

11 lines
26 KiB
JavaScript
Raw Normal View History

2024-02-01 17:24:18 +05:30
(()=>{var e,t={3381:(e,t,r)=>{"use strict";r.r(t);var o=r(9196),l=r(5736);const n=window.wp.blocks;var c=r(444);const a=(0,o.createElement)(c.SVG,{xmlns:"http://www.w3.org/2000/SVG",viewBox:"0 0 24 24"},(0,o.createElement)("path",{opacity:".87",fill:"none",d:"M0 0h24v24H0V0z"}),(0,o.createElement)("path",{d:"M21 8h-6.31l.95-4.57.03-.32c0-.41-.17-.79-.44-1.06L14.17 1 7.59 7.59C7.22 7.95 7 8.45 7 9v10c0 1.1.9 2 2 2h9c.83 0 1.54-.5 1.84-1.22l3.02-7.05c.09-.23.14-.47.14-.73v-2c0-1.1-.9-2-2-2zm0 4l-3 7H9V9l4.34-4.34L12.23 10H21v2zM1 9h4v12H1z"}));var s=r(1984);const i=JSON.parse('{"name":"woocommerce/product-top-rated","title":"Top Rated Products","category":"woocommerce","keywords":["WooCommerce"],"description":"Display a grid of your top rated products.","supports":{"align":["wide","full"],"html":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":"rating"}},"textdomain":"woocommerce","apiVersion":2,"$schema":"https://schemas.wp.org/trunk/block.json"}'),d=window.wc.wcSettings,m={columns:{type:"number",default:(0,d.getSetting)("defaultColumns",3)},rows:{type:"number",default:(0,d.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,d.getSetting)("stockStatusOptions",[]))}},u=window.wp.blockEditor,g=window.wp.components,h=window.wp.serverSideRender;var p=r.n(h);const E=({onChange:e,settings:t})=>{const{image:r,button:n,price:c,rating:a,title:s}=t,i=!1!==r;return(0,o.createElement)(o.Fragment,null,(0,o.createElement)(g.ToggleControl,{label:(0,l.__)("Product image","woocommerce"),checked:i,onChange:()=>e({...t,image:!i})}),(0,o.createElement)(g.ToggleControl,{label:(0,l.__)("Product title","woocommerce"),checked:s,onChange:()=>e({...t,title:!s})}),(0,o.createElement)(g.ToggleControl,{label:(0,l.__)("Product price","woocommerce"),checked:c,onChange:()=>e({...t,price:!c})}),(0,o.createElement)(g.ToggleControl,{label:(0,l.__)("Product rating","woocommerce"),checked:a,onChange:()=>e({...t,rating:!a})}),(0,o.createElement)(g.ToggleControl,{label:(0,l.__)("Add to Cart button","woocommerce"),checked:n,onChange:()=>e({...t,button:!n})}))},w=(e,t,r)=>r?Math.min(e,t)===e?t:Math.max(e,r)===e?r:e:Math.max(e,t)===t?e:t,b=({columns:e,rows:t,setAttributes:r,alignButtons:n,minColumns:c=1,maxColumns:a=6,minRows:s=1,maxRows:i=6})=>(0,o.createElement)(o.Fragment,null,(0,o.createElement)(g.RangeControl,{label:(0,l.__)("Columns","woocommerce"),value:e,onChange:e=>{const t=w(e,c,a);r({columns:Number.isNaN(t)?"":t})},min:c,max:a}),(0,o.createElement)(g.RangeControl,{label:(0,l.__)("Rows","woocommerce"),value:t,onChange:e=>{const t=w(e,s,i);r({rows:Number.isNaN(t)?"":t})},min:s,max:i}),(0,o.createElement)(g.ToggleControl,{label:(0,l.__)("Align the last block to the bottom","woocommerce"),help:n?(0,l.__)("Align the last block to the bottom.","woocommerce"):(0,l.__)("The last inner block will follow other content.","woocommerce"),checked:n,onChange:()=>r({alignButtons:!n})}));var f=r(4184),y=r.n(f),x=r(9307);function _(e,t,r){const o=new Set(t.map((e=>e[r])));return e.filter((e=>!o.has(e[r])))}const k=window.wp.htmlEntitie
/* Translators: %s search term */
noResults:(0,l.__)("No results for %s","woocommerce"),search:(0,l.__)("Search for items","woocommerce"),selected:e=>(0,l.sprintf)(/* translators: Number of items selected from list. */
(0,l._n)("%d item selected","%d items selected",e,"woocommerce"),e),updated:(0,l.__)("Search results updated.","woocommerce")},C=(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=("id",t.reduce(((e,t)=>(e[String(t.id)]=t,e)),{}));const l=["0"],n=(e={})=>e.parent?[...n(o[e.parent]),e.name]:e.name?[e.name]:[],c=e=>e.map((e=>{const t=r[e.id];return l.push(""+e.id),{...e,breadcrumbs:n(o[e.parent]),children:t&&t.length?c(t):[]}})),a=c(r[0]||[]);return Object.entries(r).forEach((([e,t])=>{l.includes(e)||a.push(...c(t||[]))})),a},S=(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,o.createElement)("strong",{key:t},e):(0,o.createElement)(x.Fragment,{key:t},e)))},N=({label:e})=>(0,o.createElement)("span",{className:"woocommerce-search-list__item-count"},e),O=e=>{const{item:t,search:r}=e,l=t.breadcrumbs&&t.breadcrumbs.length;return(0,o.createElement)("span",{className:"woocommerce-search-list__item-label"},l?(0,o.createElement)("span",{className:"woocommerce-search-list__item-prefix"},1===(n=t.breadcrumbs).length?n.slice(0,1).toString():2===n.length?n.slice(0,1).toString()+" "+n.slice(-1).toString():n.slice(0,1).toString()+" … "+n.slice(-1).toString()):null,(0,o.createElement)("span",{className:"woocommerce-search-list__item-name"},S((0,k.decodeEntities)(t.name),r)));var n},P=({countLabel:e,className:t,depth:r=0,controlId:l="",item:n,isSelected:c,isSingle:a,onSelect:s,search:i="",selected:d,useExpandedPanelId:m,...u})=>{var h,p;const[E,w]=m,b=null!=e&&void 0!==n.count&&null!==n.count,f=!(null===(h=n.breadcrumbs)||void 0===h||!h.length),v=!(null===(p=n.children)||void 0===p||!p.length),C=E===n.id,P=y()(["woocommerce-search-list__item",`depth-${r}`,t],{"has-breadcrumbs":f,"has-children":v,"has-count":b,"is-expanded":C,"is-radio-button":a}),I=u.name||`search-list-item-${l}`,B=`${I}-${n.id}`,R=(0,x.useCallback)((()=>{w(C?-1:Number(n.id))}),[C,n.id,w]);return v?(0,o.createElement)("div",{className:P,onClick:R,onKeyDown:e=>"Enter"===e.key||" "===e.key?R():null,role:"treeitem",tabIndex:0},a?(0,o.createElement)(o.Fragment,null,(0,o.createElement)("input",{type:"radio",id:B,name:I,value:n.value,onChange:s(n),onClick:e=>e.stopPropagation(),checked:c,className:"woocommerce-search-list__item-input",...u}),(0,o.createElement)(O,{item:n,search:i}),b?(0,o.createElement)(N,{label:e||n.count}):null):(0,o.createElement)(o.Fragment,null,(0,o.createElement)(g.CheckboxControl,{className:"woocommerce-search-list__item-input",checked:c,...!c&&n.children.some((e=>d.find((t=>t.id===e.id))))?{indeterminate:!0}:{},label:S((0,k.decodeEntities)(n.name),i),onChange:()=>{c?s(_(d,n.children,"id"))():s(function(e,t,r){const o=_(t,e,"id");return[...e,...o]}(d,n.children))()},onClick:e=>e.stopPropagation()}),b?(0,o.createElement)(N,{label:e||n.count}):null)):(0,o.createElement)("label",{htmlFor:B,className:P},a?(0,o.createElement)(o.Fragment,null,(0,o.createElement)("input",{...u,type:"radio",id:B,name:I,value:n.value,onChange:s(n),checked:c,className:"woocommerce-search-list__item-input"}),(0,o.createElement)(O,{item:n,search:i})):(0,o.createElement)(g.CheckboxControl,{...u,id:B,name:I,className:"woocommerce-search-list__item-input",value:(0,k.decodeEntities)(n.value),label:S((0,k.decodeEntities)(n.name),i),onChange:s(n),checked:c}),b?(0,o.createElement)(N,{label:e||n.count}):null)},I=P;var B=r(5430),R=r(4333),$=r(906);r(5932);const T=({id:e,label:t,popoverContents:r,remove:n,screenReaderLabel:c,className:a=""})=>{const[i,d]=(0,x.useState)(!1),m=(0,R.useInstanceId)(T);if(c=c||t,!t)return null;t=(0,k.decodeEntities)(t);const u=y()("woocommerce-tag",a,{"has-remove":!!n}),h=`woocommerce-tag__label-${m}`,p=(0,o.createElement)(o.Fragment,null,(0,o.createElement)("span",{className:"screen-reader-text"},c),(0,o.createElement)("span",{"aria-hidden":"true"},t));return(0,o.createElement)("span",{className:u},r?(0,o.createElement)(g.Button,{className:"woocommerce-tag__text",id:h,onClick:()=>d(!0)},p):(0,o.createElement)("span",
// Translators: %s label.
(0,l.__)("Remove %s","woocommerce"),t),"aria-describedby":h},(0,o.createElement)(s.Z,{icon:$.Z,size:20,className:"clear-icon",role:"img"})))},F=T;r(8462);const j=e=>(0,o.createElement)(I,{...e}),L=e=>{const{list:t,selected:r,renderItem:l,depth:n=0,onSelect:c,instanceId:a,isSingle:s,search:i,useExpandedPanelId:d}=e,[m]=d;return t?(0,o.createElement)(x.Fragment,null,t.map((t=>{var u,g;const h=null!==(u=t.children)&&void 0!==u&&u.length&&!s?t.children.every((({id:e})=>r.find((t=>t.id===e)))):!!r.find((({id:e})=>e===t.id)),p=(null===(g=t.children)||void 0===g?void 0:g.length)&&m===t.id;return(0,o.createElement)(x.Fragment,{key:t.id},(0,o.createElement)("li",null,l({item:t,isSelected:h,onSelect:c,isSingle:s,selected:r,search:i,depth:n,useExpandedPanelId:d,controlId:a})),p?(0,o.createElement)(L,{...e,list:t.children,depth:n+1}):null)}))):null},M=({isLoading:e,isSingle:t,selected:r,messages:n,onChange:c,onRemove:a})=>{if(e||t||!r)return null;const s=r.length;return(0,o.createElement)("div",{className:"woocommerce-search-list__selected"},(0,o.createElement)("div",{className:"woocommerce-search-list__selected-header"},(0,o.createElement)("strong",null,n.selected(s)),s>0?(0,o.createElement)(g.Button,{isLink:!0,isDestructive:!0,onClick:()=>c([]),"aria-label":n.clear},(0,l.__)("Clear all","woocommerce")):null),s>0?(0,o.createElement)("ul",null,r.map(((e,t)=>(0,o.createElement)("li",{key:t},(0,o.createElement)(F,{label:e.name,id:e.id,remove:a}))))):null)},A=({filteredList:e,search:t,onSelect:r,instanceId:n,useExpandedPanelId:c,...a})=>{const{messages:i,renderItem:d,selected:m,isSingle:u}=a,g=d||j;return 0===e.length?(0,o.createElement)("div",{className:"woocommerce-search-list__list is-not-found"},(0,o.createElement)("span",{className:"woocommerce-search-list__not-found-icon"},(0,o.createElement)(s.Z,{icon:B.Z,role:"img"})),(0,o.createElement)("span",{className:"woocommerce-search-list__not-found-text"},t?(0,l.sprintf)(i.noResults,t):i.noItems)):(0,o.createElement)("ul",{className:"woocommerce-search-list__list"},(0,o.createElement)(L,{useExpandedPanelId:c,list:e,selected:m,renderItem:g,onSelect:r,instanceId:n,isSingle:u,search:t}))},H=e=>{const{className:t="",isCompact:r,isHierarchical:n,isLoading:c,isSingle:a,list:s,messages:i=v,onChange:d,onSearch:m,selected:u,type:h="text",debouncedSpeak:p}=e,[E,w]=(0,x.useState)(""),b=(0,x.useState)(-1),f=(0,R.useInstanceId)(H),_=(0,x.useMemo)((()=>({...v,...i})),[i]),k=(0,x.useMemo)((()=>((e,t,r)=>{if(!t)return r?C(e):e;const o=new RegExp(t.replace(/[-\/\\^$*+?.()|[\]{}]/g,"\\$&"),"i"),l=e.map((e=>!!o.test(e.name)&&e)).filter(Boolean);return r?C(l,e):l})(s,E,n)),[s,E,n]);(0,x.useEffect)((()=>{p&&p(_.updated)}),[p,_]),(0,x.useEffect)((()=>{"function"==typeof m&&m(E)}),[E,m]);const S=(0,x.useCallback)((e=>()=>{a&&d([]);const t=u.findIndex((({id:t})=>t===e));d([...u.slice(0,t),...u.slice(t+1)])}),[a,u,d]),N=(0,x.useCallback)((e=>()=>{Array.isArray(e)?d(e):-1===u.findIndex((({id:t})=>t===e.id))?d(a?[e]:[...u,e]):S(e.id)()}),[a,S,d,u]),O=(0,x.useCallback)((e=>{const[t]=u.filter((t=>!e.find((e=>t.id===e.id))));S(t.id)()}),[S,u]);return(0,o.createElement)("div",{className:y()("woocommerce-search-list",t,{"is-compact":r,"is-loading":c,"is-token":"token"===h})},"text"===h&&(0,o.createElement)(M,{...e,onRemove:S,messages:_}),(0,o.createElement)("div",{className:"woocommerce-search-list__search"},"text"===h?(0,o.createElement)(g.TextControl,{label:_.search,type:"search",value:E,onChange:e=>w(e)}):(0,o.createElement)(g.FormTokenField,{disabled:c,label:_.search,onChange:O,onInputChange:e=>w(e),suggestions:[],__experimentalValidateInput:()=>!1,value:c?[(0,l.__)("Loading…","woocommerce")]:u.map((e=>({...e,value:e.name}))),__experimentalShowHowTo:!1})),c?(0,o.createElement)("div",{className:"woocommerce-search-list__list"},(0,o.createElement)(g.Spinner,null)):(0,o.createElement)(A,{...e,search:E,filteredList:k,messages:_,onSelect:N,instanceId:f,useExpandedPanelId:b}))},V=((0,g.withSpokenMessages)(H),window.wp.url),D=window.wp.apiFetch;var z=r.n(D);const Z=(0,R.createHigherOrderComponent)((e=>class extends x
(0,l._n)("%d category selected","%d categories selected",e,"woocommerce"),e),updated:(0,l.__)("Category search results updated.","woocommerce")};return t?(0,o.createElement)(G,{error:t}):(0,o.createElement)(o.Fragment,null,(0,o.createElement)(H,{className:"woocommerce-product-categories",list:e,isLoading:r,selected:s.map((t=>e.find((e=>e.id===t)))).filter(Boolean),onChange:n,renderItem:e=>{const{item:t,search:r,depth:n=0}=e,c=t.breadcrumbs.length?`${t.breadcrumbs.join(", ")}, ${t.name}`:t.name,a=m?(0,l.sprintf)(/* translators: %1$s is the item name, %2$d is the count of reviews for the item. */
(0,l._n)("%1$s, has %2$d review","%1$s, has %2$d reviews",t.review_count,"woocommerce"),c,t.review_count):(0,l.sprintf)(/* translators: %1$s is the item name, %2$d is the count of products for the item. */
(0,l._n)("%1$s, has %2$d product","%1$s, has %2$d products",t.count,"woocommerce"),c,t.count),s=m?(0,l.sprintf)(/* translators: %d is the count of reviews. */
(0,l._n)("%d review","%d reviews",t.review_count,"woocommerce"),t.review_count):(0,l.sprintf)(/* translators: %d is the count of products. */
(0,l._n)("%d product","%d products",t.count,"woocommerce"),t.count);return(0,o.createElement)(P,{className:y()("woocommerce-product-categories__item","has-count",{"is-searching":r.length>0,"is-skip-level":0===n&&0!==t.parent}),...e,countLabel:s,"aria-label":a})},messages:u,isCompact:i,isHierarchical:!0,isSingle:d}),!!c&&(0,o.createElement)("div",{hidden:s.length<2},(0,o.createElement)(g.SelectControl,{className:"woocommerce-product-categories__operator",label:(0,l.__)("Display products matching","woocommerce"),help:(0,l.__)("Pick at least two categories to use this setting.","woocommerce"),value:a,onChange:c,options:[{label:(0,l.__)("Any selected categories","woocommerce"),value:"any"},{label:(0,l.__)("All selected categories","woocommerce"),value:"all"}]})))};J.defaultProps={operator:"any",isCompact:!1,isSingle:!1};const K=Z(J),Q=(0,d.getSetting)("hideOutOfStockItems",!1),Y=(0,d.getSetting)("stockStatusOptions",{}),q=({value:e,setAttributes:t})=>{const{outofstock:r,...n}=Y,c=Q?n:Y,a=Object.entries(c).map((([e,t])=>({value:e,label:t}))).filter((e=>!!e.label)),s=Object.keys(c).filter((e=>!!e)),[i,d]=(0,x.useState)(e||s);(0,x.useEffect)((()=>{t({stockStatus:["",...i]})}),[i,t]);const m=(0,x.useCallback)((e=>{const t=i.includes(e),r=i.filter((t=>t!==e));t||(r.push(e),r.sort()),d(r)}),[i]);return(0,o.createElement)(o.Fragment,null,a.map((e=>{const t=i.includes(e.value)?/* translators: %s stock status. */(0,l.__)('Stock status "%s" visible.',"woocommerce"):/* translators: %s stock status. */(0,l.__)('Stock status "%s" hidden.',"woocommerce");return(0,o.createElement)(g.ToggleControl,{label:e.label,key:e.value,help:(0,l.sprintf)(t,e.label),checked:i.includes(e.value),onChange:()=>m(e.value)})})))},U=(0,o.createElement)("svg",{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 230 250",style:{width:"100%"}},(0,o.createElement)("title",null,"Grid Block Preview"),(0,o.createElement)("rect",{width:"65.374",height:"65.374",x:".162",y:".779",fill:"#E1E3E6",rx:"3"}),(0,o.createElement)("rect",{width:"47.266",height:"5.148",x:"9.216",y:"76.153",fill:"#E1E3E6",rx:"2.574"}),(0,o.createElement)("rect",{width:"62.8",height:"15",x:"1.565",y:"101.448",fill:"#E1E3E6",rx:"5"}),(0,o.createElement)("rect",{width:"65.374",height:"65.374",x:".162",y:"136.277",fill:"#E1E3E6",rx:"3"}),(0,o.createElement)("rect",{width:"47.266",height:"5.148",x:"9.216",y:"211.651",fill:"#E1E3E6",rx:"2.574"}),(0,o.createElement)("rect",{width:"62.8",height:"15",x:"1.565",y:"236.946",fill:"#E1E3E6",rx:"5"}),(0,o.createElement)("rect",{width:"65.374",height:"65.374",x:"82.478",y:".779",fill:"#E1E3E6",rx:"3"}),(0,o.createElement)("rect",{width:"47.266",height:"5.148",x:"91.532",y:"76.153",fill:"#E1E3E6",rx:"2.574"}),(0,o.createElement)("rect",{width:"62.8",height:"15",x:"83.882",y:"101.448",fill:"#E1E3E6",rx:"5"}),(0,o.createElement)("rect",{width:"65.374",height:"65.374",x:"82.478",y:"136.277",fill:"#E1E3E6",rx:"3"}),(0,o.createElement)("rect",{width:"47.266",height:"5.148",x:"91.532",y:"211.651",fill:"#E1E3E6",rx:"2.574"}),(0,o.createElement)("rect",{width:"62.8",height:"15",x:"83.882",y:"236.946",fill:"#E1E3E6",rx:"5"}),(0,o.createElement)("rect",{width:"65.374",height:"65.374",x:"164.788",y:".779",fill:"#E1E3E6",rx:"3"}),(0,o.createElement)("rect",{width:"47.266",height:"5.148",x:"173.843",y:"76.153",fill:"#E1E3E6",rx:"2.574"}),(0,o.createElement)("rect",{width:"62.8",height:"15",x:"166.192",y:"101.448",fill:"#E1E3E6",rx:"5"}),(0,o.createElement)("rect",{width:"65.374",height:"65.374",x:"164.788",y:"136.277",fill:"#E1E3E6",rx:"3"}),(0,o.createElement)("rect",{width:"47.266",height:"5.148",x:"173.843",y:"211.651",fill:"#E1E3E6",rx:"2.574"}),(0,o.createElement)("rect",{width:"62.8",height:"15",x:"166.192",y:"236.946",fill:"#E1E3E6",rx:"5"}),(0,o.createElement)("rect",{width:"6.177",height:"6.177",x:"13.283",y:"86.301",fill:"#E1E3E6",rx:"3"}),(0,o.createElement)("rect",{width:"6.177",height:"6.177",x:"21.498",y:"86.301",fill:"#E1E3E6",rx:"3"}),(0,o.createElement)("rect",{width:"6.177",height:"6.177",x:"29.713",y:"86.301",fill:"#E1E3E6",rx:"3"}),(0,o.createEle