@revenexx/cover 0.3.0 → 0.3.1
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.
|
@@ -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
|
+
}
|
|
@@ -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.
|
|
3
|
+
"version": "0.3.1",
|
|
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",
|