basklee-react 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
@@ -199,7 +199,7 @@ Product details, saved items and the cart.
199
199
 
200
200
  | Component | Name | What it does |
201
201
  | --- | --- | --- |
202
- | **Product details** | `StorefrontProduct` | Loads and displays a published product or a secret-key preview with images, purchase choices, details and reviews. |
202
+ | **Product details** | `StorefrontProduct` | Loads and displays a published product or a secret-key preview with images and videos, purchase choices, details and reviews. |
203
203
  | **Page path** | `BaskleeBreadcrumbs` | Linked path from the storefront home page through parent categories to the current page. |
204
204
  | **Product characteristics** | `ProductSpecificationsDialog` | Every characteristic of the product in a dialog over the page. |
205
205
  | **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-react",
3
- "version": "0.9.10",
3
+ "version": "0.9.11",
4
4
  "description": "Next.js 16 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",
@@ -29,6 +29,16 @@ select the first and last. A tap, click or Enter on the main image opens the
29
29
  photos in `ProductReviewImageViewer`; the photo chosen there stays selected.
30
30
  Every image reserves display space while it loads.
31
31
 
32
+ The product's videos (`product.videos`, uploaded on the Video tab of the
33
+ panel) follow the photos in the same gallery, in the order the backend sends
34
+ them; a video without a file is left out. A video's thumbnail shows its
35
+ `preview` frame under a round play mark and is labelled Product video.
36
+ Choosing it puts a `<video>` with the browser's controls in the main image's
37
+ place (`preload="metadata"`, `playsInline`, the preview as the poster, never
38
+ playing by itself); choosing another item stops it. The previous and next
39
+ controls, swipes and thumbnail keys go through photos and videos alike; the
40
+ full-screen viewer shows the photos only.
41
+
32
42
  The localized product description is rendered as safe plain paragraphs on the
33
43
  server and sanitized editor HTML in the browser. Long descriptions collapse
34
44
  behind More. Characteristics include the manufacturer, positive weight, all
@@ -204,6 +204,7 @@
204
204
  }
205
205
 
206
206
  .thumbnail {
207
+ position: relative;
207
208
  box-sizing: border-box;
208
209
  flex: 0 0 56px;
209
210
  width: 56px;
@@ -239,6 +240,35 @@
239
240
  object-fit: contain;
240
241
  }
241
242
 
