@nuvler/cli 0.1.0 → 0.2.0
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 +12 -1
- package/dist/commands/theme/create.js +103 -21
- package/dist/commands/theme/create.js.map +1 -1
- package/dist/index.js +21 -4
- package/dist/index.js.map +1 -1
- package/dist/nuvler.js +104 -18
- package/dist/nuvler.js.map +1 -1
- package/dist/templates/nuvler-atelier/README.md +30 -0
- package/dist/templates/nuvler-atelier/nuvler.theme.json +10 -0
- package/dist/templates/nuvler-atelier/package.json +29 -0
- package/dist/templates/nuvler-atelier/src/definition.tsx +201 -0
- package/dist/templates/nuvler-atelier/src/theme.css +278 -0
- package/dist/templates/nuvler-atelier/src/theme.tsx +105 -0
- package/dist/templates/nuvler-default/.env.example +3 -0
- package/dist/templates/nuvler-default/README.md +34 -0
- package/dist/templates/nuvler-default/gitignore.template +9 -0
- package/dist/templates/nuvler-default/nuvler.theme.json +10 -0
- package/dist/templates/nuvler-default/package.json +29 -0
- package/dist/templates/nuvler-default/scripts/clean-dist.mjs +6 -0
- package/dist/templates/nuvler-default/scripts/copy-assets.mjs +12 -0
- package/dist/templates/nuvler-default/src/banner-carousel.tsx +24 -0
- package/dist/templates/nuvler-default/src/definition.ts +59 -0
- package/dist/templates/nuvler-default/src/footer.tsx +7 -0
- package/dist/templates/nuvler-default/src/header-interactions.tsx +190 -0
- package/dist/templates/nuvler-default/src/header.tsx +14 -0
- package/dist/templates/nuvler-default/src/home.tsx +69 -0
- package/dist/templates/nuvler-default/src/index.ts +28 -0
- package/dist/templates/nuvler-default/src/product-carousel.tsx +12 -0
- package/dist/templates/nuvler-default/src/product-detail.tsx +60 -0
- package/dist/templates/nuvler-default/src/products.tsx +15 -0
- package/dist/templates/nuvler-default/src/shared.tsx +44 -0
- package/dist/templates/nuvler-default/src/styles.d.ts +1 -0
- package/dist/templates/nuvler-default/src/theme-component.tsx +97 -0
- package/dist/templates/nuvler-default/src/theme.css +2934 -0
- package/dist/templates/nuvler-default/src/theme.tsx +2 -0
- package/dist/templates/nuvler-default/tsconfig.json +10 -0
- package/dist/templates/starter/.env.example +3 -0
- package/dist/templates/starter/gitignore.template +9 -0
- package/{templates/starter-theme → dist/templates/starter}/package.json +1 -1
- package/dist/templates/starter/src/styles.d.ts +1 -0
- package/dist/templates/starter/tsconfig.json +17 -0
- package/package.json +1 -2
- /package/{templates/starter-theme → dist/templates/nuvler-atelier}/.env.example +0 -0
- /package/{templates/starter-theme → dist/templates/nuvler-atelier}/gitignore.template +0 -0
- /package/{templates/starter-theme → dist/templates/nuvler-atelier}/src/styles.d.ts +0 -0
- /package/{templates/starter-theme → dist/templates/nuvler-atelier}/tsconfig.json +0 -0
- /package/{templates/starter-theme → dist/templates/starter}/README.md +0 -0
- /package/{templates/starter-theme → dist/templates/starter}/nuvler.theme.json +0 -0
- /package/{templates/starter-theme → dist/templates/starter}/src/definition.tsx +0 -0
- /package/{templates/starter-theme → dist/templates/starter}/src/theme.css +0 -0
- /package/{templates/starter-theme → dist/templates/starter}/src/theme.tsx +0 -0
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export { nuvlerDefaultTheme, manifest } from "./definition.js";
|
|
2
|
+
export { Theme, createNuvlerDefaultRuntime } from "./theme-component.js";
|
|
3
|
+
export type { NuvlerDefaultThemeProps } from "./theme-component.js";
|
|
4
|
+
export { Header } from "./header.js";
|
|
5
|
+
export { Footer } from "./footer.js";
|
|
6
|
+
export { Home } from "./home.js";
|
|
7
|
+
export { ProductGrid, ProductCard } from "./products.js";
|
|
8
|
+
export { ProductDetail } from "./product-detail.js";
|
|
9
|
+
export type {
|
|
10
|
+
FooterProps,
|
|
11
|
+
HeaderProps,
|
|
12
|
+
HomeProps,
|
|
13
|
+
NuvlerStoreThemeDefinition,
|
|
14
|
+
ProductDetailProps,
|
|
15
|
+
ProductGridProps,
|
|
16
|
+
SiteTemplate,
|
|
17
|
+
ThemeCategory,
|
|
18
|
+
ThemeCartItem,
|
|
19
|
+
ThemeContact,
|
|
20
|
+
ThemeEditorialItem,
|
|
21
|
+
ThemeHomeSection,
|
|
22
|
+
ThemeImage,
|
|
23
|
+
ThemeManifest,
|
|
24
|
+
ThemePageSummary,
|
|
25
|
+
ThemeProduct,
|
|
26
|
+
ThemeSettings,
|
|
27
|
+
ThemeSite,
|
|
28
|
+
} from "@nuvler/theme-sdk";
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { useRef } from "react";
|
|
4
|
+
import type { ThemeProduct } from "@nuvler/theme-sdk";
|
|
5
|
+
import { ProductCard } from "./products.js";
|
|
6
|
+
|
|
7
|
+
export function ProductCarousel({ products, showCategory, showDescription }: { products: ThemeProduct[]; showCategory: boolean; showDescription: boolean }) {
|
|
8
|
+
const track = useRef<HTMLDivElement>(null);
|
|
9
|
+
if (!products.length) return <div className="empty-state"><span>7</span><h2>Nenhum produto encontrado</h2><p>Escolha outra categoria ou publique produtos para esta vitrine.</p></div>;
|
|
10
|
+
const move = (direction: -1 | 1) => track.current?.scrollBy({ left: direction * Math.min(track.current.clientWidth, 900), behavior: "smooth" });
|
|
11
|
+
return <div className="product-carousel"><div className="product-carousel-track" ref={track}>{products.map((product) => <div className="product-carousel-item" key={product.slug}><ProductCard product={product} showCategory={showCategory} showDescription={showDescription} /></div>)}</div><button type="button" className="carousel-arrow carousel-arrow-prev" onClick={() => move(-1)} aria-label="Produtos anteriores">‹</button><button type="button" className="carousel-arrow carousel-arrow-next" onClick={() => move(1)} aria-label="Próximos produtos">›</button></div>;
|
|
12
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { useMemo, useState, type PointerEvent } from "react";
|
|
4
|
+
import type { ProductDetailProps, ThemeImage } from "@nuvler/theme-sdk";
|
|
5
|
+
import { ThemeImageView } from "./shared.js";
|
|
6
|
+
|
|
7
|
+
export function ProductDetail({ product, contact, productUrl, descriptionContent, onAddToCart }: ProductDetailProps) {
|
|
8
|
+
const initialVariant = product.variants.find((item) => item.active);
|
|
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);
|
|
34
|
+
|
|
35
|
+
function moveZoom(event: PointerEvent<HTMLDivElement>) {
|
|
36
|
+
if (event.pointerType !== "mouse" || !selectedImage?.url || !zoomEnabled || (event.target as Element).closest(".product-zoom-toggle")) {
|
|
37
|
+
setZoom((current) => ({ ...current, visible: false }));
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
const bounds = event.currentTarget.getBoundingClientRect();
|
|
41
|
+
const image = event.currentTarget.querySelector("img");
|
|
42
|
+
const naturalWidth = image?.naturalWidth || selectedImage.width || bounds.width;
|
|
43
|
+
const naturalHeight = image?.naturalHeight || selectedImage.height || bounds.height;
|
|
44
|
+
const imageAspect = naturalWidth / naturalHeight;
|
|
45
|
+
const containerAspect = bounds.width / bounds.height;
|
|
46
|
+
const renderedWidth = imageAspect > containerAspect ? bounds.width : bounds.height * imageAspect;
|
|
47
|
+
const renderedHeight = imageAspect > containerAspect ? bounds.width / imageAspect : bounds.height;
|
|
48
|
+
const left = (bounds.width - renderedWidth) / 2;
|
|
49
|
+
const top = (bounds.height - renderedHeight) / 2;
|
|
50
|
+
const pointerX = Math.max(left, Math.min(left + renderedWidth, event.clientX - bounds.left));
|
|
51
|
+
const pointerY = Math.max(top, Math.min(top + renderedHeight, event.clientY - bounds.top));
|
|
52
|
+
const size = Math.min(280, Math.max(210, bounds.width * 0.42));
|
|
53
|
+
const scale = 2.5;
|
|
54
|
+
const backgroundWidth = renderedWidth * scale;
|
|
55
|
+
const backgroundHeight = renderedHeight * scale;
|
|
56
|
+
setZoom({ visible: true, x: pointerX / bounds.width * 100, y: pointerY / bounds.height * 100, size, backgroundX: size / 2 - (pointerX - left) / renderedWidth * backgroundWidth, backgroundY: size / 2 - (pointerY - top) / renderedHeight * backgroundHeight, backgroundWidth, backgroundHeight });
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return <div className="product-detail"><div className="product-gallery"><div className="product-main-image product-image-magnifier" data-zoom-enabled={zoomEnabled} onPointerEnter={moveZoom} onPointerMove={moveZoom} onPointerLeave={() => setZoom((current) => ({ ...current, visible: false }))}><ThemeImageView image={selectedImage} fallbackAlt={variant?.name || product.title} priority />{selectedImage?.url && <button className={`product-zoom-toggle${zoomEnabled ? " active" : ""}`} type="button" aria-pressed={zoomEnabled} aria-label={zoomEnabled ? "Desativar lupa" : "Ativar lupa"} onClick={() => { setZoomEnabled((enabled) => !enabled); setZoom((current) => ({ ...current, visible: false })); }}><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><span>Lupa</span></button>}{selectedImage?.url && <span className={`product-zoom-lens${zoom.visible ? " visible" : ""}`} aria-hidden="true" style={{ left: `${zoom.x}%`, top: `${zoom.y}%`, width: zoom.size, height: zoom.size, backgroundImage: `url(${JSON.stringify(selectedImage.url)})`, backgroundPosition: `${zoom.backgroundX}px ${zoom.backgroundY}px`, backgroundSize: `${zoom.backgroundWidth}px ${zoom.backgroundHeight}px` }} />}</div>{images.length > 1 && <div className="product-thumbnails">{images.map((image, index) => <button className={selectedImage?.url === image.url ? "active" : ""} type="button" aria-pressed={selectedImage?.url === image.url} aria-label={`Exibir imagem ${index + 1} de ${product.title}`} onClick={() => setImageUrl(image.url || undefined)} key={`${image.url}-${index}`}><ThemeImageView image={image} fallbackAlt={`${product.title} ${index + 1}`} /></button>)}</div>}</div><div className="product-info">{product.categories[0] && <span className="product-category">{product.categories[0].name}</span>}<h1>{product.title}</h1><div className="product-description">{descriptionContent}</div><div className="product-purchase">{hasVariants && <div className="variant-selector">{product.variantOptions.map((option) => <fieldset key={option.name}><legend>{option.name}: <strong>{selected[option.name]}</strong></legend><div className="variant-values">{option.values.map((value) => <button key={value} type="button" className={selected[option.name] === value ? "active" : ""} aria-pressed={selected[option.name] === value} onClick={() => { setSelected((current) => ({ ...current, [option.name]: value })); setImageUrl(undefined); }}>{value}</button>)}</div></fieldset>)}{variant ? <p className="selected-variant"><strong>{variant.name || variantDescription}</strong>{variant.sku && <span>Referência: {variant.sku}</span>}</p> : <p className="variant-unavailable">Esta combinação não está disponível.</p>}</div>}{canPurchase && onAddToCart && <button type="button" className="button button-primary button-block" onClick={() => onAddToCart({ productSlug: product.slug, title: product.title, sku: variant?.sku || product.sku, variantId: variant?.id, variantName: variantDescription, image: variant?.image || product.image, unitPrice: variant ? null : product.promotionalPrice ?? product.price })}>Adicionar ao orçamento</button>}{canPurchase && whatsapp && <a className={`button ${onAddToCart ? "button-secondary" : "button-primary"} button-block`} href={whatsapp} target="_blank" rel="noreferrer">Orçar somente este item</a>}{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>}{canPurchase && !whatsapp && !contact?.email && contact?.phone && <a className="button button-primary button-block" href={`tel:${contact.phone}`}>Ligar e solicitar orçamento</a>}</div><div className="purchase-benefits"><span><strong>Atendimento direto</strong> Fale com quem entende do produto</span><span><strong>Orçamento personalizado</strong> Condições para a sua necessidade</span></div></div></div>;
|
|
60
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { ProductGridProps, ThemeProduct } from "@nuvler/theme-sdk";
|
|
2
|
+
import { plainText, ThemeImageView } from "./shared.js";
|
|
3
|
+
|
|
4
|
+
export function ProductCard({ product, showCategory = true, showDescription = true }: {
|
|
5
|
+
product: ThemeProduct;
|
|
6
|
+
showCategory?: boolean;
|
|
7
|
+
showDescription?: boolean;
|
|
8
|
+
}) {
|
|
9
|
+
return <article className="product-card"><a className="product-card-image" href={`/produto/${product.slug}`}><ThemeImageView image={product.image} fallbackAlt={product.title} /></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 href={`/produto/${product.slug}`}>{product.title}</a></h3>{showDescription && product.description && <p className="product-card-description">{plainText(product.description)}</p>}<a className="button button-secondary button-block" href={`/produto/${product.slug}`}>Ver detalhes e orçar</a></div></article>;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function ProductGrid({ products, columns = 4, showCategory = true, showDescription = true }: ProductGridProps) {
|
|
13
|
+
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>;
|
|
15
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { ThemeImage, ThemeProduct } from "@nuvler/theme-sdk";
|
|
2
|
+
|
|
3
|
+
export function ThemeImageView({
|
|
4
|
+
image,
|
|
5
|
+
fallbackAlt,
|
|
6
|
+
className,
|
|
7
|
+
priority = false,
|
|
8
|
+
}: {
|
|
9
|
+
image: ThemeImage | null | undefined;
|
|
10
|
+
fallbackAlt: string;
|
|
11
|
+
className?: string;
|
|
12
|
+
priority?: boolean;
|
|
13
|
+
}) {
|
|
14
|
+
if (!image?.url) {
|
|
15
|
+
return <span className={`store-image-placeholder ${className ?? ""}`} aria-hidden="true"><span>7</span></span>;
|
|
16
|
+
}
|
|
17
|
+
return <img
|
|
18
|
+
src={image.url}
|
|
19
|
+
alt={image.alt || fallbackAlt}
|
|
20
|
+
width={image.width || 900}
|
|
21
|
+
height={image.height || 900}
|
|
22
|
+
className={className}
|
|
23
|
+
loading={priority ? "eager" : "lazy"}
|
|
24
|
+
/>;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
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();
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export function displayPrice(product: ThemeProduct): string | null {
|
|
36
|
+
const price = product.promotionalPrice ?? product.price;
|
|
37
|
+
return typeof price === "number"
|
|
38
|
+
? new Intl.NumberFormat("pt-BR", { style: "currency", currency: "BRL" }).format(price)
|
|
39
|
+
: null;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export function categoryUrl(path: string[]): string {
|
|
43
|
+
return `/categoria/${path.map(encodeURIComponent).join("/")}`;
|
|
44
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
declare module "*.css";
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { useMemo, useState, type CSSProperties } from "react";
|
|
4
|
+
import type { NuvlerStoreThemeDefinition, ThemeCartItem, ThemeCategory, ThemeEditorialItem, ThemeHomeSection, ThemePageSummary, ThemeProduct, ThemeRuntimeAdapters, ThemeSite } from "@nuvler/theme-sdk";
|
|
5
|
+
import { nuvlerDefaultTheme } from "./definition.js";
|
|
6
|
+
import { plainText, ThemeImageView } from "./shared.js";
|
|
7
|
+
|
|
8
|
+
interface PreviewContext {
|
|
9
|
+
store: { name: string; slug: string };
|
|
10
|
+
site: { modules: string[]; settings: ThemeSite["settings"] };
|
|
11
|
+
navigation: { pages: ThemePageSummary[]; categories: ThemeCategory[] };
|
|
12
|
+
home: { content: { sections: ThemeHomeSection[] } };
|
|
13
|
+
catalog: { products: ThemeProduct[] };
|
|
14
|
+
editorial: { posts: ThemeEditorialItem[]; services: ThemeEditorialItem[]; cases: ThemeEditorialItem[] };
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
type PreviewRoute =
|
|
18
|
+
| { type: "home" | "loading" | "not-found" | "page"; title?: string }
|
|
19
|
+
| { type: "catalog"; products: ThemeProduct[]; pagination: { page: number; total: number; totalPages: number; hasPreviousPage: boolean; hasNextPage: boolean }; search: string; categorySlug: string | null; categoryPath: string[]; variants: string[]; facets: Array<{ name: string; values: Array<{ value: string; count: number }> }> }
|
|
20
|
+
| { type: "product"; product: ThemeProduct }
|
|
21
|
+
| { type: "editorial-list"; title: string; basePath: string; items: ThemeEditorialItem[] }
|
|
22
|
+
| { type: "editorial-detail"; basePath: string; item: ThemeEditorialItem };
|
|
23
|
+
|
|
24
|
+
export interface NuvlerDefaultThemeProps {
|
|
25
|
+
context: PreviewContext;
|
|
26
|
+
route?: PreviewRoute;
|
|
27
|
+
adapters?: ThemeRuntimeAdapters;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
interface PreviewCartItem extends ThemeCartItem {
|
|
31
|
+
key: string;
|
|
32
|
+
quantity: number;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function catalogHref(route: Extract<PreviewRoute, { type: "catalog" }>, page: number): string {
|
|
36
|
+
const params = new URLSearchParams();
|
|
37
|
+
if (route.search) params.set("busca", route.search);
|
|
38
|
+
route.variants.forEach((variant) => params.append("variante", variant));
|
|
39
|
+
if (page > 1) params.set("pagina", String(page));
|
|
40
|
+
const pathname = route.categoryPath.length ? `/categoria/${route.categoryPath.map(encodeURIComponent).join("/")}` : "/produtos";
|
|
41
|
+
return params.size ? `${pathname}?${params}` : pathname;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function EditorialPreview({ items, basePath }: { items: ThemeEditorialItem[]; basePath: string }) {
|
|
45
|
+
return <div className="editorial-grid">{items.map((item) => <article className="editorial-card" key={item.slug}><div className="editorial-card-content"><h2><a href={`${basePath}/${item.slug}`}>{item.title}</a></h2><p>{item.description}</p><a className="text-link" href={`${basePath}/${item.slug}`}>Saiba mais <span>→</span></a></div></article>)}</div>;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export function createNuvlerDefaultRuntime(themeDefinition: NuvlerStoreThemeDefinition) {
|
|
49
|
+
function Theme({ context, route = { type: "home" }, adapters }: NuvlerDefaultThemeProps) {
|
|
50
|
+
const [cartItems, setCartItems] = useState<PreviewCartItem[]>([]);
|
|
51
|
+
const [cartOpen, setCartOpen] = useState(false);
|
|
52
|
+
const { Header, Footer, Home, ProductDetail, ProductGrid } = themeDefinition.components;
|
|
53
|
+
const site: ThemeSite = { tenant: context.store, modules: context.site.modules, settings: context.site.settings };
|
|
54
|
+
const configured = site.settings?.theme;
|
|
55
|
+
const tokens = {
|
|
56
|
+
colors: { ...themeDefinition.tokens.colors, ...configured?.colors },
|
|
57
|
+
layout: { ...themeDefinition.tokens.layout, ...configured?.layout },
|
|
58
|
+
};
|
|
59
|
+
const style = {
|
|
60
|
+
"--color-primary": tokens.colors.primary,
|
|
61
|
+
"--color-secondary": tokens.colors.secondary,
|
|
62
|
+
"--store-background": tokens.colors.background,
|
|
63
|
+
"--store-text": tokens.colors.text,
|
|
64
|
+
"--container-width": `${tokens.layout.containerWidth}px`,
|
|
65
|
+
"--border-radius": `${tokens.layout.borderRadius}px`,
|
|
66
|
+
} as CSSProperties;
|
|
67
|
+
const cartCount = cartItems.reduce((total, item) => total + item.quantity, 0);
|
|
68
|
+
const cartMessage = useMemo(() => `Olá! Gostaria de solicitar um orçamento para os itens abaixo:\n\n${cartItems.map((item, index) => `${index + 1}. ${item.quantity}x ${item.title}${item.variantName ? ` (${item.variantName})` : ""}${item.sku ? ` — ref. ${item.sku}` : ""}`).join("\n\n")}`, [cartItems]);
|
|
69
|
+
const whatsapp = site.settings?.contact.whatsapp?.replace(/\D/g, "");
|
|
70
|
+
const checkoutUrl = whatsapp && cartItems.length
|
|
71
|
+
? `https://wa.me/${whatsapp}?text=${encodeURIComponent(cartMessage)}`
|
|
72
|
+
: null;
|
|
73
|
+
const addToCart = (item: ThemeCartItem) => {
|
|
74
|
+
const key = `${item.productSlug}::${item.variantId || "parent"}`;
|
|
75
|
+
setCartItems((current) => {
|
|
76
|
+
const existing = current.find((candidate) => candidate.key === key);
|
|
77
|
+
if (existing) return current.map((candidate) => candidate.key === key ? { ...candidate, quantity: Math.min(99, candidate.quantity + 1) } : candidate);
|
|
78
|
+
return [...current, { ...item, key, quantity: 1 }];
|
|
79
|
+
});
|
|
80
|
+
setCartOpen(true);
|
|
81
|
+
};
|
|
82
|
+
const cartButton = <button type="button" className="cart-button" onClick={() => setCartOpen(true)} aria-label={`Abrir carrinho com ${cartCount} itens`}><svg viewBox="0 0 24 24" aria-hidden="true"><path d="M3 4h2l2 11h10l2-8H6M9 20h.01M17 20h.01" /></svg>{cartCount > 0 && <span>{Math.min(cartCount, 99)}</span>}</button>;
|
|
83
|
+
let content;
|
|
84
|
+
if (route.type === "home") content = <main><Home sections={context.home.content.sections} products={context.catalog.products} posts={context.editorial.posts} services={context.editorial.services} cases={context.editorial.cases} site={site} template={themeDefinition.template} /></main>;
|
|
85
|
+
else if (route.type === "product") content = <main className="product-page"><div className="store-container"><nav className="breadcrumbs" aria-label="Navegação estrutural"><a href="/">Início</a><span>/</span><a href="/produtos">Produtos</a><span>/</span><strong>{route.product.title}</strong></nav><ProductDetail product={route.product} contact={site.settings?.contact} productUrl={window.location.href} descriptionContent={<p>{plainText(route.product.description)}</p>} onAddToCart={addToCart} /></div></main>;
|
|
86
|
+
else if (route.type === "catalog") content = <main className="catalog-page"><section className="catalog-hero"><div className="store-container"><span>Nosso catálogo</span><h1>{route.search ? `Busca por “${route.search}”` : "Todos os produtos"}</h1><p>{route.pagination.total} produto(s)</p></div></section><div className="store-container catalog-layout"><aside className="category-filter catalog-filters"><form action={route.categoryPath.length ? `/categoria/${route.categoryPath.join("/")}` : "/produtos"} className="catalog-filter-form"><label htmlFor="preview-catalog-search">Buscar no catálogo</label><div className="catalog-filter-search"><input id="preview-catalog-search" name="busca" type="search" defaultValue={route.search} placeholder="Nome do produto" /><button type="submit" aria-label="Pesquisar">⌕</button></div></form>{route.facets.length > 0 && <form className="catalog-variant-filters">{route.search && <input type="hidden" name="busca" value={route.search} />}{route.facets.map((facet) => <fieldset className="catalog-filter-section" key={facet.name}><legend>{facet.name}</legend>{facet.values.map(({ value, count }) => { const token = `${facet.name}::${value}`; return <label className="catalog-filter-checkbox" key={token}><input type="checkbox" name="variante" value={token} defaultChecked={route.variants.includes(token)} /><span>{value}</span><small>{count}</small></label>; })}</fieldset>)}<button type="submit" className="button button-primary button-block">Aplicar filtros</button></form>}</aside><section className="catalog-results"><ProductGrid products={route.products} columns={site.settings?.catalog?.desktopColumns || 3} showCategory={site.settings?.catalog?.showCategory} showDescription={site.settings?.catalog?.showDescription} />{route.pagination.totalPages > 1 && <nav className="catalog-pagination" aria-label="Paginação dos produtos"><a className={route.pagination.hasPreviousPage ? "" : "disabled"} href={catalogHref(route, Math.max(1, route.pagination.page - 1))}><span>‹</span> Anterior</a><div className="catalog-pagination-pages"><span className="catalog-pagination-item"><a className="active" href={catalogHref(route, route.pagination.page)}>{route.pagination.page}</a></span></div><a className={route.pagination.hasNextPage ? "" : "disabled"} href={catalogHref(route, Math.min(route.pagination.totalPages, route.pagination.page + 1))}>Próxima <span>›</span></a></nav>}</section></div></main>;
|
|
87
|
+
else if (route.type === "editorial-list") content = <main className="catalog-page"><section className="catalog-hero"><div className="store-container"><span>Conteúdo</span><h1>{route.title}</h1></div></section><section className="store-section"><div className="store-container"><EditorialPreview items={route.items} basePath={route.basePath} /></div></section></main>;
|
|
88
|
+
else if (route.type === "editorial-detail") content = <main className="store-section"><article className="store-container editorial-content"><span>Conteúdo</span><h1>{route.item.title}</h1><p>{route.item.description}</p></article></main>;
|
|
89
|
+
else content = <main className="not-found-page"><div className="not-found-card"><span>{route.type === "loading" ? "Carregando" : "404"}</span><h1>{route.title || (route.type === "loading" ? "Buscando conteúdo da loja" : "Conteúdo não encontrado")}</h1></div></main>;
|
|
90
|
+
return <div className="store-shell nuvler-default-theme" data-theme-id={themeDefinition.manifest.id} data-theme-version={themeDefinition.manifest.version} style={style}><Header site={site} categories={context.navigation.categories} pages={context.navigation.pages} template={themeDefinition.template} searchProducts={adapters?.searchProducts} cart={cartButton} /><div className="store-page">{content}</div><Footer site={site} pages={context.navigation.pages} template={themeDefinition.template} />{cartOpen && <div className="cart-backdrop" role="presentation" onPointerDown={(event) => event.target === event.currentTarget && setCartOpen(false)}><aside className="cart-drawer" aria-label="Carrinho de orçamento"><div className="cart-heading"><div><small>Seu orçamento</small><strong>{cartCount} {cartCount === 1 ? "item" : "itens"}</strong></div><button type="button" onClick={() => setCartOpen(false)} aria-label="Fechar carrinho">×</button></div><div className="cart-items">{!cartItems.length && <div className="cart-empty"><strong>Seu carrinho está vazio</strong><p>Abra um produto e adicione-o para montar a solicitação.</p><button type="button" onClick={() => setCartOpen(false)}>Continuar navegando</button></div>}{cartItems.map((item) => <article className="cart-item" key={item.key}><a href={`/produto/${item.productSlug}`} onClick={() => setCartOpen(false)}><ThemeImageView image={item.image} fallbackAlt={item.title} /></a><div><strong>{item.title}</strong>{item.variantName && <small>{item.variantName}</small>}{item.sku && <small>Ref. {item.sku}</small>}<div className="cart-quantity"><button type="button" onClick={() => setCartItems((current) => current.flatMap((candidate) => candidate.key !== item.key ? [candidate] : candidate.quantity > 1 ? [{ ...candidate, quantity: candidate.quantity - 1 }] : []))}>−</button><span>{item.quantity}</span><button type="button" onClick={() => setCartItems((current) => current.map((candidate) => candidate.key === item.key ? { ...candidate, quantity: Math.min(99, candidate.quantity + 1) } : candidate))}>+</button><button type="button" className="cart-remove" onClick={() => setCartItems((current) => current.filter((candidate) => candidate.key !== item.key))}>Remover</button></div></div></article>)}</div>{cartItems.length > 0 && <footer className="cart-footer"><p>O valor e a disponibilidade serão confirmados pela loja.</p>{checkoutUrl ? <a className="button button-primary button-block" href={checkoutUrl} target="_blank" rel="noreferrer">Enviar orçamento pelo WhatsApp</a> : <p className="cart-warning">Configure o WhatsApp da loja para enviar o orçamento.</p>}</footer>}</aside></div>}</div>;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
Theme.displayName = `NuvlerThemeRuntime(${themeDefinition.manifest.id})`;
|
|
94
|
+
return Theme;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export const Theme = createNuvlerDefaultRuntime(nuvlerDefaultTheme);
|