@nuvler/cli 0.5.17 → 0.5.19

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 (26) hide show
  1. package/dist/api/theme-context.js.map +1 -1
  2. package/dist/commands/theme/create.js +1 -1
  3. package/dist/nuvler.js +10 -1
  4. package/dist/nuvler.js.map +1 -1
  5. package/dist/templates/nuvler-atelier/package.json +2 -2
  6. package/dist/templates/nuvler-default/README.md +4 -4
  7. package/dist/templates/nuvler-default/nuvler.theme.json +1 -1
  8. package/dist/templates/nuvler-default/package.json +2 -2
  9. package/dist/templates/nuvler-default/src/catalog-filters.tsx +169 -0
  10. package/dist/templates/nuvler-default/src/interaction-colors.ts +49 -0
  11. package/dist/templates/nuvler-default/src/kit-composition.ts +15 -0
  12. package/dist/templates/nuvler-default/src/not-found.tsx +288 -21
  13. package/dist/templates/nuvler-default/src/product-detail-interactive.tsx +24 -12
  14. package/dist/templates/nuvler-default/src/server-shell.tsx +21 -3
  15. package/dist/templates/nuvler-default/src/theme-component.tsx +100 -27
  16. package/dist/templates/nuvler-default/src/theme.css +599 -210
  17. package/dist/templates/nuvler-default/src/whatsapp-message.ts +82 -0
  18. package/dist/templates/nuvler-default/test/catalog-filters.test.mjs +44 -0
  19. package/dist/templates/nuvler-default/test/interaction-colors.test.mjs +74 -0
  20. package/dist/templates/nuvler-default/test/kit-composition.test.mjs +28 -0
  21. package/dist/templates/nuvler-default/test/kit-detail.test.mjs +3 -3
  22. package/dist/templates/nuvler-default/test/whatsapp-message.test.mjs +126 -0
  23. package/dist/templates/starter/package.json +2 -2
  24. package/package.json +3 -3
  25. package/preview-host/package.json +1 -1
  26. package/preview-host/vendor/theme-runtime/default-theme.tsx +15 -6
@@ -13,13 +13,13 @@
13
13
  "typecheck": "tsc -p tsconfig.json --noEmit"
14
14
  },
15
15
  "dependencies": {
16
- "@nuvler/theme-sdk": "^1.4.7"
16
+ "@nuvler/theme-sdk": "^1.4.8"
17
17
  },
18
18
  "peerDependencies": {
19
19
  "react": "^19.0.0"
20
20
  },
