@rocketsearch/vue-uappi 0.1.4 → 0.1.6
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/package.json +1 -1
- package/runtime/banner.js +27 -0
- package/runtime/components/RocketSearch.vue +10 -4
- package/runtime/components/banner/RocketBannerItem.vue +77 -2
- package/runtime/components/search/RocketSearchFacets.vue +20 -1
- package/runtime/css/banner.css +18 -0
- package/runtime/css/search.css +14 -0
- package/runtime/listing.js +17 -3
package/package.json
CHANGED
package/runtime/banner.js
CHANGED
|
@@ -101,6 +101,30 @@ export function pickStyles (styles, keys) {
|
|
|
101
101
|
return out;
|
|
102
102
|
}
|
|
103
103
|
|
|
104
|
+
// Vídeo no banner (ROC-420): a imagem segue sendo o pôster e o LCP.
|
|
105
|
+
function hasVideo (content) {
|
|
106
|
+
return !!(content && (content.videoUrl || content.mobileVideoUrl));
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* URL do vídeo a tocar, ou '' quando a imagem deve ficar sozinha: reduced-motion,
|
|
111
|
+
* economia de dados ou formato que o navegador não toca. Só no cliente (recebe o window).
|
|
112
|
+
*/
|
|
113
|
+
export function pickVideoUrl (content, win) {
|
|
114
|
+
if (!win || !hasVideo(content)) return '';
|
|
115
|
+
const mq = q => !!(win.matchMedia && win.matchMedia(q).matches);
|
|
116
|
+
const url = (mq(MOBILE_MEDIA) && content.mobileVideoUrl) || content.videoUrl || content.mobileVideoUrl;
|
|
117
|
+
if (mq('(prefers-reduced-motion: reduce)')) return '';
|
|
118
|
+
const conn = win.navigator && win.navigator.connection;
|
|
119
|
+
if (conn && conn.saveData) return '';
|
|
120
|
+
// Contrato da ROC-418: a chave leva a extensão real (banners/{storeId}/{uuid}.mp4|webm).
|
|
121
|
+
// Sem extensão conhecida não arrisca: canPlayType('video/mp4') aprovaria um .mov.
|
|
122
|
+
const ext = /\.(mp4|webm)(?:[?#]|$)/i.exec(url);
|
|
123
|
+
if (!ext) return '';
|
|
124
|
+
const probe = win.document.createElement('video');
|
|
125
|
+
return probe.canPlayType && probe.canPlayType('video/' + ext[1].toLowerCase()) ? url : '';
|
|
126
|
+
}
|
|
127
|
+
|
|
104
128
|
export function isHeroSlot (position) {
|
|
105
129
|
return /^(hero|fullbanner|header|top)$/i.test(String(position || ''));
|
|
106
130
|
}
|
|
@@ -129,6 +153,8 @@ export function bannerTracking (item, opts) {
|
|
|
129
153
|
slideIndex: o.slideIndex
|
|
130
154
|
};
|
|
131
155
|
if (embedded) tracking.bannerId = item.bannerId;
|
|
156
|
+
// Tipo do criativo, não do que tocou: com reduced-motion o visitante vê o pôster.
|
|
157
|
+
if (hasVideo(item.banner)) tracking.mediaType = 'video';
|
|
132
158
|
if (item.experiment) {
|
|
133
159
|
tracking.experimentId = item.experiment.experimentId;
|
|
134
160
|
tracking.variantId = item.experiment.variantId;
|
|
@@ -140,6 +166,7 @@ function baseData (t, meta) {
|
|
|
140
166
|
const data = { vitrine: t.id, showcaseId: t.id, meta };
|
|
141
167
|
if (t.slot) meta.slot = String(t.slot);
|
|
142
168
|
if (t.imageVariant) meta.imageVariant = t.imageVariant;
|
|
169
|
+
if (t.mediaType) meta.mediaType = t.mediaType;
|
|
143
170
|
if (t.bannerId != null) {
|
|
144
171
|
data.bannerId = t.bannerId;
|
|
145
172
|
meta.bannerId = t.bannerId;
|
|
@@ -74,7 +74,7 @@
|
|
|
74
74
|
<li v-for="(value, j) in facet.values || []" :key="'f-' + j" :data-alias="facet.alias">
|
|
75
75
|
<span class="option-title" :data-alias="facet.alias">
|
|
76
76
|
<span class="name" v-text="facet.alias + ':'" />
|
|
77
|
-
<span class="label" v-text="value" />
|
|
77
|
+
<span class="label" v-text="facet.type === 'rating' ? ratingLabel(value) : value" />
|
|
78
78
|
</span>
|
|
79
79
|
<button class="rocket-search__facets__selected__clear-filter" aria-label="Remover filtro" @click="clearFacet(value, facet)">
|
|
80
80
|
x
|
|
@@ -185,7 +185,7 @@ import '../css/search.css';
|
|
|
185
185
|
import RocketSearchFacets from './search/RocketSearchFacets.vue';
|
|
186
186
|
import RocketSearchPagination from './search/RocketSearchPagination.vue';
|
|
187
187
|
import { productImage, productPath, productPrice, formatCurrency } from '../uappi.js';
|
|
188
|
-
import { TRACKING_PARAMS, didYouMeanQuery, dispatchDidYouMeanClick } from '../listing.js';
|
|
188
|
+
import { TRACKING_PARAMS, didYouMeanQuery, dispatchDidYouMeanClick, ratingLabel } from '../listing.js';
|
|
189
189
|
|
|
190
190
|
// Parâmetros de campanha nunca viram filtro na busca.
|
|
191
191
|
function emptyContext () {
|
|
@@ -295,6 +295,7 @@ export default {
|
|
|
295
295
|
productPath,
|
|
296
296
|
productPrice,
|
|
297
297
|
formatCurrency,
|
|
298
|
+
ratingLabel,
|
|
298
299
|
|
|
299
300
|
// ---- Busca ----
|
|
300
301
|
|
|
@@ -401,17 +402,22 @@ export default {
|
|
|
401
402
|
// ---- Facets ----
|
|
402
403
|
|
|
403
404
|
isSelected (value, facet) {
|
|
405
|
+
// Avaliação: 0 e 1 são opções (Sem avaliações / 1 estrela ou mais), não o booleano.
|
|
406
|
+
if (facet.type === 'rating') {
|
|
407
|
+
const rating = (this.context.appliedFilters || []).find(f => f.field === facet.field);
|
|
408
|
+
return !!rating && (rating.values || []).includes(Number(value));
|
|
409
|
+
}
|
|
404
410
|
if (value === 0 || value === 1) {
|
|
405
411
|
const booleanFilter = (this.context.appliedFilters || []).find(f => f.type === 'boolean' && f.field === facet.field);
|
|
406
412
|
return !!booleanFilter && booleanFilter.value === (value === 1);
|
|
407
413
|
}
|
|
408
|
-
return (this.context.appliedFilters || []).some(f => (f.values || []).includes(value));
|
|
414
|
+
return (this.context.appliedFilters || []).some(f => f.type !== 'rating' && (f.values || []).includes(value));
|
|
409
415
|
},
|
|
410
416
|
|
|
411
417
|
clickFacet (value, facet) {
|
|
412
418
|
const selected = this.isSelected(value.value, facet);
|
|
413
419
|
this.updateQuery((query) => {
|
|
414
|
-
if (value.value === 0 || value.value === 1) {
|
|
420
|
+
if (facet.type !== 'rating' && (value.value === 0 || value.value === 1)) {
|
|
415
421
|
query[facet.label] = selected ? '' : String(value.value);
|
|
416
422
|
}
|
|
417
423
|
else {
|
|
@@ -25,6 +25,22 @@
|
|
|
25
25
|
@load="syncRatio"
|
|
26
26
|
@error="onImageError"
|
|
27
27
|
>
|
|
28
|
+
<!-- Vídeo (ROC-420) por cima do pôster; src e play() só depois do load e na tela. -->
|
|
29
|
+
<video
|
|
30
|
+
v-if="videoSrc"
|
|
31
|
+
ref="video"
|
|
32
|
+
:key="videoSrc"
|
|
33
|
+
class="rocket-search__banner__video"
|
|
34
|
+
:class="{ 'rocket-search__banner__video--playing': videoPlaying }"
|
|
35
|
+
muted
|
|
36
|
+
loop
|
|
37
|
+
playsinline
|
|
38
|
+
preload="none"
|
|
39
|
+
aria-hidden="true"
|
|
40
|
+
:style="imgStyle"
|
|
41
|
+
@playing="videoPlaying = true"
|
|
42
|
+
@error="dropVideo"
|
|
43
|
+
/>
|
|
28
44
|
</picture>
|
|
29
45
|
<!-- Texto só quando o lojista marcou showStoreText no dashboard. -->
|
|
30
46
|
<div v-if="content.showStoreText && (content.title || content.subtitle || content.ctaText)" class="rocket-search__banner__caption" :style="captionStyle">
|
|
@@ -38,7 +54,7 @@
|
|
|
38
54
|
<script>
|
|
39
55
|
import {
|
|
40
56
|
MOBILE_MEDIA, cdnResize, buildSrcset, resolveAspectRatio, hasExplicitAspectRatio, pickStyles,
|
|
41
|
-
highestMilestone, bannerTracking, bannerViewData, bannerClickData
|
|
57
|
+
highestMilestone, bannerTracking, bannerViewData, bannerClickData, pickVideoUrl
|
|
42
58
|
} from '../../banner.js';
|
|
43
59
|
|
|
44
60
|
const VIEW_THRESHOLD = 0.5;
|
|
@@ -62,7 +78,7 @@ export default {
|
|
|
62
78
|
aspectRatio: { type: String, default: '' }
|
|
63
79
|
},
|
|
64
80
|
data () {
|
|
65
|
-
return { naturalRatio: null, resizeFailed: false, mobileMedia: MOBILE_MEDIA };
|
|
81
|
+
return { naturalRatio: null, resizeFailed: false, mobileMedia: MOBILE_MEDIA, videoSrc: '', videoPlaying: false };
|
|
66
82
|
},
|
|
67
83
|
computed: {
|
|
68
84
|
content () {
|
|
@@ -125,11 +141,21 @@ export default {
|
|
|
125
141
|
else this.onImageError(); // falhou antes do mount
|
|
126
142
|
}
|
|
127
143
|
this.observeImpression();
|
|
144
|
+
// Codec, reduced-motion e saveData só se sabem no navegador; sem vídeo, fica a imagem.
|
|
145
|
+
this.setupVideo();
|
|
128
146
|
},
|
|
129
147
|
beforeUnmount () {
|
|
130
148
|
if (this.observer) this.observer.disconnect();
|
|
149
|
+
this.dropVideo();
|
|
131
150
|
clearTimeout(this.dwellTimer);
|
|
132
151
|
},
|
|
152
|
+
watch: {
|
|
153
|
+
// O pai reaproveita o componente sem :key quando a vitrine recarrega (SPA):
|
|
154
|
+
// o vídeo tem que acompanhar o banner novo, como a imagem já acompanha.
|
|
155
|
+
content () {
|
|
156
|
+
this.setupVideo();
|
|
157
|
+
}
|
|
158
|
+
},
|
|
133
159
|
methods: {
|
|
134
160
|
// Sem proporção cadastrada, a caixa reservada é um chute (3:1): corrige para a
|
|
135
161
|
// proporção real do arquivo assim que carrega — senão o cover cortaria o banner.
|
|
@@ -145,6 +171,55 @@ export default {
|
|
|
145
171
|
if (this.resize) this.resizeFailed = true;
|
|
146
172
|
},
|
|
147
173
|
|
|
174
|
+
// Toca na tela, pausa fora dela. Falha (rede, codec, autoplay bloqueado) tira o vídeo
|
|
175
|
+
// via v-if e deixa o pôster.
|
|
176
|
+
watchVideo () {
|
|
177
|
+
if (!this.videoSrc) return; // caiu entre o setup e o nextTick/load
|
|
178
|
+
if (!('IntersectionObserver' in window)) return this.startVideo();
|
|
179
|
+
this.videoObserver = new IntersectionObserver((entries) => {
|
|
180
|
+
entries.forEach((entry) => {
|
|
181
|
+
const video = this.$refs.video;
|
|
182
|
+
if (entry.isIntersecting) this.startVideo();
|
|
183
|
+
else if (video && video.getAttribute('src')) video.pause();
|
|
184
|
+
});
|
|
185
|
+
});
|
|
186
|
+
this.videoObserver.observe(this.$el);
|
|
187
|
+
},
|
|
188
|
+
|
|
189
|
+
// muted/playsinline vêm do template (o Vue aplica muted como propriedade), antes do play().
|
|
190
|
+
startVideo () {
|
|
191
|
+
const video = this.$refs.video;
|
|
192
|
+
if (!video) return;
|
|
193
|
+
if (!video.getAttribute('src')) video.setAttribute('src', this.videoSrc);
|
|
194
|
+
const p = video.play();
|
|
195
|
+
// AbortError = pause() saindo da tela no meio do play(); não é falha.
|
|
196
|
+
if (p && p.catch) p.catch((err) => { if (!err || err.name !== 'AbortError') this.dropVideo(); });
|
|
197
|
+
},
|
|
198
|
+
|
|
199
|
+
setupVideo () {
|
|
200
|
+
this.dropVideo();
|
|
201
|
+
this.videoSrc = pickVideoUrl(this.content, window);
|
|
202
|
+
if (!this.videoSrc) return;
|
|
203
|
+
if (document.readyState === 'complete') this.$nextTick(this.watchVideo);
|
|
204
|
+
else window.addEventListener('load', this.watchVideo, { once: true });
|
|
205
|
+
// A imagem troca sozinha de variante (<source media>) ao girar a tela; o vídeo não.
|
|
206
|
+
this.videoMq = window.matchMedia && window.matchMedia(MOBILE_MEDIA);
|
|
207
|
+
if (this.videoMq && this.videoMq.addEventListener) this.videoMq.addEventListener('change', this.onBreakpoint);
|
|
208
|
+
},
|
|
209
|
+
|
|
210
|
+
// Variante do vídeo deixou de valer: sai e fica o pôster certo.
|
|
211
|
+
onBreakpoint () {
|
|
212
|
+
if (pickVideoUrl(this.content, window) !== this.videoSrc) this.dropVideo();
|
|
213
|
+
},
|
|
214
|
+
|
|
215
|
+
dropVideo () {
|
|
216
|
+
this.videoSrc = '';
|
|
217
|
+
this.videoPlaying = false;
|
|
218
|
+
if (this.videoObserver) this.videoObserver.disconnect();
|
|
219
|
+
window.removeEventListener('load', this.watchVideo);
|
|
220
|
+
if (this.videoMq && this.videoMq.removeEventListener) this.videoMq.removeEventListener('change', this.onBreakpoint);
|
|
221
|
+
},
|
|
222
|
+
|
|
148
223
|
imageVariant () {
|
|
149
224
|
const narrow = window.matchMedia && window.matchMedia(MOBILE_MEDIA).matches;
|
|
150
225
|
if (narrow && this.content.mobileImageUrl) return 'mobile';
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
<li v-for="(value, j) in facet.values || []" :key="'f-' + j" :data-alias="facet.alias">
|
|
15
15
|
<span class="option-title" :data-alias="facet.alias">
|
|
16
16
|
<span class="name" v-text="facet.alias + ':'" />
|
|
17
|
-
<span class="label" v-text="value" />
|
|
17
|
+
<span class="label" v-text="facet.type === 'rating' ? ratingLabel(value) : value" />
|
|
18
18
|
</span>
|
|
19
19
|
<button class="rocket-search__facets__selected__clear-filter" @click="$emit('clear-facet', value, facet)">
|
|
20
20
|
x
|
|
@@ -73,6 +73,22 @@
|
|
|
73
73
|
:facet="facet"
|
|
74
74
|
@apply="$emit('apply-price', $event)"
|
|
75
75
|
/>
|
|
76
|
+
<ul v-else-if="facet.type === 'rating'" class="facet-rating-list">
|
|
77
|
+
<li
|
|
78
|
+
v-for="value in facet.values || []"
|
|
79
|
+
:key="value.value"
|
|
80
|
+
:data-selected="isSelected(value.value, facet)"
|
|
81
|
+
:class="{ selected: isSelected(value.value, facet) }"
|
|
82
|
+
>
|
|
83
|
+
<a href="javascript:void(0);" @click="$emit('click-facet', value, facet)">
|
|
84
|
+
<span v-if="value.value > 0" style="display:flex;align-items:center;gap:6px;">
|
|
85
|
+
<span class="rating-stars"><span v-for="n in 5" :key="n" :class="n <= value.value ? 'star-filled' : 'star-empty'">★</span></span>
|
|
86
|
+
<span class="rating-label"><span v-text="value.value" /><span v-text="ratingSuffix(value.value)" /></span>
|
|
87
|
+
</span>
|
|
88
|
+
<span v-else class="rating-label no-reviews">Sem avaliações</span>
|
|
89
|
+
</a>
|
|
90
|
+
</li>
|
|
91
|
+
</ul>
|
|
76
92
|
<!-- terms e boolean usam a mesma lista (na Linx o boolean reaproveitava o template de terms). -->
|
|
77
93
|
<ul v-else>
|
|
78
94
|
<li
|
|
@@ -110,6 +126,7 @@
|
|
|
110
126
|
<script>
|
|
111
127
|
import RocketSearchRange from './RocketSearchRange.vue';
|
|
112
128
|
import { formatCurrency } from '../../uappi.js';
|
|
129
|
+
import { ratingLabel, ratingSuffix } from '../../listing.js';
|
|
113
130
|
|
|
114
131
|
export default {
|
|
115
132
|
name: 'RocketSearchFacets',
|
|
@@ -132,6 +149,8 @@ export default {
|
|
|
132
149
|
},
|
|
133
150
|
methods: {
|
|
134
151
|
formatCurrency,
|
|
152
|
+
ratingLabel,
|
|
153
|
+
ratingSuffix,
|
|
135
154
|
// Facet booleano (ex.: Disponibilidade/hasStock) vem como 0/1 — mesmo texto do chip aplicado.
|
|
136
155
|
valueLabel (value) {
|
|
137
156
|
if (value === 0) return 'Não';
|
package/runtime/css/banner.css
CHANGED
|
@@ -21,6 +21,7 @@
|
|
|
21
21
|
color: inherit;
|
|
22
22
|
|
|
23
23
|
& .rocket-search__banner__media {
|
|
24
|
+
position: relative;
|
|
24
25
|
display: block;
|
|
25
26
|
width: 100%;
|
|
26
27
|
/* fallback p/ browser sem aspect-ratio: a imagem define a altura */
|
|
@@ -36,6 +37,23 @@
|
|
|
36
37
|
object-fit: cover;
|
|
37
38
|
}
|
|
38
39
|
|
|
40
|
+
/* Vídeo (ROC-420) por cima do pôster; só aparece quando começa a tocar, sem quadro preto. */
|
|
41
|
+
& .rocket-search__banner__video {
|
|
42
|
+
position: absolute;
|
|
43
|
+
top: 0;
|
|
44
|
+
left: 0;
|
|
45
|
+
width: 100%;
|
|
46
|
+
height: 100%;
|
|
47
|
+
object-fit: cover;
|
|
48
|
+
opacity: 0;
|
|
49
|
+
transition: opacity 0.3s;
|
|
50
|
+
pointer-events: none;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
& .rocket-search__banner__video--playing {
|
|
54
|
+
opacity: 1;
|
|
55
|
+
}
|
|
56
|
+
|
|
39
57
|
& .rocket-search__banner__caption {
|
|
40
58
|
position: absolute;
|
|
41
59
|
left: 0;
|
package/runtime/css/search.css
CHANGED
|
@@ -717,3 +717,17 @@
|
|
|
717
717
|
text-decoration: underline;
|
|
718
718
|
}
|
|
719
719
|
}
|
|
720
|
+
|
|
721
|
+
/* Faceta de avaliação (type 'rating'). */
|
|
722
|
+
.rocket-search .facet-rating-list .star-filled {
|
|
723
|
+
color: #f5a623;
|
|
724
|
+
}
|
|
725
|
+
|
|
726
|
+
.rocket-search .facet-rating-list .star-empty {
|
|
727
|
+
color: #d9d9d9;
|
|
728
|
+
}
|
|
729
|
+
|
|
730
|
+
.rocket-search .facet-rating-list li.selected .rating-label {
|
|
731
|
+
color: #232626;
|
|
732
|
+
font-weight: 700;
|
|
733
|
+
}
|
package/runtime/listing.js
CHANGED
|
@@ -21,6 +21,19 @@ function splitValues (raw) {
|
|
|
21
21
|
return String(raw || '').split(';').filter(v => v !== '');
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
+
// Faceta de avaliação (type 'rating'): opções cumulativas 5..1 e 0 = sem avaliação.
|
|
25
|
+
export function ratingSuffix (n) {
|
|
26
|
+
n = Number(n);
|
|
27
|
+
if (n === 5) return ' estrelas';
|
|
28
|
+
if (n === 1) return ' estrela ou mais';
|
|
29
|
+
return ' estrelas ou mais';
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function ratingLabel (n) {
|
|
33
|
+
n = Number(n);
|
|
34
|
+
return n === 0 ? 'Sem avaliações' : n + ratingSuffix(n);
|
|
35
|
+
}
|
|
36
|
+
|
|
24
37
|
function isForwardable (key) {
|
|
25
38
|
const lower = key.toLowerCase();
|
|
26
39
|
return !THEME_PARAMS.includes(key) && !TRACKING_PARAMS.includes(lower) && lower.indexOf('utm_') !== 0;
|
|
@@ -66,10 +79,11 @@ function facetValues (facet, query, path) {
|
|
|
66
79
|
const active = splitValues(query[facet.label]);
|
|
67
80
|
return (facet.values || []).map((v, index) => {
|
|
68
81
|
const value = String(v.value);
|
|
82
|
+
const label = facet.type === 'rating' ? ratingLabel(v.value) : value;
|
|
69
83
|
return {
|
|
70
84
|
id: index + 1,
|
|
71
|
-
nome:
|
|
72
|
-
label
|
|
85
|
+
nome: label,
|
|
86
|
+
label,
|
|
73
87
|
imagem: '',
|
|
74
88
|
imagemOriginal: '',
|
|
75
89
|
ordem: index,
|
|
@@ -109,7 +123,7 @@ export function toUappiListing (response, products, rawQuery, options) {
|
|
|
109
123
|
return;
|
|
110
124
|
}
|
|
111
125
|
// Disponibilidade (0/1) não tem par na listagem da Uappi.
|
|
112
|
-
if (facet.type !== 'terms' || facet.field === 'hasStock' || !(facet.values || []).length) return;
|
|
126
|
+
if ((facet.type !== 'terms' && facet.type !== 'rating') || facet.field === 'hasStock' || !(facet.values || []).length) return;
|
|
113
127
|
const values = facetValues(facet, query, path);
|
|
114
128
|
if (facet.field === 'brand.name') marcas.push(...values);
|
|
115
129
|
else atributos.push({ id: index + 1, nome: facet.label, tipo: 'texto', campo: facet.field, valores: values });
|