@plasmicpkgs/commerce 0.0.6 → 0.0.7
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.
- package/dist/commerce.cjs.development.js +294 -71
- package/dist/commerce.cjs.development.js.map +1 -1
- package/dist/commerce.cjs.production.min.js +1 -1
- package/dist/commerce.cjs.production.min.js.map +1 -1
- package/dist/commerce.d.ts +1 -0
- package/dist/commerce.esm.js +263 -71
- package/dist/commerce.esm.js.map +1 -1
- package/dist/index.d.ts +12 -0
- package/dist/product/use-product.d.ts +5 -0
- package/dist/registerAddToCartButton.d.ts +1 -0
- package/dist/registerCart.d.ts +10 -0
- package/dist/registerProductBox.d.ts +13 -0
- package/dist/registerProductCollection.d.ts +1 -0
- package/dist/registerProductLink.d.ts +12 -0
- package/dist/registerProductPrice.d.ts +1 -1
- package/dist/types/product.d.ts +10 -0
- package/package.json +2 -2
- package/dist/registerUseCart.d.ts +0 -9
|
@@ -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,d(e,t)}function f(e){return(f=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function d(e,t){return(d=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function m(){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 v(e,t,r){return(v=m()?Reflect.construct:function(e,t,r){var n=[null];n.push.apply(n,t);var o=new(Function.bind.apply(e,n));return r&&d(o,r.prototype),o}).apply(null,arguments)}function h(e){var t="function"==typeof Map?new Map:void 0;return(h=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 v(e,arguments,f(this).constructor)}return r.prototype=Object.create(e.prototype,{constructor:{value:r,enumerable:!1,writable:!0,configurable:!0}}),d(r,e)})(e)}function y(e,t){return e(t={exports:{}},t.exports),t.exports}var g=y((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 C(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=w(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 f(){}function d(){}var m={};m[o]=function(){return this};var v=Object.getPrototypeOf,h=v&&v(v(E([])));h&&h!==t&&r.call(h,o)&&(m=h);var y=d.prototype=p.prototype=Object.create(m);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 w(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,w(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 C(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:N}}function N(){return{value:void 0,done:!0}}return f.prototype=y.constructor=d,d.constructor=f,f.displayName=c(d,a,"GeneratorFunction"),e.isGeneratorFunction=function(e){var t="function"==typeof e&&e.constructor;return!!t&&(t===f||"GeneratorFunction"===(t.displayName||t.name))},e.mark=function(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,d):(e.__proto__=d,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,C.prototype={constructor:C,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)}})),x=n.createContext(void 0);function w(e){var t=e.product,r=e.children,i=o.useForm();return n.createElement(x.Provider,{value:t,key:t.id},n.createElement(o.FormProvider,Object.assign({},i),r))}function b(){return r.useContext(x)}var P=["children"],C=r.createContext({});function E(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(C.Provider,{value:s},o)}function N(){return r.useContext(C)}var _=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}(h(Error)),k=function(e){function t(t){var r;return(r=e.call(this,t)||this).code="validation_error",r}return p(t,e),t}(_),O=function(e){function t(t){var r;return(r=e.call(this,t)||this).status=t.status,r}return p(t,e),t}(_);function L(){var e,t=N();return null!=(e=t.providerRef.current.fetcher)?e:t.fetcherRef.current}function j(e){return e(N().providerRef.current)}function F(e){var t=L();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(g.mark((function e(t,r,n){var i,a,u,l=arguments;return g.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 _||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 I(e){var t=L();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 T=function(e){return(0,e.fetch)(e.options)},S=function(e){return(0,e.fetch)(s({},e.options,{body:e.input}))},R=S,V=function(e){var t;return null==(t=e.cart)?void 0:t.useAddItem},A=function(){var e=j(V);return I(s({fetcher:R},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:"commerce-providers/commerce",importName:"AddToCartButton"};function G(e){var t=e.children,r=b(),i=o.useFormContext(),a=A(),c=function(){var e=l(g.mark((function e(){var t,n,o;return g.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 _({message:"The item quantity has to be a valid integer greater than 0"});case 3:if(!r){e.next=7;break}return o=i.getValues().ProductVariant,e.next=7,a({productId:r.id,variantId:o,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}var M=T,U=function(e){var t;return null==(t=e.products)?void 0:t.useSearch},B=function(e){var t=j(U);return F(s({fetcher:M},t))(e)},H={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}}]},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:[]}},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:"commerce-providers/commerce",importName:"ProductCollection"};function Q(e){var t=e.className,r=e.children,o=e.noLayout,i=e.setControlContextData,c=B({categoryId:e.category,brandId:e.brand,count:e.count}).data,u=pe({}).data,l=me({}).data;u&&l&&(null==i||i({categories:u,brands:l}));var s=null==c?void 0:c.products.map((function(e,t){return n.createElement(w,{product:e,key:e.id},a.repeatedElement(0===t,r))}));return o?n.createElement(n.Fragment,null,s):n.createElement("div",{className:t},s)}var D={name:"plasmic-commerce-product-media",displayName:"Product Media",props:{mediaIndex:"number"},importPath:"commerce-providers/commerce",importName:"ProductMedia"};function z(e){var t,r=e.className,o=e.mediaIndex,i=void 0===o?0:o,a=b(),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 Y(e){var t=e.amount;return new Intl.NumberFormat(e.locale,{style:"currency",currency:e.currencyCode}).format(t)}function W(e){var t=null!=e?e:{},n=t.amount,o=t.baseAmount,i=t.currencyCode,a=N().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:Y({amount:t,currencyCode:n,locale:o}),basePrice:i?Y({amount:r,currencyCode:n,locale:o}):null,discount:c}}({amount:n,baseAmount:o,currencyCode:i,locale:a}):Y({amount:n,currencyCode:i,locale:a}):""}),[n,o,i]);return"string"==typeof c?{price:c}:c}var J=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},K={name:"plasmic-commerce-product-price",displayName:"Product Price",props:{},importPath:"commerce-providers/commerce",importName:"ProductPrice"};function X(e){var t=e.className,r=b(),i=o.useFormContext();if(!r)throw new Error("This component must be within a product context.");var a=i.watch("ProductVariant",null==r?void 0:r.variants[0].id),c=W({amount:r?J(r,a):0,currencyCode:r?r.price.currencyCode:"USD"});return n.createElement("span",{className:t},c.price)}var Z={name:"plasmic-commerce-product-quantity",displayName:"Product Quantity",props:{children:{type:"slot",defaultValue:[{type:"input",attrs:{value:"1"}}]}},importPath:"commerce-providers/commerce",importName:"ProductQuantity"};function $(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)}}))}var ee={name:"plasmic-commerce-product-text-field",displayName:"Product Text Field",props:{field:{type:"choice",options:["id","name","description","sku","slug","path"]}},importPath:"commerce-providers/commerce",importName:"ProductTextField"};function te(e){var t=e.className,r=e.field,o=b();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")}var re={name:"plasmic-commerce-product-variant-picker",displayName:"Product Variant Picker",props:{},importPath:"commerce-providers/commerce",importName:"ProductVariantPicker"};function ne(e){var t=e.className,r=b(),i=o.useFormContext();return n.createElement(o.Controller,{name:"ProductVariant",control:null==i?void 0:i.control,defaultValue:null==r?void 0:r.variants[0].id,render:function(e){var o;return n.createElement("select",Object.assign({className:t},e.field),null!=(o=null==r?void 0:r.variants.map((function(e){return n.createElement("option",{value:e.id},e.name)})))?o:n.createElement("option",null,"Fake Product Variant"))}})}var oe=function(){var e=l(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)}}(),ie=function(e){var t;return null==(t=e.cart)?void 0:t.useCart},ae=function(e){var t,r=j(ie),n=N().cartCookie,o=null!=(t=r.fetcher)?t:oe;return F(s({},r,{fetcher:function(e){return e.input.cartId=c.get(n),o(e)}}))(e)},ce={name:"plasmic-commerce-use-cart",displayName:"Use Cart",props:{field:{type:"choice",options:["Size","Total Price"]}},importPath:"commerce-providers/commerce",importName:"UseCart"};function ue(e){var t,r,o,i,a=e.className,c=e.field,u=ae().data,l=W({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!=(i=null==u?void 0:u.lineItems.length)?i:0):"Total Price"===c&&(o=""+l),n.createElement("span",{className:a},o)):n.createElement("p",null,"You must set the field prop")}var le=T,se=function(e){var t;return null==(t=e.site)?void 0:t.useCategories},pe=function(e){var t=j(se);return F(s({fetcher:le},t))(e)},fe=T,de=function(e){var t;return null==(t=e.site)?void 0:t.useBrands},me=function(e){var t=j(de);return F(s({fetcher:fe},t))(e)},ve=S,he=function(e){var t;return null==(t=e.cart)?void 0:t.useRemoveItem},ye=S,ge=function(e){var t;return null==(t=e.cart)?void 0:t.useUpdateItem};exports.CartType={__proto__:null},exports.CommerceError=_,exports.CoreCommerceProvider=E,exports.FetcherError=O,exports.ProductTypes={__proto__:null},exports.SiteTypes={__proto__:null},exports.ValidationError=k,exports.fetcher=M,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,P);return n.createElement(E,{provider:s({},e,o)},r)}},exports.registerAll=function(e){!function(e,r){!function(){e?e.registerComponent.apply(e,arguments):t.apply(void 0,arguments)}(Q,H)}(e),function(e,r){!function(){e?e.registerComponent.apply(e,arguments):t.apply(void 0,arguments)}(te,ee)}(e),function(e,r){!function(){e?e.registerComponent.apply(e,arguments):t.apply(void 0,arguments)}(X,K)}(e),function(e,r){!function(){e?e.registerComponent.apply(e,arguments):t.apply(void 0,arguments)}(z,D)}(e),function(e,r){!function(){e?e.registerComponent.apply(e,arguments):t.apply(void 0,arguments)}(ue,ce)}(e),function(e,r){!function(){e?e.registerComponent.apply(e,arguments):t.apply(void 0,arguments)}(G,q)}(e),function(e,r){!function(){e?e.registerComponent.apply(e,arguments):t.apply(void 0,arguments)}($,Z)}(e),function(e,r){!function(){e?e.registerComponent.apply(e,arguments):t.apply(void 0,arguments)}(ne,re)}(e)},exports.useAddItem=A,exports.useBrands=me,exports.useCart=ae,exports.useCategories=pe,exports.useCommerce=N,exports.useRemoveItem=function(e){var t=j(he);return I(s({fetcher:ve},t))(e)},exports.useSearch=B,exports.useUpdateItem=function(e){var t=j(ge);return I(s({fetcher:ye},t))(e)},exports.x=function(){return 2};
|
|
1
|
+
"use strict";function t(t){return t&&"object"==typeof t&&"default"in t?t.default:t}Object.defineProperty(exports,"__esModule",{value:!0});var e=t(require("@plasmicapp/host/registerComponent")),r=require("react"),n=t(r),o=require("react-hook-form"),i=t(require("swr")),a=require("@plasmicapp/host"),c=t(require("js-cookie"));function u(t,e,r,n,o,i,a){try{var c=t[i](a),u=c.value}catch(t){return void r(t)}c.done?e(u):Promise.resolve(u).then(n,o)}function l(t){return function(){var e=this,r=arguments;return new Promise((function(n,o){var i=t.apply(e,r);function a(t){u(i,n,o,a,c,"next",t)}function c(t){u(i,n,o,a,c,"throw",t)}a(void 0)}))}}function s(){return(s=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var r=arguments[e];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(t[n]=r[n])}return t}).apply(this,arguments)}function p(t,e){t.prototype=Object.create(e.prototype),t.prototype.constructor=t,f(t,e)}function d(t){return(d=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}function f(t,e){return(f=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}function m(){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(t){return!1}}function h(t,e,r){return(h=m()?Reflect.construct:function(t,e,r){var n=[null];n.push.apply(n,e);var o=new(Function.bind.apply(t,n));return r&&f(o,r.prototype),o}).apply(null,arguments)}function v(t){var e="function"==typeof Map?new Map:void 0;return(v=function(t){if(null===t||!function(t){return-1!==Function.toString.call(t).indexOf("[native code]")}(t))return t;if("function"!=typeof t)throw new TypeError("Super expression must either be null or a function");if(void 0!==e){if(e.has(t))return e.get(t);e.set(t,r)}function r(){return h(t,arguments,d(this).constructor)}return r.prototype=Object.create(t.prototype,{constructor:{value:r,enumerable:!1,writable:!0,configurable:!0}}),f(r,t)})(t)}function y(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=new Array(e);r<e;r++)n[r]=t[r];return n}function g(t,e){return t(e={exports:{}},e.exports),e.exports}var x=g((function(t){var e=function(t){var e=Object.prototype,r=e.hasOwnProperty,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",i=n.asyncIterator||"@@asyncIterator",a=n.toStringTag||"@@toStringTag";function c(t,e,r){return Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{c({},"")}catch(t){c=function(t,e,r){return t[e]=r}}function u(t,e,r,n){var o=Object.create((e&&e.prototype instanceof p?e:p).prototype),i=new C(n||[]);return o._invoke=function(t,e,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=P(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(t,e,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)}}}(t,r,i),o}function l(t,e,r){try{return{type:"normal",arg:t.call(e,r)}}catch(t){return{type:"throw",arg:t}}}t.wrap=u;var s={};function p(){}function d(){}function f(){}var m={};m[o]=function(){return this};var h=Object.getPrototypeOf,v=h&&h(h(E([])));v&&v!==e&&r.call(v,o)&&(m=v);var y=f.prototype=p.prototype=Object.create(m);function g(t){["next","throw","return"].forEach((function(e){c(t,e,(function(t){return this._invoke(e,t)}))}))}function x(t,e){var n;this._invoke=function(o,i){function a(){return new e((function(n,a){!function n(o,i,a,c){var u=l(t[o],t,i);if("throw"!==u.type){var s=u.arg,p=s.value;return p&&"object"==typeof p&&r.call(p,"__await")?e.resolve(p.__await).then((function(t){n("next",t,a,c)}),(function(t){n("throw",t,a,c)})):e.resolve(p).then((function(t){s.value=t,a(s)}),(function(t){return n("throw",t,a,c)}))}c(u.arg)}(o,i,n,a)}))}return n=n?n.then(a,a):a()}}function P(t,e){var r=t.iterator[e.method];if(void 0===r){if(e.delegate=null,"throw"===e.method){if(t.iterator.return&&(e.method="return",e.arg=void 0,P(t,e),"throw"===e.method))return s;e.method="throw",e.arg=new TypeError("The iterator does not provide a 'throw' method")}return s}var n=l(r,t.iterator,e.arg);if("throw"===n.type)return e.method="throw",e.arg=n.arg,e.delegate=null,s;var o=n.arg;return o?o.done?(e[t.resultName]=o.value,e.next=t.nextLoc,"return"!==e.method&&(e.method="next",e.arg=void 0),e.delegate=null,s):o:(e.method="throw",e.arg=new TypeError("iterator result is not an object"),e.delegate=null,s)}function b(t){var e={tryLoc:t[0]};1 in t&&(e.catchLoc=t[1]),2 in t&&(e.finallyLoc=t[2],e.afterLoc=t[3]),this.tryEntries.push(e)}function w(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function C(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(b,this),this.reset(!0)}function E(t){if(t){var e=t[o];if(e)return e.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var n=-1,i=function e(){for(;++n<t.length;)if(r.call(t,n))return e.value=t[n],e.done=!1,e;return e.value=void 0,e.done=!0,e};return i.next=i}}return{next:k}}function k(){return{value:void 0,done:!0}}return d.prototype=y.constructor=f,f.constructor=d,d.displayName=c(f,a,"GeneratorFunction"),t.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===d||"GeneratorFunction"===(e.displayName||e.name))},t.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,f):(t.__proto__=f,c(t,a,"GeneratorFunction")),t.prototype=Object.create(y),t},t.awrap=function(t){return{__await:t}},g(x.prototype),x.prototype[i]=function(){return this},t.AsyncIterator=x,t.async=function(e,r,n,o,i){void 0===i&&(i=Promise);var a=new x(u(e,r,n,o),i);return t.isGeneratorFunction(r)?a:a.next().then((function(t){return t.done?t.value:a.next()}))},g(y),c(y,a,"Generator"),y[o]=function(){return this},y.toString=function(){return"[object Generator]"},t.keys=function(t){var e=[];for(var r in t)e.push(r);return e.reverse(),function r(){for(;e.length;){var n=e.pop();if(n in t)return r.value=n,r.done=!1,r}return r.done=!0,r}},t.values=E,C.prototype={constructor:C,reset:function(t){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(w),!t)for(var e in this)"t"===e.charAt(0)&&r.call(this,e)&&!isNaN(+e.slice(1))&&(this[e]=void 0)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(t){if(this.done)throw t;var e=this;function n(r,n){return a.type="throw",a.arg=t,e.next=r,n&&(e.method="next",e.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(t,e){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"===t||"continue"===t)&&i.tryLoc<=e&&e<=i.finallyLoc&&(i=null);var a=i?i.completion:{};return a.type=t,a.arg=e,i?(this.method="next",this.next=i.finallyLoc,s):this.complete(a)},complete:function(t,e){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&e&&(this.next=e),s},finish:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.finallyLoc===t)return this.complete(r.completion,r.afterLoc),w(r),s}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.tryLoc===t){var n=r.completion;if("throw"===n.type){var o=n.arg;w(r)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(t,e,r){return this.delegate={iterator:E(t),resultName:e,nextLoc:r},"next"===this.method&&(this.arg=void 0),s}},t}(t.exports);try{regeneratorRuntime=e}catch(t){Function("r","regeneratorRuntime = r")(e)}})),P=n.createContext(void 0);function b(t){var e=t.product,r=t.children,i=o.useForm();return n.createElement(P.Provider,{value:e,key:e.id},n.createElement(o.FormProvider,Object.assign({},i),r))}function w(){return r.useContext(P)}var C=["children"],E=r.createContext({});function k(t){var e=t.provider,o=t.children,i=r.useRef(e),a=r.useRef(e.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(E.Provider,{value:s},o)}function N(){return r.useContext(E)}var L=function(t){function e(e){var r,n=e.message,o=e.code,i=e.errors,a=n?s({message:n},o?{code:o}:{}):i[0];return(r=t.call(this,a.message)||this).errors=n?[a]:i,a.code&&(r.code=a.code),r}return p(e,t),e}(v(Error)),O=function(t){function e(e){var r;return(r=t.call(this,e)||this).code="validation_error",r}return p(e,t),e}(L),_=function(t){function e(e){var r;return(r=t.call(this,e)||this).status=e.status,r}return p(e,t),e}(L);function j(){var t,e=N();return null!=(t=e.providerRef.current.fetcher)?t:e.fetcherRef.current}function F(t){return t(N().providerRef.current)}function I(t){var e=j();return t.useHook({useData:function(r){var n,o,a,c,u,s,p;return o=t,a=null!=(n=null==r?void 0:r.input)?n:[],c=e,u=null==r?void 0:r.swrOptions,s=Array.isArray(a)?a:Object.entries(a),"isLoading"in(p=i((function(){var t=o.fetchOptions;return t?[t.url,t.query,t.method].concat(s.map((function(t){return t[1]}))):null}),function(){var t=l(x.mark((function t(e,r,n){var i,a,u,l=arguments;return x.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:for(t.prev=0,i=l.length,a=new Array(i>3?i-3:0),u=3;u<i;u++)a[u-3]=l[u];return t.next=4,o.fetcher({options:{url:e,query:r,method:n},input:a.reduce((function(t,e,r){return t[s[r][0]]=e,t}),{}),fetch:c});case 4:return t.abrupt("return",t.sent);case 7:throw t.prev=7,t.t0=t.catch(0),t.t0 instanceof L||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)}}(),u))||Object.defineProperty(p,"isLoading",{get:function(){return void 0===p.data},enumerable:!0}),p}})}function T(t){var e=j();return t.useHook({fetch:r.useCallback((function(r){return t.fetcher({input:(void 0===r?{}:r).input,options:t.fetchOptions,fetch:e})}),[e,t.fetchOptions])})}var S=function(t){return(0,t.fetch)(t.options)},A=function(t){return(0,t.fetch)(s({},t.options,{body:t.input}))},M=A,V=function(t){var e;return null==(e=t.cart)?void 0:e.useAddItem},R=function(){var t=F(V);return T(s({fetcher:M},t)).apply(void 0,arguments)},B={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 q(t){var e=t.children,r=w(),i=o.useFormContext(),a=R(),c=function(){var t=l(x.mark((function t(){var e,n,o;return x.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(n=null!=(e=+i.getValues().ProductQuantity)?e:1,!(isNaN(n)||n<1)){t.next=3;break}throw new L({message:"The item quantity has to be a valid integer greater than 0"});case 3:if(!r){t.next=7;break}return o=i.getValues().ProductVariant,t.next=7,a({productId:r.id,variantId:o,quantity:n});case 7:case"end":return t.stop()}}),t)})));return function(){return t.apply(this,arguments)}}();return n.isValidElement(e)?n.cloneElement(e,{onClick:function(t){e.props.onClick&&"function"==typeof e.props.onClick&&e.props.onClick(t),c()}}):null}function G(t,r){!function(){t?t.registerComponent.apply(t,arguments):e.apply(void 0,arguments)}(q,null!=r?r:B)}var D=S,Q=function(t){var e;return null==(e=t.products)?void 0:e.useProduct},H=function(t){var e=F(Q);return I(s({fetcher:D},e))(t)},U={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 Y(t){var e=t.className,r=t.children,o=t.noLayout,i=t.id,a=H({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 L({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(b,{product:c},r);return o?n.createElement(n.Fragment,null,s):n.createElement("div",{className:e},s)}function z(t,r){!function(){t?t.registerComponent.apply(t,arguments):e.apply(void 0,arguments)}(Y,null!=r?r:U)}var W=S,$=function(t){var e;return null==(e=t.products)?void 0:e.useSearch},J=function(t){var e=F($);return I(s({fetcher:W},e))(t)},K=S,X=function(t){var e;return null==(e=t.site)?void 0:e.useCategories},Z=function(t){var e=F(X);return I(s({fetcher:K},e))(t)},tt=S,et=function(t){var e;return null==(e=t.site)?void 0:e.useBrands},rt=function(t){var e=F(et);return I(s({fetcher:tt},e))(t)},nt={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}}]},count:"number",category:{type:"choice",options:function(t,e){var r;return null!=(r=null==e?void 0:e.categories.map((function(t){return{label:t.name,value:t.id}})))?r:[]}},brand:{type:"choice",options:function(t,e){var r;return null!=(r=null==e?void 0:e.brands.map((function(t){return{label:t.name,value:t.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 ot(t){var e=t.className,r=t.children,o=t.noLayout,i=t.setControlContextData,c=J({categoryId:t.category,brandId:t.brand,count:t.count}).data,u=Z().data,l=rt().data;u&&l&&(null==i||i({categories:u,brands:l}));var s=null==c?void 0:c.products.map((function(t,e){return n.createElement(b,{product:t,key:t.id},a.repeatedElement(0===e,r))}));return o?n.createElement(n.Fragment,null,s):n.createElement("div",{className:e},s)}function it(t,r){!function(){t?t.registerComponent.apply(t,arguments):e.apply(void 0,arguments)}(ot,null!=r?r:nt)}var at={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 ct(t){var e=t.className,r=t.children,o=t.linkDest,i=w();return n.createElement("a",{className:e,href:function(t){var e;if(i&&t){for(var r,n=/{[^}]*}/,o=new RegExp(n,"g"),a=null!=(e=t.match(o))?e:[],c=t,u=function(t,e){var r="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(r)return(r=r.call(t)).next.bind(r);if(Array.isArray(t)||(r=function(t,e){if(t){if("string"==typeof t)return y(t,void 0);var r=Object.prototype.toString.call(t).slice(8,-1);return"Object"===r&&t.constructor&&(r=t.constructor.name),"Map"===r||"Set"===r?Array.from(t):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?y(t,void 0):void 0}}(t))){r&&(t=r);var n=0;return function(){return n>=t.length?{done:!0}:{done:!1,value:t[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 ut(t,r){!function(){t?t.registerComponent.apply(t,arguments):e.apply(void 0,arguments)}(ct,null!=r?r:at)}var lt={name:"plasmic-commerce-product-media",displayName:"Product Media",props:{mediaIndex:"number"},importPath:"@plasmicpkgs/commerce",importName:"ProductMedia"};function st(t){var e,r=t.className,o=t.mediaIndex,i=void 0===o?0:o,a=w(),c=null==a?void 0:a.images[i];return n.createElement("img",{alt:(null==a?void 0:a.name)||"Product Image",src:a?null!=(e=null==c?void 0:c.url)?e:"":"https://static1.plasmic.app/commerce/lightweight-jacket-0.png",loading:"lazy",className:r})}function pt(t,r){!function(){t?t.registerComponent.apply(t,arguments):e.apply(void 0,arguments)}(st,null!=r?r:lt)}function dt(t){var e=t.amount;return new Intl.NumberFormat(t.locale,{style:"currency",currency:t.currencyCode}).format(e)}function ft(t){var e=null!=t?t:{},n=e.amount,o=e.baseAmount,i=e.currencyCode,a=N().locale,c=r.useMemo((function(){return"number"==typeof n&&i?o?function(t){var e=t.amount,r=t.baseAmount,n=t.currencyCode,o=t.locale,i=r>e,a=new Intl.NumberFormat(o,{style:"percent"}),c=i?a.format((r-e)/r):null;return{price:dt({amount:e,currencyCode:n,locale:o}),basePrice:i?dt({amount:r,currencyCode:n,locale:o}):null,discount:c}}({amount:n,baseAmount:o,currencyCode:i,locale:a}):dt({amount:n,currencyCode:i,locale:a}):""}),[n,o,i]);return"string"==typeof c?{price:c}:c}var mt=function(t,e){var r,n;return null!=(r=null==(n=t.variants.find((function(t){return t.id===e})))?void 0:n.price)?r:t.price.value},ht={name:"plasmic-commerce-product-price",displayName:"Product Price",props:{},importPath:"@plasmicpkgs/commerce",importName:"ProductPrice"};function vt(t){var e=t.className,r=w(),i=o.useFormContext();if(!r)throw new Error("This component must be within a product context.");var a=i.watch("ProductVariant",null==r?void 0:r.variants[0].id),c=ft({amount:r?mt(r,a):0,currencyCode:r?r.price.currencyCode:"USD"});return n.createElement("span",{className:e},c.price)}function yt(t,r){!function(){t?t.registerComponent.apply(t,arguments):e.apply(void 0,arguments)}(vt,null!=r?r:ht)}var gt={name:"plasmic-commerce-product-quantity",displayName:"Product Quantity",props:{children:{type:"slot",defaultValue:[{type:"input",attrs:{value:"1"}}]}},importPath:"@plasmicpkgs/commerce",importName:"ProductQuantity"};function xt(t){var e=t.className,r=t.children,i=o.useFormContext();return n.createElement("div",{className:e},n.createElement(o.Controller,{name:"ProductQuantity",defaultValue:1,control:null==i?void 0:i.control,render:function(t){var e=t.field;return n.isValidElement(r)?n.cloneElement(r,s({},r.props,e,{name:"ProductQuantity"})):n.createElement(n.Fragment,null)}}))}function Pt(t,r){!function(){t?t.registerComponent.apply(t,arguments):e.apply(void 0,arguments)}(xt,null!=r?r:gt)}var bt={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 wt(t){var e=t.className,r=t.field,o=w();return o?r?"description"===r?o.descriptionHtml?n.createElement("div",{className:e,dangerouslySetInnerHTML:{__html:o.descriptionHtml}}):n.createElement("div",{className:e},o.description):n.createElement("span",{className:e},o[r]):n.createElement("span",{className:e},"Unknown Product Field"):n.createElement("span",{className:e},"Fake Product Field")}function Ct(t,r){!function(){t?t.registerComponent.apply(t,arguments):e.apply(void 0,arguments)}(wt,null!=r?r:bt)}var Et={name:"plasmic-commerce-product-variant-picker",displayName:"Product Variant Picker",props:{},importPath:"@plasmicpkgs/commerce",importName:"ProductVariantPicker"};function kt(t){var e=t.className,r=w(),i=o.useFormContext();return n.createElement(o.Controller,{name:"ProductVariant",control:null==i?void 0:i.control,defaultValue:null==r?void 0:r.variants[0].id,render:function(t){var o;return n.createElement("select",Object.assign({className:e},t.field),null!=(o=null==r?void 0:r.variants.map((function(t){return n.createElement("option",{value:t.id},t.name)})))?o:n.createElement("option",null,"Fake Product Variant"))}})}function Nt(t,r){!function(){t?t.registerComponent.apply(t,arguments):e.apply(void 0,arguments)}(kt,null!=r?r:Et)}var Lt=function(){var t=l(x.mark((function t(e){var r,n;return x.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(r=e.options,n=e.fetch,!e.input.cartId){t.next=7;break}return t.next=4,n(r);case 4:t.t0=t.sent,t.next=8;break;case 7:t.t0=null;case 8:return t.abrupt("return",t.t0);case 9:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}(),Ot=function(t){var e;return null==(e=t.cart)?void 0:e.useCart},_t=function(t){var e,r=F(Ot),n=N().cartCookie,o=null!=(e=r.fetcher)?e:Lt;return I(s({},r,{fetcher:function(t){return t.input.cartId=c.get(n),o(t)}}))(t)},jt={name:"plasmic-commerce-cart",displayName:"Cart",props:{field:{type:"choice",options:["Size","Total Price"]}},importPath:"@plasmicpkgs/commerce",importName:"Cart"};function Ft(t){var e,r,o,i,a=t.className,c=t.field,u=_t().data,l=ft({amount:null!=(e=null==u?void 0:u.totalPrice)?e:0,currencyCode:null!=(r=null==u?void 0:u.currency.code)?r:"USD"}).price;return c?("Size"===c?o=""+(null!=(i=null==u?void 0:u.lineItems.length)?i:0):"Total Price"===c&&(o=""+l),n.createElement("span",{className:a},o)):n.createElement("p",null,"You must set the field prop")}function It(t,r){!function(){t?t.registerComponent.apply(t,arguments):e.apply(void 0,arguments)}(Ft,null!=r?r:jt)}var Tt=A,St=function(t){var e;return null==(e=t.cart)?void 0:e.useRemoveItem},At=A,Mt=function(t){var e;return null==(e=t.cart)?void 0:e.useUpdateItem};exports.AddToCartButton=q,exports.CartComponent=Ft,exports.CartType={__proto__:null},exports.CommerceError=L,exports.CoreCommerceProvider=k,exports.FetcherError=_,exports.ProductBox=Y,exports.ProductCollection=ot,exports.ProductLink=ct,exports.ProductMedia=st,exports.ProductPriceComponent=vt,exports.ProductQuantity=xt,exports.ProductTextField=wt,exports.ProductTypes={__proto__:null},exports.ProductVariantPicker=kt,exports.SiteTypes={__proto__:null},exports.ValidationError=O,exports.addToCartButtonMeta=B,exports.cartMeta=jt,exports.fetcher=W,exports.getCommerceProvider=function(t){return function(e){var r=e.children,o=function(t,e){if(null==t)return{};var r,n,o={},i=Object.keys(t);for(n=0;n<i.length;n++)e.indexOf(r=i[n])>=0||(o[r]=t[r]);return o}(e,C);return n.createElement(k,{provider:s({},t,o)},r)}},exports.productBoxMeta=U,exports.productCollectionMeta=nt,exports.productLinkMeta=at,exports.productMediaMeta=lt,exports.productPriceMeta=ht,exports.productQuantityMeta=gt,exports.productTextFieldMeta=bt,exports.productVariantPickerMeta=Et,exports.registerAddToCartButton=G,exports.registerAll=function(t){it(t),Ct(t),yt(t),pt(t),It(t),G(t),Pt(t),Nt(t),z(t),ut(t)},exports.registerCart=It,exports.registerProductBox=z,exports.registerProductCollection=it,exports.registerProductLink=ut,exports.registerProductMedia=pt,exports.registerProductPrice=yt,exports.registerProductQuantity=Pt,exports.registerProductVariantPicker=Nt,exports.registerTextField=Ct,exports.useAddItem=R,exports.useBrands=rt,exports.useCart=_t,exports.useCategories=Z,exports.useCommerce=N,exports.useProduct=H,exports.useRemoveItem=function(t){var e=F(St);return T(s({fetcher:Tt},e))(t)},exports.useSearch=J,exports.useUpdateItem=function(t){var e=F(Mt);return T(s({fetcher:At},e))(t)},exports.x=function(){return 2};
|
|
2
2
|
//# sourceMappingURL=commerce.cjs.production.min.js.map
|