11 lines
44 KiB
JavaScript
11 lines
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
|
|||
|
/* 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.crea
|
|||
|
// 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);con
|
|||
|
(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
|