UNPKG

@apicart/vue-components

Version:

Apicart Vue.Js components for simple e-commerce platform development

8 lines (6 loc) 7.01 kB
/** * @apicart/vue-components v1.0.0-alpha7 * (c) 2018-2020 Apicart Company * Released under the MIT License. */ !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e(require("@apicart/core-sdk")):"function"==typeof define&&define.amd?define(["@apicart/core-sdk"],e):(t=t||self).ApicartBuyButtonWithQuantity=e(t.Apicart)}(this,(function(t){"use strict";function e(t,e,n,i){return new(n||(n=Promise))((function(a,r){function o(t){try{s(i.next(t))}catch(t){r(t)}}function u(t){try{s(i.throw(t))}catch(t){r(t)}}function s(t){var e;t.done?a(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(o,u)}s((i=i.apply(t,e||[])).next())}))}function n(t,e){var n,i,a,r,o={label:0,sent:function(){if(1&a[0])throw a[1];return a[1]},trys:[],ops:[]};return r={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(r[Symbol.iterator]=function(){return this}),r;function u(r){return function(u){return function(r){if(n)throw new TypeError("Generator is already executing.");for(;o;)try{if(n=1,i&&(a=2&r[0]?i.return:r[0]?i.throw||((a=i.return)&&a.call(i),0):i.next)&&!(a=a.call(i,r[1])).done)return a;switch(i=0,a&&(r=[2&r[0],a.value]),r[0]){case 0:case 1:a=r;break;case 4:return o.label++,{value:r[1],done:!1};case 5:o.label++,i=r[1],r=[0];continue;case 7:r=o.ops.pop(),o.trys.pop();continue;default:if(!(a=o.trys,(a=a.length>0&&a[a.length-1])||6!==r[0]&&2!==r[0])){o=0;continue}if(3===r[0]&&(!a||r[1]>a[0]&&r[1]<a[3])){o.label=r[1];break}if(6===r[0]&&o.label<a[1]){o.label=a[1],a=r;break}if(a&&o.label<a[2]){o.label=a[2],o.ops.push(r);break}a[2]&&o.ops.pop(),o.trys.pop();continue}r=e.call(t,o)}catch(t){r=[6,t],i=0}finally{n=a=0}if(5&r[0])throw r[1];return{value:r[0]?r[1]:void 0,done:!0}}([r,u])}}}var i;t=t&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t;var a=function(t){return e(void 0,void 0,void 0,(function(){var e;return n(this,(function(n){switch(n.label){case 0:return i&&i.hasCartHash()?[4,i.getCart()]:[2,null];case 1:return[4,n.sent().getEntity()];case 2:return e=n.sent(),[2,e.findItemByDataUrl(t)]}}))}))},r=function(t){return e(void 0,void 0,void 0,(function(){var e;return n(this,(function(n){switch(n.label){case 0:return[4,a(t)];case 1:return[2,(e=n.sent())?e.getQuantity():0]}}))}))},o={name:"apicart-buy-button-with-quantity",props:["product-url"],data:function(){return{quantity:null}},methods:{addItem:function(){this.quantity++,this.updateItemQuantity()},removeItem:function(){this.quantity--,this.updateItemQuantity()},updateItemQuantity:function(){return e(this,void 0,void 0,(function(){var t,e;return n(this,(function(n){switch(n.label){case 0:return[4,r(this.productUrl)];case 1:return t=n.sent(),this.quantity<=0&&(this.quantity=0),[4,i.getCart()];case 2:return e=n.sent(),this.quantity>t?e.addItem(this.productUrl,this.quantity-t):this.quantity<t&&e.removeItem(this.productUrl,t-this.quantity),[2]}}))}))}},created:function(){return e(this,void 0,void 0,(function(){var e,a=this;return n(this,(function(n){switch(n.label){case 0:return i=t.getConfigParameter("store"),e=this,[4,r(this.productUrl)];case 1:return e.quantity=n.sent(),t.Utils.EventDispatcher.addListener("apicart-buy-button-with-quantity-"+this._uid,"apicart:cart:item:updated",(function(t){t.getItem().getDataUrl()===a.productUrl&&(a.quantity=t.getQuantity())})),[2]}}))}))}};!function(t,e){void 0===e&&(e={});var n=e.insertAt;if(t&&"undefined"!=typeof document){var i=document.head||document.getElementsByTagName("head")[0],a=document.createElement("style");a.type="text/css","top"===n&&i.firstChild?i.insertBefore(a,i.firstChild):i.appendChild(a),a.styleSheet?a.styleSheet.cssText=t:a.appendChild(document.createTextNode(t))}}('.apicart-buy-button-with-quantity{font-family:-apple-system,"Segoe UI",Roboto,Oxygen,Ubuntu,Cantarell,"Helvetica Neue",Arial,sans-serif,"Apple Color Emoji","Segoe UI Emoji","Segoe UI Symbol";-webkit-font-smoothing:antialiased;box-sizing:border-box;outline:0}.apicart-buy-button-with-quantity *{box-sizing:border-box;outline:0}.apicart-buy-button-with-quantity{display:inline-flex;white-space:nowrap;height:38px}.apicart-buy-button-with-quantity__form{display:inline-flex;align-items:stretch}.apicart-buy-button-with-quantity__quantity-button{width:34px;line-height:38px;border:1px solid #e6e6e7;display:inline-block;vertical-align:middle;text-align:center;cursor:pointer;user-select:none;transition:background-color .15s linear;font-size:20px;outline:0;user-select:none;-webkit-tap-highlight-color:none}.apicart-buy-button-with-quantity__quantity-button:active,.apicart-buy-button-with-quantity__quantity-button:hover{background-color:#e6e6e7}.apicart-buy-button-with-quantity__quantity-field{width:48px;text-align:center;font-size:16px;border:1px solid #e6e6e7;border-right:0;border-left:0;display:inline-block;vertical-align:middle;-moz-appearance:textfield}.apicart-buy-button-with-quantity__quantity-field::-webkit-inner-spin-button{-webkit-appearance:none;margin:0}.apicart-buy-button-with-quantity__pcs{margin-left:8px}.apicart-buy-button-with-quantity__quantity-button--minus{border-radius:2px 0 0 2px}.apicart-buy-button-with-quantity__quantity-button--plus{border-radius:0 2px 2px 0}');return function(t,e,n,i,a,r,o,u,s,c){"boolean"!=typeof o&&(s=u,u=o,o=!1);const l="function"==typeof n?n.options:n;let d;if(t&&t.render&&(l.render=t.render,l.staticRenderFns=t.staticRenderFns,l._compiled=!0,a&&(l.functional=!0)),i&&(l._scopeId=i),r?(d=function(t){(t=t||this.$vnode&&this.$vnode.ssrContext||this.parent&&this.parent.$vnode&&this.parent.$vnode.ssrContext)||"undefined"==typeof __VUE_SSR_CONTEXT__||(t=__VUE_SSR_CONTEXT__),e&&e.call(this,s(t)),t&&t._registeredComponents&&t._registeredComponents.add(r)},l._ssrRegister=d):e&&(d=o?function(t){e.call(this,c(t,this.$root.$options.shadowRoot))}:function(t){e.call(this,u(t))}),d)if(l.functional){const t=l.render;l.render=function(e,n){return d.call(n),t(e,n)}}else{const t=l.beforeCreate;l.beforeCreate=t?[].concat(t,d):[d]}return n}({render:function(){var t=this,e=t.$createElement,n=t._self._c||e;return n("div",{staticClass:"apicart-buy-button-with-quantity"},[n("span",{staticClass:"apicart-buy-button-with-quantity__form"},[n("a",{staticClass:"apicart-buy-button-with-quantity__quantity-button apicart-buy-button-with-quantity__quantity-button--minus",attrs:{role:"button"},on:{click:t.removeItem}},[n("span",{staticClass:"apicart-icon-minus"})]),n("input",{directives:[{name:"model",rawName:"v-model",value:t.quantity,expression:"quantity"}],staticClass:"apicart-buy-button-with-quantity__quantity-field",attrs:{type:"number",min:"0"},domProps:{value:t.quantity},on:{change:t.updateItemQuantity,input:function(e){e.target.composing||(t.quantity=e.target.value)}}}),n("a",{staticClass:"apicart-buy-button-with-quantity__quantity-button apicart-buy-button-with-quantity__quantity-button--plus",attrs:{role:"button"},on:{click:t.addItem}},[n("span",{staticClass:"apicart-icon-plus"})])])])},staticRenderFns:[]},void 0,o,void 0,!1,void 0,!1,void 0,void 0,void 0)}));