@wikala/spmkt 2.31.1 → 3.0.0-beta.1

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.
Files changed (132) hide show
  1. package/MIGRATION_GUIDE.md +310 -0
  2. package/api/product.js +1 -0
  3. package/api/request.js +12 -6
  4. package/api/user.js +1 -1
  5. package/components/Account/AccountDashboard.vue +101 -101
  6. package/components/Account/AccountStore.js +57 -31
  7. package/components/Account/AffiliateReport.vue +56 -60
  8. package/components/Account/{OrderDetail.vue → Orders/OrderDetail.vue} +44 -30
  9. package/components/Account/Orders/Orders.vue +124 -0
  10. package/components/Account/{AccountSettings.vue → Settings/AccountSettings.vue} +4 -4
  11. package/components/Account/Settings/ChangeEmail.vue +136 -0
  12. package/components/Account/Settings/ChangeName.vue +82 -0
  13. package/components/Account/Settings/ChangePassword.vue +91 -0
  14. package/components/Address/Address.vue +38 -57
  15. package/components/Address/AddressBook.vue +77 -57
  16. package/components/Address/AddressSelect.vue +94 -87
  17. package/components/Address/Edit.vue +253 -265
  18. package/components/Address/PostalCode.vue +22 -21
  19. package/components/AgeGate.vue +11 -5
  20. package/components/Auth/Login.vue +62 -44
  21. package/components/Auth/Register.vue +82 -60
  22. package/components/Auth/ResetPassword.vue +45 -30
  23. package/components/Cart/AgeVerification/AgeChecker.vue +3 -3
  24. package/components/Cart/CartBadge.vue +15 -4
  25. package/components/Cart/CartBox.vue +19 -11
  26. package/components/Cart/CartItem.vue +3 -3
  27. package/components/Cart/CartMode.vue +6 -5
  28. package/components/Cart/CartPreview.vue +24 -18
  29. package/components/Cart/CreditCard/Everyware.vue +10 -10
  30. package/components/Cart/CreditCard/ExtendedCreditCard.vue +5 -5
  31. package/components/Cart/CreditCard/SquarePay.vue +18 -16
  32. package/components/Cart/CreditCard/StandardCreditCard.vue +9 -9
  33. package/components/Cart/Delivery/Delivery.vue +16 -12
  34. package/components/Cart/Delivery/DeliveryAddress.vue +1 -1
  35. package/components/Cart/Delivery/DeliveryMethods.vue +1 -1
  36. package/components/Cart/Delivery/DeliveryOptions.vue +15 -9
  37. package/components/Cart/Delivery/DeliveryTypes.vue +8 -5
  38. package/components/Cart/Delivery/ReservationSlots.vue +14 -8
  39. package/components/Cart/Disclaimer.vue +1 -1
  40. package/components/Cart/OrderConfirmation.vue +1 -1
  41. package/components/Cart/Payment/Payment.vue +37 -33
  42. package/components/Cart/Payment/PaymentMethods.vue +6 -4
  43. package/components/Cart/ReviewAndSubmit.vue +9 -7
  44. package/components/Cart/ShoppingCart.vue +42 -31
  45. package/components/Cart/Store/actions.js +1 -1
  46. package/components/Cart/Store/getters.js +2 -1
  47. package/components/Cart/Store/index.js +1 -1
  48. package/components/Cart/Store/mutations.js +9 -7
  49. package/components/Cart/Store/state.js +2 -2
  50. package/components/Cart/UserIdentity.vue +1 -1
  51. package/components/Category/CategoryFilter.vue +128 -114
  52. package/components/Category/CategorySort.vue +44 -32
  53. package/components/Category/LoadMore.vue +39 -23
  54. package/components/DeliverTo.vue +10 -15
  55. package/components/DeliveryNotice.vue +72 -68
  56. package/components/DobInput.vue +24 -24
  57. package/components/Gmaps/GmapsAutocomplete.vue +139 -78
  58. package/components/Gmaps/GmapsLocations.vue +1 -1
  59. package/components/Gmaps/GmapsSingleLocation.vue +121 -87
  60. package/components/MobileMenu/icons/LeftArrowIcon.vue +1 -1
  61. package/components/MobileMenu/icons/MenuIcon.vue +1 -1
  62. package/components/MobileMenu/icons/RightArrowIcon.vue +1 -1
  63. package/components/ModalContainer/ModalContainer.vue +20 -13
  64. package/components/ModalContainer/index.js +62 -18
  65. package/components/Product/AddToCart.vue +237 -221
  66. package/components/Product/BoxAddToCart.vue +114 -86
  67. package/components/Product/Compare.vue +91 -49
  68. package/components/Product/CompareBox.vue +128 -123
  69. package/components/Product/Lookup.vue +92 -65
  70. package/components/Product/Photo.vue +105 -66
  71. package/components/Product/Price.vue +64 -43
  72. package/components/Product/ProductAutocomplete.vue +52 -57
  73. package/components/Product/ProductBox.vue +61 -38
  74. package/components/Product/ProductImages.vue +83 -86
  75. package/components/Product/Quantity.vue +115 -53
  76. package/components/Product/QuickView.vue +52 -45
  77. package/components/Product/RelatedProducts.vue +88 -23
  78. package/components/Product/SKU.vue +27 -8
  79. package/components/Product/Variants.vue +336 -342
  80. package/components/Product/reviews-questions/ProductQuestions.vue +226 -198
  81. package/components/Product/reviews-questions/ProductReviews.vue +122 -107
  82. package/components/Product/reviews-questions/Review.vue +54 -59
  83. package/components/Product/reviews-questions/ReviewForm.vue +222 -170
  84. package/components/Product/reviews-questions/ReviewImages.vue +197 -216
  85. package/components/Product/reviews-questions/Vote.vue +83 -57
  86. package/components/QuantityInput.vue +18 -8
  87. package/components/RangeInput.vue +15 -8
  88. package/components/Recaptcha.vue +8 -1
  89. package/components/SelectShippingCountry.vue +81 -62
  90. package/components/TimedOffer.vue +59 -74
  91. package/composables/globals.js +53 -0
  92. package/config.js +5 -2
  93. package/index.js +41 -10
  94. package/install.js +88 -0
  95. package/locales/en.json +2 -1
  96. package/locales/sr.json +2 -1
  97. package/package.json +49 -37
  98. package/utils/animate.css +50 -0
  99. package/utils/animate.js +1 -1
  100. package/utils/buefy.js +62 -0
  101. package/utils/directives.js +28 -45
  102. package/utils/event-bus.js +56 -0
  103. package/utils/filters.js +24 -7
  104. package/utils/format-date.js +17 -0
  105. package/utils/{gmaps.js → google/gmaps.js} +43 -10
  106. package/utils/{google-analytics-eec.js → google/google-analytics-eec.js} +7 -7
  107. package/utils/random-id.js +10 -0
  108. package/babel.config.js +0 -5
  109. package/components/Account/ChangeEmail.vue +0 -133
  110. package/components/Account/ChangeName.vue +0 -92
  111. package/components/Account/ChangePassword.vue +0 -94
  112. package/components/Account/CreditCards.vue +0 -18
  113. package/components/Account/Orders.vue +0 -110
  114. package/components/Account/Settings.vue +0 -18
  115. package/components/Cart/Delivery/DeliveryAddressGuest.spec.js +0 -128
  116. package/components/Cart/Delivery/DeliveryTypes.spec.js +0 -83
  117. package/components/Cart/PCIBadge/SecurityMetrics.vue +0 -11
  118. package/components/Instagram.vue +0 -49
  119. package/components/ProductImageModal.vue +0 -41
  120. package/jest.config.js +0 -16
  121. package/test/e2e/.babelrc.js +0 -8
  122. package/test/e2e/.eslintrc.js +0 -11
  123. package/test/e2e/accAuth.spec.js +0 -64
  124. package/test/e2e/ageGate.spec.js +0 -26
  125. package/test/e2e/checkout.spec.js +0 -106
  126. package/test/e2e/compare.spec.js +0 -52
  127. package/test/e2e/config/data.js +0 -21
  128. package/test/e2e/config/routes.js +0 -11
  129. package/test/e2e/region.spec.js +0 -46
  130. package/test/e2e/search.spec.js +0 -32
  131. package/tests/vueBuefy.js +0 -4
  132. package/tsconfig.json +0 -8
