UNPKG

@apicart/vue-components

Version:

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

193 lines (175 loc) 8.91 kB
/** * @apicart/vue-components v1.0.0-alpha7 * (c) 2018-2020 Apicart Company * Released under the MIT License. */ import Apicart from '@apicart/core-sdk'; import { Translator } from '../..'; import { ApicartDialog, ApicartBuyButtonWithQuantity } from './..'; var config = { enabled: true, dispatcherEvents: ['apicart:cart:item:added'] }; var store; var translator = Apicart.VueComponentsTranslator || Translator; var i18n = translator.getI18n(); var refs = null; var windowIsDefined = typeof window !== 'undefined'; var script = { name: 'apicart-cart-dialog', components: { 'apicart-dialog': windowIsDefined && window.ApicartDialog ? window.ApicartDialog : ApicartDialog, 'apicart-buy-button-with-quantity': windowIsDefined && window.ApicartBuyButtonWithQuantity ? window.ApicartBuyButtonWithQuantity : ApicartBuyButtonWithQuantity }, i18n: i18n, data: function () { return { cartItem: null, enabled: false }; }, created: function () { config = Apicart.Utils.Objects.merge(config, Apicart.getConfigParameter('vueComponents.cartDialog')); this.enabled = config.enabled; store = Apicart.getConfigParameter('store'); }, mounted: function () { var _this = this; if (typeof this.$refs.apicartDialog !== 'undefined' && config.enabled) { refs = this.$refs; Apicart.Utils.EventDispatcher.addListener('apicart-cart-dialog-' + this._uid, config.dispatcherEvents, function (cartItem) { _this.cartItem = cartItem; refs.apicartDialog.open(); }); } } }; function styleInject(css, ref) { if ( ref === void 0 ) ref = {}; var insertAt = ref.insertAt; if (!css || typeof document === 'undefined') { return; } var head = document.head || document.getElementsByTagName('head')[0]; var style = document.createElement('style'); style.type = 'text/css'; if (insertAt === 'top') { if (head.firstChild) { head.insertBefore(style, head.firstChild); } else { head.appendChild(style); } } else { head.appendChild(style); } if (style.styleSheet) { style.styleSheet.cssText = css; } else { style.appendChild(document.createTextNode(css)); } } var css_248z = ".apicart-cart-dialog{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-cart-dialog *{box-sizing:border-box;outline:0}.apicart-cart-dialog.apicart-dialog__mask{z-index:9999}.apicart-cart-dialog .apicart-dialog__container{max-width:600px}.apicart-cart-dialog .apicart-cart-dialog__title{margin:0}.apicart-cart-dialog .apicart-cart-dialog__item{align-items:center;display:flex;background:#f8f9fa!important;border-radius:2px;padding:8px}.apicart-cart-dialog .apicart-cart-dialog__item-image-wrapper{max-width:80px;display:flex;max-height:80px;margin-right:12px}@media (min-width:768px){.apicart-cart-dialog .apicart-cart-dialog__item-image-wrapper{max-width:160px;max-height:160px}}.apicart-cart-dialog .apicart-cart-dialog__item-image{max-width:100%;max-height:100%;display:inline-block}.apicart-cart-dialog .apicart-cart-dialog__item-info{display:flex;flex-direction:column;flex:1}.apicart-cart-dialog .apicart-cart-dialog__item-name{margin-bottom:12px;font-size:20px}.apicart-cart-dialog .apicart-cart-dialog__item-price-quantity-wrapper{display:flex;align-items:center;flex-wrap:wrap;justify-content:space-between}.apicart-cart-dialog .apicart-cart-dialog__item-price{margin-right:12px}"; styleInject(css_248z); function normalizeComponent(template, style, script, scopeId, isFunctionalTemplate, moduleIdentifier /* server only */, shadowMode, createInjector, createInjectorSSR, createInjectorShadow) { if (typeof shadowMode !== 'boolean') { createInjectorSSR = createInjector; createInjector = shadowMode; shadowMode = false; } // Vue.extend constructor export interop. const options = typeof script === 'function' ? script.options : script; // render functions if (template && template.render) { options.render = template.render; options.staticRenderFns = template.staticRenderFns; options._compiled = true; // functional template if (isFunctionalTemplate) { options.functional = true; } } // scopedId if (scopeId) { options._scopeId = scopeId; } let hook; if (moduleIdentifier) { // server build hook = function (context) { // 2.3 injection context = context || // cached call (this.$vnode && this.$vnode.ssrContext) || // stateful (this.parent && this.parent.$vnode && this.parent.$vnode.ssrContext); // functional // 2.2 with runInNewContext: true if (!context && typeof __VUE_SSR_CONTEXT__ !== 'undefined') { context = __VUE_SSR_CONTEXT__; } // inject component styles if (style) { style.call(this, createInjectorSSR(context)); } // register component module identifier for async chunk inference if (context && context._registeredComponents) { context._registeredComponents.add(moduleIdentifier); } }; // used by ssr in case component is cached and beforeCreate // never gets called options._ssrRegister = hook; } else if (style) { hook = shadowMode ? function (context) { style.call(this, createInjectorShadow(context, this.$root.$options.shadowRoot)); } : function (context) { style.call(this, createInjector(context)); }; } if (hook) { if (options.functional) { // register for functional component in vue file const originalRender = options.render; options.render = function renderWithStyleInjection(h, context) { hook.call(context); return originalRender(h, context); }; } else { // inject component registration as beforeCreate hook const existing = options.beforeCreate; options.beforeCreate = existing ? [].concat(existing, hook) : [hook]; } } return script; } /* script */ const __vue_script__ = script; /* template */ var __vue_render__ = function () {var _vm=this;var _h=_vm.$createElement;var _c=_vm._self._c||_h;return _c('apicart-dialog',{directives:[{name:"show",rawName:"v-show",value:(_vm.cartItem),expression:"cartItem"}],ref:"apicartDialog",staticClass:"apicart-cart-dialog"},[(_vm.cartItem)?_c('div',{attrs:{"slot":"header"},slot:"header"},[_c('h1',{staticClass:"apicart-dialog__title apicart-cart-dialog__title"},[_vm._v(_vm._s(_vm.$t('cartDialog.title')))])]):_vm._e(),(_vm.cartItem)?_c('div',{attrs:{"slot":"body"},slot:"body"},[_c('div',{staticClass:"apicart-cart-dialog__item"},[(_vm.cartItem.getItem().getParameterValue('images').primary.url)?_c('div',{staticClass:"apicart-cart-dialog__item-image-wrapper"},[_c('img',{staticClass:"apicart-cart-dialog__item-image",attrs:{"src":_vm.cartItem.getItem().getParameterValue('images').primary.url,"alt":""}})]):_vm._e(),_c('div',{staticClass:"apicart-cart-dialog__item-info"},[_c('div',{staticClass:"apicart-cart-dialog__item-name"},[_c('strong',[_vm._v(_vm._s(_vm.cartItem.getItem().getName()))])]),_c('div',{staticClass:"apicart-cart-dialog__item-price-quantity-wrapper"},[_c('div',{staticClass:"apicart-cart-dialog__item-price"},[_vm._v(_vm._s(_vm.$n(_vm.cartItem.getItem().getPrice(), 'currency')))]),_c('div',{staticClass:"apicart-cart-dialog__item-quantity-manipulator"},[_c('apicart-buy-button-with-quantity',{attrs:{"productUrl":_vm.cartItem.getItem().getDataUrl()}})],1)])])])]):_vm._e()])}; var __vue_staticRenderFns__ = []; /* style */ const __vue_inject_styles__ = undefined; /* scoped */ const __vue_scope_id__ = undefined; /* module identifier */ const __vue_module_identifier__ = undefined; /* functional template */ const __vue_is_functional_template__ = false; /* style inject */ /* style inject SSR */ /* style inject shadow dom */ const __vue_component__ = normalizeComponent( { render: __vue_render__, staticRenderFns: __vue_staticRenderFns__ }, __vue_inject_styles__, __vue_script__, __vue_scope_id__, __vue_is_functional_template__, __vue_module_identifier__, false, undefined, undefined, undefined ); export default __vue_component__;