@apicart/vue-components
Version:
Apicart Vue.Js components for simple e-commerce platform development
852 lines (813 loc) • 38.8 kB
JavaScript
/**
* @apicart/vue-components v1.0.0-alpha7
* (c) 2018-2020 Apicart Company
* Released under the MIT License.
*/
import Apicart from '@apicart/core-sdk';
export { default } from '@apicart/core-sdk';
import Vue from 'vue';
import VueI18n from 'vue-i18n';
import { ApicartCartDialog, ApicartCategory, ApicartCheckoutDialog, ApicartOrderDialog, ApicartProductDetail, ApicartCartDropdown, ApicartButton, ApicartBuyButton, ApicartBuyButtonWithQuantity, ApicartCategoriesList, ApicartDialog, ApicartDrawer, ApicartCheckout, ApicartLoader, ApicartPaymentMethodsList, ApicartProductsList, ApicartShippingMethodsList } from '../..';
import { StoreBrowser } from '@apicart/store-sdk/lib';
import Payments from '@apicart/payments-sdk';
/*! *****************************************************************************
Copyright (c) Microsoft Corporation.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
***************************************************************************** */
var __assign = function() {
__assign = Object.assign || function __assign(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
function __awaiter(thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
}
function __generator(thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (_) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
}
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 = "@font-face {\n font-family: 'apicart-icons';\n src: url('data:font/woff;base64,d09GRgABAAAAAArMAAsAAAAACoAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAABPUy8yAAABCAAAAGAAAABgDxIF8WNtYXAAAAFoAAAAXAAAAFzpQ+m8Z2FzcAAAAcQAAAAIAAAACAAAABBnbHlmAAABzAAABlAAAAZQla7j+GhlYWQAAAgcAAAANgAAADYYnMfiaGhlYQAACFQAAAAkAAAAJAeXA8xobXR4AAAIeAAAACwAAAAsIgADOGxvY2EAAAikAAAAGAAAABgFQgbwbWF4cAAACLwAAAAgAAAAIAARAHVuYW1lAAAI3AAAAc4AAAHO8dCgtXBvc3QAAAqsAAAAIAAAACAAAwAAAAMDwAGQAAUAAAKZAswAAACPApkCzAAAAesAMwEJAAAAAAAAAAAAAAAAAAAAARAAAAAAAAAAAAAAAAAAAAAAQAAA6QcDwP/AAEADwABAAAAAAQAAAAAAAAAAAAAAIAAAAAAAAwAAAAMAAAAcAAEAAwAAABwAAwABAAAAHAAEAEAAAAAMAAgAAgAEAAEAIOkF6Qf//f//AAAAAAAg6QDpB//9//8AAf/jFwQXAwADAAEAAAAAAAAAAAAAAAAAAQAB//8ADwABAAAAAAAAAAAAAgAANzkBAAAAAAEAAAAAAAAAAAACAAA3OQEAAAAAAQAAAAAAAAAAAAIAADc5AQAAAAABAKsBgANVAdUADgAAEyEyNjU0JiMhIgYVFBYz1QJWERkZEf2qERkZEQGAGRIRGRkREhkAAQCrAFUDVQMAACAAABMhERQWMzI2NREhMjY1NCYjIRE0JiMiBhURISIGFRQWM9UBABkSEhkBABEZGRH/ABkSEhn/ABEZGREBgP8AEhkZEgEAGRIRGQEAEhkZEv8AGRESGQAAAAUAVQAAA6sDVQAbADQATAB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AAAAAAAMADQBIAAEAAAAAAAQADQCrAAEAAAAAAAUACwAnAAEAAAAAAAYADQBvAAEAAAAAAAoAGgDSAAMAAQQJAAEAGgANAAMAAQQJAAIADgCdAAMAAQQJAAMAGgBVAAMAAQQJAAQAGgC4AAMAAQQJAAUAFgAyAAMAAQQJAAYAGgB8AAMAAQQJAAoANADsYXBpY2FydC1pY29ucwBhAHAAaQBjAGEAcgB0AC0AaQBjAG8AbgBzVmVyc2lvbiAxLjAAVgBlAHIAcwBpAG8AbgAgADEALgAwYXBpY2FydC1pY29ucwBhAHAAaQBjAGEAcgB0AC0AaQBjAG8AbgBzYXBpY2FydC1pY29ucwBhAHAAaQBjAGEAcgB0AC0AaQBjAG8AbgBzUmVndWxhcgBSAGUAZwB1AGwAYQByYXBpY2FydC1pY29ucwBhAHAAaQBjAGEAcgB0AC0AaQBjAG8AbgBzRm9udCBnZW5lcmF0ZWQgYnkgSWNvTW9vbi4ARgBvAG4AdAAgAGcAZQBuAGUAcgBhAHQAZQBkACAAYgB5ACAASQBjAG8ATQBvAG8AbgAuAAAAAwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA==') format('woff');\n font-weight: normal;\n font-style: normal;\n font-display: block;\n}\n\n[class^=\"apicart-icon-\"], [class*=\" apicart-icon-\"] {\n /* use !important to prevent issues with browser extensions that change fonts */\n font-family: 'apicart-icons' !important;\n speak: none;\n font-style: normal;\n font-weight: normal;\n font-variant: normal;\n text-transform: none;\n line-height: 1;\n\n /* Better Font Rendering =========== */\n -webkit-font-smoothing: antialiased;\n -moz-osx-font-smoothing: grayscale;\n}\n\n.apicart-icon-image:before {\n content: \"\\e902\";\n}\n.apicart-icon-x:before {\n content: \"\\e907\";\n}\n.apicart-icon-minus:before {\n content: \"\\e900\";\n}\n.apicart-icon-plus:before {\n content: \"\\e901\";\n}\n.apicart-icon-arrow-left-circle:before {\n content: \"\\e903\";\n}\n.apicart-icon-arrow-right-circle:before {\n content: \"\\e904\";\n}\n.apicart-icon-shopping-bag:before {\n content: \"\\e905\";\n}\n";
styleInject(css_248z);
var category = {
id: "category",
showCategories: "Show categories"
};
var checkout = {
title: "Checkout",
validation: {
title: "Please correct the following error(s):",
emptyCart: "Your cart is empty. You cannot create an order without adding any products.",
missingPaymentMethod: "You must select payment method.",
missingShippingMethod: "You must select shipping method."
},
steps: {
continueShopping: "Continue shopping",
cartOverview: "Cart overview",
paymentAndDelivery: "Payment & Delivery",
contactInformation: "Contact information",
finishOrder: "Finish order"
},
summary: {
title: "Order summary",
paymentMethod: "Payment method",
paymentMethodNotSelected: "Not selected",
shippingMethod: "Shipping method",
shippingMethodNotSelected: "Not selected",
taxBase: "Tax base",
vat: "Vat",
totalPrice: "Total price"
},
cartOverview: {
id: "cart-overview",
title: "Cart Overview",
taxBase: "Tax Base",
vat: "Vat",
totalPrice: "Total Price",
emptyCart: "Your cart is empty."
},
contactInformationForm: {
id: "contact-information",
billing: {
id: "billing-information",
title: "Billing Information",
email: "E-mail",
firstName: "Name",
lastName: "Surname",
town: "Town",
zip: "Zip",
streetAndNumber: "Street and number"
},
shipping: {
id: "shipping-information",
title: "Shipping Information",
email: "E-mail",
firstName: "Name",
lastName: "Surname",
company: "Company",
town: "Town",
zip: "Zip",
streetAndNumber: "Street and number"
},
validation: {
requiredFields: "You must fill all contact information fields with the star (*) symbol."
},
fillShippingInfoButton: "Fill shipping info",
requiredFields: "Fields with <strong>*</strong> are required",
finishOrderButton: "Finish order"
}
};
var buyButton = "Add to cart";
var cartDialog = {
id: "cart-dialog",
title: "Cart updated"
};
var cartDropdown = {
id: "cart-dropdown",
emptyCart: "Your cart is empty.",
toggleButton: "Cart",
itemsCount: "Items count",
totalPrice: "Total price",
button: "Finish order"
};
var dialog = {
okButton: "Ok"
};
var loader = {
loading: "Loading..."
};
var orderDialog = {
id: "order-dialog",
order: {
success: {
title: "Order successfully created!",
text: "Your order with variable symbol <strong>{variableSymbol}</strong> and total price <strong>{totalPrice}</strong> has been successfully created.<br>Check your e-mail for recapitulation."
},
error: {
title: "Something terribly wrong happened",
text: "We are sorry but your order could not be created.<br>Please contact us."
}
},
payment: {
success: {
title: "Payment successful!",
text: "Your payment for an order with variable symbol <strong>{variableSymbol}</strong> with total amount of <strong>{totalPrice}</strong> was successfully made."
},
error: {
title: "An error occured during payment",
text: "Your payment was not made because an error occurred. Please contact us.<br>Error message \"{error}\"."
}
},
closeButton: {
ok: "Ok",
close: "Close",
pay: "Go to payment"
}
};
var paymentMethodsList = {
id: "payment-methods",
methodsNotFound: "No payment methods found."
};
var shippingMethodsList = {
id: "shipping-methods",
methodsNotFound: "No shipping methods found."
};
var fallbackTranslations = {
category: category,
checkout: checkout,
buyButton: buyButton,
cartDialog: cartDialog,
cartDropdown: cartDropdown,
dialog: dialog,
loader: loader,
orderDialog: orderDialog,
paymentMethodsList: paymentMethodsList,
shippingMethodsList: shippingMethodsList
};
Vue.use(VueI18n);
var Translator = (function () {
function Translator() {
var _this = this;
this._config = {
actualLocale: null,
fallbackLocale: 'en',
localization: {},
localizationFilesUrl: 'https://cdn.jsdelivr.net/npm/@apicart/web-components-localization@1.0.0-alpha7/localization',
currencyFormats: {
en: {
currency: {
style: 'currency', currency: 'EUR', currencyDisplay: 'symbol', code: 'EUR'
}
}
}
};
this._i18n = null;
this._loadedLanguages = ['en'];
this._processedLanguageFiles = {};
this._downloadUrlsWithError = [];
this._loadingLanguagePromise = null;
this._configurationPromises = null;
this.configure();
Apicart.Utils.EventDispatcher.addListener('apicart-vueComponentsTranslator-configure', 'apicart:configure', function () {
_this.configure();
});
}
Translator.prototype.configure = function (config) {
if (config === void 0) { config = null; }
return __awaiter(this, void 0, void 0, function () {
var configurationPromises, _a, _b;
return __generator(this, function (_c) {
switch (_c.label) {
case 0: return [4, this._configurationPromises];
case 1:
_c.sent();
config = config || Apicart.getConfigParameter('vueComponentsTranslator') || {};
this._config = Apicart.Utils.Objects.merge(this._config, config);
if (!this._config.actualLocale) {
this._config.actualLocale = this.detectLocale();
}
configurationPromises = [];
_b = (_a = configurationPromises).push;
return [4, this.loadLocalizationFiles(this._config.actualLocale)];
case 2:
_b.apply(_a, [_c.sent()]);
if (this._config.localization) {
configurationPromises.push(this.addLocalization(this._config.localization));
}
this._configurationPromises = Promise.all(configurationPromises);
return [4, this._configurationPromises];
case 3:
_c.sent();
if (this._config.currencyFormats) {
this.addNumberFormat(this._config.currencyFormats);
}
return [2];
}
});
});
};
Translator.prototype.getActualCurrencyConfig = function () {
var currencyConfig = typeof this.getI18n().numberFormats[this.getActualLocale()] === 'undefined'
? this.getI18n().numberFormats[this.getFallbackLocale()]
: this.getI18n().numberFormats[this.getActualLocale()];
return typeof currencyConfig === 'undefined' ? {} : currencyConfig.currency;
};
Translator.prototype.getActualLocale = function () {
return this.getI18n().locale;
};
Translator.prototype.getFallbackLocale = function () {
return this.getI18n().fallbackLocale ? this.getI18n().fallbackLocale : this._config.fallbackLocale;
};
Translator.prototype.getI18n = function () {
if (!this._i18n) {
var messages = Apicart.Storage.getItem('apicart-localization') || {};
messages[this._config.fallbackLocale] = fallbackTranslations;
this._i18n = new VueI18n({
locale: this.detectLocale(),
fallbackLocale: this._config.fallbackLocale,
messages: messages,
numberFormats: this._config.currencyFormats || this._config.defaultCurrencyFormats
});
}
return this._i18n;
};
Translator.prototype.loadLocalizationFiles = function (lang, url) {
if (url === void 0) { url = null; }
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4, this._loadingLanguagePromise];
case 1:
_a.sent();
this._loadingLanguagePromise = this.downloadLocalizationFilesContent(lang, url || this._config.localizationFilesUrl + '/' + lang + '.json');
return [4, this._loadingLanguagePromise];
case 2:
_a.sent();
return [2, this.setI18nLanguage(lang)];
}
});
});
};
Translator.prototype.addLocalization = function (localization) {
var _this = this;
Apicart.Utils.Loops.forEach(localization, function (translationsOrUrl, locale) {
if (typeof translationsOrUrl === 'string') {
_this.loadLocalizationFiles(locale, translationsOrUrl);
}
else {
_this.mergeLocaleMessages(locale, translationsOrUrl);
}
});
};
Translator.prototype.addNumberFormat = function (numberFormat) {
var _this = this;
Apicart.Utils.Loops.forEach(numberFormat, function (numberFormat, locale) {
_this.getI18n().mergeNumberFormat(locale, numberFormat);
});
};
Translator.prototype.downloadLocalizationFilesContent = function (locale, url) {
return __awaiter(this, void 0, void 0, function () {
var response, loaded, localeObject;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
if (this._loadedLanguages.includes(locale)) {
return [2, true];
}
if (this._downloadUrlsWithError.includes(url)) {
return [2, false];
}
if (!(url in this._processedLanguageFiles)) {
this._processedLanguageFiles[url] = Apicart.Utils.Ajax.get(url);
}
return [4, this._processedLanguageFiles[url]];
case 1:
response = _a.sent();
loaded = response && Apicart.Utils.Objects.isObject(response.data);
if (loaded) {
localeObject = {};
localeObject[locale] = response.data;
Apicart.Storage.updateItem('apicart-localization', localeObject);
this.mergeLocaleMessages(locale, response.data);
}
else {
Apicart.Utils.Console.error('Localization file "' + url + '" could not be loaded.');
this._downloadUrlsWithError.push(url);
}
this._loadedLanguages.push(locale);
return [2, loaded];
}
});
});
};
Translator.prototype.setI18nLanguage = function (lang) {
this.getI18n().locale = lang;
if (this.isInBrowser()) {
document.querySelector('html').setAttribute('lang', lang);
}
return lang;
};
Translator.prototype.isInBrowser = function () {
return typeof window !== 'undefined' && typeof document !== 'undefined';
};
Translator.prototype.detectLocale = function () {
if (!this.isInBrowser()) {
return this._config.fallbackLocale;
}
var documentLang = document.documentElement.getAttribute('lang');
return documentLang ? documentLang : navigator.language || window.navigator.userLanguage;
};
Translator.prototype.mergeLocaleMessages = function (locale, messages) {
this.getI18n().mergeLocaleMessage(locale, messages);
Apicart.Utils.EventDispatcher.dispatchEvent('apicart:translations:updated');
};
return Translator;
}());
var Translator$1 = new Translator();
var eventListenersInitialized = false;
var init = function () {
if (eventListenersInitialized) {
return;
}
eventListenersInitialized = true;
var store = null;
var getStore = function () {
if (!store) {
store = Apicart.getConfigParameter('store');
}
return store;
};
Apicart.Utils.Dom
.on('click', '[data-apicart-add-item]', function (event) { return __awaiter(void 0, void 0, void 0, function () {
var el;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
el = event.currentTarget;
return [4, getStore().getCart()];
case 1:
(_a.sent()).addItem(el.getAttribute('data-apicart-add-item'), el.getAttribute('data-apicart-item-quantity') || 1);
return [2];
}
});
}); })
.on('click', '[data-apicart-remove-item]', function (event) { return __awaiter(void 0, void 0, void 0, function () {
var el, itemUrl, cart, quantity, cartItem;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
el = event.currentTarget;
itemUrl = el.getAttribute('data-apicart-remove-item');
return [4, getStore().getCart()];
case 1:
cart = _a.sent();
quantity = el.getAttribute('data-apicart-item-quantity') || 1;
if (!(quantity === 'all')) return [3, 3];
return [4, cart.findItemByDataUrl(itemUrl)];
case 2:
cartItem = _a.sent();
if (cartItem) {
quantity = cartItem.getQuantity();
}
_a.label = 3;
case 3:
cart.removeItem(itemUrl, quantity);
return [2];
}
});
}); });
};
var basicEventListeners = {
init: init
};
var script = {
name: 'apicart-bundle-default',
components: {
'apicart-cart-dialog': ApicartCartDialog,
'apicart-category': ApicartCategory,
'apicart-checkout-dialog': ApicartCheckoutDialog,
'apicart-order-dialog': ApicartOrderDialog,
'apicart-product-detail': ApicartProductDetail
},
data: function () {
return {
productDetailConfig: null
};
},
created: function () {
this.productDetailConfig = Apicart.getConfigParameter('vueComponents.productDetail');
},
mounted: function () {
var _this = this;
Apicart.Utils.Dom.on('click', '.apicart-open-checkout', function () { return _this.$refs.apicartCheckoutDialog.open(); });
Apicart.Utils.EventDispatcher.addListener('apicart-bundle-checkout-open', 'apicart:checkout:open', function () { return _this.$refs.apicartCheckoutDialog.open(); });
if (typeof document !== 'undefined') {
basicEventListeners.init();
}
}
};
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('div',[(_vm.productDetailConfig)?_c('apicart-product-detail',{ref:"apicartProductDetail",attrs:{"productUrl":_vm.productDetailConfig.dataUrl}}):_c('apicart-category',{ref:"apicartCategory"}),_c('apicart-checkout-dialog',{ref:"apicartCheckoutDialog"}),_c('apicart-cart-dialog',{ref:"apicartCartDialog"}),_c('apicart-order-dialog',{ref:"apicartOrderDialog"})],1)};
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
);
var script$1 = {
name: 'apicart-default-bundle-cart-dropdown',
components: {
'apicart-cart-dropdown-default': ApicartCartDropdown,
},
methods: {
openCheckout: function () {
Apicart.Utils.EventDispatcher.dispatchEvent('apicart:checkout:open');
}
}
};
/* script */
const __vue_script__$1 = script$1;
/* template */
var __vue_render__$1 = function () {var _vm=this;var _h=_vm.$createElement;var _c=_vm._self._c||_h;return _c('apicart-cart-dropdown-default',{on:{"toggle-button-click":_vm.openCheckout,"footer-button-click":_vm.openCheckout}})};
var __vue_staticRenderFns__$1 = [];
/* style */
const __vue_inject_styles__$1 = undefined;
/* scoped */
const __vue_scope_id__$1 = undefined;
/* module identifier */
const __vue_module_identifier__$1 = undefined;
/* functional template */
const __vue_is_functional_template__$1 = false;
/* style inject */
/* style inject SSR */
/* style inject shadow dom */
const __vue_component__$1 = normalizeComponent(
{ render: __vue_render__$1, staticRenderFns: __vue_staticRenderFns__$1 },
__vue_inject_styles__$1,
__vue_script__$1,
__vue_scope_id__$1,
__vue_is_functional_template__$1,
__vue_module_identifier__$1,
false,
undefined,
undefined,
undefined
);
var ProductsDownloader = (function () {
function ProductsDownloader() {
this._localStorage = Apicart.Storage;
this._storageName = 'apicart-products-files';
this._loadedProducts = {};
this._loadedProducts = this.getStorage();
}
ProductsDownloader.prototype.getStorageName = function () {
return this._storageName;
};
ProductsDownloader.prototype.getStorage = function () {
return this._localStorage.getItem(this.getStorageName()) || {};
};
ProductsDownloader.prototype.getLoadedProducts = function () {
return this._loadedProducts;
};
ProductsDownloader.prototype.getLoadedProductsData = function (productsFilesConfigOrUrl) {
var _this = this;
var products = [];
Apicart.Utils.Loops
.forEach(productsFilesConfigOrUrl, function (productDataConfigOrUrl) {
var dataUrl = productDataConfigOrUrl;
var pageUrl = null;
var data = null;
if (typeof productDataConfigOrUrl !== 'string') {
dataUrl = productDataConfigOrUrl.dataUrl;
pageUrl = productDataConfigOrUrl.pageUrl;
if (productDataConfigOrUrl.data && Object.keys(productDataConfigOrUrl.data).length) {
data = productDataConfigOrUrl.data;
}
}
if (!data && !(dataUrl in _this._loadedProducts)) {
return;
}
products.push({
dataUrl: dataUrl,
data: data || _this._loadedProducts[dataUrl].data,
pageUrl: pageUrl || _this._loadedProducts[dataUrl].pageUrl
});
});
return products;
};
ProductsDownloader.prototype.getProductsData = function (productsFilesConfigOrUrl) {
return __awaiter(this, void 0, void 0, function () {
var localStorage, productsPromises, products, filteredProducts;
var _this = this;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
localStorage = Apicart.Storage;
productsPromises = [];
Apicart.Utils.Loops
.forEach(productsFilesConfigOrUrl, function (productDataConfigOrUrl) {
var dataUrl = productDataConfigOrUrl;
var pageUrl = null;
var data = null;
if (typeof productDataConfigOrUrl !== 'string') {
dataUrl = productDataConfigOrUrl.dataUrl;
pageUrl = productDataConfigOrUrl.pageUrl;
data = productDataConfigOrUrl.data || null;
}
var dataNotEmpty = data && Object.keys(data).length !== 0;
if (dataUrl in _this._loadedProducts || dataNotEmpty) {
productsPromises.push(Promise.resolve({
dataUrl: dataUrl,
data: dataNotEmpty ? data : _this._loadedProducts[dataUrl].data,
pageUrl: pageUrl
}));
}
else {
productsPromises.push((function () { return __awaiter(_this, void 0, void 0, function () {
var productDataResponse;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4, Apicart.Utils.Ajax.get(dataUrl)];
case 1:
productDataResponse = _a.sent();
if (typeof productDataResponse !== 'object' || parseInt(productDataResponse.status) !== 200) {
return [2];
}
return [2, {
dataUrl: dataUrl,
data: productDataResponse.data,
pageUrl: pageUrl
}];
}
});
}); })());
}
});
return [4, Promise.all(productsPromises)];
case 1:
products = _a.sent();
filteredProducts = [];
Apicart.Utils.Loops.forEach(products, function (product) {
if (!product) {
return;
}
_this._loadedProducts[product.dataUrl] = {
data: product.data,
pageUrl: product.pageUrl
};
filteredProducts.push(product);
});
localStorage.setItem(this._storageName, this._loadedProducts);
return [2, filteredProducts];
}
});
});
};
ProductsDownloader.prototype.getProductData = function (productUrl) {
return __awaiter(this, void 0, void 0, function () {
var response;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4, this.getProductsData([productUrl])];
case 1:
response = _a.sent();
return [2, response.length === 0 || typeof response[0] === 'undefined' ? null : response[0].data];
}
});
});
};
ProductsDownloader.prototype.getLoadedProductData = function (productUrl) {
var products = this.getLoadedProductsData([productUrl]);
return products.length === 1 ? products[0] : null;
};
return ProductsDownloader;
}());
var ProductsDownloader$1 = new ProductsDownloader();
Apicart.Store = StoreBrowser;
Apicart.Payments = Payments;
Apicart.VueComponentsTranslator = Translator$1;
Apicart.VueComponentsProductsDownloader = ProductsDownloader$1;
Apicart.initVueBundle = function () {
if (typeof window === 'undefined') {
return Apicart;
}
new Vue({
el: '#apicart',
render: function (createElement) {
var el = document.querySelector('#apicart');
var context = {
props: __assign({}, el.dataset)
};
return createElement(__vue_component__, context);
}
});
var cartDropdownSelector = '#apicart-cart-dropdown';
if (document.querySelector(cartDropdownSelector)) {
new Vue({
el: cartDropdownSelector,
render: function (h) {
return h(__vue_component__$1);
}
});
}
return Apicart;
};
if (typeof window !== 'undefined') {
window.Vue = Vue;
window.VueI18n = VueI18n;
window.ApicartButton = ApicartButton;
window.ApicartBuyButton = ApicartBuyButton;
window.ApicartBuyButtonWithQuantity = ApicartBuyButtonWithQuantity;
window.ApicartCartDialog = ApicartCartDialog;
window.ApicartCartDropdown = ApicartCartDropdown;
window.ApicartCategoriesList = ApicartCategoriesList;
window.ApicartCategory = ApicartCategory;
window.ApicartDialog = ApicartDialog;
window.ApicartDrawer = ApicartDrawer;
window.ApicartCheckout = ApicartCheckout;
window.ApicartCheckoutDialog = ApicartCheckoutDialog;
window.ApicartLoader = ApicartLoader;
window.ApicartOrderDialog = ApicartOrderDialog;
window.ApicartPaymentMethodsList = ApicartPaymentMethodsList;
window.ApicartProductDetail = ApicartProductDetail;
window.ApicartProductsList = ApicartProductsList;
window.ApicartShippingMethodsList = ApicartShippingMethodsList;
}
export { __vue_component__ as ApicartDefaultBundleApp, __vue_component__$1 as ApicartDefaultBundleCartDropdown };