package/locales/sr.json CHANGED
@@ -47,6 +47,7 @@
47
47
  "city": "Grad",
48
48
  "country": "Država",
49
49
  "findStreetAddress": "",
50
+ "autocompleteUnavailable": "Pretraga adresa nije dostupna. Unesite adresu ručno.",
50
51
  "firstName": "Ime",
51
52
  "isBusiness": "Naručujem kao pravno lice",
52
53
  "lastName": "Prezime",
@@ -176,7 +177,7 @@
176
177
  "applyRange": "Primeni raspon",
177
178
  "cancel": "Odustani",
178
179
  "clear": "Očisti",
179
- "close": "",
180
+ "close": "Zatvori",
180
181
  "confirmed": "Potvrđeno",
181
182
  "days": "dana",
182
183
  "delete": "Obriši",
package/package.json CHANGED
@@ -1,60 +1,72 @@
1
1
  {
2
2
  "name": "@wikala/spmkt",
3
- "version": "2.31.1",
3
+ "version": "3.0.0-beta.1",
4
4
  "private": false,
5
5
  "description": "supermarket",
6
+ "type": "module",
6
7
  "scripts": {
7
- "serve": "vue-cli-service serve",
8
- "build": "vue-cli-service build --target lib --name @wikala/spmkt ./index.js",
9
- "test:unit": "vue-cli-service test:unit",
10
- "lint": "vue-cli-service lint"
8
+ "build": "vite build --mode lib",
9
+ "storybook": "storybook dev -p 6006",
10
+ "build-storybook": "storybook build"
11
11
  },
12
12
  "main": "index.js",
13
+ "sideEffects": [
14
+ "*.css",
15
+ "*.scss",
16
+ "./utils/custom-event-bus.js",
17
+ "./utils/google/google-analytics-eec.js"
18
+ ],
19
+ "files": [
20
+ "index.js",
21
+ "install.js",
22
+ "api.js",
23
+ "config.js",
24
+ "translations.js",
25
+ "api",
26
+ "components",
27
+ "composables",
28
+ "locales",
29
+ "utils",
30
+ "MIGRATION_GUIDE.md"
31
+ ],
13
32
  "dependencies": {
14
33
  "@googlemaps/js-api-loader": "^1.12.2",
15
- "animate.css": "^4.1.1",
16
- "buefy": "^0.9.10",
17
- "bulma-divider": "^0.2.0",
18
- "core-js": "^3.17.2",
34
+ "axios": "^1.20.0",
19
35
  "currency.js": "^2.0.4",
20
36
  "embedo": "^1.14.0",
21
- "intl-dateformat": "^0.1.4",
22
37
  "js-cookie": "^3.0.1",
23
- "scrollmonitor": "^1.2.4",
24
- "shortid": "^2.2.16",
25
- "underscore": "^1.13.1",
26
- "vue-mq": "^1.0.1",
27
- "vuex": "^3.6.2"
38
+ "mitt": "^3.0.1",
39
+ "underscore": "^1.13.1"
28
40
  },
29
41
  "devDependencies": {
30
- "@babel/plugin-proposal-optional-chaining": "^7.14.5",
31
- "@vue/cli-plugin-babel": "^4.5.13",
32
- "@vue/cli-plugin-unit-jest": "~4.5.11",
33
- "@vue/cli-service": "^4.5.13",
34
- "@vue/runtime-dom": "^3.3.8",
35
- "@vue/test-utils": "^1.3.6",
36
- "axios": "^0.21.1",
37
- "babel-plugin-transform-es2015-modules-commonjs": "^6.26.2",
38
- "bootstrap-sass": "^3.4.1",
39
- "browser-sync": "^2.26.14",
40
- "browser-sync-webpack-plugin": "^2.3.0",
41
- "cross-env": "^7.0.3",
42
- "faker": "^5.5.3",
43
- "path-override-webpack-plugin": "^0.1.2",
42
+ "@storybook/addon-docs": "^10.1.11",
43
+ "@storybook/addon-links": "^10.1.11",
44
+ "@storybook/vue3-vite": "^10.1.11",
45
+ "@vitejs/plugin-vue": "^5.2.0",
46
+ "@vue/test-utils": "^2.4.3",
47
+ "buefy": "^3.0.3",
48
+ "msw": "2.12.7",
44
49
  "prettier": "^2.3.1",
45
50
  "pretty-quick": "^3.1.0",
46
- "sass": "^1.39.0",
47
- "sass-loader": "^10.1.1",
48
- "scss": "^0.2.4",
49
- "vue": "^2.6.14",
50
- "vue-cli-plugin-jest-puppeteer": "^0.1.5",
51
- "vue-template-compiler": "^2.6.14",
52
- "webpack": "^4.46.0",
53
- "webpack-cli": "^3.3.12"
51
+ "storybook": "^10.1.11",
52
+ "vite": "^6.0.0",
53
+ "vitest": "^4.1.11",
54
+ "vue": "^3.4.0",
55
+ "vuex": "^4.1.0"
56
+ },
57
+ "peerDependencies": {
58
+ "vue": "^3.4.0",
59
+ "vuex": "^4.1.0",
60
+ "buefy": "^3.0.3"
54
61
  },
55
62
  "husky": {
56
63
  "hooks": {
57
64
  "pre-commit": "pretty-quick --staged"
58
65
  }
66
+ },
67
+ "msw": {
68
+ "workerDirectory": [
69
+ "public"
70
+ ]
59
71
  }
60
72
  }
