@nuvler/cli 0.5.3 → 0.5.5

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 (37) hide show
  1. package/README.md +2 -2
  2. package/dist/api/client.js +3 -0
  3. package/dist/api/client.js.map +1 -1
  4. package/dist/api/theme-context.js +6 -1
  5. package/dist/api/theme-context.js.map +1 -1
  6. package/dist/commands/theme/create.js +1 -1
  7. package/dist/migrate/generator.js +32 -9
  8. package/dist/migrate/generator.js.map +1 -1
  9. package/dist/nuvler.js +101 -14
  10. package/dist/nuvler.js.map +1 -1
  11. package/dist/templates/nuvler-atelier/nuvler.theme.json +2 -2
  12. package/dist/templates/nuvler-atelier/package.json +3 -3
  13. package/dist/templates/nuvler-atelier/src/definition.tsx +42 -6
  14. package/dist/templates/nuvler-atelier/src/theme.css +20 -0
  15. package/dist/templates/nuvler-atelier/src/theme.tsx +1 -1
  16. package/dist/templates/nuvler-default/nuvler.theme.json +2 -2
  17. package/dist/templates/nuvler-default/package.json +2 -2
  18. package/dist/templates/nuvler-default/src/banner-carousel.tsx +19 -15
  19. package/dist/templates/nuvler-default/src/header-interactions.tsx +4 -4
  20. package/dist/templates/nuvler-default/src/header.tsx +2 -2
  21. package/dist/templates/nuvler-default/src/home.tsx +5 -3
  22. package/dist/templates/nuvler-default/src/server-shell.tsx +4 -1
  23. package/dist/templates/nuvler-default/src/theme-component.tsx +2 -2
  24. package/dist/templates/nuvler-default/src/theme.css +9 -2
  25. package/dist/templates/starter/README.md +5 -0
  26. package/dist/templates/starter/nuvler.theme.json +1 -1
  27. package/dist/templates/starter/package.json +2 -2
  28. package/dist/templates/starter/src/definition.tsx +30 -4
  29. package/dist/templates/starter/src/theme.css +13 -2
  30. package/dist/templates/starter/src/theme.tsx +1 -1
  31. package/package.json +3 -3
  32. package/preview-host/package.json +1 -1
  33. package/preview-host/src/main.tsx +31 -11
  34. package/preview-host/src/preview-path.d.mts +4 -0
  35. package/preview-host/src/preview-path.mjs +14 -0
  36. package/preview-host/src/public-preview-url.mjs +1 -1
  37. package/preview-host/vendor/theme-runtime/default-theme.tsx +39 -13
@@ -1,12 +1,23 @@
1
1
  * { box-sizing: border-box; }
2
2
  body { margin: 0; }
3
3
  .nuvler-starter-theme { min-height: 100vh; background: var(--theme-background); color: var(--theme-text); font-family: Inter, system-ui, sans-serif; }
4
- .theme-header, .theme-footer, .theme-section, .theme-hero { width: min(calc(100% - 32px), var(--theme-container)); margin-inline: auto; }
4
+ .theme-header, .theme-footer, .theme-section, .theme-hero, .theme-banner { width: min(calc(100% - 32px), var(--theme-container)); margin-inline: auto; }
5
5
  .theme-header { min-height: 72px; display: flex; align-items: center; justify-content: space-between; gap: 24px; background: var(--theme-header-background); color: var(--theme-header-text); }
6
6
  .theme-brand { color: var(--theme-primary); font-size: 20px; font-weight: 800; text-decoration: none; }
7
+ .theme-navigation { display: flex; align-items: center; gap: 16px; }
8
+ .theme-navigation a { color: inherit; text-decoration: none; }
9
+ .theme-header-button { border-radius: var(--theme-radius); padding: 12px 18px; font-weight: 800; text-decoration: none; white-space: nowrap; }
7
10
  .theme-header form { display: flex; gap: 8px; }
8
11
  .theme-header input { min-width: 260px; border: 1px solid var(--theme-border); border-radius: var(--theme-radius); background: var(--theme-surface); color: var(--theme-header-text); padding: 11px 14px; }
9
12
  .theme-header button, .theme-product-detail button { border: 0; border-radius: var(--theme-radius); background: var(--theme-primary); color: var(--theme-primary-text); padding: 12px 18px; font-weight: 700; }