21
21
  "devDependencies": {
22
- "@nuvler/cli": "^0.5.17",
22
+ "@nuvler/cli": "^0.5.18",
23
23
  "@types/react": "^19.0.0",
24
24
  "react": "^19.0.0",
25
25
  "typescript": "^5.9.0"
@@ -66,16 +66,16 @@ Para compilar, gerar o artefato ou publicar, execute na raiz do tooling:
66
66
  ```bash
67
67
  npm run pack:cli
68
68
  npm run pack:default
69
- npm publish ./artifacts/nuvler-cli-0.5.13.tgz --access public
70
- npm publish ./artifacts/nuvler-theme-default-1.1.7.tgz --access public
71
69
 
72
70
  node packages/cli/dist/nuvler.js theme build --theme themes/nuvler-default
73
71
  npm run pack:theme -- nuvler-default
74
72
  node packages/cli/dist/nuvler.js theme publish --theme themes/nuvler-default --official
75
73
  ```
76
74
 
77
- O pacote npm contém o renderer local e o CSS. O artefato do Theme Registry é
78
- gerado separadamente como `artifacts/nuvler-default-1.1.7.nuvler-theme.tgz`.
75
+ O pacote npm contém o renderer local e o CSS. As versões e a ordem de
76
+ publicação dos pacotes estão no [guia do monorepo](../../README.md#publicação-dos-pacotes-npm).
77
+ O artefato do Theme Registry é gerado separadamente como
78
+ `artifacts/nuvler-default-<versão>.nuvler-theme.tgz`.
79
79
 
80
80
  Exemplo no App Router:
81
81
 
@@ -5,7 +5,7 @@
5
5
  "schemaVersion": 1,
6
6
  "id": "nuvler-default",
7
7
  "name": "Nuvler Default",
8
- "version": "1.1.15",
8
+ "version": "1.1.24",
9
9
  "runtimeVersion": "1",
10
10
  "sdkVersion": "^1.3.3",
11
11
  "entry": "src/theme.tsx",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nuvler/theme-default",
3
- "version": "1.1.15",
3
+ "version": "1.1.24",
4
4
  "description": "Tema padrão oficial da Nuvler",
5
5
  "type": "module",
6
6
  "sideEffects": [
@@ -65,7 +65,7 @@
65
65
  "react": "^19.0.0"
66
66
  },
67
67
  "dependencies": {
68
- "@nuvler/theme-sdk": "^1.4.7"
68
+ "@nuvler/theme-sdk": "^1.4.9"
69
69
  },
70
70
  "devDependencies": {
71
71
  "@types/react": "^19.0.0",
@@ -0,0 +1,169 @@
1
+ "use client";
2
+
3
+ import { useEffect, useId, useRef, useState, type ReactNode } from "react";
4
+
5
+ export function CatalogFilters({
6
+ children,
7
+ total,
8
+ activeCount,
9
+ resetHref,
10
+ }: {
11
+ children: ReactNode;
12
+ total: number;
13
+ activeCount: number;
14
+ resetHref: string;
15
+ }) {
16
+ const [open, setOpen] = useState(false);
17
+ const panel = useRef<HTMLElement>(null);
18
+ const trigger = useRef<HTMLButtonElement>(null);
19
+ const close = useRef<HTMLButtonElement>(null);
20
+ const panelId = useId();
21
+
22
+ useEffect(() => {
23
+ if (!open) return;
24
+ const previous = document.body.style.overflow;
25
+ const opener = trigger.current;
26
+ document.body.style.overflow = "hidden";
27
+ const frame = requestAnimationFrame(() => close.current?.focus());
28
+ const desktop = window.matchMedia("(min-width: 801px)");
29
+ const resize = () => {
30
+ if (desktop.matches) setOpen(false);
31
+ };
32
+ desktop.addEventListener("change", resize);
33
+ return () => {
34
+ cancelAnimationFrame(frame);
35
+ document.body.style.overflow = previous;
36
+ desktop.removeEventListener("change", resize);
37
+ opener?.focus();
38
+ };
39
+ }, [open]);
40
+
41
+ function apply() {
42
+ const form =
43
+ panel.current?.querySelector<HTMLFormElement>(
44
+ ".catalog-variant-filters",
45
+ ) ??
46
+ panel.current?.querySelector<HTMLFormElement>(".catalog-filter-form");
47
+ if (!form) return;
48
+ const search = panel.current?.querySelector<HTMLInputElement>(
49
+ 'input[type="search"][name="busca"]',
50
+ );
51
+ if (search && !form.contains(search)) {
52
+ let field = form.querySelector<HTMLInputElement>('input[name="busca"]');
53
+ if (!field) {
54
+ field = document.createElement("input");
55
+ field.type = "hidden";
56
+ field.name = "busca";
57
+ form.appendChild(field);
58
+ }
59
+ field.value = search.value;
60
+ }
61
+ form.requestSubmit();
62
+ }
63
+
64
+ return (
65
+ <div
66
+ className="catalog-filter-container"
67
+ data-filters-open={open || undefined}
68
+ >
69
+ <div className="catalog-mobile-toolbar">
70
+ <span>
71
+ {total} {total === 1 ? "produto" : "produtos"}
72
+ </span>
73
+ <button
74
+ ref={trigger}
75
+ type="button"
76
+ aria-expanded={open}
77
+ aria-controls={panelId}
78
+ onClick={() => setOpen(true)}
79
+ >
80
+ <svg viewBox="0 0 24 24" aria-hidden="true">
81
+ <path d="M4 7h16M4 17h16M8 4v6m8 4v6" />
82
+ </svg>
83
+ Filtros
84
+ {activeCount > 0 && (
85
+ <span className="catalog-filter-count">{activeCount}</span>
86
+ )}
87
+ </button>
88
+ </div>
89
+ {open && (
90
+ <div
91
+ className="catalog-filter-backdrop"
92
+ aria-hidden="true"
93
+ onClick={() => setOpen(false)}
94
+ />
95
+ )}
96
+ <aside
97
+ ref={panel}
98
+ id={panelId}
99
+ className="category-filter catalog-filters"
100
+ role={open ? "dialog" : undefined}
101
+ aria-modal={open || undefined}
102
+ aria-label="Filtros do catálogo"
103
+ onSubmitCapture={(event) => {
104
+ if (
105
+ open &&
106
+ (event.target as HTMLFormElement).classList.contains(
107
+ "catalog-filter-form",
108
+ ) &&
109
+ panel.current?.querySelector(".catalog-variant-filters")
110
+ ) {
111
+ event.preventDefault();
112
+ event.stopPropagation();
113
+ apply();
114
+ return;
115
+ }
116
+ setOpen(false);
117
+ }}
118
+ onClickCapture={(event) => {
119
+ if ((event.target as Element).closest("a[href]")) setOpen(false);
120
+ }}
121
+ onKeyDown={(event) => {
122
+ if (!open) return;
123
+ if (event.key === "Escape") {
124
+ event.preventDefault();
125
+ setOpen(false);
126
+ }
127
+ if (event.key !== "Tab") return;
128
+ const items = [
129
+ ...(panel.current?.querySelectorAll<HTMLElement>(
130
+ 'a[href], button:not(:disabled), input:not(:disabled), select:not(:disabled), [tabindex="0"]',
131
+ ) ?? []),
132
+ ].filter((item) => item.getClientRects().length > 0);
133
+ const first = items[0];
134
+ const last = items.at(-1);
135
+ if (event.shiftKey && document.activeElement === first) {
136
+ event.preventDefault();
137
+ last?.focus();
138
+ } else if (!event.shiftKey && document.activeElement === last) {
139
+ event.preventDefault();
140
+ first?.focus();
141
+ }
142
+ }}
143
+ >
144
+ <div className="catalog-filter-mobile-heading">
145
+ <strong>Filtrar produtos</strong>
146
+ <button
147
+ ref={close}
148
+ type="button"
149
+ aria-label="Fechar filtros"
150
+ onClick={() => setOpen(false)}
151
+ >
152
+ ×
153
+ </button>
154
+ </div>
155
+ <div className="catalog-filter-body">{children}</div>
156
+ <div className="catalog-filter-mobile-actions">
157
+ <a href={resetHref}>Limpar</a>
158
+ <button
159
+ type="button"
160
+ className="button button-primary"
161
+ onClick={apply}
162
+ >
163
+ Ver resultados
164
+ </button>
165
+ </div>
166
+ </aside>
167
+ </div>
168
+ );
169
+ }
@@ -0,0 +1,49 @@
1
+ import type { ThemeSiteColors } from "@nuvler/theme-sdk";
2
+
3
+ /** Keep existing tokens as defaults; isolate component overrides from other surfaces. */
4
+ export function interactionColorVariables(colors: ThemeSiteColors) {
5
+ const surface = colors.surface ?? "#ffffff";
6
+ const text = colors.text;
7
+ return {
8
+ "--mobile-menu-text":
9
+ colors.mobileMenuText ?? colors.headerText ?? text,
10
+ "--mobile-menu-hover": `color-mix(in srgb, ${colors.mobileMenuText ?? colors.headerText ?? text}, transparent 88%)`,
11
+ "--search-toggle-background": colors.searchButtonBackground ?? "transparent",
12
+ "--search-toggle-text":
13
+ colors.searchButtonText ?? colors.headerText ?? text,
14
+ "--search-toggle-hover": colors.searchButtonBackground
15
+ ? `color-mix(in srgb, ${colors.searchButtonBackground}, ${colors.searchButtonText ?? "#ffffff"} 12%)`
16
+ : (colors.surfaceAlt ?? "#f4f7f3"),
17
+ "--search-background": colors.searchBackground ?? surface,
18
+ "--search-text": colors.searchText ?? text,
19
+ "--search-button-background":
20
+ colors.searchButtonBackground ?? colors.secondary,
21
+ "--search-button-text": colors.searchButtonText ?? "#ffffff",
22
+ "--search-muted": colors.searchText
23
+ ? `color-mix(in srgb, ${colors.searchText}, transparent 25%)`
24
+ : (colors.textMuted ?? "#657068"),
25
+ "--search-hover":
26
+ colors.searchBackground || colors.searchText
27
+ ? `color-mix(in srgb, ${colors.searchBackground ?? surface}, ${colors.searchText ?? text} 8%)`
28
+ : (colors.surfaceAlt ?? "#f4f7f3"),
29
+ "--cart-close-background":
30
+ colors.cartBackground || colors.cartText
31
+ ? `color-mix(in srgb, ${colors.cartText ?? text}, ${colors.cartBackground ?? surface} 95%)`
32
+ : colors.background,
33
+ "--search-border":
34
+ colors.searchBackground || colors.searchText
35
+ ? `color-mix(in srgb, ${colors.searchText ?? text}, transparent 80%)`
36
+ : (colors.border ?? "#dce3dc"),
37
+ "--cart-button-background": colors.cartButtonBackground ?? surface,
38
+ "--cart-button-text": colors.cartButtonText ?? text,
39
+ "--cart-background": colors.cartBackground ?? surface,
40
+ "--cart-text": colors.cartText ?? text,
41
+ "--cart-muted": colors.cartText
42
+ ? `color-mix(in srgb, ${colors.cartText}, transparent 25%)`
43
+ : (colors.textMuted ?? "#657068"),
44
+ "--cart-border":
45
+ colors.cartBackground || colors.cartText
46
+ ? `color-mix(in srgb, ${colors.cartText ?? text}, transparent 80%)`
47
+ : (colors.border ?? "#dce3dc"),
48
+ };
49
+ }
@@ -0,0 +1,15 @@
1
+ import {
2
+ kitCompositionText as groupedCompositionText,
3
+ type ThemeCartItem,
4
+ } from "@nuvler/theme-sdk";
5
+
6
+ /** The default theme displays legacy kit choices without a generated prefix. */
7
+ export function kitCompositionText(
8
+ item: Pick<ThemeCartItem, "kitSize" | "kitGroups" | "composition">,
9
+ ): string {
10
+ if (item.kitGroups?.length) return groupedCompositionText(item);
11
+ if (!item.kitSize) return "";
12
+ return (item.composition ?? [])
13
+ .map((part) => `${part.name}: ${part.quantity}`)
14
+ .join("; ");
15
+ }
@@ -1,16 +1,188 @@
1
1
  "use client";
2
2
 
3
- import type { NotFoundProps } from "@nuvler/theme-sdk";
3
+ import { useEffect, useState } from "react";
4
+ import {
5
+ notFoundCopy,
6
+ type NotFoundProps,
7
+ type ThemeNotFoundResource,
8
+ type ThemeProduct,
9
+ } from "@nuvler/theme-sdk";
4
10
 
5
- function SadCloudIllustration() {
6
- return <svg className="nuvler-not-found-cloud-svg" viewBox="0 0 640 420" aria-hidden="true">
7
- <path fill="currentColor" fillRule="evenodd" clipRule="evenodd" d="M124 319C75 319 36 282 36 236C36 195 67 161 108 155C112 100 158 58 215 58C242 58 267 67 287 83C316 45 362 22 413 22C488 22 550 77 559 148C605 154 640 192 640 238C640 283 603 319 556 319H124ZM250 183C239 183 232 194 232 210C232 226 239 237 250 237C261 237 268 226 268 210C268 194 261 183 250 183ZM391 183C380 183 373 194 373 210C373 226 380 237 391 237C402 237 409 226 409 210C409 194 402 183 391 183ZM210 164C224 160 238 152 250 140C254 136 260 137 263 141C267 145 266 151 262 155C248 169 231 178 215 181C210 182 206 179 205 174C204 169 206 166 210 164ZM432 164C418 160 404 152 392 140C388 136 382 137 379 141C375 145 376 151 380 155C394 169 411 178 427 181C432 182 436 179 437 174C438 169 436 166 432 164ZM282 260C292 241 307 232 321 232C336 232 351 241 360 260C362 265 360 270 355 272C350 274 346 271 344 267C338 254 330 247 321 247C312 247 304 254 297 267C295 271 290 274 285 272C280 270 279 265 282 260Z" />
8
- <path fill="currentColor" fillRule="evenodd" clipRule="evenodd" d="M165 286C165 254 190 229 222 229C254 229 280 254 280 286C280 316 259 339 231 344C219 346 209 341 202 332C195 342 184 347 172 344C145 338 128 312 135 286C139 270 149 258 165 250V286ZM167 300C171 297 176 298 179 302C187 311 192 320 195 331C196 336 193 340 188 341C183 342 179 339 178 334C176 326 171 317 164 310C161 306 162 302 167 300ZM192 294C196 291 201 292 204 296C212 305 217 314 220 325C221 330 218 334 213 335C208 336 204 333 203 328C201 320 196 311 189 304C186 300 187 296 192 294Z" />
9
- <path fill="currentColor" fillRule="evenodd" clipRule="evenodd" d="M360 286C360 254 386 229 418 229C450 229 476 254 476 286C476 316 455 339 427 344C415 346 405 341 398 332C391 342 380 347 368 344C341 338 324 312 331 286C335 270 345 258 360 250V286ZM362 300C366 297 371 298 374 302C382 311 387 320 390 331C391 336 388 340 383 341C378 342 374 339 373 334C371 326 366 317 359 310C356 306 357 302 362 300ZM387 294C391 291 396 292 399 296C407 305 412 314 415 325C416 330 413 334 408 335C403 336 399 333 398 328C396 320 391 311 384 304C381 300 382 296 387 294Z" />
10
- </svg>;
11
+ import { ProductGrid } from "./products.js";
12
+ import type { ThemeImageComponent } from "./shared.js";
13
+
14
+ export interface NotFoundShortcut {
15
+ label: string;
16
+ href: string;
17
+ }
18
+
19
+ /**
20
+ * Props do 404 do tema padrão. Os campos extras são opcionais: sem eles
21
+ * (ex.: fallback local do storefront) a página continua completa, só sem
22
+ * atalhos e sugestões.
23
+ */
24
+ export interface NuvlerNotFoundProps extends NotFoundProps {
25
+ /** Produtos exibidos em "Talvez você goste destes" (produto/categoria). */
26
+ suggestions?: ThemeProduct[];
27
+ /** Busca usada para sugerir itens parecidos com o slug acessado. */
28
+ searchProducts?: (query: string) => Promise<ThemeProduct[]>;
29
+ /** Links de "Ou vá direto para" no 404 genérico. */
30
+ shortcuts?: NotFoundShortcut[];
31
+ showPrices?: boolean;
32
+ ImageComponent?: ThemeImageComponent;
33
+ }
34
+
35
+ const SUGGESTION_LIMIT = 4;
36
+
37
+ /** Títulos e textos com a voz do tema; o SDK fornece o rótulo neutro. */
38
+ const THEME_COPY: Record<
39
+ ThemeNotFoundResource,
40
+ { title: string; description: string }
41
+ > = {
42
+ page: {
43
+ title: "Essa página se perdeu nas nuvens",
44
+ description:
45
+ "O endereço pode ter mudado, sido removido ou digitado errado. Mas calma, a gente te ajuda a voltar pro caminho.",
46
+ },
47
+ product: {
48
+ title: "Procuramos por todo canto e esse produto não apareceu",
49
+ description:
50
+ "Ele pode ter esgotado, saído do catálogo ou o link mudou. Que tal buscar algo parecido?",
51
+ },
52
+ category: {
53
+ title: "Essa categoria saiu da vitrine",
54
+ description:
55
+ "Ela pode ter sido renomeada ou removida. Busque o que você procura ou veja todos os produtos.",
56
+ },
57
+ post: {
58
+ title: "Esse artigo voou para longe",
59
+ description:
60
+ "Ele pode ter sido removido ou o link mudou. Os outros conteúdos do blog continuam por aqui.",
61
+ },
62
+ service: {
63
+ title: "Esse serviço não está mais por aqui",
64
+ description:
65
+ "Ele pode ter sido atualizado ou mudado de endereço. Confira os serviços disponíveis.",
66
+ },
67
+ case: {
68
+ title: "Esse case não está mais por aqui",
69
+ description:
70
+ "Ele pode ter sido removido ou ainda não foi publicado. Veja os outros cases.",
71
+ },
72
+ };
73
+
74
+ /** "camiseta-azul-p" -> "camiseta azul" para buscar itens parecidos. */
75
+ function searchTermsFromPath(pathname?: string): string {
76
+ const slug = pathname?.split("/").filter(Boolean).at(-1) ?? "";
77
+ let decoded = slug;
78
+ try {
79
+ decoded = decodeURIComponent(slug);
80
+ } catch {
81
+ // Mantém o slug bruto quando a URL vem malformada.
82
+ }
83
+ return decoded
84
+ .split(/[-_\s]+/)
85
+ .filter((word) => word.length >= 3 && !/^\d+$/.test(word))
86
+ .slice(0, 3)
87
+ .join(" ");
11
88
  }
12
89
 
13
- export function NotFound({ homeHref = "/" }: NotFoundProps) {
90
+ function CloudIllustration({ variant }: { variant: "lost" | "search" }) {
91
+ return (
92
+ <svg
93
+ className="nuvler-not-found-illustration"
94
+ viewBox="0 0 280 200"
95
+ aria-hidden="true"
96
+ >
97
+ <path
98
+ className="nf-cloud"
99
+ d="M74 172h128c30 0 52-21 52-48 0-26-20-46-46-47-6-32-33-55-66-55-27 0-50 16-59 40-4-1-8-1-12-1-30 0-53 24-53 54 0 32 24 57 56 57Z"
100
+ />
101
+ <ellipse className="nf-eye" cx="118" cy="114" rx="7" ry="9" />
102
+ <ellipse className="nf-eye" cx="160" cy="114" rx="7" ry="9" />
103
+ <circle className="nf-eye-shine" cx="120.5" cy="110" r="2.4" />
104
+ <circle className="nf-eye-shine" cx="162.5" cy="110" r="2.4" />
105
+ <ellipse className="nf-cheek" cx="100" cy="134" rx="10" ry="5.5" />
106
+ <ellipse className="nf-cheek" cx="178" cy="134" rx="10" ry="5.5" />
107
+ {variant === "lost" ? (
108
+ <>
109
+ <path className="nf-mouth" d="M128 141q11-8 22 0" />
110
+ <path
111
+ className="nf-accent-stroke"
112
+ d="M222 26c0-11 9-18 19-18s19 7 19 17c0 13-17 14-17 28"
113
+ />
114
+ <circle className="nf-accent-fill" cx="243" cy="68" r="5.5" />
115
+ </>
116
+ ) : (
117
+ <>
118
+ <path className="nf-mouth" d="M128 139h22" />
119
+ <circle className="nf-lens" cx="232" cy="46" r="24" />
120
+ <path className="nf-lens-shine" d="M220 36a14 14 0 0 1 12-6" />
121
+ <path className="nf-accent-stroke" d="M215 64l-18 22" />
122
+ </>
123
+ )}
124
+ </svg>
125
+ );
126
+ }
127
+
128
+ function HomeIcon() {
129
+ return (
130
+ <svg viewBox="0 0 24 24" aria-hidden="true">
131
+ <path d="M4 11.5 12 5l8 6.5V20a1 1 0 0 1-1 1h-4.5v-6h-5v6H5a1 1 0 0 1-1-1z" />
132
+ </svg>
133
+ );
134
+ }
135
+
136
+ function BackIcon() {
137
+ return (
138
+ <svg viewBox="0 0 24 24" aria-hidden="true">
139
+ <path d="m14.5 6-6 6 6 6" />
140
+ </svg>
141
+ );
142
+ }
143
+
144
+ function SearchIcon() {
145
+ return (
146
+ <svg viewBox="0 0 24 24" aria-hidden="true">
147
+ <circle cx="11" cy="11" r="7" />
148
+ <path d="m16.5 16.5 4 4" />
149
+ </svg>
150
+ );
151
+ }
152
+
153
+ export function NotFound({
154
+ homeHref = "/",
155
+ resource = "page",
156
+ pathname,
157
+ suggestions = [],
158
+ searchProducts,
159
+ shortcuts = [],
160
+ showPrices = true,
161
+ ImageComponent,
162
+ }: NuvlerNotFoundProps) {
163
+ const label = notFoundCopy(resource, homeHref);
164
+ const copy = THEME_COPY[resource] ?? THEME_COPY.page;
165
+ const isCatalog = resource === "product" || resource === "category";
166
+
167
+ const [related, setRelated] = useState<ThemeProduct[] | null>(null);
168
+ const terms = isCatalog ? searchTermsFromPath(pathname) : "";
169
+ useEffect(() => {
170
+ if (!terms || !searchProducts) return;
171
+ let cancelled = false;
172
+ searchProducts(terms)
173
+ .then((items) => {
174
+ if (!cancelled && items.length)
175
+ setRelated(items.slice(0, SUGGESTION_LIMIT));
176
+ })
177
+ .catch(() => {
178
+ // Sem sugestões relacionadas: mantém as sugestões gerais.
179
+ });
180
+ return () => {
181
+ cancelled = true;
182
+ };
183
+ }, [terms, searchProducts]);
184
+ const products = related ?? suggestions.slice(0, SUGGESTION_LIMIT);
185
+
14
186
  const goBack = () => {
15
187
  if (window.history.length > 1) {
16
188
  window.history.back();
@@ -19,18 +191,113 @@ export function NotFound({ homeHref = "/" }: NotFoundProps) {
19
191
  window.location.assign(homeHref);
20
192
  };
21
193
 
22
- return <main className="nuvler-not-found">
23
- <div className="nuvler-not-found-content">
24
- <div className="nuvler-not-found-visual" aria-hidden="true">
25
- <SadCloudIllustration />
26
- <span className="nuvler-not-found-code">404</span>
27
- </div>
28
- <h1>Página não encontrada</h1>
29
- <p>Parece que esta página foi movida, removida ou nunca existiu.</p>
30
- <div className="nuvler-not-found-actions">
31
- <a className="button button-primary" href={homeHref}>Ir para o início</a>
32
- <button className="button button-secondary" type="button" onClick={goBack}>Voltar</button>
194
+ if (isCatalog)
195
+ return (
196
+ <main
197
+ className="nuvler-not-found nuvler-not-found-catalog"
198
+ data-not-found-resource={resource}
199
+ >
200
+ <div className="store-container">
201
+ <section className="nuvler-not-found-card">
202
+ <div className="nuvler-not-found-art">
203
+ <CloudIllustration variant="search" />
204
+ </div>
205
+ <div className="nuvler-not-found-body">
206
+ <span className="nuvler-not-found-eyebrow">
207
+ Erro 404 · {label.title}
208
+ </span>
209
+ <h1>{copy.title}</h1>
210
+ <p>{copy.description}</p>
211
+ <form
212
+ className="nuvler-not-found-search"
213
+ action="/produtos"
214
+ method="get"
215
+ role="search"
216
+ >
217
+ <label>
218
+ <SearchIcon />
219
+ <span className="nuvler-not-found-sr">Buscar na loja</span>
220
+ <input
221
+ name="busca"
222
+ type="search"
223
+ placeholder="Buscar na loja..."
224
+ autoComplete="off"
225
+ />
226
+ </label>
227
+ <button className="button button-primary" type="submit">
228
+ Buscar
229
+ </button>
230
+ </form>
231
+ <div className="nuvler-not-found-links">
232
+ <a className="is-primary" href={label.action.href}>
233
+ {label.action.label} →
234
+ </a>
235
+ <a href={homeHref}>Voltar à loja</a>
236
+ </div>
237
+ </div>
238
+ </section>
239
+ {products.length > 0 && (
240
+ <section className="nuvler-not-found-suggestions">
241
+ <header>
242
+ <h2>Talvez você goste destes</h2>
243
+ <a href={label.action.href}>Ver mais</a>
244
+ </header>
245
+ <ProductGrid
246
+ products={products}
247
+ columns={4}
248
+ showPrices={showPrices}
249
+ showDescription={false}
250
+ ImageComponent={ImageComponent}
251
+ />
252
+ </section>
253
+ )}
254
+ </div>
255
+ </main>
256
+ );
257
+
258
+ const specific = resource !== "page";
259
+ return (
260
+ <main
261
+ className="nuvler-not-found nuvler-not-found-page"
262
+ data-not-found-resource={resource}
263
+ >
264
+ <span className="nuvler-not-found-puff puff-a" aria-hidden="true" />
265
+ <span className="nuvler-not-found-puff puff-b" aria-hidden="true" />
266
+ <span className="nuvler-not-found-puff puff-c" aria-hidden="true" />
267
+ <div className="nuvler-not-found-content">
268
+ <CloudIllustration variant="lost" />
269
+ <span className="nuvler-not-found-eyebrow">
270
+ {specific ? `Erro 404 · ${label.title}` : "Erro 404"}
271
+ </span>
272
+ <h1>{copy.title}</h1>
273
+ <p>{copy.description}</p>
274
+ <div className="nuvler-not-found-actions">
275
+ <a className="button button-primary" href={label.action.href}>
276
+ {!specific && <HomeIcon />}
277
+ {label.action.label}
278
+ </a>
279
+ <button
280
+ className="button nuvler-not-found-ghost"
281
+ type="button"
282
+ onClick={goBack}
283
+ >
284
+ <BackIcon />
285
+ Voltar à página anterior
286
+ </button>
287
+ </div>
288
+ {shortcuts.length > 0 && (
289
+ <nav className="nuvler-not-found-shortcuts" aria-label="Atalhos">
290
+ <span>Ou vá direto para</span>
291
+ <ul>
292
+ {shortcuts.map((shortcut) => (
293
+ <li key={shortcut.href}>
294
+ <a href={shortcut.href}>{shortcut.label}</a>
295
+ </li>
296
+ ))}
297
+ </ul>
298
+ </nav>
299
+ )}
33
300
  </div>
34
- </div>
35
- </main>;
301
+ </main>
302
+ );
36
303
  }