@nuvler/cli 0.5.18 → 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.
- package/dist/commands/theme/create.js +1 -1
- package/dist/nuvler.js +1 -1
- package/dist/nuvler.js.map +1 -1
- package/dist/templates/nuvler-default/nuvler.theme.json +1 -1
- package/dist/templates/nuvler-default/package.json +2 -2
- package/dist/templates/nuvler-default/src/not-found.tsx +288 -21
- package/dist/templates/nuvler-default/src/theme-component.tsx +42 -4
- package/dist/templates/nuvler-default/src/theme.css +295 -209
- package/dist/templates/starter/package.json +2 -2
- package/package.json +2 -2
- package/preview-host/vendor/theme-runtime/default-theme.tsx +15 -6
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nuvler/theme-default",
|
|
3
|
-
"version": "1.1.
|
|
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.
|
|
68
|
+
"@nuvler/theme-sdk": "^1.4.9"
|
|
69
69
|
},
|
|
70
70
|
"devDependencies": {
|
|
71
71
|
"@types/react": "^19.0.0",
|
|
@@ -1,16 +1,188 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
|
|
3
|
-
import
|
|
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
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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
|
-
|
|
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
|
-
|
|
23
|
-
|
|
24
|
-
<
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
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
|
-
</
|
|
35
|
-
|
|
301
|
+
</main>
|
|
302
|
+
);
|
|
36
303
|
}
|
|
@@ -14,6 +14,7 @@ import {
|
|
|
14
14
|
useMemo,
|
|
15
15
|
useRef,
|
|
16
16
|
useState,
|
|
17
|
+
type ComponentType,
|
|
17
18
|
type CSSProperties,
|
|
18
19
|
} from "react";
|
|
19
20
|
import {
|
|
@@ -26,6 +27,7 @@ import {
|
|
|
26
27
|
type ThemeEditorialItem,
|
|
27
28
|
type ThemeHomeSection,
|
|
28
29
|
type ThemeNavigationItem,
|
|
30
|
+
type ThemeNotFoundResource,
|
|
29
31
|
type ThemePageContent,
|
|
30
32
|
type ThemePageSummary,
|
|
31
33
|
type ThemeImage,
|
|
@@ -36,7 +38,25 @@ import {
|
|
|
36
38
|
} from "@nuvler/theme-sdk";
|
|
37
39
|
import { nuvlerDefaultTheme } from "./definition.js";
|
|
38
40
|
import { ThemeInteractionProvider } from "./product-detail-interactive.js";
|
|
39
|
-
import { plainText, ThemeImageView } from "./shared.js";
|
|
41
|
+
import { categoryUrl, plainText, ThemeImageView } from "./shared.js";
|
|
42
|
+
import type { NotFoundShortcut, NuvlerNotFoundProps } from "./not-found.js";
|
|
43
|
+
|
|
44
|
+
/** Atalhos do 404 genérico, conforme os módulos e conteúdos da loja. */
|
|
45
|
+
function notFoundShortcuts(context: PreviewContext): NotFoundShortcut[] {
|
|
46
|
+
const shortcuts: NotFoundShortcut[] = [];
|
|
47
|
+
if (context.site.modules.includes("PRODUCTS")) {
|
|
48
|
+
shortcuts.push({ label: "Produtos", href: "/produtos" });
|
|
49
|
+
for (const category of context.navigation.categories.slice(0, 2))
|
|
50
|
+
shortcuts.push({ label: category.name, href: categoryUrl([category.slug]) });
|
|
51
|
+
}
|
|
52
|
+
if (context.editorial.services.length)
|
|
53
|
+
shortcuts.push({ label: "Serviços", href: "/servicos" });
|
|
54
|
+
if (context.editorial.posts.length)
|
|
55
|
+
shortcuts.push({ label: "Blog", href: "/blog" });
|
|
56
|
+
if (context.editorial.cases.length)
|
|
57
|
+
shortcuts.push({ label: "Cases", href: "/cases" });
|
|
58
|
+
return shortcuts.slice(0, 5);
|
|
59
|
+
}
|
|
40
60
|
import { CustomHtmlContent } from "./custom-html-content.js";
|
|
41
61
|
|
|
42
62
|
interface PreviewContext {
|
|
@@ -64,7 +84,13 @@ type PreviewEditorialItem = ThemeEditorialItem & {
|
|
|
64
84
|
};
|
|
65
85
|
|
|
66
86
|
type PreviewRoute =
|
|
67
|
-
| { type: "home" | "loading"
|
|
87
|
+
| { type: "home" | "loading"; title?: string }
|
|
88
|
+
| {
|
|
89
|
+
type: "not-found";
|
|
90
|
+
title?: string;
|
|
91
|
+
pathname?: string;
|
|
92
|
+
resource?: ThemeNotFoundResource;
|
|
93
|
+
}
|
|
68
94
|
| { type: "page"; title: string; slug: string; content: ThemePageContent }
|
|
69
95
|
| {
|
|
70
96
|
type: "catalog";
|
|
@@ -462,6 +488,10 @@ export function createNuvlerDefaultRuntime(
|
|
|
462
488
|
|
|
463
489
|
const { Header, Footer, Home, ProductDetail, ProductGrid, NotFound } =
|
|
464
490
|
themeDefinition.components;
|
|
491
|
+
// O NotFound do tema aceita dados extras (sugestões, busca, atalhos).
|
|
492
|
+
const NotFoundView = NotFound as
|
|
493
|
+
| ComponentType<NuvlerNotFoundProps>
|
|
494
|
+
| undefined;
|
|
465
495
|
const site: ThemeSite = {
|
|
466
496
|
tenant: context.store,
|
|
467
497
|
modules: context.site.modules,
|
|
@@ -865,8 +895,16 @@ export function createNuvlerDefaultRuntime(
|
|
|
865
895
|
</main>
|
|
866
896
|
);
|
|
867
897
|
else if (route.type === "not-found")
|
|
868
|
-
content =
|
|
869
|
-
<
|
|
898
|
+
content = NotFoundView ? (
|
|
899
|
+
<NotFoundView
|
|
900
|
+
homeHref="/"
|
|
901
|
+
resource={route.resource}
|
|
902
|
+
pathname={route.pathname}
|
|
903
|
+
suggestions={context.catalog.products}
|
|
904
|
+
searchProducts={adapters?.searchProducts}
|
|
905
|
+
shortcuts={notFoundShortcuts(context)}
|
|
906
|
+
showPrices={showPrices}
|
|
907
|
+
/>
|
|
870
908
|
) : (
|
|
871
909
|
<main className="not-found-page">
|
|
872
910
|
<div className="not-found-card">
|