@nuvler/cli 0.5.6 → 0.5.7

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 (33) hide show
  1. package/dist/nuvler.js +49 -9
  2. package/dist/nuvler.js.map +1 -1
  3. package/dist/preview/launcher.js +4 -3
  4. package/dist/preview/launcher.js.map +1 -1
  5. package/dist/templates/nuvler-default/nuvler.theme.json +150 -7
  6. package/dist/templates/nuvler-default/package.json +1 -1
  7. package/dist/templates/nuvler-default/src/assets/not-found-cloud.png +0 -0
  8. package/dist/templates/nuvler-default/src/assets/not-found-cloud.svg +131 -0
  9. package/dist/templates/nuvler-default/src/assets/not-found-illustration.png +0 -0
  10. package/dist/templates/nuvler-default/src/banner-carousel.tsx +11 -0
  11. package/dist/templates/nuvler-default/src/carousel-frame.tsx +8 -4
  12. package/dist/templates/nuvler-default/src/definition.ts +2 -1
  13. package/dist/templates/nuvler-default/src/footer.tsx +4 -2
  14. package/dist/templates/nuvler-default/src/header-interactions.tsx +30 -17
  15. package/dist/templates/nuvler-default/src/header.tsx +25 -10
  16. package/dist/templates/nuvler-default/src/home.tsx +37 -25
  17. package/dist/templates/nuvler-default/src/index.ts +2 -0
  18. package/dist/templates/nuvler-default/src/not-found.tsx +29 -0
  19. package/dist/templates/nuvler-default/src/product-carousel.tsx +1 -1
  20. package/dist/templates/nuvler-default/src/product-detail-interactive.tsx +7 -1
  21. package/dist/templates/nuvler-default/src/product-detail.tsx +27 -5
  22. package/dist/templates/nuvler-default/src/products.tsx +13 -2
  23. package/dist/templates/nuvler-default/src/server-shell.tsx +5 -5
  24. package/dist/templates/nuvler-default/src/styles.d.ts +15 -0
  25. package/dist/templates/nuvler-default/src/theme-component.tsx +27 -8
  26. package/dist/templates/nuvler-default/src/theme-config.ts +12 -12
  27. package/dist/templates/nuvler-default/src/theme.css +1724 -169
  28. package/package.json +1 -1
  29. package/preview-host/src/main.tsx +16 -1
  30. package/preview-host/src/preview-path.d.mts +4 -1
  31. package/preview-host/src/preview-path.mjs +32 -1
  32. package/preview-host/vendor/theme-runtime/default-theme.tsx +41 -2
  33. package/preview-host/vendor/theme-runtime/index.ts +1 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nuvler/cli",
3
- "version": "0.5.6",
3
+ "version": "0.5.7",
4
4
  "description": "CLI oficial para criação, validação, preview e empacotamento de temas Nuvler",
5
5
  "type": "module",
