woocommerce/packages/woocommerce-blocks/build/products-by-attribute.js

11 lines
30 KiB
JavaScript
Raw Permalink Normal View History

2021-12-10 12:03:04 +00:00
this.wc=this.wc||{},this.wc.blocks=this.wc.blocks||{},this.wc.blocks["products-by-attribute"]=function(e){function t(t){for(var n,i,l=t[0],a=t[1],u=t[2],b=0,d=[];b<l.length;b++)i=l[b],Object.prototype.hasOwnProperty.call(c,i)&&c[i]&&d.push(c[i][0]),c[i]=0;for(n in a)Object.prototype.hasOwnProperty.call(a,n)&&(e[n]=a[n]);for(s&&s(t);d.length;)d.shift()();return o.push.apply(o,u||[]),r()}function r(){for(var e,t=0;t<o.length;t++){for(var r=o[t],n=!0,l=1;l<r.length;l++){var a=r[l];0!==c[a]&&(n=!1)}n&&(o.splice(t--,1),e=i(i.s=r[0]))}return e}var n={},c={36:0},o=[];function i(t){if(n[t])return n[t].exports;var r=n[t]={i:t,l:!1,exports:{}};return e[t].call(r.exports,r,r.exports,i),r.l=!0,r.exports}i.m=e,i.c=n,i.d=function(e,t,r){i.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},i.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},i.t=function(e,t){if(1&t&&(e=i(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(i.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var n in e)i.d(r,n,function(t){return e[t]}.bind(null,n));return r},i.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return i.d(t,"a",t),t},i.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},i.p="";var l=window.webpackWcBlocksJsonp=window.webpackWcBlocksJsonp||[],a=l.push.bind(l);l.push=t,l=l.slice();for(var u=0;u<l.length;u++)t(l[u]);var s=a;return o.push([766,0]),r()}({0:function(e,t){e.exports=window.wp.element},1:function(e,t){e.exports=window.wp.i18n},11:function(e,t){e.exports=window.React},12:function(e,t){e.exports=window.wp.blockEditor},121:function(e,t){},122:function(e,t){e.exports=window.wp.coreData},130:function(e,t,r){"use strict";var n=r(0),c=r(1),o=r(4);r(2),t.a=function(e){var t=e.value,r=e.setAttributes;return Object(n.createElement)(o.SelectControl,{label:Object(c.__)("Order products by",'woocommerce'),value:t,options:[{label:Object(c.__)("Newness - newest first",'woocommerce'),value:"date"},{label:Object(c.__)("Price - low to high",'woocommerce'),value:"price_asc"},{label:Object(c.__)("Price - high to low",'woocommerce'),value:"price_desc"},{label:Object(c.__)("Rating - highest first",'woocommerce'),value:"rating"},{label:Object(c.__)("Sales - most first",'woocommerce'),value:"popularity"},{label:Object(c.__)("Title - alphabetical",'woocommerce'),value:"title"},{label:Object(c.__)("Menu Order",'woocommerce'),value:"menu_order"}],onChange:function(e){return r({orderby:e})}})}},131:function(e,t,r){"use strict";var n=r(9),c=r.n(n),o=r(16),i=r.n(o),l=r(0),a=r(49),u=r(4),s=r(6),b=r.n(s),d=["className","item","isSelected","isLoading","onSelect","disabled"];t.a=function(e){var t=e.className,r=e.item,n=e.isSelected,o=e.isLoading,s=e.onSelect,p=e.disabled,g=i()(e,d);return Object(l.createElement)(l.Fragment,null,Object(l.createElement)(a.c,c()({},g,{key:r.id,className:t,isSelected:n,item:r,onSelect:s,isSingle:!0,disabled:p})),n&&o&&Object(l.createElement)("div",{key:"loading",className:b()("woocommerce-search-list__item","woocommerce-product-attributes__item","depth-1","is-loading","is-not-active")},Object(l.createElement)(u.Spinner,null)))}},14:function(e,t){e.exports=window.wp.data},15:function(e,t){e.exports=window.wp.apiFetch},188:function(e,t,r){"use strict";r.d(t,"a",(function(){return c}));var n=r(0),c=Object(n.createElement)("svg",{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 230 250",style:{width:"100%"}},Object(n.createElement)("title",null,"Grid Block Preview"),Object(n.createElement)("rect",{width:"65.374",height:"65.374",x:".162",y:".779",fill:"#E1E3E6",rx:"3"}),Object(n.createElement)("rect",{width:"47.266",height:"5.148",x:"9.216",y:"76.153",fill:"#E1E3E6",rx:"2.574"}),Object(n.createElement)("rect",{width:"62.8",height:"15",x:"1.565",y:"101.448",fill:"#E1E3E6",rx:"5"}),Object(n.createElement)("rect",{width:"65.374",height:"65.374",x:".162",y:"136.277",fil
/* translators: %d is the count of attributes selected. */
Object(c._n)("%d attribute selected","%d attributes selected",e,'woocommerce'),e)},updated:Object(c.__)("Product attribute search results updated.",'woocommerce')};return r?Object(n.createElement)(q.a,{error:r}):Object(n.createElement)(n.Fragment,null,Object(n.createElement)(A.b,{className:"woocommerce-product-attributes",list:h,isLoading:b,selected:p.map((function(e){var t=e.id;return h.find((function(e){return e.id===t}))})).filter(Boolean),onChange:i,renderItem:function(e){var t=e.item,r=e.search,a=e.depth,s=void 0===a?0:a,b=["woocommerce-product-attributes__item","woocommerce-search-list__item",{"is-searching":r.length>0,"is-skip-level":0===s&&0!==t.parent}];if(!t.breadcrumbs.length){var d=o===t.id;return Object(n.createElement)(W.a,C()({},e,{className:U.a.apply(void 0,b.concat([{"is-selected":d}])),isSelected:d,item:t,isLoading:g,disabled:"0"===t.count,onSelect:function(e){var t=e.id;return function(){i([]),l(t)}},name:"attributes-".concat(u),countLabel:Object(c.sprintf)(
/* translators: %d is the count of terms. */
Object(c._n)("%d term","%d terms",t.count,'woocommerce'),t.count),"aria-label":Object(c.sprintf)(
/* translators: %1$s is the item name, %2$d is the count of terms for the item. */
Object(c._n)("%1$s, has %2$d term","%1$s, has %2$d terms",t.count,'woocommerce'),t.name,t.count)}))}var p="".concat(t.breadcrumbs[0],": ").concat(t.name);return Object(n.createElement)(A.c,C()({},e,{name:"terms-".concat(u),className:U.a.apply(void 0,b.concat(["has-count"])),countLabel:Object(c.sprintf)(
/* translators: %d is the count of products. */
Object(c._n)("%d product","%d products",t.count,'woocommerce'),t.count),"aria-label":Object(c.sprintf)(
/* translators: %1$s is the attribute name, %2$d is the count of products for that attribute. */
Object(c._n)("%1$s, has %2$d product","%1$s, has %2$d products",t.count,'woocommerce'),p,t.count)}))},messages:O,isCompact:s,isHierarchical:!0}),!!a&&Object(n.createElement)("div",{hidden:p.length<2},Object(n.createElement)(v.SelectControl,{className:"woocommerce-product-attributes__operator",label:Object(c.__)("Display products matching",'woocommerce'),help:Object(c.__)("Pick at least two attributes to use this setting.",'woocommerce'),value:d,onChange:a,options:[{label:Object(c.__)("Any selected attributes",'woocommerce'),value:"any"},{label:Object(c.__)("All selected attributes",'woocommerce'),value:"all"}]})))});J.defaultProps={isCompact:!1,operator:"any"};var Y,K=(Y=Object(R.withInstanceId)(J),function(e){var t=e.selected,r=void 0===t?[]:t,c=r.length?r[0].attr_slug:null,o=Object(n.useState)(null),i=N()(o,2),l=i[0],a=i[1],u=Object(n.useState)(0),s=N()(u,2),b=s[0],d=s[1],p=Object(n.useState)({}),g=N()(p,2),f=g[0],h=g[1],O=Object(n.useState)(!0),w=N()(O,2),m=w[0],E=w[1],j=Object(n.useState)(!1),y=N()(j,2),v=y[0],_=y[1],x=Object(n.useState)(null),k=N()(x,2),P=k[0],S=k[1];return Object(n.useEffect)((function(){null===l&&Object($.b)().then((function(e){if(e=e.map((function(e){return V(V({},e),{},{parent:0})})),a(e),c){var t=Q(c,e,"taxonomy");t&&d(t.id)}})).catch(function(){var e=B()(I.a.mark((function e(t){return I.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.t0=S,e.next=3,Object(z.a)(t);case 3:e.t1=e.sent,(0,e.t0)(e.t1);case 5:case"end":return e.stop()}}),e)})));return function(_x){return e.apply(this,arguments)}}()).finally((function(){E(!1)}))}),[l,c]),Object(n.useEffect)((function(){var e=Q(b,l);e&&(_(!0),Object($.i)(b).then((function(t){t=t.map((function(t){return V(V({},t),{},{parent:b,attr_slug:e.taxonomy})})),h((function(e){return V(V({},e),{},L()({},b,t))}))})).catch(function(){var e=B()(I.a.mark((function e(t){return I.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.t0=S,e.next=3,Object(z.a)(t);case 3:e.t1=e.sent,(0,e.t0)(e.t1);case 5:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}()).finally((function(){_(!1)})))}),[b,l]),Object(n.createElement)(Y,C()({},e,{attributes:l||[],error:P,expandedAttribute:b,onExpandAttribute:d,isLoading:m,termsAreLoading:v,termsList:f}))}),X=r(130),Z=r(188);var ee=function(e){f()(a,e);var t,r,i=(t=a,r=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}(),function(){var e,n=m()(t);if(r){var c=m()(this).constructor;e=Reflect.construct(n,arguments,c)}else e=n.apply(this,arguments);return O()(this,e)});function a(){return b()(this,a),i.apply(this,arguments)}return p()(a,[{key:"getInspectorControls",value:function(){var e=this.props.setAttributes,t=this.props.attributes,r=t.attributes,o=t.attrOperator,i=t.columns,l=t.contentVisibility,a=t.orderby,s=t.rows,b=t.alignButtons;return Object(n.createElement)(E.InspectorControls,{key:"inspector"},Object(n.createElement)(v.PanelBody,{title:Object(c.__)("Layout",'woocommerce'),initialOpen:!0},Object(n.createElement)(x.a,{columns:i,rows:s,alignButtons:b,setAttributes:e,minColumns:Object(u.getSetting)("min_columns",1),maxColumns:Object(u.getSetting)("max_columns",6),minRows:Object(u.getSetting)("min_rows",1),maxRows:Object(u.getSetting)("max_rows",6)})),Object(n.createElement)(v.PanelBody,{title:Object(c.__)("Content",'woocommerce'),initialOpen:!0},Object(n.createElement)(_.a,{settings:l,onChange:function(t){return e({contentVisibility:t})}})),Object(n.createElement)(v.PanelBody,{title:Object(c.__)("Filter by Product Attribute",'woocommerce'),initialOpen:!1},Object(n.createElement)(K,{selected:r,onChange:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[],r=t.map((function(e){return{id:e.id,attr_slug:e.attr_slug}}));e({attributes:r})},operator:o,onOperatorChange:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"any";return e({att