@rocketsearch/nuxt-uappi 0.2.4 → 0.2.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/README.md CHANGED
@@ -13,4 +13,8 @@ modules: [
13
13
  ]
14
14
  ```
15
15
 
16
+ Landing page ("Personalizado" no painel): `<RocketLanding>` mostra todas as vitrines da landing, na ordem do
17
+ painel. O identificador vem do nome da rota (`/black-friday` → `black-friday`) ou de `custom-key="..."`.
18
+ Banners da landing: `<RocketBanner page-type="custom" />`, com a mesma regra do identificador.
19
+
16
20
  Documentação completa: https://api.rocketsearch.com.br/sdk/uappi/docs.html
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rocketsearch/nuxt-uappi",
3
- "version": "0.2.4",
3
+ "version": "0.2.6",
4
4
  "description": "Rocket Search para storefronts Uappi (Nuxt 2): busca, autocomplete, vitrines, banners e eventos",
5
5
  "main": "module.js",
6
6
  "files": [
@@ -1,7 +1,7 @@
1
1
  <template>
2
2
  <div
3
3
  :class="['rocket-search', 'rocket-search__banner-slot', { 'rocket-search--empty': !waiting && !banners.length }]"
4
- :data-rocket-banner-position="position"
4
+ :data-rocket-banner-position="position || undefined"
5
5
  >
6
6
  <!-- Skeleton só com proporção declarada: sem saber a altura, ele é que causaria o pulo. -->
7
7
  <div v-if="waiting && ratio" class="rocket-search__banner-skeleton" :style="{ aspectRatio: ratioCss }" aria-hidden="true" />
@@ -26,12 +26,14 @@
26
26
  import RocketBannerItem from './banner/RocketBannerItem.vue';
27
27
  import { exactWidth, isHeroSlot } from '../banner.js';
28
28
 
29
+ const positionOf = b => (b && ((b.placement && b.placement.position) || b.position)) || '';
30
+
29
31
  export default {
30
32
  name: 'RocketBanner',
31
33
  components: { RocketBannerItem },
32
34
  props: {
33
- // placement.position cadastrada no painel (hero, top, middle...).
34
- position: { type: String, required: true },
35
+ // placement.position cadastrada no painel (hero, top, middle...). Obrigatória fora da landing.
36
+ position: { type: String, default: '' },
35
37
  // ssr: vem no HTML (hero/LCP). ondemand: busca só quando o slot chega perto da viewport.
36
38
  loading: {
37
39
  type: String,
@@ -40,6 +42,9 @@ export default {
40
42
  },
41
43
  // Força o pageType; sem ele vem da página atual (dadosPageAtual do tema).
42
44
  pageType: { type: String, default: '' },
45
+ // Landing (page-type="custom"): identificador no painel; sem ele, o nome da rota
46
+ // (/black-friday -> black-friday). A landing não tem posição: vêm todos os banners dela.
47
+ customKey: { type: String, default: '' },
43
48
  limit: { type: Number, default: 0 },
44
49
  // Proporção do slot ("16/9", "3:1") — reserva a caixa e liga o skeleton.
45
50
  ratio: { type: String, default: '' },
@@ -65,11 +70,22 @@ export default {
65
70
  return this.loading === 'ssr';
66
71
  },
67
72
  computed: {
73
+ landingKey () {
74
+ if (this.pageType !== 'custom') return '';
75
+ if (this.customKey) return this.customKey;
76
+ return ((this.$route && this.$route.path) || '').split('/').filter(Boolean).pop() || '';
77
+ },
68
78
  ratioCss () {
69
79
  return String(this.ratio).trim().replace(':', ' / ');
70
80
  }
71
81
  },
72
82
  watch: {
83
+ // Mesma página, outra landing (rota dinâmica reaproveita o componente): busca de novo.
84
+ landingKey () {
85
+ if (!this.requested) return;
86
+ this.requested = false;
87
+ this.tryLoad();
88
+ },
73
89
  // O contexto da página chega por setDadosPageAtual (o plugin traduz para $rocket.setPage).
74
90
  '$store.state.dadosPageAtual' () {
75
91
  if (this.loading === 'ssr' || this.visible) this.tryLoad();
@@ -101,16 +117,23 @@ export default {
101
117
  if (process.client && this.$el && this.$el.clientWidth) {
102
118
  this.width = exactWidth(this.$el.clientWidth, window.devicePixelRatio);
103
119
  }
104
- const list = await this.$rocket.getBannersByContext(this.pageType || undefined, { position: this.position });
105
- const mine = list.filter(b => ((b.placement && b.placement.position) || b.position) === this.position);
120
+ const key = this.landingKey;
121
+ const list = this.pageType === 'custom'
122
+ ? (key ? await this.$rocket.getBannersByContext('custom', { customKey: key }) : [])
123
+ : await this.$rocket.getBannersByContext(this.pageType || undefined, { position: this.position });
124
+ // Troca rápida de landing: a resposta da anterior não sobrescreve a atual.
125
+ if (key !== this.landingKey) return;
126
+ const mine = this.pageType === 'custom' ? list : list.filter(b => positionOf(b) === this.position);
106
127
  this.banners = this.limit > 0 ? mine.slice(0, this.limit) : mine;
107
128
  this.waiting = false;
108
129
  },
109
130
 
110
131
  itemProps (index) {
111
- const hero = isHeroSlot(this.position) && index === 0;
132
+ // Na landing o slot é a posição do próprio banner.
133
+ const position = this.position || positionOf(this.banners[index]);
134
+ const hero = isHeroSlot(position) && index === 0;
112
135
  return {
113
- position: this.position,
136
+ position,
114
137
  slideIndex: index,
115
138
  loading: hero ? 'eager' : 'lazy',
116
139
  fetchPriority: hero ? 'high' : '',
@@ -0,0 +1,60 @@
1
+ <template>
2
+ <!-- Vue 2 exige um elemento raiz: display: contents faz as vitrines herdarem o espaçamento do container do tema. -->
3
+ <div v-if="showcases.length" class="rocket-search-landing" style="display: contents">
4
+ <RocketShowcase
5
+ v-for="showcase in showcases"
6
+ :key="showcase.id"
7
+ page-type="custom"
8
+ :custom-key="key"
9
+ :showcase-id="showcase.id"
10
+ :position="(showcase.placement && showcase.placement.position) || 'middle'"
11
+ :media-size="mediaSize"
12
+ >
13
+ <template v-if="$scopedSlots.default" #default="scope">
14
+ <slot v-bind="scope" />
15
+ </template>
16
+ <template v-if="$scopedSlots.product" #product="scope">
17
+ <slot name="product" v-bind="scope" />
18
+ </template>
19
+ </RocketShowcase>
20
+ </div>
21
+ </template>
22
+
23
+ <script>
24
+ import RocketShowcase from './RocketShowcase.vue';
25
+
26
+ // Landing page ("Personalizado" no painel): todas as vitrines da landing, empilhadas pela ordem
27
+ // do painel (a API já responde por display_order).
28
+ export default {
29
+ name: 'RocketLanding',
30
+ components: { RocketShowcase },
31
+ props: {
32
+ // Identificador da landing no painel; sem ele, o nome da rota (/black-friday -> black-friday).
33
+ customKey: { type: String, default: '' },
34
+ mediaSize: { type: String, default: 'medium' }
35
+ },
36
+ data () {
37
+ return { showcases: [] };
38
+ },
39
+ computed: {
40
+ key () {
41
+ if (this.customKey) return this.customKey;
42
+ return ((this.$route && this.$route.path) || '').split('/').filter(Boolean).pop() || '';
43
+ }
44
+ },
45
+ watch: {
46
+ key: 'load'
47
+ },
48
+ mounted () {
49
+ this.load();
50
+ },
51
+ methods: {
52
+ async load () {
53
+ const key = this.key;
54
+ const showcases = key ? await this.$rocket.getPageShowcases('custom', key, true) : [];
55
+ // Troca rápida de rota: a resposta da landing anterior não sobrescreve a atual.
56
+ if (key === this.key) this.showcases = showcases;
57
+ }
58
+ }
59
+ };
60
+ </script>
@@ -1,8 +1,8 @@
1
1
  <template>
2
2
  <div
3
- v-if="showcase || loading || debug"
4
- :class="['rocket-search', { 'rocket-search--empty': !showcase && !loading }]"
5
- :data-rocket-showcase-position="position"
3
+ v-if="showcase || loading || debug || restIds.length"
4
+ :class="['rocket-search', { 'rocket-search--empty': !showcase && !loading && !restIds.length, 'rocket-search--stacked': stacked }]"
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">
8
8
  <div class="rocket-search__showcase__title rocket-search__product-placeholder__item" />
@@ -47,6 +47,26 @@
47
47
  <button type="button" class="rocket-search__swiper-button-next" aria-label="Próximos" @click="slide(1)" />
48
48
  </slot>
49
49
  </section>
50
+
51
+ <!-- Demais vitrines da mesma posição, na ordem da API: cada uma medida por conta própria. -->
52
+ <RocketShowcase
53
+ v-for="id in restIds"
54
+ :key="id"
55
+ :position="position"
56
+ :page-type="pageType"
57
+ :custom-key="customKey"
58
+ :showcase-id="id"
59
+ :media-size="mediaSize"
60
+ stacked
61
+ @products-loaded="$emit('products-loaded', $event)"
62
+ >
63
+ <template v-if="$scopedSlots.default" #default="scope">
64
+ <slot v-bind="scope" />
65
+ </template>
66
+ <template v-if="$scopedSlots.product" #product="scope">
67
+ <slot name="product" v-bind="scope" />
68
+ </template>
69
+ </RocketShowcase>
50
70
  </div>
51
71
  </template>
52
72
 
@@ -63,10 +83,17 @@ export default {
63
83
  position: { type: String, required: true },
64
84
  // Força o pageType; sem ele vem da página atual (dadosPageAtual do tema).
65
85
  pageType: { type: String, default: '' },
66
- mediaSize: { type: String, default: 'medium' }
86
+ // Landing (page-type="custom"): identificador cadastrado no painel em "Personalizado".
87
+ customKey: { type: String, default: '' },
88
+ // Vitrine específica (a landing tem várias na mesma posição); sem ele, todas as da posição.
89
+ showcaseId: { type: [String, Number], default: null },
90
+ mediaSize: { type: String, default: 'medium' },
91
+ // Uso interno: vitrine empilhada abaixo da primeira da posição. Sem o atributo de posição,
92
+ // o debug contorna a posição uma vez só.
93
+ stacked: { type: Boolean, default: false }
67
94
  },
68
95
  data () {
69
- return { showcase: null, products: [], loading: false, debug: false };
96
+ return { showcase: null, products: [], restIds: [], loading: false, debug: false };
70
97
  },
71
98
  computed: {
72
99
  columns () {
@@ -112,9 +139,14 @@ export default {
112
139
  if (this.started) return;
113
140
  this.started = true;
114
141
  try {
115
- const showcases = await this.$rocket.getPageShowcases(this.pageType || undefined);
116
- const showcase = showcases.find(s => ((s.placement && s.placement.position) || s.position) === this.position);
142
+ const showcases = await this.$rocket.getPageShowcases(this.pageType || undefined, this.customKey || undefined);
143
+ const inPosition = showcases.filter(s => ((s.placement && s.placement.position) || s.position) === this.position);
144
+ const showcase = this.showcaseId != null
145
+ ? showcases.find(s => String(s.id) === String(this.showcaseId))
146
+ : inPosition[0];
117
147
  if (!showcase) return;
148
+ // Posição sem showcaseId: este slot mostra a primeira e empilha as demais logo abaixo.
149
+ if (this.showcaseId == null) this.restIds = inPosition.slice(1).map(s => s.id);
118
150
  // Banner autônomo: render direto, sem produtos, skeleton nem impressão de vitrine
119
151
  // (o RocketBannerItem mede o criativo).
120
152
  if (isBannerItem(showcase)) {
@@ -6,6 +6,11 @@
6
6
  margin-bottom: 60px;
7
7
  }
8
8
 
9
+ /* Segunda vitrine em diante na mesma posição: o mesmo respiro entre elas. */
10
+ .rocket-search--stacked {
11
+ margin-top: 60px;
12
+ }
13
+
9
14
  .rocket-search__showcase {
10
15
  --showcase-gap: 16px;
11
16
  position: relative;
package/runtime/rocket.js CHANGED
@@ -123,7 +123,10 @@ export function createRocket (config) {
123
123
 
124
124
  rocket.setPage = function (next) {
125
125
  page = Object.assign({ section: null, productId: null, categoryId: null, product: null }, next);
126
- pageShowcases = null;
126
+ // A landing (custom) não depende do contexto da página e fica: senão, um setPage entre a busca
127
+ // do RocketLanding e a montagem das vitrines dele dispararia uma segunda chamada. Ela se
128
+ // renova quando o RocketLanding monta (refresh).
129
+ Object.keys(pageShowcases).forEach((k) => { if (k.indexOf('custom|') !== 0) delete pageShowcases[k]; });
127
130
  };
128
131
  rocket.getPage = () => page;
129
132
 
@@ -282,13 +285,15 @@ export function createRocket (config) {
282
285
  return res.json();
283
286
  };
284
287
 
285
- rocket.getShowcasesByContext = async function (type) {
288
+ // customKey: identificador da landing (pageType=custom); sem ele a API responde 400.
289
+ rocket.getShowcasesByContext = async function (type, customKey) {
286
290
  const pageType = resolvePageType(type);
287
291
  if (!pageType) return [];
288
292
  const sessionId = await getSessionIdWithTimeout();
289
293
  const params = { storeId: config.storeId, pageType, page: pageType, sessionId };
290
294
  if (pageType === 'product' && page.productId) params.productId = page.productId;
291
295
  if (pageType === 'category' && page.categoryId) params.categoryId = page.categoryId;
296
+ if (pageType === 'custom') params.customKey = customKey;
292
297
 
293
298
  const res = await fetch(config.apiUrl + '/showcases/context?' + query(params), { headers: headers() });
294
299
  const showcases = await res.json();
@@ -305,14 +310,17 @@ export function createRocket (config) {
305
310
  };
306
311
 
307
312
  // Uma chamada por página, repartida entre os slots (<RocketShowcase position>) — na Linx
308
- // era o fetchShowCases único distribuindo por data-rocket-showcase-position. Zera no setPage.
309
- let pageShowcases = null;
310
- rocket.getPageShowcases = function (type) {
311
- if (!pageShowcases) pageShowcases = rocket.getShowcasesByContext(type).catch(() => []);
312
- return pageShowcases;
313
+ // era o fetchShowCases único distribuindo por data-rocket-showcase-position. Por pageType +
314
+ // customKey: a landing e o contexto da página são chamadas distintas. O setPage zera só o contexto.
315
+ let pageShowcases = {};
316
+ rocket.getPageShowcases = function (type, customKey, refresh) {
317
+ const key = (type || '') + '|' + (customKey || '');
318
+ if (refresh || !pageShowcases[key]) pageShowcases[key] = rocket.getShowcasesByContext(type, customKey).catch(() => []);
319
+ return pageShowcases[key];
313
320
  };
314
321
 
315
322
  // Só banners (DTO banner-native). Gated pela flag `banners`: loja sem ela recebe [].
323
+ // options.customKey: identificador da landing (pageType=custom); sem ele a API responde 400.
316
324
  rocket.getBannersByContext = async function (type, options) {
317
325
  const pageType = resolvePageType(type);
318
326
  if (!pageType) return [];
@@ -320,6 +328,7 @@ export function createRocket (config) {
320
328
  try {
321
329
  const sessionId = await getSessionIdWithTimeout();
322
330
  const params = { storeId: config.storeId, pageType, sessionId, position: opts.position };
331
+ if (pageType === 'custom') params.customKey = opts.customKey;
323
332
  const res = await fetch(config.apiUrl + '/banners/context?' + query(params), { headers: headers() });
324
333
  if (!res.ok) return [];
325
334
  const banners = await res.json();