@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.
Files changed (41) hide show
  1. package/README.md +25 -2
  2. package/dist/commands/theme/create.js +2 -2
  3. package/dist/commands/theme/validate.js +21 -0
  4. package/dist/commands/theme/validate.js.map +1 -1
  5. package/dist/index.js +1 -1
  6. package/dist/migrate/generator.js +6 -5
  7. package/dist/migrate/generator.js.map +1 -1
  8. package/dist/nuvler.js +163 -10
  9. package/dist/nuvler.js.map +1 -1
  10. package/dist/templates/nuvler-atelier/nuvler.theme.json +1 -1
  11. package/dist/templates/nuvler-atelier/package.json +2 -2
  12. package/dist/templates/nuvler-atelier/src/definition.tsx +10 -9
  13. package/dist/templates/nuvler-atelier/src/theme.tsx +2 -2
  14. package/dist/templates/nuvler-default/README.md +50 -4
  15. package/dist/templates/nuvler-default/nuvler.theme.json +2 -2
  16. package/dist/templates/nuvler-default/package.json +37 -5
  17. package/dist/templates/nuvler-default/src/banner-carousel.tsx +42 -12
  18. package/dist/templates/nuvler-default/src/carousel-frame.tsx +58 -0
  19. package/dist/templates/nuvler-default/src/definition.ts +9 -59
  20. package/dist/templates/nuvler-default/src/footer.tsx +7 -2
  21. package/dist/templates/nuvler-default/src/header-interactions.tsx +114 -12
  22. package/dist/templates/nuvler-default/src/header.tsx +7 -5
  23. package/dist/templates/nuvler-default/src/home.tsx +61 -20
  24. package/dist/templates/nuvler-default/src/index.ts +1 -0
  25. package/dist/templates/nuvler-default/src/product-carousel.tsx +13 -7
  26. package/dist/templates/nuvler-default/src/product-detail-interactive.tsx +261 -0
  27. package/dist/templates/nuvler-default/src/product-detail.tsx +80 -55
  28. package/dist/templates/nuvler-default/src/products.tsx +9 -6
  29. package/dist/templates/nuvler-default/src/server-shell.tsx +91 -0
  30. package/dist/templates/nuvler-default/src/shared.tsx +28 -16
  31. package/dist/templates/nuvler-default/src/theme-component.tsx +6 -5
  32. package/dist/templates/nuvler-default/src/theme-config.ts +63 -0
  33. package/dist/templates/nuvler-default/src/theme.css +159 -3
  34. package/dist/templates/starter/nuvler.theme.json +1 -1
  35. package/dist/templates/starter/package.json +2 -2
  36. package/dist/templates/starter/src/definition.tsx +3 -2
  37. package/dist/theme/performance.js +126 -0
  38. package/dist/theme/performance.js.map +1 -0
  39. package/package.json +2 -2
  40. package/preview-host/package.json +1 -1
  41. package/preview-host/vendor/theme-runtime/default-theme.tsx +13 -12
@@ -1,7 +1,7 @@
1
1
  "use client";
2
2
 
3
- import { useEffect, useLayoutEffect, useRef, useState, type KeyboardEvent } from "react";
4
- import type { ThemeCategory, ThemePageSummary, ThemeProduct, ThemeSite } from "@nuvler/theme-sdk";
3
+ import { useCallback, useEffect, useLayoutEffect, useRef, useState, type KeyboardEvent } from "react";
4
+ import { productUrl, type ThemeCategory, type ThemeNavigationItem, type ThemePageSummary, type ThemeProduct, type ThemeSite } from "@nuvler/theme-sdk";
5
5
  import { categoryUrl, displayPrice, ThemeImageView } from "./shared.js";
6
6
 