243
+ /* A product video: it plays in the large photo's place, its thumbnail shows
244
+ the preview frame under a round play mark. */
245
+ .mainVideo {
246
+ cursor: auto;
247
+ }
248
+
249
+ .thumbnailPreview {
250
+ object-fit: cover;
251
+ }
252
+
253
+ .videoMark {
254
+ position: absolute;
255
+ inset: 0;
256
+ display: grid;
257
+ width: 28px;
258
+ height: 28px;
259
+ margin: auto;
260
+ place-items: center;
261
+ border-radius: 9999px;
262
+ background: color-mix(in srgb, var(--basklee-text) 80%, transparent);
263
+ color: var(--basklee-surface);
264
+ }
265
+
266
+ .videoMark svg {
267
+ width: 14px;
268
+ height: 14px;
269
+ margin-left: 2px;
270
+ }
271
+
242
272
  .railArrow {
243
273
  position: absolute;
244
274
  top: 50%;
@@ -33,6 +33,7 @@ import { featureLabels } from '@/lib/basklee/featureLabels';
33
33
  import { htmlTextParagraphs } from '@/lib/basklee/htmlText';
34
34
  import { productActionLabels } from '@/lib/basklee/productActionLabels';
35
35
  import {
36
+ productMediaItems,
36
37
  productThumbnailKeyTarget,
37
38
  productThumbnailRailEdges,
38
39
  productThumbnailScrollTarget,
@@ -290,6 +291,11 @@ export function StorefrontProduct({
290
291
  ? Boolean(descriptionHtml)
291
292
  : descriptionText.length > 0;
292
293
  const photos = useMemo(() => productPagePhotos(product), [product]);
294
+ // The gallery: the photos, then the product's videos (Video tab of the
295
+ // panel). A video plays in the large photo's place; the full-screen viewer
296
+ // keeps to the photos, which come first, so their numbers are the same.
297
+ const media = useMemo(() => productMediaItems(product), [product]);
298
+ const current = media[image] ?? media[0];
293
299
  const manufacturer = useMemo(
294
300
  () => productPageManufacturer(product, locale),
295
301
  [product, locale],
@@ -514,7 +520,7 @@ export function StorefrontProduct({
514
520
  updateRail();
515
521
 
516
522
  return () => observer?.disconnect();
517
- }, [photos, updateRail]);
523
+ }, [media, updateRail]);
518
524
 
519
525
  useEffect(() => {
520
526
  const element = descriptionBody.current;
@@ -578,7 +584,7 @@ export function StorefrontProduct({
578
584
  rail.current.scrollLeft = 0;
579
585
  }
580
586
  updateRail();
581
- }, [photos, updateRail]);
587
+ }, [media, updateRail]);
582
588
 
583
589
  const viewerPhotos = useMemo(
584
590
  () => photos.map((photo, id) => ({ id, image: photo })),
@@ -593,8 +599,8 @@ export function StorefrontProduct({
593
599
  }
594
600
 
595
601
  function showImage(index: number) {
596
- if (photos.length) {
597
- setImage((index + photos.length) % photos.length);
602
+ if (media.length) {
603
+ setImage((index + media.length) % media.length);
598
604
  }
599
605
  }
600
606
 
@@ -619,7 +625,7 @@ export function StorefrontProduct({
619
625
  showImage(
620
626
  productPhotoAfterSwipe(
621
627
  image,
622
- photos.length,
628
+ media.length,
623
629
  touch.clientX - start.x,
624
630
  touch.clientY - start.y,
625
631
  ),
@@ -655,7 +661,7 @@ export function StorefrontProduct({
655
661
  event: KeyboardEvent<HTMLButtonElement>,
656
662
  index: number,
657
663
  ) {
658
- const target = productThumbnailKeyTarget(event.key, index, photos.length);
664
+ const target = productThumbnailKeyTarget(event.key, index, media.length);
659
665
  if (target === undefined) {
660
666
  return;
661
667
  }
@@ -902,7 +908,7 @@ export function StorefrontProduct({
902
908
  {product ? (
903
909
  <>
904
910
  <div className={styles.layout}>
905
- {photos.length ? (
911
+ {media.length ? (
906
912
  <section
907
913
  className={styles.gallery}
908
914
  aria-label={labels.gallery}
@@ -910,7 +916,7 @@ export function StorefrontProduct({
910
916
  >
911
917
  <div
912
918
  className={
913
- photos.length > 1
919
+ media.length > 1
914
920
  ? `${styles.mainImage} ${styles.mainImageSwipe}`
915
921
  : styles.mainImage
916
922
  }
@@ -918,21 +924,35 @@ export function StorefrontProduct({
918
924
  onTouchStart={startSwipe}
919
925
  onTouchEnd={endSwipe}
920
926
  >
921
- <BaskleeImage
922
- src={photos[image]}
923
- alt={title}
924
- width={800}
925
- height={1000}
926
- loading="eager"
927
- role="button"
928
- tabIndex={0}
929
- aria-label={labels.openProductPhoto}
930
- data-product-photo-open
931
- onClick={() => setViewerOpen(true)}
932
- onKeyDown={openViewerKey}
933
- className={styles.mainImageAsset}
934
- />
935
- {photos.length > 1 ? (
927
+ {current?.kind === 'video' ? (
928
+ <video
929
+ key={current.key}
930
+ src={current.src}
931
+ poster={current.preview || undefined}
932
+ aria-label={labels.productVideo}
933
+ controls
934
+ playsInline
935
+ preload="metadata"
936
+ data-product-video
937
+ className={`${styles.mainImageAsset} ${styles.mainVideo}`}
938
+ />
939
+ ) : current ? (
940
+ <BaskleeImage
941
+ src={current.src}
942
+ alt={title}
943
+ width={800}
944
+ height={1000}
945
+ loading="eager"
946
+ role="button"
947
+ tabIndex={0}
948
+ aria-label={labels.openProductPhoto}
949
+ data-product-photo-open
950
+ onClick={() => setViewerOpen(true)}
951
+ onKeyDown={openViewerKey}
952
+ className={styles.mainImageAsset}
953
+ />
954
+ ) : null}
955
+ {media.length > 1 ? (
936
956
  <>
937
957
  <button
938
958
  type="button"
@@ -971,7 +991,7 @@ export function StorefrontProduct({
971
991
  </>
972
992
  ) : null}
973
993
  </div>
974
- {photos.length > 1 ? (
994
+ {media.length > 1 ? (
975
995
  <div
976
996
  className={styles.thumbnailRail}
977
997
  data-product-thumbnail-rail
@@ -982,27 +1002,59 @@ export function StorefrontProduct({
982
1002
  data-product-thumbnails
983
1003
  onScroll={updateRail}
984
1004
  >
985
- {photos.map((photo, index) => (
1005
+ {media.map((item, index) => (
986
1006
  <button
987
- key={`${photo}:${index}`}
1007
+ key={item.key}
988
1008
  type="button"
989
1009
  className={`${styles.thumbnail} ${
990
1010
  index === image ? styles.thumbnailSelected : ''
991
1011
  }`}
992
- aria-label={`${labels.gallery} ${index + 1}`}
1012
+ aria-label={`${
1013
+ item.kind === 'video'
1014
+ ? labels.productVideo
1015
+ : labels.gallery
1016
+ } ${index + 1}`}
993
1017
  aria-pressed={index === image}
994
1018
  tabIndex={index === image ? 0 : -1}
995
1019
  data-product-thumbnail={index}
1020
+ data-product-thumbnail-video={
1021
+ item.kind === 'video' || undefined
1022
+ }
996
1023
  onClick={() => setImage(index)}
997
1024
  onKeyDown={(event) => thumbnailKeydown(event, index)}
998
1025
  >
999
- <BaskleeImage
1000
- src={photo}
1001
- alt=""
1002
- width={72}
1003
- height={90}
1004
- className={styles.thumbnailImage}
1005
- />
1026
+ {item.kind === 'image' || item.preview ? (
1027
+ <BaskleeImage
1028
+ src={
1029
+ item.kind === 'image'
1030
+ ? item.src
1031
+ : (item.preview as string)
1032
+ }
1033
+ alt=""
1034
+ width={72}
1035
+ height={90}
1036
+ className={
1037
+ item.kind === 'image'
1038
+ ? styles.thumbnailImage
1039
+ : `${styles.thumbnailImage} ${styles.thumbnailPreview}`
1040
+ }
1041
+ />
1042
+ ) : null}
1043
+ {item.kind === 'video' ? (
1044
+ <span
1045
+ className={styles.videoMark}
1046
+ aria-hidden="true"
1047
+ data-product-video-mark
1048
+ >
1049
+ <svg
1050
+ viewBox="0 0 24 24"
1051
+ fill="currentColor"
1052
+ aria-hidden="true"
1053
+ >
1054
+ <path d="M8 5v14l11-7z" />
1055
+ </svg>
1056
+ </span>
1057
+ ) : null}
1006
1058
  </button>
1007
1059
  ))}
1008
1060
  </div>
@@ -62,3 +62,40 @@ export function productThumbnailKeyTarget(
62
62
 
63
63
  return undefined;
64
64
  }
65
+
66
+ export type ProductMediaItem =
67
+ | { kind: 'image'; key: string; src: string }
68
+ | { kind: 'video'; key: string; src: string; preview: string | null };
69
+
70
+ export interface ProductMediaSources {
71
+ images?: { full?: string[] | null; small?: string[] | null } | null;
72
+ videos?:
73
+ | { id: number; product_video: string | null; preview: string | null }[]
74
+ | null;
75
+ }
76
+
77
+ // The pictures and videos of a product in the order its gallery shows them:
78
+ // the full images first (the small copies when it has none), then the videos
79
+ // in the order the backend sends them. A video without a file is left out.
80
+ export function productMediaItems(
81
+ product: ProductMediaSources | null | undefined,
82
+ ): ProductMediaItem[] {
83
+ const images = product?.images;
84
+ const photos = images?.full?.length ? images.full : (images?.small ?? []);
85
+ const items = photos.map(
86
+ (src, index): ProductMediaItem => ({ kind: 'image', key: `image-${index}`, src }),
87
+ );
88
+
89
+ for (const video of product?.videos ?? []) {
90
+ if (video.product_video) {
91
+ items.push({
92
+ kind: 'video',
93
+ key: `video-${video.id}`,
94
+ src: video.product_video,
95
+ preview: video.preview,
96
+ });
97
+ }
98
+ }
99
+
100
+ return items;
101
+ }
@@ -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',