@@ -0,0 +1,50 @@
1
+ /*
2
+ * The two animate.css (https://animate.style/, MIT) animations animateCSS() is called
3
+ * with, under animate.css's class names. A host that uses others imports animate.css.
4
+ */
5
+ .animate__animated {
6
+ animation-duration: var(--animate-duration, 1s);
7
+ animation-fill-mode: both;
8
+ }
9
+
10
+ @keyframes pulse {
11
+ from {
12
+ transform: scale3d(1, 1, 1);
13
+ }
14
+
15
+ 50% {
16
+ transform: scale3d(1.05, 1.05, 1.05);
17
+ }
18
+
19
+ to {
20
+ transform: scale3d(1, 1, 1);
21
+ }
22
+ }
23
+
24
+ .animate__pulse {
25
+ animation-name: pulse;
26
+ animation-timing-function: ease-in-out;
27
+ }
28
+
29
+ @keyframes slideInUp {
30
+ from {
31
+ transform: translate3d(0, 100%, 0);
32
+ visibility: visible;
33
+ }
34
+
35
+ to {
36
+ transform: translate3d(0, 0, 0);
37
+ }
38
+ }
39
+
40
+ .animate__slideInUp {
41
+ animation-name: slideInUp;
42
+ }
43
+
44
+ @media print, (prefers-reduced-motion: reduce) {
45
+ .animate__animated {
46
+ animation-duration: 1ms !important;
47
+ transition-duration: 1ms !important;
48
+ animation-iteration-count: 1 !important;
49
+ }
50
+ }
package/utils/animate.js CHANGED
@@ -1,4 +1,4 @@
1
- import 'animate.css'
1
+ import './animate.css'
2
2
 
