11 lines
No EOL
44 KiB
JavaScript
11 lines
No EOL
44 KiB
JavaScript
(()=>{var e,t={9161:(e,t,o)=>{"use strict";o.r(t);const r=window.wp.blocks,n=JSON.parse('{"$schema":"https://schemas.wp.org/trunk/block.json","apiVersion":2,"name":"woocommerce/product-collection","version":"1.0.0","title":"Product Collection (Beta)","description":"Display a collection of products from your store.","category":"woocommerce","keywords":["WooCommerce","Products (Beta)"],"textdomain":"woocommerce","attributes":{"queryId":{"type":"number"},"query":{"type":"object"},"tagName":{"type":"string"},"displayLayout":{"type":"object"},"convertedFromProducts":{"type":"boolean","default":false}},"providesContext":{"queryId":"queryId","query":"query","displayLayout":"displayLayout"},"supports":{"align":["wide","full"],"anchor":true,"html":false,"__experimentalLayout":true}}');var c=o(9196);const l=window.wp.blockEditor;var a=o(4333),s=o(9307);let u=function(e){return e.SINGLE="single",e.THUMBNAIL="thumbnail",e}({});const i=window.wp.components;var m=o(229);function d(e,{blockDescription:t,blockIcon:o,blockTitle:n,variationName:c}){(0,r.registerBlockVariation)(e,{description:t,name:c,title:n,isActive:e=>e.__woocommerceNamespace===c,icon:{src:o},attributes:{__woocommerceNamespace:c},scope:["block","inserter"]})}var p=o(5736),b=o(1984);const g=(0,p.__)("Product Title","woocommerce"),_=((0,c.createElement)(b.Z,{icon:m.Z,className:"wc-block-editor-components-block-icon"}),(0,p.__)("Display the title of a product.","woocommerce")),w="woocommerce/product-collection/product-title",h=window.wp.hooks;var y=o(7286),k=o(6755);o(4662);const E=({text:e,title:t=(0,p.__)("Feedback?","woocommerce"),url:o})=>{const[r,n]=(0,s.useState)(!1);return(0,s.useEffect)((()=>{n(!0)}),[]),(0,c.createElement)(c.Fragment,null,r&&(0,c.createElement)("div",{className:"wc-block-feedback-prompt"},(0,c.createElement)(b.Z,{icon:y.Z}),(0,c.createElement)("h2",{className:"wc-block-feedback-prompt__title"},t),(0,c.createElement)("p",{className:"wc-block-feedback-prompt__text"},e),(0,c.createElement)("a",{href:o,className:"wc-block-feedback-prompt__link",rel:"noreferrer noopener",target:"_blank"},(0,p.__)("Give us your feedback.","woocommerce"),(0,c.createElement)(b.Z,{icon:k.Z,size:16}))))},f=()=>(0,c.createElement)(E,{text:(0,p.__)("Thanks for trying out the Product Collection block! Help us make it better by sharing your feedback.","woocommerce"),title:(0,p.__)("Share your feedback!","woocommerce"),url:"https://airtable.com/shrqsMSDPvAKoY99u"}),v=window.wp.data,S=window.wc.wcSettings,C="wc-blocks_upgraded-products-to-product-collection",x=()=>({status:"notseen",time:Date.now(),displayCount:0}),N=e=>"woocommerce/product-collection"===e.name&&e.attributes.convertedFromProducts,I=(e,t)=>{let o=[];return e.forEach((e=>{t(e)&&(o=[...o,e.clientId]),o=[...o,...I(e.innerBlocks,t)]})),o},P=(0,S.getSettingWithCoercion)("postTemplateHasSupportForGridView",!1,(e=>"boolean"==typeof e)),T=()=>{const e=window.localStorage.getItem(C);return e?JSON.parse(e):x()},A=e=>{window.localStorage.setItem(C,JSON.stringify(e))};let O=function(e){return e.GRID="flex",e.STACK="list",e}({}),B=function(e){return e.IN="in",e.NOT_IN="not-in",e}({});function L(e,t){const{query:o}=e.attributes;e.setAttributes({query:{...o,...t}})}function R(){const e=(0,v.select)("core/edit-site"),t=null==e?void 0:e.getEditedPostId();return!!t&&["woocommerce/woocommerce//archive-product","woocommerce/woocommerce//taxonomy-product_cat","woocommerce/woocommerce//taxonomy-product_tag","woocommerce/woocommerce//taxonomy-product_attribute","woocommerce/woocommerce//product-search-results"].includes(t)}const q=(0,S.getSetting)("stockStatusOptions",[]),D=(0,S.getSetting)("hideOutOfStockItems",!1),F=()=>D?Object.keys(function(e,t){const{[t]:o,...r}=e;return r}(q,"outofstock")):Object.keys(q),M={perPage:9,pages:0,offset:0,postType:"product",order:"asc",orderBy:"title",search:"",exclude:[],inherit:null,taxQuery:{},isProductCollectionBlock:!0,featured:!1,woocommerceOnSale:!1,woocommerceStockStatus:F(),woocommerceAttributes:[],woocommerceHandPickedProducts:[],timeFrame:void 0},j={query:M,tagName:"div",displayLayout:{type:O.GRID,columns:3,shrinkColumns:!1}},G=e=>({...e,orderBy:M.orderBy,order:M.order,inherit:R()}),$=()=>j.displayLayout,V={woocommerceOnSale:M.woocommerceOnSale,woocommerceStockStatus:F(),woocommerceAttributes:[],taxQuery:M.taxQuery,woocommerceHandPickedProducts:[],featured:M.featured,timeFrame:void 0};const H=e=>"flex"===e?"grid":"list"===e?"default":"grid",Q=e=>{const{type:t,columns:o}=e;return{type:H(t),columnCount:o}},Z=(e,t)=>{const o=e.map((e=>{const{name:o,attributes:n}=e,c=Z(e.innerBlocks);return(({name:e})=>"woocommerce/product-template"===e)(e)?((e,t,o)=>(0,r.createBlock)("core/post-template",{className:"products-block-post-template",layout:P?Q(o):void 0,__woocommerceNamespace:"woocommerce/product-query/product-template",...e.attributes},t))(e,c,t):(({name:e,attributes:t})=>"core/post-title"===e&&"woocommerce/product-collection/product-title"===t.__woocommerceNamespace)(e)?((e,t)=>{const{__woocommerceNamespace:o,...n}=e.attributes;return(0,r.createBlock)("core/post-title",{__woocommerceNamespace:"woocommerce/product-collection/product-title",...n},t)})(e,c):(({name:e,attributes:t})=>"core/post-excerpt"===e&&"woocommerce/product-collection/product-summary"===t.__woocommerceNamespace)(e)?((e,t)=>{const{__woocommerceNamespace:o,...n}=e.attributes;return(0,r.createBlock)("core/post-excerpt",{__woocommerceNamespace:"woocommerce/product-collection/product-summary",...n},t)})(e,c):(0,r.createBlock)(o,n,c)}));return o},z=e=>{const t=(0,v.select)("core/block-editor").getBlock(e),o=((e,t)=>{const o=(0,v.select)("core/block-editor").getBlockRootClientId(e)||void 0;return(0,v.select)("core/block-editor").canInsertBlockType(t,o)})(e,"core/query");if(t&&o){const{attributes:o={},innerBlocks:n=[]}=t,{displayLayout:c,...l}=o,a=(e=>{const{query:t,...o}=e,{woocommerceAttributes:r,woocommerceStockStatus:n,woocommerceOnSale:c,woocommerceHandPickedProducts:l,taxQuery:a,isProductCollectionBlock:s,...u}=t,i={...u};return l&&(i.include=l),c&&(i.__woocommerceOnSale=c),a&&(i.taxQuery=a),{...o,namespace:"woocommerce/product-query",query:{__woocommerceAttributes:r||[],__woocommerceStockStatus:n||[],...i}}})(P?l:o),s=Z(n,c),u=(0,r.createBlock)("core/query",a,s);return(0,v.dispatch)("core/block-editor").replaceBlock(e,u),!0}return!1},J=()=>{var e;A({status:"reverted",time:Date.now()}),(e=(0,v.select)("core/block-editor").getBlocks(),I(e,N)).map(z)},K=(0,s.createInterpolateElement)((0,p.__)("Products (Beta) block was upgraded to <strongText />, an updated version with new features and simplified settings.","woocommerce"),{strongText:(0,c.createElement)("strong",null,(0,p.__)("Product Collection","woocommerce"))}),U=(0,p.__)("Revert to Products (Beta)","woocommerce"),W=({revertMigration:e})=>{const[t,o]=((e,t)=>{const[o,r]=(0,s.useState)((()=>{const o=window.localStorage.getItem(e);if(o)try{return JSON.parse(o)}catch{console.error(`Value for key '${e}' could not be retrieved from localStorage because it can't be parsed.`)}return t}));return(0,s.useEffect)((()=>{try{window.localStorage.setItem(e,JSON.stringify(o))}catch{console.error(`Value for key '${e}' could not be saved in localStorage because it can't be converted into a string.`)}}),[e,o]),[o,r]})(C,x()),r=(0,s.useRef)(!0),{status:n}=t;return(0,s.useEffect)((()=>()=>{r.current&&((()=>{const e=T(),t="number"==typeof e.displayCount?e.displayCount+1:0;A({...e,displayCount:t})})(),r.current=!1)}),[r]),"notseen"===n?(0,c.createElement)(i.Notice,{onRemove:()=>{o({status:"seen",time:Date.now()})}},(0,c.createElement)(c.Fragment,null,K," "),(0,c.createElement)("br",null),(0,c.createElement)("br",null),(0,c.createElement)(i.Button,{variant:"link",onClick:()=>{e()}},U)):null},Y=(0,p.__)("Shrink columns to fit","woocommerce"),X=(0,p.__)("Reduce the number of columns to better fit smaller screens and spaces.","woocommerce"),ee=e=>e?(0,p.__)("Max Columns","woocommerce"):(0,p.__)("Columns","woocommerce"),te=e=>{const{type:t,columns:o,shrinkColumns:r}=e.displayLayout,n="flex"===t,l=$(),a=()=>{e.setAttributes({displayLayout:l})};return n?(0,c.createElement)(c.Fragment,null,(0,c.createElement)(i.__experimentalToolsPanelItem,{hasValue:()=>(null==l?void 0:l.shrinkColumns)!==r,isShownByDefault:!0,onDeselect:a},(0,c.createElement)(i.ToggleControl,{checked:!!r,label:Y,help:X,onChange:t=>{e.setAttributes({displayLayout:{...e.displayLayout,shrinkColumns:t}})}})),(0,c.createElement)(i.__experimentalToolsPanelItem,{hasValue:()=>(null==l?void 0:l.columns)!==o||(null==l?void 0:l.type)!==t,isShownByDefault:!0,onDeselect:a},(0,c.createElement)(i.RangeControl,{label:ee(!!r),onChange:t=>e.setAttributes({displayLayout:{...e.displayLayout,columns:t}}),value:o,min:2,max:Math.max(6,o)}))):null},oe=e=>!(e=>null===e)(e)&&e instanceof Object&&e.constructor===Object;function re(e,t){return oe(e)&&t in e}const ne=(0,p.__)("Inherit query from template","woocommerce"),ce=({setQueryAttribute:e,query:t})=>{const o=null==t?void 0:t.inherit,r=(0,v.select)("core/edit-site"),n=function(e,t){const o=(0,s.useRef)();return(0,s.useEffect)((()=>{o.current===e||t&&!t(e,o.current)||(o.current=e)}),[e,t]),o.current}(t,(e=>!1===(null==e?void 0:e.inherit))),l=(0,s.useMemo)((()=>R()),[]);return(e=>{if(oe(e)){const t=e.getEditedPostType();return"wp_template"===t||"wp_template_part"===t}return!1})(r)?(0,c.createElement)(i.__experimentalToolsPanelItem,{label:ne,hasValue:()=>o!==l,isShownByDefault:!0,onDeselect:()=>{e({inherit:l})}},(0,c.createElement)(i.ToggleControl,{className:"wc-block-product-collection__inherit-query-control",label:ne,help:(0,p.__)("Toggle to use the global query context that is set with the current template, such as an archive or search. Disable to customize the settings independently.","woocommerce"),checked:!!o,onChange:t=>{e(t?{...M,inherit:t}:{...M,...n,inherit:t})}})):null},le=[{label:(0,p.__)("A → Z","woocommerce"),value:"title/asc"},{label:(0,p.__)("Z → A","woocommerce"),value:"title/desc"},{label:(0,p.__)("Newest to oldest","woocommerce"),value:"date/desc"},{label:(0,p.__)("Oldest to newest","woocommerce"),value:"date/asc"},{value:"popularity/desc",label:(0,p.__)("Best Selling","woocommerce")},{value:"rating/desc",label:(0,p.__)("Top Rated","woocommerce")}],ae=e=>{const{query:t,setQueryAttribute:o}=e,{order:r,orderBy:n}=t,l=G(t);return(0,c.createElement)(i.__experimentalToolsPanelItem,{label:(0,p.__)("Order by","woocommerce"),hasValue:()=>r!==(null==l?void 0:l.order)||n!==(null==l?void 0:l.orderBy),isShownByDefault:!0,onDeselect:()=>{o(l)}},(0,c.createElement)(i.SelectControl,{value:`${n}/${r}`,options:le,label:(0,p.__)("Order by","woocommerce"),onChange:e=>{const[t,r]=e.split("/");o({order:r,orderBy:t})}}))},se=e=>{const{query:t,setQueryAttribute:o}=e;return(0,c.createElement)(i.__experimentalToolsPanelItem,{label:(0,p.__)("On Sale","woocommerce"),hasValue:()=>!0===t.woocommerceOnSale,isShownByDefault:!0,onDeselect:()=>{o({woocommerceOnSale:!1})}},(0,c.createElement)(i.ToggleControl,{label:(0,p.__)("Show only products on sale","woocommerce"),checked:t.woocommerceOnSale||!1,onChange:e=>{o({woocommerceOnSale:e})}}))};var ue=o(2991),ie=o.n(ue);function me(e){var t;const o="string"==typeof e?e:e.value;return null===(t=Object.entries(q).find((([,e])=>e===o)))||void 0===t?void 0:t[0]}const de=e=>{var t;const{query:o,setQueryAttribute:r}=e;return(0,c.createElement)(i.__experimentalToolsPanelItem,{label:(0,p.__)("Stock status","woocommerce"),hasValue:()=>!ie()(o.woocommerceStockStatus,F()),onDeselect:()=>{r({woocommerceStockStatus:F()})},isShownByDefault:!0},(0,c.createElement)(i.FormTokenField,{label:(0,p.__)("Stock status","woocommerce"),onChange:e=>{const t=e.map(me).filter(Boolean);r({woocommerceStockStatus:t})},suggestions:Object.values(q),validateInput:e=>Object.values(q).includes(e),value:(null==o||null===(t=o.woocommerceStockStatus)||void 0===t?void 0:t.map((e=>q[e])))||[],__experimentalExpandOnFocus:!0,__experimentalShowHowTo:!1}))},pe=e=>{const{query:t,setQueryAttribute:o}=e,[r,n]=(0,s.useState)(t.search),l=(0,a.useDebounce)((()=>{t.search!==r&&o({search:r})}),250);return(0,s.useEffect)((()=>(l(),l.cancel)),[r,l]),(0,c.createElement)(i.__experimentalToolsPanelItem,{hasValue:()=>!!r,label:(0,p.__)("Keyword","woocommerce"),onDeselect:()=>n(""),resetAllFilter:()=>n("")},(0,c.createElement)(i.TextControl,{label:(0,p.__)("Keyword","woocommerce"),value:r,onChange:n}))};var be=o(4184),ge=o.n(be);function _e(e,t,o){const r=new Set(t.map((e=>e[o])));return e.filter((e=>!r.has(e[o])))}const we=window.wp.htmlEntities,he={clear:(0,p.__)("Clear all selected items","woocommerce"),noItems:(0,p.__)("No items found.","woocommerce"),
|
||
/* Translators: %s search term */
|
||
noResults:(0,p.__)("No results for %s","woocommerce"),search:(0,p.__)("Search for items","woocommerce"),selected:e=>(0,p.sprintf)(/* translators: Number of items selected from list. */
|
||
(0,p._n)("%d item selected","%d items selected",e,"woocommerce"),e),updated:(0,p.__)("Search results updated.","woocommerce")},ye=(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=("id",t.reduce(((e,t)=>(e[String(t.id)]=t,e)),{}));const n=["0"],c=(e={})=>e.parent?[...c(r[e.parent]),e.name]:e.name?[e.name]:[],l=e=>e.map((e=>{const t=o[e.id];return n.push(""+e.id),{...e,breadcrumbs:c(r[e.parent]),children:t&&t.length?l(t):[]}})),a=l(o[0]||[]);return Object.entries(o).forEach((([e,t])=>{n.includes(e)||a.push(...l(t||[]))})),a},ke=(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,c.createElement)("strong",{key:t},e):(0,c.createElement)(s.Fragment,{key:t},e)))},Ee=({label:e})=>(0,c.createElement)("span",{className:"woocommerce-search-list__item-count"},e),fe=e=>{const{item:t,search:o}=e,r=t.breadcrumbs&&t.breadcrumbs.length;return(0,c.createElement)("span",{className:"woocommerce-search-list__item-label"},r?(0,c.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,c.createElement)("span",{className:"woocommerce-search-list__item-name"},ke((0,we.decodeEntities)(t.name),o)));var n},ve=({countLabel:e,className:t,depth:o=0,controlId:r="",item:n,isSelected:l,isSingle:a,onSelect:u,search:m="",selected:d,useExpandedPanelId:p,...b})=>{var g,_;const[w,h]=p,y=null!=e&&void 0!==n.count&&null!==n.count,k=!(null===(g=n.breadcrumbs)||void 0===g||!g.length),E=!(null===(_=n.children)||void 0===_||!_.length),f=w===n.id,v=ge()(["woocommerce-search-list__item",`depth-${o}`,t],{"has-breadcrumbs":k,"has-children":E,"has-count":y,"is-expanded":f,"is-radio-button":a}),S=b.name||`search-list-item-${r}`,C=`${S}-${n.id}`,x=(0,s.useCallback)((()=>{h(f?-1:Number(n.id))}),[f,n.id,h]);return E?(0,c.createElement)("div",{className:v,onClick:x,onKeyDown:e=>"Enter"===e.key||" "===e.key?x():null,role:"treeitem",tabIndex:0},a?(0,c.createElement)(c.Fragment,null,(0,c.createElement)("input",{type:"radio",id:C,name:S,value:n.value,onChange:u(n),onClick:e=>e.stopPropagation(),checked:l,className:"woocommerce-search-list__item-input",...b}),(0,c.createElement)(fe,{item:n,search:m}),y?(0,c.createElement)(Ee,{label:e||n.count}):null):(0,c.createElement)(c.Fragment,null,(0,c.createElement)(i.CheckboxControl,{className:"woocommerce-search-list__item-input",checked:l,...!l&&n.children.some((e=>d.find((t=>t.id===e.id))))?{indeterminate:!0}:{},label:ke((0,we.decodeEntities)(n.name),m),onChange:()=>{l?u(_e(d,n.children,"id"))():u(function(e,t,o){const r=_e(t,e,"id");return[...e,...r]}(d,n.children))()},onClick:e=>e.stopPropagation()}),y?(0,c.createElement)(Ee,{label:e||n.count}):null)):(0,c.createElement)("label",{htmlFor:C,className:v},a?(0,c.createElement)(c.Fragment,null,(0,c.createElement)("input",{...b,type:"radio",id:C,name:S,value:n.value,onChange:u(n),checked:l,className:"woocommerce-search-list__item-input"}),(0,c.createElement)(fe,{item:n,search:m})):(0,c.createElement)(i.CheckboxControl,{...b,id:C,name:S,className:"woocommerce-search-list__item-input",value:(0,we.decodeEntities)(n.value),label:ke((0,we.decodeEntities)(n.name),m),onChange:u(n),checked:l}),y?(0,c.createElement)(Ee,{label:e||n.count}):null)},Se=ve;var Ce=o(5430),xe=o(906);o(5932);const Ne=({id:e,label:t,popoverContents:o,remove:r,screenReaderLabel:n,className:l=""})=>{const[u,m]=(0,s.useState)(!1),d=(0,a.useInstanceId)(Ne);if(n=n||t,!t)return null;t=(0,we.decodeEntities)(t);const g=ge()("woocommerce-tag",l,{"has-remove":!!r}),_=`woocommerce-tag__label-${d}`,w=(0,c.createElement)(c.Fragment,null,(0,c.createElement)("span",{className:"screen-reader-text"},n),(0,c.createElement)("span",{"aria-hidden":"true"},t));return(0,c.createElement)("span",{className:g},o?(0,c.createElement)(i.Button,{className:"woocommerce-tag__text",id:_,onClick:()=>m(!0)},w):(0,c.createElement)("span",{className:"woocommerce-tag__text",id:_},w),o&&u&&(0,c.createElement)(i.Popover,{onClose:()=>m(!1)},o),r&&(0,c.createElement)(i.Button,{className:"woocommerce-tag__remove",onClick:r(e),label:(0,p.sprintf)(
|
||
// Translators: %s label.
|
||
(0,p.__)("Remove %s","woocommerce"),t),"aria-describedby":_},(0,c.createElement)(b.Z,{icon:xe.Z,size:20,className:"clear-icon",role:"img"})))},Ie=Ne;o(8462);const Pe=e=>(0,c.createElement)(Se,{...e}),Te=e=>{const{list:t,selected:o,renderItem:r,depth:n=0,onSelect:l,instanceId:a,isSingle:u,search:i,useExpandedPanelId:m}=e,[d]=m;return t?(0,c.createElement)(s.Fragment,null,t.map((t=>{var p,b;const g=null!==(p=t.children)&&void 0!==p&&p.length&&!u?t.children.every((({id:e})=>o.find((t=>t.id===e)))):!!o.find((({id:e})=>e===t.id)),_=(null===(b=t.children)||void 0===b?void 0:b.length)&&d===t.id;return(0,c.createElement)(s.Fragment,{key:t.id},(0,c.createElement)("li",null,r({item:t,isSelected:g,onSelect:l,isSingle:u,selected:o,search:i,depth:n,useExpandedPanelId:m,controlId:a})),_?(0,c.createElement)(Te,{...e,list:t.children,depth:n+1}):null)}))):null},Ae=({isLoading:e,isSingle:t,selected:o,messages:r,onChange:n,onRemove:l})=>{if(e||t||!o)return null;const a=o.length;return(0,c.createElement)("div",{className:"woocommerce-search-list__selected"},(0,c.createElement)("div",{className:"woocommerce-search-list__selected-header"},(0,c.createElement)("strong",null,r.selected(a)),a>0?(0,c.createElement)(i.Button,{isLink:!0,isDestructive:!0,onClick:()=>n([]),"aria-label":r.clear},(0,p.__)("Clear all","woocommerce")):null),a>0?(0,c.createElement)("ul",null,o.map(((e,t)=>(0,c.createElement)("li",{key:t},(0,c.createElement)(Ie,{label:e.name,id:e.id,remove:l}))))):null)},Oe=({filteredList:e,search:t,onSelect:o,instanceId:r,useExpandedPanelId:n,...l})=>{const{messages:a,renderItem:s,selected:u,isSingle:i}=l,m=s||Pe;return 0===e.length?(0,c.createElement)("div",{className:"woocommerce-search-list__list is-not-found"},(0,c.createElement)("span",{className:"woocommerce-search-list__not-found-icon"},(0,c.createElement)(b.Z,{icon:Ce.Z,role:"img"})),(0,c.createElement)("span",{className:"woocommerce-search-list__not-found-text"},t?(0,p.sprintf)(a.noResults,t):a.noItems)):(0,c.createElement)("ul",{className:"woocommerce-search-list__list"},(0,c.createElement)(Te,{useExpandedPanelId:n,list:e,selected:u,renderItem:m,onSelect:o,instanceId:r,isSingle:i,search:t}))},Be=e=>{const{className:t="",isCompact:o,isHierarchical:r,isLoading:n,isSingle:l,list:u,messages:m=he,onChange:d,onSearch:b,selected:g,type:_="text",debouncedSpeak:w}=e,[h,y]=(0,s.useState)(""),k=(0,s.useState)(-1),E=(0,a.useInstanceId)(Be),f=(0,s.useMemo)((()=>({...he,...m})),[m]),v=(0,s.useMemo)((()=>((e,t,o)=>{if(!t)return o?ye(e):e;const r=new RegExp(t.replace(/[-\/\\^$*+?.()|[\]{}]/g,"\\$&"),"i"),n=e.map((e=>!!r.test(e.name)&&e)).filter(Boolean);return o?ye(n,e):n})(u,h,r)),[u,h,r]);(0,s.useEffect)((()=>{w&&w(f.updated)}),[w,f]),(0,s.useEffect)((()=>{"function"==typeof b&&b(h)}),[h,b]);const S=(0,s.useCallback)((e=>()=>{l&&d([]);const t=g.findIndex((({id:t})=>t===e));d([...g.slice(0,t),...g.slice(t+1)])}),[l,g,d]),C=(0,s.useCallback)((e=>()=>{Array.isArray(e)?d(e):-1===g.findIndex((({id:t})=>t===e.id))?d(l?[e]:[...g,e]):S(e.id)()}),[l,S,d,g]),x=(0,s.useCallback)((e=>{const[t]=g.filter((t=>!e.find((e=>t.id===e.id))));S(t.id)()}),[S,g]);return(0,c.createElement)("div",{className:ge()("woocommerce-search-list",t,{"is-compact":o,"is-loading":n,"is-token":"token"===_})},"text"===_&&(0,c.createElement)(Ae,{...e,onRemove:S,messages:f}),(0,c.createElement)("div",{className:"woocommerce-search-list__search"},"text"===_?(0,c.createElement)(i.TextControl,{label:f.search,type:"search",value:h,onChange:e=>y(e)}):(0,c.createElement)(i.FormTokenField,{disabled:n,label:f.search,onChange:x,onInputChange:e=>y(e),suggestions:[],__experimentalValidateInput:()=>!1,value:n?[(0,p.__)("Loading…","woocommerce")]:g.map((e=>({...e,value:e.name}))),__experimentalShowHowTo:!1})),n?(0,c.createElement)("div",{className:"woocommerce-search-list__list"},(0,c.createElement)(i.Spinner,null)):(0,c.createElement)(Oe,{...e,search:h,filteredList:v,messages:f,onSelect:C,instanceId:E,useExpandedPanelId:k}))},Le=((0,i.withSpokenMessages)(Be),window.wp.url),Re=window.wp.apiFetch;var qe,De,Fe,Me,je,Ge,$e,Ve,He,Qe,Ze=o.n(Re);const ze=(0,S.getSetting)("wcBlocksConfig",{buildPhase:1,pluginUrl:"",productCount:0,defaultAvatar:"",restApiRoutes:{},wordCountType:"words"}),Je=(ze.pluginUrl,ze.pluginUrl,ze.buildPhase,null===(qe=S.STORE_PAGES.shop)||void 0===qe||qe.permalink,null===(De=S.STORE_PAGES.checkout)||void 0===De||De.id,null===(Fe=S.STORE_PAGES.checkout)||void 0===Fe||Fe.permalink,null===(Me=S.STORE_PAGES.privacy)||void 0===Me||Me.permalink,null===(je=S.STORE_PAGES.privacy)||void 0===je||je.title,null===(Ge=S.STORE_PAGES.terms)||void 0===Ge||Ge.permalink,null===($e=S.STORE_PAGES.terms)||void 0===$e||$e.title,null===(Ve=S.STORE_PAGES.cart)||void 0===Ve||Ve.id,null===(He=S.STORE_PAGES.cart)||void 0===He||He.permalink,null!==(Qe=S.STORE_PAGES.myaccount)&&void 0!==Qe&&Qe.permalink?S.STORE_PAGES.myaccount.permalink:(0,S.getSetting)("wpLoginUrl","/wp-login.php"),(0,S.getSetting)("localPickupEnabled",!1),(0,S.getSetting)("countries",{})),Ke=(0,S.getSetting)("countryData",{}),Ue=(Object.fromEntries(Object.keys(Ke).filter((e=>!0===Ke[e].allowBilling)).map((e=>[e,Je[e]||""]))),Object.fromEntries(Object.keys(Ke).filter((e=>!0===Ke[e].allowBilling)).map((e=>[e,Ke[e].states||[]]))),Object.fromEntries(Object.keys(Ke).filter((e=>!0===Ke[e].allowShipping)).map((e=>[e,Je[e]||""]))),Object.fromEntries(Object.keys(Ke).filter((e=>!0===Ke[e].allowShipping)).map((e=>[e,Ke[e].states||[]]))),Object.fromEntries(Object.keys(Ke).map((e=>[e,Ke[e].locale||[]]))),(e,t)=>{const o=new Map;return e.filter((e=>{const r=t(e);return!o.has(r)&&(o.set(r,e),!0)}))}),We=e=>Ze()({path:`wc/store/v1/products/attributes/${e}/terms`});const Ye=window.wp.escapeHtml,Xe=({error:e})=>(0,c.createElement)("div",{className:"wc-block-error-message"},(({message:e,type:t})=>e?"general"===t?(0,c.createElement)("span",null,(0,p.__)("The following error was returned","woocommerce"),(0,c.createElement)("br",null),(0,c.createElement)("code",null,(0,Ye.escapeHTML)(e))):"api"===t?(0,c.createElement)("span",null,(0,p.__)("The following error was returned from the API","woocommerce"),(0,c.createElement)("br",null),(0,c.createElement)("code",null,(0,Ye.escapeHTML)(e))):e:(0,p.__)("An error has prevented the block from being updated.","woocommerce"))(e)),et=({className:e,item:t,isSelected:o,isLoading:r,onSelect:n,disabled:l,...a})=>(0,c.createElement)(c.Fragment,null,(0,c.createElement)(ve,{...a,key:t.id,className:e,isSelected:o,item:t,onSelect:n,disabled:l}),o&&r&&(0,c.createElement)("div",{key:"loading",className:ge()("woocommerce-search-list__item","woocommerce-product-attributes__item","depth-1","is-loading","is-not-active")},(0,c.createElement)(i.Spinner,null))),tt=((0,S.getSetting)("attributes",[]).reduce(((e,t)=>{const o=(r=t)&&r.attribute_name?{id:parseInt(r.attribute_id,10),name:r.attribute_name,taxonomy:"pa_"+r.attribute_name,label:r.attribute_label}:null;var r;return o&&o.id&&e.push(o),e}),[]),e=>{const{count:t,id:o,name:r,parent:n}=e;return{count:t,id:o,name:r,parent:n,breadcrumbs:[],children:[],value:(c=e,re(c,"count")&&re(c,"description")&&re(c,"id")&&re(c,"name")&&re(c,"parent")&&re(c,"slug")&&"number"==typeof c.count&&"string"==typeof c.description&&"number"==typeof c.id&&"string"==typeof c.name&&"number"==typeof c.parent&&"string"==typeof c.slug?e.attr_slug:"")};var c});o(9669);const ot=(0,a.withInstanceId)((({onChange:e,onOperatorChange:t,instanceId:o,isCompact:r=!1,messages:n={},operator:l="any",selected:a,type:u="text"})=>{const{errorLoadingAttributes:m,isLoadingAttributes:d,productsAttributes:b}=function(e){const[t,o]=(0,s.useState)(null),[r,n]=(0,s.useState)(!1),[c,l]=(0,s.useState)([]),a=(0,s.useRef)(!1);return(0,s.useEffect)((()=>{if(e&&!r&&!a.current)return async function(){n(!0);try{const e=await Ze()({path:"wc/store/v1/products/attributes"}),t=[];for(const o of e){const e=await We(o.id);t.push({...o,parent:0,terms:e.map((e=>({...e,attr_slug:o.taxonomy,parent:o.id})))})}l(t),a.current=!0}catch(e){e instanceof Error&&o(await(async e=>{if(!("json"in e))return{message:e.message,type:e.type||"general"};try{const t=await e.json();return{message:t.message,type:t.type||"api"}}catch(e){return{message:e.message,type:"general"}}})(e))}finally{n(!1)}}(),()=>{a.current=!0}}),[r,e]),{errorLoadingAttributes:t,isLoadingAttributes:r,productsAttributes:c}}(!0),g=b.reduce(((e,t)=>{const{terms:o,...r}=t;return[...e,tt(r),...o.map(tt)]}),[]);return n={clear:(0,p.__)("Clear all product attributes","woocommerce"),noItems:(0,p.__)("Your store doesn't have any product attributes.","woocommerce"),search:(0,p.__)("Search for product attributes","woocommerce"),selected:e=>(0,p.sprintf)(/* translators: %d is the count of attributes selected. */
|
||
(0,p._n)("%d attribute selected","%d attributes selected",e,"woocommerce"),e),updated:(0,p.__)("Product attribute search results updated.","woocommerce"),...n},m?(0,c.createElement)(Xe,{error:m}):(0,c.createElement)(c.Fragment,null,(0,c.createElement)(Be,{className:"woocommerce-product-attributes",isCompact:r,isHierarchical:!0,isLoading:d,isSingle:!1,list:g,messages:n,onChange:e,renderItem:e=>{const{item:t,search:r,depth:n=0}=e,l=t.count||0,a=["woocommerce-product-attributes__item","woocommerce-search-list__item",{"is-searching":r.length>0,"is-skip-level":0===n&&0!==t.parent}];if(!t.breadcrumbs.length)return(0,c.createElement)(et,{...e,className:ge()(a),item:t,isLoading:d,disabled:0===t.count,name:`attributes-${o}`,countLabel:(0,p.sprintf)(/* translators: %d is the count of terms. */
|
||
(0,p._n)("%d term","%d terms",l,"woocommerce"),l),"aria-label":(0,p.sprintf)(/* translators: %1$s is the item name, %2$d is the count of terms for the item. */
|
||
(0,p._n)("%1$s, has %2$d term","%1$s, has %2$d terms",l,"woocommerce"),t.name,l)});const s=`${t.breadcrumbs[0]}: ${t.name}`;return(0,c.createElement)(ve,{...e,name:`terms-${o}`,className:ge()(...a,"has-count"),countLabel:(0,p.sprintf)(/* translators: %d is the count of products. */
|
||
(0,p._n)("%d product","%d products",l,"woocommerce"),l),"aria-label":(0,p.sprintf)(/* translators: %1$s is the attribute name, %2$d is the count of products for that attribute. */
|
||
(0,p._n)("%1$s, has %2$d product","%1$s, has %2$d products",l,"woocommerce"),s,l)})},selected:a.map((({id:e})=>g.find((t=>t.id===e)))).filter(Boolean),type:u}),!!t&&(0,c.createElement)("div",{hidden:a.length<2},(0,c.createElement)(i.SelectControl,{className:"woocommerce-product-attributes__operator",label:(0,p.__)("Display products matching","woocommerce"),help:(0,p.__)("Pick at least two attributes to use this setting.","woocommerce"),value:l,onChange:t,options:[{label:(0,p.__)("Any selected attributes","woocommerce"),value:"any"},{label:(0,p.__)("All selected attributes","woocommerce"),value:"all"}]})))})),rt=`${S.ADMIN_URL}edit.php?post_type=product&page=product_attributes`,nt=({query:e,setQueryAttribute:t})=>{const o=e.woocommerceAttributes||[],r=null==o?void 0:o.map((({termId:e})=>({id:e})));return(0,c.createElement)(i.__experimentalToolsPanelItem,{label:(0,p.__)("Product Attributes","woocommerce"),hasValue:()=>!(null==o||!o.length)},(0,c.createElement)(ot,{messages:{search:(0,p.__)("Attributes","woocommerce")},selected:r||[],onChange:e=>{const o=e.map((({id:e,value:t})=>({termId:e,taxonomy:t})));t({woocommerceAttributes:o})},operator:"any",isCompact:!0,type:"token"}),(0,c.createElement)(i.ExternalLink,{className:"wc-block-editor-product-collection-panel__manage-attributes-link",href:rt},(0,p.__)("Manage attributes","woocommerce")))},ct=window.wp.coreData,lt=[],at={order:"asc",_fields:"id,name,slug",context:"view"},st=(e,t)=>(null==e?void 0:e.id)||t.get(e)||t.get(e.toLocaleLowerCase()),ut=(e,t,o)=>1===o.get(e)?e:`${e} - ${t}`,it=({taxonomy:e,termIds:t,onChange:o})=>{const[r,n]=(0,s.useState)(void 0),l=(0,s.useRef)(lt),u=(0,s.useRef)(lt),m=(0,a.useDebounce)(n,250),{termIdToNameMap:d,termNameToIdMap:p,isResolving:b}=(e=>{const{records:t,isResolving:o}=(0,ct.useEntityRecords)("taxonomy",e.slug,{...at});return(0,s.useMemo)((()=>{const e=new Map,r=new Map;if(!t)return{termIdToNameMap:e,termNameToIdMap:r,isResolving:o};const n=(e=>e.reduce(((e,t)=>{const o=t.name;return e.has(o)?e.set(o,e.get(o)+1):e.set(o,1),e}),new Map))(t);for(const o of t){const t=o.id,c=o.name,l=ut(c,o.slug,n);e.set(t,l),r.set(l,t),r.set(l.toLocaleLowerCase(),t)}return{termIdToNameMap:e,termNameToIdMap:r,isResolving:o}}),[t,o])})(e),{records:g,hasResolved:_}=(0,ct.useEntityRecords)("taxonomy",e.slug,{...at,search:r,orderby:"name",exclude:t,per_page:20},{enabled:void 0!==r});l.current=(0,s.useMemo)((()=>_?g.map((e=>d.get(e.id)||e.name)):l.current),[_,g,d]);const{records:w,hasResolved:h}=(0,ct.useEntityRecords)("taxonomy",e.slug,{...at,include:t},{enabled:(null==t?void 0:t.length)>0});return u.current=(0,s.useMemo)((()=>!1===h?u.current:w&&t.length?w.map((({id:e,name:t})=>({id:e,value:d.get(e)||t}))):lt),[w,h,d,t]),(0,c.createElement)("div",{className:"wc-block-editor-product-collection-inspector__taxonomy-control"},(0,c.createElement)(i.FormTokenField,{label:e.name,value:u.current,onInputChange:m,suggestions:l.current,onChange:e=>{const t=[];for(const o of e){const e=st(o,p);e&&t.push(e)}o(t)},disabled:b,__experimentalShowHowTo:!1}))},mt=function({setQueryAttribute:e,query:t}){const{taxQuery:o}=t,r=(0,v.useSelect)((e=>{const{getTaxonomies:t}=e(ct.store);return t({type:"product",per_page:-1,context:"view"})}),[]);return r&&0!==r.length?(0,c.createElement)(i.__experimentalToolsPanelItem,{label:(0,p.__)("Taxonomies","woocommerce"),hasValue:()=>Object.values(o||{}).some((e=>!!e.length)),onDeselect:()=>e({taxQuery:{}})},r.map((t=>{const r=(null==o?void 0:o[t.slug])||[];return(0,c.createElement)(it,{key:t.slug,taxonomy:t,termIds:r,onChange:r=>e({taxQuery:{...o,[t.slug]:r}})})}))):null},dt=({query:e,setQueryAttribute:t})=>{const o=e.woocommerceHandPickedProducts,{productsMap:r,productsList:n}=function(){const[e,t]=(0,s.useState)(new Map),[o,r]=(0,s.useState)([]);return(0,s.useEffect)((()=>{(({selected:e=[],search:t="",queryArgs:o={}})=>{const r=(({selected:e=[],search:t="",queryArgs:o={}})=>{const r=ze.productCount>100,n={per_page:r?100:0,catalog_visibility:"any",search:t,orderby:"title",order:"asc"},c=[(0,Le.addQueryArgs)("/wc/store/v1/products",{...n,...o})];return r&&e.length&&c.push((0,Le.addQueryArgs)("/wc/store/v1/products",{catalog_visibility:"any",include:e,per_page:0})),c})({selected:e,search:t,queryArgs:o});return Promise.all(r.map((e=>Ze()({path:e})))).then((e=>{const t=e.flat(),o=Ue(t,(e=>e.id));return o.map((e=>({...e,parent:0})))})).catch((e=>{throw e}))})({selected:[]}).then((e=>{const o=new Map;e.forEach((e=>{o.set(e.id,e),o.set(e.name,e)})),r(e),t(o)}))}),[]),{productsMap:e,productsList:o}}(),l=(0,s.useCallback)((e=>{const o=e.reduce(((e,t)=>{const o=r.get(t)||r.get(Number(t));return o&&e.add(String(o.id)),e}),new Set);t({woocommerceHandPickedProducts:Array.from(o)})}),[t,r]),a=(0,s.useMemo)((()=>n.filter((e=>!(null!=o&&o.includes(String(e.id))))).map((e=>e.name))),[n,o]);return(0,c.createElement)(i.__experimentalToolsPanelItem,{label:(0,p.__)("Hand-picked Products","woocommerce"),hasValue:()=>!(null==o||!o.length),onDeselect:()=>{t({woocommerceHandPickedProducts:[]})}},(0,c.createElement)(i.FormTokenField,{disabled:!r.size,displayTransform:e=>{const t=Number(e);if(Number.isNaN(t))return e;const o=r.get(t);return(null==o?void 0:o.name)||""},label:(0,p.__)("Pick some products","woocommerce"),onChange:l,suggestions:a,__experimentalValidateInput:e=>r.has(e),value:r.size?o||[]:[(0,p.__)("Loading…","woocommerce")],__experimentalExpandOnFocus:!0}))},pt=e=>{switch(e){case O.GRID:return(0,p.__)("Display products using rows and columns.","woocommerce");case O.STACK:return(0,p.__)("Display products in a single column.","woocommerce");default:return""}},bt=O.GRID,gt=e=>{const{type:t,columns:o}=e.displayLayout,r=t=>{e.setAttributes({displayLayout:{type:t,columns:o}})};return(0,c.createElement)(i.__experimentalToolsPanelItem,{label:(0,p.__)("Layout","woocommerce"),hasValue:()=>t!==bt,isShownByDefault:!0,onDeselect:()=>{r(O.GRID)}},(0,c.createElement)(i.__experimentalToggleGroupControl,{label:(0,p.__)("Layout","woocommerce"),isBlock:!0,onChange:e=>{r(e)},help:pt(t),value:t},(0,c.createElement)(i.__experimentalToggleGroupControlOption,{value:O.STACK,label:(0,p.__)("Stack","woocommerce")}),(0,c.createElement)(i.__experimentalToggleGroupControlOption,{value:O.GRID,label:(0,p.__)("Grid","woocommerce")})))},_t=e=>{const{query:t,setQueryAttribute:o}=e;return(0,c.createElement)(i.__experimentalToolsPanelItem,{label:(0,p.__)("Featured","woocommerce"),hasValue:()=>!0===t.featured,onDeselect:()=>{o({featured:!1})}},(0,c.createElement)(i.BaseControl,{id:"product-collection-featured-products-control",label:(0,p.__)("Featured","woocommerce")},(0,c.createElement)(i.ToggleControl,{label:(0,p.__)("Show only featured products","woocommerce"),checked:t.featured||!1,onChange:e=>{o({featured:e})}})))},wt=e=>{const{query:t,setQueryAttribute:o}=e,{timeFrame:r}=t;return(0,c.createElement)(i.__experimentalToolsPanelItem,{label:(0,p.__)("Created","woocommerce"),hasValue:()=>(null==r?void 0:r.operator)&&(null==r?void 0:r.value),onDeselect:()=>{o({timeFrame:void 0})}},(0,c.createElement)(i.Flex,{direction:"column",gap:3},(0,c.createElement)(i.FlexItem,null,(0,c.createElement)(i.__experimentalToggleGroupControl,{label:(0,p.__)("Created","woocommerce"),isBlock:!0,onChange:e=>{o({timeFrame:{...r,operator:e}})},value:(null==r?void 0:r.operator)||B.IN},(0,c.createElement)(i.__experimentalToggleGroupControlOption,{value:B.IN,label:(0,p._x)("Within","Product Collection query operator","woocommerce")}),(0,c.createElement)(i.__experimentalToggleGroupControlOption,{value:B.NOT_IN,label:(0,p._x)("Before","Product Collection query operator","woocommerce")}))),(0,c.createElement)(i.FlexItem,null,(0,c.createElement)(i.RadioControl,{onChange:e=>{o({timeFrame:{operator:B.IN,...r,value:e}})},options:[{label:"last 24 hours",value:"-1 day"},{label:"last 7 days",value:"-7 days"},{label:"last 30 days",value:"-30 days"},{label:"last 3 months",value:"-3 months"}],selected:null==r?void 0:r.value}))))},ht=e=>{const t=e.attributes.query,o=!1===(null==t?void 0:t.inherit),r=(0,s.useMemo)((()=>L.bind(null,e)),[e]),n={setAttributes:e.setAttributes,displayLayout:e.attributes.displayLayout},a={setQueryAttribute:r,query:t};return(0,c.createElement)(l.InspectorControls,null,(0,c.createElement)(i.__experimentalToolsPanel,{label:(0,p.__)("Settings","woocommerce"),resetAll:()=>{const t=(o=e.attributes,{displayLayout:$(),query:G(o.query)});var o;e.setAttributes(t)}},(0,c.createElement)(gt,{...n}),(0,c.createElement)(te,{...n}),(0,c.createElement)(ce,{...a}),o?(0,c.createElement)(ae,{...a}):null),o?(0,c.createElement)(i.__experimentalToolsPanel,{label:(0,p.__)("Filters","woocommerce"),resetAll:t=>{L(e,V),t.forEach((e=>e()))},className:"wc-block-editor-product-collection-inspector-toolspanel__filters"},(0,c.createElement)(se,{...a}),(0,c.createElement)(de,{...a}),(0,c.createElement)(dt,{...a}),(0,c.createElement)(pe,{...a}),(0,c.createElement)(nt,{...a}),(0,c.createElement)(mt,{...a}),(0,c.createElement)(_t,{...a}),(0,c.createElement)(wt,{...a})):null,(0,c.createElement)(f,null))};(()=>{if((0,S.isWpVersion)("6.1",">=")){const{status:e}=T()}})();const yt=e=>{const t=e+2592e5;return Date.now()<t},kt=(e=0)=>e<=4;(0,h.addFilter)("editor.BlockEdit","woocommerce/product-collection",(e=>t=>{if(!(e=>e===n.name)(t.name))return(0,c.createElement)(e,{...t});const o=(e=>{const{attributes:t}=e,{convertedFromProducts:o}=t,{status:r,time:n,displayCount:c}=T();return o&&"notseen"===r&&yt(n)&&kt(c)})(t),r=(e=>{const{attributes:t}=e,{convertedFromProducts:o}=t,{status:r,time:n,displayCount:c}=T();return o&&("seen"===r||!yt(n)||!kt(c))})(t);return r&&t.setAttributes({convertedFromProducts:!1}),(0,c.createElement)(c.Fragment,null,o&&(0,c.createElement)(l.InspectorControls,null,(0,c.createElement)(W,{revertMigration:J})),(0,c.createElement)(e,{...t}))})),o(6547);var Et=o(9522);const ft=({onToggle:e})=>(0,c.createElement)(i.ToolbarButton,{icon:Et.Z,label:(0,p.__)("Display settings","woocommerce"),onClick:e}),vt=({query:e,setQueryAttribute:t})=>{const o=e=>{const o=Number(e);!isNaN(o)&&o>=1&&o<=100&&t({perPage:o})},r=e=>{const o=Number(e);!isNaN(o)&&o>=0&&o<=100&&t({offset:o})},n=e=>{const o=Number(e);!isNaN(o)&&o>=0&&t({pages:o})},l={__unstableInputWidth:"60px",labelPosition:"edge",step:"1",isDragEnabled:!1};return(0,c.createElement)(i.ToolbarGroup,null,(0,c.createElement)(i.Dropdown,{contentClassName:"wc-block-editor-product-collection__display-settings",renderToggle:({onToggle:e})=>(0,c.createElement)(ft,{onToggle:e}),renderContent:()=>(0,c.createElement)(c.Fragment,null,(0,c.createElement)(i.__experimentalNumberControl,{...l,label:(0,p.__)("Items per Page","woocommerce"),min:1,max:100,onChange:o,value:e.perPage}),(0,c.createElement)(i.__experimentalNumberControl,{...l,label:(0,p.__)("Offset","woocommerce"),min:0,max:100,onChange:r,value:e.offset}),(0,c.createElement)(i.BaseControl,{help:(0,p.__)("Limit the pages you want to show, even if the query has more results. To show all pages use 0 (zero).","woocommerce"),id:"woocommerce-products-block__display-settings-pages"},(0,c.createElement)(i.__experimentalNumberControl,{...l,label:(0,p.__)("Max page to show","woocommerce"),min:0,onChange:n,value:e.pages})))}))};var St=o(8960),Ct=o(5186);const xt=e=>{const{type:t,columns:o}=e.displayLayout,r=t=>{e.setAttributes({displayLayout:t})},n=[{icon:St.Z,title:(0,p.__)("List view","woocommerce"),onClick:()=>r({type:"list",columns:o}),isActive:"list"===t},{icon:Ct.Z,title:(0,p.__)("Grid view","woocommerce"),onClick:()=>r({type:"flex",columns:o}),isActive:"flex"===t}];return(0,c.createElement)(i.ToolbarGroup,{controls:n})},Nt=e=>(0,c.createElement)(i.ToolbarGroup,null,(0,c.createElement)(i.ToolbarButton,{onClick:e.openPatternSelectionModal},(0,p.__)("Choose pattern","woocommerce"))),It="woocommerce/product-collection",Pt=e=>{const{clientId:t,query:o}=e,{replaceBlock:n,selectBlock:a}=(0,v.useDispatch)(l.store),s=e=>{const t=e.innerBlocks.map(s);if(e.name===It){const{perPage:n,offset:c,pages:l}=e.attributes.query,a={...o,perPage:n,offset:c,pages:l};return(0,r.cloneBlock)(e,{query:a},t)}return(0,r.cloneBlock)(e,{},t)},u=(0,v.useSelect)((e=>{const{getBlockRootClientId:o,getPatternsByBlockTypes:r}=e(l.store),n=o(t);return r(It,n)}),[It,t]);return(0,c.createElement)(i.Modal,{overlayClassName:"wc-blocks-product-collection__selection-modal",title:(0,p.__)("Choose a pattern","woocommerce"),onRequestClose:e.closePatternSelectionModal,isFullScreen:!0},(0,c.createElement)("div",{className:"wc-blocks-product-collection__selection-content"},(0,c.createElement)(l.__experimentalBlockPatternsList,{blockPatterns:u,shownPatterns:u,onClickPattern:(e,o)=>{const r=o.map(s);n(t,r),a(r[0].clientId)}})))};function Tt(e){const[t,o]=(0,s.useState)(!1),{attributes:r,clientId:n,setAttributes:a}=e,{query:u,displayLayout:i}=r,m=(0,s.useMemo)((()=>L.bind(null,e)),[e]);return(0,c.createElement)(l.BlockControls,null,(0,c.createElement)(Nt,{openPatternSelectionModal:()=>o(!0)}),!u.inherit&&(0,c.createElement)(c.Fragment,null,(0,c.createElement)(vt,{query:u,setQueryAttribute:m}),(0,c.createElement)(xt,{displayLayout:i,setAttributes:a})),t&&(0,c.createElement)(Pt,{clientId:n,query:u,closePatternSelectionModal:()=>o(!1)}))}const At=[["woocommerce/product-template",{},[["woocommerce/product-image",{imageSizing:u.THUMBNAIL}],["core/post-title",{textAlign:"center",level:3,fontSize:"medium",style:{spacing:{margin:{bottom:"0.75rem",top:"0"}}},isLink:!0,__woocommerceNamespace:w}],["woocommerce/product-price",{textAlign:"center",fontSize:"small"}],["woocommerce/product-button",{textAlign:"center",fontSize:"small"}]]],["core/query-pagination",{layout:{type:"flex",justifyContent:"center"}}],["woocommerce/product-collection-no-results"]],Ot=e=>{var t;const{attributes:o,setAttributes:r}=e,{queryId:n}=o,u=(0,l.useBlockProps)(),i=(0,l.useInnerBlocksProps)(u,{template:At}),m=(0,a.useInstanceId)(Ot);return(0,s.useEffect)((()=>{Number.isFinite(n)||r({queryId:Number(m)})}),[n,m,r]),(0,s.useEffect)((()=>{r({...j,query:{...j.query,inherit:R()},...o})}),[r]),"boolean"!=typeof(null==o||null===(t=o.query)||void 0===t?void 0:t.inherit)?null:(0,c.createElement)("div",{...u},(0,c.createElement)(ht,{...e}),(0,c.createElement)(Tt,{...e}),(0,c.createElement)("div",{...i}))},Bt=Ot;var Lt=o(897);const Rt=(0,p.__)("Product Summary","woocommerce"),qt=((0,c.createElement)(b.Z,{icon:Lt.Z,className:"wc-block-editor-components-block-icon"}),(0,p.__)("Display a short description about a product.","woocommerce"));(0,r.registerBlockType)(n,{icon:()=>(0,c.createElement)("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg"},(0,c.createElement)("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M19 11H5C4.72386 11 4.5 11.2239 4.5 11.5V17.5C4.5 17.7761 4.72386 18 5 18H19C19.2761 18 19.5 17.7761 19.5 17.5V11.5C19.5 11.2239 19.2761 11 19 11ZM5 9.5H19C20.1046 9.5 21 10.3954 21 11.5V17.5C21 18.6046 20.1046 19.5 19 19.5H5C3.89543 19.5 3 18.6046 3 17.5V11.5C3 10.3954 3.89543 9.5 5 9.5Z",fill:"currentColor"}),(0,c.createElement)("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M18 7.5C18 7.77614 17.7761 8 17.5 8L6.5 8C6.22386 8 6 7.77614 6 7.5V7.5C6 7.22386 6.22386 7 6.5 7L17.5 7C17.7761 7 18 7.22386 18 7.5V7.5Z",fill:"currentColor"}),(0,c.createElement)("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M16 5C16 5.27614 15.7761 5.5 15.5 5.5L8.5 5.5C8.22386 5.5 8 5.27614 8 5V5C8 4.72386 8.22386 4.5 8.5 4.5L15.5 4.5C15.7761 4.5 16 4.72386 16 5V5Z",fill:"currentColor"})),edit:Bt,save:function({attributes:{tagName:e="div"}}){const t=l.useBlockProps.save(),o=l.useInnerBlocksProps.save(t);return(0,c.createElement)(e,{...o})}}),d("core/post-excerpt",{blockDescription:qt,blockIcon:(0,c.createElement)(i.Icon,{icon:Lt.Z}),blockTitle:Rt,variationName:"woocommerce/product-collection/product-summary"}),d("core/post-title",{blockDescription:_,blockIcon:(0,c.createElement)(i.Icon,{icon:m.Z}),blockTitle:g,variationName:w})},6547:()=>{},4662:()=>{},9669:()=>{},8462:()=>{},5932:()=>{},9196:e=>{"use strict";e.exports=window.React},4333:e=>{"use strict";e.exports=window.wp.compose},9307:e=>{"use strict";e.exports=window.wp.element},5736:e=>{"use strict";e.exports=window.wp.i18n},444:e=>{"use strict";e.exports=window.wp.primitives}},o={};function r(e){var n=o[e];if(void 0!==n)return n.exports;var c=o[e]={exports:{}};return t[e].call(c.exports,c,c.exports,r),c.exports}r.m=t,e=[],r.O=(t,o,n,c)=>{if(!o){var l=1/0;for(i=0;i<e.length;i++){for(var[o,n,c]=e[i],a=!0,s=0;s<o.length;s++)(!1&c||l>=c)&&Object.keys(r.O).every((e=>r.O[e](o[s])))?o.splice(s--,1):(a=!1,c<l&&(l=c));if(a){e.splice(i--,1);var u=n();void 0!==u&&(t=u)}}return t}c=c||0;for(var i=e.length;i>0&&e[i-1][2]>c;i--)e[i]=e[i-1];e[i]=[o,n,c]},r.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return r.d(t,{a:t}),t},r.d=(e,t)=>{for(var o in t)r.o(t,o)&&!r.o(e,o)&&Object.defineProperty(e,o,{enumerable:!0,get:t[o]})},r.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.j=4603,(()=>{var e={4603:0};r.O.j=t=>0===e[t];var t=(t,o)=>{var n,c,[l,a,s]=o,u=0;if(l.some((t=>0!==e[t]))){for(n in a)r.o(a,n)&&(r.m[n]=a[n]);if(s)var i=s(r)}for(t&&t(o);u<l.length;u++)c=l[u],r.o(e,c)&&e[c]&&e[c][0](),e[c]=0;return r.O(i)},o=self.webpackChunkwebpackWcBlocksJsonp=self.webpackChunkwebpackWcBlocksJsonp||[];o.forEach(t.bind(null,0)),o.push=t.bind(null,o.push.bind(o))})();var n=r.O(void 0,[2869],(()=>r(9161)));n=r.O(n),((this.wc=this.wc||{}).blocks=this.wc.blocks||{})["product-collection"]=n})(); |