@revenexx/cover 0.3.0 → 0.3.2

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.
@@ -1,5 +1,6 @@
1
1
  <script setup lang="ts">
2
- import { footerLinks as defaultFooterLinks, legalLinks as defaultLegalLinks, shopContact } from "../../../config/navigation";
2
+ import type { ShopContact } from "../../../config/navigation";
3
+ import { footerLinks as defaultFooterLinks, legalLinks as defaultLegalLinks, shopContact as noContact } from "../../../config/navigation";
3
4
 
4
5
  // Consumers replace the footer columns / legal links, in priority order:
5
6
  // per-request live menus (useState, e.g. the Blokkli theme from the pages app)
@@ -15,6 +16,9 @@ const liveFooterLinks = useState<{ heading: string; links: { label: string; to:
15
16
  const liveLegalLinks = useState<{ label: string; to: string }[] | null>("cover:nav:legalLinks", () => null);
16
17
  const footerLinks = computed(() => liveFooterLinks.value ?? (appConfig.footerLinks as typeof defaultFooterLinks | undefined) ?? defaultFooterLinks);
17
18
  const legalLinks = computed(() => liveLegalLinks.value ?? (appConfig.legalLinks as typeof defaultLegalLinks | undefined) ?? defaultLegalLinks);
19
+ // The shop's own contact details. The design system holds none, so a storefront
20
+ // that states nothing prints nothing rather than somebody else's address.
21
+ const shopContact = computed<ShopContact>(() => (appConfig.shopContact as ShopContact | undefined) ?? noContact);
18
22
 
19
23
  const { icon } = useIcons();
20
24
  const localePath = useLocalePath();
@@ -34,8 +38,14 @@ const year = new Date().getFullYear();
34
38
  <p class="text-sm/6 text-muted dark:text-white/90">
35
39
  {{ t('footer.tagline') }}
36
40
  </p>
37
- <address class="not-italic flex flex-col gap-2.5 text-sm">
38
- <span class="flex items-start gap-2">
41
+ <address
42
+ v-if="shopContact.address || shopContact.phone || shopContact.email"
43
+ class="not-italic flex flex-col gap-2.5 text-sm"
44
+ >
45
+ <span
46
+ v-if="shopContact.address"
47
+ class="flex items-start gap-2"
48
+ >
39
49
  <UIcon
40
50
  :name="icon('location')"
41
51
  class="size-4 mt-0.5 shrink-0 text-(--ui-primary)"
@@ -43,6 +53,7 @@ const year = new Date().getFullYear();
43
53
  <span class="text-muted dark:text-white/90">{{ shopContact.address }}</span>
44
54
  </span>
45
55
  <a
56
+ v-if="shopContact.phone"
46
57
  :href="`tel:${shopContact.phone.replace(/\s/g, '')}`"
47
58
  class="flex items-center gap-2 text-sm text-muted dark:text-white/90
48
59
  hover:text-default dark:hover:text-white transition-colors"
@@ -54,6 +65,7 @@ const year = new Date().getFullYear();
54
65
  {{ shopContact.phone }}
55
66
  </a>
56
67
  <a
68
+ v-if="shopContact.email"
57
69
  :href="`mailto:${shopContact.email}`"
58
70
  class="flex items-center gap-2 text-sm text-muted dark:text-white/90
59
71
  hover:text-default dark:hover:text-white transition-colors"
@@ -0,0 +1,212 @@
1
+ <script setup lang="ts">
2
+ import type { ProductDetailCategory } from "../../../interfaces/product-detail";
3
+
4
+ /**
5
+ * The whole product page, as a storefront binds it: one component, so a
6
+ * code-first theme and the demo shop show the same page instead of two copies
7
+ * of it that drift (RX-791 — the copies had already drifted, and the one that
8
+ * lost was the one emitting a 404).
9
+ *
10
+ * The URL it reads is `/category/<…category path of any depth>/product/<slug>`.
11
+ * Route parsing is useRouteSubject's, the single place that reads route params
12
+ * for a product URL.
13
+ */
14
+ const localePath = useLocalePath();
15
+
16
+ const { slug, id } = useRouteProductSubject();
17
+
18
+ const {
19
+ status,
20
+ productInfo, mainImages, longDescription,
21
+ stocks, attributes, prices, taxRate, offerPending,
22
+ productCategories, categorySlug, subcategorySlug,
23
+ formatPrice, getDetailImageUrl, ready,
24
+ } = useProductDetail(id);
25
+ await ready();
26
+
27
+ const { icon } = useIcons();
28
+ const { t } = useI18n();
29
+ const toast = useToast();
30
+ const cartStore = useCartStore();
31
+
32
+ const currentCartQuantity = computed(() => {
33
+ return cartStore.items.find(item => item.id === id.value)?.quantity ?? 0;
34
+ });
35
+
36
+ const basePriceCents = computed(() => prices.value[0]?.["1"] ?? 0);
37
+ /** Price on request: no price for this buyer context — never render €0. */
38
+ const hasPrice = computed(() => Object.keys(prices.value[0] ?? {}).length > 0);
39
+
40
+ /** Not found = a malformed product URL (no slug) or a finished fetch with no product. */
41
+ const notFound = computed(
42
+ () => !slug.value || (status.value !== "pending" && !productInfo.value),
43
+ );
44
+
45
+ // Reflect not-found as a real 404. Checked synchronously AFTER the await above:
46
+ // on the server a non-sync watcher runs once at setup and is then stopped, so a
47
+ // watchEffect here would evaluate before the fetch resolved and always see a
48
+ // product. (Never let an empty product crash the render into a 500 — see the
49
+ // guarded template below.)
50
+ if (import.meta.server && notFound.value) {
51
+ setResponseStatus(useRequestEvent(), 404);
52
+ }
53
+
54
+ async function copySku(): Promise<void> {
55
+ if (!productInfo.value) {
56
+ return;
57
+ }
58
+ await navigator.clipboard.writeText(productInfo.value.sku);
59
+ toast.add({ title: t("product.detail.skuCopied"), duration: 1200, icon: icon("copy-check") });
60
+ }
61
+
62
+ const rootCategory = computed(() =>
63
+ productCategories.value.find((c: ProductDetailCategory) => c.type === "root"),
64
+ );
65
+ const mainCategory = computed(() =>
66
+ productCategories.value.find((c: ProductDetailCategory) => c.type === "main"),
67
+ );
68
+ const subCategory = computed(() =>
69
+ productCategories.value.find((c: ProductDetailCategory) => c.type === "subcategory"),
70
+ );
71
+
72
+ const breadcrumb = computed(() => [
73
+ { label: rootCategory.value?.name ?? t("product.detail.home"), to: localePath("/") },
74
+ ...(mainCategory.value?.name
75
+ ? [{ label: mainCategory.value.name, to: localePath(`/category/${categorySlug.value}`) }]
76
+ : []),
77
+ ...(subCategory.value?.name
78
+ ? [{ label: subCategory.value.name, to: localePath(`/category/${categorySlug.value}/${subcategorySlug.value}`) }]
79
+ : []),
80
+ { label: productInfo.value?.name ?? (status.value === "pending" ? "..." : t("product.detail.notFoundTitle")) },
81
+ ]);
82
+ </script>
83
+
84
+ <template>
85
+ <UContainer class="py-6">
86
+ <UBreadcrumb :items="breadcrumb" />
87
+
88
+ <CategorySkeletonCategoryDetailSkeleton v-if="status === 'pending'" />
89
+
90
+ <UiFeedbackErrorBoundary
91
+ v-else-if="notFound || !productInfo"
92
+ :show-retry="false"
93
+ :title="t('product.detail.notFoundTitle')"
94
+ :description="t('product.detail.notFoundDescription')"
95
+ />
96
+
97
+ <div
98
+ v-else
99
+ class="mt-8"
100
+ >
101
+ <div class="grid grid-cols-1 lg:grid-cols-2 gap-10 xl:gap-14 items-start">
102
+ <ProductDetailImageGallery
103
+ class="lg:sticky lg:top-(--ui-header-height)"
104
+ :images="mainImages"
105
+ :get-image-url="getDetailImageUrl"
106
+ />
107
+
108
+ <div class="flex flex-col gap-6">
109
+ <!-- Identity -->
110
+ <div>
111
+ <p class="text-xs font-semibold uppercase tracking-wide text-muted">
112
+ {{ productInfo.manufacturer }}
113
+ </p>
114
+ <h1 class="mt-1 text-3xl font-semibold tracking-tight text-highlighted">
115
+ {{ productInfo.name }}
116
+ </h1>
117
+ <button
118
+ type="button"
119
+ tabindex="0"
120
+ class="mt-2 inline-flex items-center gap-1.5 text-sm text-muted
121
+ hover:text-highlighted transition-colors cursor-pointer"
122
+ :title="t('product.detail.copySku')"
123
+ @click="copySku"
124
+ >
125
+ {{ t('product.detail.sku') }}: {{ productInfo.sku }}
126
+ <UIcon
127
+ :name="icon('copy')"
128
+ class="size-3.5"
129
+ />
130
+ </button>
131
+ </div>
132
+
133
+ <!-- Price (Offer domain — hydrates after first paint) -->
134
+ <USkeleton
135
+ v-if="offerPending"
136
+ class="h-9 w-44"
137
+ />
138
+ <div
139
+ v-else-if="hasPrice"
140
+ class="flex items-baseline gap-3"
141
+ >
142
+ <span class="text-3xl font-semibold text-highlighted tabular-nums">
143
+ {{ formatPrice(basePriceCents) }}
144
+ </span>
145
+ <span class="text-sm text-muted">
146
+ {{ t('product.detail.priceNote') }}
147
+ </span>
148
+ </div>
149
+ <div
150
+ v-else
151
+ class="text-2xl font-semibold text-muted"
152
+ >
153
+ {{ t('product.price.onRequest') }}
154
+ </div>
155
+
156
+ <ProductDetailStock
157
+ :stocks="stocks"
158
+ :available="productInfo.available"
159
+ />
160
+
161
+ <ProductDetailAddToCart
162
+ v-if="hasPrice"
163
+ :product="productInfo"
164
+ :max-quantity="stocks[0]?.maxOrderQuantity ?? 1"
165
+ :price="basePriceCents"
166
+ :tax-rate="taxRate"
167
+ :sku="productInfo.sku"
168
+ :image-url="getDetailImageUrl(mainImages[0]?.url ?? '')"
169
+ :prices="prices"
170
+ :category-slug="categorySlug"
171
+ :subcategory-slug="subcategorySlug"
172
+ >
173
+ <template #after-cta>
174
+ <ProductDetailSaveToList
175
+ compact
176
+ :product-id="productInfo.id"
177
+ :sku="productInfo.sku"
178
+ :name="productInfo.name"
179
+ :image="mainImages[0]?.url"
180
+ :price="basePriceCents / 100"
181
+ :tax-rate="taxRate"
182
+ :category-slug="categorySlug"
183
+ :subcategory-slug="subcategorySlug"
184
+ />
185
+ </template>
186
+ </ProductDetailAddToCart>
187
+
188
+ <ProductDetailPricing
189
+ :prices="prices"
190
+ :format-price="formatPrice"
191
+ :current-cart-quantity="currentCartQuantity"
192
+ />
193
+ </div>
194
+ </div>
195
+
196
+ <div
197
+ class="mt-14 pt-10 border-t border-(--ui-border)
198
+ grid grid-cols-1 lg:grid-cols-3 gap-10"
199
+ >
200
+ <ProductDetailDescription
201
+ v-if="longDescription"
202
+ class="lg:col-span-2"
203
+ :description="longDescription"
204
+ />
205
+ <ProductDetailSpecifications
206
+ v-if="attributes.length"
207
+ :attributes="attributes"
208
+ />
209
+ </div>
210
+ </div>
211
+ </UContainer>
212
+ </template>
@@ -0,0 +1,65 @@
1
+ import { parseProductIdFromSlug } from "./useProducts";
2
+
3
+ /**
4
+ * The single place a storefront learns what the URL is about. Pages and blocks never
5
+ * touch `useRoute()` themselves: they read the subject from here, so the same
6
+ * block renders the authored sample in the editor canvas (no route params) and
7
+ * the real subject on a template route page.
8
+ */
9
+
10
+ /** Normalise a route param, which is `string | string[] | undefined`. */
11
+ export function routeSegments(param: unknown): string[] {
12
+ if (Array.isArray(param)) {
13
+ return param.filter((s): s is string => typeof s === "string" && s.length > 0);
14
+ }
15
+ return typeof param === "string" && param ? [param] : [];
16
+ }
17
+
18
+ /**
19
+ * The product slug out of a `/category/<…any depth…>/product/<slug>` tail.
20
+ *
21
+ * Everything before the literal `product` marker is the display-only category
22
+ * path — one level, several levels or the `_` placeholder that
23
+ * `categoryProductPath()` emits for an uncategorised product. `lastIndexOf`
24
+ * (not `indexOf`) so a category literally named "product" can't shadow the
25
+ * marker. Returns "" when there is no marker, which the page turns into a 404.
26
+ */
27
+ export function productSlugFromSegments(segments: string[]): string {
28
+ const marker = segments.lastIndexOf("product");
29
+ return marker >= 0 ? (segments[marker + 1] ?? "") : "";
30
+ }
31
+
32
+ /** The product a `category/[category]/[...rest]` URL points at. */
33
+ export function useRouteProductSubject() {
34
+ const route = useRoute();
35
+
36
+ const slug = computed(() => productSlugFromSegments(routeSegments(route.params.rest)));
37
+ const id = computed(() => parseProductIdFromSlug(slug.value));
38
+
39
+ return { slug, id };
40
+ }
41
+
42
+ /** The category (and optional subcategory) a `category/[category]/[[subcategory]]` URL points at. */
43
+ export function useRouteCategorySubject() {
44
+ const route = useRoute();
45
+
46
+ const categorySlug = computed(() => routeSegments(route.params.category)[0] ?? "");
47
+ const subcategorySlug = computed(() => routeSegments(route.params.subcategory)[0]);
48
+
49
+ return { categorySlug, subcategorySlug };
50
+ }
51
+
52
+ /**
53
+ * The record an `/account/<domain>/[id]` URL points at.
54
+ *
55
+ * The five account detail blocks are authored ONCE with a sample record and
56
+ * then serve every record: on a live detail route the URL wins, and in the
57
+ * editor canvas (no `id` param) the authored id keeps the preview reviewable.
58
+ */
59
+ export function useRouteRecordSubject() {
60
+ const route = useRoute();
61
+
62
+ const id = computed(() => routeSegments(route.params.id)[0] ?? "");
63
+
64
+ return { id };
65
+ }
@@ -47,11 +47,27 @@ export const legalLinks = [
47
47
  { label: "Cookie Policy", to: "/legal/cookies" },
48
48
  ];
49
49
 
50
- export const shopContact = {
51
- address: "200 Market Street, Suite 800, San Francisco, CA 94105",
52
- phone: "+1 (800) 555-0100",
53
- email: "support@covercorp.com",
54
- };
50
+ /**
51
+ * A storefront's own contact details, as the footer and the focus layout print
52
+ * them. Every field is optional and the design system supplies NONE of them:
53
+ * this is a fact about the shop, not about the design system, and a default
54
+ * here is printed by every storefront that never overrode it (RX-789 — the
55
+ * default used to be an invented San Francisco address, and it stood under a
56
+ * German shop for months).
57
+ *
58
+ * A storefront states what it has, in `app.config.ts`:
59
+ *
60
+ * shopContact: { address: "…", phone: "…", email: "…" }
61
+ *
62
+ * What it does not state is not printed.
63
+ */
64
+ export interface ShopContact {
65
+ address?: string;
66
+ phone?: string;
67
+ email?: string;
68
+ }
69
+
70
+ export const shopContact: ShopContact = {};
55
71
 
56
72
  /* ------------------------------------------------------------------ */
57
73
  /* Storefront chrome — structure adopted from the relation prototype */
@@ -1,11 +1,14 @@
1
1
  <script setup lang="ts">
2
- import { legalLinks as defaultLegalLinks, shopContact } from "../config/navigation";
2
+ import type { ShopContact } from "../config/navigation";
3
+ import { legalLinks as defaultLegalLinks, shopContact as noContact } from "../config/navigation";
3
4
 
4
5
  // Distraction-free layout for conversion-critical pages — authentication
5
6
  // (login, register, recovery) and the checkout funnel. No shop chrome:
6
7
  // logo + back link on top, the page content, and a slim footer with the
7
8
  // essential links (contact + legal).
8
9
  const appConfig = useAppConfig();
10
+ // The shop's own support address, stated by the storefront or not at all.
11
+ const shopContact = computed<ShopContact>(() => (appConfig.shopContact as ShopContact | undefined) ?? noContact);
9
12
  const legalLinks = computed(() => (appConfig.legalLinks as typeof defaultLegalLinks | undefined) ?? defaultLegalLinks);
10
13
  const { t } = useI18n();
11
14
  const localePath = useLocalePath();
@@ -59,6 +62,7 @@ const tinted = computed(() => /\/checkout(\/|$)/.test(route.path));
59
62
  aria-label="Legal"
60
63
  >
61
64
  <a
65
+ v-if="shopContact.email"
62
66
  :href="`mailto:${shopContact.email}`"
63
67
  class="text-xs text-dimmed hover:text-default transition-colors"
64
68
  >
@@ -64,7 +64,10 @@
64
64
  "sku": "Artikel-Nr.",
65
65
  "copySku": "Artikelnummer kopieren",
66
66
  "skuCopied": "Artikelnummer kopiert",
67
- "priceNote": "pro Stück · zzgl. MwSt."
67
+ "priceNote": "pro Stück · zzgl. MwSt.",
68
+ "notFoundTitle": "Artikel nicht gefunden",
69
+ "notFoundDescription": "Diesen Artikel gibt es nicht — prüfen Sie die Artikelnummer oder suchen Sie im Katalog.",
70
+ "home": "Startseite"
68
71
  },
69
72
  "list": {
70
73
  "view": {
@@ -64,7 +64,10 @@
64
64
  "sku": "Article no.",
65
65
  "copySku": "Copy article number",
66
66
  "skuCopied": "Article number copied",
67
- "priceNote": "per unit · excl. VAT"
67
+ "priceNote": "per unit · excl. VAT",
68
+ "notFoundTitle": "Article not found",
69
+ "notFoundDescription": "This article does not exist — check the article number, or search the catalogue.",
70
+ "home": "Home"
68
71
  },
69
72
  "list": {
70
73
  "view": {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@revenexx/cover",
3
- "version": "0.3.0",
3
+ "version": "0.3.2",
4
4
  "description": "Cover \u2014 revenexx design system for Nuxt. Distributed as a Nuxt layer: generic UI components, theming tokens and stores shared by the demo shop, custom storefronts and the Blokkli theme.",
5
5
  "type": "module",
6
6
  "main": "./nuxt.config.ts",