basklee-nuxt 0.9.10 → 0.9.12

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
@@ -201,7 +201,7 @@ Product details, saved items and the cart.
201
201
 
202
202
  | Component | Name | What it does |
203
203
  | --- | --- | --- |
204
- | **Product details** | `StorefrontProduct` | Loads and displays a published product or a secret-key preview with images, purchase choices, details and reviews. |
204
+ | **Product details** | `StorefrontProduct` | Loads and displays a published product or a secret-key preview with images and videos, purchase choices, details and reviews. |
205
205
  | **Page path** | `BaskleeBreadcrumbs` | Linked path from the storefront home page through parent categories to the current page. |
206
206
  | **Product characteristics** | `ProductSpecificationsDialog` | Every characteristic of the product in a dialog over the page. |
207
207
  | **Product reviews** | `ProductReviews` | Reviews, replies, ratings and the user’s submissions. |
@@ -516,7 +516,7 @@ route data. The homepage retains additional backend Open Graph and Twitter tags
516
516
  through `useHead()`. Profile and logout pages remain excluded from indexing;
517
517
  search results retain their `noindex, follow` policy.
518
518
  A product page takes the product's SEO tab: its heading is the page title (the product name without one), its meta description and keywords fill their tags, and its own Open Graph and Twitter Cards tags are added in the page's language only, replacing a default tag of the same name.
519
- Pages with a canonical address also link the same page in the other storefront languages (`hreflang`) and set `og:type` and `og:locale`; a journal article adds its publication date (`article:published_time`) and schema.org `BlogPosting` data. The store icon (`logos.ico`) is the page's `<link rel="icon">`. An unknown `?locale` opens the default language.
519
+ Pages with a canonical address also link the same page in the other storefront languages (`hreflang`) and set `og:type` and `og:locale`; a journal article adds its publication date (`article:published_time`) and schema.org `BlogPosting` data. The store icon (`logos.ico`) is the page's `<link rel="icon">`. An unknown `?locale` opens the language closest to the browser's, else the first one.
520
520
 
521
521
  List pages (journal, categories, stores) link their previous and next pages as real links (`?page=2`). Each later page has its own canonical address and a title with its page number; a journal page past the last one answers 404.
522
522
 
@@ -657,7 +657,11 @@ from `store.locales` directly. Import it without a data prop. It accepts a
657
657
  `label` (default `Language`), `disabled` (default `false`) and `codeOnly`
658
658
  (default `false`). Missing names
659
659
  fall back to another translation, then the human name or code. Empty data
660
- disables the selector. The store initially selects its first available language.
660
+ disables the selector. A first visit without `?locale` opens in the storefront
661
+ language closest to the browser's languages (`Accept-Language` during the server
662
+ render, `navigator.languages` in the browser): the same code first, then the same
663
+ language (`ru-RU` finds `ru`, `en` finds `en-GB`); the first available language when
664
+ none of them is offered. A language picked in the selector goes into the address.
661
665
 
662
666
  Flags from `flag_img` appear beside the selected language and in every dropdown
663
667
  option that has an available image. Missing or failed images leave the language
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "basklee-nuxt",
3
- "version": "0.9.10",
3
+ "version": "0.9.12",
4
4
  "description": "Nuxt 4 storefront for your Basklee marketplace: setup CLI, server API gateway, typed store and ready-made catalog, cart, checkout and account components in English, Russian and Spanish, plus an Android app build. Powered by Basklee: https://basklee.com",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -20,6 +20,8 @@ Above the gallery and the purchase column, `BaskleeBreadcrumbs` shows the path t
20
20
 
21
21
  The gallery uses `product.images.full`, falling back to `product.images.small` when empty. On wide screens the thumbnails form a column as tall as the main image beside it; on narrow screens they form a row below it. The strip has no scrollbar: when more thumbnails exist than fit, arrow buttons at its ends move it by one thumbnail, and each button disappears at the first or last position. The selected thumbnail has a dark border and scrolls into view when the photo changes. The thumbnails are one keyboard stop: arrow keys select the previous or next photo, Home and End the first and last. The previous and next buttons over the main image cycle through the photos. A tap, click or Enter on the main image opens the photos in `ProductReviewImageViewer`; the photo chosen there stays selected on the page.
