@rocketsearch/vue-uappi 0.1.9 → 0.2.0
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/README.md +3 -0
- package/index.js +2 -0
- package/package.json +1 -1
- package/runtime/components/RocketShowcase.vue +104 -5
- package/runtime/css/showcase.css +57 -0
- package/runtime/tabs.js +37 -0
package/README.md
CHANGED
|
@@ -27,6 +27,9 @@ optimizeDeps: { exclude: ['@rocketsearch/vue-uappi'] }
|
|
|
27
27
|
Use os componentes em PascalCase (`<RocketSearch>`, `<RocketShowcase position="top">`): o tema pode ter
|
|
28
28
|
`isCustomElement` para tags com hífen.
|
|
29
29
|
|
|
30
|
+
Vitrines em abas: `showcaseTabs: true` (ou `['top']`, só nessas posições) no `app.use` junta as vitrines da mesma
|
|
31
|
+
posição numa barra de abas; a prop `tabs` / `:tabs="false"` do `<RocketShowcase>` vence a opção.
|
|
32
|
+
|
|
30
33
|
Landing page ("Personalizado" no painel): `<RocketLanding>` mostra todas as vitrines da landing, na ordem do
|
|
31
34
|
painel. O identificador vem do nome da rota (`/black-friday` → `black-friday`) ou de `custom-key="..."`.
|
|
32
35
|
Banners da landing: `<RocketBanner page-type="custom" />`, com a mesma regra do identificador.
|
package/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
<template>
|
|
2
2
|
<div
|
|
3
|
-
v-if="
|
|
4
|
-
:class="['rocket-search', { 'rocket-search--empty':
|
|
3
|
+
v-if="!empty || debug"
|
|
4
|
+
:class="['rocket-search', { 'rocket-search--empty': empty, 'rocket-search--stacked': stacked, 'rocket-search__showcase-tabs': tabsView.bar }]"
|
|
5
5
|
:data-rocket-showcase-position="stacked ? null : position"
|
|
6
6
|
>
|
|
7
7
|
<div v-if="loading" class="rocket-search__showcase rocket-search__showcase--skeleton" :style="columnsStyle">
|
|
@@ -67,6 +67,56 @@
|
|
|
67
67
|
<slot name="product" v-bind="scope" />
|
|
68
68
|
</template>
|
|
69
69
|
</RocketShowcase>
|
|
70
|
+
|
|
71
|
+
<!-- Abas (showcaseTabs): banner autônomo acima da barra; cada vitrine vira um painel que
|
|
72
|
+
carrega e mede por conta própria. Painel inativo fica montado com hidden: a impressão
|
|
73
|
+
(IntersectionObserver no root da vitrine) só sai quando a aba é aberta. -->
|
|
74
|
+
<RocketShowcase
|
|
75
|
+
v-for="item in tabBanners"
|
|
76
|
+
:key="item.id"
|
|
77
|
+
:position="position"
|
|
78
|
+
:page-type="pageType"
|
|
79
|
+
:custom-key="customKey"
|
|
80
|
+
:showcase-id="item.id"
|
|
81
|
+
:media-size="mediaSize"
|
|
82
|
+
stacked
|
|
83
|
+
/>
|
|
84
|
+
<ul v-if="tabsView.bar" ref="nav" class="rocket-search__showcase-tabs__nav" role="tablist">
|
|
85
|
+
<li v-for="(item, index) in tabsView.tabs" :key="item.id">
|
|
86
|
+
<button
|
|
87
|
+
:id="'rs-showcase-tab-' + item.id"
|
|
88
|
+
type="button"
|
|
89
|
+
role="tab"
|
|
90
|
+
:class="['rocket-search__showcase-tabs__tab', { 'is-active': item === tabsView.active }]"
|
|
91
|
+
:aria-selected="item === tabsView.active ? 'true' : 'false'"
|
|
92
|
+
:aria-controls="'rs-showcase-panel-' + item.id"
|
|
93
|
+
:tabindex="item === tabsView.active ? 0 : -1"
|
|
94
|
+
@click="selectTab(item)"
|
|
95
|
+
@keydown="onTabKey($event, index)"
|
|
96
|
+
v-text="item.name"
|
|
97
|
+
/>
|
|
98
|
+
</li>
|
|
99
|
+
</ul>
|
|
100
|
+
<RocketShowcase
|
|
101
|
+
v-for="item in tabPanels"
|
|
102
|
+
:key="item.id"
|
|
103
|
+
v-bind="panelAttrs(item)"
|
|
104
|
+
:position="position"
|
|
105
|
+
:page-type="pageType"
|
|
106
|
+
:custom-key="customKey"
|
|
107
|
+
:showcase-id="item.id"
|
|
108
|
+
:media-size="mediaSize"
|
|
109
|
+
stacked
|
|
110
|
+
@products-loaded="$emit('products-loaded', $event)"
|
|
111
|
+
@empty="emptyIds.push(item.id)"
|
|
112
|
+
>
|
|
113
|
+
<template v-if="$slots.default" #default="scope">
|
|
114
|
+
<slot v-bind="scope" />
|
|
115
|
+
</template>
|
|
116
|
+
<template v-if="$slots.product" #product="scope">
|
|
117
|
+
<slot name="product" v-bind="scope" />
|
|
118
|
+
</template>
|
|
119
|
+
</RocketShowcase>
|
|
70
120
|
</div>
|
|
71
121
|
</template>
|
|
72
122
|
|
|
@@ -79,11 +129,13 @@ import '../css/banner.css';
|
|
|
79
129
|
import RocketBannerItem from './banner/RocketBannerItem.vue';
|
|
80
130
|
import { productImage, productPath, productPrice, formatCurrency } from '../uappi.js';
|
|
81
131
|
import { isBannerItem } from '../banner.js';
|
|
132
|
+
import { tabsEnabled, splitTabs, tabsState, tabKeyIndex } from '../tabs.js';
|
|
82
133
|
|
|
83
134
|
export default {
|
|
84
135
|
name: 'RocketShowcase',
|
|
85
136
|
components: { RocketBannerItem },
|
|
86
|
-
|
|
137
|
+
// empty: o slot terminou sem nada para mostrar (o painel de aba sai da barra por ele).
|
|
138
|
+
emits: ['products-loaded', 'empty'],
|
|
87
139
|
props: {
|
|
88
140
|
// Posição cadastrada no painel (placement.position): top, middle, bottom...
|
|
89
141
|
position: { type: String, required: true },
|
|
@@ -96,12 +148,20 @@ export default {
|
|
|
96
148
|
mediaSize: { type: String, default: 'medium' },
|
|
97
149
|
// Uso interno: vitrine empilhada abaixo da primeira da posição. Sem o atributo de posição,
|
|
98
150
|
// o debug contorna a posição uma vez só.
|
|
99
|
-
stacked: { type: Boolean, default: false }
|
|
151
|
+
stacked: { type: Boolean, default: false },
|
|
152
|
+
// Vitrines da posição em abas: true/false vence a opção showcaseTabs do plugin; sem a prop, segue ela.
|
|
153
|
+
tabs: { type: Boolean, default: null }
|
|
100
154
|
},
|
|
101
155
|
data () {
|
|
102
|
-
return { showcase: null, products: [], restIds: [], loading: false, debug: false };
|
|
156
|
+
return { showcase: null, products: [], restIds: [], tabBanners: [], tabPanels: [], emptyIds: [], activeId: null, loading: false, debug: false };
|
|
103
157
|
},
|
|
104
158
|
computed: {
|
|
159
|
+
empty () {
|
|
160
|
+
return !this.showcase && !this.loading && !this.restIds.length && !this.tabPanels.length;
|
|
161
|
+
},
|
|
162
|
+
tabsView () {
|
|
163
|
+
return tabsState(this.tabPanels, this.emptyIds, this.activeId);
|
|
164
|
+
},
|
|
105
165
|
columns () {
|
|
106
166
|
const layout = (this.showcase && this.showcase.layout) || {};
|
|
107
167
|
const mobile = typeof window !== 'undefined' && window.innerWidth < 1024;
|
|
@@ -150,6 +210,16 @@ export default {
|
|
|
150
210
|
? showcases.find(s => String(s.id) === String(this.showcaseId))
|
|
151
211
|
: inPosition[0];
|
|
152
212
|
if (!showcase) return;
|
|
213
|
+
// Abas: cada vitrine vira um painel filho (carrega e mede sozinho); com menos de 2
|
|
214
|
+
// vitrines de produto não há barra e segue o render normal.
|
|
215
|
+
const split = this.showcaseId == null && tabsEnabled(this.tabs, this.$rocket.config.showcaseTabs, this.position)
|
|
216
|
+
? splitTabs(inPosition)
|
|
217
|
+
: null;
|
|
218
|
+
if (split && split.panels.length > 1) {
|
|
219
|
+
this.tabBanners = split.banners;
|
|
220
|
+
this.tabPanels = split.panels;
|
|
221
|
+
return;
|
|
222
|
+
}
|
|
153
223
|
// Posição sem showcaseId: este slot mostra a primeira e empilha as demais logo abaixo.
|
|
154
224
|
if (this.showcaseId == null) this.restIds = inPosition.slice(1).map(s => s.id);
|
|
155
225
|
// Banner autônomo: render direto, sem produtos, skeleton nem impressão de vitrine
|
|
@@ -175,10 +245,39 @@ export default {
|
|
|
175
245
|
}
|
|
176
246
|
finally {
|
|
177
247
|
this.loading = false;
|
|
248
|
+
if (this.empty) this.$emit('empty');
|
|
178
249
|
}
|
|
179
250
|
this.$nextTick(this.observeImpression);
|
|
180
251
|
},
|
|
181
252
|
|
|
253
|
+
panelAttrs (item) {
|
|
254
|
+
const view = this.tabsView;
|
|
255
|
+
if (!view.bar) return {};
|
|
256
|
+
return {
|
|
257
|
+
id: 'rs-showcase-panel-' + item.id,
|
|
258
|
+
class: 'rocket-search__showcase-tabs__panel',
|
|
259
|
+
role: 'tabpanel',
|
|
260
|
+
'aria-labelledby': 'rs-showcase-tab-' + item.id,
|
|
261
|
+
hidden: item !== view.active
|
|
262
|
+
};
|
|
263
|
+
},
|
|
264
|
+
|
|
265
|
+
selectTab (item) {
|
|
266
|
+
this.activeId = item.id;
|
|
267
|
+
// Carrossel do tema no slot (Swiper etc.) iniciado com o painel escondido mede largura 0:
|
|
268
|
+
// o resize faz ele recalcular. O trilho padrão (scroll nativo) não precisa.
|
|
269
|
+
this.$nextTick(() => window.dispatchEvent(new Event('resize')));
|
|
270
|
+
},
|
|
271
|
+
|
|
272
|
+
onTabKey (event, index) {
|
|
273
|
+
const tabs = this.tabsView.tabs;
|
|
274
|
+
const next = tabKeyIndex(event.key, index, tabs.length);
|
|
275
|
+
if (next < 0) return;
|
|
276
|
+
event.preventDefault();
|
|
277
|
+
this.selectTab(tabs[next]);
|
|
278
|
+
this.$refs.nav.querySelectorAll('[role="tab"]')[next].focus();
|
|
279
|
+
},
|
|
280
|
+
|
|
182
281
|
experimentData (data) {
|
|
183
282
|
const exp = this.showcase.experiment;
|
|
184
283
|
if (exp) {
|
package/runtime/css/showcase.css
CHANGED
|
@@ -59,3 +59,60 @@
|
|
|
59
59
|
}
|
|
60
60
|
}
|
|
61
61
|
|
|
62
|
+
/* Abas (showcaseTabs): a barra leva o nome de cada vitrine, então o título interno sai.
|
|
63
|
+
Visual neutro (cor do tema); a loja estiliza pelas classes. */
|
|
64
|
+
.rocket-search__showcase-tabs {
|
|
65
|
+
display: flex;
|
|
66
|
+
flex-direction: column;
|
|
67
|
+
gap: 24px;
|
|
68
|
+
|
|
69
|
+
& > .rocket-search--stacked {
|
|
70
|
+
margin-top: 0;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
& .rocket-search__showcase__title {
|
|
74
|
+
display: none;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
.rocket-search__showcase-tabs__nav {
|
|
79
|
+
display: flex;
|
|
80
|
+
gap: 24px;
|
|
81
|
+
width: fit-content;
|
|
82
|
+
max-width: 100%;
|
|
83
|
+
margin: 0 auto;
|
|
84
|
+
padding: 0;
|
|
85
|
+
list-style: none;
|
|
86
|
+
overflow-x: auto;
|
|
87
|
+
scrollbar-width: none;
|
|
88
|
+
|
|
89
|
+
&::-webkit-scrollbar {
|
|
90
|
+
display: none;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
& > li {
|
|
94
|
+
flex: 0 0 auto;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
.rocket-search__showcase-tabs__tab {
|
|
99
|
+
padding: 8px 0;
|
|
100
|
+
border: 0;
|
|
101
|
+
border-bottom: 2px solid transparent;
|
|
102
|
+
background: none;
|
|
103
|
+
color: inherit;
|
|
104
|
+
font: inherit;
|
|
105
|
+
cursor: pointer;
|
|
106
|
+
opacity: 0.6;
|
|
107
|
+
|
|
108
|
+
&[aria-selected="true"] {
|
|
109
|
+
border-bottom-color: currentColor;
|
|
110
|
+
font-weight: 700;
|
|
111
|
+
opacity: 1;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/* O tema pode forçar display no root da vitrine; a aba inativa precisa sumir mesmo assim. */
|
|
116
|
+
.rocket-search__showcase-tabs__panel[hidden] {
|
|
117
|
+
display: none !important;
|
|
118
|
+
}
|
package/runtime/tabs.js
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Vitrines em abas (showcaseTabs, ROC-795) — partes puras; o markup fica no RocketShowcase.vue.
|
|
3
|
+
* Mesmo contrato do buildShowcaseTabs de linxecommerce/2.0.0/src/js/rs-showcase.js.
|
|
4
|
+
* Cópia de packages/nuxt-uappi/runtime/tabs.js — correção aqui vale lá também.
|
|
5
|
+
*/
|
|
6
|
+
import { isBannerItem } from './banner.js';
|
|
7
|
+
|
|
8
|
+
// A prop `tabs` do slot (true/false) vence a opção do plugin. Opção: true = todas as posições;
|
|
9
|
+
// ['hero', 'top'] (ou "hero,top") = só nelas; ausente/false = desligado.
|
|
10
|
+
export function tabsEnabled (prop, setting, position) {
|
|
11
|
+
if (typeof prop === 'boolean') return prop;
|
|
12
|
+
if (setting === true || setting === 'true') return true;
|
|
13
|
+
const list = Array.isArray(setting) ? setting : typeof setting === 'string' ? setting.split(',') : [];
|
|
14
|
+
return list.some(p => String(p).trim() === position);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
// Banner autônomo fica fora das abas (acima da barra); vitrine sem produto nem vira aba.
|
|
18
|
+
// A ordem da API é mantida.
|
|
19
|
+
export function splitTabs (showcases) {
|
|
20
|
+
return {
|
|
21
|
+
banners: showcases.filter(isBannerItem),
|
|
22
|
+
panels: showcases.filter(s => !isBannerItem(s) && (s.products || []).length > 0)
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// Painel que terminou vazio (sem produto ativo na Uappi) sai da barra; a ativa é a escolhida
|
|
27
|
+
// ou a primeira que sobrou; com menos de 2 não há barra (render normal).
|
|
28
|
+
export function tabsState (panels, emptyIds, activeId) {
|
|
29
|
+
const tabs = panels.filter(s => emptyIds.indexOf(s.id) < 0);
|
|
30
|
+
return { tabs, active: tabs.find(s => s.id === activeId) || tabs[0] || null, bar: tabs.length > 1 };
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// Teclado da barra (padrão WAI-ARIA de abas): setas circulam, Home/End vão às pontas; -1 = ignora.
|
|
34
|
+
export function tabKeyIndex (key, index, count) {
|
|
35
|
+
const keys = { ArrowRight: index + 1, ArrowLeft: index - 1, Home: 0, End: count - 1 };
|
|
36
|
+
return key in keys ? (keys[key] + count) % count : -1;
|
|
37
|
+
}
|