@plasmicpkgs/commerce 0.0.209 → 0.0.210

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,2 +1,2 @@
1
- "use strict";function e(e){return e&&"object"==typeof e&&"default"in e?e.default:e}Object.defineProperty(exports,"__esModule",{value:!0});var t=e(require("@plasmicapp/host/registerComponent")),r=require("react"),n=e(r),o=require("react-hook-form"),a=require("@plasmicapp/query"),i=require("@plasmicapp/host"),c=e(require("js-cookie")),l=e(require("debounce"));function u(){u=function(){return t};var e,t={},r=Object.prototype,n=r.hasOwnProperty,o=Object.defineProperty||function(e,t,r){e[t]=r.value},a="function"==typeof Symbol?Symbol:{},i=a.iterator||"@@iterator",c=a.asyncIterator||"@@asyncIterator",l=a.toStringTag||"@@toStringTag";function s(e,t,r){return Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}),e[t]}try{s({},"")}catch(e){s=function(e,t,r){return e[t]=r}}function p(e,t,r,n){var a=Object.create((t&&t.prototype instanceof h?t:h).prototype),i=new S(n||[]);return o(a,"_invoke",{value:k(e,r,i)}),a}function d(e,t,r){try{return{type:"normal",arg:e.call(t,r)}}catch(e){return{type:"throw",arg:e}}}t.wrap=p;var m="suspendedStart",f="executing",y="completed",v={};function h(){}function g(){}function x(){}var C={};s(C,i,(function(){return this}));var b=Object.getPrototypeOf,P=b&&b(b(O([])));P&&P!==r&&n.call(P,i)&&(C=P);var w=x.prototype=h.prototype=Object.create(C);function E(e){["next","throw","return"].forEach((function(t){s(e,t,(function(e){return this._invoke(t,e)}))}))}function N(e,t){function r(o,a,i,c){var l=d(e[o],e,a);if("throw"!==l.type){var u=l.arg,s=u.value;return s&&"object"==typeof s&&n.call(s,"__await")?t.resolve(s.__await).then((function(e){r("next",e,i,c)}),(function(e){r("throw",e,i,c)})):t.resolve(s).then((function(e){u.value=e,i(u)}),(function(e){return r("throw",e,i,c)}))}c(l.arg)}var a;o(this,"_invoke",{value:function(e,n){function o(){return new t((function(t,o){r(e,n,t,o)}))}return a=a?a.then(o,o):o()}})}function k(t,r,n){var o=m;return function(a,i){if(o===f)throw new Error("Generator is already running");if(o===y){if("throw"===a)throw i;return{value:e,done:!0}}for(n.method=a,n.arg=i;;){var c=n.delegate;if(c){var l=I(c,n);if(l){if(l===v)continue;return l}}if("next"===n.method)n.sent=n._sent=n.arg;else if("throw"===n.method){if(o===m)throw o=y,n.arg;n.dispatchException(n.arg)}else"return"===n.method&&n.abrupt("return",n.arg);o=f;var u=d(t,r,n);if("normal"===u.type){if(o=n.done?y:"suspendedYield",u.arg===v)continue;return{value:u.arg,done:n.done}}"throw"===u.type&&(o=y,n.method="throw",n.arg=u.arg)}}}function I(t,r){var n=r.method,o=t.iterator[n];if(o===e)return r.delegate=null,"throw"===n&&t.iterator.return&&(r.method="return",r.arg=e,I(t,r),"throw"===r.method)||"return"!==n&&(r.method="throw",r.arg=new TypeError("The iterator does not provide a '"+n+"' method")),v;var a=d(o,t.iterator,r.arg);if("throw"===a.type)return r.method="throw",r.arg=a.arg,r.delegate=null,v;var i=a.arg;return i?i.done?(r[t.resultName]=i.value,r.next=t.nextLoc,"return"!==r.method&&(r.method="next",r.arg=e),r.delegate=null,v):i:(r.method="throw",r.arg=new TypeError("iterator result is not an object"),r.delegate=null,v)}function L(e){var t={tryLoc:e[0]};1 in e&&(t.catchLoc=e[1]),2 in e&&(t.finallyLoc=e[2],t.afterLoc=e[3]),this.tryEntries.push(t)}function M(e){var t=e.completion||{};t.type="normal",delete t.arg,e.completion=t}function S(e){this.tryEntries=[{tryLoc:"root"}],e.forEach(L,this),this.reset(!0)}function O(t){if(t||""===t){var r=t[i];if(r)return r.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var o=-1,a=function r(){for(;++o<t.length;)if(n.call(t,o))return r.value=t[o],r.done=!1,r;return r.value=e,r.done=!0,r};return a.next=a}}throw new TypeError(typeof t+" is not iterable")}return g.prototype=x,o(w,"constructor",{value:x,configurable:!0}),o(x,"constructor",{value:g,configurable:!0}),g.displayName=s(x,l,"GeneratorFunction"),t.isGeneratorFunction=function(e){var t="function"==typeof e&&e.constructor;return!!t&&(t===g||"GeneratorFunction"===(t.displayName||t.name))},t.mark=function(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,x):(e.__proto__=x,s(e,l,"GeneratorFunction")),e.prototype=Object.create(w),e},t.awrap=function(e){return{__await:e}},E(N.prototype),s(N.prototype,c,(function(){return this})),t.AsyncIterator=N,t.async=function(e,r,n,o,a){void 0===a&&(a=Promise);var i=new N(p(e,r,n,o),a);return t.isGeneratorFunction(r)?i:i.next().then((function(e){return e.done?e.value:i.next()}))},E(w),s(w,l,"Generator"),s(w,i,(function(){return this})),s(w,"toString",(function(){return"[object Generator]"})),t.keys=function(e){var t=Object(e),r=[];for(var n in t)r.push(n);return r.reverse(),function e(){for(;r.length;){var n=r.pop();if(n in t)return e.value=n,e.done=!1,e}return e.done=!0,e}},t.values=O,S.prototype={constructor:S,reset:function(t){if(this.prev=0,this.next=0,this.sent=this._sent=e,this.done=!1,this.delegate=null,this.method="next",this.arg=e,this.tryEntries.forEach(M),!t)for(var r in this)"t"===r.charAt(0)&&n.call(this,r)&&!isNaN(+r.slice(1))&&(this[r]=e)},stop:function(){this.done=!0;var e=this.tryEntries[0].completion;if("throw"===e.type)throw e.arg;return this.rval},dispatchException:function(t){if(this.done)throw t;var r=this;function o(n,o){return c.type="throw",c.arg=t,r.next=n,o&&(r.method="next",r.arg=e),!!o}for(var a=this.tryEntries.length-1;a>=0;--a){var i=this.tryEntries[a],c=i.completion;if("root"===i.tryLoc)return o("end");if(i.tryLoc<=this.prev){var l=n.call(i,"catchLoc"),u=n.call(i,"finallyLoc");if(l&&u){if(this.prev<i.catchLoc)return o(i.catchLoc,!0);if(this.prev<i.finallyLoc)return o(i.finallyLoc)}else if(l){if(this.prev<i.catchLoc)return o(i.catchLoc,!0)}else{if(!u)throw new Error("try statement without catch or finally");if(this.prev<i.finallyLoc)return o(i.finallyLoc)}}}},abrupt:function(e,t){for(var r=this.tryEntries.length-1;r>=0;--r){var o=this.tryEntries[r];if(o.tryLoc<=this.prev&&n.call(o,"finallyLoc")&&this.prev<o.finallyLoc){var a=o;break}}a&&("break"===e||"continue"===e)&&a.tryLoc<=t&&t<=a.finallyLoc&&(a=null);var i=a?a.completion:{};return i.type=e,i.arg=t,a?(this.method="next",this.next=a.finallyLoc,v):this.complete(i)},complete:function(e,t){if("throw"===e.type)throw e.arg;return"break"===e.type||"continue"===e.type?this.next=e.arg:"return"===e.type?(this.rval=this.arg=e.arg,this.method="return",this.next="end"):"normal"===e.type&&t&&(this.next=t),v},finish:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var r=this.tryEntries[t];if(r.finallyLoc===e)return this.complete(r.completion,r.afterLoc),M(r),v}},catch:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var r=this.tryEntries[t];if(r.tryLoc===e){var n=r.completion;if("throw"===n.type){var o=n.arg;M(r)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(t,r,n){return this.delegate={iterator:O(t),resultName:r,nextLoc:n},"next"===this.method&&(this.arg=e),v}},t}function s(e,t,r,n,o,a,i){try{var c=e[a](i),l=c.value}catch(e){return void r(e)}c.done?t(l):Promise.resolve(l).then(n,o)}function p(e){return function(){var t=this,r=arguments;return new Promise((function(n,o){var a=e.apply(t,r);function i(e){s(a,n,o,i,c,"next",e)}function c(e){s(a,n,o,i,c,"throw",e)}i(void 0)}))}}function d(){return(d=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e}).apply(this,arguments)}function m(e,t){e.prototype=Object.create(t.prototype),e.prototype.constructor=e,y(e,t)}function f(e){return(f=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function y(e,t){return(y=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e})(e,t)}function v(){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 h(e,t,r){return(h=v()?Reflect.construct.bind():function(e,t,r){var n=[null];n.push.apply(n,t);var o=new(Function.bind.apply(e,n));return r&&y(o,r.prototype),o}).apply(null,arguments)}function g(e){var t="function"==typeof Map?new Map:void 0;return(g=function(e){if(null===e||!function(e){return-1!==Function.toString.call(e).indexOf("[native code]")}(e))return e;if("function"!=typeof e)throw new TypeError("Super expression must either be null or a function");if(void 0!==t){if(t.has(e))return t.get(e);t.set(e,r)}function r(){return h(e,arguments,f(this).constructor)}return r.prototype=Object.create(e.prototype,{constructor:{value:r,enumerable:!1,writable:!0,configurable:!0}}),y(r,e)})(e)}function x(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r<t;r++)n[r]=e[r];return n}function C(e,t){var r="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(r)return(r=r.call(e)).next.bind(r);if(Array.isArray(e)||(r=function(e,t){if(e){if("string"==typeof e)return x(e,void 0);var r=Object.prototype.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?x(e,void 0):void 0}}(e))||t&&e&&"number"==typeof e.length){r&&(e=r);var n=0;return function(){return n>=e.length?{done:!0}:{done:!1,value:e[n++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var b=["children"],P=r.createContext({});function w(e){var t=e.provider,o=e.children,a=r.useRef(t),i=r.useRef(t.fetcher),c=a.current,l=c.locale,u=c.cartCookie,s=r.useMemo((function(){return{providerRef:a,fetcherRef:i,locale:l,cartCookie:u}}),[l,u]);return n.createElement(P.Provider,{value:s},o)}function E(){return r.useContext(P)}var N=function(e){function t(t){var r,n=t.message,o=t.code,a=t.errors,i=n?d({message:n},o?{code:o}:{}):a[0];return(r=e.call(this,i.message)||this).errors=n?[i]:a,i.code&&(r.code=i.code),r}return m(t,e),t}(g(Error)),k=function(e){function t(t){var r;return(r=e.call(this,t)||this).code="validation_error",r}return m(t,e),t}(N),I=function(e){function t(t){var r;return(r=e.call(this,t)||this).status=t.status,r}return m(t,e),t}(N);function L(){var e,t=E();return null!=(e=t.providerRef.current.fetcher)?e:t.fetcherRef.current}function M(){return E().providerRef.current}function S(e){return e(E().providerRef.current)}function O(e){var t=L(),r=M();return e.useHook({useData:function(n){var o;return function(e,t,r,n,o){var i=Array.isArray(t)?t:Object.entries(t),c=a.useMutablePlasmicQueryData((function(){var t=e.fetchOptions;return t?[t.url,t.query,t.method].concat(i.map((function(e){return e[1]}))):null}),function(){var t=p(u().mark((function t(n,a,c){var l,s,p,d=arguments;return u().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:for(t.prev=0,l=d.length,s=new Array(l>3?l-3:0),p=3;p<l;p++)s[p-3]=d[p];return t.next=4,e.fetcher({options:{url:n,query:a,method:c},input:s.reduce((function(e,t,r){return e[i[r][0]]=t,e}),{}),fetch:r,provider:o});case 4:return t.abrupt("return",t.sent);case 7:throw t.prev=7,t.t0=t.catch(0),t.t0 instanceof N||console.error(t.t0),t.t0;case 11:case"end":return t.stop()}}),t,null,[[0,7]])})));return function(e,r,n){return t.apply(this,arguments)}}(),n);return"isLoading"in c||Object.defineProperty(c,"isLoading",{get:function(){return void 0===c.data},enumerable:!0}),c}(e,null!=(o=null==n?void 0:n.input)?o:[],t,null==n?void 0:n.swrOptions,r)}})}function V(e){var t=L(),n=M();return e.useHook({fetch:r.useCallback((function(r){return e.fetcher({input:(void 0===r?{}:r).input,options:e.fetchOptions,fetch:t,provider:n})}),[t,e.fetchOptions])})}var _=function(e){return(0,e.fetch)(e.options)},j=function(e){return(0,e.fetch)(d({},e.options,{body:e.input}))},F=j,T=function(e){var t;return null==(t=e.cart)?void 0:t.useAddItem},A=function(){var e=S(T);return V(d({fetcher:F},e)).apply(void 0,arguments)},D=j,R=function(e){var t;return null==(t=e.cart)?void 0:t.useRemoveItem},q=function(e){var t=S(R);return V(d({fetcher:D},t))(e)},B=j,G=function(e){var t;return null==(t=e.cart)?void 0:t.useUpdateItem},Q=function(e){var t=S(G);return V(d({fetcher:B},t))(e)},H={id:"123456789",name:"Product name",description:"",descriptionHtml:"\n <p>This is a <strong>placeholder</strong>.</p>\n ",images:[{url:"https://static1.plasmic.app/commerce/lightweight-jacket-0.png",alt:"Lightweight Jacket"},{url:"https://static1.plasmic.app/commerce/lightweight-jacket-1.png",alt:"Lightweight Jacket"},{url:"https://static1.plasmic.app/commerce/lightweight-jacket-2.png",alt:"Lightweight Jacket"}],variants:[{id:"variant1",name:"Variant 1",options:[]},{id:"variant2",name:"Variant 2",options:[]}],price:{value:0,currencyCode:"USD"},options:[]};function U(e){var t=e.product,r=e.children,a=o.useForm();return n.createElement(i.DataProvider,{name:"currentProduct",data:t,key:t.id},n.createElement(o.FormProvider,Object.assign({},a),r))}var Y=function(){var e=i.useSelector("currentProduct");return null!=e?e:H},W=n.createContext(void 0);function z(e){var t=e.category;return n.createElement(i.DataProvider,{name:"currentCategory",data:t,key:t.id},e.children)}var J=function(){return i.useSelector("currentCategory")};function X(e){var t=e.mediaIndex,r=e.onClick,o=e.children;return n.createElement(i.DataProvider,{name:"currentMedia",data:t,key:t},n.cloneElement(n.isValidElement(o)?o:n.createElement(n.Fragment,null),{onClick:r}))}var $={name:"plasmic-commerce-add-to-cart-button",displayName:"Add To Cart Button",props:{children:{type:"slot",defaultValue:[{type:"button",value:"Add To Cart"}]}},importPath:"@plasmicpkgs/commerce",importName:"AddToCartButton"};function K(e){var t=e.children,r=Y(),a=o.useFormContext(),i=A(),c=function(){var e=p(u().mark((function e(){var t,n,o,c;return u().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(n=+(null!=(t=a.getValues().ProductQuantity)?t:1),!(isNaN(n)||n<1)){e.next=3;break}throw new N({message:"The item quantity has to be a valid integer greater than 0"});case 3:if(!r){e.next=7;break}return c=null!=(o=a.getValues().ProductVariant)?o:r.variants[0].id,e.next=7,i({productId:r.id,variantId:c,quantity:n});case 7:case"end":return e.stop()}}),e)})));return function(){return e.apply(this,arguments)}}();return n.isValidElement(t)?n.cloneElement(t,{onClick:function(e){t.props.onClick&&"function"==typeof t.props.onClick&&t.props.onClick(e),c()}}):null}function Z(e,r){!function(){e?e.registerComponent.apply(e,arguments):t.apply(void 0,arguments)}(K,null!=r?r:$)}var ee=function(){var e=p(u().mark((function e(t){var r,n;return u().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(r=t.options,n=t.fetch,!t.input.cartId){e.next=7;break}return e.next=4,n(r);case 4:e.t0=e.sent,e.next=8;break;case 7:e.t0=null;case 8:return e.abrupt("return",e.t0);case 9:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}(),te=function(e){var t;return null==(t=e.cart)?void 0:t.useCart},re=function(e){var t,r=S(te),n=E().cartCookie,o=null!=(t=r.fetcher)?t:ee;return O(d({},r,{fetcher:function(e){return e.input.cartId=c.get(n),o(e)}}))(e)};function ne(e){var t=e.amount;return new Intl.NumberFormat(e.locale,{style:"currency",currency:e.currencyCode}).format(t)}function oe(e){var t=null!=e?e:{},n=t.amount,o=t.baseAmount,a=t.currencyCode,i=E().locale,c=r.useMemo((function(){return"number"==typeof n&&a?o?function(e){var t=e.amount,r=e.baseAmount,n=e.currencyCode,o=e.locale,a=r>t,i=new Intl.NumberFormat(o,{style:"percent"}),c=a?i.format((r-t)/r):null;return{price:ne({amount:t,currencyCode:n,locale:o}),basePrice:a?ne({amount:r,currencyCode:n,locale:o}):null,discount:c}}({amount:n,baseAmount:o,currencyCode:a,locale:i}):ne({amount:n,currencyCode:a,locale:i}):""}),[n,o,a]);return"string"==typeof c?{price:c}:c}var ae={name:"plasmic-commerce-cart",displayName:"Cart",description:"Show the size or total of the cart. See Cart Provider component to access more cart data.",props:{field:{type:"choice",options:["Size","Total Price"]},hideIfIsEmpty:{type:"boolean",defaultValue:!1,description:"You can hide this component if the cart is empty"}},importPath:"@plasmicpkgs/commerce",importName:"CartComponent"};function ie(e){var t,r,o,a,i=e.className,c=e.field,l=e.hideIfIsEmpty,u=re().data,s=oe({amount:null!=(t=null==u?void 0:u.totalPrice)?t:0,currencyCode:null!=(r=null==u?void 0:u.currency.code)?r:"USD"}).price;return c?("Size"===c?o=null!=(a=null==u?void 0:u.lineItems.length)?a:0:"Total Price"===c&&(o=null!=s?s:0),l&&0===o?null:n.createElement("span",{className:i},o)):n.createElement("p",null,"You must set the field prop")}function ce(e,r){!function(){e?e.registerComponent.apply(e,arguments):t.apply(void 0,arguments)}(ie,null!=r?r:ae)}var le={name:"plasmic-commerce-cart-provider",displayName:"Cart Provider",description:"Use this to create bespoke cart UI. Inside Cart Provider, use dynamic values to access cart data.",props:{children:"slot"},providesData:!0,importPath:"@plasmicpkgs/commerce",importName:"CartProvider"};function ue(e){var t=re();return n.createElement(i.DataProvider,{data:t.data,name:"cart"},e.children)}function se(e,r){!function(){e?e.registerComponent.apply(e,arguments):t.apply(void 0,arguments)}(ue,null!=r?r:le)}var pe=_,de=function(e){var t;return null==(t=e.site)?void 0:t.useCategories},me=function(e){var t=S(de);return O(d({fetcher:pe},t))(e)},fe={name:"plasmic-commerce-category-collection",displayName:"Category Collection",props:{children:{type:"slot",defaultValue:[{type:"vbox",children:[{type:"component",name:"plasmic-commerce-category-field",props:{field:"name"}},{type:"component",name:"plasmic-commerce-product-collection"}],styles:{width:"100%",minWidth:0}}]},emptyMessage:{type:"slot",defaultValue:{type:"text",value:"No collection found!"}},loadingMessage:{type:"slot",defaultValue:{type:"text",value:"Loading..."}},category:{type:"choice",options:function(e,t){var r;return null!=(r=null==t?void 0:t.categories.map((function(e){var t;return{label:""+" ".repeat(null!=(t=e.depth)?t:0)+e.name,value:e.id}})))?r:[]}},noLayout:{type:"boolean",displayName:"No layout",description:"Do not render a container element."},noAutoRepeat:{type:"boolean",displayName:"No auto-repeat",description:"Do not automatically repeat children for every category."}},defaultStyles:{display:"grid",gridTemplateColumns:"1fr",gridRowGap:"8px",padding:"8px",maxWidth:"100%"},importPath:"@plasmicpkgs/commerce",importName:"CategoryCollection",providesData:!0};function ye(e){var t,r=e.children,o=e.noLayout,a=e.noAutoRepeat,c=e.className,l=e.loadingMessage,u=e.emptyMessage,s=e.category,p=e.setControlContextData,d=n.useContext(i.PlasmicCanvasContext),m=me(),f=m.data,y=m.isLoading,v=me({categoryId:s,addIsEmptyField:!!d}),h=v.data,g=v.isLoading;f&&(null==p||p({categories:f}));var x=null==h?void 0:h.find((function(e){return!e.isEmpty})),C=null!=(t=null==h?void 0:h.findIndex((function(e){return!e.isEmpty})))?t:-1,b=a?r:null==h?void 0:h.map((function(e,t){return n.createElement(z,{category:e,key:e.id},i.repeatedElement(t<C?t+1:t===C?0:t,r))}));return[y,g].includes(!0)?n.isValidElement(l)?l:null:h&&0!==h.length?n.createElement(i.DataProvider,{name:"categories",data:h},n.createElement(W.Provider,{value:null!=x?x:h[0]},o?n.createElement(n.Fragment,null,b):n.createElement("div",{className:c},b))):n.isValidElement(u)?u:null}function ve(e,r){!function(){e?e.registerComponent.apply(e,arguments):t.apply(void 0,arguments)}(ye,null!=r?r:fe)}var he={name:"plasmic-commerce-category-field",displayName:"Category Field",props:{field:{type:"choice",options:["id","name","slug","path"]}},importPath:"@plasmicpkgs/commerce",importName:"CategoryField"};function ge(e){var t=e.className,r=e.field,o=J();return r?n.createElement("span",{className:t},o?o[r]:"Category field placeholder"):n.createElement("span",null,"You must set the field prop")}function xe(e,r){!function(){e?e.registerComponent.apply(e,arguments):t.apply(void 0,arguments)}(ge,null!=r?r:he)}var Ce={name:"plasmic-commerce-category-link",displayName:"Category Link",props:{children:"slot",linkDest:{type:"string",defaultValueHint:"category/{slug}",description:"Set the link destination. You can use {slug} to replace by the category slug"}},importPath:"@plasmicpkgs/commerce",importName:"CategoryLink"};function be(e){var t=e.className,r=e.children,o=e.linkDest,a=J();return n.createElement("a",{className:t,href:function(e){var t;if(e){for(var r,n=/{[^}]*}/,o=new RegExp(n,"g"),i=null!=(t=e.match(o))?t:[],c=e,l=C(i);!(r=l()).done;){var u=r.value.slice(1,-1);if(!a||!(u in a))return;c=c.replace(n,a[u])}return c}}(o),style:{color:"inherit",textDecoration:"inherit"}},r)}function Pe(e,r){!function(){e?e.registerComponent.apply(e,arguments):t.apply(void 0,arguments)}(be,null!=r?r:Ce)}var we={name:"plasmic-commerce-category-media",displayName:"Category Media",props:{mediaIndex:"number"},importPath:"@plasmicpkgs/commerce",importName:"CategoryMedia"},Ee=n.forwardRef((function(e,t){var r,o=e.className,a=e.mediaIndex,i=void 0===a?0:a,c=J(),l=null!=c&&c.images?c.images[i]:void 0;return n.createElement("img",{ref:t,alt:(null==c?void 0:c.name)||"Category Image",src:null!=(r=null==l?void 0:l.url)?r:"",loading:"lazy",className:o})}));function Ne(e,r){!function(){e?e.registerComponent.apply(e,arguments):t.apply(void 0,arguments)}(Ee,null!=r?r:we)}var ke=_,Ie=function(e){var t;return null==(t=e.products)?void 0:t.useProduct},Le=function(e){var t=S(Ie);return O(d({fetcher:ke},t))(e)},Me=_,Se=function(e){var t;return null==(t=e.products)?void 0:t.useSearch},Oe=function(e){var t=S(Se);return O(d({fetcher:Me},t))(e)},Ve={name:"plasmic-commerce-product-box",displayName:"Product Box",description:"Show a single product. [See commerce tutorial video](https://www.youtube.com/watch?v=1OJ_gXmta2Q)",props:{children:{type:"slot",defaultValue:[{type:"vbox",children:[{type:"component",name:"plasmic-commerce-product-text-field",props:{field:"name"}},{type:"component",name:"plasmic-commerce-product-media"}],styles:{width:"100%",minWidth:0}}]},noLayout:"boolean",id:{type:"cardPicker",modalTitle:"Product",onSearch:function(e,t){return null==t?void 0:t.onSearch},showInput:!0,options:function(e,t){var r;return null!=(r=null==t?void 0:t.products.map((function(e){var t,r;return{imgUrl:null==(t=e.images)||null==(t=t[0])?void 0:t.url,value:e.id,label:null!=(r=e.slug)?r:e.name,footer:n.createElement("div",null,n.createElement("div",null,n.createElement("strong",null,e.name)),n.createElement("div",null,e.slug))}})))?r:[]}}},importPath:"@plasmicpkgs/commerce",importName:"ProductBox",providesData:!0};function _e(e){var t=e.className,r=e.children,o=e.noLayout,a=e.id,i=e.setControlContextData,c=n.useState(""),u=c[0],s=c[1],p=Oe({search:""!==u?u:void 0}).data,d=n.useCallback(l((function(e){return s(e)}),300),[]);p&&(null==i||i({products:p.products,onSearch:d}));var m=Le({id:a}),f=m.data,y=m.error,v=m.isLoading;if(!a)return n.createElement("span",null,"You must set the id prop");if(y)throw new N({message:y.message,code:y.code});if(v)return n.createElement("span",null,"Loading...");if(!f)throw new Error("Product not found!");var h=n.createElement(U,{product:f},r);return o?n.createElement(n.Fragment,null,h):n.createElement("div",{className:t},h)}function je(e,r){!function(){e?e.registerComponent.apply(e,arguments):t.apply(void 0,arguments)}(_e,null!=r?r:Ve)}var Fe=_,Te=function(e){var t;return null==(t=e.site)?void 0:t.useBrands},Ae=function(e){var t=S(Te);return O(d({fetcher:Fe},t))(e)},De={name:"plasmic-commerce-product-collection",displayName:"Product Collection",description:"Show a product category. [See commerce tutorial video](https://www.youtube.com/watch?v=1OJ_gXmta2Q)",props:{children:{type:"slot",defaultValue:[{type:"vbox",children:[{type:"component",name:"plasmic-commerce-product-text-field",props:{field:"name"}},{type:"component",name:"plasmic-commerce-product-media"}],styles:{width:"100%",minWidth:0}}]},emptyMessage:{type:"slot",defaultValue:{type:"text",value:"No product found!"}},loadingMessage:{type:"slot",defaultValue:{type:"text",value:"Loading..."}},count:"number",category:{type:"choice",options:function(e,t){var r;return null!=(r=null==t?void 0:t.categories.map((function(e){var t;return{label:""+" ".repeat(null!=(t=e.depth)?t:0)+e.name,value:e.id}})))?r:[]},defaultValueHint:function(e,t){var r;return null==t||null==(r=t.categoryCtx)?void 0:r.name},readOnly:function(e,t){return!(null==t||!t.categoryCtx)}},includeSubCategories:{type:"boolean",hidden:function(e,t){var r;return!(null!=t&&null!=(r=t.features)&&r.includeSubCategories)}},brand:{type:"choice",options:function(e,t){var r;return null!=(r=null==t?void 0:t.brands.map((function(e){return{label:e.name,value:e.entityId}})))?r:[]}},search:{type:"string"},sort:{type:"choice",options:[{label:"Trending",value:"trending-desc"},{label:"New Arrivals",value:"latest-desc"},{label:"Price: Low to High",value:"price-asc"},{label:"Price: High to Low",value:"price-desc"}]},noLayout:{type:"boolean",displayName:"No layout",description:"Do not render a container element."},noAutoRepeat:{type:"boolean",displayName:"No auto-repeat",description:"Do not automatically repeat children for every category."}},defaultStyles:{display:"grid",gridTemplateColumns:"1fr 1fr 1fr 1fr",gridRowGap:"8px",gridColumnGap:"8px",padding:"8px",maxWidth:"100%"},importPath:"@plasmicpkgs/commerce",importName:"ProductCollection",providesData:!0};function Re(e){var t,o=e.className,a=e.children,c=e.count,l=e.category,u=e.includeSubCategories,s=e.brand,p=e.noLayout,d=e.noAutoRepeat,m=e.setControlContextData,f=e.emptyMessage,y=e.loadingMessage,v=e.search,h=e.sort,g=me(),x=g.data,C=g.isLoading,b=Ae(),P=b.data,w=b.isLoading,N=J(),k=Oe({categoryId:null!=(t=null==N?void 0:N.id)?t:l,brandId:s,count:c,categories:null!=x?x:[],includeSubCategories:u,search:v,sort:h}),I=k.data,L=k.isLoading,M=E().providerRef.current.extraFeatures,S=r.useContext(W);x&&P&&(null==m||m({categories:x,brands:P,features:M,categoryCtx:S}));var O=d?a:null==I?void 0:I.products.map((function(e,t){return n.createElement(U,{product:e,key:e.id},i.repeatedElement(t,a))}));return[L,w,C].includes(!0)?n.isValidElement(y)?y:null:I&&0!==I.products.length?n.createElement(i.DataProvider,{name:"products",data:null==I?void 0:I.products},p?n.createElement(n.Fragment,null,O):n.createElement("div",{className:o},O)):n.isValidElement(f)?f:null}function qe(e,r){!function(){e?e.registerComponent.apply(e,arguments):t.apply(void 0,arguments)}(Re,null!=r?r:De)}var Be={name:"plasmic-commerce-product-link",displayName:"Product Link",props:{children:"slot",linkDest:{type:"string",defaultValueHint:"products/{slug}",description:"Set the link destination. You can use {slug} to replace by the product slug"}},importPath:"@plasmicpkgs/commerce",importName:"ProductLink"};function Ge(e){var t=e.className,r=e.children,o=e.linkDest,a=Y();return n.createElement("a",{className:t,href:function(e){var t;if(e){for(var r,n=/{[^}]*}/,o=new RegExp(n,"g"),i=null!=(t=e.match(o))?t:[],c=e,l=C(i);!(r=l()).done;){var u=r.value.slice(1,-1);if(!a||!(u in a))return;c=c.replace(n,a[u])}return c}}(o),style:{color:"inherit",textDecoration:"inherit"}},r)}function Qe(e,r){!function(){e?e.registerComponent.apply(e,arguments):t.apply(void 0,arguments)}(Ge,null!=r?r:Be)}var He={name:"plasmic-commerce-product-media",displayName:"Product Media",props:{mediaIndex:{type:"number",min:0,hidden:function(e,t){return!(null==t||!t.inMediaContext)}}},importPath:"@plasmicpkgs/commerce",importName:"ProductMedia"},Ue=n.forwardRef((function(e,t){var r,o=e.className,a=e.mediaIndex,c=void 0===a?0:a,l=e.setControlContextData,u=Y(),s=i.useSelector("currentMedia");null==l||l({inMediaContext:void 0!==s});var p=null==u?void 0:u.images[null!=s?s:c];return n.createElement("img",{ref:t,alt:(null==u?void 0:u.name)||"Product Image",src:u?null!=(r=null==p?void 0:p.url)?r:"":"https://static1.plasmic.app/commerce/lightweight-jacket-0.png",loading:"lazy",className:o})}));function Ye(e,r){!function(){e?e.registerComponent.apply(e,arguments):t.apply(void 0,arguments)}(Ue,null!=r?r:He)}var We={name:"plasmic-commerce-product-media-collection",displayName:"Product Media Collection",props:{media:{type:"slot",defaultValue:{type:"component",name:"plasmic-commerce-product-media"},allowedComponents:["plasmic-commerce-product-media"]}},defaultStyles:{display:"grid",gridTemplateColumns:"1fr 1fr",gridRowGap:"8px",gridColumnGap:"8px",padding:"8px",maxWidth:"100%"},importPath:"@plasmicpkgs/commerce",importName:"ProductMediaCollection",providesData:!0};function ze(e){var t=e.media,r=e.className,o=Y();return n.createElement("div",{className:r},null==o?void 0:o.images.map((function(e,r){return i.repeatedElement(r,n.createElement(X,{mediaIndex:r,children:t}))})))}function Je(e,r){!function(){e?e.registerComponent.apply(e,arguments):t.apply(void 0,arguments)}(ze,null!=r?r:We)}var Xe=function(e,t){var r,n;return null!=(r=null==(n=e.variants.find((function(e){return e.id===t})))?void 0:n.price)?r:e.price.value},$e={name:"plasmic-commerce-product-price",displayName:"Product Price",props:{},importPath:"@plasmicpkgs/commerce",importName:"ProductPriceComponent"};function Ke(e){var t,r=e.className,a=Y(),i=o.useFormContext(),c=null==i?void 0:i.watch("ProductVariant",null!=(t=a.price)?t:""),l=oe({amount:a?Xe(a,c):0,currencyCode:a?a.price.currencyCode:"USD"});return n.createElement("span",{className:r},l.price)}function Ze(e,r){!function(){e?e.registerComponent.apply(e,arguments):t.apply(void 0,arguments)}(Ke,null!=r?r:$e)}var et={name:"plasmic-commerce-product-quantity",displayName:"Product Quantity",props:{children:{type:"slot",defaultValue:[{type:"input",attrs:{value:"1"}}]}},importPath:"@plasmicpkgs/commerce",importName:"ProductQuantity"};function tt(e){var t=e.className,r=e.children,a=o.useFormContext();return n.createElement("div",{className:t},n.createElement(o.Controller,{name:"ProductQuantity",defaultValue:1,control:null==a?void 0:a.control,render:function(e){var t=e.field;return n.isValidElement(r)?n.cloneElement(r,d({},r.props,t,{name:"ProductQuantity"})):n.createElement(n.Fragment,null)}}))}function rt(e,r){!function(){e?e.registerComponent.apply(e,arguments):t.apply(void 0,arguments)}(tt,null!=r?r:et)}var nt={name:"plasmic-commerce-product-slider",displayName:"Product Slider",providesData:!0,props:{thumbsVisible:{type:"number",description:"Number of thumbs visible",defaultValue:4,defaultValueHint:4},slideContainer:{type:"slot",defaultValue:{type:"vbox",children:[{type:"component",name:"plasmic-commerce-product-media"}]}},thumbsContainer:{type:"slot",defaultValue:{type:"hbox",children:[{type:"component",name:"plasmic-commerce-product-media"}]}},slideSelected:{type:"number",defaultValue:0,defaultValueHint:0,description:"Current slide selected"}},importPath:"@plasmicpkgs/commerce",importName:"ProductSlider"};function ot(e){var t=e.className,r=e.slideContainer,o=e.thumbsContainer,a=e.thumbsVisible,c=void 0===a?4:a,l=e.slideSelected,u=void 0===l?0:l,s=Y(),p=n.useState(u),d=p[0],m=p[1],f=Math.max(0,s.images.length-c),y=Math.min(f,Math.max(0,d-1));return n.createElement("div",{className:t},n.createElement(X,{mediaIndex:d,children:r}),n.createElement("div",{style:{display:"grid",gridTemplateColumns:"repeat("+c+", 1fr)"}},s.images.slice(y,y+c).map((function(e,t){return i.repeatedElement(t,n.createElement(X,{mediaIndex:y+t,children:o,onClick:function(){return m(y+t)}}))}))))}function at(e,r){!function(){e?e.registerComponent.apply(e,arguments):t.apply(void 0,arguments)}(ot,null!=r?r:nt)}var it={name:"plasmic-commerce-product-text-field",displayName:"Product Text Field",props:{field:{type:"choice",options:["id","name","description","sku","slug","path"]}},importPath:"@plasmicpkgs/commerce",importName:"ProductTextField"};function ct(e){var t,r=e.className,o=e.field,a=Y();return a?o?"description"===o?n.createElement("div",{className:r,dangerouslySetInnerHTML:{__html:null!=(t=a.descriptionHtml)?t:a.description}}):n.createElement("span",{className:r},a[o]):n.createElement("span",{className:r},"Unknown Product Field"):n.createElement("span",{className:r},"Fake Product Field")}function lt(e,r){!function(){e?e.registerComponent.apply(e,arguments):t.apply(void 0,arguments)}(ct,null!=r?r:it)}var ut={name:"plasmic-commerce-product-variant-picker",displayName:"Product Variant Picker",props:{},importPath:"@plasmicpkgs/commerce",importName:"ProductVariantPicker"};function st(e){var t,r,a=e.className,i=Y(),c=null!=(t=o.useFormContext())?t:o.useForm();return n.createElement(o.Controller,{name:"ProductVariant",control:null==c?void 0:c.control,defaultValue:null==i||null==(r=i.variants.find((function(e){return e.price===i.price.value})))?void 0:r.id,render:function(e){var t;return n.createElement("select",Object.assign({className:a},e.field),null!=(t=null==i?void 0:i.variants.map((function(e){return n.createElement("option",{value:e.id},e.name)})))?t:n.createElement("option",null,"Product Variant Placeholder"))}})}function pt(e,r){!function(){e?e.registerComponent.apply(e,arguments):t.apply(void 0,arguments)}(st,null!=r?r:ut)}exports.AddToCartButton=K,exports.CartActionsProvider=function(e){var t=A(),r=q(),o=Q(),a=n.useMemo((function(){return{addItem:function(e,r,n){t({productId:e,variantId:r,quantity:n})},updateItem:function(e,t){o({id:e,quantity:t})},removeItem:function(e){r({id:e})}}}),[t,r,o]);return n.createElement(i.GlobalActionsProvider,{contextName:e.globalContextName,actions:a},e.children)},exports.CartComponent=ie,exports.CartProvider=ue,exports.CartType={__proto__:null},exports.CategoryCollection=ye,exports.CategoryField=ge,exports.CategoryLink=be,exports.CategoryMedia=Ee,exports.CommerceError=N,exports.CoreCommerceProvider=w,exports.FetcherError=I,exports.ProductBox=_e,exports.ProductCollection=Re,exports.ProductLink=Ge,exports.ProductMedia=Ue,exports.ProductMediaCollection=ze,exports.ProductPlaceholder=H,exports.ProductPriceComponent=Ke,exports.ProductQuantity=tt,exports.ProductSlider=ot,exports.ProductTextField=ct,exports.ProductTypes={__proto__:null},exports.ProductVariantPicker=st,exports.SiteTypes={__proto__:null},exports.ValidationError=k,exports.addToCartButtonMeta=$,exports.cartMeta=ae,exports.cartProviderMeta=le,exports.categoryCollectionMeta=fe,exports.categoryFieldMeta=he,exports.categoryLinkMeta=Ce,exports.categoryMediaMeta=we,exports.fetcher=Me,exports.getCommerceProvider=function(e){return function(t){var r=t.children,o=function(e,t){if(null==e)return{};var r,n,o={},a=Object.keys(e);for(n=0;n<a.length;n++)t.indexOf(r=a[n])>=0||(o[r]=e[r]);return o}(t,b);return n.createElement(w,{provider:d({},e,o)},r)}},exports.globalActionsRegistrations={addItem:{displayName:"Add item to cart",parameters:[{name:"productId",displayName:"Product Id",type:"string"},{name:"variantId",displayName:"Variant Id",type:"string"},{name:"quantity",displayName:"Quantity",type:"number"}]},updateItem:{displayName:"Update item in cart",parameters:[{name:"lineItemId",displayName:"Line Item Id",type:"string"},{name:"quantity",displayName:"New Quantity",type:"number"}]},removeItem:{displayName:"Remove item from cart",parameters:[{name:"lineItemId",displayName:"Line Item Id",type:"string"}]}},exports.productBoxMeta=Ve,exports.productCollectionMeta=De,exports.productLinkMeta=Be,exports.productMediaCollectionMeta=We,exports.productMediaMeta=He,exports.productPriceMeta=$e,exports.productQuantityMeta=et,exports.productSliderMeta=nt,exports.productTextFieldMeta=it,exports.productVariantPickerMeta=ut,exports.registerAddToCartButton=Z,exports.registerAll=function(e){qe(e),lt(e),Ze(e),Ye(e),Je(e),ce(e),se(e),Z(e),rt(e),pt(e),je(e),at(e),Qe(e),ve(e),xe(e),Pe(e),Ne(e)},exports.registerCart=ce,exports.registerCartProvider=se,exports.registerCategoryCollection=ve,exports.registerCategoryField=xe,exports.registerCategoryLink=Pe,exports.registerCategoryMedia=Ne,exports.registerProductBox=je,exports.registerProductCollection=qe,exports.registerProductLink=Qe,exports.registerProductMedia=Ye,exports.registerProductMediaCollection=Je,exports.registerProductPrice=Ze,exports.registerProductQuantity=rt,exports.registerProductSlider=at,exports.registerProductVariantPicker=pt,exports.registerTextField=lt,exports.useAddItem=A,exports.useBrands=Ae,exports.useCart=re,exports.useCategories=me,exports.useCommerce=E,exports.useProduct=Le,exports.useRemoveItem=q,exports.useSearch=Oe,exports.useUpdateItem=Q;
1
+ "use strict";function e(e){return e&&"object"==typeof e&&"default"in e?e.default:e}Object.defineProperty(exports,"__esModule",{value:!0});var t=e(require("@plasmicapp/host/registerComponent")),r=require("react"),n=e(r),o=require("react-hook-form"),a=require("@plasmicapp/query"),i=require("@plasmicapp/host"),c=e(require("js-cookie")),l=e(require("debounce"));function u(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=Array(t);r<t;r++)n[r]=e[r];return n}function s(e,t,r,n,o,a,i){try{var c=e[a](i),l=c.value}catch(e){return void r(e)}c.done?t(l):Promise.resolve(l).then(n,o)}function p(e){return function(){var t=this,r=arguments;return new Promise((function(n,o){var a=e.apply(t,r);function i(e){s(a,n,o,i,c,"next",e)}function c(e){s(a,n,o,i,c,"throw",e)}i(void 0)}))}}function d(e,t,r){if(h())return Reflect.construct.apply(null,arguments);var n=[null];n.push.apply(n,t);var o=new(e.bind.apply(e,n));return r&&x(o,r.prototype),o}function m(e,t){var r="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(r)return(r=r.call(e)).next.bind(r);if(Array.isArray(e)||(r=function(e,t){if(e){if("string"==typeof e)return u(e,t);var r={}.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?u(e,t):void 0}}(e))||t&&e&&"number"==typeof e.length){r&&(e=r);var n=0;return function(){return n>=e.length?{done:!0}:{done:!1,value:e[n++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function f(){return(f=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)({}).hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e}).apply(null,arguments)}function y(e){return(y=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function v(e,t){e.prototype=Object.create(t.prototype),e.prototype.constructor=e,x(e,t)}function h(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch(e){}return(h=function(){return!!e})()}function g(){g=function(){return t};var e,t={},r=Object.prototype,n=r.hasOwnProperty,o=Object.defineProperty||function(e,t,r){e[t]=r.value},a="function"==typeof Symbol?Symbol:{},i=a.iterator||"@@iterator",c=a.asyncIterator||"@@asyncIterator",l=a.toStringTag||"@@toStringTag";function u(e,t,r){return Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}),e[t]}try{u({},"")}catch(e){u=function(e,t,r){return e[t]=r}}function s(e,t,r,n){var a=Object.create((t&&t.prototype instanceof v?t:v).prototype),i=new S(n||[]);return o(a,"_invoke",{value:k(e,r,i)}),a}function p(e,t,r){try{return{type:"normal",arg:e.call(t,r)}}catch(e){return{type:"throw",arg:e}}}t.wrap=s;var d="suspendedStart",m="executing",f="completed",y={};function v(){}function h(){}function x(){}var C={};u(C,i,(function(){return this}));var b=Object.getPrototypeOf,P=b&&b(b(O([])));P&&P!==r&&n.call(P,i)&&(C=P);var w=x.prototype=v.prototype=Object.create(C);function E(e){["next","throw","return"].forEach((function(t){u(e,t,(function(e){return this._invoke(t,e)}))}))}function N(e,t){function r(o,a,i,c){var l=p(e[o],e,a);if("throw"!==l.type){var u=l.arg,s=u.value;return s&&"object"==typeof s&&n.call(s,"__await")?t.resolve(s.__await).then((function(e){r("next",e,i,c)}),(function(e){r("throw",e,i,c)})):t.resolve(s).then((function(e){u.value=e,i(u)}),(function(e){return r("throw",e,i,c)}))}c(l.arg)}var a;o(this,"_invoke",{value:function(e,n){function o(){return new t((function(t,o){r(e,n,t,o)}))}return a=a?a.then(o,o):o()}})}function k(t,r,n){var o=d;return function(a,i){if(o===m)throw Error("Generator is already running");if(o===f){if("throw"===a)throw i;return{value:e,done:!0}}for(n.method=a,n.arg=i;;){var c=n.delegate;if(c){var l=I(c,n);if(l){if(l===y)continue;return l}}if("next"===n.method)n.sent=n._sent=n.arg;else if("throw"===n.method){if(o===d)throw o=f,n.arg;n.dispatchException(n.arg)}else"return"===n.method&&n.abrupt("return",n.arg);o=m;var u=p(t,r,n);if("normal"===u.type){if(o=n.done?f:"suspendedYield",u.arg===y)continue;return{value:u.arg,done:n.done}}"throw"===u.type&&(o=f,n.method="throw",n.arg=u.arg)}}}function I(t,r){var n=r.method,o=t.iterator[n];if(o===e)return r.delegate=null,"throw"===n&&t.iterator.return&&(r.method="return",r.arg=e,I(t,r),"throw"===r.method)||"return"!==n&&(r.method="throw",r.arg=new TypeError("The iterator does not provide a '"+n+"' method")),y;var a=p(o,t.iterator,r.arg);if("throw"===a.type)return r.method="throw",r.arg=a.arg,r.delegate=null,y;var i=a.arg;return i?i.done?(r[t.resultName]=i.value,r.next=t.nextLoc,"return"!==r.method&&(r.method="next",r.arg=e),r.delegate=null,y):i:(r.method="throw",r.arg=new TypeError("iterator result is not an object"),r.delegate=null,y)}function L(e){var t={tryLoc:e[0]};1 in e&&(t.catchLoc=e[1]),2 in e&&(t.finallyLoc=e[2],t.afterLoc=e[3]),this.tryEntries.push(t)}function M(e){var t=e.completion||{};t.type="normal",delete t.arg,e.completion=t}function S(e){this.tryEntries=[{tryLoc:"root"}],e.forEach(L,this),this.reset(!0)}function O(t){if(t||""===t){var r=t[i];if(r)return r.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var o=-1,a=function r(){for(;++o<t.length;)if(n.call(t,o))return r.value=t[o],r.done=!1,r;return r.value=e,r.done=!0,r};return a.next=a}}throw new TypeError(typeof t+" is not iterable")}return h.prototype=x,o(w,"constructor",{value:x,configurable:!0}),o(x,"constructor",{value:h,configurable:!0}),h.displayName=u(x,l,"GeneratorFunction"),t.isGeneratorFunction=function(e){var t="function"==typeof e&&e.constructor;return!!t&&(t===h||"GeneratorFunction"===(t.displayName||t.name))},t.mark=function(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,x):(e.__proto__=x,u(e,l,"GeneratorFunction")),e.prototype=Object.create(w),e},t.awrap=function(e){return{__await:e}},E(N.prototype),u(N.prototype,c,(function(){return this})),t.AsyncIterator=N,t.async=function(e,r,n,o,a){void 0===a&&(a=Promise);var i=new N(s(e,r,n,o),a);return t.isGeneratorFunction(r)?i:i.next().then((function(e){return e.done?e.value:i.next()}))},E(w),u(w,l,"Generator"),u(w,i,(function(){return this})),u(w,"toString",(function(){return"[object Generator]"})),t.keys=function(e){var t=Object(e),r=[];for(var n in t)r.push(n);return r.reverse(),function e(){for(;r.length;){var n=r.pop();if(n in t)return e.value=n,e.done=!1,e}return e.done=!0,e}},t.values=O,S.prototype={constructor:S,reset:function(t){if(this.prev=0,this.next=0,this.sent=this._sent=e,this.done=!1,this.delegate=null,this.method="next",this.arg=e,this.tryEntries.forEach(M),!t)for(var r in this)"t"===r.charAt(0)&&n.call(this,r)&&!isNaN(+r.slice(1))&&(this[r]=e)},stop:function(){this.done=!0;var e=this.tryEntries[0].completion;if("throw"===e.type)throw e.arg;return this.rval},dispatchException:function(t){if(this.done)throw t;var r=this;function o(n,o){return c.type="throw",c.arg=t,r.next=n,o&&(r.method="next",r.arg=e),!!o}for(var a=this.tryEntries.length-1;a>=0;--a){var i=this.tryEntries[a],c=i.completion;if("root"===i.tryLoc)return o("end");if(i.tryLoc<=this.prev){var l=n.call(i,"catchLoc"),u=n.call(i,"finallyLoc");if(l&&u){if(this.prev<i.catchLoc)return o(i.catchLoc,!0);if(this.prev<i.finallyLoc)return o(i.finallyLoc)}else if(l){if(this.prev<i.catchLoc)return o(i.catchLoc,!0)}else{if(!u)throw Error("try statement without catch or finally");if(this.prev<i.finallyLoc)return o(i.finallyLoc)}}}},abrupt:function(e,t){for(var r=this.tryEntries.length-1;r>=0;--r){var o=this.tryEntries[r];if(o.tryLoc<=this.prev&&n.call(o,"finallyLoc")&&this.prev<o.finallyLoc){var a=o;break}}a&&("break"===e||"continue"===e)&&a.tryLoc<=t&&t<=a.finallyLoc&&(a=null);var i=a?a.completion:{};return i.type=e,i.arg=t,a?(this.method="next",this.next=a.finallyLoc,y):this.complete(i)},complete:function(e,t){if("throw"===e.type)throw e.arg;return"break"===e.type||"continue"===e.type?this.next=e.arg:"return"===e.type?(this.rval=this.arg=e.arg,this.method="return",this.next="end"):"normal"===e.type&&t&&(this.next=t),y},finish:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var r=this.tryEntries[t];if(r.finallyLoc===e)return this.complete(r.completion,r.afterLoc),M(r),y}},catch:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var r=this.tryEntries[t];if(r.tryLoc===e){var n=r.completion;if("throw"===n.type){var o=n.arg;M(r)}return o}}throw Error("illegal catch attempt")},delegateYield:function(t,r,n){return this.delegate={iterator:O(t),resultName:r,nextLoc:n},"next"===this.method&&(this.arg=e),y}},t}function x(e,t){return(x=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e})(e,t)}function C(e){var t="function"==typeof Map?new Map:void 0;return(C=function(e){if(null===e||!function(e){try{return-1!==Function.toString.call(e).indexOf("[native code]")}catch(t){return"function"==typeof e}}(e))return e;if("function"!=typeof e)throw new TypeError("Super expression must either be null or a function");if(void 0!==t){if(t.has(e))return t.get(e);t.set(e,r)}function r(){return d(e,arguments,y(this).constructor)}return r.prototype=Object.create(e.prototype,{constructor:{value:r,enumerable:!1,writable:!0,configurable:!0}}),x(r,e)})(e)}var b=["children"],P=r.createContext({});function w(e){var t=e.provider,o=e.children,a=r.useRef(t),i=r.useRef(t.fetcher),c=a.current,l=c.locale,u=c.cartCookie,s=r.useMemo((function(){return{providerRef:a,fetcherRef:i,locale:l,cartCookie:u}}),[l,u]);return n.createElement(P.Provider,{value:s},o)}function E(){return r.useContext(P)}var N=function(e){function t(t){var r,n=t.message,o=t.code,a=t.errors,i=n?f({message:n},o?{code:o}:{}):a[0];return(r=e.call(this,i.message)||this).errors=n?[i]:a,i.code&&(r.code=i.code),r}return v(t,e),t}(C(Error)),k=function(e){function t(t){var r;return(r=e.call(this,t)||this).code="validation_error",r}return v(t,e),t}(N),I=function(e){function t(t){var r;return(r=e.call(this,t)||this).status=t.status,r}return v(t,e),t}(N);function L(){var e,t=E();return null!=(e=t.providerRef.current.fetcher)?e:t.fetcherRef.current}function M(){return E().providerRef.current}function S(e){return e(E().providerRef.current)}function O(e){var t=L(),r=M();return e.useHook({useData:function(n){var o;return function(e,t,r,n,o){var i=Array.isArray(t)?t:Object.entries(t),c=a.useMutablePlasmicQueryData((function(){var t=e.fetchOptions;return t?[t.url,t.query,t.method].concat(i.map((function(e){return e[1]}))):null}),function(){var t=p(g().mark((function t(n,a,c){var l,u,s,p=arguments;return g().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:for(t.prev=0,l=p.length,u=new Array(l>3?l-3:0),s=3;s<l;s++)u[s-3]=p[s];return t.next=4,e.fetcher({options:{url:n,query:a,method:c},input:u.reduce((function(e,t,r){return e[i[r][0]]=t,e}),{}),fetch:r,provider:o});case 4:return t.abrupt("return",t.sent);case 7:throw t.prev=7,t.t0=t.catch(0),t.t0 instanceof N||console.error(t.t0),t.t0;case 11:case"end":return t.stop()}}),t,null,[[0,7]])})));return function(e,r,n){return t.apply(this,arguments)}}(),n);return"isLoading"in c||Object.defineProperty(c,"isLoading",{get:function(){return void 0===c.data},enumerable:!0}),c}(e,null!=(o=null==n?void 0:n.input)?o:[],t,null==n?void 0:n.swrOptions,r)}})}function V(e){var t=L(),n=M();return e.useHook({fetch:r.useCallback((function(r){return e.fetcher({input:(void 0===r?{}:r).input,options:e.fetchOptions,fetch:t,provider:n})}),[t,e.fetchOptions])})}var _=function(e){return(0,e.fetch)(e.options)},F=function(e){return(0,e.fetch)(f({},e.options,{body:e.input}))},j=F,T=function(e){var t;return null==(t=e.cart)?void 0:t.useAddItem},A=function(){var e=S(T);return V(f({fetcher:j},e)).apply(void 0,arguments)},D=F,R=function(e){var t;return null==(t=e.cart)?void 0:t.useRemoveItem},q=function(e){var t=S(R);return V(f({fetcher:D},t))(e)},B=F,G=function(e){var t;return null==(t=e.cart)?void 0:t.useUpdateItem},Q=function(e){var t=S(G);return V(f({fetcher:B},t))(e)},H={id:"123456789",name:"Product name",description:"",descriptionHtml:"\n <p>This is a <strong>placeholder</strong>.</p>\n ",images:[{url:"https://static1.plasmic.app/commerce/lightweight-jacket-0.png",alt:"Lightweight Jacket"},{url:"https://static1.plasmic.app/commerce/lightweight-jacket-1.png",alt:"Lightweight Jacket"},{url:"https://static1.plasmic.app/commerce/lightweight-jacket-2.png",alt:"Lightweight Jacket"}],variants:[{id:"variant1",name:"Variant 1",options:[]},{id:"variant2",name:"Variant 2",options:[]}],price:{value:0,currencyCode:"USD"},options:[]};function U(e){var t=e.product,r=e.children,a=o.useForm();return n.createElement(i.DataProvider,{name:"currentProduct",data:t,key:t.id},n.createElement(o.FormProvider,Object.assign({},a),r))}var Y=function(){var e=i.useSelector("currentProduct");return null!=e?e:H},W=n.createContext(void 0);function z(e){var t=e.category;return n.createElement(i.DataProvider,{name:"currentCategory",data:t,key:t.id},e.children)}var J=function(){return i.useSelector("currentCategory")};function X(e){var t=e.mediaIndex,r=e.onClick,o=e.children;return n.createElement(i.DataProvider,{name:"currentMedia",data:t,key:t},n.cloneElement(n.isValidElement(o)?o:n.createElement(n.Fragment,null),{onClick:r}))}var $={name:"plasmic-commerce-add-to-cart-button",displayName:"Add To Cart Button",props:{children:{type:"slot",defaultValue:[{type:"button",value:"Add To Cart"}]}},importPath:"@plasmicpkgs/commerce",importName:"AddToCartButton"};function K(e){var t=e.children,r=Y(),a=o.useFormContext(),i=A(),c=function(){var e=p(g().mark((function e(){var t,n,o,c;return g().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(n=+(null!=(t=a.getValues().ProductQuantity)?t:1),!(isNaN(n)||n<1)){e.next=3;break}throw new N({message:"The item quantity has to be a valid integer greater than 0"});case 3:if(!r){e.next=7;break}return c=null!=(o=a.getValues().ProductVariant)?o:r.variants[0].id,e.next=7,i({productId:r.id,variantId:c,quantity:n});case 7:case"end":return e.stop()}}),e)})));return function(){return e.apply(this,arguments)}}();return n.isValidElement(t)?n.cloneElement(t,{onClick:function(e){t.props.onClick&&"function"==typeof t.props.onClick&&t.props.onClick(e),c()}}):null}function Z(e,r){!function(){e?e.registerComponent.apply(e,arguments):t.apply(void 0,arguments)}(K,null!=r?r:$)}var ee=function(){var e=p(g().mark((function e(t){var r,n;return g().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(r=t.options,n=t.fetch,!t.input.cartId){e.next=7;break}return e.next=4,n(r);case 4:e.t0=e.sent,e.next=8;break;case 7:e.t0=null;case 8:return e.abrupt("return",e.t0);case 9:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}(),te=function(e){var t;return null==(t=e.cart)?void 0:t.useCart},re=function(e){var t,r=S(te),n=E().cartCookie,o=null!=(t=r.fetcher)?t:ee;return O(f({},r,{fetcher:function(e){return e.input.cartId=c.get(n),o(e)}}))(e)};function ne(e){var t=e.amount;return new Intl.NumberFormat(e.locale,{style:"currency",currency:e.currencyCode}).format(t)}function oe(e){var t=null!=e?e:{},n=t.amount,o=t.baseAmount,a=t.currencyCode,i=E().locale,c=r.useMemo((function(){return"number"==typeof n&&a?o?function(e){var t=e.amount,r=e.baseAmount,n=e.currencyCode,o=e.locale,a=r>t,i=new Intl.NumberFormat(o,{style:"percent"}),c=a?i.format((r-t)/r):null;return{price:ne({amount:t,currencyCode:n,locale:o}),basePrice:a?ne({amount:r,currencyCode:n,locale:o}):null,discount:c}}({amount:n,baseAmount:o,currencyCode:a,locale:i}):ne({amount:n,currencyCode:a,locale:i}):""}),[n,o,a]);return"string"==typeof c?{price:c}:c}var ae={name:"plasmic-commerce-cart",displayName:"Cart",description:"Show the size or total of the cart. See Cart Provider component to access more cart data.",props:{field:{type:"choice",options:["Size","Total Price"]},hideIfIsEmpty:{type:"boolean",defaultValue:!1,description:"You can hide this component if the cart is empty"}},importPath:"@plasmicpkgs/commerce",importName:"CartComponent"};function ie(e){var t,r,o,a,i=e.className,c=e.field,l=e.hideIfIsEmpty,u=re().data,s=oe({amount:null!=(t=null==u?void 0:u.totalPrice)?t:0,currencyCode:null!=(r=null==u?void 0:u.currency.code)?r:"USD"}).price;return c?("Size"===c?o=null!=(a=null==u?void 0:u.lineItems.length)?a:0:"Total Price"===c&&(o=null!=s?s:0),l&&0===o?null:n.createElement("span",{className:i},o)):n.createElement("p",null,"You must set the field prop")}function ce(e,r){!function(){e?e.registerComponent.apply(e,arguments):t.apply(void 0,arguments)}(ie,null!=r?r:ae)}var le={name:"plasmic-commerce-cart-provider",displayName:"Cart Provider",description:"Use this to create bespoke cart UI. Inside Cart Provider, use dynamic values to access cart data.",props:{children:"slot"},providesData:!0,importPath:"@plasmicpkgs/commerce",importName:"CartProvider"};function ue(e){var t=re();return n.createElement(i.DataProvider,{data:t.data,name:"cart"},e.children)}function se(e,r){!function(){e?e.registerComponent.apply(e,arguments):t.apply(void 0,arguments)}(ue,null!=r?r:le)}var pe=_,de=function(e){var t;return null==(t=e.site)?void 0:t.useCategories},me=function(e){var t=S(de);return O(f({fetcher:pe},t))(e)},fe={name:"plasmic-commerce-category-collection",displayName:"Category Collection",props:{children:{type:"slot",defaultValue:[{type:"vbox",children:[{type:"component",name:"plasmic-commerce-category-field",props:{field:"name"}},{type:"component",name:"plasmic-commerce-product-collection"}],styles:{width:"100%",minWidth:0}}]},emptyMessage:{type:"slot",defaultValue:{type:"text",value:"No collection found!"}},loadingMessage:{type:"slot",defaultValue:{type:"text",value:"Loading..."}},category:{type:"choice",options:function(e,t){var r;return null!=(r=null==t?void 0:t.categories.map((function(e){var t;return{label:""+" ".repeat(null!=(t=e.depth)?t:0)+e.name,value:e.id}})))?r:[]}},noLayout:{type:"boolean",displayName:"No layout",description:"Do not render a container element."},noAutoRepeat:{type:"boolean",displayName:"No auto-repeat",description:"Do not automatically repeat children for every category."}},defaultStyles:{display:"grid",gridTemplateColumns:"1fr",gridRowGap:"8px",padding:"8px",maxWidth:"100%"},importPath:"@plasmicpkgs/commerce",importName:"CategoryCollection",providesData:!0};function ye(e){var t,r=e.children,o=e.noLayout,a=e.noAutoRepeat,c=e.className,l=e.loadingMessage,u=e.emptyMessage,s=e.category,p=e.setControlContextData,d=n.useContext(i.PlasmicCanvasContext),m=me(),f=m.data,y=m.isLoading,v=me({categoryId:s,addIsEmptyField:!!d}),h=v.data,g=v.isLoading;f&&(null==p||p({categories:f}));var x=null==h?void 0:h.find((function(e){return!e.isEmpty})),C=null!=(t=null==h?void 0:h.findIndex((function(e){return!e.isEmpty})))?t:-1,b=a?r:null==h?void 0:h.map((function(e,t){return n.createElement(z,{category:e,key:e.id},i.repeatedElement(t<C?t+1:t===C?0:t,r))}));return[y,g].includes(!0)?n.isValidElement(l)?l:null:h&&0!==h.length?n.createElement(i.DataProvider,{name:"categories",data:h},n.createElement(W.Provider,{value:null!=x?x:h[0]},o?n.createElement(n.Fragment,null,b):n.createElement("div",{className:c},b))):n.isValidElement(u)?u:null}function ve(e,r){!function(){e?e.registerComponent.apply(e,arguments):t.apply(void 0,arguments)}(ye,null!=r?r:fe)}var he={name:"plasmic-commerce-category-field",displayName:"Category Field",props:{field:{type:"choice",options:["id","name","slug","path"]}},importPath:"@plasmicpkgs/commerce",importName:"CategoryField"};function ge(e){var t=e.className,r=e.field,o=J();return r?n.createElement("span",{className:t},o?o[r]:"Category field placeholder"):n.createElement("span",null,"You must set the field prop")}function xe(e,r){!function(){e?e.registerComponent.apply(e,arguments):t.apply(void 0,arguments)}(ge,null!=r?r:he)}var Ce={name:"plasmic-commerce-category-link",displayName:"Category Link",props:{children:"slot",linkDest:{type:"string",defaultValueHint:"category/{slug}",description:"Set the link destination. You can use {slug} to replace by the category slug"}},importPath:"@plasmicpkgs/commerce",importName:"CategoryLink"};function be(e){var t=e.className,r=e.children,o=e.linkDest,a=J();return n.createElement("a",{className:t,href:function(e){var t;if(e){for(var r,n=/{[^}]*}/,o=new RegExp(n,"g"),i=null!=(t=e.match(o))?t:[],c=e,l=m(i);!(r=l()).done;){var u=r.value.slice(1,-1);if(!a||!(u in a))return;c=c.replace(n,a[u])}return c}}(o),style:{color:"inherit",textDecoration:"inherit"}},r)}function Pe(e,r){!function(){e?e.registerComponent.apply(e,arguments):t.apply(void 0,arguments)}(be,null!=r?r:Ce)}var we={name:"plasmic-commerce-category-media",displayName:"Category Media",props:{mediaIndex:"number"},importPath:"@plasmicpkgs/commerce",importName:"CategoryMedia"},Ee=n.forwardRef((function(e,t){var r,o=e.className,a=e.mediaIndex,i=void 0===a?0:a,c=J(),l=null!=c&&c.images?c.images[i]:void 0;return n.createElement("img",{ref:t,alt:(null==c?void 0:c.name)||"Category Image",src:null!=(r=null==l?void 0:l.url)?r:"",loading:"lazy",className:o})}));function Ne(e,r){!function(){e?e.registerComponent.apply(e,arguments):t.apply(void 0,arguments)}(Ee,null!=r?r:we)}var ke=_,Ie=function(e){var t;return null==(t=e.products)?void 0:t.useProduct},Le=function(e){var t=S(Ie);return O(f({fetcher:ke},t))(e)},Me=_,Se=function(e){var t;return null==(t=e.products)?void 0:t.useSearch},Oe=function(e){var t=S(Se);return O(f({fetcher:Me},t))(e)},Ve={name:"plasmic-commerce-product-box",displayName:"Product Box",description:"Show a single product. [See commerce tutorial video](https://www.youtube.com/watch?v=1OJ_gXmta2Q)",props:{children:{type:"slot",defaultValue:[{type:"vbox",children:[{type:"component",name:"plasmic-commerce-product-text-field",props:{field:"name"}},{type:"component",name:"plasmic-commerce-product-media"}],styles:{width:"100%",minWidth:0}}]},noLayout:"boolean",id:{type:"cardPicker",modalTitle:"Product",onSearch:function(e,t){return null==t?void 0:t.onSearch},showInput:!0,options:function(e,t){var r;return null!=(r=null==t?void 0:t.products.map((function(e){var t,r;return{imgUrl:null==(t=e.images)||null==(t=t[0])?void 0:t.url,value:e.id,label:null!=(r=e.slug)?r:e.name,footer:n.createElement("div",null,n.createElement("div",null,n.createElement("strong",null,e.name)),n.createElement("div",null,e.slug))}})))?r:[]}}},importPath:"@plasmicpkgs/commerce",importName:"ProductBox",providesData:!0};function _e(e){var t=e.className,r=e.children,o=e.noLayout,a=e.id,i=e.setControlContextData,c=n.useState(""),u=c[0],s=c[1],p=Oe({search:""!==u?u:void 0}).data,d=n.useCallback(l((function(e){return s(e)}),300),[]);p&&(null==i||i({products:p.products,onSearch:d}));var m=Le({id:a}),f=m.data,y=m.error,v=m.isLoading;if(!a)return n.createElement("span",null,"You must set the id prop");if(y)throw new N({message:y.message,code:y.code});if(v)return n.createElement("span",null,"Loading...");if(!f)throw new Error("Product not found!");var h=n.createElement(U,{product:f},r);return o?n.createElement(n.Fragment,null,h):n.createElement("div",{className:t},h)}function Fe(e,r){!function(){e?e.registerComponent.apply(e,arguments):t.apply(void 0,arguments)}(_e,null!=r?r:Ve)}var je=_,Te=function(e){var t;return null==(t=e.site)?void 0:t.useBrands},Ae=function(e){var t=S(Te);return O(f({fetcher:je},t))(e)},De={name:"plasmic-commerce-product-collection",displayName:"Product Collection",description:"Show a product category. [See commerce tutorial video](https://www.youtube.com/watch?v=1OJ_gXmta2Q)",props:{children:{type:"slot",defaultValue:[{type:"vbox",children:[{type:"component",name:"plasmic-commerce-product-text-field",props:{field:"name"}},{type:"component",name:"plasmic-commerce-product-media"}],styles:{width:"100%",minWidth:0}}]},emptyMessage:{type:"slot",defaultValue:{type:"text",value:"No product found!"}},loadingMessage:{type:"slot",defaultValue:{type:"text",value:"Loading..."}},count:"number",category:{type:"choice",options:function(e,t){var r;return null!=(r=null==t?void 0:t.categories.map((function(e){var t;return{label:""+" ".repeat(null!=(t=e.depth)?t:0)+e.name,value:e.id}})))?r:[]},defaultValueHint:function(e,t){var r;return null==t||null==(r=t.categoryCtx)?void 0:r.name},readOnly:function(e,t){return!(null==t||!t.categoryCtx)}},includeSubCategories:{type:"boolean",hidden:function(e,t){var r;return!(null!=t&&null!=(r=t.features)&&r.includeSubCategories)}},brand:{type:"choice",options:function(e,t){var r;return null!=(r=null==t?void 0:t.brands.map((function(e){return{label:e.name,value:e.entityId}})))?r:[]}},search:{type:"string"},sort:{type:"choice",options:[{label:"Trending",value:"trending-desc"},{label:"New Arrivals",value:"latest-desc"},{label:"Price: Low to High",value:"price-asc"},{label:"Price: High to Low",value:"price-desc"}]},noLayout:{type:"boolean",displayName:"No layout",description:"Do not render a container element."},noAutoRepeat:{type:"boolean",displayName:"No auto-repeat",description:"Do not automatically repeat children for every category."}},defaultStyles:{display:"grid",gridTemplateColumns:"1fr 1fr 1fr 1fr",gridRowGap:"8px",gridColumnGap:"8px",padding:"8px",maxWidth:"100%"},importPath:"@plasmicpkgs/commerce",importName:"ProductCollection",providesData:!0};function Re(e){var t,o=e.className,a=e.children,c=e.count,l=e.category,u=e.includeSubCategories,s=e.brand,p=e.noLayout,d=e.noAutoRepeat,m=e.setControlContextData,f=e.emptyMessage,y=e.loadingMessage,v=e.search,h=e.sort,g=me(),x=g.data,C=g.isLoading,b=Ae(),P=b.data,w=b.isLoading,N=J(),k=Oe({categoryId:null!=(t=null==N?void 0:N.id)?t:l,brandId:s,count:c,categories:null!=x?x:[],includeSubCategories:u,search:v,sort:h}),I=k.data,L=k.isLoading,M=E().providerRef.current.extraFeatures,S=r.useContext(W);x&&P&&(null==m||m({categories:x,brands:P,features:M,categoryCtx:S}));var O=d?a:null==I?void 0:I.products.map((function(e,t){return n.createElement(U,{product:e,key:e.id},i.repeatedElement(t,a))}));return[L,w,C].includes(!0)?n.isValidElement(y)?y:null:I&&0!==I.products.length?n.createElement(i.DataProvider,{name:"products",data:null==I?void 0:I.products},p?n.createElement(n.Fragment,null,O):n.createElement("div",{className:o},O)):n.isValidElement(f)?f:null}function qe(e,r){!function(){e?e.registerComponent.apply(e,arguments):t.apply(void 0,arguments)}(Re,null!=r?r:De)}var Be={name:"plasmic-commerce-product-link",displayName:"Product Link",props:{children:"slot",linkDest:{type:"string",defaultValueHint:"products/{slug}",description:"Set the link destination. You can use {slug} to replace by the product slug"}},importPath:"@plasmicpkgs/commerce",importName:"ProductLink"};function Ge(e){var t=e.className,r=e.children,o=e.linkDest,a=Y();return n.createElement("a",{className:t,href:function(e){var t;if(e){for(var r,n=/{[^}]*}/,o=new RegExp(n,"g"),i=null!=(t=e.match(o))?t:[],c=e,l=m(i);!(r=l()).done;){var u=r.value.slice(1,-1);if(!a||!(u in a))return;c=c.replace(n,a[u])}return c}}(o),style:{color:"inherit",textDecoration:"inherit"}},r)}function Qe(e,r){!function(){e?e.registerComponent.apply(e,arguments):t.apply(void 0,arguments)}(Ge,null!=r?r:Be)}var He={name:"plasmic-commerce-product-media",displayName:"Product Media",props:{mediaIndex:{type:"number",min:0,hidden:function(e,t){return!(null==t||!t.inMediaContext)}}},importPath:"@plasmicpkgs/commerce",importName:"ProductMedia"},Ue=n.forwardRef((function(e,t){var r,o=e.className,a=e.mediaIndex,c=void 0===a?0:a,l=e.setControlContextData,u=Y(),s=i.useSelector("currentMedia");null==l||l({inMediaContext:void 0!==s});var p=null==u?void 0:u.images[null!=s?s:c];return n.createElement("img",{ref:t,alt:(null==u?void 0:u.name)||"Product Image",src:u?null!=(r=null==p?void 0:p.url)?r:"":"https://static1.plasmic.app/commerce/lightweight-jacket-0.png",loading:"lazy",className:o})}));function Ye(e,r){!function(){e?e.registerComponent.apply(e,arguments):t.apply(void 0,arguments)}(Ue,null!=r?r:He)}var We={name:"plasmic-commerce-product-media-collection",displayName:"Product Media Collection",props:{media:{type:"slot",defaultValue:{type:"component",name:"plasmic-commerce-product-media"},allowedComponents:["plasmic-commerce-product-media"]}},defaultStyles:{display:"grid",gridTemplateColumns:"1fr 1fr",gridRowGap:"8px",gridColumnGap:"8px",padding:"8px",maxWidth:"100%"},importPath:"@plasmicpkgs/commerce",importName:"ProductMediaCollection",providesData:!0};function ze(e){var t=e.media,r=e.className,o=Y();return n.createElement("div",{className:r},null==o?void 0:o.images.map((function(e,r){return i.repeatedElement(r,n.createElement(X,{mediaIndex:r,children:t}))})))}function Je(e,r){!function(){e?e.registerComponent.apply(e,arguments):t.apply(void 0,arguments)}(ze,null!=r?r:We)}var Xe=function(e,t){var r,n;return null!=(r=null==(n=e.variants.find((function(e){return e.id===t})))?void 0:n.price)?r:e.price.value},$e={name:"plasmic-commerce-product-price",displayName:"Product Price",props:{},importPath:"@plasmicpkgs/commerce",importName:"ProductPriceComponent"};function Ke(e){var t,r=e.className,a=Y(),i=o.useFormContext(),c=null==i?void 0:i.watch("ProductVariant",null!=(t=a.price)?t:""),l=oe({amount:a?Xe(a,c):0,currencyCode:a?a.price.currencyCode:"USD"});return n.createElement("span",{className:r},l.price)}function Ze(e,r){!function(){e?e.registerComponent.apply(e,arguments):t.apply(void 0,arguments)}(Ke,null!=r?r:$e)}var et={name:"plasmic-commerce-product-quantity",displayName:"Product Quantity",props:{children:{type:"slot",defaultValue:[{type:"input",attrs:{value:"1"}}]}},importPath:"@plasmicpkgs/commerce",importName:"ProductQuantity"};function tt(e){var t=e.className,r=e.children,a=o.useFormContext();return n.createElement("div",{className:t},n.createElement(o.Controller,{name:"ProductQuantity",defaultValue:1,control:null==a?void 0:a.control,render:function(e){var t=e.field;return n.isValidElement(r)?n.cloneElement(r,f({},r.props,t,{name:"ProductQuantity"})):n.createElement(n.Fragment,null)}}))}function rt(e,r){!function(){e?e.registerComponent.apply(e,arguments):t.apply(void 0,arguments)}(tt,null!=r?r:et)}var nt={name:"plasmic-commerce-product-slider",displayName:"Product Slider",providesData:!0,props:{thumbsVisible:{type:"number",description:"Number of thumbs visible",defaultValue:4,defaultValueHint:4},slideContainer:{type:"slot",defaultValue:{type:"vbox",children:[{type:"component",name:"plasmic-commerce-product-media"}]}},thumbsContainer:{type:"slot",defaultValue:{type:"hbox",children:[{type:"component",name:"plasmic-commerce-product-media"}]}},slideSelected:{type:"number",defaultValue:0,defaultValueHint:0,description:"Current slide selected"}},importPath:"@plasmicpkgs/commerce",importName:"ProductSlider"};function ot(e){var t=e.className,r=e.slideContainer,o=e.thumbsContainer,a=e.thumbsVisible,c=void 0===a?4:a,l=e.slideSelected,u=void 0===l?0:l,s=Y(),p=n.useState(u),d=p[0],m=p[1],f=Math.max(0,s.images.length-c),y=Math.min(f,Math.max(0,d-1));return n.createElement("div",{className:t},n.createElement(X,{mediaIndex:d,children:r}),n.createElement("div",{style:{display:"grid",gridTemplateColumns:"repeat("+c+", 1fr)"}},s.images.slice(y,y+c).map((function(e,t){return i.repeatedElement(t,n.createElement(X,{mediaIndex:y+t,children:o,onClick:function(){return m(y+t)}}))}))))}function at(e,r){!function(){e?e.registerComponent.apply(e,arguments):t.apply(void 0,arguments)}(ot,null!=r?r:nt)}var it={name:"plasmic-commerce-product-text-field",displayName:"Product Text Field",props:{field:{type:"choice",options:["id","name","description","sku","slug","path"]}},importPath:"@plasmicpkgs/commerce",importName:"ProductTextField"};function ct(e){var t,r=e.className,o=e.field,a=Y();return a?o?"description"===o?n.createElement("div",{className:r,dangerouslySetInnerHTML:{__html:null!=(t=a.descriptionHtml)?t:a.description}}):n.createElement("span",{className:r},a[o]):n.createElement("span",{className:r},"Unknown Product Field"):n.createElement("span",{className:r},"Fake Product Field")}function lt(e,r){!function(){e?e.registerComponent.apply(e,arguments):t.apply(void 0,arguments)}(ct,null!=r?r:it)}var ut={name:"plasmic-commerce-product-variant-picker",displayName:"Product Variant Picker",props:{},importPath:"@plasmicpkgs/commerce",importName:"ProductVariantPicker"};function st(e){var t,r,a=e.className,i=Y(),c=null!=(t=o.useFormContext())?t:o.useForm();return n.createElement(o.Controller,{name:"ProductVariant",control:null==c?void 0:c.control,defaultValue:null==i||null==(r=i.variants.find((function(e){return e.price===i.price.value})))?void 0:r.id,render:function(e){var t;return n.createElement("select",Object.assign({className:a},e.field),null!=(t=null==i?void 0:i.variants.map((function(e){return n.createElement("option",{value:e.id},e.name)})))?t:n.createElement("option",null,"Product Variant Placeholder"))}})}function pt(e,r){!function(){e?e.registerComponent.apply(e,arguments):t.apply(void 0,arguments)}(st,null!=r?r:ut)}exports.AddToCartButton=K,exports.CartActionsProvider=function(e){var t=A(),r=q(),o=Q(),a=n.useMemo((function(){return{addItem:function(e,r,n){t({productId:e,variantId:r,quantity:n})},updateItem:function(e,t){o({id:e,quantity:t})},removeItem:function(e){r({id:e})}}}),[t,r,o]);return n.createElement(i.GlobalActionsProvider,{contextName:e.globalContextName,actions:a},e.children)},exports.CartComponent=ie,exports.CartProvider=ue,exports.CartType={__proto__:null},exports.CategoryCollection=ye,exports.CategoryField=ge,exports.CategoryLink=be,exports.CategoryMedia=Ee,exports.CommerceError=N,exports.CoreCommerceProvider=w,exports.FetcherError=I,exports.ProductBox=_e,exports.ProductCollection=Re,exports.ProductLink=Ge,exports.ProductMedia=Ue,exports.ProductMediaCollection=ze,exports.ProductPlaceholder=H,exports.ProductPriceComponent=Ke,exports.ProductQuantity=tt,exports.ProductSlider=ot,exports.ProductTextField=ct,exports.ProductTypes={__proto__:null},exports.ProductVariantPicker=st,exports.SiteTypes={__proto__:null},exports.ValidationError=k,exports.addToCartButtonMeta=$,exports.cartMeta=ae,exports.cartProviderMeta=le,exports.categoryCollectionMeta=fe,exports.categoryFieldMeta=he,exports.categoryLinkMeta=Ce,exports.categoryMediaMeta=we,exports.fetcher=Me,exports.getCommerceProvider=function(e){return function(t){var r=t.children,o=function(e,t){if(null==e)return{};var r={};for(var n in e)if({}.hasOwnProperty.call(e,n)){if(-1!==t.indexOf(n))continue;r[n]=e[n]}return r}(t,b);return n.createElement(w,{provider:f({},e,o)},r)}},exports.globalActionsRegistrations={addItem:{displayName:"Add item to cart",parameters:[{name:"productId",displayName:"Product Id",type:"string"},{name:"variantId",displayName:"Variant Id",type:"string"},{name:"quantity",displayName:"Quantity",type:"number"}]},updateItem:{displayName:"Update item in cart",parameters:[{name:"lineItemId",displayName:"Line Item Id",type:"string"},{name:"quantity",displayName:"New Quantity",type:"number"}]},removeItem:{displayName:"Remove item from cart",parameters:[{name:"lineItemId",displayName:"Line Item Id",type:"string"}]}},exports.productBoxMeta=Ve,exports.productCollectionMeta=De,exports.productLinkMeta=Be,exports.productMediaCollectionMeta=We,exports.productMediaMeta=He,exports.productPriceMeta=$e,exports.productQuantityMeta=et,exports.productSliderMeta=nt,exports.productTextFieldMeta=it,exports.productVariantPickerMeta=ut,exports.registerAddToCartButton=Z,exports.registerAll=function(e){qe(e),lt(e),Ze(e),Ye(e),Je(e),ce(e),se(e),Z(e),rt(e),pt(e),Fe(e),at(e),Qe(e),ve(e),xe(e),Pe(e),Ne(e)},exports.registerCart=ce,exports.registerCartProvider=se,exports.registerCategoryCollection=ve,exports.registerCategoryField=xe,exports.registerCategoryLink=Pe,exports.registerCategoryMedia=Ne,exports.registerProductBox=Fe,exports.registerProductCollection=qe,exports.registerProductLink=Qe,exports.registerProductMedia=Ye,exports.registerProductMediaCollection=Je,exports.registerProductPrice=Ze,exports.registerProductQuantity=rt,exports.registerProductSlider=at,exports.registerProductVariantPicker=pt,exports.registerTextField=lt,exports.useAddItem=A,exports.useBrands=Ae,exports.useCart=re,exports.useCategories=me,exports.useCommerce=E,exports.useProduct=Le,exports.useRemoveItem=q,exports.useSearch=Oe,exports.useUpdateItem=Q;
2
2
  //# sourceMappingURL=commerce.cjs.production.min.js.map