@plasmicpkgs/commerce 0.0.7 → 0.0.8
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 +32 -15
- 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 +2 -1
- package/dist/commerce.esm.js +33 -15
- package/dist/commerce.esm.js.map +1 -1
- package/dist/registerProductCollection.d.ts +3 -0
- package/dist/types/product.d.ts +3 -0
- package/dist/utils/types.d.ts +3 -1
- package/dist/utils/use-extra-features.d.ts +1 -0
- package/package.json +3 -3
|
@@ -1,2 +1,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};
|
|
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 v(t,e,r){return(v=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 h(t){var e="function"==typeof Map?new Map:void 0;return(h=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 v(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=b(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 v=Object.getPrototypeOf,h=v&&v(v(E([])));h&&h!==e&&r.call(h,o)&&(m=h);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 b(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,b(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 P(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(P,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)}})),b=n.createContext(void 0);function P(t){var e=t.product,r=t.children,i=o.useForm();return n.createElement(b.Provider,{value:e,key:e.id},n.createElement(o.FormProvider,Object.assign({},i),r))}function w(){return r.useContext(b)}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}(h(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 S(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 I(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 T=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 I(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,c;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 c=null!=(o=i.getValues().ProductVariant)?o:r.variants[0].id,t.next=7,a({productId:r.id,variantId:c,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=T,Q=function(t){var e;return null==(e=t.products)?void 0:e.useProduct},H=function(t){var e=F(Q);return S(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(P,{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=T,$=function(t){var e;return null==(e=t.products)?void 0:e.useSearch},J=function(t){var e=F($);return S(s({fetcher:W},e))(t)},K=T,X=function(t){var e;return null==(e=t.site)?void 0:e.useCategories},Z=function(t){var e=F(X);return S(s({fetcher:K},e))(t)},tt=T,et=function(t){var e;return null==(e=t.site)?void 0:e.useBrands},rt=function(t){var e=F(et);return S(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:[]}},includeSubCategories:{type:"boolean",hidden:function(t,e){var r;return!(null!=e&&null!=(r=e.features)&&r.includeSubCategories)}},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.count,i=t.category,c=t.includeSubCategories,u=t.brand,l=t.noLayout,s=t.setControlContextData,p=Z().data,d=rt().data,f=J({categoryId:i,brandId:u,count:o,categories:null!=p?p:[],includeSubCategories:c}).data,m=N().providerRef.current.extraFeatures;p&&d&&(null==s||s({categories:p,brands:d,features:m}));var v=null==f?void 0:f.products.map((function(t,e){return n.createElement(P,{product:t,key:t.id},a.repeatedElement(0===e,r))}));return l?n.createElement(n.Fragment,null,v):n.createElement("div",{className:e},v)}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},vt={name:"plasmic-commerce-product-price",displayName:"Product Price",props:{},importPath:"@plasmicpkgs/commerce",importName:"ProductPrice"};function ht(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)}(ht,null!=r?r:vt)}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 bt(t,r){!function(){t?t.registerComponent.apply(t,arguments):e.apply(void 0,arguments)}(xt,null!=r?r:gt)}var Pt={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:Pt)}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 S(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 St(t,r){!function(){t?t.registerComponent.apply(t,arguments):e.apply(void 0,arguments)}(Ft,null!=r?r:jt)}var It=A,Tt=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=ht,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=vt,exports.productQuantityMeta=gt,exports.productTextFieldMeta=Pt,exports.productVariantPickerMeta=Et,exports.registerAddToCartButton=G,exports.registerAll=function(t){it(t),Ct(t),yt(t),pt(t),St(t),G(t),bt(t),Nt(t),z(t),ut(t)},exports.registerCart=St,exports.registerProductBox=z,exports.registerProductCollection=it,exports.registerProductLink=ut,exports.registerProductMedia=pt,exports.registerProductPrice=yt,exports.registerProductQuantity=bt,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(Tt);return I(s({fetcher:It},e))(t)},exports.useSearch=J,exports.useUpdateItem=function(t){var e=F(Mt);return I(s({fetcher:At},e))(t)};
|
|
2
2
|
//# sourceMappingURL=commerce.cjs.production.min.js.map
|