@nuvler/cli 0.5.4 → 0.5.6
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/README.md +2 -2
- package/dist/api/client.js +3 -0
- package/dist/api/client.js.map +1 -1
- package/dist/api/theme-context.js +6 -1
- package/dist/api/theme-context.js.map +1 -1
- package/dist/commands/theme/create.js +1 -1
- package/dist/migrate/generator.js +32 -9
- package/dist/migrate/generator.js.map +1 -1
- package/dist/nuvler.js +100 -14
- package/dist/nuvler.js.map +1 -1
- package/dist/templates/nuvler-atelier/nuvler.theme.json +2 -2
- package/dist/templates/nuvler-atelier/package.json +3 -3
- package/dist/templates/nuvler-atelier/src/definition.tsx +42 -6
- package/dist/templates/nuvler-atelier/src/theme.css +20 -0
- package/dist/templates/nuvler-atelier/src/theme.tsx +1 -1
- package/dist/templates/nuvler-default/nuvler.theme.json +2 -2
- package/dist/templates/nuvler-default/package.json +2 -2
- package/dist/templates/nuvler-default/src/banner-carousel.tsx +19 -15
- package/dist/templates/nuvler-default/src/header-interactions.tsx +4 -4
- package/dist/templates/nuvler-default/src/header.tsx +2 -2
- package/dist/templates/nuvler-default/src/home.tsx +5 -3
- package/dist/templates/nuvler-default/src/server-shell.tsx +4 -1
- package/dist/templates/nuvler-default/src/theme-component.tsx +2 -2
- package/dist/templates/nuvler-default/src/theme.css +9 -2
- package/dist/templates/starter/README.md +5 -0
- package/dist/templates/starter/nuvler.theme.json +1 -1
- package/dist/templates/starter/package.json +2 -2
- package/dist/templates/starter/src/definition.tsx +30 -4
- package/dist/templates/starter/src/theme.css +13 -2
- package/dist/templates/starter/src/theme.tsx +1 -1
- package/package.json +3 -3
- package/preview-host/package.json +1 -1
- package/preview-host/vendor/theme-runtime/default-theme.tsx +127 -15
|
@@ -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
|
+
"version": "0.5.6",
|
|
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.
|
|
24
|
-
"@nuvler/theme-sdk": "^1.3.
|
|
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",
|
|
@@ -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
|
-
{
|
|
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
|
-
{
|
|
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
|
|
336
|
-
const
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
const
|
|
340
|
-
if (!banner ||
|
|
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
|
-
<
|
|
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
|
-
{
|
|
346
|
-
{
|
|
347
|
-
{
|
|
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
|
);
|
|
@@ -395,12 +421,94 @@ function formatWhatsapp(value: string): string {
|
|
|
395
421
|
: `(${digits.slice(0, 2)}) ${number.slice(0, 5)}-${number.slice(5)}`;
|
|
396
422
|
}
|
|
397
423
|
|
|
424
|
+
function formatCep(value: string): string {
|
|
425
|
+
const digits = value.replace(/\D/g, "").slice(0, 8);
|
|
426
|
+
return digits.length > 5 ? `${digits.slice(0, 5)}-${digits.slice(5)}` : digits;
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
const addressFieldAliases = {
|
|
430
|
+
address: ["address", "endereco", "logradouro"],
|
|
431
|
+
district: ["district", "bairro"],
|
|
432
|
+
city: ["city", "cidade", "municipio"],
|
|
433
|
+
state: ["state", "estado", "uf"],
|
|
434
|
+
} as const;
|
|
435
|
+
|
|
398
436
|
function ContactFormComponent({ section, sdk }: ThemeSectionRendererProps) {
|
|
399
437
|
const props = dataRecord(section.data, "props");
|
|
400
438
|
const configuredFields = dataRecords(props, "fields");
|
|
401
439
|
const fields = configuredFields;
|
|
402
440
|
const [status, setStatus] = useState<"idle" | "sending" | "success" | "error">("idle");
|
|
403
441
|
const [error, setError] = useState("");
|
|
442
|
+
const [cepStatus, setCepStatus] = useState<"idle" | "loading" | "success" | "error">("idle");
|
|
443
|
+
const [cepMessage, setCepMessage] = useState("");
|
|
444
|
+
const formRef = useRef<HTMLFormElement>(null);
|
|
445
|
+
const lastSearchedCep = useRef("");
|
|
446
|
+
const cepController = useRef<AbortController | null>(null);
|
|
447
|
+
|
|
448
|
+
useEffect(() => () => {
|
|
449
|
+
cepController.current?.abort();
|
|
450
|
+
cepController.current = null;
|
|
451
|
+
}, []);
|
|
452
|
+
|
|
453
|
+
const searchCep = async (value: string) => {
|
|
454
|
+
const cleanCep = value.replace(/\D/g, "");
|
|
455
|
+
if (cleanCep.length !== 8) {
|
|
456
|
+
cepController.current?.abort();
|
|
457
|
+
cepController.current = null;
|
|
458
|
+
lastSearchedCep.current = "";
|
|
459
|
+
setCepStatus("idle");
|
|
460
|
+
setCepMessage("");
|
|
461
|
+
return;
|
|
462
|
+
}
|
|
463
|
+
if (cleanCep === lastSearchedCep.current) return;
|
|
464
|
+
|
|
465
|
+
cepController.current?.abort();
|
|
466
|
+
const controller = new AbortController();
|
|
467
|
+
cepController.current = controller;
|
|
468
|
+
lastSearchedCep.current = cleanCep;
|
|
469
|
+
const timeout = window.setTimeout(() => controller.abort(), 5000);
|
|
470
|
+
setCepStatus("loading");
|
|
471
|
+
setCepMessage("Buscando endereço…");
|
|
472
|
+
|
|
473
|
+
try {
|
|
474
|
+
const response = await fetch(`https://viacep.com.br/ws/${cleanCep}/json/`, {
|
|
475
|
+
signal: controller.signal,
|
|
476
|
+
});
|
|
477
|
+
if (!response.ok) throw new Error("CEP_FETCH_FAILED");
|
|
478
|
+
const data = await response.json() as { erro?: boolean; logradouro?: string; bairro?: string; localidade?: string; uf?: string };
|
|
479
|
+
if (data.erro) {
|
|
480
|
+
setCepStatus("error");
|
|
481
|
+
setCepMessage("CEP não encontrado. Confira o número ou preencha o endereço manualmente.");
|
|
482
|
+
return;
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
const addressValues = {
|
|
486
|
+
address: data.logradouro || "",
|
|
487
|
+
district: data.bairro || "",
|
|
488
|
+
city: data.localidade || "",
|
|
489
|
+
state: data.uf || "",
|
|
490
|
+
};
|
|
491
|
+
const configuredKeys = new Set(fields.map((field) => dataString(field, "key")));
|
|
492
|
+
for (const [part, aliases] of Object.entries(addressFieldAliases)) {
|
|
493
|
+
const targetKey = aliases.find((alias) => configuredKeys.has(alias));
|
|
494
|
+
const nextValue = addressValues[part as keyof typeof addressValues];
|
|
495
|
+
const target = targetKey
|
|
496
|
+
? formRef.current?.elements.namedItem(targetKey)
|
|
497
|
+
: null;
|
|
498
|
+
if (nextValue && target instanceof HTMLInputElement) target.value = nextValue;
|
|
499
|
+
}
|
|
500
|
+
setCepStatus("success");
|
|
501
|
+
setCepMessage("Endereço preenchido. Confira os dados e informe o número, se necessário.");
|
|
502
|
+
} catch {
|
|
503
|
+
if (controller.signal.aborted && cepController.current !== controller) return;
|
|
504
|
+
setCepStatus("error");
|
|
505
|
+
setCepMessage(controller.signal.aborted
|
|
506
|
+
? "A consulta demorou demais. Você pode preencher o endereço manualmente."
|
|
507
|
+
: "Não foi possível consultar o CEP. Preencha o endereço manualmente.");
|
|
508
|
+
} finally {
|
|
509
|
+
window.clearTimeout(timeout);
|
|
510
|
+
}
|
|
511
|
+
};
|
|
404
512
|
|
|
405
513
|
const submit = async (event: FormEvent<HTMLFormElement>) => {
|
|
406
514
|
event.preventDefault();
|
|
@@ -431,6 +539,9 @@ function ContactFormComponent({ section, sdk }: ThemeSectionRendererProps) {
|
|
|
431
539
|
pathname: typeof window === "undefined" ? undefined : window.location.pathname,
|
|
432
540
|
});
|
|
433
541
|
event.currentTarget.reset();
|
|
542
|
+
lastSearchedCep.current = "";
|
|
543
|
+
setCepStatus("idle");
|
|
544
|
+
setCepMessage("");
|
|
434
545
|
setStatus("success");
|
|
435
546
|
} catch (cause) {
|
|
436
547
|
setStatus("error");
|
|
@@ -444,7 +555,7 @@ function ContactFormComponent({ section, sdk }: ThemeSectionRendererProps) {
|
|
|
444
555
|
<h2>{dataString(props, "title", "Fale com nossa equipe")}</h2>
|
|
445
556
|
{dataString(props, "description") && <p>{dataString(props, "description")}</p>}
|
|
446
557
|
</div>
|
|
447
|
-
<form className="contact-form" onSubmit={(event) => void submit(event)}>
|
|
558
|
+
<form className="contact-form" ref={formRef} onSubmit={(event) => void submit(event)}>
|
|
448
559
|
{fields.map((field) => {
|
|
449
560
|
const key = dataString(field, "key");
|
|
450
561
|
if (!key) return null;
|
|
@@ -463,10 +574,11 @@ function ContactFormComponent({ section, sdk }: ThemeSectionRendererProps) {
|
|
|
463
574
|
<span>{label}{required && <small aria-hidden="true"> *</small>}</span>
|
|
464
575
|
{type === "textarea"
|
|
465
576
|
? <textarea name={key} placeholder={dataString(field, "placeholder")} required={required} rows={5} />
|
|
466
|
-
: <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 : undefined} onInput={dataString(field, "mask") === "whatsapp-br" ? (event) => { event.currentTarget.value = formatWhatsapp(event.currentTarget.value); } : undefined} />}
|
|
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} />}
|
|
467
578
|
</label>;
|
|
468
579
|
})}
|
|
469
580
|
<div className="contact-form-wide">
|
|
581
|
+
{cepStatus !== "idle" && <p className={`contact-form-feedback${cepStatus === "error" ? " contact-form-error" : ""}`} role={cepStatus === "error" ? "alert" : "status"}>{cepMessage}</p>}
|
|
470
582
|
<button className="button button-primary" disabled={status === "sending"} type="submit">
|
|
471
583
|
{status === "sending" ? "Enviando…" : dataString(props, "submitLabel", "Enviar contato")}
|
|
472
584
|
</button>
|