Ubuntu

­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­ this.wc=this.wc||{},this.wc.blocks=this.wc.blocks||{},this.wc.blocks["products-by-attribute"]=function(t){function e(e){for(var o,i,u=e[0],a=e[1],s=e[2],b=0,d=[];b0){var n=Object(L.find)(r,{slug:e[0].attr_slug});o=n?n.id:0}return{list:r,attribute:o,loading:!1}})}).catch(function(){t.setState({list:[],loading:!1})})}},{key:"componentWillUnmount",value:function(){this.debouncedGetTerms.cancel()}},{key:"componentDidUpdate",value:function(t,e){e.attribute!==this.state.attribute&&this.debouncedGetTerms()}},{key:"getTerms",value:function(){var t=this,e=this.state,r=e.attribute,o=e.termsList;r&&(o[r]||this.setState({termsLoading:!0}),D()({path:Object(N.addQueryArgs)("".concat(a.ENDPOINTS.products,"/attributes/").concat(r,"/terms"),{per_page:-1})}).then(function(e){e=e.map(function(t){return I({},t,{parent:r,attr_slug:t.attribute.slug})}),t.setState(function(t){return{termsList:I({},t.termsList,P()({},r,e)),termsLoading:!1}})}).catch(function(){t.setState({termsLoading:!1})}))}},{key:"onSelectAttribute",value:function(t){var e=this;return function(){e.props.onChange([]),e.setState({attribute:t.id===e.state.attribute?0:t.id})}}},{key:"renderItem",value:function(t){var e=t.item,r=t.search,c=t.depth,i=void 0===c?0:c,u=this.state,a=u.attribute,s=u.termsLoading,l=["woocommerce-product-attributes__item","woocommerce-search-list__item"];return r.length&&l.push("is-searching"),0===i&&0!==e.parent&&l.push("is-skip-level"),e.breadcrumbs.length?Object(o.createElement)(T.b,C()({className:l.join(" ")},t,{showCount:!0,"aria-label":"".concat(e.breadcrumbs[0],": ").concat(e.name)})):[Object(o.createElement)(T.b,C()({key:"attr-".concat(e.id)},t,{className:l.join(" "),isSelected:a===e.id,onSelect:this.onSelectAttribute,isSingle:!0,disabled:"0"===e.count,"aria-expanded":a===e.id,"aria-label":Object(n.sprintf)(Object(n._n)("%s, has %d term","%s, has %d terms",e.count,'woocommerce'),e.name,e.count)})),a===e.id&&s&&Object(o.createElement)("div",{key:"loading",className:"woocommerce-search-list__item woocommerce-product-attributes__itemdepth-1 is-loading is-not-active"},Object(o.createElement)(j.Spinner,null))]}},{key:"render",value:function(){var t=this.state,e=t.attribute,r=t.list,c=t.loading,i=t.termsList,u=this.props,a=u.onChange,s=u.onOperatorChange,l=u.operator,b=u.selected,d=i[e]||[],p=[].concat(k()(r),k()(d)),g={clear:Object(n.__)("Clear all product attributes",'woocommerce'),list:Object(n.__)("Product Attributes",'woocommerce'),noItems:Object(n.__)("Your store doesn't have any product attributes.",'woocommerce'),search:Object(n.__)("Search for product attributes",'woocommerce'),selected:function(t){return Object(n.sprintf)(Object(n._n)("%d attribute selected","%d attributes selected",t,'woocommerce'),t)},updated:Object(n.__)("Product attribute search results updated.",'woocommerce')};return Object(o.createElement)(o.Fragment,null,Object(o.createElement)(T.a,{className:"woocommerce-product-attributes",list:p,isLoading:c,selected:b.map(function(t){var e=t.id;return Object(L.find)(p,{id:e})}).filter(Boolean),onChange:a,renderItem:this.renderItem,messages:g,isHierarchical:!0}),!!s&&Object(o.createElement)("div",{className:b.length<2?"screen-reader-text":""},Object(o.createElement)(j.SelectControl,{className:"woocommerce-product-attributes__operator",label:Object(n.__)("Display products matching",'woocommerce'),help:Object(n.__)("Pick at least two attributes to use this setting.",'woocommerce'),value:l,onChange:s,options:[{label:Object(n.__)("Any selected attributes",'woocommerce'),value:"any"},{label:Object(n.__)("All selected attributes",'woocommerce'),value:"all"}]})))}}]),e}(o.Component);R.defaultProps={operator:"any"};var U=R,F=r(57),W=function(t){function e(){return l()(this,e),g()(this,m()(e).apply(this,arguments))}return h()(e,t),d()(e,[{key:"getInspectorControls",value:function(){var t=this.props.setAttributes,e=this.props.attributes,r=e.attributes,c=e.attrOperator,i=e.columns,u=e.contentVisibility,a=e.orderby,s=e.rows,l=e.alignButtons;return Object(o.createElement)(_.InspectorControls,{key:"inspector"},Object(o.createElement)(j.PanelBody,{title:Object(n.__)("Layout",'woocommerce'),initialOpen:!0},Object(o.createElement)(w.a,{columns:i,rows:s,alignButtons:l,setAttributes:t})),Object(o.createElement)(j.PanelBody,{title:Object(n.__)("Content",'woocommerce'),initialOpen:!0},Object(o.createElement)(y.a,{settings:u,onChange:function(e){return t({contentVisibility:e})}})),Object(o.createElement)(j.PanelBody,{title:Object(n.__)("Filter by Product Attribute",'woocommerce'),initialOpen:!1},Object(o.createElement)(U,{selected:r,onChange:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[],r=e.map(function(t){return{id:t.id,attr_slug:t.attr_slug}});t({attributes:r})},operator:c,onOperatorChange:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"any";return t({attrOperator:e})}})),Object(o.createElement)(j.PanelBody,{title:Object(n.__)("Order By",'woocommerce'),initialOpen:!1},Object(o.createElement)(F.a,{setAttributes:t,value:a})))}},{key:"renderEditMode",value:function(){var t=this.props,e=t.debouncedSpeak,r=t.setAttributes,c=this.props.attributes;return Object(o.createElement)(j.Placeholder,{icon:Object(o.createElement)(i.a,{icon:"custom-post-type"}),label:Object(n.__)("Products by Attribute",'woocommerce'),className:"wc-block-products-grid wc-block-products-by-attribute"},Object(n.__)("Display a grid of products from your selected attributes.",'woocommerce'),Object(o.createElement)("div",{className:"wc-block-products-by-attribute__selection"},Object(o.createElement)(U,{selected:c.attributes,onChange:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[],e=t.map(function(t){return{id:t.id,attr_slug:t.attr_slug}});r({attributes:e})},operator:c.attrOperator,onOperatorChange:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"any";return r({attrOperator:t})}}),Object(o.createElement)(j.Button,{isDefault:!0,onClick:function(){r({editMode:!1}),e(Object(n.__)("Showing Products by Attribute block preview.",'woocommerce'))}},Object(n.__)("Done",'woocommerce'))))}},{key:"render",value:function(){var t=this.props,e=t.attributes,r=t.name,c=t.setAttributes,i=e.editMode;return Object(o.createElement)(o.Fragment,null,Object(o.createElement)(_.BlockControls,null,Object(o.createElement)(j.Toolbar,{controls:[{icon:"edit",title:Object(n.__)("Edit"),onClick:function(){return c({editMode:!i})},isActive:i}]})),this.getInspectorControls(),i?this.renderEditMode():Object(o.createElement)(j.Disabled,null,Object(o.createElement)(_.ServerSideRender,{block:r,attributes:e})))}}]),e}(o.Component),V=Object(j.withSpokenMessages)(W),X=r(46);Object(u.registerBlockType)("woocommerce/products-by-attribute",{title:Object(n.__)("Products by Attribute",'woocommerce'),icon:{src:Object(o.createElement)(i.a,{icon:"custom-post-type"}),foreground:"#96588a"},category:"woocommerce",keywords:[Object(n.__)("WooCommerce",'woocommerce')],description:Object(n.__)("Display a grid of products from your selected attributes.",'woocommerce'),supports:{align:["wide","full"],html:!1},attributes:{attributes:{type:"array",default:[]},attrOperator:{type:"string",default:"any"},columns:{type:"number",default:a.DEFAULT_COLUMNS},editMode:{type:"boolean",default:!0},contentVisibility:{type:"object",default:{title:!0,price:!0,rating:!0,button:!0}},orderby:{type:"string",default:"date"},rows:{type:"number",default:a.DEFAULT_ROWS},alignButtons:{type:"boolean",default:!1}},deprecated:[{attributes:{attributes:{type:"array",default:[]},attrOperator:{type:"string",default:"any"},columns:{type:"number",default:a.DEFAULT_COLUMNS},editMode:{type:"boolean",default:!0},contentVisibility:{type:"object",default:{title:!0,price:!0,rating:!0,button:!0}},orderby:{type:"string",default:"date"},rows:{type:"number",default:a.DEFAULT_ROWS}},save:Object(X.a)("woocommerce/products-by-attribute")}],edit:function(t){return Object(o.createElement)(V,t)},save:function(){return null}})},57:function(t,e,r){"use strict";var o=r(0),n=r(1),c=r(2);r(7);e.a=function(t){var e=t.value,r=t.setAttributes;return Object(o.createElement)(c.SelectControl,{label:Object(n.__)("Order products by",'woocommerce'),value:e,options:[{label:Object(n.__)("Newness - newest first",'woocommerce'),value:"date"},{label:Object(n.__)("Price - low to high",'woocommerce'),value:"price_asc"},{label:Object(n.__)("Price - high to low",'woocommerce'),value:"price_desc"},{label:Object(n.__)("Rating - highest first",'woocommerce'),value:"rating"},{label:Object(n.__)("Sales - most first",'woocommerce'),value:"popularity"},{label:Object(n.__)("Title - alphabetical",'woocommerce'),value:"title"},{label:Object(n.__)("Menu Order",'woocommerce'),value:"menu_order"}],onChange:function(t){return r({orderby:t})}})}},61:function(t,e){!function(){t.exports=this.wp.dom}()},64:function(t,e){},65:function(t,e){},67:function(t,e){},68:function(t,e){}});