6
6
  "bin": {
@@ -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(pathname: string):
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
- export function classifyPreviewPath(pathname) {
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,
@@ -426,6 +427,21 @@ function formatCep(value: string): string {
426
427
  return digits.length > 5 ? `${digits.slice(0, 5)}-${digits.slice(5)}` : digits;
427
428
  }
428
429
 
430
+ function formatDocument(value: string, mask: string): string {
431
+ if (mask === "rg-br") {
432
+ const chars = value.toUpperCase().replace(/[^0-9X]/g, "").slice(0, 9);
433
+ return chars.replace(/^(\d{2})(\d{1,3})?(\d{1,3})?([0-9X])?$/, (_, a: string, b?: string, c?: string, d?: string) =>
434
+ [a, b, c].filter(Boolean).join(".") + (d ? `-${d}` : ""));
435
+ }
436
+ const digits = value.replace(/\D/g, "").slice(0, mask === "cpf-br" ? 11 : 14);
437
+ if (mask === "cpf-br" || mask === "cpf-cnpj-br" && digits.length <= 11) {
438
+ return digits.replace(/^(\d{3})(\d{1,3})?(\d{1,3})?(\d{1,2})?$/, (_, a: string, b?: string, c?: string, d?: string) =>
439
+ a + (b ? `.${b}` : "") + (c ? `.${c}` : "") + (d ? `-${d}` : ""));
440
+ }
441
+ 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) =>
442
+ a + (b ? `.${b}` : "") + (c ? `.${c}` : "") + (d ? `/${d}` : "") + (e ? `-${e}` : ""));
443
+ }
444
+
429
445
  const addressFieldAliases = {
430
446
  address: ["address", "endereco", "logradouro"],
431
447
  district: ["district", "bairro"],
@@ -521,9 +537,15 @@ function ContactFormComponent({ section, sdk }: ThemeSectionRendererProps) {
521
537
  setError("");
522
538
  const form = new FormData(event.currentTarget);
523
539
  const values: Record<string, string | boolean | string[]> = {};
540
+ const attachments: Record<string, File> = {};
524
541
  for (const field of fields) {
525
542
  const key = dataString(field, "key");
526
543
  if (!key) continue;
544
+ if (dataString(field, "type") === "file") {
545
+ const file = form.get(key);
546
+ if (file instanceof File && file.size) attachments[key] = file;
547
+ continue;
548
+ }
527
549
  if (dataString(field, "type") === "checkbox") {
528
550
  values[key] = form.has(key);
529
551
  continue;
@@ -536,6 +558,7 @@ function ContactFormComponent({ section, sdk }: ThemeSectionRendererProps) {
536
558
  formKey: dataString(section.data, "componentKey", "contact-form"),
537
559
  sectionId: section.id,
538
560
  values,
561
+ ...(Object.keys(attachments).length ? { attachments } : {}),
539
562
  pathname: typeof window === "undefined" ? undefined : window.location.pathname,
540
563
  });
541
564
  event.currentTarget.reset();
@@ -566,6 +589,11 @@ function ContactFormComponent({ section, sdk }: ThemeSectionRendererProps) {
566
589
  <input name={key} required={required} type="checkbox" value="true" />
567
590
  <span>{label}{required && <small aria-hidden="true"> *</small>}</span>
568
591
  </label>;
592
+ if (type === "file") return <label className="contact-form-wide" key={key}>
593
+ <span>{label}{required && <small aria-hidden="true"> *</small>}</span>
594
+ <input name={key} required={required} type="file" accept=".pdf,.jpg,.jpeg,.png,application/pdf,image/jpeg,image/png" />
595
+ <small>PDF, JPG ou PNG, até 4 MB no total.</small>
596
+ </label>;
569
597
  if (type === "select") return <label key={key}>
570
598
  <span>{label}{required && <small aria-hidden="true"> *</small>}</span>
571
599
  <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 +602,7 @@ function ContactFormComponent({ section, sdk }: ThemeSectionRendererProps) {
574
602
  <span>{label}{required && <small aria-hidden="true"> *</small>}</span>
575
603
  {type === "textarea"
576
604
  ? <textarea name={key} placeholder={dataString(field, "placeholder")} required={required} rows={5} />
577
- : <input name={key} placeholder={dataString(field, "placeholder")} required={required} type={["email", "tel", "url", "number"].includes(type) ? type : "text"} maxLength={dataString(field, "mask") === "whatsapp-br" ? 15 : dataString(field, "mask") === "cep-br" ? 9 : undefined} inputMode={dataString(field, "mask") === "cep-br" ? "numeric" : undefined} autoComplete={dataString(field, "mask") === "cep-br" ? "postal-code" : undefined} 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); } : undefined} />}
605
+ : <input name={key} placeholder={dataString(field, "placeholder")} required={required} type={["email", "tel", "url", "number"].includes(type) ? type : "text"} maxLength={dataString(field, "mask") === "whatsapp-br" ? 15 : 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} inputMode={["cep-br", "cpf-br", "cnpj-br", "cpf-cnpj-br"].includes(dataString(field, "mask")) ? "numeric" : undefined} autoComplete={dataString(field, "mask") === "cep-br" ? "postal-code" : undefined} 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} />}
578
606
  </label>;
579
607
  })}
580
608
  <div className="contact-form-wide">
@@ -784,6 +812,17 @@ function ProductPage({ product, context, adapters }: {
784
812
  </div></main>;
785
813
  }
786
814
 
815
+ /** Fallback seguro para consumidores que usam um tema sem componente NotFound. */
816
+ export function DefaultNotFound({ homeHref = "/" }: NotFoundProps) {
817
+ return <main className="not-found-page">
818
+ <div className="not-found-card">
819
+ <span>404</span>
820
+ <h1>Conteúdo não encontrado</h1>
821
+ <a className="button button-primary" href={homeHref}>Voltar ao início</a>
822
+ </div>
823
+ </main>;
824
+ }
825
+
787
826
  function RouteContent({ route, context, adapters, home, sdk }: {
788
827
  route: ThemeRoute;
789
828
  context: ThemeContext;
@@ -793,7 +832,7 @@ function RouteContent({ route, context, adapters, home, sdk }: {
793
832
  }) {
794
833
  if (route.type === "home") return home;
795
834
  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 <main className="not-found-page"><div className="not-found-card"><span>404</span><h1>Conteúdo não encontrado</h1><adapters.Link className="button button-primary" href="/">Voltar ao início</adapters.Link></div></main>;
835
+ if (route.type === "not-found") return <DefaultNotFound homeHref="/" />;
797
836
  if (route.type === "catalog") return <CatalogPage adapters={adapters} context={context} route={route} />;
798
837
  if (route.type === "product") return <ProductPage adapters={adapters} context={context} product={route.product} />;
799
838
  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,