@zeyolabs/shopping 2026.11.37 → 2026.11.39

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.
Files changed (46) hide show
  1. package/basket/client.remote.ts +16 -2
  2. package/basket/cookies.server.ts +13 -1
  3. package/basket/library.ts +58 -0
  4. package/basket/pages/Basket.svelte +80 -30
  5. package/basket/service.server.ts +139 -6
  6. package/bundles/admin/BundleEditPage.svelte +7 -4
  7. package/bundles/admin/BundleForm.svelte +50 -11
  8. package/bundles/admin/BundlesPage.svelte +14 -10
  9. package/bundles/client.remote.ts +18 -6
  10. package/bundles/library.ts +51 -0
  11. package/bundles/pages/Bundle.svelte +233 -68
  12. package/bundles/schema.ts +13 -2
  13. package/bundles/service.server.ts +185 -33
  14. package/catalogue/admin/CategoriesPage.svelte +13 -10
  15. package/catalogue/admin/CategoryForm.svelte +4 -3
  16. package/catalogue/admin/ProductEditPage.svelte +7 -4
  17. package/catalogue/admin/ProductForm.svelte +31 -29
  18. package/catalogue/admin/ProductsPage.svelte +16 -14
  19. package/catalogue/client.remote.ts +23 -9
  20. package/catalogue/components/ProductCard.svelte +22 -14
  21. package/catalogue/library.ts +91 -0
  22. package/catalogue/loads.server.ts +8 -4
  23. package/catalogue/pages/Category.svelte +15 -6
  24. package/catalogue/pages/Product.svelte +164 -45
  25. package/catalogue/pages/Search.svelte +12 -7
  26. package/catalogue/pages/Shop.svelte +12 -12
  27. package/catalogue/service.server.ts +44 -9
  28. package/checkout/manager.server.ts +68 -16
  29. package/checkout/pages/CheckoutSuccess.svelte +10 -8
  30. package/customers/pages/Account.svelte +19 -15
  31. package/db/schema.ts +27 -3
  32. package/fulfilment/admin/OrderPage.svelte +60 -56
  33. package/fulfilment/admin/OrdersPage.svelte +26 -22
  34. package/orders/manager.server.ts +45 -11
  35. package/orders/pages/Order.svelte +35 -29
  36. package/orders/service.server.ts +25 -3
  37. package/package.json +5 -4
  38. package/reviews/admin/ReviewsPage.svelte +23 -19
  39. package/reviews/components/ReviewForm.svelte +3 -2
  40. package/reviews/components/Reviews.svelte +17 -13
  41. package/stock/admin/StockPage.svelte +12 -9
  42. package/stock/admin/StockRow.svelte +3 -2
  43. package/stock/service.server.ts +6 -1
  44. package/ui/PageLinks.svelte +45 -0
  45. package/ui/PageTitle.svelte +20 -4
  46. package/ui/Stars.svelte +3 -1
@@ -17,19 +17,33 @@ export const getMenuCategories = Remote.Query(async () => {
17
17
  return (await service.categories()).map(({ name, slug }) => ({ name, slug }));
18
18
  });
19
19
 
20
- export const getShop = Remote.Query(async () => {
21
- const service = catalogue();
22
- const [categories, products] = await Promise.all([service.categories(), service.products()]);
23
- return { categories, products };
24
- });
20
+ const PageParam = z.number().int().min(1).max(10_000);
25
21
 
