@nuvler/cli 0.4.1 → 0.4.3
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 +25 -2
- package/dist/commands/theme/create.js +2 -2
- package/dist/commands/theme/validate.js +21 -0
- package/dist/commands/theme/validate.js.map +1 -1
- package/dist/index.js +1 -1
- package/dist/migrate/generator.js +6 -5
- package/dist/migrate/generator.js.map +1 -1
- package/dist/nuvler.js +163 -10
- package/dist/nuvler.js.map +1 -1
- package/dist/templates/nuvler-atelier/nuvler.theme.json +1 -1
- package/dist/templates/nuvler-atelier/package.json +2 -2
- package/dist/templates/nuvler-atelier/src/definition.tsx +10 -9
- package/dist/templates/nuvler-atelier/src/theme.tsx +2 -2
- package/dist/templates/nuvler-default/README.md +50 -4
- package/dist/templates/nuvler-default/nuvler.theme.json +2 -2
- package/dist/templates/nuvler-default/package.json +37 -5
- package/dist/templates/nuvler-default/src/banner-carousel.tsx +42 -12
- package/dist/templates/nuvler-default/src/carousel-frame.tsx +58 -0
- package/dist/templates/nuvler-default/src/definition.ts +9 -59
- package/dist/templates/nuvler-default/src/footer.tsx +7 -2
- package/dist/templates/nuvler-default/src/header-interactions.tsx +114 -12
- package/dist/templates/nuvler-default/src/header.tsx +7 -5
- package/dist/templates/nuvler-default/src/home.tsx +61 -20
- package/dist/templates/nuvler-default/src/index.ts +1 -0
- package/dist/templates/nuvler-default/src/product-carousel.tsx +13 -7
- package/dist/templates/nuvler-default/src/product-detail-interactive.tsx +261 -0
- package/dist/templates/nuvler-default/src/product-detail.tsx +80 -55
- package/dist/templates/nuvler-default/src/products.tsx +9 -6
- package/dist/templates/nuvler-default/src/server-shell.tsx +91 -0
- package/dist/templates/nuvler-default/src/shared.tsx +28 -16
- package/dist/templates/nuvler-default/src/theme-component.tsx +6 -5
- package/dist/templates/nuvler-default/src/theme-config.ts +63 -0
- package/dist/templates/nuvler-default/src/theme.css +159 -3
- package/dist/templates/starter/nuvler.theme.json +1 -1
- package/dist/templates/starter/package.json +2 -2
- package/dist/templates/starter/src/definition.tsx +3 -2
- package/dist/theme/performance.js +126 -0
- package/dist/theme/performance.js.map +1 -0
- package/package.json +2 -2
- package/preview-host/package.json +1 -1
- package/preview-host/vendor/theme-runtime/default-theme.tsx +13 -12
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
createContext,
|
|
5
|
+
useEffect,
|
|
6
|
+
useContext,
|
|
7
|
+
useMemo,
|
|
8
|
+
useRef,
|
|
9
|
+
useState,
|
|
10
|
+
type PointerEvent,
|
|
11
|
+
type ReactNode,
|
|
12
|
+
} from "react";
|
|
13
|
+
import { productUrl as relativeProductUrl, type ProductDetailProps, type ThemeCartItem, type ThemeImage } from "@nuvler/theme-sdk";
|
|
14
|
+
|
|
15
|
+
type AddToCart = NonNullable<ProductDetailProps["onAddToCart"]>;
|
|
16
|
+
|
|
17
|
+
const ThemeInteractionContext = createContext<{ onAddToCart?: AddToCart }>({});
|
|
18
|
+
|
|
19
|
+
export function ThemeInteractionProvider({
|
|
20
|
+
children,
|
|
21
|
+
onAddToCart,
|
|
22
|
+
}: {
|
|
23
|
+
children: ReactNode;
|
|
24
|
+
onAddToCart?: AddToCart;
|
|
25
|
+
}) {
|
|
26
|
+
const value = useMemo(() => ({ onAddToCart }), [onAddToCart]);
|
|
27
|
+
return <ThemeInteractionContext.Provider value={value}>{children}</ThemeInteractionContext.Provider>;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function ProductCardAction({
|
|
31
|
+
href,
|
|
32
|
+
item,
|
|
33
|
+
hasVariants,
|
|
34
|
+
}: {
|
|
35
|
+
href: string;
|
|
36
|
+
item: ThemeCartItem;
|
|
37
|
+
hasVariants: boolean;
|
|
38
|
+
}) {
|
|
39
|
+
const { onAddToCart } = useContext(ThemeInteractionContext);
|
|
40
|
+
|
|
41
|
+
if (hasVariants) {
|
|
42
|
+
return <a className="button button-secondary button-block product-card-action" href={href}>Escolher opções</a>;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
if (!onAddToCart) {
|
|
46
|
+
return <a className="button button-secondary button-block product-card-action" href={href}>Ver detalhes</a>;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return (
|
|
50
|
+
<button
|
|
51
|
+
type="button"
|
|
52
|
+
className="button button-primary button-block product-card-action"
|
|
53
|
+
onClick={() => onAddToCart(item)}
|
|
54
|
+
>
|
|
55
|
+
Adicionar ao carrinho
|
|
56
|
+
</button>
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
interface ProductDetailInteractiveProps extends Omit<ProductDetailProps, "descriptionContent"> {
|
|
61
|
+
information: ReactNode;
|
|
62
|
+
benefits: ReactNode;
|
|
63
|
+
galleryImages: ReactNode;
|
|
64
|
+
galleryThumbnails: ReactNode;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export function ProductDetailInteractive({
|
|
68
|
+
product,
|
|
69
|
+
contact,
|
|
70
|
+
productUrl,
|
|
71
|
+
onAddToCart,
|
|
72
|
+
information,
|
|
73
|
+
benefits,
|
|
74
|
+
galleryImages,
|
|
75
|
+
galleryThumbnails,
|
|
76
|
+
}: ProductDetailInteractiveProps) {
|
|
77
|
+
const context = useContext(ThemeInteractionContext);
|
|
78
|
+
const addToCart = onAddToCart ?? context.onAddToCart;
|
|
79
|
+
const initialVariant = product.variants.find((item) => item.active);
|
|
80
|
+
const [selected, setSelected] = useState<Record<string, string>>(() => Object.fromEntries(
|
|
81
|
+
product.variantOptions.map((option) => [
|
|
82
|
+
option.name,
|
|
83
|
+
initialVariant?.values.find(({ name }) => name === option.name)?.value ?? option.values[0] ?? "",
|
|
84
|
+
]),
|
|
85
|
+
));
|
|
86
|
+
const [imageUrl, setImageUrl] = useState<string>();
|
|
87
|
+
const galleryRef = useRef<HTMLDivElement>(null);
|
|
88
|
+
const [zoomEnabled, setZoomEnabled] = useState(true);
|
|
89
|
+
const [zoom, setZoom] = useState({
|
|
90
|
+
visible: false,
|
|
91
|
+
x: 50,
|
|
92
|
+
y: 50,
|
|
93
|
+
size: 220,
|
|
94
|
+
backgroundX: 0,
|
|
95
|
+
backgroundY: 0,
|
|
96
|
+
backgroundWidth: 0,
|
|
97
|
+
backgroundHeight: 0,
|
|
98
|
+
});
|
|
99
|
+
const variant = useMemo(() => product.variants.find((item) => (
|
|
100
|
+
item.active && item.values.every(({ name, value }) => selected[name] === value)
|
|
101
|
+
)), [product.variants, selected]);
|
|
102
|
+
const images = useMemo(() => {
|
|
103
|
+
if (variant?.image?.url) return [variant.image];
|
|
104
|
+
const unique = new Map<string, ThemeImage>();
|
|
105
|
+
[product.image, ...(product.images || [])].forEach((image) => {
|
|
106
|
+
if (image?.url) unique.set(image.url, image);
|
|
107
|
+
});
|
|
108
|
+
return [...unique.values()];
|
|
109
|
+
}, [product.image, product.images, variant]);
|
|
110
|
+
const selectedImage = images.find((image) => image.url === imageUrl) || images[0] || product.image;
|
|
111
|
+
const phone = contact?.whatsapp?.replace(/\D/g, "");
|
|
112
|
+
const variantDescription = variant?.values.map(({ name, value }) => `${name}: ${value}`).join(", ") || "";
|
|
113
|
+
const message = `Olá! Gostaria de solicitar um orçamento para ${product.title}${variantDescription ? ` (${variantDescription})` : ""}${variant?.sku ? ` — ref. ${variant.sku}` : ""}.${productUrl ? ` ${productUrl}` : ""}`;
|
|
114
|
+
const whatsapp = phone ? `https://wa.me/${phone}?text=${encodeURIComponent(message)}` : null;
|
|
115
|
+
const hasVariants = product.variantOptions.length > 0;
|
|
116
|
+
const canPurchase = !hasVariants || Boolean(variant);
|
|
117
|
+
|
|
118
|
+
useEffect(() => {
|
|
119
|
+
const gallery = galleryRef.current;
|
|
120
|
+
if (!gallery) return;
|
|
121
|
+
const selectedUrl = selectedImage?.url ?? "";
|
|
122
|
+
const allowedUrls = new Set(images.flatMap((image) => image.url ? [image.url] : []));
|
|
123
|
+
|
|
124
|
+
gallery.querySelectorAll<HTMLElement>("[data-product-main-image]").forEach((node) => {
|
|
125
|
+
node.hidden = node.dataset.productMainImage !== selectedUrl;
|
|
126
|
+
});
|
|
127
|
+
gallery.querySelectorAll<HTMLButtonElement>("[data-product-thumbnail]").forEach((button) => {
|
|
128
|
+
const url = button.dataset.productThumbnail ?? "";
|
|
129
|
+
button.hidden = !allowedUrls.has(url);
|
|
130
|
+
button.classList.toggle("active", url === selectedUrl);
|
|
131
|
+
button.setAttribute("aria-pressed", String(url === selectedUrl));
|
|
132
|
+
});
|
|
133
|
+
}, [images, selectedImage?.url]);
|
|
134
|
+
|
|
135
|
+
function moveZoom(event: PointerEvent<HTMLDivElement>) {
|
|
136
|
+
if (event.pointerType !== "mouse" || !selectedImage?.url || !zoomEnabled || (event.target as Element).closest(".product-zoom-toggle")) {
|
|
137
|
+
setZoom((current) => ({ ...current, visible: false }));
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
const bounds = event.currentTarget.getBoundingClientRect();
|
|
141
|
+
const image = event.currentTarget.querySelector<HTMLImageElement>("[data-product-main-image]:not([hidden]) img");
|
|
142
|
+
const naturalWidth = image?.naturalWidth || selectedImage.width || bounds.width;
|
|
143
|
+
const naturalHeight = image?.naturalHeight || selectedImage.height || bounds.height;
|
|
144
|
+
const imageAspect = naturalWidth / naturalHeight;
|
|
145
|
+
const containerAspect = bounds.width / bounds.height;
|
|
146
|
+
const renderedWidth = imageAspect > containerAspect ? bounds.width : bounds.height * imageAspect;
|
|
147
|
+
const renderedHeight = imageAspect > containerAspect ? bounds.width / imageAspect : bounds.height;
|
|
148
|
+
const left = (bounds.width - renderedWidth) / 2;
|
|
149
|
+
const top = (bounds.height - renderedHeight) / 2;
|
|
150
|
+
const pointerX = Math.max(left, Math.min(left + renderedWidth, event.clientX - bounds.left));
|
|
151
|
+
const pointerY = Math.max(top, Math.min(top + renderedHeight, event.clientY - bounds.top));
|
|
152
|
+
const size = Math.min(280, Math.max(210, bounds.width * 0.42));
|
|
153
|
+
const scale = 2.5;
|
|
154
|
+
const backgroundWidth = renderedWidth * scale;
|
|
155
|
+
const backgroundHeight = renderedHeight * scale;
|
|
156
|
+
setZoom({
|
|
157
|
+
visible: true,
|
|
158
|
+
x: pointerX / bounds.width * 100,
|
|
159
|
+
y: pointerY / bounds.height * 100,
|
|
160
|
+
size,
|
|
161
|
+
backgroundX: size / 2 - (pointerX - left) / renderedWidth * backgroundWidth,
|
|
162
|
+
backgroundY: size / 2 - (pointerY - top) / renderedHeight * backgroundHeight,
|
|
163
|
+
backgroundWidth,
|
|
164
|
+
backgroundHeight,
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
return (
|
|
169
|
+
<div className="product-detail">
|
|
170
|
+
<div className="product-gallery" ref={galleryRef}>
|
|
171
|
+
<div
|
|
172
|
+
className="product-main-image product-image-magnifier"
|
|
173
|
+
data-zoom-enabled={zoomEnabled}
|
|
174
|
+
onPointerEnter={moveZoom}
|
|
175
|
+
onPointerMove={moveZoom}
|
|
176
|
+
onPointerLeave={() => setZoom((current) => ({ ...current, visible: false }))}
|
|
177
|
+
>
|
|
178
|
+
{galleryImages}
|
|
179
|
+
{selectedImage?.url && <button
|
|
180
|
+
className={`product-zoom-toggle${zoomEnabled ? " active" : ""}`}
|
|
181
|
+
type="button"
|
|
182
|
+
aria-pressed={zoomEnabled}
|
|
183
|
+
aria-label={zoomEnabled ? "Desativar lupa" : "Ativar lupa"}
|
|
184
|
+
onClick={() => {
|
|
185
|
+
setZoomEnabled((enabled) => !enabled);
|
|
186
|
+
setZoom((current) => ({ ...current, visible: false }));
|
|
187
|
+
}}
|
|
188
|
+
>
|
|
189
|
+
<svg viewBox="0 0 24 24" aria-hidden="true"><circle cx="10.5" cy="10.5" r="6.5" /><path d="m15.5 15.5 5 5M10.5 7.5v6M7.5 10.5h6" />{!zoomEnabled && <path className="zoom-off-line" d="M3 3l18 18" />}</svg>
|
|
190
|
+
<span>Lupa</span>
|
|
191
|
+
</button>}
|
|
192
|
+
{selectedImage?.url && <span
|
|
193
|
+
className={`product-zoom-lens${zoom.visible ? " visible" : ""}`}
|
|
194
|
+
aria-hidden="true"
|
|
195
|
+
style={{
|
|
196
|
+
left: `${zoom.x}%`,
|
|
197
|
+
top: `${zoom.y}%`,
|
|
198
|
+
width: zoom.size,
|
|
199
|
+
height: zoom.size,
|
|
200
|
+
backgroundImage: `url(${JSON.stringify(selectedImage.url)})`,
|
|
201
|
+
backgroundPosition: `${zoom.backgroundX}px ${zoom.backgroundY}px`,
|
|
202
|
+
backgroundSize: `${zoom.backgroundWidth}px ${zoom.backgroundHeight}px`,
|
|
203
|
+
}}
|
|
204
|
+
/>}
|
|
205
|
+
</div>
|
|
206
|
+
<div
|
|
207
|
+
className="product-thumbnails"
|
|
208
|
+
onClick={(event) => {
|
|
209
|
+
const button = (event.target as Element).closest<HTMLButtonElement>("[data-product-thumbnail]");
|
|
210
|
+
if (button?.dataset.productThumbnail) setImageUrl(button.dataset.productThumbnail);
|
|
211
|
+
}}
|
|
212
|
+
>
|
|
213
|
+
{galleryThumbnails}
|
|
214
|
+
</div>
|
|
215
|
+
</div>
|
|
216
|
+
<div className="product-info">
|
|
217
|
+
{information}
|
|
218
|
+
<div className="product-purchase">
|
|
219
|
+
{hasVariants && <div className="variant-selector">
|
|
220
|
+
{product.variantOptions.map((option) => <fieldset key={option.name}>
|
|
221
|
+
<legend>{option.name}: <strong>{selected[option.name]}</strong></legend>
|
|
222
|
+
<div className="variant-values">
|
|
223
|
+
{option.values.map((value) => <button
|
|
224
|
+
key={value}
|
|
225
|
+
type="button"
|
|
226
|
+
className={selected[option.name] === value ? "active" : ""}
|
|
227
|
+
aria-pressed={selected[option.name] === value}
|
|
228
|
+
onClick={() => {
|
|
229
|
+
setSelected((current) => ({ ...current, [option.name]: value }));
|
|
230
|
+
setImageUrl(undefined);
|
|
231
|
+
}}
|
|
232
|
+
>{value}</button>)}
|
|
233
|
+
</div>
|
|
234
|
+
</fieldset>)}
|
|
235
|
+
{variant
|
|
236
|
+
? <p className="selected-variant"><strong>{variant.name || variantDescription}</strong>{variant.sku && <span>Referência: {variant.sku}</span>}</p>
|
|
237
|
+
: <p className="variant-unavailable">Esta combinação não está disponível.</p>}
|
|
238
|
+
</div>}
|
|
239
|
+
{canPurchase && addToCart && <button
|
|
240
|
+
type="button"
|
|
241
|
+
className="button button-primary button-block"
|
|
242
|
+
onClick={() => addToCart({
|
|
243
|
+
productSlug: product.slug,
|
|
244
|
+
productUrl: relativeProductUrl(product),
|
|
245
|
+
title: product.title,
|
|
246
|
+
sku: variant?.sku || product.sku,
|
|
247
|
+
variantId: variant?.id,
|
|
248
|
+
variantName: variantDescription,
|
|
249
|
+
image: variant?.image || product.image,
|
|
250
|
+
unitPrice: variant ? null : product.promotionalPrice ?? product.price,
|
|
251
|
+
})}
|
|
252
|
+
>Adicionar ao orçamento</button>}
|
|
253
|
+
{canPurchase && whatsapp && <a className={`button ${addToCart ? "button-secondary" : "button-primary"} button-block`} href={whatsapp} target="_blank" rel="noreferrer">Orçar somente este item</a>}
|
|
254
|
+
{canPurchase && !whatsapp && contact?.email && <a className="button button-primary button-block" href={`mailto:${contact.email}?subject=${encodeURIComponent(`Orçamento: ${product.title}`)}&body=${encodeURIComponent(message)}`}>Solicitar orçamento por e-mail</a>}
|
|
255
|
+
{canPurchase && !whatsapp && !contact?.email && contact?.phone && <a className="button button-primary button-block" href={`tel:${contact.phone}`}>Ligar e solicitar orçamento</a>}
|
|
256
|
+
</div>
|
|
257
|
+
{benefits}
|
|
258
|
+
</div>
|
|
259
|
+
</div>
|
|
260
|
+
);
|
|
261
|
+
}
|
|
@@ -1,60 +1,85 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
|
|
3
|
-
import { useMemo, useState, type PointerEvent } from "react";
|
|
4
1
|
import type { ProductDetailProps, ThemeImage } from "@nuvler/theme-sdk";
|
|
5
|
-
import { ThemeImageView } from "./shared.js";
|
|
6
2
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
const [selected, setSelected] = useState<Record<string, string>>(() => Object.fromEntries(
|
|
10
|
-
product.variantOptions.map((option) => [
|
|
11
|
-
option.name,
|
|
12
|
-
initialVariant?.values.find(({ name }) => name === option.name)?.value ?? option.values[0] ?? "",
|
|
13
|
-
]),
|
|
14
|
-
));
|
|
15
|
-
const [imageUrl, setImageUrl] = useState<string>();
|
|
16
|
-
const [zoomEnabled, setZoomEnabled] = useState(true);
|
|
17
|
-
const [zoom, setZoom] = useState({ visible: false, x: 50, y: 50, size: 220, backgroundX: 0, backgroundY: 0, backgroundWidth: 0, backgroundHeight: 0 });
|
|
18
|
-
const variant = useMemo(() => product.variants.find((item) => (
|
|
19
|
-
item.active && item.values.every(({ name, value }) => selected[name] === value)
|
|
20
|
-
)), [product.variants, selected]);
|
|
21
|
-
const images = useMemo(() => {
|
|
22
|
-
if (variant?.image?.url) return [variant.image];
|
|
23
|
-
const unique = new Map<string, ThemeImage>();
|
|
24
|
-
[product.image, ...(product.images || [])].forEach((image) => { if (image?.url) unique.set(image.url, image); });
|
|
25
|
-
return [...unique.values()];
|
|
26
|
-
}, [product.image, product.images, variant]);
|
|
27
|
-
const selectedImage = images.find((image) => image.url === imageUrl) || images[0] || product.image;
|
|
28
|
-
const phone = contact?.whatsapp?.replace(/\D/g, "");
|
|
29
|
-
const variantDescription = variant?.values.map(({ name, value }) => `${name}: ${value}`).join(", ") || "";
|
|
30
|
-
const message = `Olá! Gostaria de solicitar um orçamento para ${product.title}${variantDescription ? ` (${variantDescription})` : ""}${variant?.sku ? ` — ref. ${variant.sku}` : ""}.${productUrl ? ` ${productUrl}` : ""}`;
|
|
31
|
-
const whatsapp = phone ? `https://wa.me/${phone}?text=${encodeURIComponent(message)}` : null;
|
|
32
|
-
const hasVariants = product.variantOptions.length > 0;
|
|
33
|
-
const canPurchase = !hasVariants || Boolean(variant);
|
|
3
|
+
import { ProductDetailInteractive } from "./product-detail-interactive.js";
|
|
4
|
+
import { ThemeImageView, type ThemeImageComponent } from "./shared.js";
|
|
34
5
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
6
|
+
export function ProductDetail({
|
|
7
|
+
product,
|
|
8
|
+
contact,
|
|
9
|
+
productUrl,
|
|
10
|
+
descriptionContent,
|
|
11
|
+
onAddToCart,
|
|
12
|
+
ImageComponent = ThemeImageView,
|
|
13
|
+
}: ProductDetailProps & { ImageComponent?: ThemeImageComponent }) {
|
|
14
|
+
const initialVariant = product.variants.find((variant) => variant.active);
|
|
15
|
+
const uniqueImages = new Map<string, ThemeImage>();
|
|
16
|
+
[
|
|
17
|
+
initialVariant?.image,
|
|
18
|
+
product.image,
|
|
19
|
+
...(product.images ?? []),
|
|
20
|
+
...product.variants.map((variant) => variant.image),
|
|
21
|
+
].forEach((image) => {
|
|
22
|
+
if (image?.url) uniqueImages.set(image.url, image);
|
|
23
|
+
});
|
|
24
|
+
const images = [...uniqueImages.values()];
|
|
25
|
+
const galleryImages = images.length > 0
|
|
26
|
+
? images.map((image, index) => (
|
|
27
|
+
<span
|
|
28
|
+
data-product-main-image={image.url}
|
|
29
|
+
hidden={index !== 0}
|
|
30
|
+
key={image.url}
|
|
31
|
+
>
|
|
32
|
+
<ImageComponent
|
|
33
|
+
image={image}
|
|
34
|
+
fallbackAlt={initialVariant?.name || product.title}
|
|
35
|
+
priority={index === 0}
|
|
36
|
+
sizes="(max-width: 900px) 100vw, 50vw"
|
|
37
|
+
fallbackWidth={1000}
|
|
38
|
+
fallbackHeight={1000}
|
|
39
|
+
/>
|
|
40
|
+
</span>
|
|
41
|
+
))
|
|
42
|
+
: <span data-product-main-image=""><ImageComponent image={null} fallbackAlt={product.title} /></span>;
|
|
43
|
+
const galleryThumbnails = images.length > 1
|
|
44
|
+
? images.map((image, index) => (
|
|
45
|
+
<button
|
|
46
|
+
className={index === 0 ? "active" : ""}
|
|
47
|
+
type="button"
|
|
48
|
+
aria-pressed={index === 0}
|
|
49
|
+
aria-label={`Exibir imagem ${index + 1} de ${product.title}`}
|
|
50
|
+
data-product-thumbnail={image.url}
|
|
51
|
+
key={`${image.url}-${index}`}
|
|
52
|
+
>
|
|
53
|
+
<ImageComponent
|
|
54
|
+
image={image}
|
|
55
|
+
fallbackAlt={`${product.title} ${index + 1}`}
|
|
56
|
+
sizes="96px"
|
|
57
|
+
fallbackWidth={192}
|
|
58
|
+
fallbackHeight={192}
|
|
59
|
+
/>
|
|
60
|
+
</button>
|
|
61
|
+
))
|
|
62
|
+
: null;
|
|
63
|
+
const information = <>
|
|
64
|
+
{product.categories[0] && <span className="product-category">{product.categories[0].name}</span>}
|
|
65
|
+
<h1>{product.title}</h1>
|
|
66
|
+
<div className="product-description">{descriptionContent}</div>
|
|
67
|
+
</>;
|
|
68
|
+
const benefits = <div className="purchase-benefits">
|
|
69
|
+
<span><strong>Atendimento direto</strong> Fale com quem entende do produto</span>
|
|
70
|
+
<span><strong>Orçamento personalizado</strong> Condições para a sua necessidade</span>
|
|
71
|
+
</div>;
|
|
58
72
|
|
|
59
|
-
return
|
|
73
|
+
return (
|
|
74
|
+
<ProductDetailInteractive
|
|
75
|
+
product={product}
|
|
76
|
+
contact={contact}
|
|
77
|
+
productUrl={productUrl}
|
|
78
|
+
onAddToCart={onAddToCart}
|
|
79
|
+
information={information}
|
|
80
|
+
benefits={benefits}
|
|
81
|
+
galleryImages={galleryImages}
|
|
82
|
+
galleryThumbnails={galleryThumbnails}
|
|
83
|
+
/>
|
|
84
|
+
);
|
|
60
85
|
}
|
|
@@ -1,15 +1,18 @@
|
|
|
1
|
-
import type
|
|
2
|
-
import {
|
|
1
|
+
import { productUrl, type ProductGridProps, type ThemeProduct } from "@nuvler/theme-sdk";
|
|
2
|
+
import { ProductCardAction } from "./product-detail-interactive.js";
|
|
3
|
+
import { plainText, ThemeImageView, type ThemeImageComponent } from "./shared.js";
|
|
3
4
|
|
|
4
|
-
export function ProductCard({ product, showCategory = true, showDescription = true }: {
|
|
5
|
+
export function ProductCard({ product, showCategory = true, showDescription = true, ImageComponent = ThemeImageView }: {
|
|
5
6
|
product: ThemeProduct;
|
|
6
7
|
showCategory?: boolean;
|
|
7
8
|
showDescription?: boolean;
|
|
9
|
+
ImageComponent?: ThemeImageComponent;
|
|
8
10
|
}) {
|
|
9
|
-
|
|
11
|
+
const href = productUrl(product);
|
|
12
|
+
return <article className="product-card"><a className="product-card-image" href={href} aria-label={`Ver ${product.title}`}><ImageComponent image={product.image} fallbackAlt={product.title} sizes="(max-width: 720px) 92vw, (max-width: 1100px) 45vw, 25vw" fallbackWidth={720} fallbackHeight={720} /></a><div className="product-card-content">{showCategory && <span className={`product-category${product.categories[0] ? "" : " product-category-empty"}`}>{product.categories[0]?.name || "Sem categoria"}</span>}<h3><a className="product-card-details-link" href={href}>{product.title}</a></h3>{showDescription && product.description && <p className="product-card-description">{plainText(product.description)}</p>}<ProductCardAction href={href} hasVariants={product.variantOptions.length > 0} item={{ productSlug: product.slug, productUrl: href, title: product.title, sku: product.sku, image: product.image, unitPrice: product.promotionalPrice ?? product.price }} /></div></article>;
|
|
10
13
|
}
|
|
11
14
|
|
|
12
|
-
export function ProductGrid({ products, columns = 4, showCategory = true, showDescription = true }: ProductGridProps) {
|
|
15
|
+
export function ProductGrid({ products, columns = 4, showCategory = true, showDescription = true, ImageComponent = ThemeImageView }: ProductGridProps & { ImageComponent?: ThemeImageComponent }) {
|
|
13
16
|
if (!products.length) return <div className="empty-state"><span>7</span><h2>Nenhum produto encontrado</h2><p>Novos itens aparecerão aqui assim que forem publicados.</p></div>;
|
|
14
|
-
return <div className="product-grid" data-columns={columns}>{products.map((product) => <ProductCard key={product.slug} product={product} showCategory={showCategory} showDescription={showDescription} />)}</div>;
|
|
17
|
+
return <div className="product-grid" data-columns={columns}>{products.map((product) => <ProductCard key={product.slug} product={product} showCategory={showCategory} showDescription={showDescription} ImageComponent={ImageComponent} />)}</div>;
|
|
15
18
|
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import type { CSSProperties, ReactNode } from "react";
|
|
2
|
+
import type { ThemeCategory, ThemeNavigationItem, ThemePageSummary, ThemeSite } from "@nuvler/theme-sdk";
|
|
3
|
+
|
|
4
|
+
import { Footer } from "./footer.js";
|
|
5
|
+
import { Header } from "./header.js";
|
|
6
|
+
import {
|
|
7
|
+
manifest,
|
|
8
|
+
nuvlerDefaultTemplate,
|
|
9
|
+
nuvlerDefaultTokens,
|
|
10
|
+
} from "./theme-config.js";
|
|
11
|
+
import type { ThemeImageComponent } from "./shared.js";
|
|
12
|
+
|
|
13
|
+
export interface NuvlerDefaultShellProps {
|
|
14
|
+
site: ThemeSite;
|
|
15
|
+
categories: ThemeCategory[];
|
|
16
|
+
pages: ThemePageSummary[];
|
|
17
|
+
menu?: ThemeNavigationItem[];
|
|
18
|
+
children: ReactNode;
|
|
19
|
+
cart?: ReactNode;
|
|
20
|
+
platformBrand?: ReactNode;
|
|
21
|
+
suggestionsEndpoint?: string;
|
|
22
|
+
suggestionsQueryParam?: string;
|
|
23
|
+
ImageComponent?: ThemeImageComponent;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function NuvlerDefaultShell({
|
|
27
|
+
site,
|
|
28
|
+
categories,
|
|
29
|
+
pages,
|
|
30
|
+
menu,
|
|
31
|
+
children,
|
|
32
|
+
cart,
|
|
33
|
+
platformBrand,
|
|
34
|
+
suggestionsEndpoint,
|
|
35
|
+
suggestionsQueryParam,
|
|
36
|
+
ImageComponent,
|
|
37
|
+
}: NuvlerDefaultShellProps) {
|
|
38
|
+
const configured = site.settings?.theme;
|
|
39
|
+
const tokens = {
|
|
40
|
+
colors: { ...nuvlerDefaultTokens.colors, ...configured?.colors },
|
|
41
|
+
layout: { ...nuvlerDefaultTokens.layout, ...configured?.layout },
|
|
42
|
+
};
|
|
43
|
+
const style = {
|
|
44
|
+
"--color-primary": tokens.colors.primary,
|
|
45
|
+
"--color-primary-text": tokens.colors.primaryText,
|
|
46
|
+
"--color-secondary": tokens.colors.secondary,
|
|
47
|
+
"--color-secondary-text": tokens.colors.secondaryText,
|
|
48
|
+
"--color-accent": tokens.colors.accent,
|
|
49
|
+
"--store-background": tokens.colors.background,
|
|
50
|
+
"--store-surface": tokens.colors.surface,
|
|
51
|
+
"--store-surface-alt": tokens.colors.surfaceAlt,
|
|
52
|
+
"--store-text": tokens.colors.text,
|
|
53
|
+
"--store-muted": tokens.colors.textMuted,
|
|
54
|
+
"--store-line": tokens.colors.border,
|
|
55
|
+
"--store-header-background": tokens.colors.headerBackground,
|
|
56
|
+
"--store-header-text": tokens.colors.headerText,
|
|
57
|
+
"--store-footer-background": tokens.colors.footerBackground,
|
|
58
|
+
"--store-footer-text": tokens.colors.footerText,
|
|
59
|
+
"--container-width": `${tokens.layout.containerWidth}px`,
|
|
60
|
+
"--border-radius": `${tokens.layout.borderRadius}px`,
|
|
61
|
+
} as CSSProperties;
|
|
62
|
+
|
|
63
|
+
return (
|
|
64
|
+
<div
|
|
65
|
+
className="store-shell nuvler-default-theme"
|
|
66
|
+
data-theme-id={manifest.id}
|
|
67
|
+
data-theme-version={manifest.version}
|
|
68
|
+
data-nuvler-renderer="server"
|
|
69
|
+
style={style}
|
|
70
|
+
>
|
|
71
|
+
<Header
|
|
72
|
+
site={site}
|
|
73
|
+
categories={categories}
|
|
74
|
+
pages={pages}
|
|
75
|
+
menu={menu}
|
|
76
|
+
template={nuvlerDefaultTemplate}
|
|
77
|
+
cart={cart}
|
|
78
|
+
suggestionsEndpoint={suggestionsEndpoint}
|
|
79
|
+
suggestionsQueryParam={suggestionsQueryParam}
|
|
80
|
+
ImageComponent={ImageComponent}
|
|
81
|
+
/>
|
|
82
|
+
<div className="store-page">{children}</div>
|
|
83
|
+
<Footer
|
|
84
|
+
site={site}
|
|
85
|
+
pages={pages}
|
|
86
|
+
template={nuvlerDefaultTemplate}
|
|
87
|
+
platformBrand={platformBrand}
|
|
88
|
+
/>
|
|
89
|
+
</div>
|
|
90
|
+
);
|
|
91
|
+
}
|
|
@@ -1,35 +1,47 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { ComponentType } from "react";
|
|
2
|
+
import { htmlToPlainText, type ThemeImage, type ThemeProduct } from "@nuvler/theme-sdk";
|
|
3
|
+
|
|
4
|
+
export interface ThemeImageViewProps {
|
|
5
|
+
image: ThemeImage | null | undefined;
|
|
6
|
+
fallbackAlt: string;
|
|
7
|
+
className?: string;
|
|
8
|
+
priority?: boolean;
|
|
9
|
+
loading?: "eager" | "lazy";
|
|
10
|
+
sizes?: string;
|
|
11
|
+
fallbackWidth?: number;
|
|
12
|
+
fallbackHeight?: number;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export type ThemeImageComponent = ComponentType<ThemeImageViewProps>;
|
|
2
16
|
|
|
3
17
|
export function ThemeImageView({
|
|
4
18
|
image,
|
|
5
19
|
fallbackAlt,
|
|
6
20
|
className,
|
|
7
21
|
priority = false,
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
}) {
|
|
22
|
+
loading = "lazy",
|
|
23
|
+
sizes,
|
|
24
|
+
fallbackWidth = 900,
|
|
25
|
+
fallbackHeight = 900,
|
|
26
|
+
}: ThemeImageViewProps) {
|
|
14
27
|
if (!image?.url) {
|
|
15
28
|
return <span className={`store-image-placeholder ${className ?? ""}`} aria-hidden="true"><span>7</span></span>;
|
|
16
29
|
}
|
|
17
30
|
return <img
|
|
18
31
|
src={image.url}
|
|
19
32
|
alt={image.alt || fallbackAlt}
|
|
20
|
-
width={image.width ||
|
|
21
|
-
height={image.height ||
|
|
33
|
+
width={image.width || fallbackWidth}
|
|
34
|
+
height={image.height || fallbackHeight}
|
|
22
35
|
className={className}
|
|
23
|
-
loading={priority ? "eager" :
|
|
36
|
+
loading={priority ? "eager" : loading}
|
|
37
|
+
fetchPriority={priority ? "high" : "auto"}
|
|
38
|
+
decoding="async"
|
|
39
|
+
sizes={sizes}
|
|
24
40
|
/>;
|
|
25
41
|
}
|
|
26
42
|
|
|
27
43
|
export function plainText(value: string): string {
|
|
28
|
-
return value
|
|
29
|
-
.replace(/<(script|style)\b[^>]*>[\s\S]*?<\/\1>/gi, " ")
|
|
30
|
-
.replace(/<[^>]+>/g, " ")
|
|
31
|
-
.replace(/\s+/g, " ")
|
|
32
|
-
.trim();
|
|
44
|
+
return htmlToPlainText(value);
|
|
33
45
|
}
|
|
34
46
|
|
|
35
47
|
export function displayPrice(product: ThemeProduct): string | null {
|
|
@@ -40,5 +52,5 @@ export function displayPrice(product: ThemeProduct): string | null {
|
|
|
40
52
|
}
|
|
41
53
|
|
|
42
54
|
export function categoryUrl(path: string[]): string {
|
|
43
|
-
return
|
|
55
|
+
return `/${path.map(encodeURIComponent).join("/")}`;
|
|
44
56
|
}
|