22
22
 
23
+ The product's videos (`product.videos`, uploaded on the Video tab of the panel) follow the photos in the same gallery, in the order the backend sends them; a video without a file is left out. A video's thumbnail shows its `preview` frame under a round play mark and is labelled Product video. Choosing it puts a `<video>` with the browser's controls in the main image's place (`preload="metadata"`, `playsinline`, the preview as the poster, never playing by itself); choosing another item stops it. The previous and next buttons, swipes and thumbnail keys go through photos and videos alike; the full-screen viewer shows the photos only. A product with a video and no photo shows the gallery with that video.
24
+
23
25
  On wide screens the gallery and the purchase column end at the same height: the taller of the two sets it, and the photo area takes the whole height with the photo centred in it at its own proportions, never stretched or cropped. When the purchase column is short, the photo area keeps a height that still shows the photo.
24
26
 
25
27
  Beside the gallery, the purchase column keeps its place in the layout and scrolls with the page. It shows the product name and, when `feedback_stat.c_feedbacks` is positive, the average `feedback_stat.avg_raiting` with the review count as a link to the reviews section. Below it, `ProductCard` in `details` mode shows the badges and price, then About this product and Characteristics, then the selected main variant as “variant name: value”, the variant choices, the stock notice and the actions. Changing the variant updates the gallery, heading, description, characteristics and reviews.
@@ -34,6 +34,7 @@
34
34
  import { safeArticleHtml } from '@/utils/basklee/richText';
35
35
  import { htmlTextParagraphs } from '@/utils/basklee/htmlText';
36
36
  import {
37
+ productMediaItems,
37
38
  thumbnailKeyTarget,
38
39
  thumbnailRailEdges,
39
40
  thumbnailScrollTarget,
@@ -178,6 +179,13 @@
178
179
  const images = product.value?.images;
179
180
  return images?.full?.length ? images.full : (images?.small ?? []);
180
181
  });
182
+ // The gallery: the photos, then the product's videos (Video tab of the
183
+ // panel). A video plays in the large photo's place; the full-screen viewer
184
+ // keeps to the photos, which come first, so their numbers are the same.
185
+ const media = computed(() => productMediaItems(product.value));
186
+ const current = computed(
187
+ () => media.value[image.value] ?? media.value[0],
188
+ );
181
189
  // The first request in the browser shows a placeholder with the page
182
190
  // layout; a later retry after an error shows it again. A product loaded
183
191
  // during the server render is shown at once.
@@ -503,7 +511,7 @@
503
511
  }
504
512
 
505
513
  function showImage(index: number) {
506
- const count = photos.value.length;
514
+ const count = media.value.length;
507
515
  image.value = (index + count) % count;
508
516
  }
509
517
 
