@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.
- package/MIGRATION_GUIDE.md +310 -0
- package/api/product.js +1 -0
- package/api/request.js +12 -6
- package/api/user.js +1 -1
- package/components/Account/AccountDashboard.vue +101 -101
- package/components/Account/AccountStore.js +57 -31
- package/components/Account/AffiliateReport.vue +56 -60
- package/components/Account/{OrderDetail.vue → Orders/OrderDetail.vue} +44 -30
- package/components/Account/Orders/Orders.vue +124 -0
- package/components/Account/{AccountSettings.vue → Settings/AccountSettings.vue} +4 -4
- package/components/Account/Settings/ChangeEmail.vue +136 -0
- package/components/Account/Settings/ChangeName.vue +82 -0
- package/components/Account/Settings/ChangePassword.vue +91 -0
- package/components/Address/Address.vue +38 -57
- package/components/Address/AddressBook.vue +77 -57
- package/components/Address/AddressSelect.vue +94 -87
- package/components/Address/Edit.vue +253 -265
- package/components/Address/PostalCode.vue +22 -21
- package/components/AgeGate.vue +11 -5
- package/components/Auth/Login.vue +62 -44
- package/components/Auth/Register.vue +82 -60
- package/components/Auth/ResetPassword.vue +45 -30
- package/components/Cart/AgeVerification/AgeChecker.vue +3 -3
- package/components/Cart/CartBadge.vue +15 -4
- package/components/Cart/CartBox.vue +19 -11
- package/components/Cart/CartItem.vue +3 -3
- package/components/Cart/CartMode.vue +6 -5
- package/components/Cart/CartPreview.vue +24 -18
- package/components/Cart/CreditCard/Everyware.vue +10 -10
- package/components/Cart/CreditCard/ExtendedCreditCard.vue +5 -5
- package/components/Cart/CreditCard/SquarePay.vue +18 -16
- package/components/Cart/CreditCard/StandardCreditCard.vue +9 -9
- package/components/Cart/Delivery/Delivery.vue +16 -12
- package/components/Cart/Delivery/DeliveryAddress.vue +1 -1
- package/components/Cart/Delivery/DeliveryMethods.vue +1 -1
- package/components/Cart/Delivery/DeliveryOptions.vue +15 -9
- package/components/Cart/Delivery/DeliveryTypes.vue +8 -5
- package/components/Cart/Delivery/ReservationSlots.vue +14 -8
- package/components/Cart/Disclaimer.vue +1 -1
- package/components/Cart/OrderConfirmation.vue +1 -1
- package/components/Cart/Payment/Payment.vue +37 -33
- package/components/Cart/Payment/PaymentMethods.vue +6 -4
- package/components/Cart/ReviewAndSubmit.vue +9 -7
- package/components/Cart/ShoppingCart.vue +42 -31
- package/components/Cart/Store/actions.js +1 -1
- package/components/Cart/Store/getters.js +2 -1
- package/components/Cart/Store/index.js +1 -1
- package/components/Cart/Store/mutations.js +9 -7
- package/components/Cart/Store/state.js +2 -2
- package/components/Cart/UserIdentity.vue +1 -1
- package/components/Category/CategoryFilter.vue +128 -114
- package/components/Category/CategorySort.vue +44 -32
- package/components/Category/LoadMore.vue +39 -23
- package/components/DeliverTo.vue +10 -15
- package/components/DeliveryNotice.vue +72 -68
- package/components/DobInput.vue +24 -24
- package/components/Gmaps/GmapsAutocomplete.vue +139 -78
- package/components/Gmaps/GmapsLocations.vue +1 -1
- package/components/Gmaps/GmapsSingleLocation.vue +121 -87
- package/components/MobileMenu/icons/LeftArrowIcon.vue +1 -1
- package/components/MobileMenu/icons/MenuIcon.vue +1 -1
- package/components/MobileMenu/icons/RightArrowIcon.vue +1 -1
- package/components/ModalContainer/ModalContainer.vue +20 -13
- package/components/ModalContainer/index.js +62 -18
- package/components/Product/AddToCart.vue +237 -221
- package/components/Product/BoxAddToCart.vue +114 -86
- package/components/Product/Compare.vue +91 -49
- package/components/Product/CompareBox.vue +128 -123
- package/components/Product/Lookup.vue +92 -65
- package/components/Product/Photo.vue +105 -66
- package/components/Product/Price.vue +64 -43
- package/components/Product/ProductAutocomplete.vue +52 -57
- package/components/Product/ProductBox.vue +61 -38
- package/components/Product/ProductImages.vue +83 -86
- package/components/Product/Quantity.vue +115 -53
- package/components/Product/QuickView.vue +52 -45
- package/components/Product/RelatedProducts.vue +88 -23
- package/components/Product/SKU.vue +27 -8
- package/components/Product/Variants.vue +336 -342
- package/components/Product/reviews-questions/ProductQuestions.vue +226 -198
- package/components/Product/reviews-questions/ProductReviews.vue +122 -107
- package/components/Product/reviews-questions/Review.vue +54 -59
- package/components/Product/reviews-questions/ReviewForm.vue +222 -170
- package/components/Product/reviews-questions/ReviewImages.vue +197 -216
- package/components/Product/reviews-questions/Vote.vue +83 -57
- package/components/QuantityInput.vue +18 -8
- package/components/RangeInput.vue +15 -8
- package/components/Recaptcha.vue +8 -1
- package/components/SelectShippingCountry.vue +81 -62
- package/components/TimedOffer.vue +59 -74
- package/composables/globals.js +53 -0
- package/config.js +5 -2
- package/index.js +41 -10
- package/install.js +88 -0
- package/locales/en.json +2 -1
- package/locales/sr.json +2 -1
- package/package.json +49 -37
- package/utils/animate.css +50 -0
- package/utils/animate.js +1 -1
- package/utils/buefy.js +62 -0
- package/utils/directives.js +28 -45
- package/utils/event-bus.js +56 -0
- package/utils/filters.js +24 -7
- package/utils/format-date.js +17 -0
- package/utils/{gmaps.js → google/gmaps.js} +43 -10
- package/utils/{google-analytics-eec.js → google/google-analytics-eec.js} +7 -7
- package/utils/random-id.js +10 -0
- package/babel.config.js +0 -5
- package/components/Account/ChangeEmail.vue +0 -133
- package/components/Account/ChangeName.vue +0 -92
- package/components/Account/ChangePassword.vue +0 -94
- package/components/Account/CreditCards.vue +0 -18
- package/components/Account/Orders.vue +0 -110
- package/components/Account/Settings.vue +0 -18
- package/components/Cart/Delivery/DeliveryAddressGuest.spec.js +0 -128
- package/components/Cart/Delivery/DeliveryTypes.spec.js +0 -83
- package/components/Cart/PCIBadge/SecurityMetrics.vue +0 -11
- package/components/Instagram.vue +0 -49
- package/components/ProductImageModal.vue +0 -41
- package/jest.config.js +0 -16
- package/test/e2e/.babelrc.js +0 -8
- package/test/e2e/.eslintrc.js +0 -11
- package/test/e2e/accAuth.spec.js +0 -64
- package/test/e2e/ageGate.spec.js +0 -26
- package/test/e2e/checkout.spec.js +0 -106
- package/test/e2e/compare.spec.js +0 -52
- package/test/e2e/config/data.js +0 -21
- package/test/e2e/config/routes.js +0 -11
- package/test/e2e/region.spec.js +0 -46
- package/test/e2e/search.spec.js +0 -32
- package/tests/vueBuefy.js +0 -4
- package/tsconfig.json +0 -8
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<template>
|
|
2
|
-
<b-modal
|
|
2
|
+
<b-modal v-model="showModal" :can-cancel="false" has-modal-card>
|
|
3
3
|
<div class="modal-card" v-if="locale">
|
|
4
4
|
<header class="modal-card-head">
|
|
5
5
|
<p v-if="availableLocalSite" class="modal-card-title">
|
|
@@ -12,14 +12,14 @@
|
|
|
12
12
|
<div class="modal-card-body delivery-notice">
|
|
13
13
|
<div>
|
|
14
14
|
<div v-if="availableLocalSite">
|
|
15
|
-
<div style="margin-bottom:1rem">
|
|
15
|
+
<div style="margin-bottom: 1rem">
|
|
16
16
|
We are showing you items that might not be available in your current location. To see items that ship to
|
|
17
17
|
<strong>{{ locale.country }}</strong
|
|
18
18
|
>, please visit <a :href="availableLocalSite[2]">{{ availableLocalSite[3] }}</a>
|
|
19
19
|
</div>
|
|
20
20
|
</div>
|
|
21
21
|
<div v-else>
|
|
22
|
-
<div style="margin-bottom:1rem">
|
|
22
|
+
<div style="margin-bottom: 1rem">
|
|
23
23
|
Unfortunately, we do not ship to your current location. Feel free to stick around and explore.
|
|
24
24
|
</div>
|
|
25
25
|
</div>
|
|
@@ -28,12 +28,14 @@
|
|
|
28
28
|
<footer class="modal-card-foot">
|
|
29
29
|
<div>
|
|
30
30
|
<div v-if="availableLocalSite">
|
|
31
|
-
<button class="button is-primary" @click="gotoAvailableLocalSite">
|
|
31
|
+
<button class="button is-primary" @click="gotoAvailableLocalSite">
|
|
32
|
+
Go to {{ initialState.site_name }} {{ availableLocalSite[1] }}
|
|
33
|
+
</button>
|
|
32
34
|
<button class="button is-outlined" @click="accept">Stay on {{ currentSite }}</button>
|
|
33
35
|
</div>
|
|
34
36
|
<div v-else>
|
|
35
37
|
<div>
|
|
36
|
-
<button class="button is-primary" style="width: 10rem
|
|
38
|
+
<button class="button is-primary" style="width: 10rem" @click="accept">OK</button>
|
|
37
39
|
</div>
|
|
38
40
|
</div>
|
|
39
41
|
</div>
|
|
@@ -42,78 +44,80 @@
|
|
|
42
44
|
</b-modal>
|
|
43
45
|
</template>
|
|
44
46
|
|
|
45
|
-
<script>
|
|
47
|
+
<script setup>
|
|
48
|
+
import { ref, computed, onMounted } from 'vue'
|
|
49
|
+
import { useInitialState } from '../composables/globals'
|
|
46
50
|
import Cookie from 'js-cookie'
|
|
51
|
+
import { eventBus } from '../utils/event-bus'
|
|
47
52
|
|
|
48
|
-
|
|
49
|
-
name: 'DeliveryNotice',
|
|
50
|
-
data() {
|
|
51
|
-
return {
|
|
52
|
-
showModal: false,
|
|
53
|
-
remember: true,
|
|
54
|
-
locale: null,
|
|
55
|
-
cookieName: 'delivery-notice',
|
|
56
|
-
currentSite: window.location.host,
|
|
57
|
-
}
|
|
58
|
-
},
|
|
53
|
+
const initialState = useInitialState()
|
|
59
54
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
} else {
|
|
65
|
-
return this.notices['DEFAULT']
|
|
66
|
-
}
|
|
67
|
-
},
|
|
55
|
+
const showModal = ref(false)
|
|
56
|
+
const locale = ref(null)
|
|
57
|
+
const cookieName = 'delivery-notice'
|
|
58
|
+
const currentSite = ref(typeof window !== 'undefined' ? window.location.host : '')
|
|
68
59
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
} else {
|
|
79
|
-
return null
|
|
80
|
-
}
|
|
81
|
-
},
|
|
60
|
+
const notice = computed(() => {
|
|
61
|
+
// This would need notices object from initialState
|
|
62
|
+
if (initialState && initialState.notices && locale.value?.country_iso) {
|
|
63
|
+
return initialState.notices[locale.value.country_iso]
|
|
64
|
+
}
|
|
65
|
+
return initialState.notices?.['DEFAULT'] || null
|
|
66
|
+
})
|
|
82
67
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
return false
|
|
68
|
+
const availableLocalSite = computed(() => {
|
|
69
|
+
const availableSites = initialState.localized_version?.available
|
|
70
|
+
if (availableSites && availableSites.length > 0) {
|
|
71
|
+
for (let i = 0; i < availableSites.length; i++) {
|
|
72
|
+
if (locale.value && availableSites[i][0] === locale.value.country_iso) {
|
|
73
|
+
const siteCopy = [...availableSites[i]]
|
|
74
|
+
siteCopy.push(new URL(siteCopy[2]).host)
|
|
75
|
+
return siteCopy
|
|
92
76
|
}
|
|
93
|
-
|
|
94
|
-
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
return null
|
|
80
|
+
})
|
|
95
81
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
82
|
+
const gotoAvailableLocalSite = () => {
|
|
83
|
+
if (!availableLocalSite.value) {
|
|
84
|
+
return false
|
|
85
|
+
}
|
|
86
|
+
window.location.href = availableLocalSite.value[2]
|
|
87
|
+
}
|
|
102
88
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
89
|
+
const accept = () => {
|
|
90
|
+
Cookie.set(cookieName, 'yes')
|
|
91
|
+
showModal.value = false
|
|
92
|
+
eventBus.emit('showAgeGate')
|
|
93
|
+
}
|
|
106
94
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
window.location.href.indexOf('privacy-policy') === -1
|
|
114
|
-
) {
|
|
115
|
-
this.showModal = true
|
|
95
|
+
const attachShowModalEvent = () => {
|
|
96
|
+
eventBus.on('showDeliveryNotice', (pl) => {
|
|
97
|
+
if(pl === null) {
|
|
98
|
+
locale.value = null
|
|
99
|
+
showModal.value = false
|
|
100
|
+
return
|
|
116
101
|
}
|
|
117
|
-
|
|
102
|
+
locale.value = pl;
|
|
103
|
+
showModal.value = true
|
|
104
|
+
})
|
|
118
105
|
}
|
|
106
|
+
|
|
107
|
+
onMounted(() => {
|
|
108
|
+
attachShowModalEvent()
|
|
109
|
+
locale.value = initialState.lc
|
|
110
|
+
const isAccepted = Cookie.get(cookieName)
|
|
111
|
+
|
|
112
|
+
if (
|
|
113
|
+
isAccepted !== 'yes' &&
|
|
114
|
+
initialState.localized_version &&
|
|
115
|
+
initialState.localized_version.current &&
|
|
116
|
+
locale.value?.country_iso !== initialState.localized_version.current.country_iso &&
|
|
117
|
+
window.location.href.indexOf('terms-of-use') === -1 &&
|
|
118
|
+
window.location.href.indexOf('privacy-policy') === -1
|
|
119
|
+
) {
|
|
120
|
+
showModal.value = true
|
|
121
|
+
}
|
|
122
|
+
})
|
|
119
123
|
</script>
|
package/components/DobInput.vue
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
<div class="dob-container">
|
|
3
3
|
<div :class="['dob-field', { 'dob-field-focus': fieldFocusActive }, { 'dob-field-error': error }]">
|
|
4
4
|
<label class="label">{{ label }}</label>
|
|
5
|
-
<div class="control is-clearfix dob-date">
|
|
5
|
+
<div class="control is-flex is-clearfix dob-date">
|
|
6
6
|
<div>
|
|
7
7
|
<input
|
|
8
8
|
ref="mm"
|
|
@@ -70,7 +70,7 @@
|
|
|
70
70
|
</template>
|
|
71
71
|
|
|
72
72
|
<script>
|
|
73
|
-
import formatDate from '
|
|
73
|
+
import formatDate from '../utils/format-date'
|
|
74
74
|
|
|
75
75
|
const getAge = (dateOfBirth, dateToCalculate = new Date()) => {
|
|
76
76
|
const dob = new Date(dateOfBirth).getTime()
|
|
@@ -91,7 +91,7 @@ export default {
|
|
|
91
91
|
type: String,
|
|
92
92
|
default: ''
|
|
93
93
|
},
|
|
94
|
-
|
|
94
|
+
modelValue: {
|
|
95
95
|
type: String,
|
|
96
96
|
default: ''
|
|
97
97
|
},
|
|
@@ -101,6 +101,8 @@ export default {
|
|
|
101
101
|
}
|
|
102
102
|
},
|
|
103
103
|
|
|
104
|
+
emits: ['update:modelValue'],
|
|
105
|
+
|
|
104
106
|
data() {
|
|
105
107
|
return {
|
|
106
108
|
fieldFocusActive: false,
|
|
@@ -112,9 +114,11 @@ export default {
|
|
|
112
114
|
},
|
|
113
115
|
|
|
114
116
|
watch: {
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
117
|
+
modelValue: {
|
|
118
|
+
handler() {
|
|
119
|
+
this.initValue()
|
|
120
|
+
},
|
|
121
|
+
immediate: true
|
|
118
122
|
}
|
|
119
123
|
},
|
|
120
124
|
|
|
@@ -157,14 +161,19 @@ export default {
|
|
|
157
161
|
|
|
158
162
|
methods: {
|
|
159
163
|
initValue() {
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
164
|
+
if (this.modelValue) {
|
|
165
|
+
const dob = new Date(this.modelValue)
|
|
166
|
+
if (!Number.isNaN(dob.getTime())) {
|
|
167
|
+
this.yyyy = dob.getUTCFullYear()
|
|
168
|
+
this.mm = dob.getUTCMonth() + 1
|
|
169
|
+
this.dd = dob.getUTCDate()
|
|
170
|
+
return
|
|
171
|
+
}
|
|
167
172
|
}
|
|
173
|
+
|
|
174
|
+
this.yyyy = ''
|
|
175
|
+
this.mm = ''
|
|
176
|
+
this.dd = ''
|
|
168
177
|
},
|
|
169
178
|
|
|
170
179
|
onFocus(e) {
|
|
@@ -179,10 +188,6 @@ export default {
|
|
|
179
188
|
|
|
180
189
|
onKeyUp(e, field) {
|
|
181
190
|
//console.log('KEYUP', field, e)
|
|
182
|
-
if(e.keyCode === 13) {
|
|
183
|
-
this.$emit('input', formatDate(this.date_of_birth, 'YYYY-MM-DD'), this.age, true)
|
|
184
|
-
return true
|
|
185
|
-
}
|
|
186
191
|
let value = ''
|
|
187
192
|
if (typeof e === 'object') {
|
|
188
193
|
value = e.target.value.replace(/\D/g, '')
|
|
@@ -193,9 +198,9 @@ export default {
|
|
|
193
198
|
this[field] = value
|
|
194
199
|
|
|
195
200
|
if (this.day && this.month && this.year) {
|
|
196
|
-
this.$emit('
|
|
201
|
+
this.$emit('update:modelValue', formatDate(this.date_of_birth, 'YYYY-MM-DD'))
|
|
197
202
|
} else {
|
|
198
|
-
this.$emit('
|
|
203
|
+
this.$emit('update:modelValue', '')
|
|
199
204
|
}
|
|
200
205
|
|
|
201
206
|
if (['Backspace', 'ArrowLeft', 'ArrowRight'].includes(e.key)) {
|
|
@@ -284,11 +289,6 @@ export default {
|
|
|
284
289
|
}
|
|
285
290
|
this[field] = value
|
|
286
291
|
}
|
|
287
|
-
},
|
|
288
|
-
|
|
289
|
-
mounted() {
|
|
290
|
-
//console.log(this.value)
|
|
291
|
-
this.initValue()
|
|
292
292
|
}
|
|
293
293
|
}
|
|
294
294
|
</script>
|
|
@@ -7,99 +7,160 @@
|
|
|
7
7
|
<b-field
|
|
8
8
|
:label="label"
|
|
9
9
|
label-position="inside"
|
|
10
|
+
:type="fetchFailed ? 'is-danger' : ''"
|
|
11
|
+
:message="fetchFailed ? $t('address.autocompleteUnavailable') : ''"
|
|
10
12
|
>
|
|
11
|
-
|
|
13
|
+
<!-- append-to-body: the address modal's body scrolls and would clip the dropdown -->
|
|
14
|
+
<b-autocomplete
|
|
15
|
+
v-model="pacInput"
|
|
16
|
+
append-to-body
|
|
17
|
+
:data="suggestions"
|
|
18
|
+
:loading="isFetching"
|
|
19
|
+
:placeholder="placeholderText"
|
|
20
|
+
:custom-formatter="formatSuggestion"
|
|
21
|
+
@typing="fetchSuggestions"
|
|
22
|
+
@select="selectSuggestion"
|
|
23
|
+
>
|
|
24
|
+
<template #default="{ option }">
|
|
25
|
+
<strong>{{ option.mainText?.toString() }}</strong>
|
|
26
|
+
<small v-if="option.secondaryText" class="ml-1">{{ option.secondaryText.toString() }}</small>
|
|
27
|
+
</template>
|
|
28
|
+
</b-autocomplete>
|
|
12
29
|
</b-field>
|
|
13
30
|
</template>
|
|
14
31
|
</div>
|
|
15
32
|
</template>
|
|
16
33
|
|
|
17
|
-
<script>
|
|
34
|
+
<script setup>
|
|
35
|
+
import { ref } from 'vue'
|
|
36
|
+
import _ from 'underscore'
|
|
37
|
+
// Defines window.customEventBus, which hosts call to announce that Maps has loaded
|
|
18
38
|
import '../../utils/custom-event-bus'
|
|
19
|
-
import gmaps from '../../utils/gmaps'
|
|
20
|
-
|
|
21
|
-
import addressSchema from '../Address/address.schema'
|
|
22
|
-
|
|
23
|
-
export default {
|
|
24
|
-
name: 'GmapsAutocomplete',
|
|
25
|
-
|
|
26
|
-
props: {
|
|
27
|
-
label: {
|
|
28
|
-
type: String,
|
|
29
|
-
default: 'Enter a street address'
|
|
30
|
-
},
|
|
31
|
-
placeholderText: {
|
|
32
|
-
type: String,
|
|
33
|
-
default: ''
|
|
34
|
-
},
|
|
35
|
-
restrictToCountries: {
|
|
36
|
-
type: Array,
|
|
37
|
-
default: function () {
|
|
38
|
-
return []
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
},
|
|
39
|
+
import gmaps from '../../utils/google/gmaps'
|
|
40
|
+
import { addressSchema } from '../Address/address.schema'
|
|
42
41
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
msg: '',
|
|
48
|
-
pacInput: ''
|
|
49
|
-
}
|
|
42
|
+
const props = defineProps({
|
|
43
|
+
label: {
|
|
44
|
+
type: String,
|
|
45
|
+
default: 'Enter a street address'
|
|
50
46
|
},
|
|
47
|
+
placeholderText: {
|
|
48
|
+
type: String,
|
|
49
|
+
default: ''
|
|
50
|
+
},
|
|
51
|
+
restrictToCountries: {
|
|
52
|
+
type: Array,
|
|
53
|
+
default: () => []
|
|
54
|
+
},
|
|
55
|
+
inputId: {
|
|
56
|
+
type: String,
|
|
57
|
+
default: 'pac-input'
|
|
58
|
+
}
|
|
59
|
+
})
|
|
51
60
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
61
|
+
const emit = defineEmits(['update:modelValue', 'input'])
|
|
62
|
+
|
|
63
|
+
const loading = ref(false)
|
|
64
|
+
const loaderFailed = ref(false)
|
|
65
|
+
const msg = ref('')
|
|
66
|
+
const pacInput = ref('')
|
|
67
|
+
const suggestions = ref([])
|
|
68
|
+
const isFetching = ref(false)
|
|
69
|
+
const fetchFailed = ref(false)
|
|
70
|
+
// Only the latest request may clear the spinner
|
|
71
|
+
let latestFetch = 0
|
|
72
|
+
|
|
73
|
+
// One token per typing-and-select session, so Google bills it as one session
|
|
74
|
+
let sessionToken = null
|
|
75
|
+
|
|
76
|
+
// The Maps script loads after the page module, so look the library up when it is needed
|
|
77
|
+
const placesApi = () => window.google?.maps?.places
|
|
78
|
+
|
|
79
|
+
const formatSuggestion = (prediction) => prediction.text.toString()
|
|
80
|
+
|
|
81
|
+
const countryCodes = () => props.restrictToCountries.filter(c => typeof c === 'string' && c.length > 0)
|
|
82
|
+
|
|
83
|
+
const fetchSuggestions = _.debounce(async (query) => {
|
|
84
|
+
const places = placesApi()
|
|
85
|
+
if (!query || !places?.AutocompleteSuggestion) {
|
|
86
|
+
suggestions.value = []
|
|
87
|
+
return
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
sessionToken ??= new places.AutocompleteSessionToken()
|
|
91
|
+
const request = { input: query, sessionToken }
|
|
92
|
+
const countries = countryCodes()
|
|
93
|
+
if (countries.length > 0) {
|
|
94
|
+
request.includedRegionCodes = countries
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
const fetchId = ++latestFetch
|
|
98
|
+
isFetching.value = true
|
|
99
|
+
try {
|
|
100
|
+
const response = await places.AutocompleteSuggestion.fetchAutocompleteSuggestions(request)
|
|
101
|
+
// Drop responses for text the user has already moved past
|
|
102
|
+
if (pacInput.value === query) {
|
|
103
|
+
suggestions.value = response.suggestions
|
|
104
|
+
.map(suggestion => suggestion.placePrediction)
|
|
105
|
+
.filter(Boolean)
|
|
58
106
|
}
|
|
59
|
-
|
|
107
|
+
fetchFailed.value = false
|
|
108
|
+
} catch (error) {
|
|
109
|
+
// Most often the key lacks the Places API (New), which AutocompleteSuggestion needs
|
|
110
|
+
console.error('Google Places autocomplete failed. Is the Places API (New) enabled for this key?', error)
|
|
111
|
+
suggestions.value = []
|
|
112
|
+
fetchFailed.value = true
|
|
113
|
+
} finally {
|
|
114
|
+
if (fetchId === latestFetch) {
|
|
115
|
+
isFetching.value = false
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}, 250)
|
|
60
119
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
120
|
+
// Place (New) uses longText/shortText; the shared parser expects the legacy names
|
|
121
|
+
const toLegacyComponents = (components) => components.map(component => ({
|
|
122
|
+
long_name: component.longText,
|
|
123
|
+
short_name: component.shortText,
|
|
124
|
+
types: component.types
|
|
125
|
+
}))
|
|
126
|
+
|
|
127
|
+
const selectSuggestion = async (prediction) => {
|
|
128
|
+
if (!prediction) {
|
|
129
|
+
return
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
const place = prediction.toPlace()
|
|
133
|
+
// A keystroke still waiting on the debounce would open a new, separately billed session
|
|
134
|
+
fetchSuggestions.cancel()
|
|
135
|
+
// fetchFields ends the session; the next keystroke starts a new one
|
|
136
|
+
sessionToken = null
|
|
137
|
+
suggestions.value = []
|
|
138
|
+
|
|
139
|
+
try {
|
|
140
|
+
await place.fetchFields({ fields: ['addressComponents', 'location', 'displayName'] })
|
|
141
|
+
} catch (error) {
|
|
142
|
+
console.error('Google Places details request failed', error)
|
|
143
|
+
return
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
if (!place.location) {
|
|
147
|
+
window.alert("No details available for input: '" + place.displayName + "'")
|
|
148
|
+
return
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
if (place.addressComponents) {
|
|
152
|
+
const parsedAddress = gmaps.getAddressFromComponents({ ...addressSchema }, toLegacyComponents(place.addressComponents))
|
|
153
|
+
const result = {
|
|
154
|
+
address: parsedAddress,
|
|
155
|
+
coordinates: {
|
|
156
|
+
lat: place.location.lat(),
|
|
157
|
+
lng: place.location.lng()
|
|
76
158
|
}
|
|
77
|
-
autocomplete.setFields(['address_components', 'geometry', 'icon', 'name'])
|
|
78
|
-
|
|
79
|
-
autocomplete.addListener('place_changed', function () {
|
|
80
|
-
let place = autocomplete.getPlace()
|
|
81
|
-
if (!place.geometry) {
|
|
82
|
-
window.alert("No details available for input: '" + place.name + "'")
|
|
83
|
-
return
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
if (place.address_components) {
|
|
87
|
-
address = gmaps.getAddressFromComponents(address, place.address_components)
|
|
88
|
-
vm.$emit('input', { address: address, coordinates: { lat: place.geometry.location.lat(), lng: place.geometry.location.lng() } })
|
|
89
|
-
}
|
|
90
|
-
})
|
|
91
159
|
}
|
|
92
|
-
},
|
|
93
160
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
this.loading = false
|
|
98
|
-
this.init()
|
|
99
|
-
})
|
|
100
|
-
if(window.google) {
|
|
101
|
-
this.init()
|
|
102
|
-
}
|
|
161
|
+
// Emit both for backwards compatibility and Vue 3 v-model
|
|
162
|
+
emit('input', result)
|
|
163
|
+
emit('update:modelValue', result)
|
|
103
164
|
}
|
|
104
165
|
}
|
|
105
166
|
</script>
|
|
@@ -35,7 +35,7 @@ import _ from 'underscore'
|
|
|
35
35
|
|
|
36
36
|
import { formatNumber } from '../../utils/filters'
|
|
37
37
|
import '../../utils/custom-event-bus'
|
|
38
|
-
import gmaps from '../../utils/gmaps'
|
|
38
|
+
import gmaps from '../../utils/google/gmaps'
|
|
39
39
|
import { Address } from '../../api'
|
|
40
40
|
|
|
41
41
|
import GmapsAutocomplete from './GmapsAutocomplete'
|