@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
@@ -1,10 +1,11 @@
1
1
  <script lang="ts">
2
- import { setStockForm } from '../admin.remote';
3
- import { StockSchema } from '../schema';
4
2
  import { Form, NumberField } from '@zeyolabs/ui/form';
5
3
  import Button from '@zeyolabs/ui/form/Button.svelte';
6
4
  import Span from '@zeyolabs/ui/text/Span.svelte';
7
5
 
6
+ import { setStockForm } from '../admin.remote';
7
+ import { StockSchema } from '../schema';
8
+
8
9
  let { id, name, stock }: { id: number; name: string; stock: number } = $props();
9
10
 
10
11
  const form = $derived(setStockForm.for(id));
@@ -13,7 +13,8 @@ export const MAX_COMPONENTS = 10;
13
13
  type ComponentRow = StockComponent & { componentId: number };
14
14
 
15
15
  /** The part of a paid order line the stock cares about. */
16
- export type PaidLine = { productId: number; quantity: number };
16
+ /** A paid line. `singleUnits`: `quantity` is single units (a kit's part), taken as is, not counted as sold. */
17
+ export type PaidLine = { productId: number; quantity: number; singleUnits?: boolean };
17
18
 
18
19
  /**
19
20
  * SQL for "this product can be bought right now": a plain product has at least one whole pack, a
@@ -152,6 +153,10 @@ export class StockService {
152
153
  const packSize = new Map(rows.map((r) => [r.id, r.packSize]));
153
154
  const statements = [];
154
155
  for (const line of lines) {
156
+ if (line.singleUnits) {
157
+ statements.push(this.decrement(line.productId, line.quantity));
158
+ continue;
159
+ }
155
160
  const parts = components.get(line.productId);
156
161
  if (parts) {
157
162
  for (const part of parts) {
@@ -0,0 +1,45 @@
1
+ <script lang="ts">
2
+ import { page as current } from '$app/state';
3
+ import ChevronLeft from '@lucide/svelte/icons/chevron-left';
4
+ import ChevronRight from '@lucide/svelte/icons/chevron-right';
5
+
6
+ import { Paging } from '../catalogue/library';
7
+
8
+ /** Links to the pages of a listing (`?page=N`), so every page is a real, crawlable URL. */
9
+ let { page, pages }: { page: number; pages: number } = $props();
10
+
11
+ const href = (n: number) =>
12
+ n === 1 ? current.url.pathname : `${current.url.pathname}?page=${n}`;
13
+
14
+ const box =
15
+ 'inline-flex h-10 min-w-10 items-center justify-center gap-1 rounded-full px-3 text-sm no-underline';
16
+ const link = `${box} border border-[var(--bd)] text-[var(--tx)] hover:border-[var(--primary-strong)] hover:text-[var(--primary-strong)]`;
17
+ </script>
18
+
19
+ {#if pages > 1}
20
+ <!-- eslint-disable svelte/no-navigation-without-resolve -- same path as this page, only ?page changes -->
21
+ <nav class="mt-10 flex flex-wrap items-center justify-center gap-2" aria-label="Pages">
22
+ {#if page > 1}
23
+ <a class={link} href={href(page - 1)} rel="prev">
24
+ <ChevronLeft class="size-4" aria-hidden="true" /> Previous
25
+ </a>
26
+ {/if}
27
+ {#each Paging.window(page, pages) as n, i (n ?? `gap-${i}`)}
28
+ {#if n === null}
29
+ <div class="{box} text-[var(--txt)]" aria-hidden="true">…</div>
30
+ {:else if n === page}
31
+ <div class="{box} bg-[var(--primary-strong)] font-medium text-white" aria-current="page">
32
+ {n}
33
+ </div>
34
+ {:else}
35
+ <a class={link} aria-label="Page {n}" href={href(n)}>{n}</a>
36
+ {/if}
37
+ {/each}
38
+ {#if page < pages}
39
+ <a class={link} href={href(page + 1)} rel="next">
40
+ Next <ChevronRight class="size-4" aria-hidden="true" />
41
+ </a>
42
+ {/if}
43
+ </nav>
44
+ <!-- eslint-enable svelte/no-navigation-without-resolve -->
45
+ {/if}
@@ -1,13 +1,27 @@
1
1
  <script lang="ts">
2
2
  import { page } from '$app/state';
3
+ import Title from '@zeyolabs/ui/text/Title.svelte';
3
4
 
4
5
  import { shopContext } from '../context';
5
6
 
6
- let { description, title }: { description: string; title: string } = $props();
7
+ let {
8
+ description,
9
+ heading = true,
10
+ title,
11
+ }: {
12
+ description: string;
13
+ /** False when the page renders its own `<h1>` (the product page puts it beside the gallery). */
14
+ heading?: boolean;
15
+ title: string;
16
+ } = $props();
7
17
 
8
18
  const context = shopContext();
9
- // Canonical ignores the query string, so `?show=N` deep links don't count as duplicate pages.
10
- const canonical = $derived(`${context.siteUrl}${page.url.pathname}`);
19
+ // Canonical drops the query string except `?page=N` (each listing page is its own page), so
20
+ // other parameters don't count as duplicate pages.
21
+ const listingPage = $derived(Number(page.url.searchParams.get('page')) || 1);
22
+ const canonical = $derived(
23
+ `${context.siteUrl}${page.url.pathname}${listingPage > 1 ? `?page=${listingPage}` : ''}`
24
+ );
11
25
  </script>
12
26
 
13
27
  <svelte:head>
@@ -21,4 +35,6 @@
21
35
  <meta content="website" property="og:type" />
22
36
  </svelte:head>
23
37
 
24
- <h1 class="mb-10 text-4xl font-semibold tracking-tight text-[var(--primary-strong)]">{title}</h1>
38
+ {#if heading}
39
+ <Title class="mb-10 text-[var(--primary-strong)]" level={1}>{title}</Title>
40
+ {/if}
package/ui/Stars.svelte CHANGED
@@ -4,6 +4,7 @@
4
4
  const pct = $derived(`${Math.max(0, Math.min(5, rating)) * 20}%`);
5
5
  </script>
6
6
 
7
+ <!-- eslint-disable svelte/no-restricted-html-elements -- an inline glyph graphic, not text -->
7
8
  <span
8
9
  class="relative inline-block leading-none {size}"
9
10
  aria-label="{rating} out of 5 stars"
@@ -11,8 +12,9 @@
11
12
  >
12
13
  <span class="text-[var(--bd)]" aria-hidden="true">★★★★★</span>
13
14
  <span
14
- class="absolute inset-0 overflow-hidden whitespace-nowrap text-[var(--primary-strong)]"
15
15
  style:width={pct}
16
+ class="absolute inset-0 overflow-hidden whitespace-nowrap text-[var(--primary-strong)]"
16
17
  aria-hidden="true">★★★★★</span
17
18
  >
18
19
  </span>
20
+ <!-- eslint-enable svelte/no-restricted-html-elements -->