26
- export const getCategoryPage = Remote.Query(ShopSchema.SlugParam, async (slug) => {
22
+ /** A page past the last one is a 404, so stale `?page=` links don't render an empty page. */
23
+ function checkPage<T extends { page: number; pages: number }>(listing: T): T {
24
+ if (listing.page > listing.pages) throw Error404('Page not found');
25
+ return listing;
26
+ }
27
+
28
+ export const getShop = Remote.Query(PageParam, async (page) => {
27
29
  const service = catalogue();
28
- const category = await service.category(slug);
29
- if (!category) throw Error404('Category not found');
30
- return { category, products: await service.categoryProducts(category.id) };
30
+ const [categories, listing] = await Promise.all([
31
+ service.categories(),
32
+ service.productPage(page),
33
+ ]);
34
+ return { categories, ...checkPage(listing) };
31
35
  });
32
36
 
37
+ export const getCategoryPage = Remote.Query(
38
+ z.object({ page: PageParam, slug: ShopSchema.SlugParam }),
39
+ async ({ page, slug }) => {
40
+ const service = catalogue();
41
+ const category = await service.category(slug);
42
+ if (!category) throw Error404('Category not found');
43
+ return { category, ...checkPage(await service.productPage(page, category.id)) };
44
+ }
45
+ );
46
+
33
47
  export const getProduct = Remote.Query(ShopSchema.SlugParam, async (slug) => {
34
48
  const db = shopping().db();
35
49
  const service = new CatalogueService(db);
@@ -1,9 +1,12 @@
1
1
  <script lang="ts">
2
2
  import { resolve } from '$app/paths';
3
+ import Span from '@zeyolabs/ui/text/Span.svelte';
4
+ import Text from '@zeyolabs/ui/text/Text.svelte';
5
+
3
6
  import { shopContext } from '../../context';
7
+ import { Stock } from '../../stock/library';
4
8
  import { Images } from '../../utils/images';
5
9
  import { Money } from '../../utils/money';
6
- import { Stock } from '../../stock/library';
7
10
 
8
11
  type Product = {
9
12
  comparePricePence: null | number;
@@ -47,29 +50,34 @@
47
50
  />
48
51
  {/if}
49
52
  {#if badge.kind === 'out'}
50
- <span
51
- class="absolute top-2 left-2 rounded-full bg-white/95 px-2.5 py-1 text-xs font-medium text-[var(--txs)] shadow-sm"
52
- >Out of stock</span
53
+ <Span
54
+ class="absolute top-2 left-2 rounded-full bg-white/95 px-2.5 py-1 shadow-sm"
55
+ bold
56
+ color="secondary"
57
+ size="sm">Out of stock</Span
53
58
  >
54
59
  {:else if badge.kind === 'low'}
55
- <span
56
- class="absolute top-2 left-2 rounded-full bg-white/95 px-2.5 py-1 text-xs font-medium text-[var(--txs)] shadow-sm"
57
- >Only {badge.count} left</span
60
+ <Span
61
+ class="absolute top-2 left-2 rounded-full bg-white/95 px-2.5 py-1 shadow-sm"
62
+ bold
63
+ color="secondary"
64
+ size="sm">Only {badge.count} left</Span
58
65
  >
59
66
  {:else if onSale}
60
- <span
61
- class="absolute top-2 left-2 rounded-full bg-[var(--primary-strong)] px-2.5 py-1 text-xs font-medium text-white"
62
- >Sale</span
67
+ <Span
68
+ class="absolute top-2 left-2 rounded-full bg-[var(--primary-strong)] px-2.5 py-1 text-white"
69
+ bold
70
+ size="sm">Sale</Span
63
71
  >
64
72
  {/if}
65
73
  </div>
66
74
  <div class="px-2 pt-3 pb-2">
67
- <p class="leading-snug font-medium">{product.name}</p>
68
- <p class="mt-1 text-[var(--txs)]">
69
- <span class="font-medium text-[var(--tx)]">{Money.format(product.pricePence)}</span>
75
+ <Text bold>{product.name}</Text>
76
+ <Text class="mt-1" color="secondary">
77
+ <Span bold>{Money.format(product.pricePence)}</Span>
70
78
  {#if onSale}
71
79
  <s class="ml-1 text-sm">{Money.format(product.comparePricePence!)}</s>
72
80
  {/if}
73
- </p>
81
+ </Text>
74
82
  </div>
75
83
  </a>
@@ -36,3 +36,94 @@ function fitPattern(word: string): string {
36
36
  }
37
37
  return fitted;
38
38
  }
39
+
40
+ export type ProductParagraph = { heading: null | string; text: string };
41
+ export type ProductSpec = { label: string; value: string };
42
+
43
+ const SPEC_LINE = /^([A-Za-z][\w ()%./&-]{0,29}):\s+(\S.{0,59})$/;
44
+ const UNKNOWN_VALUE = /^(unknown|n\/a|none|-+)$/i;
45
+
46
+ /**
47
+ * A product description is plain text. Blocks are separated by a blank line; a block whose lines
48
+ * are all short `Label: value` pairs (two or more) is a spec list, and a short first line without
49
+ * closing punctuation, followed by more lines, is that block's heading. Pure.
50
+ */
51
+ export const ProductText = {
52
+ /** Descriptions longer than this show their first paragraphs and fold the rest behind "Read more". */
53
+ FOLD_AFTER_CHARS: 600,
54
+
55
+ parse(description: string): { paragraphs: ProductParagraph[]; specs: ProductSpec[] } {
56
+ const paragraphs: ProductParagraph[] = [];
57
+ const specs: ProductSpec[] = [];
58
+ const blocks = description
59
+ .replace(/\r\n?/g, '\n')
60
+ .split(/\n\s*\n/)
61
+ .map((block) =>
62
+ block
63
+ .split('\n')
64
+ .map((line) => line.trim())
65
+ .filter(Boolean)
66
+ )
67
+ .filter((lines) => lines.length > 0);
68
+
69
+ for (const lines of blocks) {
70
+ const pairs = lines.map((line) => SPEC_LINE.exec(line));
71
+ if (lines.length >= 2 && pairs.every(Boolean)) {
72
+ for (const pair of pairs) {
73
+ const value = pair![2].trim();
74
+ if (!UNKNOWN_VALUE.test(value)) specs.push({ label: pair![1].trim(), value });
75
+ }
76
+ continue;
77
+ }
78
+ const [first, ...rest] = lines;
79
+ const isHeading = rest.length > 0 && first.length <= 60 && !/[.!?:,;]$/.test(first);
80
+ paragraphs.push(
81
+ isHeading
82
+ ? { heading: first, text: rest.join('\n') }
83
+ : { heading: null, text: lines.join('\n') }
84
+ );
85
+ }
86
+ return { paragraphs, specs };
87
+ },
88
+
89
+ /** How many leading paragraphs to show before folding: at least one, then up to `FOLD_AFTER_CHARS`. */
90
+ visibleCount(paragraphs: ProductParagraph[]): number {
91
+ let chars = 0;
92
+ for (const [i, p] of paragraphs.entries()) {
93
+ chars += (p.heading?.length ?? 0) + p.text.length;
94
+ if (chars > ProductText.FOLD_AFTER_CHARS) return Math.max(1, i);
95
+ }
96
+ return paragraphs.length;
97
+ },
98
+ };
99
+
100
+ /** Listing pages (`?page=N`, 1-based). Pure. */
101
+ export const Paging = {
102
+ /** Products per page: fills grids of 2, 3 and 4 columns evenly. */
103
+ PER_PAGE: 24,
104
+
105
+ /** Page count for `total` items; at least 1, so an empty listing still has its first page. */
106
+ pages(total: number): number {
107
+ return Math.max(1, Math.ceil(total / Paging.PER_PAGE));
108
+ },
109
+
110
+ /** `?page=` as a page number; anything that is not a whole number from 1 is page 1. */
111
+ parse(value: null | string): number {
112
+ const page = Number(value);
113
+ return Number.isInteger(page) && page >= 1 && page <= 10_000 ? page : 1;
114
+ },
115
+
116
+ /** The page numbers to link: first, last and the current one's neighbours, null for a gap. */
117
+ window(page: number, pages: number): (null | number)[] {
118
+ const shown = [...new Set([1, page, page + 1, page - 1, pages])]
119
+ .filter((n) => n >= 1 && n <= pages)
120
+ .toSorted((a, b) => a - b);
121
+ const out: (null | number)[] = [];
122
+ for (const [i, n] of shown.entries()) {
123
+ if (i > 0 && n - shown[i - 1] === 2) out.push(n - 1);
124
+ else if (i > 0 && n - shown[i - 1] > 2) out.push(null);
125
+ out.push(n);
126
+ }
127
+ return out;
128
+ },
129
+ };
@@ -9,6 +9,7 @@ import {
9
9
  getUkShippingRate,
10
10
  searchShop,
11
11
  } from './client.remote';
12
+ import { Paging } from './library';
12
13
  import { CatalogueService } from './service.server';
13
14
 
14
15
  /**
@@ -24,12 +25,15 @@ export async function layoutLoad() {
24
25
  return { menuCategories: await getMenuCategories() };
25
26
  }
26
27
 
27
- export async function shopLoad() {
28
- return { shop: await getShop() };
28
+ /** `/shop?page=N`. */
29
+ export async function shopLoad({ url }: { url: URL }) {
30
+ return { shop: await getShop(Paging.parse(url.searchParams.get('page'))) };
29
31
  }
30
32
 
31
- export async function categoryLoad({ params }: SlugEvent) {
32
- return { page: await getCategoryPage(params.slug ?? '') };
33
+ /** `/category/<slug>?page=N`. */
34
+ export async function categoryLoad({ params, url }: SlugEvent) {
35
+ const page = Paging.parse(url.searchParams.get('page'));
36
+ return { page: await getCategoryPage({ page, slug: params.slug ?? '' }) };
33
37
  }
34
38
 
35
39
  /** Legacy links (`/product/<old-slug>`, `/product/<parent>?variant=<code>`) redirect; unknown slugs 404. */
@@ -1,9 +1,13 @@
1
1
  <script lang="ts">
2
2
  import { resolve } from '$app/paths';
3
+ import Text from '@zeyolabs/ui/text/Text.svelte';
4
+
5
+ import type { getCategoryPage } from '../client.remote';
6
+
3
7
  import { shopContext } from '../../context';
8
+ import PageLinks from '../../ui/PageLinks.svelte';
4
9
  import PageTitle from '../../ui/PageTitle.svelte';
5
10
  import ProductCard from '../components/ProductCard.svelte';
6
- import type { getCategoryPage } from '../client.remote';
7
11
 
8
12
  /** From the route's server `load` (`categoryLoad`). */
9
13
  let { data }: { data: Awaited<ReturnType<typeof getCategoryPage>> } = $props();
@@ -11,24 +15,29 @@
11
15
  const context = shopContext();
12
16
  </script>
13
17
 
14
- <p class="mb-2 text-sm"><a class="underline" href={resolve('/shop')}>All products</a></p>
18
+ <Text class="mb-2"><a class="underline" href={resolve('/shop')}>All products</a></Text>
15
19
  <PageTitle
16
20
  description="Buy {data.category.name} from {context.siteName}."
17
21
  title={data.category.name}
18
22
  />
19
23
 
20
24
  {#if data.category.description}
21
- <p class="-mt-6 mb-6 max-w-prose whitespace-pre-line text-[var(--txs)]">
25
+ <Text class="-mt-6 mb-6 max-w-prose whitespace-pre-line" color="secondary">
22
26
  {data.category.description}
23
- </p>
27
+ </Text>
24
28
  {/if}
25
29
 
26
30
  {#if data.products.length === 0}
27
- <p>No products available right now. Please check back soon.</p>
31
+ <Text>No products available right now. Please check back soon.</Text>
28
32
  {:else}
29
- <ul class="grid gap-6 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4">
33
+ <Text class="mb-4" color="secondary">
34
+ {data.total}
35
+ {data.total === 1 ? 'product' : 'products'}{#if data.pages > 1}, page {data.page} of {data.pages}{/if}
36
+ </Text>
37
+ <ul class="grid grid-cols-2 gap-3 sm:gap-6 md:grid-cols-3 xl:grid-cols-4">
30
38
  {#each data.products as product (product.id)}
31
39
  <li><ProductCard {product} /></li>
32
40
  {/each}
33
41
  </ul>
42
+ <PageLinks page={data.page} pages={data.pages} />
34
43
  {/if}
@@ -2,20 +2,26 @@
2
2
  import type { Snippet } from 'svelte';
3
3
 
4
4
  import { resolve } from '$app/paths';
5
- import PageTitle from '../../ui/PageTitle.svelte';
6
- import Reviews from '../../reviews/components/Reviews.svelte';
7
- import Stars from '../../ui/Stars.svelte';
5
+ import ShoppingBasket from '@lucide/svelte/icons/shopping-basket';
6
+ import { Form } from '@zeyolabs/ui/form';
7
+ import Button from '@zeyolabs/ui/form/Button.svelte';
8
+ import ImageGallery from '@zeyolabs/ui/gallery/ImageGallery.svelte';
9
+ import Span from '@zeyolabs/ui/text/Span.svelte';
10
+ import Text from '@zeyolabs/ui/text/Text.svelte';
11
+ import Title from '@zeyolabs/ui/text/Title.svelte';
12
+
13
+ import type { getProduct } from '../client.remote';
14
+
8
15
  import { addToBasketForm } from '../../basket/client.remote';
9
16
  import { AddToBasketSchema } from '../../basket/schema';
10
- import type { getProduct } from '../client.remote';
11
- import ShoppingBasket from '@lucide/svelte/icons/shopping-basket';
12
17
  import { shopContext } from '../../context';
18
+ import Reviews from '../../reviews/components/Reviews.svelte';
19
+ import { Stock } from '../../stock/library';
20
+ import PageTitle from '../../ui/PageTitle.svelte';
21
+ import Stars from '../../ui/Stars.svelte';
13
22
  import { Images } from '../../utils/images';
14
23
  import { Money } from '../../utils/money';
15
- import { Stock } from '../../stock/library';
16
- import { Form } from '@zeyolabs/ui/form';
17
- import Button from '@zeyolabs/ui/form/Button.svelte';
18
- import ImageGallery from '@zeyolabs/ui/gallery/ImageGallery.svelte';
24
+ import { ProductText } from '../library';
19
25
 
20
26
  let {
21
27
  data,
@@ -28,60 +34,108 @@
28
34
  } = $props();
29
35
 
30
36
  const context = shopContext();
37
+
38
+ const STOCK_DOT = { in: 'bg-[var(--primary)]', low: 'bg-amber-500', out: 'bg-[var(--txt)]' };
31
39
  </script>
32
40
 
33
41
  {let product = $derived(data.product)}
34
42
  {let stockBadge = $derived(Stock.badge(product.stock, product.lowStockThreshold))}
43
+ {let text = $derived(ProductText.parse(product.description))}
44
+ {let visible = $derived(ProductText.visibleCount(text.paragraphs))}
45
+ {let saving = $derived(
46
+ product.comparePricePence && product.comparePricePence > product.pricePence
47
+ ? Math.round((1 - product.pricePence / product.comparePricePence) * 100)
48
+ : 0
49
+ )}
35
50
 
36
51
  <PageTitle
37
52
  description={(product.shortDescription || product.description).slice(0, 160)}
53
+ heading={false}
38
54
  title={product.name}
39
55
  />
40
56
 
41
- <div class="grid gap-8 md:grid-cols-2">
42
- {#key product.id}
43
- <ImageGallery
44
- name={product.name}
45
- images={product.images.map((image) => ({
46
- alt: image.alt,
47
- src: Images.url(context.imageBaseUrl, image.src),
48
- }))}
49
- />
50
- {/key}
51
- <div>
57
+ <div class="grid gap-8 md:grid-cols-2 lg:gap-14">
58
+ <div class="md:sticky md:top-6 md:self-start">
59
+ {#key product.id}
60
+ <ImageGallery
61
+ name={product.name}
62
+ images={product.images.map((image) => ({
63
+ alt: image.alt,
64
+ src: Images.url(context.imageBaseUrl, image.src),
65
+ }))}
66
+ />
67
+ {/key}
68
+ </div>
69
+
70
+ <div class="flex flex-col">
71
+ <Title level={1} size="lg">{product.name}</Title>
72
+
52
73
  {#if data.reviews.average !== null}
53
- <a class="mb-2 flex items-center gap-2 text-sm no-underline" href="#reviews-heading">
74
+ <a
75
+ class="mt-3 flex w-fit items-center gap-2 text-sm text-[var(--txs)] no-underline hover:text-[var(--tx)]"
76
+ href="#reviews"
77
+ >
54
78
  <Stars rating={data.reviews.average} size="text-sm" />
55
79
  {data.reviews.count}
56
80
  {data.reviews.count === 1 ? 'review' : 'reviews'}
57
81
  </a>
58
82
  {/if}
59
- <p class="text-2xl">
60
- {Money.format(product.pricePence)}
61
- {#if product.comparePricePence && product.comparePricePence > product.pricePence}
62
- <s class="text-base opacity-60">{Money.format(product.comparePricePence)}</s>
83
+
84
+ <div class="mt-5 flex flex-wrap items-baseline gap-x-3 gap-y-1">
85
+ <!-- eslint-disable-next-line svelte/no-restricted-html-elements -- the price is display-sized, bigger than any Span size -->
86
+ <span class="text-3xl font-semibold">{Money.format(product.pricePence)}</span>
87
+ {#if saving > 0}
88
+ <s class="text-lg text-[var(--txt)]">{Money.format(product.comparePricePence!)}</s>
89
+ <Span
90
+ class="rounded-full bg-[var(--primary-soft)] px-2.5 py-0.5 text-[var(--primary-strong)]"
91
+ bold
92
+ >
93
+ Save {saving}%
94
+ </Span>
63
95
  {/if}
64
- </p>
96
+ </div>
97
+ {#if product.packSize > 1}
98
+ <Text class="mt-1" color="secondary">Pack of {product.packSize}</Text>
99
+ {/if}
100
+
101
+ {#if product.shortDescription}
102
+ <Text class="mt-5" color="secondary">{product.shortDescription}</Text>
103
+ {/if}
104
+
65
105
  {#if data.options.length > 1}
66
- <p class="mt-4">
67
- {data.variationName}:
68
- {#each data.options as option (option.slug)}
69
- {#if option.slug === product.slug}
70
- <strong class="mr-2">{option.label}</strong>
71
- {:else}
72
- <a class="mr-2 underline" href={resolve('/product/[slug]', { slug: option.slug })}>
73
- {option.label}
74
- </a>
75
- {/if}
76
- {/each}
77
- </p>
106
+ <div class="mt-6">
107
+ <Text bold>{data.variationName}</Text>
108
+ <ul class="mt-2 flex flex-wrap gap-2">
109
+ {#each data.options as option (option.slug)}
110
+ <li>
111
+ {#if option.slug === product.slug}
112
+ <div
113
+ class="inline-flex rounded-full border-2 border-[var(--primary-strong)] bg-[var(--primary-soft)] px-4 py-1.5 text-sm font-medium text-[var(--primary-strong)]"
114
+ aria-current="true"
115
+ >
116
+ {option.label}
117
+ </div>
118
+ {:else}
119
+ <a
120
+ class="inline-flex rounded-full border-2 border-[var(--bd)] px-4 py-1.5 text-sm text-[var(--tx)] no-underline transition hover:border-[var(--primary-strong)] hover:text-[var(--tx)]"
121
+ href={resolve('/product/[slug]', { slug: option.slug })}
122
+ >
123
+ {option.label}
124
+ </a>
125
+ {/if}
126
+ </li>
127
+ {/each}
128
+ </ul>
129
+ </div>
78
130
  {/if}
79
- {#if product.shortDescription}<p class="mt-4">{product.shortDescription}</p>{/if}
80
- <p class="mt-4 whitespace-pre-line">{product.description}</p>
81
- <p class="mt-4">
131
+
132
+ <Text class="mt-6 flex items-center gap-2" bold>
133
+ <!-- eslint-disable-next-line svelte/no-restricted-html-elements -- a colour dot inside the line of text -->
134
+ <span class="size-2.5 rounded-full {STOCK_DOT[stockBadge.kind]}" aria-hidden="true"></span>
82
135
  {#if stockBadge.kind === 'out'}Out of stock{:else if stockBadge.kind === 'low'}Only {stockBadge.count}
83
136
  left{:else}In stock{/if}
84
- </p>
137
+ </Text>
138
+
85
139
  {#if product.stock > 0}
86
140
  {const form = addToBasketForm.for(product.id)}
87
141
  <Form
@@ -91,16 +145,81 @@
91
145
  reset={false}
92
146
  schema={AddToBasketSchema}
93
147
  >
94
- <Button {form} loadingMessage="Adding…" size="lg">
148
+ <Button class="w-full sm:w-auto" {form} loadingMessage="Adding…" size="lg">
95
149
  <ShoppingBasket size={18} />
96
150
  Add to basket
97
151
  </Button>
98
152
  </Form>
153
+ {:else}
154
+ <div class="mt-4">{@render outOfStock?.(product.id)}</div>
99
155
  {/if}
100
- {#if product.stock <= 0}
101
- {@render outOfStock?.(product.id)}
156
+
157
+ {#if text.specs.length > 0}
158
+ <dl
159
+ class="mt-8 grid grid-cols-2 gap-px overflow-hidden rounded-xl border border-[var(--bd)] bg-[var(--bd)]"
160
+ >
161
+ {#each text.specs.slice(0, 4) as spec (spec.label)}
162
+ <div class="bg-[var(--sf)] px-4 py-3">
163
+ <dt class="text-xs text-[var(--txs)]">{spec.label}</dt>
164
+ <dd class="mt-0.5 font-medium text-[var(--tx)]">{spec.value}</dd>
165
+ </div>
166
+ {/each}
167
+ </dl>
102
168
  {/if}
103
169
  </div>
104
170
  </div>
105
171
 
172
+ {#if text.paragraphs.length > 0 || text.specs.length > 4}
173
+ <section
174
+ class="mt-16 grid gap-12 border-t border-[var(--bd)] pt-10 {text.specs.length > 4 &&
175
+ text.paragraphs.length > 0
176
+ ? 'lg:grid-cols-[minmax(0,3fr)_minmax(0,2fr)]'
177
+ : ''}"
178
+ >
179
+ {#if text.paragraphs.length > 0}
180
+ <div class="max-w-prose">
181
+ <Title level={2} size="md">About this product</Title>
182
+ {#snippet paragraph(p: { heading: null | string; text: string })}
183
+ <div class="mt-5">
184
+ {#if p.heading}<Title level={3} size="sm">
185
+ {p.heading}
186
+ </Title>{/if}
187
+ <Text class="whitespace-pre-line {p.heading ? 'mt-1' : ''}" color="secondary"
188
+ >{p.text}</Text
189
+ >
190
+ </div>
191
+ {/snippet}
192
+ {#each text.paragraphs.slice(0, visible) as p, i (i)}
193
+ {@render paragraph(p)}
194
+ {/each}
195
+ {#if visible < text.paragraphs.length}
196
+ <details class="group mt-5">
197
+ <summary
198
+ class="cursor-pointer list-none font-medium text-[var(--primary-strong)] group-open:hidden"
199
+ >
200
+ Read more
201
+ </summary>
202
+ {#each text.paragraphs.slice(visible) as p, i (i)}
203
+ {@render paragraph(p)}
204
+ {/each}
205
+ </details>
206
+ {/if}
207
+ </div>
208
+ {/if}
209
+ {#if text.specs.length > 4}
210
+ <div>
211
+ <Title level={2} size="md">Specifications</Title>
212
+ <dl class="mt-5 divide-y divide-[var(--bd)] border-y border-[var(--bd)] text-sm">
213
+ {#each text.specs as spec (spec.label)}
214
+ <div class="flex justify-between gap-6 py-2.5">
215
+ <dt class="text-[var(--txs)]">{spec.label}</dt>
216
+ <dd class="text-right font-medium text-[var(--tx)]">{spec.value}</dd>
217
+ </div>
218
+ {/each}
219
+ </dl>
220
+ </div>
221
+ {/if}
222
+ </section>
223
+ {/if}
224
+
106
225
  <Reviews reviews={data.reviews} />
@@ -1,7 +1,10 @@
1
1
  <script lang="ts">
2
+ import Text from '@zeyolabs/ui/text/Text.svelte';
3
+
4
+ import type { searchShop } from '../client.remote';
5
+
2
6
  import PageTitle from '../../ui/PageTitle.svelte';
3
7
  import ProductCard from '../components/ProductCard.svelte';
4
- import type { searchShop } from '../client.remote';
5
8
 
6
9
  let {
7
10
  search,
@@ -36,14 +39,16 @@
36
39
  </form>
37
40
 
38
41
  {#if search.query === ''}
39
- <p class="text-[var(--txs)]">Type what you are looking for.</p>
42
+ <Text color="secondary">Type what you are looking for.</Text>
40
43
  {:else if search.products.length === 0}
41
- <p>Nothing matches "{search.query}". Try fewer or different words.</p>
44
+ <Text>Nothing matches "{search.query}". Try fewer or different words.</Text>
42
45
  {:else}
43
- <p class="mb-4 text-[var(--txs)]" aria-live="polite">
44
- {search.products.length === 48 ? 'Top 48' : search.products.length}
45
- {search.products.length === 1 ? 'result' : 'results'} for "{search.query}"
46
- </p>
46
+ <div class="mb-4" aria-live="polite">
47
+ <Text color="secondary">
48
+ {search.products.length === 48 ? 'Top 48' : search.products.length}
49
+ {search.products.length === 1 ? 'result' : 'results'} for "{search.query}"
50
+ </Text>
51
+ </div>
47
52
  <ul class="grid gap-6 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4">
48
53
  {#each search.products as product (product.id)}
49
54
  <li><ProductCard {product} /></li>
@@ -1,8 +1,12 @@
1
1
  <script lang="ts">
2
2
  import { resolve } from '$app/paths';
3
+ import Text from '@zeyolabs/ui/text/Text.svelte';
4
+
5
+ import type { getShop } from '../client.remote';
6
+
7
+ import PageLinks from '../../ui/PageLinks.svelte';
3
8
  import PageTitle from '../../ui/PageTitle.svelte';
4
9
  import ProductCard from '../components/ProductCard.svelte';
5
- import type { getShop } from '../client.remote';
6
10
 
7
11
  let {
8
12
  description,
@@ -18,16 +22,10 @@
18
22
  } = $props();
19
23
  </script>
20
24
 
21
- <!-- In stock first; the database order (sort order, then name) is kept within each group. -->
22
- {let sorted = $derived([
23
- ...shop.products.filter((p) => p.stock > 0),
24
- ...shop.products.filter((p) => p.stock <= 0),
25
- ])}
26
-
27
25
  <PageTitle {description} title="Shop" />
28
26
 
29
27
  {#if intro}
30
- <p class="-mt-6 mb-6 max-w-prose text-[var(--txs)]">{intro}</p>
28
+ <Text class="-mt-6 mb-6 max-w-prose" color="secondary">{intro}</Text>
31
29
  {/if}
32
30
 
33
31
  <nav class="mb-8" aria-label="Categories">
@@ -43,12 +41,14 @@
43
41
  </ul>
44
42
  </nav>
45
43
 
46
- {#if sorted.length === 0}
47
- <p>No products available right now. Please check back soon.</p>
44
+ <!-- In stock first (the query sorts by it, then sort order and name), one page at a time. -->
45
+ {#if shop.products.length === 0}
46
+ <Text>No products available right now. Please check back soon.</Text>
48
47
  {:else}
49
- <ul class="grid gap-6 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4">
50
- {#each sorted as product (product.id)}
48
+ <ul class="grid grid-cols-2 gap-3 sm:gap-6 md:grid-cols-3 xl:grid-cols-4">
49
+ {#each shop.products as product (product.id)}
51
50
  <li><ProductCard {product} /></li>
52
51
  {/each}
53
52
  </ul>
53
+ <PageLinks page={shop.page} pages={shop.pages} />
54
54
  {/if}