13
+ .theme-banner { position: relative; height: var(--theme-banner-height); overflow: hidden; border-radius: var(--theme-radius); background: var(--theme-surface-alt); }
14
+ .theme-banner picture, .theme-banner img { display: block; width: 100%; height: 100%; }
15
+ .theme-banner img { object-fit: cover; }
16
+ .theme-banner[data-fit="CONTAIN"] img { object-fit: contain; }
17
+ .theme-banner[data-fit="NATURAL"] { height: auto; }
18
+ .theme-banner[data-fit="NATURAL"] picture, .theme-banner[data-fit="NATURAL"] img { height: auto; }
19
+ .theme-banner-content { position: absolute; inset: auto 0 0; padding: clamp(24px, 5vw, 56px); color: #fff; background: linear-gradient(transparent, rgba(0, 0, 0, .72)); }
20
+ .theme-banner-content a { display: inline-block; border-radius: var(--theme-radius); background: var(--theme-primary); color: var(--theme-primary-text); padding: 12px 18px; font-weight: 800; text-decoration: none; }
10
21
  .theme-hero { margin-block: 32px; border-radius: calc(var(--theme-radius) * 1.5); background: var(--theme-primary); color: var(--theme-primary-text); padding: clamp(40px, 8vw, 96px); }
11
22
  .theme-hero span { color: var(--theme-accent); font-size: 12px; font-weight: 800; text-transform: uppercase; }
12
23
  .theme-hero h1 { max-width: 760px; margin: 12px 0; font-size: clamp(40px, 7vw, 80px); line-height: .95; }
@@ -18,4 +29,4 @@ body { margin: 0; }
18
29
  .theme-products span { margin-top: 8px; color: var(--theme-text-muted); font-size: 13px; }
19
30
  .theme-product-detail { display: grid; gap: 32px; grid-template-columns: 1fr auto; align-items: end; border-radius: var(--theme-radius); background: var(--theme-surface); padding: clamp(24px, 5vw, 56px); }
20
31
  .theme-footer { display: flex; justify-content: space-between; border-top: 1px solid var(--theme-border); background: var(--theme-footer-background); color: var(--theme-footer-text); padding: 32px 20px; }
21
- @media (max-width: 700px) { .theme-header { align-items: stretch; flex-direction: column; padding-block: 16px; } .theme-header form, .theme-header input { width: 100%; min-width: 0; } .theme-product-detail { grid-template-columns: 1fr; } }
32
+ @media (max-width: 700px) { .theme-header { align-items: stretch; flex-direction: column; padding-block: 16px; } .theme-navigation { overflow-x: auto; } .theme-header form, .theme-header input { width: 100%; min-width: 0; } .theme-banner:not([data-fit="NATURAL"]) { height: var(--theme-banner-mobile-height); } .theme-product-detail { grid-template-columns: 1fr; } }
@@ -41,5 +41,5 @@ export default function Theme({ context, route = { type: "home" }, sdk }: Nuvler
41
41
  else if (route.type === "editorial-detail") content = <main className="theme-section"><h1>{route.item.title}</h1><p>{route.item.description}</p></main>;
42
42
  else content = <main className="theme-section"><h1>{route.type === "loading" ? "Carregando…" : route.type === "page" ? route.title : "Conteúdo não encontrado"}</h1></main>;
43
43
 
44
- return <div className="nuvler-starter-theme" style={style}><Header site={site} categories={context.navigation.categories} pages={context.navigation.pages} template={themeDefinition.template} /><div>{content}</div><Footer site={site} pages={context.navigation.pages} template={themeDefinition.template} /></div>;
44
+ return <div className="nuvler-starter-theme" style={style}><Header site={site} categories={context.navigation.categories} pages={context.navigation.pages} menu={context.navigation.menu} headerButton={context.navigation.headerButton} template={themeDefinition.template} /><div>{content}</div><Footer site={site} pages={context.navigation.pages} template={themeDefinition.template} /></div>;
45
45
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nuvler/cli",
3
- "version": "0.5.3",
3
+ "version": "0.5.5",
4
4
  "description": "CLI oficial para criação, validação, preview e empacotamento de temas Nuvler",
5
5
  "type": "module",
6
6
  "bin": {
@@ -20,8 +20,8 @@
20
20
  "typecheck": "tsc -p tsconfig.json --noEmit"
21
21
  },
22
22
  "dependencies": {
23
- "@nuvler/theme-schema": "^1.3.0",
24
- "@nuvler/theme-sdk": "^1.3.1",
23
+ "@nuvler/theme-schema": "^1.3.2",
24
+ "@nuvler/theme-sdk": "^1.3.3",
25
25
  "@vitejs/plugin-react": "^6.0.5",
26
26
  "commander": "^15.0.0",
27
27
  "react": "19.2.8",
@@ -10,7 +10,7 @@
10
10
  "typecheck": "tsc -p tsconfig.json --noEmit"
11
11
  },
12
12
  "dependencies": {
13
- "@nuvler/theme-sdk": "1.3.1",
13
+ "@nuvler/theme-sdk": "1.3.3",
14
14
  "react": "19.2.8",
15
15
  "react-dom": "19.2.8"
16
16
  },
@@ -11,6 +11,11 @@ import type {
11
11
  import type { ThemePagination, ThemeProduct, ThemeRuntimeSdk } from "@nuvler/theme-sdk";
12
12
  import ActiveTheme from "virtual:nuvler-active-theme";
13
13
  import context from "virtual:nuvler-theme-context";
14
+ import { classifyPreviewPath } from "./preview-path.mjs";
15
+
16
+ class PreviewHttpError extends Error {
17
+ constructor(public status: number) { super(`HTTP ${status}`); }
18
+ }
14
19
 
15
20
  function PreviewImage({ image, fallbackAlt, className }: ThemeImageProps) {
16
21
  if (!image?.url) return <span className={`store-image-placeholder theme-image-placeholder ${className ?? ""}`} aria-hidden="true"><span>N</span></span>;
@@ -68,7 +73,7 @@ async function previewApi<T>(path: string): Promise<T> {
68
73
  const response = await fetch(`/__nuvler-api/${path.replace(/^\/+/, "")}`, {
69
74
  headers: { accept: "application/json" },
70
75
  });
71
- if (!response.ok) throw new Error(`HTTP ${response.status}`);
76
+ if (!response.ok) throw new PreviewHttpError(response.status);
72
77
  return response.json() as Promise<T>;
73
78
  }
74
79
 
@@ -93,6 +98,7 @@ function routeFromLocalData(url: URL): ThemeRoute | null {
93
98
  function PreviewApp() {
94
99
  const [route, setRoute] = useState<ThemeRoute>({ type: "loading", pathname: window.location.pathname });
95
100
  const requestId = useRef(0);
101
+ const [routeError, setRouteError] = useState<string | null>(null);
96
102
 
97
103
  useEffect(() => {
98
104
  const favicon = document.querySelector<HTMLLinkElement>('link[rel~="icon"]');
@@ -101,26 +107,26 @@ function PreviewApp() {
101
107
 
102
108
  const loadRoute = useCallback(async (url: URL) => {
103
109
  const currentRequest = ++requestId.current;
110
+ setRouteError(null);
104
111
  const localRoute = routeFromLocalData(url);
105
112
  if (localRoute) { setRoute(localRoute); return; }
106
113
  setRoute({ type: "loading", pathname: url.pathname });
107
114
  try {
108
- if (url.pathname.startsWith("/produto/")) {
109
- const slug = decodeURIComponent(url.pathname.slice("/produto/".length));
115
+ const target = classifyPreviewPath(url.pathname);
116
+ if (target.type === "product") {
117
+ const slug = target.slug;
110
118
  const product = normalizeProduct(await previewApi<unknown>(`products/${encodeURIComponent(slug)}`));
111
119
  if (currentRequest === requestId.current) setRoute({ type: "product", product });
112
120
  return;
113
121
  }
114
- if (url.pathname.split("/").filter(Boolean).length === 1) {
115
- const slug = decodeURIComponent(url.pathname.slice(1));
122
+ if (target.type === "page") {
123
+ const slug = target.slug;
116
124
  const page = await previewApi<{ title: string; slug: string; content: { schemaVersion: 1; time?: number; version?: string; blocks: Array<{ id?: string; type: string; data: Record<string, unknown> }> } }>(`pages/${encodeURIComponent(slug)}`);
117
125
  if (currentRequest === requestId.current) setRoute({ type: "page", title: page.title, slug: page.slug, content: page.content });
118
126
  return;
119
127
  }
120
- if (url.pathname === "/produtos" || url.pathname.startsWith("/categoria/")) {
121
- const categoryPath = url.pathname.startsWith("/categoria/")
122
- ? url.pathname.slice("/categoria/".length).split("/").filter(Boolean).map(decodeURIComponent)
123
- : [];
128
+ if (target.type === "catalog") {
129
+ const categoryPath = target.categoryPath;
124
130
  const params = new URLSearchParams();
125
131
  const page = Math.max(1, Number(url.searchParams.get("pagina")) || 1);
126
132
  const search = url.searchParams.get("busca")?.trim() || "";
@@ -139,8 +145,15 @@ function PreviewApp() {
139
145
  return;
140
146
  }
141
147
  setRoute({ type: "not-found", pathname: url.pathname });
142
- } catch {
143
- if (currentRequest === requestId.current) setRoute({ type: "not-found", pathname: url.pathname });
148
+ } catch (error) {
149
+ if (currentRequest !== requestId.current) return;
150
+ if (error instanceof PreviewHttpError && error.status === 404) {
151
+ setRoute({ type: "not-found", pathname: url.pathname });
152
+ } else {
153
+ setRouteError(error instanceof PreviewHttpError
154
+ ? `A API respondeu HTTP ${error.status}. Confira a conexão e a configuração do preview.`
155
+ : "Não foi possível carregar o conteúdo. Confira a conexão com a API.");
156
+ }
144
157
  }
145
158
  }, []);
146
159
 
@@ -199,6 +212,13 @@ function PreviewApp() {
199
212
  },
200
213
  }), [loadRoute]);
201
214
 
215
+ if (routeError) return <main role="alert" style={{ padding: "2rem" }}>
216
+ <h1>Não foi possível carregar esta página</h1>
217
+ <p>{routeError}</p>
218
+ <button onClick={() => void loadRoute(new URL(window.location.href))}>Tentar novamente</button>
219
+ <a href="/">Voltar ao início</a>
220
+ </main>;
221
+
202
222
  return <>
203
223
  <ActiveTheme adapters={adapters} context={context} route={route} sdk={sdk} />
204
224
  <PlatformBrand routeKey={`${route.type}:${window.location.pathname}`} />
@@ -0,0 +1,4 @@
1
+ export function classifyPreviewPath(pathname: string):
2
+ | { type: "catalog"; categoryPath: string[] }
3
+ | { type: "page" | "product"; slug: string }
4
+ | { type: "not-found" };
@@ -0,0 +1,14 @@
1
+ export function classifyPreviewPath(pathname) {
2
+ const segments = pathname.split("/").filter(Boolean).map(decodeURIComponent);
3
+ if (segments.length === 1 && segments[0] === "produtos") {
4
+ return { type: "catalog", categoryPath: [] };
5
+ }
6
+ if (segments[0] === "categoria" && segments.length > 1) {
7
+ return { type: "catalog", categoryPath: segments.slice(1) };
8
+ }
9
+ if (segments[0] === "produto" && segments.length === 2) {
10
+ return { type: "product", slug: segments[1] };
11
+ }
12
+ if (segments.length === 1) return { type: "page", slug: segments[0] };
13
+ return { type: "not-found" };
14
+ }
@@ -37,7 +37,7 @@ export function resolvePublicPreviewUrl(requestUrl, apiUrl, store) {
37
37
  }
38
38
 
39
39
  const allowed = (
40
- (segments[0] === "products" && segments.length <= 2)
40
+ (["products", "pages"].includes(segments[0]) && segments.length <= 2)
41
41
  || (segments.length === 1 && singleResourcePaths.has(segments[0] ?? ""))
42
42
  );
43
43
  if (!allowed) return null;
@@ -1,6 +1,7 @@
1
1
  import { useEffect, useMemo, useRef, useState, type CSSProperties, type FormEvent, type ReactNode } from "react";
2
2
  import type {
3
3
  ThemeCategory,
4
+ ThemeBannerCarouselData,
4
5
  ThemeContext,
5
6
  ThemeHomeSection,
6
7
  ThemeHomeSectionType,
@@ -171,6 +172,8 @@ function Header({ context, adapters }: Omit<DefaultThemeProps, "children">) {
171
172
  const name = settings?.siteName || context.store.name;
172
173
  const categories = context.navigation.categories;
173
174
  const extraLinks = moduleLinks(context);
175
+ const configuredLinks = context.navigation.menu?.length ? context.navigation.menu : null;
176
+ const headerButton = context.navigation.headerButton;
174
177
 
175
178
  return (
176
179
  <>
@@ -201,7 +204,17 @@ function Header({ context, adapters }: Omit<DefaultThemeProps, "children">) {
201
204
  <strong>{settings?.description?.trim() || template.announcement}</strong>
202
205
  </span>
203
206
  </div>
204
- {extraLinks.length > 0 && (
207
+ {headerButton?.enabled && (
208
+ <Link
209
+ className="header-highlight-link"
210
+ href={headerButton.href}
211
+ rel={headerButton.openInNewTab ? "noreferrer" : undefined}
212
+ target={headerButton.openInNewTab ? "_blank" : undefined}
213
+ >
214
+ <span style={{ backgroundColor: headerButton.backgroundColor, color: headerButton.textColor }}>{headerButton.label}</span>
215
+ </Link>
216
+ )}
217
+ {!configuredLinks && extraLinks.length > 0 && (
205
218
  <div className="header-actions">
206
219
  <details className="header-more-menu">
207
220
  <summary>Mais <span aria-hidden="true">⌄</span></summary>
@@ -212,7 +225,15 @@ function Header({ context, adapters }: Omit<DefaultThemeProps, "children">) {
212
225
  </div>
213
226
  )}
214
227
  </div>
215
- {categories.length > 0 ? (
228
+ {configuredLinks ? (
229
+ <div className="primary-nav-shell">
230
+ <nav className="store-container main-nav" aria-label="Navegação principal">
231
+ {configuredLinks.map((item) => (
232
+ <Link href={item.href} key={item.key} rel={item.openInNewTab ? "noreferrer" : undefined} target={item.openInNewTab ? "_blank" : undefined}>{item.label}</Link>
233
+ ))}
234
+ </nav>
235
+ </div>
236
+ ) : categories.length > 0 ? (
216
237
  <nav className="category-nav" aria-label="Categorias de produtos">
217
238
  <div className="store-container category-nav-inner">
218
239
  <details className="category-nav-all">
@@ -332,19 +353,24 @@ function HeroSection({ section, context, adapters }: ThemeSectionRendererProps)
332
353
  }
333
354
 
334
355
  function BannerSection({ section, adapters }: ThemeSectionRendererProps) {
335
- const { Link, Image } = adapters;
336
- const banners = Array.isArray(section.data.banners)
337
- ? section.data.banners.filter((item): item is Record<string, unknown> => Boolean(item) && typeof item === "object")
338
- : [];
339
- const banner = banners[0];
340
- if (!banner || typeof banner.imageUrl !== "string") return null;
356
+ const { Link } = adapters;
357
+ const data = section.data as ThemeBannerCarouselData;
358
+ const banner = data.banners?.find((item) => Boolean(item.image?.url || item.imageUrl));
359
+ const desktopUrl = banner?.image?.url || banner?.imageUrl || "";
360
+ const mobileUrl = banner?.mobileImage?.url || banner?.mobileImageUrl || "";
361
+ if (!banner || !desktopUrl) return null;
362
+ const natural = data.imageFit === "NATURAL";
363
+ const fit = data.imageFit === "CONTAIN" ? "contain" : "cover";
341
364
  return (
342
- <section className="banner-carousel"><div className="banner-track"><article className="banner-slide">
343
- <Image image={{ url: banner.imageUrl, alt: typeof banner.imageAlt === "string" ? banner.imageAlt : "Banner", width: null, height: null }} fallbackAlt="Banner" />
365
+ <section className="banner-carousel" data-image-fit={data.imageFit || "COVER"} style={{ "--banner-desktop-height": `${data.desktopHeight || 520}px`, "--banner-mobile-height": `${data.mobileHeight || 360}px` } as CSSProperties}><div className="banner-track"><article className="banner-slide">
366
+ <picture className="banner-responsive-media">
367
+ {mobileUrl && <source media="(max-width: 700px)" srcSet={mobileUrl} />}
368
+ <img src={desktopUrl} alt={banner.imageAlt || banner.image?.alt || banner.title || "Banner"} style={{ display: "block", height: natural ? "auto" : "100%", objectFit: fit, width: "100%" }} />
369
+ </picture>
344
370
  <div className="banner-overlay"><div className="store-container"><div className="banner-copy">
345
- {typeof banner.title === "string" && <h2>{banner.title}</h2>}
346
- {typeof banner.description === "string" && <p>{banner.description}</p>}
347
- {typeof banner.buttonLabel === "string" && typeof banner.buttonUrl === "string" && <Link className="button button-primary" href={banner.buttonUrl}>{banner.buttonLabel}</Link>}
371
+ {banner.title && <h2>{banner.title}</h2>}
372
+ {banner.description && <p>{banner.description}</p>}
373
+ {banner.buttonLabel && banner.buttonUrl && <Link className="button button-primary" href={banner.buttonUrl}>{banner.buttonLabel}</Link>}
348
374
  </div></div></div>
349
375
  </article></div></section>
350
376
  );