basklee-svelte 0.9.10 → 0.9.11

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
@@ -206,7 +206,7 @@ Product details, saved items and the cart.
206
206
 
207
207
  | Component | Name | What it does |
208
208
  | --- | --- | --- |
209
- | **Product details** | `StorefrontProduct` | Loads and displays a published product or a secret-key preview with images, purchase choices, details and reviews. |
209
+ | **Product details** | `StorefrontProduct` | Loads and displays a published product or a secret-key preview with images and videos, purchase choices, details and reviews. |
210
210
  | **Page path** | `BaskleeBreadcrumbs` | Linked path from the storefront home page through parent categories to the current page. |
211
211
  | **Product characteristics** | `ProductSpecificationsDialog` | Every characteristic of the product in a dialog over the page. |
212
212
  | **Product reviews** | `ProductReviews` | Reviews, replies, ratings and the user’s submissions. |
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "basklee-svelte",
3
- "version": "0.9.10",
3
+ "version": "0.9.11",
4
4
  "description": "SvelteKit 2 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",
@@ -8,6 +8,12 @@ preview address with `?key=` uses `products_preview`, so anyone with the complet
8
8
  preview address can view it without signing in. The request also runs during server
9
9
  rendering so the product is present in the HTML.
10
10
 
11
+ The media are the photos, then the product's videos (`product.videos`, from the Video
12
+ tab of the panel; a video without a file is left out). A video's thumbnail shows its
13
+ `preview` frame under a round play mark; choosing it plays the video with the browser's
14
+ controls in the main image's place, never by itself. The full-screen viewer shows the
15
+ photos only.
16
+
11
17
  Under the reviews, “You may also like” shows the products attached to this product on
12
18
  the panel's Relevant Products tab (`related.data`, without the product itself, up to
13
19
  eight). Only a product without attached products shows up to eight more products of its
@@ -33,6 +33,7 @@
33
33
  import { safeArticleHtml } from '@/lib/utils/basklee/richText';
34
34
  import { htmlTextParagraphs } from '@/lib/utils/basklee/htmlText';
35
35
  import {
36
+ productMediaItems,
36
37
  thumbnailKeyTarget,
37
38
  thumbnailRailEdges,
38
39
  thumbnailScrollTarget,
@@ -203,6 +204,13 @@
203
204
  const images = product.value?.images;
204
205
  return images?.full?.length ? images.full : (images?.small ?? []);
205
206
  });
207
+ // The gallery: the photos, then the product's videos (Video tab of the
208
+ // panel). A video plays in the large photo's place; the full-screen viewer
209
+ // keeps to the photos, which come first, so their numbers are the same.
210
+ const media = computed(() => productMediaItems(product.value));
211
+ const current = computed(
212
+ () => media.value[image.value] ?? media.value[0],
213
+ );
206
214
  // The first request in the browser shows a placeholder with the page
207
215
  // layout; a later retry after an error shows it again. A product loaded
208
216
  // during the server render is shown at once.
@@ -528,7 +536,7 @@
528
536
  }
529
537
 
530
538
  function showImage(index: number) {
531
- const count = photos.value.length;
539
+ const count = media.value.length;
532
540
  image.value = (index + count) % count;
533
541
  }
534
542
 
