1 line
3.9 KiB
JavaScript
1 line
3.9 KiB
JavaScript
this.wc=this.wc||{},this.wc.wcBlocksSharedHocs=function(e){var t={};function r(n){if(t[n])return t[n].exports;var o=t[n]={i:n,l:!1,exports:{}};return e[n].call(o.exports,o,o.exports,r),o.l=!0,o.exports}return r.m=e,r.c=t,r.d=function(e,t,n){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)r.d(n,o,function(t){return e[t]}.bind(null,o));return n},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="",r(r.s=158)}({0:function(e,t){e.exports=window.wp.element},1:function(e,t){e.exports=window.wp.data},158:function(e,t,r){"use strict";r.r(t),r.d(t,"withProductDataContext",(function(){return f})),r.d(t,"withFilteredAttributes",(function(){return b}));var n=r(0),o=r(17),c=r(1),u=r(18),s=r.n(u);function a(e){const t=Object(n.useRef)(e);return s()(e,t.current)||(t.current=e),t.current}const i=e=>{const t={namespace:"/wc/store/v1",resourceName:"products"},{results:r,isLoading:u}=(e=>{const{namespace:t,resourceName:r,resourceValues:u=[],query:s={},shouldSelect:i=!0}=e;if(!t||!r)throw new Error("The options object must have valid values for the namespace and the resource properties.");const l=Object(n.useRef)({results:[],isLoading:!0}),d=a(s),p=a(u),f=(()=>{const[,e]=Object(n.useState)();return Object(n.useCallback)((t=>{e((()=>{throw t}))}),[])})(),b=Object(c.useSelect)((e=>{if(!i)return null;const n=e(o.COLLECTIONS_STORE_KEY),c=[t,r,d,p],u=n.getCollectionError(...c);if(u){if(!(u instanceof Error))throw new Error("TypeError: `error` object is not an instance of Error constructor");f(u)}return{results:n.getCollection(...c),isLoading:!n.hasFinishedResolution("getCollection",c)}}),[t,r,p,d,i]);return null!==b&&(l.current=b),l.current})({...t,query:e}),{value:s}=((e,t)=>{const{namespace:r,resourceName:n,resourceValues:u=[],query:s={}}=t;if(!r||!n)throw new Error("The options object must have valid values for the namespace and the resource name properties.");const i=a(s),l=a(u),{value:d,isLoading:p=!0}=Object(c.useSelect)((t=>{const c=t(o.COLLECTIONS_STORE_KEY),u=[e,r,n,i,l];return{value:c.getCollectionHeader(...u),isLoading:c.hasFinishedResolution("getCollectionHeader",u)}}),[e,r,n,l,i]);return{value:d,isLoading:p}})("x-wp-total",{...t,query:e});return{products:r,totalProducts:parseInt(s,10),productsLoading:u}};var l=r(33);const d=(e,t)=>e.find((e=>e.id===t)),p=e=>{const{productId:t,OriginalComponent:r,postId:o,product:c}=e,u=null!=e&&e.isDescendentOfQueryLoop?o:t,{products:s,productsLoading:a}=i({include:u}),p={product:u>0&&s.length>0?d(s,u):null,isLoading:a};return c?Object(n.createElement)(l.ProductDataContextProvider,{product:c,isLoading:!1},Object(n.createElement)(r,{...e})):Object(n.createElement)(l.ProductDataContextProvider,{product:p.product,isLoading:p.isLoading},Object(n.createElement)(r,{...e}))},f=e=>t=>{const r=Object(l.useProductDataContext)();return t.product||!r.hasContext?Object(n.createElement)(p,{...t,OriginalComponent:e}):Object(n.createElement)(e,{...t})},b=e=>t=>r=>{const o=((e,t)=>{const r=[];return Object.keys(e).forEach((n=>{if(void 0!==t[n])switch(e[n].type){case"boolean":r[n]="false"!==t[n]&&!1!==t[n];break;case"number":r[n]=parseInt(t[n],10);break;case"array":case"object":r[n]=JSON.parse(t[n]);break;default:r[n]=t[n]}else r[n]=e[n].default})),r})(e,r);return Object(n.createElement)(t,{...r,...o})}},17:function(e,t){e.exports=window.wc.wcBlocksData},18:function(e,t){e.exports=window.wp.isShallowEqual},33:function(e,t){e.exports=window.wc.wcBlocksSharedContext}}); |