7
7
  function CategoryTree({ categories, path = [], depth = 0 }: {
@@ -21,11 +21,71 @@ function CategoryTree({ categories, path = [], depth = 0 }: {
21
21
  });
22
22
  }
23
23
 
24
- export function CategoryNavigation({ categories }: { categories: ThemeCategory[] }) {
24
+ type CategoryLoadStatus = "idle" | "loading" | "loaded" | "error";
25
+
26
+ interface CategoryMatch {
27
+ category: ThemeCategory;
28
+ path: string[];
29
+ }
30
+
31
+ function categorySlugFromMenuItem(item: ThemeNavigationItem) {
32
+ if (item.type !== "CATEGORY") return null;
33
+ const keySlug = item.key.startsWith("CATEGORY:") ? item.key.slice("CATEGORY:".length) : "";
34
+ if (keySlug) return keySlug;
35
+ const segments = item.href.split(/[?#]/, 1)[0].split("/").filter(Boolean);
36
+ return segments.length ? decodeURIComponent(segments.at(-1)!) : null;
37
+ }
38
+
39
+ function findCategory(categories: ThemeCategory[], slug: string, path: string[] = []): CategoryMatch | null {
40
+ for (const category of categories) {
41
+ const currentPath = [...path, category.slug];
42
+ if (category.slug === slug) return { category, path: currentPath };
43
+ const child = findCategory(category.children ?? [], slug, currentPath);
44
+ if (child) return child;
45
+ }
46
+ return null;
47
+ }
48
+
49
+ function useLazyCategories(initialCategories: ThemeCategory[]) {
50
+ const [categories, setCategories] = useState(initialCategories);
51
+ const [status, setStatus] = useState<CategoryLoadStatus>("idle");
52
+ const pendingRequest = useRef<Promise<void> | null>(null);
53
+
54
+ const load = useCallback(() => {
55
+ if (status === "loaded") return Promise.resolve();
56
+ if (pendingRequest.current) return pendingRequest.current;
57
+
58
+ setStatus("loading");
59
+ const request = fetch("/api/product-categories", {
60
+ headers: { accept: "application/json" },
61
+ })
62
+ .then(async (response) => {
63
+ if (!response.ok) throw new Error(`Categorias indisponíveis (${response.status})`);
64
+ const payload: unknown = await response.json();
65
+ if (!Array.isArray(payload)) throw new Error("Resposta de categorias inválida");
66
+ setCategories(payload as ThemeCategory[]);
67
+ setStatus("loaded");
68
+ })
69
+ .catch(() => {
70
+ setStatus("error");
71
+ })
72
+ .finally(() => {
73
+ pendingRequest.current = null;
74
+ });
75
+
76
+ pendingRequest.current = request;
77
+ return request;
78
+ }, [status]);
79
+
80
+ return { categories, status, load };
81
+ }
82
+
83
+ export function CategoryNavigation({ categories: initialCategories }: { categories: ThemeCategory[] }) {
25
84
  const innerRef = useRef<HTMLDivElement>(null);
26
85
  const allRef = useRef<HTMLDetailsElement>(null);
27
86
  const itemRefs = useRef<Array<HTMLDivElement | null>>([]);
28
87
  const [visibleCount, setVisibleCount] = useState(0);
88
+ const { categories, status, load } = useLazyCategories(initialCategories);
29
89
 
30
90
  useLayoutEffect(() => {
31
91
  const inner = innerRef.current;
@@ -59,24 +119,57 @@ export function CategoryNavigation({ categories }: { categories: ThemeCategory[]
59
119
 
60
120
  return <nav className="category-nav" aria-label="Categorias de produtos">
61
121
  <div className="store-container category-nav-inner" ref={innerRef}>
62
- <details className="category-nav-all" ref={allRef}>
122
+ <details
123
+ className="category-nav-all"
124
+ ref={allRef}
125
+ onToggle={(event) => {
126
+ if (event.currentTarget.open) void load();
127
+ }}
128
+ >
63
129
  <summary className="all-categories"><svg viewBox="0 0 24 24" aria-hidden="true"><path d="M4 7h16M4 12h16M4 17h16" /></svg><span>Todas as categorias</span><svg className="category-nav-chevron" viewBox="0 0 20 20" aria-hidden="true"><path d="m6 8 4 4 4-4" /></svg></summary>
64
130
  <div className="category-nav-all-panel">
65
131
  <div className="category-nav-panel-heading"><div><span>Explore o catálogo</span><strong>Todas as categorias</strong></div><a href="/produtos">Ver todos</a></div>
132
+ {status === "loading" && <p className="category-nav-status" role="status">Carregando categorias…</p>}
133
+ {status === "error" && <p className="category-nav-status">Não foi possível atualizar as categorias.</p>}
66
134
  <div className="category-nav-tree"><CategoryTree categories={categories} /></div>
67
135
  </div>
68
136
  </details>
69
137
  {categories.map((category, index) => {
70
138
  const overflowed = index >= visibleCount;
71
- return <div className="category-nav-group" data-overflowed={overflowed || undefined} aria-hidden={overflowed || undefined} key={category.slug} ref={(node) => { itemRefs.current[index] = node; }}>
72
- <a href={categoryUrl([category.slug])}>{category.name}{category.children?.length > 0 && <span aria-hidden="true">⌄</span>}</a>
73
- {category.children?.length > 0 && <div className="category-nav-submenu"><CategoryTree categories={category.children} path={[category.slug]} /></div>}
139
+ const hasSubmenu = status !== "loaded" || category.children?.length > 0;
140
+ return <div className="category-nav-group" data-overflowed={overflowed || undefined} aria-hidden={overflowed || undefined} key={category.slug} ref={(node) => { itemRefs.current[index] = node; }} onPointerEnter={() => { void load(); }} onFocusCapture={() => { void load(); }}>
141
+ <a href={categoryUrl([category.slug])}>{category.name}{hasSubmenu && <svg className="category-item-chevron" viewBox="0 0 20 20" aria-hidden="true"><path d="m6 8 4 4 4-4" /></svg>}</a>
142
+ {hasSubmenu && <div className="category-nav-submenu">
143
+ {status !== "loaded" && category.children.length === 0 && <p className="category-nav-status" role="status">{status === "error" ? "Não foi possível carregar as subcategorias." : "Carregando subcategorias…"}</p>}
144
+ {category.children?.length > 0 && <CategoryTree categories={category.children} path={[category.slug]} />}
145
+ </div>}
74
146
  </div>;
75
147
  })}
76
148
  </div>
77
149
  </nav>;
78
150
  }
79
151
 
152
+ export function ConfiguredNavigation({ menu, categories: initialCategories }: { menu: ThemeNavigationItem[]; categories: ThemeCategory[] }) {
153
+ const { categories, status, load } = useLazyCategories(initialCategories);
154
+ return <div className="primary-nav-shell"><nav className="store-container main-nav" aria-label="Navegação principal">
155
+ <a href="/">Início</a>
156
+ {menu.map((item) => {
157
+ const categorySlug = categorySlugFromMenuItem(item);
158
+ if (!categorySlug) return <a href={item.href} key={item.key}>{item.label}</a>;
159
+ const match = findCategory(categories, categorySlug);
160
+ const hasSubcategories = status !== "loaded" || Boolean(match?.category.children.length);
161
+ return <div className="main-nav-group" key={item.key} onPointerEnter={() => { void load(); }} onFocusCapture={() => { void load(); }}>
162
+ <a href={item.href}>{item.label}{hasSubcategories && <svg className="category-item-chevron" viewBox="0 0 20 20" aria-hidden="true"><path d="m6 8 4 4 4-4" /></svg>}</a>
163
+ {hasSubcategories && <div className="category-nav-submenu configured-category-submenu">
164
+ <div className="configured-category-heading"><div><span>Explore a categoria</span><strong>{match?.category.name ?? item.label}</strong></div><a href={item.href}>Ver todos</a></div>
165
+ {status !== "loaded" && !match?.category.children.length && <p className="category-nav-status" role="status">{status === "error" ? "Não foi possível carregar as subcategorias." : "Carregando subcategorias…"}</p>}
166
+ {match?.category.children.length ? <div className="configured-category-grid"><CategoryTree categories={match.category.children} path={match.path} /></div> : null}
167
+ </div>}
168
+ </div>;
169
+ })}
170
+ </nav></div>;
171
+ }
172
+
80
173
  export function SmartProductSearch({ endpoint = "/api/product-suggestions", queryParam = "q", searchProducts }: { endpoint?: string; queryParam?: string; searchProducts?: (query: string) => Promise<ThemeProduct[]> }) {
81
174
  const [value, setValue] = useState("");
82
175
  const [results, setResults] = useState<ThemeProduct[]>([]);
@@ -142,7 +235,7 @@ export function SmartProductSearch({ endpoint = "/api/product-suggestions", quer
142
235
  }
143
236
  if (event.key === "Enter" && activeIndex >= 0) {
144
237
  event.preventDefault();
145
- window.location.assign(`/produto/${results[activeIndex].slug}`);
238
+ window.location.assign(productUrl(results[activeIndex]));
146
239
  }
147
240
  }
148
241
 
@@ -158,8 +251,8 @@ export function SmartProductSearch({ endpoint = "/api/product-suggestions", quer
158
251
  {open && query.length >= 2 && <div className="search-suggestions" id="theme-search-suggestions" role="listbox" aria-label="Sugestões de produtos">
159
252
  <div className="search-suggestions-heading"><strong>Sugestões para “{query}”</strong>{!loading && <span>{resultLabel}</span>}</div>
160
253
  {loading && <div className="search-suggestions-loading"><span aria-hidden="true" /><p>Procurando os produtos mais próximos…</p></div>}
161
- {!loading && results.map((product, index) => <a id={`theme-search-result-${index}`} className={activeIndex === index ? "active" : ""} href={`/produto/${product.slug}`} role="option" aria-selected={activeIndex === index} key={product.slug} onPointerEnter={() => setActiveIndex(index)}>
162
- <span className="search-suggestion-image"><ThemeImageView image={product.image} fallbackAlt={product.title} /></span>
254
+ {!loading && results.map((product, index) => <a id={`theme-search-result-${index}`} className={activeIndex === index ? "active" : ""} href={productUrl(product)} role="option" aria-selected={activeIndex === index} key={product.slug} onPointerEnter={() => setActiveIndex(index)}>
255
+ <span className="search-suggestion-image"><ThemeImageView image={product.image} fallbackAlt={product.title} sizes="56px" fallbackWidth={112} fallbackHeight={112} /></span>
163
256
  <span className="search-suggestion-copy"><strong>{product.title}</strong><span className="search-suggestion-meta">{product.categories[0]?.name && <small>{product.categories[0].name}</small>}{product.sku && <small>Ref. {product.sku}</small>}</span></span>
164
257
  {displayPrice(product) && <b>{displayPrice(product)}</b>}
165
258
  <span className="search-suggestion-arrow" aria-hidden="true">→</span>
@@ -177,8 +270,9 @@ function MobileCategories({ categories, path = [] }: { categories: ThemeCategory
177
270
  });
178
271
  }
179
272
 
180
- export function MobileStoreMenu({ site, categories, pages }: { site: ThemeSite; categories: ThemeCategory[]; pages: ThemePageSummary[] }) {
273
+ export function MobileStoreMenu({ site, categories: initialCategories, pages, menu = [] }: { site: ThemeSite; categories: ThemeCategory[]; pages: ThemePageSummary[]; menu?: ThemeNavigationItem[] }) {
181
274
  const [open, setOpen] = useState(false);
275
+ const { categories, status, load } = useLazyCategories(initialCategories);
182
276
  useEffect(() => {
183
277
  if (!open) return;
184
278
  const previous = document.body.style.overflow;
@@ -186,5 +280,13 @@ export function MobileStoreMenu({ site, categories, pages }: { site: ThemeSite;
186
280
  return () => { document.body.style.overflow = previous; };
187
281
  }, [open]);
188
282
  const settings = site.settings;
189
- return <><button type="button" className="mobile-menu-trigger" onClick={() => setOpen(true)} aria-label="Abrir menu"><svg viewBox="0 0 24 24" aria-hidden="true"><path d="M4 7h16M4 12h16M4 17h16" /></svg></button>{open && <div className="mobile-menu-backdrop" role="presentation" onPointerDown={(event) => event.target === event.currentTarget && setOpen(false)}><aside className="mobile-menu-drawer" aria-label="Menu da loja"><div className="mobile-menu-heading"><div><small>Navegue pela loja</small><strong>{settings?.siteName || site.tenant.name}</strong></div><button type="button" onClick={() => setOpen(false)} aria-label="Fechar menu">×</button></div><nav className="mobile-menu-links"><a href="/">Início</a>{site.modules.includes("PRODUCTS") && <a href="/produtos">Todos os produtos</a>}{site.modules.includes("BLOG") && <a href="/blog">Blog</a>}{site.modules.includes("SERVICES") && <a href="/servicos">Serviços</a>}{site.modules.includes("CASES") && <a href="/cases">Cases</a>}{pages.slice(0, 8).map((page) => <a href={`/${page.slug}`} key={page.slug}>{page.title}</a>)}</nav>{categories.length > 0 && <section className="mobile-menu-categories"><h2>Categorias</h2><MobileCategories categories={categories} /></section>}</aside></div>}</>;
283
+ const configuredMenu = [...menu].sort((left, right) => left.order - right.order);
284
+ const configuredHasCategories = configuredMenu.some((item) => item.type === "CATEGORY");
285
+ return <><button type="button" className="mobile-menu-trigger" onClick={() => { setOpen(true); if (!configuredMenu.length || configuredHasCategories) void load(); }} aria-label="Abrir menu"><svg viewBox="0 0 24 24" aria-hidden="true"><path d="M4 7h16M4 12h16M4 17h16" /></svg></button>{open && <div className="mobile-menu-backdrop" role="presentation" onPointerDown={(event) => event.target === event.currentTarget && setOpen(false)}><aside className="mobile-menu-drawer" aria-label="Menu da loja"><div className="mobile-menu-heading"><div><small>Navegue pela loja</small><strong>{settings?.siteName || site.tenant.name}</strong></div><button type="button" onClick={() => setOpen(false)} aria-label="Fechar menu">×</button></div><nav className="mobile-menu-links"><a href="/">Início</a>{configuredMenu.length ? configuredMenu.map((item) => {
286
+ const categorySlug = categorySlugFromMenuItem(item);
287
+ if (!categorySlug) return <a href={item.href} key={item.key}>{item.label}</a>;
288
+ const match = findCategory(categories, categorySlug);
289
+ const hasSubcategories = status !== "loaded" || Boolean(match?.category.children.length);
290
+ return hasSubcategories ? <details key={item.key} className="mobile-menu-category"><summary><span>{item.label}</span><span aria-hidden="true">+</span></summary><div><a href={item.href}>Ver tudo em {item.label}</a>{status !== "loaded" && !match?.category.children.length && <p className="mobile-menu-category-status" role="status">{status === "error" ? "Não foi possível carregar as subcategorias." : "Carregando subcategorias…"}</p>}{match?.category.children.length ? <MobileCategories categories={match.category.children} path={match.path} /> : null}</div></details> : <a href={item.href} key={item.key}>{item.label}</a>;
291
+ }) : <>{site.modules.includes("PRODUCTS") && <a href="/produtos">Todos os produtos</a>}{site.modules.includes("BLOG") && <a href="/blog">Blog</a>}{site.modules.includes("SERVICES") && <a href="/servicos">Serviços</a>}{site.modules.includes("CASES") && <a href="/cases">Cases</a>}{pages.slice(0, 8).map((page) => <a href={`/${page.slug}`} key={page.slug}>{page.title}</a>)}</>}</nav>{!configuredMenu.length && categories.length > 0 && <section className="mobile-menu-categories"><h2>Categorias</h2>{status === "loading" && <p className="mobile-menu-category-status" role="status">Carregando categorias…</p>}{status === "error" && <p className="mobile-menu-category-status">Não foi possível atualizar as categorias.</p>}<MobileCategories categories={categories} /></section>}</aside></div>}</>;
190
292
  }
@@ -1,14 +1,16 @@
1
1
  import type { HeaderProps } from "@nuvler/theme-sdk";
2
- import { CategoryNavigation, MobileStoreMenu, SmartProductSearch } from "./header-interactions.js";
3
- import { ThemeImageView } from "./shared.js";
2
+ import { CategoryNavigation, ConfiguredNavigation, MobileStoreMenu, SmartProductSearch } from "./header-interactions.js";
3
+ import { ThemeImageView, type ThemeImageComponent } from "./shared.js";
4
4
 
5
5
  function SupplementaryLinks({ site, pages }: Pick<HeaderProps, "site" | "pages">) {
6
6
  return <>{site.modules.includes("BLOG") && <a href="/blog">Blog</a>}{site.modules.includes("SERVICES") && <a href="/servicos">Serviços</a>}{site.modules.includes("CASES") && <a href="/cases">Cases</a>}{pages.slice(0, 6).map((page) => <a key={page.slug} href={`/${page.slug}`}>{page.title}</a>)}</>;
7
7
  }
8
8
 
9
- export function Header({ site, categories, pages, template, cart, suggestionsEndpoint, suggestionsQueryParam, searchProducts }: HeaderProps) {
9
+ export function Header({ site, categories, pages, menu = [], template, cart, suggestionsEndpoint, suggestionsQueryParam, searchProducts, ImageComponent = ThemeImageView }: HeaderProps & { ImageComponent?: ThemeImageComponent }) {
10
10
  const name = site.settings?.siteName || site.tenant.name;
11
11
  const hasCategories = categories.length > 0;
12
- const hasExtra = site.modules.some((module) => ["BLOG", "SERVICES", "CASES"].includes(module)) || pages.length > 0;
13
- return <><div className="announcement"><div className="store-container announcement-inner"><span>{template.announcement}</span>{site.settings?.contact.phone && <span>{site.settings.contact.phone}</span>}</div></div><header className="store-header"><div className={`store-container header-inner${hasCategories && hasExtra ? "" : " header-inner-simple"}`}><MobileStoreMenu site={site} categories={categories} pages={pages} /><a className="brand" href="/" aria-label={`${name} — início`}>{site.settings?.logo?.url ? <ThemeImageView image={site.settings.logo} fallbackAlt={name} className="brand-logo" priority /> : <><span className="brand-mark">7</span><span>{name}</span></>}</a>{site.modules.includes("PRODUCTS") && <SmartProductSearch endpoint={suggestionsEndpoint} queryParam={suggestionsQueryParam} searchProducts={searchProducts} />}<div className="header-message"><span className="header-message-icon" aria-hidden="true"><svg viewBox="0 0 24 24"><path d="m12 3 2.1 4.9L19 10l-4.9 2.1L12 17l-2.1-4.9L5 10l4.9-2.1L12 3Z" /></svg></span><span className="header-message-copy"><small>Nossa loja</small><strong>{site.settings?.description?.trim() || template.announcement}</strong></span></div>{hasCategories && hasExtra && <div className="header-actions"><details className="header-more-menu"><summary>Mais <span aria-hidden="true">⌄</span></summary><div className="header-more-panel"><SupplementaryLinks site={site} pages={pages} /></div></details></div>}{cart}</div>{hasCategories ? <CategoryNavigation categories={categories} /> : <div className="primary-nav-shell"><nav className="store-container main-nav" aria-label="Navegação principal"><a href="/">Início</a>{site.modules.includes("PRODUCTS") && <a href="/produtos">Produtos</a>}<SupplementaryLinks site={site} pages={pages} /></nav></div>}</header></>;
12
+ const configuredMenu = [...menu].sort((left, right) => left.order - right.order);
13
+ const hasConfiguredMenu = configuredMenu.length > 0;
14
+ const hasExtra = !hasConfiguredMenu && (site.modules.some((module) => ["BLOG", "SERVICES", "CASES"].includes(module)) || pages.length > 0);
15
+ return <><div className="announcement"><div className="store-container announcement-inner"><span>{template.announcement}</span>{site.settings?.contact.phone && <span>{site.settings.contact.phone}</span>}</div></div><header className="store-header"><div className={`store-container header-inner${hasCategories && hasExtra ? "" : " header-inner-simple"}`}><MobileStoreMenu site={site} categories={categories} pages={pages} menu={configuredMenu} /><a className="brand" href="/" aria-label={`${name} — início`}>{site.settings?.logo?.url ? <ImageComponent image={site.settings.logo} fallbackAlt={name} className="brand-logo" sizes="200px" fallbackWidth={240} fallbackHeight={96} /> : <><span className="brand-mark">7</span><span>{name}</span></>}</a>{site.modules.includes("PRODUCTS") && <SmartProductSearch endpoint={suggestionsEndpoint} queryParam={suggestionsQueryParam} searchProducts={searchProducts} />}<div className="header-message"><span className="header-message-icon" aria-hidden="true"><svg viewBox="0 0 24 24"><path d="m12 3 2.1 4.9L19 10l-4.9 2.1L12 17l-2.1-4.9L5 10l4.9-2.1L12 3Z" /></svg></span><span className="header-message-copy"><small>Nossa loja</small><strong>{site.settings?.description?.trim() || template.announcement}</strong></span></div>{hasCategories && hasExtra && <div className="header-actions"><details className="header-more-menu"><summary>Mais <span aria-hidden="true">⌄</span></summary><div className="header-more-panel"><SupplementaryLinks site={site} pages={pages} /></div></details></div>}{cart}</div>{hasConfiguredMenu ? <ConfiguredNavigation menu={configuredMenu} categories={categories} /> : hasCategories ? <CategoryNavigation categories={categories} /> : <div className="primary-nav-shell"><nav className="store-container main-nav" aria-label="Navegação principal"><a href="/">Início</a>{site.modules.includes("PRODUCTS") && <a href="/produtos">Produtos</a>}<SupplementaryLinks site={site} pages={pages} /></nav></div>}</header></>;
14
16
  }
@@ -1,7 +1,8 @@
1
- import type { HomeProps, ThemeEditorialItem, ThemeHomeSection, ThemeSite } from "@nuvler/theme-sdk";
1
+ import type { HomeProps, ThemeEditorialItem, ThemeHomeSection, ThemeImage, ThemeSite } from "@nuvler/theme-sdk";
2
2
  import { BannerCarousel, type ThemeBanner } from "./banner-carousel.js";
3
3
  import { ProductCarousel } from "./product-carousel.js";
4
- import { ThemeImageView } from "./shared.js";
4
+ import { ProductGrid } from "./products.js";
5
+ import { categoryUrl, ThemeImageView, type ThemeImageComponent } from "./shared.js";
5
6
 
6
7
  function text(data: Record<string, unknown>, key: string, fallback = "") {
7
8
  const value = data[key];
@@ -13,13 +14,43 @@ function limit(data: Record<string, unknown>) {
13
14
  return Number.isInteger(value) ? Math.min(12, Math.max(1, value)) : 6;
14
15
  }
15
16
 
17
+ function productCategory(data: Record<string, unknown>) {
18
+ const value = text(data, "categorySlug").toLocaleLowerCase("pt-BR");
19
+ if (["", "all", "todos", "todas", "all-categories", "todas-as-categorias"].includes(value)) return "";
20
+ return value;
21
+ }
22
+
23
+ function imageValue(value: unknown): ThemeImage | null {
24
+ if (!value || typeof value !== "object" || Array.isArray(value)) return null;
25
+ const image = value as Record<string, unknown>;
26
+ if (typeof image.url !== "string" || !image.url) return null;
27
+ return {
28
+ url: image.url,
29
+ alt: typeof image.alt === "string" ? image.alt : null,
30
+ width: typeof image.width === "number" ? image.width : null,
31
+ height: typeof image.height === "number" ? image.height : null,
32
+ };
33
+ }
34
+
35
+ function sectionImage(data: Record<string, unknown>, fallbackAlt: string): ThemeImage | null {
36
+ const enriched = imageValue(data.image);
37
+ if (enriched) return enriched;
38
+ const imageUrl = text(data, "imageUrl");
39
+ return imageUrl ? {
40
+ url: imageUrl,
41
+ alt: text(data, "imageAlt", fallbackAlt),
42
+ width: null,
43
+ height: null,
44
+ } : null;
45
+ }
46
+
16
47
  function banners(data: Record<string, unknown>): ThemeBanner[] {
17
48
  if (!Array.isArray(data.banners)) return [];
18
49
  return data.banners.flatMap((entry) => {
19
50
  if (!entry || typeof entry !== "object") return [];
20
51
  const item = entry as Record<string, unknown>;
21
52
  if (typeof item.imageUrl !== "string" || !item.imageUrl) return [];
22
- return [{ imageUrl: item.imageUrl, imageAlt: typeof item.imageAlt === "string" ? item.imageAlt : undefined, title: typeof item.title === "string" ? item.title : undefined, description: typeof item.description === "string" ? item.description : undefined, buttonLabel: typeof item.buttonLabel === "string" ? item.buttonLabel : undefined, buttonUrl: typeof item.buttonUrl === "string" ? item.buttonUrl : undefined }];
53
+ return [{ imageUrl: item.imageUrl, image: imageValue(item.image), imageAlt: typeof item.imageAlt === "string" ? item.imageAlt : undefined, title: typeof item.title === "string" ? item.title : undefined, description: typeof item.description === "string" ? item.description : undefined, buttonLabel: typeof item.buttonLabel === "string" ? item.buttonLabel : undefined, buttonUrl: typeof item.buttonUrl === "string" ? item.buttonUrl : undefined }];
23
54
  });
24
55
  }
25
56
 
@@ -27,43 +58,53 @@ function Heading({ data, title, href }: { data: Record<string, unknown>; title:
27
58
  return <div className="section-heading"><div><span>{text(data, "eyebrow", "Em destaque")}</span><h2>{text(data, "title", title)}</h2></div><a href={href}>Ver todos</a></div>;
28
59
  }
29
60
 
30
- function Hero({ section, site, action }: { section: ThemeHomeSection; site: ThemeSite; action: { label: string; href: string } }) {
61
+ function Hero({ section, site, action, priority, ImageComponent = ThemeImageView }: { section: ThemeHomeSection; site: ThemeSite; action: { label: string; href: string }; priority: boolean; ImageComponent?: ThemeImageComponent }) {
31
62
  const name = site.settings?.siteName || site.tenant.name;
32
63
  const title = text(section.data, "title", "Tudo o que você procura, em um só lugar.");
33
64
  const description = text(section.data, "description", site.settings?.description || `Conheça a seleção de produtos da ${name}.`);
34
- const imageUrl = text(section.data, "imageUrl");
65
+ const image = sectionImage(section.data, title);
35
66
  const copy = <div className="hero-copy"><span className="hero-eyebrow">{text(section.data, "eyebrow", "Bem-vindo à nossa loja")}</span><h1>{title}</h1><p>{description}</p><div className="hero-actions"><a className="button button-primary" href={text(section.data, "buttonUrl", action.href)}>{text(section.data, "buttonLabel", action.label)}</a>{site.modules.includes("PRODUCTS") && <a className="text-link" href="/produtos">Ver catálogo completo <span>→</span></a>}</div></div>;
36
- if (imageUrl) return <section className="hero-section hero-section-image"><ThemeImageView image={{ url: imageUrl, alt: text(section.data, "imageAlt", title), width: null, height: null }} fallbackAlt={title} className="hero-background-image" priority /><div className="hero-background-overlay" aria-hidden="true" /><div className="store-container hero-image-content">{copy}</div></section>;
67
+ if (image) return <section className="hero-section hero-section-image"><ImageComponent image={image} fallbackAlt={title} className="hero-background-image" priority={priority} sizes="100vw" fallbackWidth={1600} fallbackHeight={700} /><div className="hero-background-overlay" aria-hidden="true" /><div className="store-container hero-image-content">{copy}</div></section>;
37
68
  return <section className="hero-section"><div className="store-container hero-grid">{copy}<div className="hero-art" aria-hidden="true"><div className="hero-orbit hero-orbit-one" /><div className="hero-orbit hero-orbit-two" /><div className="hero-seven">7</div><span className="hero-card hero-card-top">Seleção especial</span><span className="hero-card hero-card-bottom">Atendimento humano</span></div></div></section>;
38
69
  }
39
70
 
40
- function EditorialGrid({ items, basePath }: { items: ThemeEditorialItem[]; basePath: string }) {
71
+ function EditorialGrid({ items, basePath, ImageComponent = ThemeImageView }: { items: ThemeEditorialItem[]; basePath: string; ImageComponent?: ThemeImageComponent }) {
41
72
  if (!items.length) return <div className="empty-state"><span>7</span><h2>Nenhum conteúdo publicado</h2><p>As publicações aparecerão aqui quando estiverem disponíveis.</p></div>;
42
- return <div className="editorial-grid">{items.map((item) => <article className="editorial-card" key={item.slug}><a className="editorial-card-image" href={`${basePath}/${item.slug}`}><ThemeImageView image={item.image || item.thumbnail || item.coverImage} fallbackAlt={item.title} /></a><div className="editorial-card-content">{(item.category?.title || item.category?.name) && <span>{item.category.title || item.category.name}</span>}<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>;
73
+ return <div className="editorial-grid">{items.map((item) => <article className="editorial-card" key={item.slug}><a className="editorial-card-image" href={`${basePath}/${item.slug}`}><ImageComponent image={item.image || item.thumbnail || item.coverImage} fallbackAlt={item.title} sizes="(max-width: 720px) 92vw, 33vw" fallbackWidth={720} fallbackHeight={480} /></a><div className="editorial-card-content">{(item.category?.title || item.category?.name) && <span>{item.category.title || item.category.name}</span>}<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>;
43
74
  }
44
75
 
45
- function TextSection({ section }: { section: ThemeHomeSection }) {
76
+ function TextSection({ section, ImageComponent = ThemeImageView }: { section: ThemeHomeSection; ImageComponent?: ThemeImageComponent }) {
46
77
  const title = text(section.data, "title", "Conteúdo");
47
78
  const description = text(section.data, "description", text(section.data, "text"));
48
- const imageUrl = text(section.data, "imageUrl");
49
- if (section.type === "image-text") return <section className="store-section image-text-section"><div className="store-container image-text-layout" data-position={section.data.imagePosition === "right" ? "right" : "left"}>{imageUrl && <div className="image-text-media"><ThemeImageView image={{ url: imageUrl, alt: title, width: null, height: null }} fallbackAlt={title} /></div>}<div className="image-text-copy">{text(section.data, "eyebrow") && <span>{text(section.data, "eyebrow")}</span>}<h2>{title}</h2>{description && <p>{description}</p>}</div></div></section>;
79
+ const image = sectionImage(section.data, title);
80
+ if (section.type === "image-text") return <section className="store-section image-text-section"><div className="store-container image-text-layout" data-position={section.data.imagePosition === "right" ? "right" : "left"}>{image && <div className="image-text-media"><ImageComponent image={image} fallbackAlt={title} sizes="(max-width: 900px) 100vw, 50vw" fallbackWidth={800} fallbackHeight={600} /></div>}<div className="image-text-copy">{text(section.data, "eyebrow") && <span>{text(section.data, "eyebrow")}</span>}<h2>{title}</h2>{description && <p>{description}</p>}</div></div></section>;
50
81
  return <section className="store-section editorial-section"><div className="store-container editorial-content">{text(section.data, "eyebrow") && <span>{text(section.data, "eyebrow")}</span>}<h2>{title}</h2>{description && <p>{description}</p>}{section.type === "cta" && text(section.data, "buttonLabel") && text(section.data, "buttonUrl") && <a className="button button-primary" href={text(section.data, "buttonUrl")}>{text(section.data, "buttonLabel")}</a>}</div></section>;
51
82
  }
52
83
 
53
- export function Home({ sections, products, posts, services, cases, site, template }: HomeProps) {
84
+ export function Home({ sections, products, posts, services, cases, site, template, ImageComponent = ThemeImageView }: HomeProps & { ImageComponent?: ThemeImageComponent }) {
54
85
  const visible = [...sections].filter((section) => section.enabled).sort((a, b) => a.order - b.order);
55
86
  const rendered = visible.length ? visible : template.fallbackSections(site.modules);
56
- const catalog = site.settings?.catalog ?? { showCategory: true, showDescription: true };
87
+ const catalog = site.settings?.catalog ?? { showCategory: true, showDescription: true, desktopColumns: 4 as const };
57
88
  return <>{rendered.map((section, index) => {
58
- if (section.type === "hero") return <Hero key={section.id || index} section={section} site={site} action={template.primaryAction(site.modules)} />;
59
- if (section.type === "banner-carousel") return <BannerCarousel key={section.id || index} banners={banners(section.data)} autoplay={section.data.autoplay !== false} />;
60
- if (["image-text", "rich-text", "cta"].includes(section.type)) return <TextSection key={section.id || index} section={section} />;
89
+ if (section.type === "hero") return <Hero key={section.id || index} section={section} site={site} action={template.primaryAction(site.modules)} priority={index === 0} ImageComponent={ImageComponent} />;
90
+ if (section.type === "banner-carousel") return <BannerCarousel key={section.id || index} banners={banners(section.data)} autoplay={section.data.autoplay !== false} priority={index === 0} ImageComponent={ImageComponent} />;
91
+ if (["image-text", "rich-text", "cta"].includes(section.type)) return <TextSection key={section.id || index} section={section} ImageComponent={ImageComponent} />;
61
92
  if (section.type === "products-grid" || section.type === "products-carousel") {
62
- const category = text(section.data, "categorySlug");
63
- const items = products.filter((product) => !category || product.categories.some(({ slug }) => slug === category)).slice(0, limit(section.data));
64
- return <section className="store-section" key={section.id || index}><div className="store-container"><Heading data={section.data} title={section.type === "products-grid" ? "Produtos em destaque" : "Vitrine de produtos"} href="/produtos" /><ProductCarousel products={items} showCategory={catalog.showCategory} showDescription={catalog.showDescription} /></div></section>;
93
+ const category = productCategory(section.data);
94
+ const items = products.filter((product) => !category || product.categories.some(({ slug }) => slug === category) || product.categoryPath?.includes(category)).slice(0, limit(section.data));
95
+ const matchingPath = category
96
+ ? items.find((product) => product.categoryPath?.includes(category))?.categoryPath
97
+ : undefined;
98
+ const categoryIndex = matchingPath?.indexOf(category) ?? -1;
99
+ const allProductsHref = categoryIndex >= 0 && matchingPath
100
+ ? categoryUrl(matchingPath.slice(0, categoryIndex + 1))
101
+ : category ? `/produtos?categoria=${encodeURIComponent(category)}` : "/produtos";
102
+ const productsView = section.type === "products-grid"
103
+ ? <ProductGrid products={items} columns={catalog.desktopColumns} showCategory={catalog.showCategory} showDescription={catalog.showDescription} ImageComponent={ImageComponent} />
104
+ : <ProductCarousel products={items} showCategory={catalog.showCategory} showDescription={catalog.showDescription} ImageComponent={ImageComponent} />;
105
+ return <section className="store-section" key={section.id || index}><div className="store-container"><Heading data={section.data} title={section.type === "products-grid" ? "Produtos em destaque" : "Vitrine de produtos"} href={allProductsHref} />{productsView}</div></section>;
65
106
  }
66
107
  const map = section.type === "services-grid" ? { items: services, path: "/servicos", title: "Nossos serviços" } : section.type === "cases-grid" ? { items: cases, path: "/cases", title: "Cases e resultados" } : { items: posts, path: "/blog", title: "Conteúdos recentes" };
67
- return <section className="store-section" key={section.id || index}><div className="store-container"><Heading data={section.data} title={map.title} href={map.path} /><EditorialGrid items={map.items.slice(0, limit(section.data))} basePath={map.path} /></div></section>;
108
+ return <section className="store-section" key={section.id || index}><div className="store-container"><Heading data={section.data} title={map.title} href={map.path} /><EditorialGrid items={map.items.slice(0, limit(section.data))} basePath={map.path} ImageComponent={ImageComponent} /></div></section>;
68
109
  })}<section className="benefits-section"><div className="store-container benefits-grid">{template.benefits.map((benefit) => <div key={benefit.title}><strong>{benefit.title}</strong><span>{benefit.description}</span></div>)}</div></section></>;
69
110
  }
@@ -3,6 +3,7 @@ export { Theme, createNuvlerDefaultRuntime } from "./theme-component.js";
3
3
  export type { NuvlerDefaultThemeProps } from "./theme-component.js";
4
4
  export { Header } from "./header.js";
5
5
  export { Footer } from "./footer.js";
6
+ export type { NuvlerDefaultFooterProps } from "./footer.js";
6
7
  export { Home } from "./home.js";
7
8
  export { ProductGrid, ProductCard } from "./products.js";
8
9
  export { ProductDetail } from "./product-detail.js";
@@ -1,12 +1,18 @@
1
- "use client";
2
-
3
- import { useRef } from "react";
4
1
  import type { ThemeProduct } from "@nuvler/theme-sdk";
2
+
3
+ import { ProductCarouselFrame } from "./carousel-frame.js";
5
4
  import { ProductCard } from "./products.js";
5
+ import type { ThemeImageComponent } from "./shared.js";
6
6
 
7
- export function ProductCarousel({ products, showCategory, showDescription }: { products: ThemeProduct[]; showCategory: boolean; showDescription: boolean }) {
8
- const track = useRef<HTMLDivElement>(null);
7
+ export function ProductCarousel({ products, showCategory, showDescription, ImageComponent }: { products: ThemeProduct[]; showCategory: boolean; showDescription: boolean; ImageComponent?: ThemeImageComponent }) {
9
8
  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>;
9
+ return (
10
+ <ProductCarouselFrame>
11
+ {products.map((product) => (
12
+ <div className="product-carousel-item" key={product.slug}>
13
+ <ProductCard product={product} showCategory={showCategory} showDescription={showDescription} ImageComponent={ImageComponent} />
14
+ </div>
15
+ ))}
16
+ </ProductCarouselFrame>
17
+ );
12
18
  }