@@ -530,7 +538,7 @@
530
538
  showImage(
531
539
  productPhotoAfterSwipe(
532
540
  image.value,
533
- photos.value.length,
541
+ media.value.length,
534
542
  touch.clientX - start.x,
535
543
  touch.clientY - start.y,
536
544
  ),
@@ -641,7 +649,7 @@
641
649
 
642
650
  // Arrow keys, Home and End move between thumbnails, which form one tab stop.
643
651
  function thumbnailKeydown(event: KeyboardEvent, index: number) {
644
- const target = thumbnailKeyTarget(event.key, index, photos.value.length);
652
+ const target = thumbnailKeyTarget(event.key, index, media.value.length);
645
653
 
646
654
  if (target === undefined) {
647
655
  return;
@@ -784,7 +792,7 @@
784
792
  revealThumbnail(index);
785
793
  });
786
794
  // Another variant's photos start from the first thumbnail.
787
- watch(photos, async () => {
795
+ watch(media, async () => {
788
796
  await nextTick();
789
797
 
790
798
  if (rail.value) {
@@ -840,20 +848,41 @@
840
848
  class="grid items-start gap-8 @min-[960px]/product:grid-cols-[minmax(0,7fr)_minmax(0,5fr)] @min-[960px]/product:items-stretch @min-[960px]/product:gap-x-12 @min-[1200px]/product:gap-x-20"
841
849
  >
842
850
  <section
843
- v-if="photos.length"
851
+ v-if="media.length"
844
852
  class="grid min-w-0 gap-3 @min-[560px]/product:grid-cols-[72px_minmax(0,1fr)] @min-[560px]/product:gap-4 @min-[960px]/product:col-start-1 @min-[960px]/product:row-start-1"
845
853
  :aria-label="labels.gallery"
846
854
  data-product-gallery
847
855
  >
848
856
  <div
849
857
  class="relative min-w-0 @min-[560px]/product:col-start-2 @min-[560px]/product:row-start-1 @min-[960px]/product:min-h-96"
850
- :class="{ 'touch-pan-y': photos.length > 1 }"
858
+ :class="{ 'touch-pan-y': media.length > 1 }"
851
859
  data-product-main-image
852
860
  @touchstart.passive="startSwipe"
853
861
  @touchend="endSwipe"
854
862
  >
863
+ <video
864
+ v-if="current?.kind === 'video'"
865
+ :key="current.key"
866
+ :src="current.src"
867
+ :poster="current.preview || undefined"
868
+ :aria-label="labels.productVideo"
869
+ controls
870
+ playsinline
871
+ preload="metadata"
872
+ data-product-video
873
+ class="
874
+ box-border aspect-square h-auto max-h-[70vh] w-full
875
+ bg-basklee-surface object-contain
876
+ @min-[560px]/product:aspect-[4/5]
877
+ @min-[960px]/product:absolute @min-[960px]/product:inset-0
878
+ @min-[960px]/product:m-auto @min-[960px]/product:aspect-auto
879
+ @min-[960px]/product:h-full
880
+ @min-[960px]/product:max-h-[calc(100vh-12rem)]
881
+ "
882
+ />
855
883
  <BaskleeImage
856
- :src="photos[image]"
884
+ v-else-if="current"
885
+ :src="current.src"
857
886
  :alt="title"
858
887
  :width="800"
859
888
  :height="1000"
@@ -877,7 +906,7 @@
877
906
  @min-[960px]/product:max-h-[calc(100vh-12rem)]
878
907
  "
879
908
  />
880
- <template v-if="photos.length > 1">
909
+ <template v-if="media.length > 1">
881
910
  <button
882
911
  type="button"
883
912
  class="absolute left-2 top-1/2 -translate-y-1/2 grid h-10 w-10 place-items-center rounded-full p-0 cursor-pointer border border-solid border-basklee-border bg-basklee-surface/90 text-basklee-text outline-none transition-colors motion-reduce:transition-none hover:border-basklee-text focus-visible:border-basklee-text"
@@ -917,7 +946,7 @@
917
946
  </template>
918
947
  </div>
919
948
  <div
920
- v-if="photos.length > 1"
949
+ v-if="media.length > 1"
921
950
  class="relative min-w-0 @min-[560px]/product:col-start-1 @min-[560px]/product:row-start-1 @min-[560px]/product:h-0 @min-[560px]/product:min-h-full"
922
951
  data-product-thumbnail-rail
923
952
  >
@@ -928,27 +957,45 @@
928
957
  @scroll.passive="updateRail"
929
958
  >
930
959
  <button
931
- v-for="(photo, index) in photos"
932
- :key="photo"
960
+ v-for="(item, index) in media"
961
+ :key="item.key"
933
962
  type="button"
934
- class="box-border h-[70px] w-14 shrink-0 p-1 @min-[560px]/product:h-[90px] @min-[560px]/product:w-[72px] cursor-pointer border border-solid bg-basklee-surface outline-none transition-[opacity,border-color] motion-reduce:transition-none hover:opacity-100 focus-visible:border-2 focus-visible:border-basklee-text"
963
+ class="relative box-border h-[70px] w-14 shrink-0 p-1 @min-[560px]/product:h-[90px] @min-[560px]/product:w-[72px] cursor-pointer border border-solid bg-basklee-surface outline-none transition-[opacity,border-color] motion-reduce:transition-none hover:opacity-100 focus-visible:border-2 focus-visible:border-basklee-text"
935
964
  :class="
936
965
  index === image
937
966
  ? 'border-basklee-text opacity-100'
938
967
  : 'border-transparent opacity-75'
939
968
  "
940
- :aria-label="`${labels.gallery} ${index + 1}`"
969
+ :aria-label="`${item.kind === 'video' ? labels.productVideo : labels.gallery} ${index + 1}`"
941
970
  :aria-pressed="index === image"
942
971
  :tabindex="index === image ? 0 : -1"
943
972
  :data-product-thumbnail="index"
973
+ :data-product-thumbnail-video="item.kind === 'video' || undefined"
944
974
  @click="image = index"
945
975
  @keydown="thumbnailKeydown($event, index)"
946
976
  >
947
977
  <BaskleeImage
948
- :src="photo"
978
+ v-if="item.kind === 'image' || item.preview"
979
+ :src="item.kind === 'image' ? item.src : (item.preview as string)"
949
980
  alt=""
950
- class="h-full w-full object-contain"
981
+ class="h-full w-full"
982
+ :class="item.kind === 'image' ? 'object-contain' : 'object-cover'"
951
983
  />
984
+ <span
985
+ v-if="item.kind === 'video'"
986
+ class="absolute inset-0 m-auto grid h-7 w-7 place-items-center rounded-full bg-basklee-text/80 text-basklee-surface"
987
+ aria-hidden="true"
988
+ data-product-video-mark
989
+ >
990
+ <svg
991
+ viewBox="0 0 24 24"
992
+ class="ml-0.5 h-3.5 w-3.5"
993
+ fill="currentColor"
994
+ aria-hidden="true"
995
+ >
996
+ <path d="M8 5v14l11-7z" />
997
+ </svg>
998
+ </span>
952
999
  </button>
953
1000
  </div>
954
1001
  <button
@@ -1,6 +1,11 @@
1
- import { abortNavigation, defineNuxtRouteMiddleware } from '#imports';
1
+ import {
2
+ abortNavigation,
3
+ defineNuxtRouteMiddleware,
4
+ useRequestHeaders,
5
+ } from '#imports';
2
6
  import { useBaskleeAppLoad } from '@/composables/useBaskleeAppLoad';
3
7
  import { storefrontPageError } from '@/composables/useBaskleeMissingPage';
8
+ import { wantedLanguages } from '@/utils/basklee/presentation';
4
9
 
5
10
  /**
6
11
  * Bootstrap precedes page setup. A failed Application Load opens the
@@ -13,6 +18,21 @@ export default defineNuxtRouteMiddleware(async (to) => {
13
18
  ? to.query.locale
14
19
  : '';
15
20
 
21
+ // A first visit without ?locale= opens in the storefront language closest
22
+ // to the browser's languages (the request's Accept-Language while the
23
+ // server renders, navigator.languages in the browser); the storefront's
24
+ // first language when none of them is offered.
25
+ if (store.status === 'idle') {
26
+ store.wantLocales([
27
+ locale,
28
+ ...wantedLanguages(
29
+ import.meta.server
30
+ ? useRequestHeaders(['accept-language'])['accept-language']
31
+ : navigator.languages,
32
+ ),
33
+ ]);
34
+ }
35
+
16
36
  await initialize(locale);
17
37
 
18
38
  if (!to.matched.length) {
@@ -74,6 +74,7 @@ function createStoreState(scope: string, pinia: Pinia) {
74
74
  const lengthId = forwardedState(selectionRefs.lengthId);
75
75
  const {
76
76
  setLocale,
77
+ wantLocales,
77
78
  setCurrency,
78
79
  setUnit,
79
80
  } = selections;
@@ -409,6 +410,7 @@ function createStoreState(scope: string, pinia: Pinia) {
409
410
  currentLocale,
410
411
  currentCurrency,
411
412
  setLocale,
413
+ wantLocales,
412
414
  setCurrency,
413
415
  setUnit,
414
416
  getProducts,
@@ -3,6 +3,7 @@ import type { ComputedRef } from 'vue';
3
3
  import { defineStore } from 'pinia';
4
4
  import type { Pinia } from 'pinia';
5
5
  import { resolveBaskleeDomain } from '@/stores/baskleeDomainAccess';
6
+ import { closestLocale } from '@/utils/basklee/presentation';
6
7
  import '@/stores/basklee';
7
8
  import type { IAppLoadCommon } from '@/interfaces/basklee/appBase/IAppLoadCommon';
8
9
 
@@ -17,6 +18,9 @@ export function useBaskleeSelections(
17
18
  const currencyId = ref('');
18
19
  const weightId = ref('');
19
20
  const lengthId = ref('');
21
+ // What the customer asked for before the storefront knew its languages:
22
+ // the address's ?locale=, then the browser's languages.
23
+ const wantedLocales = ref<string[]>([]);
20
24
  const locales = computed(() => init.value?.locale ?? {});
21
25
  const currencies = computed(() => init.value?.currencies ?? {});
22
26
  const weights = computed(() => init.value?.weights ?? {});
@@ -75,8 +79,30 @@ export function useBaskleeSelections(
75
79
  }
76
80
  }
77
81
 
82
+ /** Languages the customer wants, most wanted first (see reconcile). */
83
+ function wantLocales(tags: readonly (string | null | undefined)[]) {
84
+ wantedLocales.value = tags
85
+ .map((tag) => tag?.trim() ?? '')
86
+ .filter(Boolean);
87
+ }
88
+
89
+ function wantedLocale() {
90
+ const code = closestLocale(
91
+ Object.entries(locales.value).map(
92
+ ([key, value]) => value.code?.trim() || key,
93
+ ),
94
+ wantedLocales.value,
95
+ );
96
+ return code ? findLocale(code) : undefined;
97
+ }
98
+
99
+ // A language still offered stays; otherwise the one closest to what the
100
+ // customer wants; otherwise the storefront's first language.
78
101
  function reconcile() {
79
- const selected = findLocale(localeCode.value) ?? Object.entries(locales.value)[0];
102
+ const selected =
103
+ findLocale(localeCode.value) ??
104
+ wantedLocale() ??
105
+ Object.entries(locales.value)[0];
80
106
  localeCode.value = selected?.[1].code?.trim() || selected?.[0] || '';
81
107
  currencyId.value = availableCurrency(
82
108
  currencies.value[currencyId.value]?.allowed_select
@@ -109,6 +135,7 @@ export function useBaskleeSelections(
109
135
  currencyId,
110
136
  weightId,
111
137
  lengthId,
138
+ wantedLocales,
112
139
  locales,
113
140
  currencies,
114
141
  weights,
@@ -116,6 +143,7 @@ export function useBaskleeSelections(
116
143
  currentLocale,
117
144
  currentCurrency,
118
145
  setLocale,
146
+ wantLocales,
119
147
  setCurrency,
120
148
  setUnit,
121
149
  reconcile,
@@ -70,3 +70,56 @@ export function localesMatch(left: string, right: string) {
70
70
  value.trim().toLowerCase().replaceAll('_', '-');
71
71
  return normalize(left) === normalize(right);
72
72
  }
73
+
74
+ /**
75
+ * The languages a customer's browser asks for, most wanted first: an
76
+ * Accept-Language header («ru-RU,ru;q=0.9,en;q=0.8») or navigator.languages.
77
+ */
78
+ export function wantedLanguages(
79
+ source: string | readonly string[] | null | undefined,
80
+ ): string[] {
81
+ if (!source) {
82
+ return [];
83
+ }
84
+ if (typeof source !== 'string') {
85
+ return source.map((tag) => tag.trim()).filter(Boolean);
86
+ }
87
+ return source
88
+ .split(',')
89
+ .map((part, index) => {
90
+ const [tag = '', ...parameters] = part.split(';');
91
+ const weight = parameters
92
+ .map((parameter) => /^q=([0-9.]+)$/i.exec(parameter.trim()))
93
+ .find(Boolean);
94
+ return { tag: tag.trim(), weight: weight ? Number(weight[1]) : 1, index };
95
+ })
96
+ .filter((item) => item.tag && item.tag !== '*' && item.weight > 0)
97
+ .sort((left, right) => right.weight - left.weight || left.index - right.index)
98
+ .map((item) => item.tag);
99
+ }
100
+
101
+ /**
102
+ * The shop's language closest to what the customer wants, in the customer's
103
+ * order: the same tag first (pt_BR = pt-BR), then the same language (ru-RU
104
+ * finds ru, en finds en-GB). Nothing when no wanted language is offered.
105
+ */
106
+ export function closestLocale(
107
+ available: readonly string[],
108
+ wanted: readonly string[],
109
+ ): string | undefined {
110
+ const language = (tag: string) =>
111
+ tag.trim().toLowerCase().split(/[-_]/)[0] ?? '';
112
+ for (const tag of wanted) {
113
+ const same = available.find((code) => localesMatch(code, tag));
114
+ if (same) {
115
+ return same;
116
+ }
117
+ const kin = language(tag)
118
+ ? available.find((code) => language(code) === language(tag))
119
+ : undefined;
120
+ if (kin) {
121
+ return kin;
122
+ }
123
+ }
124
+ return undefined;
125
+ }
@@ -70,3 +70,40 @@ export function thumbnailKeyTarget(
70
70
 
71
71
  return undefined;
72
72
  }
73
+
74
+ export type ProductMediaItem =
75
+ | { kind: 'image'; key: string; src: string }
76
+ | { kind: 'video'; key: string; src: string; preview: string | null };
77
+
78
+ export interface IProductMediaSources {
79
+ images?: { full?: string[] | null; small?: string[] | null } | null;
80
+ videos?:
81
+ | { id: number; product_video: string | null; preview: string | null }[]
82
+ | null;
83
+ }
84
+
85
+ // The pictures and videos of a product in the order its gallery shows them:
86
+ // the full images first (the small copies when it has none), then the videos
87
+ // in the order the backend sends them. A video without a file is left out.
88
+ export function productMediaItems(
89
+ product: IProductMediaSources | null | undefined,
90
+ ): ProductMediaItem[] {
91
+ const images = product?.images;
92
+ const photos = images?.full?.length ? images.full : (images?.small ?? []);
93
+ const items = photos.map(
94
+ (src, index): ProductMediaItem => ({ kind: 'image', key: `image-${index}`, src }),
95
+ );
96
+
97
+ for (const video of product?.videos ?? []) {
98
+ if (video.product_video) {
99
+ items.push({
100
+ kind: 'video',
101
+ key: `video-${video.id}`,
102
+ src: video.product_video,
103
+ preview: video.preview,
104
+ });
105
+ }
106
+ }
107
+
108
+ return items;
109
+ }
@@ -52,6 +52,7 @@ const en = {
52
52
  zoomIn: 'Show at full size',
53
53
  zoomOut: 'Fit to screen',
54
54
  nextImage: 'Next image',
55
+ productVideo: 'Product video',
55
56
  thumbnailsBack: 'Show previous thumbnails',
56
57
  thumbnailsForward: 'Show next thumbnails',
57
58
  characteristics: 'Characteristics',
@@ -133,6 +134,7 @@ const ru: typeof en = {
133
134
  zoomIn: 'Показать в полный размер',
134
135
  zoomOut: 'Вписать в экран',
135
136
  nextImage: 'Следующая фотография',
137
+ productVideo: 'Видео товара',
136
138
  thumbnailsBack: 'Показать предыдущие миниатюры',
137
139
  thumbnailsForward: 'Показать следующие миниатюры',
138
140
  characteristics: 'Характеристики',
@@ -215,6 +217,7 @@ const es: typeof en = {
215
217
  zoomIn: 'Ver a tamaño completo',
216
218
  zoomOut: 'Ajustar a la pantalla',
217
219
  nextImage: 'Imagen siguiente',
220
+ productVideo: 'Vídeo del producto',
218
221
  thumbnailsBack: 'Ver miniaturas anteriores',
219
222
  thumbnailsForward: 'Ver miniaturas siguientes',
220
223
  characteristics: 'Características',
@@ -9,7 +9,8 @@ Field pages describe their data and usage with a physical interface reference.
9
9
  Fields used by supplied components also link to their previews and source files.
10
10
  Configuration and shared counters have dedicated data references.
11
11
 
12
- The store chooses the first available language and its default currency and
12
+ The store chooses the available language closest to the browser's languages
13
+ (the first available one when none is close) and its default currency and
13
14
  units. `MainLanguageSwitcher` updates `store.localeCode` and replaces the current
14
15
  currency and unit selections with that language's defaults;
15
16
  `MainCurrencySwitcher` updates `store.currencyId`. `UnitSwitcher` uses