@plasmicpkgs/commerce 0.0.9 → 0.0.12

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"),i=e(require("swr")),a=require("@plasmicapp/host"),c=e(require("js-cookie"));function u(e,t,r,n,o,i,a){try{var c=e[i](a),u=c.value}catch(e){return void r(e)}c.done?t(u):Promise.resolve(u).then(n,o)}function l(e){return function(){var t=this,r=arguments;return new Promise((function(n,o){var i=e.apply(t,r);function a(e){u(i,n,o,a,c,"next",e)}function c(e){u(i,n,o,a,c,"throw",e)}a(void 0)}))}}function s(){return(s=Object.assign||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 p(e,t){e.prototype=Object.create(t.prototype),e.prototype.constructor=e,m(e,t)}function d(e){return(d=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function m(e,t){return(m=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function f(){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=f()?Reflect.construct:function(e,t,r){var n=[null];n.push.apply(n,t);var o=new(Function.bind.apply(e,n));return r&&m(o,r.prototype),o}).apply(null,arguments)}function v(e){var t="function"==typeof Map?new Map:void 0;return(v=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,d(this).constructor)}return r.prototype=Object.create(e.prototype,{constructor:{value:r,enumerable:!1,writable:!0,configurable:!0}}),m(r,e)})(e)}function y(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 g(e,t){return e(t={exports:{}},t.exports),t.exports}var x=g((function(e){var t=function(e){var t=Object.prototype,r=t.hasOwnProperty,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",i=n.asyncIterator||"@@asyncIterator",a=n.toStringTag||"@@toStringTag";function c(e,t,r){return Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}),e[t]}try{c({},"")}catch(e){c=function(e,t,r){return e[t]=r}}function u(e,t,r,n){var o=Object.create((t&&t.prototype instanceof p?t:p).prototype),i=new w(n||[]);return o._invoke=function(e,t,r){var n="suspendedStart";return function(o,i){if("executing"===n)throw new Error("Generator is already running");if("completed"===n){if("throw"===o)throw i;return{value:void 0,done:!0}}for(r.method=o,r.arg=i;;){var a=r.delegate;if(a){var c=C(a,r);if(c){if(c===s)continue;return c}}if("next"===r.method)r.sent=r._sent=r.arg;else if("throw"===r.method){if("suspendedStart"===n)throw n="completed",r.arg;r.dispatchException(r.arg)}else"return"===r.method&&r.abrupt("return",r.arg);n="executing";var u=l(e,t,r);if("normal"===u.type){if(n=r.done?"completed":"suspendedYield",u.arg===s)continue;return{value:u.arg,done:r.done}}"throw"===u.type&&(n="completed",r.method="throw",r.arg=u.arg)}}}(e,r,i),o}function l(e,t,r){try{return{type:"normal",arg:e.call(t,r)}}catch(e){return{type:"throw",arg:e}}}e.wrap=u;var s={};function p(){}function d(){}function m(){}var f={};f[o]=function(){return this};var h=Object.getPrototypeOf,v=h&&h(h(E([])));v&&v!==t&&r.call(v,o)&&(f=v);var y=m.prototype=p.prototype=Object.create(f);function g(e){["next","throw","return"].forEach((function(t){c(e,t,(function(e){return this._invoke(t,e)}))}))}function x(e,t){var n;this._invoke=function(o,i){function a(){return new t((function(n,a){!function n(o,i,a,c){var u=l(e[o],e,i);if("throw"!==u.type){var s=u.arg,p=s.value;return p&&"object"==typeof p&&r.call(p,"__await")?t.resolve(p.__await).then((function(e){n("next",e,a,c)}),(function(e){n("throw",e,a,c)})):t.resolve(p).then((function(e){s.value=e,a(s)}),(function(e){return n("throw",e,a,c)}))}c(u.arg)}(o,i,n,a)}))}return n=n?n.then(a,a):a()}}function C(e,t){var r=e.iterator[t.method];if(void 0===r){if(t.delegate=null,"throw"===t.method){if(e.iterator.return&&(t.method="return",t.arg=void 0,C(e,t),"throw"===t.method))return s;t.method="throw",t.arg=new TypeError("The iterator does not provide a 'throw' method")}return s}var n=l(r,e.iterator,t.arg);if("throw"===n.type)return t.method="throw",t.arg=n.arg,t.delegate=null,s;var o=n.arg;return o?o.done?(t[e.resultName]=o.value,t.next=e.nextLoc,"return"!==t.method&&(t.method="next",t.arg=void 0),t.delegate=null,s):o:(t.method="throw",t.arg=new TypeError("iterator result is not an object"),t.delegate=null,s)}function b(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 P(e){var t=e.completion||{};t.type="normal",delete t.arg,e.completion=t}function w(e){this.tryEntries=[{tryLoc:"root"}],e.forEach(b,this),this.reset(!0)}function E(e){if(e){var t=e[o];if(t)return t.call(e);if("function"==typeof e.next)return e;if(!isNaN(e.length)){var n=-1,i=function t(){for(;++n<e.length;)if(r.call(e,n))return t.value=e[n],t.done=!1,t;return t.value=void 0,t.done=!0,t};return i.next=i}}return{next:k}}function k(){return{value:void 0,done:!0}}return d.prototype=y.constructor=m,m.constructor=d,d.displayName=c(m,a,"GeneratorFunction"),e.isGeneratorFunction=function(e){var t="function"==typeof e&&e.constructor;return!!t&&(t===d||"GeneratorFunction"===(t.displayName||t.name))},e.mark=function(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,m):(e.__proto__=m,c(e,a,"GeneratorFunction")),e.prototype=Object.create(y),e},e.awrap=function(e){return{__await:e}},g(x.prototype),x.prototype[i]=function(){return this},e.AsyncIterator=x,e.async=function(t,r,n,o,i){void 0===i&&(i=Promise);var a=new x(u(t,r,n,o),i);return e.isGeneratorFunction(r)?a:a.next().then((function(e){return e.done?e.value:a.next()}))},g(y),c(y,a,"Generator"),y[o]=function(){return this},y.toString=function(){return"[object Generator]"},e.keys=function(e){var t=[];for(var r in e)t.push(r);return t.reverse(),function r(){for(;t.length;){var n=t.pop();if(n in e)return r.value=n,r.done=!1,r}return r.done=!0,r}},e.values=E,w.prototype={constructor:w,reset:function(e){if(this.prev=0,this.next=0,this.sent=this._sent=void 0,this.done=!1,this.delegate=null,this.method="next",this.arg=void 0,this.tryEntries.forEach(P),!e)for(var t in this)"t"===t.charAt(0)&&r.call(this,t)&&!isNaN(+t.slice(1))&&(this[t]=void 0)},stop:function(){this.done=!0;var e=this.tryEntries[0].completion;if("throw"===e.type)throw e.arg;return this.rval},dispatchException:function(e){if(this.done)throw e;var t=this;function n(r,n){return a.type="throw",a.arg=e,t.next=r,n&&(t.method="next",t.arg=void 0),!!n}for(var o=this.tryEntries.length-1;o>=0;--o){var i=this.tryEntries[o],a=i.completion;if("root"===i.tryLoc)return n("end");if(i.tryLoc<=this.prev){var c=r.call(i,"catchLoc"),u=r.call(i,"finallyLoc");if(c&&u){if(this.prev<i.catchLoc)return n(i.catchLoc,!0);if(this.prev<i.finallyLoc)return n(i.finallyLoc)}else if(c){if(this.prev<i.catchLoc)return n(i.catchLoc,!0)}else{if(!u)throw new Error("try statement without catch or finally");if(this.prev<i.finallyLoc)return n(i.finallyLoc)}}}},abrupt:function(e,t){for(var n=this.tryEntries.length-1;n>=0;--n){var o=this.tryEntries[n];if(o.tryLoc<=this.prev&&r.call(o,"finallyLoc")&&this.prev<o.finallyLoc){var i=o;break}}i&&("break"===e||"continue"===e)&&i.tryLoc<=t&&t<=i.finallyLoc&&(i=null);var a=i?i.completion:{};return a.type=e,a.arg=t,i?(this.method="next",this.next=i.finallyLoc,s):this.complete(a)},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),s},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),P(r),s}},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;P(r)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(e,t,r){return this.delegate={iterator:E(e),resultName:t,nextLoc:r},"next"===this.method&&(this.arg=void 0),s}},e}(e.exports);try{regeneratorRuntime=t}catch(e){Function("r","regeneratorRuntime = r")(t)}})),C={id:"123456789",name:"Product Placeholder",description:"",descriptionHtml:"\n <p>This is a <strong>placeholder</strong>.</p>\n <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>\n <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</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:"variiant1",name:"Variant Placeholder",options:[]},{id:"variant2",name:"Variant Placeholder 2",options:[]}],price:{value:0,currencyCode:"USD"},options:[]},b=n.createContext(void 0),P=n.createContext(void 0);function w(e){var t=e.product,r=e.children,i=o.useForm();return n.createElement(b.Provider,{value:t,key:t.id},n.createElement(o.FormProvider,Object.assign({},i),r))}var E=function(){var e=r.useContext(b);return null!=e?e:C};function k(e){var t=e.category;return n.createElement(P.Provider,{value:t,key:t.id},e.children)}var N=function(){return r.useContext(P)},L=["children"],O=r.createContext({});function _(e){var t=e.provider,o=e.children,i=r.useRef(t),a=r.useRef(t.fetcher),c=i.current,u=c.locale,l=c.cartCookie,s=r.useMemo((function(){return{providerRef:i,fetcherRef:a,locale:u,cartCookie:l}}),[u,l]);return n.createElement(O.Provider,{value:s},o)}function F(){return r.useContext(O)}var j=function(e){function t(t){var r,n=t.message,o=t.code,i=t.errors,a=n?s({message:n},o?{code:o}:{}):i[0];return(r=e.call(this,a.message)||this).errors=n?[a]:i,a.code&&(r.code=a.code),r}return p(t,e),t}(v(Error)),I=function(e){function t(t){var r;return(r=e.call(this,t)||this).code="validation_error",r}return p(t,e),t}(j),M=function(e){function t(t){var r;return(r=e.call(this,t)||this).status=t.status,r}return p(t,e),t}(j);function S(){var e,t=F();return null!=(e=t.providerRef.current.fetcher)?e:t.fetcherRef.current}function V(e){return e(F().providerRef.current)}function T(e){var t=S();return e.useHook({useData:function(r){var n,o,a,c,u,s,p;return o=e,a=null!=(n=null==r?void 0:r.input)?n:[],c=t,u=null==r?void 0:r.swrOptions,s=Array.isArray(a)?a:Object.entries(a),"isLoading"in(p=i((function(){var e=o.fetchOptions;return e?[e.url,e.query,e.method].concat(s.map((function(e){return e[1]}))):null}),function(){var e=l(x.mark((function e(t,r,n){var i,a,u,l=arguments;return x.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:for(e.prev=0,i=l.length,a=new Array(i>3?i-3:0),u=3;u<i;u++)a[u-3]=l[u];return e.next=4,o.fetcher({options:{url:t,query:r,method:n},input:a.reduce((function(e,t,r){return e[s[r][0]]=t,e}),{}),fetch:c});case 4:return e.abrupt("return",e.sent);case 7:throw e.prev=7,e.t0=e.catch(0),e.t0 instanceof j||console.error(e.t0),e.t0;case 11:case"end":return e.stop()}}),e,null,[[0,7]])})));return function(t,r,n){return e.apply(this,arguments)}}(),u))||Object.defineProperty(p,"isLoading",{get:function(){return void 0===p.data},enumerable:!0}),p}})}function A(e){var t=S();return e.useHook({fetch:r.useCallback((function(r){return e.fetcher({input:(void 0===r?{}:r).input,options:e.fetchOptions,fetch:t})}),[t,e.fetchOptions])})}var R=function(e){return(0,e.fetch)(e.options)},q=function(e){return(0,e.fetch)(s({},e.options,{body:e.input}))},B=q,G=function(e){var t;return null==(t=e.cart)?void 0:t.useAddItem},D=function(){var e=V(G);return A(s({fetcher:B},e)).apply(void 0,arguments)},Q={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 H(e){var t=e.children,r=E(),i=o.useFormContext(),a=D(),c=function(){var e=l(x.mark((function e(){var t,n,o,c;return x.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(n=+(null!=(t=i.getValues().ProductQuantity)?t:1),!(isNaN(n)||n<1)){e.next=3;break}throw new j({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=i.getValues().ProductVariant)?o:r.variants[0].id,e.next=7,a({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 U(e,r){!function(){e?e.registerComponent.apply(e,arguments):t.apply(void 0,arguments)}(H,null!=r?r:Q)}var Y=R,W=function(e){var t;return null==(t=e.products)?void 0:t.useProduct},z=function(e){var t=V(W);return T(s({fetcher:Y},t))(e)},J={name:"plasmic-commerce-product-box",displayName:"Product Box",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:"string",description:"Fetch a product by its slug or ID"}},importPath:"@plasmicpkgs/commerce",importName:"ProductBox"};function $(e){var t=e.className,r=e.children,o=e.noLayout,i=e.id,a=z({id:i}),c=a.data,u=a.error,l=a.isLoading;if(!i)return n.createElement("span",null,"You must set the id prop");if(u)throw new j({message:u.message,code:u.code});if(l)return n.createElement("span",null,"Loading...");if(!c)throw new Error("Product not found!");var s=n.createElement(w,{product:c},r);return o?n.createElement(n.Fragment,null,s):n.createElement("div",{className:t},s)}function K(e,r){!function(){e?e.registerComponent.apply(e,arguments):t.apply(void 0,arguments)}($,null!=r?r:J)}var X=R,Z=function(e){var t;return null==(t=e.products)?void 0:t.useSearch},ee=function(e){var t=V(Z);return T(s({fetcher:X},t))(e)},te=R,re=function(e){var t;return null==(t=e.site)?void 0:t.useCategories},ne=function(e){var t=V(re);return T(s({fetcher:te},t))(e)},oe=R,ie=function(e){var t;return null==(t=e.site)?void 0:t.useBrands},ae=function(e){var t=V(ie);return T(s({fetcher:oe},t))(e)},ce=function(){return F().providerRef.current.extraFeatures},ue={name:"plasmic-commerce-product-collection",displayName:"Product Collection",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){return{label:e.name,value:e.id}})))?r:[]},hidden:function(e,t){return!(null==t||!t.hasCategoryCtx)}},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:[]}},noLayout:"boolean"},defaultStyles:{display:"grid",gridTemplateColumns:"1fr 1fr 1fr 1fr",gridRowGap:"8px",gridColumnGap:"8px",padding:"8px",maxWidth:"100%"},importPath:"@plasmicpkgs/commerce",importName:"ProductCollection"};function le(e){var t,r=e.className,o=e.children,i=e.count,c=e.category,u=e.includeSubCategories,l=e.brand,s=e.noLayout,p=e.setControlContextData,d=e.emptyMessage,m=e.loadingMessage,f=ne(),h=f.data,v=f.isLoading,y=ae(),g=y.data,x=y.isLoading,C=N(),b=ee({categoryId:null!=(t=null==C?void 0:C.id)?t:c,brandId:l,count:i,categories:null!=h?h:[],includeSubCategories:u}),P=b.data,E=b.isLoading,k=ce();h&&g&&(null==p||p({categories:h,brands:g,features:k,hasCategoryCtx:!!C}));var L=null==P?void 0:P.products.map((function(e,t){return n.createElement(w,{product:e,key:e.id},a.repeatedElement(0===t,o))}));return[E,x,v].includes(!0)?n.isValidElement(m)?m:null:P&&0!==P.products.length?s?n.createElement(n.Fragment,null,L):n.createElement("div",{className:r},L):n.isValidElement(d)?d:null}function se(e,r){!function(){e?e.registerComponent.apply(e,arguments):t.apply(void 0,arguments)}(le,null!=r?r:ue)}var pe={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 de(e){var t=e.className,r=e.children,o=e.linkDest,i=E();return n.createElement("a",{className:t,href:function(e){var t;if(i&&e){for(var r,n=/{[^}]*}/,o=new RegExp(n,"g"),a=null!=(t=e.match(o))?t:[],c=e,u=function(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 y(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)?y(e,void 0):void 0}}(e))){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.")}(a);!(r=u()).done;){var l=r.value.slice(1,-1);if(!(l in i))return;c=c.replace(n,i[l])}return c}}(o),style:{color:"inherit",textDecoration:"inherit"}},r)}function me(e,r){!function(){e?e.registerComponent.apply(e,arguments):t.apply(void 0,arguments)}(de,null!=r?r:pe)}var fe={name:"plasmic-commerce-product-media",displayName:"Product Media",props:{mediaIndex:"number"},importPath:"@plasmicpkgs/commerce",importName:"ProductMedia"};function he(e){var t,r=e.className,o=e.mediaIndex,i=void 0===o?0:o,a=E(),c=null==a?void 0:a.images[i];return n.createElement("img",{alt:(null==a?void 0:a.name)||"Product Image",src:a?null!=(t=null==c?void 0:c.url)?t:"":"https://static1.plasmic.app/commerce/lightweight-jacket-0.png",loading:"lazy",className:r})}function ve(e,r){!function(){e?e.registerComponent.apply(e,arguments):t.apply(void 0,arguments)}(he,null!=r?r:fe)}function ye(e){var t=e.amount;return new Intl.NumberFormat(e.locale,{style:"currency",currency:e.currencyCode}).format(t)}function ge(e){var t=null!=e?e:{},n=t.amount,o=t.baseAmount,i=t.currencyCode,a=F().locale,c=r.useMemo((function(){return"number"==typeof n&&i?o?function(e){var t=e.amount,r=e.baseAmount,n=e.currencyCode,o=e.locale,i=r>t,a=new Intl.NumberFormat(o,{style:"percent"}),c=i?a.format((r-t)/r):null;return{price:ye({amount:t,currencyCode:n,locale:o}),basePrice:i?ye({amount:r,currencyCode:n,locale:o}):null,discount:c}}({amount:n,baseAmount:o,currencyCode:i,locale:a}):ye({amount:n,currencyCode:i,locale:a}):""}),[n,o,i]);return"string"==typeof c?{price:c}:c}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},Ce={name:"plasmic-commerce-product-price",displayName:"Product Price",props:{},importPath:"@plasmicpkgs/commerce",importName:"ProductPrice"};function be(e){var t,r=e.className,i=E(),a=o.useFormContext(),c=null==a?void 0:a.watch("ProductVariant",null!=(t=i.variants[0].id)?t:""),u=ge({amount:i?xe(i,c):0,currencyCode:i?i.price.currencyCode:"USD"});return n.createElement("span",{className:r},u.price)}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-product-quantity",displayName:"Product Quantity",props:{children:{type:"slot",defaultValue:[{type:"input",attrs:{value:"1"}}]}},importPath:"@plasmicpkgs/commerce",importName:"ProductQuantity"};function Ee(e){var t=e.className,r=e.children,i=o.useFormContext();return n.createElement("div",{className:t},n.createElement(o.Controller,{name:"ProductQuantity",defaultValue:1,control:null==i?void 0:i.control,render:function(e){var t=e.field;return n.isValidElement(r)?n.cloneElement(r,s({},r.props,t,{name:"ProductQuantity"})):n.createElement(n.Fragment,null)}}))}function ke(e,r){!function(){e?e.registerComponent.apply(e,arguments):t.apply(void 0,arguments)}(Ee,null!=r?r:we)}var Ne={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 Le(e){var t=e.className,r=e.field,o=E();return o?r?"description"===r?o.descriptionHtml?n.createElement("div",{className:t,dangerouslySetInnerHTML:{__html:o.descriptionHtml}}):n.createElement("div",{className:t},o.description):n.createElement("span",{className:t},o[r]):n.createElement("span",{className:t},"Unknown Product Field"):n.createElement("span",{className:t},"Fake Product Field")}function Oe(e,r){!function(){e?e.registerComponent.apply(e,arguments):t.apply(void 0,arguments)}(Le,null!=r?r:Ne)}var _e={name:"plasmic-commerce-product-variant-picker",displayName:"Product Variant Picker",props:{},importPath:"@plasmicpkgs/commerce",importName:"ProductVariantPicker"};function Fe(e){var t,r=e.className,i=E(),a=null!=(t=o.useFormContext())?t:o.useForm();return n.createElement(o.Controller,{name:"ProductVariant",control:null==a?void 0:a.control,defaultValue:null==i?void 0:i.variants[0].id,render:function(e){var t;return n.createElement("select",Object.assign({className:r},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 je(e,r){!function(){e?e.registerComponent.apply(e,arguments):t.apply(void 0,arguments)}(Fe,null!=r?r:_e)}var Ie=function(){var e=l(x.mark((function e(t){var r,n;return x.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)}}(),Me=function(e){var t;return null==(t=e.cart)?void 0:t.useCart},Se=function(e){var t,r=V(Me),n=F().cartCookie,o=null!=(t=r.fetcher)?t:Ie;return T(s({},r,{fetcher:function(e){return e.input.cartId=c.get(n),o(e)}}))(e)},Ve={name:"plasmic-commerce-cart",displayName:"Cart",props:{field:{type:"choice",options:["Size","Total Price"]},hideIfIsEmpty:{type:"boolean"}},importPath:"@plasmicpkgs/commerce",importName:"Cart"};function Te(e){var t,r,o,i,a=e.className,c=e.field,u=e.hideIfIsEmpty,l=Se().data,s=ge({amount:null!=(t=null==l?void 0:l.totalPrice)?t:0,currencyCode:null!=(r=null==l?void 0:l.currency.code)?r:"USD"}).price;return c?("Size"===c?o=null!=(i=null==l?void 0:l.lineItems.length)?i:0:"Total Price"===c&&(o=null!=s?s:0),u&&0===o?null:n.createElement("span",{className:a},o)):n.createElement("p",null,"You must set the field prop")}function Ae(e,r){!function(){e?e.registerComponent.apply(e,arguments):t.apply(void 0,arguments)}(Te,null!=r?r:Ve)}var Re={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}}]},noLayout:{type:"boolean"},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){return{label:e.name,value:e.id}})))?r:[]}}},defaultStyles:{display:"grid",gridTemplateColumns:"1fr",gridRowGap:"8px",padding:"8px",maxWidth:"100%"},importPath:"@plasmicpkgs/commerce",importName:"CategoryCollection"};function qe(e){var t=e.children,r=e.noLayout,o=e.className,i=e.loadingMessage,c=e.emptyMessage,u=e.category,l=e.setControlContextData,s=ce(),p=a.usePlasmicCanvasContext(),d=ne(),m=d.data,f=d.isLoading,h=ne({categoryId:u,topologicalSort:!u&&(null==s?void 0:s.includeSubCategories),addIsEmptyField:!!p}),v=h.data,y=h.isLoading;m&&(null==l||l({categories:m}));var g=null==v?void 0:v.find((function(e){return!e.isEmpty})),x=null==v?void 0:v.map((function(e,r){return n.createElement(k,{category:e,key:e.id},a.repeatedElement(g?e===g:0===r,t))}));return[f,y].includes(!0)?n.isValidElement(i)?i:null:v&&0!==v.length?r?n.createElement(n.Fragment,null,x):n.createElement("div",{className:o},x):n.isValidElement(c)?c:null}function Be(e,r){!function(){e?e.registerComponent.apply(e,arguments):t.apply(void 0,arguments)}(qe,null!=r?r:Re)}var Ge={name:"plasmic-commerce-category-field",displayName:"Category Field",props:{field:{type:"choice",options:["id","name","slug","path"]}},importPath:"@plasmicpkgs/commerce",importName:"CategoryField"};function De(e){var t=e.className,r=e.field,o=N();return r?n.createElement("span",{className:t},o?o[r]:"Category field placeholder"):n.createElement("span",null,"You must set the field prop")}function Qe(e,r){!function(){e?e.registerComponent.apply(e,arguments):t.apply(void 0,arguments)}(De,null!=r?r:Ge)}var He=q,Ue=function(e){var t;return null==(t=e.cart)?void 0:t.useRemoveItem},Ye=q,We=function(e){var t;return null==(t=e.cart)?void 0:t.useUpdateItem};exports.AddToCartButton=H,exports.CartComponent=Te,exports.CartType={__proto__:null},exports.CategoryCollection=qe,exports.CategoryField=De,exports.CommerceError=j,exports.CoreCommerceProvider=_,exports.FetcherError=M,exports.ProductBox=$,exports.ProductCollection=le,exports.ProductLink=de,exports.ProductMedia=he,exports.ProductPriceComponent=be,exports.ProductQuantity=Ee,exports.ProductTextField=Le,exports.ProductTypes={__proto__:null},exports.ProductVariantPicker=Fe,exports.SiteTypes={__proto__:null},exports.ValidationError=I,exports.addToCartButtonMeta=Q,exports.cartMeta=Ve,exports.categoryCollectionMeta=Re,exports.categoryFieldMeta=Ge,exports.fetcher=X,exports.getCommerceProvider=function(e){return function(t){var r=t.children,o=function(e,t){if(null==e)return{};var r,n,o={},i=Object.keys(e);for(n=0;n<i.length;n++)t.indexOf(r=i[n])>=0||(o[r]=e[r]);return o}(t,L);return n.createElement(_,{provider:s({},e,o)},r)}},exports.productBoxMeta=J,exports.productCollectionMeta=ue,exports.productLinkMeta=pe,exports.productMediaMeta=fe,exports.productPriceMeta=Ce,exports.productQuantityMeta=we,exports.productTextFieldMeta=Ne,exports.productVariantPickerMeta=_e,exports.registerAddToCartButton=U,exports.registerAll=function(e){se(e),Oe(e),Pe(e),ve(e),Ae(e),U(e),ke(e),je(e),K(e),me(e),Be(e),Qe(e)},exports.registerCart=Ae,exports.registerCategoryCollection=Be,exports.registerCategoryField=Qe,exports.registerProductBox=K,exports.registerProductCollection=se,exports.registerProductLink=me,exports.registerProductMedia=ve,exports.registerProductPrice=Pe,exports.registerProductQuantity=ke,exports.registerProductVariantPicker=je,exports.registerTextField=Oe,exports.useAddItem=D,exports.useBrands=ae,exports.useCart=Se,exports.useCategories=ne,exports.useCommerce=F,exports.useProduct=z,exports.useRemoveItem=function(e){var t=V(Ue);return A(s({fetcher:He},t))(e)},exports.useSearch=ee,exports.useUpdateItem=function(e){var t=V(We);return A(s({fetcher:Ye},t))(e)};
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"),i=e(require("swr")),a=require("@plasmicapp/host"),c=e(require("js-cookie"));function u(e,t,r,n,o,i,a){try{var c=e[i](a),u=c.value}catch(e){return void r(e)}c.done?t(u):Promise.resolve(u).then(n,o)}function l(e){return function(){var t=this,r=arguments;return new Promise((function(n,o){var i=e.apply(t,r);function a(e){u(i,n,o,a,c,"next",e)}function c(e){u(i,n,o,a,c,"throw",e)}a(void 0)}))}}function s(){return(s=Object.assign||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 p(e,t){e.prototype=Object.create(t.prototype),e.prototype.constructor=e,m(e,t)}function d(e){return(d=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function m(e,t){return(m=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function f(){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=f()?Reflect.construct:function(e,t,r){var n=[null];n.push.apply(n,t);var o=new(Function.bind.apply(e,n));return r&&m(o,r.prototype),o}).apply(null,arguments)}function v(e){var t="function"==typeof Map?new Map:void 0;return(v=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,d(this).constructor)}return r.prototype=Object.create(e.prototype,{constructor:{value:r,enumerable:!1,writable:!0,configurable:!0}}),m(r,e)})(e)}function y(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 g(e,t){return e(t={exports:{}},t.exports),t.exports}var x=g((function(e){var t=function(e){var t=Object.prototype,r=t.hasOwnProperty,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",i=n.asyncIterator||"@@asyncIterator",a=n.toStringTag||"@@toStringTag";function c(e,t,r){return Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}),e[t]}try{c({},"")}catch(e){c=function(e,t,r){return e[t]=r}}function u(e,t,r,n){var o=Object.create((t&&t.prototype instanceof p?t:p).prototype),i=new w(n||[]);return o._invoke=function(e,t,r){var n="suspendedStart";return function(o,i){if("executing"===n)throw new Error("Generator is already running");if("completed"===n){if("throw"===o)throw i;return{value:void 0,done:!0}}for(r.method=o,r.arg=i;;){var a=r.delegate;if(a){var c=C(a,r);if(c){if(c===s)continue;return c}}if("next"===r.method)r.sent=r._sent=r.arg;else if("throw"===r.method){if("suspendedStart"===n)throw n="completed",r.arg;r.dispatchException(r.arg)}else"return"===r.method&&r.abrupt("return",r.arg);n="executing";var u=l(e,t,r);if("normal"===u.type){if(n=r.done?"completed":"suspendedYield",u.arg===s)continue;return{value:u.arg,done:r.done}}"throw"===u.type&&(n="completed",r.method="throw",r.arg=u.arg)}}}(e,r,i),o}function l(e,t,r){try{return{type:"normal",arg:e.call(t,r)}}catch(e){return{type:"throw",arg:e}}}e.wrap=u;var s={};function p(){}function d(){}function m(){}var f={};f[o]=function(){return this};var h=Object.getPrototypeOf,v=h&&h(h(E([])));v&&v!==t&&r.call(v,o)&&(f=v);var y=m.prototype=p.prototype=Object.create(f);function g(e){["next","throw","return"].forEach((function(t){c(e,t,(function(e){return this._invoke(t,e)}))}))}function x(e,t){var n;this._invoke=function(o,i){function a(){return new t((function(n,a){!function n(o,i,a,c){var u=l(e[o],e,i);if("throw"!==u.type){var s=u.arg,p=s.value;return p&&"object"==typeof p&&r.call(p,"__await")?t.resolve(p.__await).then((function(e){n("next",e,a,c)}),(function(e){n("throw",e,a,c)})):t.resolve(p).then((function(e){s.value=e,a(s)}),(function(e){return n("throw",e,a,c)}))}c(u.arg)}(o,i,n,a)}))}return n=n?n.then(a,a):a()}}function C(e,t){var r=e.iterator[t.method];if(void 0===r){if(t.delegate=null,"throw"===t.method){if(e.iterator.return&&(t.method="return",t.arg=void 0,C(e,t),"throw"===t.method))return s;t.method="throw",t.arg=new TypeError("The iterator does not provide a 'throw' method")}return s}var n=l(r,e.iterator,t.arg);if("throw"===n.type)return t.method="throw",t.arg=n.arg,t.delegate=null,s;var o=n.arg;return o?o.done?(t[e.resultName]=o.value,t.next=e.nextLoc,"return"!==t.method&&(t.method="next",t.arg=void 0),t.delegate=null,s):o:(t.method="throw",t.arg=new TypeError("iterator result is not an object"),t.delegate=null,s)}function b(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 P(e){var t=e.completion||{};t.type="normal",delete t.arg,e.completion=t}function w(e){this.tryEntries=[{tryLoc:"root"}],e.forEach(b,this),this.reset(!0)}function E(e){if(e){var t=e[o];if(t)return t.call(e);if("function"==typeof e.next)return e;if(!isNaN(e.length)){var n=-1,i=function t(){for(;++n<e.length;)if(r.call(e,n))return t.value=e[n],t.done=!1,t;return t.value=void 0,t.done=!0,t};return i.next=i}}return{next:k}}function k(){return{value:void 0,done:!0}}return d.prototype=y.constructor=m,m.constructor=d,d.displayName=c(m,a,"GeneratorFunction"),e.isGeneratorFunction=function(e){var t="function"==typeof e&&e.constructor;return!!t&&(t===d||"GeneratorFunction"===(t.displayName||t.name))},e.mark=function(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,m):(e.__proto__=m,c(e,a,"GeneratorFunction")),e.prototype=Object.create(y),e},e.awrap=function(e){return{__await:e}},g(x.prototype),x.prototype[i]=function(){return this},e.AsyncIterator=x,e.async=function(t,r,n,o,i){void 0===i&&(i=Promise);var a=new x(u(t,r,n,o),i);return e.isGeneratorFunction(r)?a:a.next().then((function(e){return e.done?e.value:a.next()}))},g(y),c(y,a,"Generator"),y[o]=function(){return this},y.toString=function(){return"[object Generator]"},e.keys=function(e){var t=[];for(var r in e)t.push(r);return t.reverse(),function r(){for(;t.length;){var n=t.pop();if(n in e)return r.value=n,r.done=!1,r}return r.done=!0,r}},e.values=E,w.prototype={constructor:w,reset:function(e){if(this.prev=0,this.next=0,this.sent=this._sent=void 0,this.done=!1,this.delegate=null,this.method="next",this.arg=void 0,this.tryEntries.forEach(P),!e)for(var t in this)"t"===t.charAt(0)&&r.call(this,t)&&!isNaN(+t.slice(1))&&(this[t]=void 0)},stop:function(){this.done=!0;var e=this.tryEntries[0].completion;if("throw"===e.type)throw e.arg;return this.rval},dispatchException:function(e){if(this.done)throw e;var t=this;function n(r,n){return a.type="throw",a.arg=e,t.next=r,n&&(t.method="next",t.arg=void 0),!!n}for(var o=this.tryEntries.length-1;o>=0;--o){var i=this.tryEntries[o],a=i.completion;if("root"===i.tryLoc)return n("end");if(i.tryLoc<=this.prev){var c=r.call(i,"catchLoc"),u=r.call(i,"finallyLoc");if(c&&u){if(this.prev<i.catchLoc)return n(i.catchLoc,!0);if(this.prev<i.finallyLoc)return n(i.finallyLoc)}else if(c){if(this.prev<i.catchLoc)return n(i.catchLoc,!0)}else{if(!u)throw new Error("try statement without catch or finally");if(this.prev<i.finallyLoc)return n(i.finallyLoc)}}}},abrupt:function(e,t){for(var n=this.tryEntries.length-1;n>=0;--n){var o=this.tryEntries[n];if(o.tryLoc<=this.prev&&r.call(o,"finallyLoc")&&this.prev<o.finallyLoc){var i=o;break}}i&&("break"===e||"continue"===e)&&i.tryLoc<=t&&t<=i.finallyLoc&&(i=null);var a=i?i.completion:{};return a.type=e,a.arg=t,i?(this.method="next",this.next=i.finallyLoc,s):this.complete(a)},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),s},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),P(r),s}},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;P(r)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(e,t,r){return this.delegate={iterator:E(e),resultName:t,nextLoc:r},"next"===this.method&&(this.arg=void 0),s}},e}(e.exports);try{regeneratorRuntime=t}catch(e){Function("r","regeneratorRuntime = r")(t)}})),C={id:"123456789",name:"Product Placeholder",description:"",descriptionHtml:"\n <p>This is a <strong>placeholder</strong>.</p>\n <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>\n <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</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:"variiant1",name:"Variant Placeholder",options:[]},{id:"variant2",name:"Variant Placeholder 2",options:[]}],price:{value:0,currencyCode:"USD"},options:[]},b=n.createContext(void 0),P=n.createContext(void 0);function w(e){var t=e.product,r=e.children,i=o.useForm();return n.createElement(b.Provider,{value:t,key:t.id},n.createElement(o.FormProvider,Object.assign({},i),r))}var E=function(){var e=r.useContext(b);return null!=e?e:C};function k(e){var t=e.category;return n.createElement(P.Provider,{value:t,key:t.id},e.children)}var N=function(){return r.useContext(P)},L=["children"],O=r.createContext({});function _(e){var t=e.provider,o=e.children,i=r.useRef(t),a=r.useRef(t.fetcher),c=i.current,u=c.locale,l=c.cartCookie,s=r.useMemo((function(){return{providerRef:i,fetcherRef:a,locale:u,cartCookie:l}}),[u,l]);return n.createElement(O.Provider,{value:s},o)}function F(){return r.useContext(O)}var j=function(e){function t(t){var r,n=t.message,o=t.code,i=t.errors,a=n?s({message:n},o?{code:o}:{}):i[0];return(r=e.call(this,a.message)||this).errors=n?[a]:i,a.code&&(r.code=a.code),r}return p(t,e),t}(v(Error)),I=function(e){function t(t){var r;return(r=e.call(this,t)||this).code="validation_error",r}return p(t,e),t}(j),M=function(e){function t(t){var r;return(r=e.call(this,t)||this).status=t.status,r}return p(t,e),t}(j);function S(){var e,t=F();return null!=(e=t.providerRef.current.fetcher)?e:t.fetcherRef.current}function V(e){return e(F().providerRef.current)}function T(e){var t=S();return e.useHook({useData:function(r){var n,o,a,c,u,s,p;return o=e,a=null!=(n=null==r?void 0:r.input)?n:[],c=t,u=null==r?void 0:r.swrOptions,s=Array.isArray(a)?a:Object.entries(a),"isLoading"in(p=i((function(){var e=o.fetchOptions;return e?[e.url,e.query,e.method].concat(s.map((function(e){return e[1]}))):null}),function(){var e=l(x.mark((function e(t,r,n){var i,a,u,l=arguments;return x.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:for(e.prev=0,i=l.length,a=new Array(i>3?i-3:0),u=3;u<i;u++)a[u-3]=l[u];return e.next=4,o.fetcher({options:{url:t,query:r,method:n},input:a.reduce((function(e,t,r){return e[s[r][0]]=t,e}),{}),fetch:c});case 4:return e.abrupt("return",e.sent);case 7:throw e.prev=7,e.t0=e.catch(0),e.t0 instanceof j||console.error(e.t0),e.t0;case 11:case"end":return e.stop()}}),e,null,[[0,7]])})));return function(t,r,n){return e.apply(this,arguments)}}(),u))||Object.defineProperty(p,"isLoading",{get:function(){return void 0===p.data},enumerable:!0}),p}})}function A(e){var t=S();return e.useHook({fetch:r.useCallback((function(r){return e.fetcher({input:(void 0===r?{}:r).input,options:e.fetchOptions,fetch:t})}),[t,e.fetchOptions])})}var R=function(e){return(0,e.fetch)(e.options)},q=function(e){return(0,e.fetch)(s({},e.options,{body:e.input}))},B=q,G=function(e){var t;return null==(t=e.cart)?void 0:t.useAddItem},D=function(){var e=V(G);return A(s({fetcher:B},e)).apply(void 0,arguments)},Q={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 H(e){var t=e.children,r=E(),i=o.useFormContext(),a=D(),c=function(){var e=l(x.mark((function e(){var t,n,o,c;return x.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(n=+(null!=(t=i.getValues().ProductQuantity)?t:1),!(isNaN(n)||n<1)){e.next=3;break}throw new j({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=i.getValues().ProductVariant)?o:r.variants[0].id,e.next=7,a({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 U(e,r){!function(){e?e.registerComponent.apply(e,arguments):t.apply(void 0,arguments)}(H,null!=r?r:Q)}var Y=R,W=function(e){var t;return null==(t=e.products)?void 0:t.useProduct},z=function(e){var t=V(W);return T(s({fetcher:Y},t))(e)},J={name:"plasmic-commerce-product-box",displayName:"Product Box",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:"string",description:"Fetch a product by its slug or ID"}},importPath:"@plasmicpkgs/commerce",importName:"ProductBox"};function $(e){var t=e.className,r=e.children,o=e.noLayout,i=e.id,a=z({id:i}),c=a.data,u=a.error,l=a.isLoading;if(!i)return n.createElement("span",null,"You must set the id prop");if(u)throw new j({message:u.message,code:u.code});if(l)return n.createElement("span",null,"Loading...");if(!c)throw new Error("Product not found!");var s=n.createElement(w,{product:c},r);return o?n.createElement(n.Fragment,null,s):n.createElement("div",{className:t},s)}function K(e,r){!function(){e?e.registerComponent.apply(e,arguments):t.apply(void 0,arguments)}($,null!=r?r:J)}var X=R,Z=function(e){var t;return null==(t=e.products)?void 0:t.useSearch},ee=function(e){var t=V(Z);return T(s({fetcher:X},t))(e)},te=R,re=function(e){var t;return null==(t=e.site)?void 0:t.useCategories},ne=function(e){var t=V(re);return T(s({fetcher:te},t))(e)},oe=R,ie=function(e){var t;return null==(t=e.site)?void 0:t.useBrands},ae=function(e){var t=V(ie);return T(s({fetcher:oe},t))(e)},ce=function(){return F().providerRef.current.extraFeatures},ue={name:"plasmic-commerce-product-collection",displayName:"Product Collection",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){return{label:e.name,value:e.id}})))?r:[]},hidden:function(e,t){return!(null==t||!t.hasCategoryCtx)}},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:[]}},noLayout:"boolean"},defaultStyles:{display:"grid",gridTemplateColumns:"1fr 1fr 1fr 1fr",gridRowGap:"8px",gridColumnGap:"8px",padding:"8px",maxWidth:"100%"},importPath:"@plasmicpkgs/commerce",importName:"ProductCollection"};function le(e){var t,r=e.className,o=e.children,i=e.count,c=e.category,u=e.includeSubCategories,l=e.brand,s=e.noLayout,p=e.setControlContextData,d=e.emptyMessage,m=e.loadingMessage,f=ne(),h=f.data,v=f.isLoading,y=ae(),g=y.data,x=y.isLoading,C=N(),b=ee({categoryId:null!=(t=null==C?void 0:C.id)?t:c,brandId:l,count:i,categories:null!=h?h:[],includeSubCategories:u}),P=b.data,E=b.isLoading,k=ce();h&&g&&(null==p||p({categories:h,brands:g,features:k,hasCategoryCtx:!!C}));var L=null==P?void 0:P.products.map((function(e,t){return n.createElement(w,{product:e,key:e.id},a.repeatedElement(0===t,o))}));return[E,x,v].includes(!0)?n.isValidElement(m)?m:null:P&&0!==P.products.length?s?n.createElement(n.Fragment,null,L):n.createElement("div",{className:r},L):n.isValidElement(d)?d:null}function se(e,r){!function(){e?e.registerComponent.apply(e,arguments):t.apply(void 0,arguments)}(le,null!=r?r:ue)}var pe={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 de(e){var t=e.className,r=e.children,o=e.linkDest,i=E();return n.createElement("a",{className:t,href:function(e){var t;if(i&&e){for(var r,n=/{[^}]*}/,o=new RegExp(n,"g"),a=null!=(t=e.match(o))?t:[],c=e,u=function(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 y(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)?y(e,void 0):void 0}}(e))){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.")}(a);!(r=u()).done;){var l=r.value.slice(1,-1);if(!(l in i))return;c=c.replace(n,i[l])}return c}}(o),style:{color:"inherit",textDecoration:"inherit"}},r)}function me(e,r){!function(){e?e.registerComponent.apply(e,arguments):t.apply(void 0,arguments)}(de,null!=r?r:pe)}var fe={name:"plasmic-commerce-product-media",displayName:"Product Media",props:{mediaIndex:"number"},importPath:"@plasmicpkgs/commerce",importName:"ProductMedia"};function he(e){var t,r=e.className,o=e.mediaIndex,i=void 0===o?0:o,a=E(),c=null==a?void 0:a.images[i];return n.createElement("img",{alt:(null==a?void 0:a.name)||"Product Image",src:a?null!=(t=null==c?void 0:c.url)?t:"":"https://static1.plasmic.app/commerce/lightweight-jacket-0.png",loading:"lazy",className:r})}function ve(e,r){!function(){e?e.registerComponent.apply(e,arguments):t.apply(void 0,arguments)}(he,null!=r?r:fe)}function ye(e){var t=e.amount;return new Intl.NumberFormat(e.locale,{style:"currency",currency:e.currencyCode}).format(t)}function ge(e){var t=null!=e?e:{},n=t.amount,o=t.baseAmount,i=t.currencyCode,a=F().locale,c=r.useMemo((function(){return"number"==typeof n&&i?o?function(e){var t=e.amount,r=e.baseAmount,n=e.currencyCode,o=e.locale,i=r>t,a=new Intl.NumberFormat(o,{style:"percent"}),c=i?a.format((r-t)/r):null;return{price:ye({amount:t,currencyCode:n,locale:o}),basePrice:i?ye({amount:r,currencyCode:n,locale:o}):null,discount:c}}({amount:n,baseAmount:o,currencyCode:i,locale:a}):ye({amount:n,currencyCode:i,locale:a}):""}),[n,o,i]);return"string"==typeof c?{price:c}:c}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},Ce={name:"plasmic-commerce-product-price",displayName:"Product Price",props:{},importPath:"@plasmicpkgs/commerce",importName:"ProductPrice"};function be(e){var t,r=e.className,i=E(),a=o.useFormContext(),c=null==a?void 0:a.watch("ProductVariant",null!=(t=i.variants[0].id)?t:""),u=ge({amount:i?xe(i,c):0,currencyCode:i?i.price.currencyCode:"USD"});return n.createElement("span",{className:r},u.price)}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-product-quantity",displayName:"Product Quantity",props:{children:{type:"slot",defaultValue:[{type:"input",attrs:{value:"1"}}]}},importPath:"@plasmicpkgs/commerce",importName:"ProductQuantity"};function Ee(e){var t=e.className,r=e.children,i=o.useFormContext();return n.createElement("div",{className:t},n.createElement(o.Controller,{name:"ProductQuantity",defaultValue:1,control:null==i?void 0:i.control,render:function(e){var t=e.field;return n.isValidElement(r)?n.cloneElement(r,s({},r.props,t,{name:"ProductQuantity"})):n.createElement(n.Fragment,null)}}))}function ke(e,r){!function(){e?e.registerComponent.apply(e,arguments):t.apply(void 0,arguments)}(Ee,null!=r?r:we)}var Ne={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 Le(e){var t=e.className,r=e.field,o=E();return o?r?"description"===r?o.descriptionHtml?n.createElement("div",{className:t,dangerouslySetInnerHTML:{__html:o.descriptionHtml}}):n.createElement("div",{className:t},o.description):n.createElement("span",{className:t},o[r]):n.createElement("span",{className:t},"Unknown Product Field"):n.createElement("span",{className:t},"Fake Product Field")}function Oe(e,r){!function(){e?e.registerComponent.apply(e,arguments):t.apply(void 0,arguments)}(Le,null!=r?r:Ne)}var _e={name:"plasmic-commerce-product-variant-picker",displayName:"Product Variant Picker",props:{},importPath:"@plasmicpkgs/commerce",importName:"ProductVariantPicker"};function Fe(e){var t,r=e.className,i=E(),a=null!=(t=o.useFormContext())?t:o.useForm();return n.createElement(o.Controller,{name:"ProductVariant",control:null==a?void 0:a.control,defaultValue:null==i?void 0:i.variants[0].id,render:function(e){var t;return n.createElement("select",Object.assign({className:r},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 je(e,r){!function(){e?e.registerComponent.apply(e,arguments):t.apply(void 0,arguments)}(Fe,null!=r?r:_e)}var Ie=function(){var e=l(x.mark((function e(t){var r,n;return x.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)}}(),Me=function(e){var t;return null==(t=e.cart)?void 0:t.useCart},Se=function(e){var t,r=V(Me),n=F().cartCookie,o=null!=(t=r.fetcher)?t:Ie;return T(s({},r,{fetcher:function(e){return e.input.cartId=c.get(n),o(e)}}))(e)},Ve={name:"plasmic-commerce-cart",displayName:"Cart",props:{field:{type:"choice",options:["Size","Total Price"]},hideIfIsEmpty:{type:"boolean"}},importPath:"@plasmicpkgs/commerce",importName:"Cart"};function Te(e){var t,r,o,i,a=e.className,c=e.field,u=e.hideIfIsEmpty,l=Se().data,s=ge({amount:null!=(t=null==l?void 0:l.totalPrice)?t:0,currencyCode:null!=(r=null==l?void 0:l.currency.code)?r:"USD"}).price;return c?("Size"===c?o=null!=(i=null==l?void 0:l.lineItems.length)?i:0:"Total Price"===c&&(o=null!=s?s:0),u&&0===o?null:n.createElement("span",{className:a},o)):n.createElement("p",null,"You must set the field prop")}function Ae(e,r){!function(){e?e.registerComponent.apply(e,arguments):t.apply(void 0,arguments)}(Te,null!=r?r:Ve)}var Re={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}}]},noLayout:{type:"boolean"},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){return{label:e.name,value:e.id}})))?r:[]}}},defaultStyles:{display:"grid",gridTemplateColumns:"1fr",gridRowGap:"8px",padding:"8px",maxWidth:"100%"},importPath:"@plasmicpkgs/commerce",importName:"CategoryCollection"};function qe(e){var t=e.children,r=e.noLayout,o=e.className,i=e.loadingMessage,c=e.emptyMessage,u=e.category,l=e.setControlContextData,s=ce(),p=n.useContext(a.PlasmicCanvasContext),d=ne(),m=d.data,f=d.isLoading,h=ne({categoryId:u,topologicalSort:!u&&(null==s?void 0:s.includeSubCategories),addIsEmptyField:!!p}),v=h.data,y=h.isLoading;m&&(null==l||l({categories:m}));var g=null==v?void 0:v.find((function(e){return!e.isEmpty})),x=null==v?void 0:v.map((function(e,r){return n.createElement(k,{category:e,key:e.id},a.repeatedElement(g?e===g:0===r,t))}));return[f,y].includes(!0)?n.isValidElement(i)?i:null:v&&0!==v.length?r?n.createElement(n.Fragment,null,x):n.createElement("div",{className:o},x):n.isValidElement(c)?c:null}function Be(e,r){!function(){e?e.registerComponent.apply(e,arguments):t.apply(void 0,arguments)}(qe,null!=r?r:Re)}var Ge={name:"plasmic-commerce-category-field",displayName:"Category Field",props:{field:{type:"choice",options:["id","name","slug","path"]}},importPath:"@plasmicpkgs/commerce",importName:"CategoryField"};function De(e){var t=e.className,r=e.field,o=N();return r?n.createElement("span",{className:t},o?o[r]:"Category field placeholder"):n.createElement("span",null,"You must set the field prop")}function Qe(e,r){!function(){e?e.registerComponent.apply(e,arguments):t.apply(void 0,arguments)}(De,null!=r?r:Ge)}var He=q,Ue=function(e){var t;return null==(t=e.cart)?void 0:t.useRemoveItem},Ye=q,We=function(e){var t;return null==(t=e.cart)?void 0:t.useUpdateItem};exports.AddToCartButton=H,exports.CartComponent=Te,exports.CartType={__proto__:null},exports.CategoryCollection=qe,exports.CategoryField=De,exports.CommerceError=j,exports.CoreCommerceProvider=_,exports.FetcherError=M,exports.ProductBox=$,exports.ProductCollection=le,exports.ProductLink=de,exports.ProductMedia=he,exports.ProductPriceComponent=be,exports.ProductQuantity=Ee,exports.ProductTextField=Le,exports.ProductTypes={__proto__:null},exports.ProductVariantPicker=Fe,exports.SiteTypes={__proto__:null},exports.ValidationError=I,exports.addToCartButtonMeta=Q,exports.cartMeta=Ve,exports.categoryCollectionMeta=Re,exports.categoryFieldMeta=Ge,exports.fetcher=X,exports.getCommerceProvider=function(e){return function(t){var r=t.children,o=function(e,t){if(null==e)return{};var r,n,o={},i=Object.keys(e);for(n=0;n<i.length;n++)t.indexOf(r=i[n])>=0||(o[r]=e[r]);return o}(t,L);return n.createElement(_,{provider:s({},e,o)},r)}},exports.productBoxMeta=J,exports.productCollectionMeta=ue,exports.productLinkMeta=pe,exports.productMediaMeta=fe,exports.productPriceMeta=Ce,exports.productQuantityMeta=we,exports.productTextFieldMeta=Ne,exports.productVariantPickerMeta=_e,exports.registerAddToCartButton=U,exports.registerAll=function(e){se(e),Oe(e),Pe(e),ve(e),Ae(e),U(e),ke(e),je(e),K(e),me(e),Be(e),Qe(e)},exports.registerCart=Ae,exports.registerCategoryCollection=Be,exports.registerCategoryField=Qe,exports.registerProductBox=K,exports.registerProductCollection=se,exports.registerProductLink=me,exports.registerProductMedia=ve,exports.registerProductPrice=Pe,exports.registerProductQuantity=ke,exports.registerProductVariantPicker=je,exports.registerTextField=Oe,exports.useAddItem=D,exports.useBrands=ae,exports.useCart=Se,exports.useCategories=ne,exports.useCommerce=F,exports.useProduct=z,exports.useRemoveItem=function(e){var t=V(Ue);return A(s({fetcher:He},t))(e)},exports.useSearch=ee,exports.useUpdateItem=function(e){var t=V(We);return A(s({fetcher:Ye},t))(e)};
2
2
  //# sourceMappingURL=commerce.cjs.production.min.js.map