@@ -555,7 +563,7 @@
555
563
  showImage(
556
564
  productPhotoAfterSwipe(
557
565
  image.value,
558
- photos.value.length,
566
+ media.value.length,
559
567
  touch.clientX - start.x,
560
568
  touch.clientY - start.y,
561
569
  ),
@@ -666,7 +674,7 @@
666
674
 
667
675
  // Arrow keys, Home and End move between thumbnails, which form one tab stop.
668
676
  function thumbnailKeydown(event: KeyboardEvent, index: number) {
669
- const target = thumbnailKeyTarget(event.key, index, photos.value.length);
677
+ const target = thumbnailKeyTarget(event.key, index, media.value.length);
670
678
 
671
679
  if (target === undefined) {
672
680
  return;
@@ -809,7 +817,7 @@
809
817
  revealThumbnail(index);
810
818
  });
811
819
  // Another variant's photos start from the first thumbnail.
812
- watch(photos, async () => {
820
+ watch(media, async () => {
813
821
  await nextTick();
814
822
 
815
823
  if (rail.value) {
@@ -877,7 +885,7 @@
877
885
  `,
878
886
  ]}
879
887
  >
880
- {#if photos.value.length}
888
+ {#if media.value.length}
881
889
  <section
882
890
  aria-label={labels.value.gallery}
883
891
  data-product-gallery
@@ -897,40 +905,64 @@
897
905
  relative min-w-0 @min-[560px]/product:col-start-2
898
906
  @min-[560px]/product:row-start-1 @min-[960px]/product:min-h-96
899
907
  `,
900
- photos.value.length > 1 && 'touch-pan-y',
908
+ media.value.length > 1 && 'touch-pan-y',
901
909
  ]}
902
910
  ontouchstart={startSwipe}
903
911
  ontouchend={endSwipe}
904
912
  >
905
- <BaskleeImage
906
- src={photos.value[image.value]}
907
- alt={title.value}
908
- width={800}
909
- height={1000}
910
- loading="eager"
911
- role="button"
912
- tabindex="0"
913
- aria-label={labels.value.openProductPhoto}
914
- data-product-photo-open
915
- onclick={() => {
916
- viewerOpen.value = true;
917
- }}
918
- onkeydown={openViewerKey}
919
- class={[
920
- `
921
- box-border aspect-square h-auto max-h-[70vh] w-full bg-basklee-surface
922
- cursor-zoom-in outline-none focus-visible:outline-1
923
- focus-visible:outline-solid focus-visible:outline-basklee-text
924
- object-contain @min-[560px]/product:aspect-[4/5]
925
- @min-[960px]/product:absolute @min-[960px]/product:inset-0
926
- @min-[960px]/product:m-auto @min-[960px]/product:aspect-auto
927
- @min-[960px]/product:h-full
928
- @min-[960px]/product:max-h-[calc(100vh-12rem)]
929
- `,
930
- ]}
931
- />
913
+ {#if current.value?.kind === 'video'}
914
+ {#key current.value.key}
915
+ <video
916
+ src={current.value.src}
917
+ poster={current.value.preview || undefined}
918
+ aria-label={labels.value.productVideo}
919
+ controls
920
+ playsinline
921
+ preload="metadata"
922
+ data-product-video
923
+ class={[
924
+ `
925
+ box-border aspect-square h-auto max-h-[70vh] w-full bg-basklee-surface
926
+ object-contain @min-[560px]/product:aspect-[4/5]
927
+ @min-[960px]/product:absolute @min-[960px]/product:inset-0
928
+ @min-[960px]/product:m-auto @min-[960px]/product:aspect-auto
929
+ @min-[960px]/product:h-full
930
+ @min-[960px]/product:max-h-[calc(100vh-12rem)]
931
+ `,
932
+ ]}
933
+ ></video>
934
+ {/key}
935
+ {:else if current.value}
936
+ <BaskleeImage
937
+ src={current.value.src}
938
+ alt={title.value}
939
+ width={800}
940
+ height={1000}
941
+ loading="eager"
942
+ role="button"
943
+ tabindex="0"
944
+ aria-label={labels.value.openProductPhoto}
945
+ data-product-photo-open
946
+ onclick={() => {
947
+ viewerOpen.value = true;
948
+ }}
949
+ onkeydown={openViewerKey}
950
+ class={[
951
+ `
952
+ box-border aspect-square h-auto max-h-[70vh] w-full bg-basklee-surface
953
+ cursor-zoom-in outline-none focus-visible:outline-1
954
+ focus-visible:outline-solid focus-visible:outline-basklee-text
955
+ object-contain @min-[560px]/product:aspect-[4/5]
956
+ @min-[960px]/product:absolute @min-[960px]/product:inset-0
957
+ @min-[960px]/product:m-auto @min-[960px]/product:aspect-auto
958
+ @min-[960px]/product:h-full
959
+ @min-[960px]/product:max-h-[calc(100vh-12rem)]
960
+ `,
961
+ ]}
962
+ />
963
+ {/if}
932
964
 
933
- {#if photos.value.length > 1}
965
+ {#if media.value.length > 1}
934
966
  <button
935
967
  type="button"
936
968
  aria-label={labels.value.previousImage}
@@ -990,7 +1022,7 @@
990
1022
  {/if}
991
1023
  </div>
992
1024
 
993
- {#if photos.value.length > 1}
1025
+ {#if media.value.length > 1}
994
1026
  <div
995
1027
  data-product-thumbnail-rail
996
1028
  class={[
@@ -1014,13 +1046,14 @@
1014
1046
  `,
1015
1047
  ]}
1016
1048
  >
1017
- {#each photos.value as photo, index (photo)}
1049
+ {#each media.value as item, index (item.key)}
1018
1050
  <button
1019
1051
  type="button"
1020
- aria-label={`${labels.value.gallery} ${index + 1}`}
1052
+ aria-label={`${item.kind === 'video' ? labels.value.productVideo : labels.value.gallery} ${index + 1}`}
1021
1053
  aria-pressed={index === image.value}
1022
1054
  tabindex={index === image.value ? 0 : -1}
1023
1055
  data-product-thumbnail={index}
1056
+ data-product-thumbnail-video={item.kind === 'video' || undefined}
1024
1057
  onclick={() => {
1025
1058
  image.value = index;
1026
1059
  }}
@@ -1029,7 +1062,7 @@
1029
1062
  }}
1030
1063
  class={[
1031
1064
  `
1032
- box-border h-[70px] w-14 shrink-0 p-1 @min-[560px]/product:h-[90px]
1065
+ relative box-border h-[70px] w-14 shrink-0 p-1 @min-[560px]/product:h-[90px]
1033
1066
  @min-[560px]/product:w-[72px] cursor-pointer border border-solid
1034
1067
  bg-basklee-surface outline-none transition-[opacity,border-color]
1035
1068
  motion-reduce:transition-none hover:opacity-100 focus-visible:border-2
@@ -1040,11 +1073,37 @@
1040
1073
  : 'border-transparent opacity-75',
1041
1074
  ]}
1042
1075
  >
1043
- <BaskleeImage
1044
- src={photo}
1045
- alt=""
1046
- class={['h-full w-full object-contain']}
1047
- />
1076
+ {#if item.kind === 'image' || item.preview}
1077
+ <BaskleeImage
1078
+ src={item.kind === 'image' ? item.src : (item.preview as string)}
1079
+ alt=""
1080
+ class={[
1081
+ 'h-full w-full',
1082
+ item.kind === 'image' ? 'object-contain' : 'object-cover',
1083
+ ]}
1084
+ />
1085
+ {/if}
1086
+ {#if item.kind === 'video'}
1087
+ <span
1088
+ aria-hidden="true"
1089
+ data-product-video-mark
1090
+ class={[
1091
+ `
1092
+ absolute inset-0 m-auto grid h-7 w-7 place-items-center rounded-full
1093
+ bg-basklee-text/80 text-basklee-surface
1094
+ `,
1095
+ ]}
1096
+ >
1097
+ <svg
1098
+ viewBox="0 0 24 24"
1099
+ class="ml-0.5 h-3.5 w-3.5"
1100
+ fill="currentColor"
1101
+ aria-hidden="true"
1102
+ >
1103
+ <path d="M8 5v14l11-7z" />
1104
+ </svg>
1105
+ </span>
1106
+ {/if}
1048
1107
  </button>
1049
1108
  {/each}
1050
1109
  </div>
@@ -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',