@nuvler/cli 0.5.6 → 0.5.8
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/nuvler.js +49 -9
- package/dist/nuvler.js.map +1 -1
- package/dist/preview/launcher.js +4 -3
- package/dist/preview/launcher.js.map +1 -1
- package/dist/templates/nuvler-default/nuvler.theme.json +150 -7
- package/dist/templates/nuvler-default/package.json +1 -1
- package/dist/templates/nuvler-default/src/assets/not-found-cloud.png +0 -0
- package/dist/templates/nuvler-default/src/assets/not-found-cloud.svg +131 -0
- package/dist/templates/nuvler-default/src/assets/not-found-illustration.png +0 -0
- package/dist/templates/nuvler-default/src/banner-carousel.tsx +11 -0
- package/dist/templates/nuvler-default/src/carousel-frame.tsx +8 -4
- package/dist/templates/nuvler-default/src/definition.ts +2 -1
- package/dist/templates/nuvler-default/src/footer.tsx +4 -2
- package/dist/templates/nuvler-default/src/header-interactions.tsx +30 -17
- package/dist/templates/nuvler-default/src/header.tsx +25 -10
- package/dist/templates/nuvler-default/src/home.tsx +37 -25
- package/dist/templates/nuvler-default/src/index.ts +2 -0
- package/dist/templates/nuvler-default/src/not-found.tsx +29 -0
- package/dist/templates/nuvler-default/src/product-carousel.tsx +1 -1
- package/dist/templates/nuvler-default/src/product-detail-interactive.tsx +7 -1
- package/dist/templates/nuvler-default/src/product-detail.tsx +27 -5
- package/dist/templates/nuvler-default/src/products.tsx +13 -2
- package/dist/templates/nuvler-default/src/server-shell.tsx +5 -5
- package/dist/templates/nuvler-default/src/styles.d.ts +15 -0
- package/dist/templates/nuvler-default/src/theme-component.tsx +27 -8
- package/dist/templates/nuvler-default/src/theme-config.ts +12 -12
- package/dist/templates/nuvler-default/src/theme.css +1724 -169
- package/package.json +1 -1
- package/preview-host/src/main.tsx +16 -1
- package/preview-host/src/preview-path.d.mts +4 -1
- package/preview-host/src/preview-path.mjs +32 -1
- package/preview-host/vendor/theme-runtime/default-theme.tsx +57 -5
- package/preview-host/vendor/theme-runtime/index.ts +1 -1
package/package.json
CHANGED
|
@@ -22,8 +22,22 @@ function PreviewImage({ image, fallbackAlt, className }: ThemeImageProps) {
|
|
|
22
22
|
return <img className={className} src={image.url} alt={image.alt || fallbackAlt} />;
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
+
function categoryPathFromNavigation(slug: string, categories: typeof context.navigation.categories, path: string[] = []): string[] | null {
|
|
26
|
+
for (const category of categories) {
|
|
27
|
+
const currentPath = [...path, category.slug];
|
|
28
|
+
if (category.slug === slug) return currentPath;
|
|
29
|
+
const match = categoryPathFromNavigation(slug, category.children ?? [], currentPath);
|
|
30
|
+
if (match) return match;
|
|
31
|
+
}
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
|
|
25
35
|
function normalizeProduct(value: unknown): ThemeProduct {
|
|
26
36
|
const product = value as Partial<ThemeProduct>;
|
|
37
|
+
const explicitCategoryPath = product.categoryPath?.filter(Boolean) ?? [];
|
|
38
|
+
const categoryPath = explicitCategoryPath.length > 0
|
|
39
|
+
? explicitCategoryPath
|
|
40
|
+
: product.categories?.map((category) => categoryPathFromNavigation(category.slug, context.navigation.categories)).find(Boolean) ?? [];
|
|
27
41
|
return {
|
|
28
42
|
title: product.title || "Produto",
|
|
29
43
|
slug: product.slug || "produto",
|
|
@@ -38,6 +52,7 @@ function normalizeProduct(value: unknown): ThemeProduct {
|
|
|
38
52
|
image: product.image || null,
|
|
39
53
|
images: product.images || [],
|
|
40
54
|
categories: product.categories || [],
|
|
55
|
+
categoryPath,
|
|
41
56
|
variantOptions: product.variantOptions || [],
|
|
42
57
|
variants: product.variants || [],
|
|
43
58
|
publishedAt: product.publishedAt ?? null,
|
|
@@ -112,7 +127,7 @@ function PreviewApp() {
|
|
|
112
127
|
if (localRoute) { setRoute(localRoute); return; }
|
|
113
128
|
setRoute({ type: "loading", pathname: url.pathname });
|
|
114
129
|
try {
|
|
115
|
-
const target = classifyPreviewPath(url.pathname);
|
|
130
|
+
const target = classifyPreviewPath(url.pathname, context.navigation.categories);
|
|
116
131
|
if (target.type === "product") {
|
|
117
132
|
const slug = target.slug;
|
|
118
133
|
const product = normalizeProduct(await previewApi<unknown>(`products/${encodeURIComponent(slug)}`));
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
export function classifyPreviewPath(
|
|
1
|
+
export function classifyPreviewPath(
|
|
2
|
+
pathname: string,
|
|
3
|
+
categories?: Array<{ slug: string; children?: unknown[] }>,
|
|
4
|
+
):
|
|
2
5
|
| { type: "catalog"; categoryPath: string[] }
|
|
3
6
|
| { type: "page" | "product"; slug: string }
|
|
4
7
|
| { type: "not-found" };
|
|
@@ -1,4 +1,18 @@
|
|
|
1
|
-
|
|
1
|
+
function matchedCategoryPath(segments, categories) {
|
|
2
|
+
const path = [];
|
|
3
|
+
let current = Array.isArray(categories) ? categories : [];
|
|
4
|
+
|
|
5
|
+
for (const segment of segments) {
|
|
6
|
+
const category = current.find((item) => item?.slug === segment);
|
|
7
|
+
if (!category) break;
|
|
8
|
+
path.push(category.slug);
|
|
9
|
+
current = Array.isArray(category.children) ? category.children : [];
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
return path;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function classifyPreviewPath(pathname, categories = []) {
|
|
2
16
|
const segments = pathname.split("/").filter(Boolean).map(decodeURIComponent);
|
|
3
17
|
if (segments.length === 1 && segments[0] === "produtos") {
|
|
4
18
|
return { type: "catalog", categoryPath: [] };
|
|
@@ -9,6 +23,23 @@ export function classifyPreviewPath(pathname) {
|
|
|
9
23
|
if (segments[0] === "produto" && segments.length === 2) {
|
|
10
24
|
return { type: "product", slug: segments[1] };
|
|
11
25
|
}
|
|
26
|
+
|
|
27
|
+
// As categorias do tenant podem ser links de primeiro nível, como `/casa`.
|
|
28
|
+
// Somente um caminho que corresponda integralmente à árvore é um catálogo;
|
|
29
|
+
// o segmento seguinte é o slug do produto.
|
|
30
|
+
const categoryPath = matchedCategoryPath(segments, categories);
|
|
31
|
+
if (categoryPath.length === segments.length && categoryPath.length > 0) {
|
|
32
|
+
return { type: "catalog", categoryPath };
|
|
33
|
+
}
|
|
34
|
+
if (categoryPath.length > 0 && segments.length === categoryPath.length + 1) {
|
|
35
|
+
return { type: "product", slug: segments.at(-1) };
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// A URL canônica do Theme SDK preserva o caminho da categoria antes do slug
|
|
39
|
+
// do produto (por exemplo, /moveis/mesas/mesa-de-jantar).
|
|
40
|
+
if (segments.length > 1) {
|
|
41
|
+
return { type: "product", slug: segments.at(-1) };
|
|
42
|
+
}
|
|
12
43
|
if (segments.length === 1) return { type: "page", slug: segments[0] };
|
|
13
44
|
return { type: "not-found" };
|
|
14
45
|
}
|
|
@@ -6,6 +6,7 @@ import type {
|
|
|
6
6
|
ThemeHomeSection,
|
|
7
7
|
ThemeHomeSectionType,
|
|
8
8
|
ThemeEditorialItem,
|
|
9
|
+
NotFoundProps,
|
|
9
10
|
ThemeProduct,
|
|
10
11
|
ThemeRuntimeSdk,
|
|
11
12
|
ThemeSiteColors,
|
|
@@ -412,13 +413,15 @@ function dataRecords(data: Record<string, unknown>, field: string): Record<strin
|
|
|
412
413
|
}
|
|
413
414
|
|
|
414
415
|
function formatWhatsapp(value: string): string {
|
|
415
|
-
const
|
|
416
|
+
const rawDigits = value.replace(/\D/g, "");
|
|
417
|
+
const digits = (rawDigits.length > 11 && rawDigits.startsWith("55") ? rawDigits.slice(2) : rawDigits).slice(0, 11);
|
|
416
418
|
if (!digits) return "";
|
|
417
419
|
if (digits.length <= 2) return `(${digits}`;
|
|
418
420
|
const number = digits.slice(2);
|
|
419
|
-
|
|
421
|
+
const prefixLength = number.length > 8 ? 5 : 4;
|
|
422
|
+
return number.length <= prefixLength
|
|
420
423
|
? `(${digits.slice(0, 2)}) ${number}`
|
|
421
|
-
: `(${digits.slice(0, 2)}) ${number.slice(0,
|
|
424
|
+
: `(${digits.slice(0, 2)}) ${number.slice(0, prefixLength)}-${number.slice(prefixLength)}`;
|
|
422
425
|
}
|
|
423
426
|
|
|
424
427
|
function formatCep(value: string): string {
|
|
@@ -426,6 +429,21 @@ function formatCep(value: string): string {
|
|
|
426
429
|
return digits.length > 5 ? `${digits.slice(0, 5)}-${digits.slice(5)}` : digits;
|
|
427
430
|
}
|
|
428
431
|
|
|
432
|
+
function formatDocument(value: string, mask: string): string {
|
|
433
|
+
if (mask === "rg-br") {
|
|
434
|
+
const chars = value.toUpperCase().replace(/[^0-9X]/g, "").slice(0, 9);
|
|
435
|
+
return chars.replace(/^(\d{2})(\d{1,3})?(\d{1,3})?([0-9X])?$/, (_, a: string, b?: string, c?: string, d?: string) =>
|
|
436
|
+
[a, b, c].filter(Boolean).join(".") + (d ? `-${d}` : ""));
|
|
437
|
+
}
|
|
438
|
+
const digits = value.replace(/\D/g, "").slice(0, mask === "cpf-br" ? 11 : 14);
|
|
439
|
+
if (mask === "cpf-br" || mask === "cpf-cnpj-br" && digits.length <= 11) {
|
|
440
|
+
return digits.replace(/^(\d{3})(\d{1,3})?(\d{1,3})?(\d{1,2})?$/, (_, a: string, b?: string, c?: string, d?: string) =>
|
|
441
|
+
a + (b ? `.${b}` : "") + (c ? `.${c}` : "") + (d ? `-${d}` : ""));
|
|
442
|
+
}
|
|
443
|
+
return digits.replace(/^(\d{2})(\d{1,3})?(\d{1,3})?(\d{1,4})?(\d{1,2})?$/, (_, a: string, b?: string, c?: string, d?: string, e?: string) =>
|
|
444
|
+
a + (b ? `.${b}` : "") + (c ? `.${c}` : "") + (d ? `/${d}` : "") + (e ? `-${e}` : ""));
|
|
445
|
+
}
|
|
446
|
+
|
|
429
447
|
const addressFieldAliases = {
|
|
430
448
|
address: ["address", "endereco", "logradouro"],
|
|
431
449
|
district: ["district", "bairro"],
|
|
@@ -521,9 +539,15 @@ function ContactFormComponent({ section, sdk }: ThemeSectionRendererProps) {
|
|
|
521
539
|
setError("");
|
|
522
540
|
const form = new FormData(event.currentTarget);
|
|
523
541
|
const values: Record<string, string | boolean | string[]> = {};
|
|
542
|
+
const attachments: Record<string, File> = {};
|
|
524
543
|
for (const field of fields) {
|
|
525
544
|
const key = dataString(field, "key");
|
|
526
545
|
if (!key) continue;
|
|
546
|
+
if (dataString(field, "type") === "file") {
|
|
547
|
+
const file = form.get(key);
|
|
548
|
+
if (file instanceof File && file.size) attachments[key] = file;
|
|
549
|
+
continue;
|
|
550
|
+
}
|
|
527
551
|
if (dataString(field, "type") === "checkbox") {
|
|
528
552
|
values[key] = form.has(key);
|
|
529
553
|
continue;
|
|
@@ -536,6 +560,7 @@ function ContactFormComponent({ section, sdk }: ThemeSectionRendererProps) {
|
|
|
536
560
|
formKey: dataString(section.data, "componentKey", "contact-form"),
|
|
537
561
|
sectionId: section.id,
|
|
538
562
|
values,
|
|
563
|
+
...(Object.keys(attachments).length ? { attachments } : {}),
|
|
539
564
|
pathname: typeof window === "undefined" ? undefined : window.location.pathname,
|
|
540
565
|
});
|
|
541
566
|
event.currentTarget.reset();
|
|
@@ -566,6 +591,11 @@ function ContactFormComponent({ section, sdk }: ThemeSectionRendererProps) {
|
|
|
566
591
|
<input name={key} required={required} type="checkbox" value="true" />
|
|
567
592
|
<span>{label}{required && <small aria-hidden="true"> *</small>}</span>
|
|
568
593
|
</label>;
|
|
594
|
+
if (type === "file") return <label className="contact-form-wide" key={key}>
|
|
595
|
+
<span>{label}{required && <small aria-hidden="true"> *</small>}</span>
|
|
596
|
+
<input name={key} required={required} type="file" accept=".pdf,.jpg,.jpeg,.png,application/pdf,image/jpeg,image/png" />
|
|
597
|
+
<small>PDF, JPG ou PNG, até 4 MB no total.</small>
|
|
598
|
+
</label>;
|
|
569
599
|
if (type === "select") return <label key={key}>
|
|
570
600
|
<span>{label}{required && <small aria-hidden="true"> *</small>}</span>
|
|
571
601
|
<select name={key} required={required}>{dataRecords(field, "options").map((option) => <option key={dataString(option, "value")} value={dataString(option, "value")}>{dataString(option, "label", dataString(option, "value"))}</option>)}</select>
|
|
@@ -574,7 +604,18 @@ function ContactFormComponent({ section, sdk }: ThemeSectionRendererProps) {
|
|
|
574
604
|
<span>{label}{required && <small aria-hidden="true"> *</small>}</span>
|
|
575
605
|
{type === "textarea"
|
|
576
606
|
? <textarea name={key} placeholder={dataString(field, "placeholder")} required={required} rows={5} />
|
|
577
|
-
: <input
|
|
607
|
+
: <input
|
|
608
|
+
name={key}
|
|
609
|
+
placeholder={dataString(field, "placeholder")}
|
|
610
|
+
required={required}
|
|
611
|
+
type={["email", "tel", "url", "number"].includes(type) ? type : "text"}
|
|
612
|
+
maxLength={dataString(field, "mask") === "cep-br" ? 9 : dataString(field, "mask") === "cpf-br" ? 14 : dataString(field, "mask") === "cnpj-br" || dataString(field, "mask") === "cpf-cnpj-br" ? 18 : dataString(field, "mask") === "rg-br" ? 12 : undefined}
|
|
613
|
+
inputMode={["cep-br", "cpf-br", "cnpj-br", "cpf-cnpj-br"].includes(dataString(field, "mask")) ? "numeric" : undefined}
|
|
614
|
+
autoComplete={dataString(field, "mask") === "cep-br" ? "postal-code" : undefined}
|
|
615
|
+
pattern={dataString(field, "mask") === "whatsapp-br" ? "\\([1-9][0-9]\\) [0-9]{4,5}-[0-9]{4}" : undefined}
|
|
616
|
+
title={dataString(field, "mask") === "whatsapp-br" ? "Informe o DDD e um telefone com 8 ou 9 dígitos." : undefined}
|
|
617
|
+
onInput={dataString(field, "mask") === "whatsapp-br" ? (event) => { event.currentTarget.value = formatWhatsapp(event.currentTarget.value); } : dataString(field, "mask") === "cep-br" ? (event) => { event.currentTarget.value = formatCep(event.currentTarget.value); void searchCep(event.currentTarget.value); } : ["cpf-br", "cnpj-br", "cpf-cnpj-br", "rg-br"].includes(dataString(field, "mask")) ? (event) => { event.currentTarget.value = formatDocument(event.currentTarget.value, dataString(field, "mask")); } : undefined}
|
|
618
|
+
/>}
|
|
578
619
|
</label>;
|
|
579
620
|
})}
|
|
580
621
|
<div className="contact-form-wide">
|
|
@@ -784,6 +825,17 @@ function ProductPage({ product, context, adapters }: {
|
|
|
784
825
|
</div></main>;
|
|
785
826
|
}
|
|
786
827
|
|
|
828
|
+
/** Fallback seguro para consumidores que usam um tema sem componente NotFound. */
|
|
829
|
+
export function DefaultNotFound({ homeHref = "/" }: NotFoundProps) {
|
|
830
|
+
return <main className="not-found-page">
|
|
831
|
+
<div className="not-found-card">
|
|
832
|
+
<span>404</span>
|
|
833
|
+
<h1>Conteúdo não encontrado</h1>
|
|
834
|
+
<a className="button button-primary" href={homeHref}>Voltar ao início</a>
|
|
835
|
+
</div>
|
|
836
|
+
</main>;
|
|
837
|
+
}
|
|
838
|
+
|
|
787
839
|
function RouteContent({ route, context, adapters, home, sdk }: {
|
|
788
840
|
route: ThemeRoute;
|
|
789
841
|
context: ThemeContext;
|
|
@@ -793,7 +845,7 @@ function RouteContent({ route, context, adapters, home, sdk }: {
|
|
|
793
845
|
}) {
|
|
794
846
|
if (route.type === "home") return home;
|
|
795
847
|
if (route.type === "loading") return <main className="not-found-page"><div className="not-found-card"><span>Carregando</span><h1>Buscando conteúdo da loja</h1></div></main>;
|
|
796
|
-
if (route.type === "not-found") return <
|
|
848
|
+
if (route.type === "not-found") return <DefaultNotFound homeHref="/" />;
|
|
797
849
|
if (route.type === "catalog") return <CatalogPage adapters={adapters} context={context} route={route} />;
|
|
798
850
|
if (route.type === "product") return <ProductPage adapters={adapters} context={context} product={route.product} />;
|
|
799
851
|
if (route.type === "editorial-list") return <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"><EditorialCards adapters={adapters} basePath={route.basePath} items={route.items} /></div></section></main>;
|
|
@@ -17,7 +17,7 @@ export type {
|
|
|
17
17
|
ThemeRuntimeAdapters,
|
|
18
18
|
} from "@nuvler/theme-sdk";
|
|
19
19
|
|
|
20
|
-
export { DefaultTheme, defaultSectionRegistry } from "./default-theme.js";
|
|
20
|
+
export { DefaultNotFound, DefaultTheme, defaultSectionRegistry } from "./default-theme.js";
|
|
21
21
|
export type {
|
|
22
22
|
ThemeSectionRenderer,
|
|
23
23
|
ThemeSectionRendererProps,
|