3
3
  function animateCSS(element, animationName, callback) {
4
4
 
package/utils/buefy.js ADDED
@@ -0,0 +1,62 @@
1
+ import {
2
+ ConfigProgrammatic,
3
+ Autocomplete,
4
+ Button,
5
+ Carousel,
6
+ Checkbox,
7
+ Dialog,
8
+ Field,
9
+ Icon,
10
+ Input,
11
+ Loading,
12
+ Modal,
13
+ Pagination,
14
+ Progress,
15
+ Radio,
16
+ Select,
17
+ Slider,
18
+ Snackbar,
19
+ Table,
20
+ Tabs,
21
+ Toast,
22
+ Upload
23
+ } from 'buefy'
24
+
25
+ /**
26
+ * The Buefy plugins spmkt's components use (<b-*> tags and $buefy.dialog/toast/
27
+ * loading/snackbar). Installing these instead of all of Buefy keeps the ~25 unused
28
+ * components (pickers, taginput, steps, ...) out of the host's bundle. A host whose
29
+ * own templates use another one installs it itself: app.use(Tooltip).
30
+ */
31
+ export const buefyPlugins = [
32
+ Autocomplete,
33
+ Button,
34
+ Carousel,
35
+ Checkbox,
36
+ Dialog,
37
+ Field,
38
+ Icon,
39
+ Input,
40
+ Loading,
41
+ Modal,
42
+ Pagination,
43
+ Progress,
44
+ Radio,
45
+ Select,
46
+ Slider,
47
+ Snackbar,
48
+ Table,
49
+ Tabs,
50
+ Toast,
51
+ Upload
52
+ ]
53
+
54
+ // What app.use(Buefy, options) does, for buefyPlugins only
55
+ export function installBuefy(app, options = {}) {
56
+ ConfigProgrammatic.setOptions(options)
57
+ buefyPlugins.forEach((plugin) => app.use(plugin))
58
+
59
+ const buefy = app.config.globalProperties.$buefy
60
+ buefy.config = ConfigProgrammatic
61
+ buefy.globalNoticeInterval = undefined
62
+ }
@@ -1,5 +1,18 @@
1
+ /**
2
+ * Vue 3 Custom Directives
3
+ *
4
+ * Vue 3 directive lifecycle hooks:
5
+ * - created (new)
6
+ * - beforeMount (was: bind)
7
+ * - mounted (was: inserted)
8
+ * - beforeUpdate (new)
9
+ * - updated (was: componentUpdated)
10
+ * - beforeUnmount (new)
11
+ * - unmounted (was: unbind)
12
+ */
13
+
1
14
  const digitsonly = {
2
- inserted: function (el, binding, vNode) {
15
+ mounted: function (el, binding, vNode) {
3
16
  let innerInputs = el.getElementsByTagName('input')
4
17
  if (innerInputs && innerInputs[0]) {
5
18
  el = innerInputs[0]
@@ -10,30 +23,28 @@ const digitsonly = {
10
23
  if (/[a-zA-Z]+/gi.test(e.target.value)) {
11
24
  let newValue = e.target.value.replace(/[a-zA-Z]+/gi, '')
12
25
  e.target.value = newValue
13
- if (vNode.componentInstance) {
14
- //console.log('is component instance')
15
- vNode.componentInstance.$emit('input', newValue)
16
- } else {
17
- //console.log('is NOT component instance')
18
- vNode.elm.dispatchEvent(new CustomEvent('input'))
19
- }
26
+ // Vue 3: use el directly, vNode structure is different
27
+ el.dispatchEvent(new CustomEvent('input', { detail: newValue }))
20
28
  }
21
29
  }
22
30
  }
23
31
  el.addEventListener('input', handler)
32
+ // Store handler for cleanup
33
+ el.__digitsOnlyHandler__ = handler
34
+ },
35
+ unmounted: function (el) {
36
+ if (el.__digitsOnlyHandler__) {
37
+ el.removeEventListener('input', el.__digitsOnlyHandler__)
38
+ el.__digitsOnlyHandler__ = null
39
+ }
24
40
  }
25
41
  }
26
42
 
27
43
  const clickoutside = {
28
- bind: function (el, binding, vNode) {
44
+ beforeMount: function (el, binding, vNode) {
29
45
  // Provided expression must evaluate to a function.
30
46
  if (typeof binding.value !== 'function') {
31
- const compName = vNode.context.name
32
47
  let warn = `[Vue-click-outside:] provided expression '${binding.expression}' is not a function, but has to be`
33
- if (compName) {
34
- warn += `Found in component '${compName}'`
35
- }
36
-
37
48
  console.warn(warn)
38
49
  }
39
50
  // Define Handler and cache it on the element
@@ -49,7 +60,7 @@ const clickoutside = {
49
60
  document.addEventListener('click', handler)
50
61
  },
51
62
 
52
- unbind: function (el, binding) {
63
+ unmounted: function (el, binding) {
53
64
  // Remove Event Listeners
54
65
  document.removeEventListener('click', el.__vueClickOutside__)
55
66
  el.__vueClickOutside__ = null
@@ -61,36 +72,8 @@ let directives = [
61
72
  { name: 'click-outside', value: clickoutside }
62
73
  ]
63
74
 
64
- export default function registerDirectives(vue) {
75
+ export default function registerDirectives(app) {
65
76
  directives.forEach((directive) => {
66
- vue.directive(directive.name, directive.value)
77
+ app.directive(directive.name, directive.value)
67
78
  })
68
79
  }
69
-
70
- /*
71
- Vue.directive('digitsonly', {
72
- inserted: function (el, binding, vNode) {
73
- let innerInputs = el.getElementsByTagName('input')
74
- if (innerInputs && innerInputs[0]) {
75
- el = innerInputs[0]
76
- }
77
-
78
- let handler = function (e) {
79
- if (e.target) {
80
- if (/[a-zA-Z]+/gi.test(e.target.value)) {
81
- let newValue = e.target.value.replace(/[a-zA-Z]+/gi, '')
82
- e.target.value = newValue
83
- if (vNode.componentInstance) {
84
- //console.log('is component instance')
85
- vNode.componentInstance.$emit('input', newValue)
86
- } else {
87
- //console.log('is NOT component instance')
88
- vNode.elm.dispatchEvent(new CustomEvent('input'))
89
- }
90
- }
91
- }
92
- }
93
- el.addEventListener('input', handler)
94
- }
95
- })
96
- */
@@ -0,0 +1,56 @@
1
+ /**
2
+ * Event Bus for Vue 3
3
+ *
4
+ * Replaces Vue 2's $bus pattern (Vue.prototype.$bus = new Vue())
5
+ * with mitt - a tiny event emitter library.
6
+ *
7
+ * Usage:
8
+ * import { eventBus } from '@/utils/event-bus'
9
+ *
10
+ * // Emit event
11
+ * eventBus.emit('event-name', payload)
12
+ *
13
+ * // Listen to event
14
+ * eventBus.on('event-name', handler)
15
+ *
16
+ * // Remove listener
17
+ * eventBus.off('event-name', handler)
18
+ *
19
+ * // Listen once
20
+ * eventBus.once('event-name', handler)
21
+ */
22
+
23
+ import mitt from 'mitt'
24
+
25
+ const emitter = mitt()
26
+
27
+ // mitt passes a single payload to handlers; forward every argument instead,
28
+ // as Vue 2's $emit did (e.g. emit('updatePrice', price, comparePrice))
29
+ emitter.emit = (type, ...args) => {
30
+ ;(emitter.all.get(type) || []).slice().forEach((handler) => handler(...args))
31
+ ;(emitter.all.get('*') || []).slice().forEach((handler) => handler(type, ...args))
32
+ }
33
+
34
+ // Add a 'once' method for convenience (mitt doesn't have it built-in)
35
+ const originalOn = emitter.on.bind(emitter)
36
+ emitter.once = (type, handler) => {
37
+ const wrappedHandler = (...args) => {
38
+ handler(...args)
39
+ emitter.off(type, wrappedHandler)
40
+ }
41
+ originalOn(type, wrappedHandler)
42
+ }
43
+
44
+ export const eventBus = emitter
45
+
46
+ // Vue 3 plugin to install $bus globally
47
+ export const EventBusPlugin = {
48
+ install(app) {
49
+ app.config.globalProperties.$bus = eventBus
50
+
51
+ // Also provide for Composition API usage
52
+ app.provide('eventBus', eventBus)
53
+ }
54
+ }
55
+
56
+ export default eventBus
package/utils/filters.js CHANGED
@@ -1,3 +1,12 @@
1
+ /**
2
+ * Vue 3 Global Filters Migration
3
+ *
4
+ * Vue 3 removed Vue.filter(). These functions can be:
5
+ * 1. Imported and used directly in components
6
+ * 2. Registered as global properties via app.config.globalProperties
7
+ * 3. Used in templates with {{ $filters.filterName(value) }}
8
+ */
9
+
1
10
  import currency from 'currency.js'
2
11
  import config from '../config'
3
12
 
@@ -82,12 +91,20 @@ export const nl2p = function (str) {
82
91
  return '<p>' + str.split('\n\n').join('</p><p>') + '</p>'
83
92
  }
84
93
 
85
- let filters = [formatMoney, formatNumber, round, hidecc, date, nl2p]
94
+ // All filters as an object for Vue 3 global properties
95
+ export const filters = {
96
+ formatMoney,
97
+ formatNumber,
98
+ round,
99
+ hidecc,
100
+ date,
101
+ nl2p
102
+ }
86
103
 
87
- export default function registerFilters(vue) {
88
- filters.forEach((filter) => {
89
- if (typeof vue.filter === 'function') {
90
- vue.filter(filter.name, filter)
91
- }
92
- })
104
+ /**
105
+ * Vue 3 Plugin to register filters as global properties
106
+ * Usage in templates: {{ $filters.formatMoney(value) }}
107
+ */
108
+ export default function registerFilters(app) {
109
+ app.config.globalProperties.$filters = filters
93
110
  }
@@ -0,0 +1,17 @@
1
+ const pad = (n) => String(n).padStart(2, '0')
2
+
3
+ /**
4
+ * Formats a date in local time, e.g. formatDate(date, 'DD.MM.YYYY HH:mm').
5
+ * Tokens: YYYY, MM, DD, HH, mm. Digits are Latin whatever the browser's locale,
6
+ * so 'YYYY-MM-DD' is safe to send to the server.
7
+ */
8
+ export default function formatDate(date, format) {
9
+ const parts = {
10
+ YYYY: date.getFullYear(),
11
+ MM: pad(date.getMonth() + 1),
12
+ DD: pad(date.getDate()),
13
+ HH: pad(date.getHours()),
14
+ mm: pad(date.getMinutes())
15
+ }
16
+ return format.replace(/YYYY|MM|DD|HH|mm/g, (token) => parts[token])
17
+ }
@@ -1,8 +1,7 @@
1
1
  import { Loader } from '@googlemaps/js-api-loader'
2
2
  import _ from 'underscore'
3
3
 
4
- const API_KEY = 'AIzaSyBiGg5anTzSl3KBp5pKg6g2wukIOcHz2CM'
5
-
4
+ let API_KEY = ''
6
5
  let MAP_OPTIONS = {
7
6
  center: {
8
7
  lat: 52.2019792,
@@ -13,6 +12,15 @@ let MAP_OPTIONS = {
13
12
  scrollwheel: false
14
13
  }
15
14
 
15
+ function configure(options) {
16
+ if (options.API_KEY) {
17
+ API_KEY = options.API_KEY
18
+ }
19
+ if (options.MAP_OPTIONS) {
20
+ MAP_OPTIONS = { ...MAP_OPTIONS, ...options.MAP_OPTIONS }
21
+ }
22
+ }
23
+
16
24
  function geocodeLatLng(latlng, map, address) {
17
25
  let geocoder = new google.maps.Geocoder()
18
26
  geocoder.geocode({ location: latlng }, (results, status) => {
@@ -78,6 +86,29 @@ function getAddressFromComponents(address, components) {
78
86
  return address
79
87
  }
80
88
 
89
+ let gmapsLoadingPromise = null
90
+ function ensureGmapsLoaded(apiKey) {
91
+ if (gmapsLoadingPromise) {
92
+ return gmapsLoadingPromise
93
+ }
94
+
95
+ if (window.google?.maps?.Map) {
96
+ return Promise.resolve()
97
+ }
98
+
99
+ const gmapsLoader = new Loader({
100
+ apiKey: apiKey || API_KEY,
101
+ version: 'weekly',
102
+ libraries: ['places', 'drawing'],
103
+ })
104
+
105
+ gmapsLoadingPromise = gmapsLoader.load().finally(() => {
106
+ gmapsLoadingPromise = null
107
+ })
108
+
109
+ return gmapsLoadingPromise
110
+ }
111
+
81
112
  async function load(vm, apiKey) {
82
113
  let gmapsLoader = new Loader({
83
114
  apiKey: apiKey ? apiKey : API_KEY,
@@ -93,12 +124,12 @@ async function load(vm, apiKey) {
93
124
  vm.loading = true
94
125
  vm.msg = 'Loading Google Maps...'
95
126
  try {
96
- await gmapsLoader.load()
127
+ await ensureGmapsLoaded(apiKey)
97
128
  vm.loading = false
98
129
  } catch (e) {
99
130
  vm.loaderFailed = true
100
131
  vm.msg = 'Cannot load Google Maps. Address and location coordinates input require Google Maps. Check your internet connection and try reloading page.'
101
- return false
132
+ console.error(e)
102
133
  }
103
134
  }
104
135
  }
@@ -222,15 +253,17 @@ function createMarker(map, lat, lng, color='red') {
222
253
  }
223
254
 
224
255
  export default {
225
- MAP_OPTIONS,
256
+ // A getter: configure() replaces the object, and components (GmapsLocations) set options on it
257
+ get MAP_OPTIONS() {
258
+ return MAP_OPTIONS
259
+ },
260
+ configure,
226
261
  createMarker,
262
+ findNearest,
227
263
  geocodeAddress,
228
264
  geocodeLatLng,
229
265
  getAddressComponent,
230
266
  getAddressFromComponents,
231
- getShapeGeoJSON,
232
- getPolygonBounds,
233
- findClosestMarker,
234
- findNearest,
235
- load
267
+ load,
268
+ ensureGmapsLoaded,
236
269
  }
@@ -8,7 +8,7 @@ class GoogleAnalyticsEEC {
8
8
 
9
9
  productView(productData) {
10
10
  //console.log('GA productView: ', productData)
11
- dataLayer.push({
11
+ window.dataLayer?.push({
12
12
  event: 'view_item',
13
13
  ecommerce: {
14
14
  items: [productData]
@@ -19,7 +19,7 @@ class GoogleAnalyticsEEC {
19
19
  signUp(source) {
20
20
  let signupSource = source || 'standard'
21
21
  console.log('dl push', 'sign_up', signupSource)
22
- dataLayer.push({
22
+ window.dataLayer?.push({
23
23
  event: 'sign_up',
24
24
  eventProps: {
25
25
  source: signupSource
@@ -39,11 +39,11 @@ class GoogleAnalyticsEEC {
39
39
  console.log('doNotTrack enabled')
40
40
  addToCartData.eventTimeout = 2000
41
41
  }
42
- dataLayer.push(addToCartData)
42
+ window.dataLayer?.push(addToCartData)
43
43
  }
44
44
 
45
45
  removeFromCart(productData) {
46
- dataLayer.push({
46
+ window.dataLayer?.push({
47
47
  event: 'remove_from_cart',
48
48
  ecommerce: {
49
49
  items: [productData]
@@ -55,14 +55,14 @@ class GoogleAnalyticsEEC {
55
55
  //step += 1 //step numbering starts from 1 in GA
56
56
  //console.log('GA EEC checkout step', step)
57
57
  if (step === 'preview') {
58
- dataLayer.push({
58
+ window.dataLayer?.push({
59
59
  event: 'begin_checkout',
60
60
  ecommerce: {
61
61
  items: payload
62
62
  }
63
63
  })
64
64
  } else {
65
- dataLayer.push({
65
+ window.dataLayer?.push({
66
66
  event: step,
67
67
  ecommerce: {
68
68
  items: payload
@@ -73,7 +73,7 @@ class GoogleAnalyticsEEC {
73
73
 
74
74
  purchase(orderData, currency) {
75
75
  console.log('purchase orderData', orderData, currency)
76
- dataLayer.push({
76
+ window.dataLayer?.push({
77
77
  event: 'purchase',
78
78
  ecommerce: {
79
79
  purchase: {
@@ -0,0 +1,10 @@
1
+ const ALPHABET = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_-'
2
+
3
+ /**
4
+ * A random id from shortid's alphabet, no longer than its 14-character ids, so it fits
5
+ * wherever the backend stored those (the checkout idempotency key). 64 symbols, so
6
+ * masking each random byte to 6 bits keeps it unbiased.
7
+ */
8
+ export default function randomId(length = 14) {
9
+ return Array.from(crypto.getRandomValues(new Uint8Array(length)), (byte) => ALPHABET[byte & 63]).join('')
10
+ }
package/babel.config.js DELETED
@@ -1,5 +0,0 @@
1
- module.exports = {
2
- presets: [
3
- '@vue/cli-plugin-babel/preset'
4
- ]
5
- }