@nuvler/cli 0.5.13 → 0.5.14
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/api/theme-context.js +3 -1
- package/dist/api/theme-context.js.map +1 -1
- package/dist/nuvler.js +6 -1
- package/dist/nuvler.js.map +1 -1
- package/dist/templates/nuvler-atelier/src/definition.tsx +3 -3
- package/dist/templates/nuvler-atelier/src/theme.tsx +34 -1
- package/dist/templates/nuvler-default/README.md +3 -1
- package/dist/templates/nuvler-default/nuvler.theme.json +1 -1
- package/dist/templates/nuvler-default/package.json +1 -1
- package/dist/templates/nuvler-default/src/footer.tsx +2 -1
- package/dist/templates/nuvler-default/src/home.tsx +5 -0
- package/dist/templates/nuvler-default/src/theme-component.tsx +114 -18
- package/dist/templates/nuvler-default/src/theme.css +960 -230
- package/dist/templates/nuvler-default/test/home-reference.test.mjs +42 -0
- package/dist/templates/starter/src/theme.tsx +20 -2
- package/package.json +1 -1
- package/preview-host/vendor/theme-runtime/default-theme.tsx +4 -2
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import test from "node:test";
|
|
3
|
+
import { createElement } from "react";
|
|
4
|
+
import { renderToStaticMarkup } from "react-dom/server";
|
|
5
|
+
import { Home } from "../dist/src/home.js";
|
|
6
|
+
import { Footer } from "../dist/src/footer.js";
|
|
7
|
+
import { nuvlerDefaultTemplate } from "../dist/src/theme-config.js";
|
|
8
|
+
import { ThemeHomeSectionSchema, ThemeSiteSchema } from "@nuvler/theme-schema";
|
|
9
|
+
|
|
10
|
+
const image = url => ({ url, alt: "Logo", width: 200, height: 80 });
|
|
11
|
+
const settings = { siteName: "Loja", description: null, logo: image("https://example.com/header.png"), footerLogo: image("https://example.com/footer.png"), favicon: null, contact: {}, social: {}, theme: null };
|
|
12
|
+
const site = { tenant: { name: "Loja", slug: "loja" }, modules: [], settings };
|
|
13
|
+
|
|
14
|
+
test("public schema retains optional references and footer logos", () => {
|
|
15
|
+
const section = { reference: "casos", type: "rich-text", enabled: true, order: 0, data: {} };
|
|
16
|
+
assert.equal(ThemeHomeSectionSchema.parse(section).reference, "casos");
|
|
17
|
+
assert.equal(ThemeHomeSectionSchema.safeParse({ ...section, reference: "Invalid Reference" }).success, false);
|
|
18
|
+
assert.equal(ThemeSiteSchema.parse({ modules: [], settings }).settings.footerLogo.url, settings.footerLogo.url);
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
test("Home renders anchors for native and theme sections without exposing internal IDs", () => {
|
|
22
|
+
const sections = [
|
|
23
|
+
{ id: "internal-one", reference: "casos", type: "cases-grid", enabled: true, order: 1, data: {} },
|
|
24
|
+
{ id: "internal-two", reference: "inicio", type: "hero", enabled: true, order: 0, data: {} },
|
|
25
|
+
{ id: "internal-three", reference: "oculta", type: "rich-text", enabled: false, order: 2, data: {} },
|
|
26
|
+
];
|
|
27
|
+
const html = renderToStaticMarkup(createElement(Home, { sections, products: [], posts: [], services: [], cases: [], site }));
|
|
28
|
+
assert.equal((html.match(/id="casos"/g) ?? []).length, 1);
|
|
29
|
+
assert.equal((html.match(/id="inicio"/g) ?? []).length, 1);
|
|
30
|
+
assert.ok(html.indexOf('id="inicio"') < html.indexOf('id="casos"'));
|
|
31
|
+
assert.ok(!html.includes('id="oculta"'));
|
|
32
|
+
assert.ok(!html.includes('id="internal-one"'));
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
test("Footer renders the alternative logo and falls back to the original", () => {
|
|
36
|
+
const html = renderToStaticMarkup(createElement(Footer, { site, pages: [], template: nuvlerDefaultTemplate }));
|
|
37
|
+
assert.ok(html.includes(settings.footerLogo.url));
|
|
38
|
+
assert.ok(!html.includes(settings.logo.url));
|
|
39
|
+
const legacySite = { ...site, settings: { ...settings, footerLogo: undefined } };
|
|
40
|
+
const fallback = renderToStaticMarkup(createElement(Footer, { site: legacySite, pages: [], template: nuvlerDefaultTemplate }));
|
|
41
|
+
assert.ok(fallback.includes(settings.logo.url));
|
|
42
|
+
});
|
|
@@ -1,10 +1,27 @@
|
|
|
1
1
|
import type { CSSProperties } from "react";
|
|
2
|
-
import type { NuvlerThemeProps, ThemeSite } from "@nuvler/theme-sdk";
|
|
2
|
+
import type { NuvlerThemeProps, ThemePageContent, ThemeSite } from "@nuvler/theme-sdk";
|
|
3
3
|
import { themeDefinition } from "./definition.js";
|
|
4
4
|
import "./theme.css";
|
|
5
5
|
|
|
6
6
|
export { manifest, themeDefinition } from "./definition.js";
|
|
7
7
|
|
|
8
|
+
function PageBlocks({ content }: { content: ThemePageContent }) {
|
|
9
|
+
return <article className="theme-page-content">{content.blocks.map((block, index) => {
|
|
10
|
+
const data = block.data;
|
|
11
|
+
const key = block.id || `${block.type}-${index}`;
|
|
12
|
+
const text = (value: unknown) => typeof value === "string" ? value.replace(/<(script|style)\b[^>]*>[\s\S]*?<\/\1>/gi, " ").replace(/<[^>]+>/g, " ").replace(/\s+/g, " ").trim() : "";
|
|
13
|
+
if (block.type === "header") return <h2 key={key}>{text(data.text)}</h2>;
|
|
14
|
+
if (block.type === "paragraph") return <p key={key}>{text(data.text)}</p>;
|
|
15
|
+
if (block.type === "delimiter") return <hr key={key} />;
|
|
16
|
+
if (block.type === "quote") return <blockquote key={key}><p>{text(data.text)}</p>{text(data.caption) && <cite>{text(data.caption)}</cite>}</blockquote>;
|
|
17
|
+
if (block.type === "list") { const items = Array.isArray(data.items) ? data.items : []; const List = data.style === "ordered" ? "ol" : "ul"; return <List key={key}>{items.map((item, i) => <li key={i}>{text(item && typeof item === "object" && "content" in item ? (item as { content: unknown }).content : item)}</li>)}</List>; }
|
|
18
|
+
if (block.type === "image") { const image = data.file && typeof data.file === "object" ? data.file as Record<string, unknown> : {}; const url = typeof image.url === "string" ? image.url : ""; return url ? <figure key={key}><img src={url} alt={text(data.caption)} loading="lazy" />{text(data.caption) && <figcaption>{text(data.caption)}</figcaption>}</figure> : null; }
|
|
19
|
+
if (block.type === "imageText") { const image = data.image && typeof data.image === "object" ? data.image as Record<string, unknown> : {}; const url = typeof image.url === "string" ? image.url : ""; return <section key={key}>{url && <img src={url} alt={text(image.alt)} loading="lazy" />}{text(data.title) && <h2>{text(data.title)}</h2>}{text(data.text) && <p>{text(data.text)}</p>}</section>; }
|
|
20
|
+
if (block.type === "table") { const rows = Array.isArray(data.content) ? data.content : []; return <div key={key}><table><tbody>{rows.map((row, ri) => <tr key={ri}>{Array.isArray(row) ? row.map((cell, ci) => <td key={ci}>{text(cell)}</td>) : null}</tr>)}</tbody></table></div>; }
|
|
21
|
+
return null;
|
|
22
|
+
})}</article>;
|
|
23
|
+
}
|
|
24
|
+
|
|
8
25
|
export default function Theme({ context, route = { type: "home" }, sdk }: NuvlerThemeProps) {
|
|
9
26
|
const { Header, Footer, Home, ProductGrid, ProductDetail } = themeDefinition.components;
|
|
10
27
|
const site: ThemeSite = { tenant: context.store, ...context.site };
|
|
@@ -39,7 +56,8 @@ export default function Theme({ context, route = { type: "home" }, sdk }: Nuvler
|
|
|
39
56
|
else if (route.type === "product") content = <main className="theme-section"><ProductDetail product={route.product} showPrices={site.settings?.catalog?.showPrices ?? true} contact={site.settings?.contact} productUrl={null} descriptionContent={<p>{route.product.description}</p>} onAddToCart={sdk?.cart.add} /></main>;
|
|
40
57
|
else if (route.type === "editorial-list") content = <main className="theme-section"><h1>{route.title}</h1>{route.items.map((item) => <article key={item.slug}><h2>{item.title}</h2><p>{item.description}</p></article>)}</main>;
|
|
41
58
|
else if (route.type === "editorial-detail") content = <main className="theme-section"><h1>{route.item.title}</h1><p>{route.item.description}</p></main>;
|
|
42
|
-
else content = <main className="theme-section"><h1>{route.
|
|
59
|
+
else if (route.type === "page") content = <main className="theme-section"><h1>{route.title}</h1><PageBlocks content={route.content} /></main>;
|
|
60
|
+
else content = <main className="theme-section"><h1>{route.type === "loading" ? "Carregando…" : "Conteúdo não encontrado"}</h1></main>;
|
|
43
61
|
|
|
44
62
|
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
63
|
}
|
package/package.json
CHANGED
|
@@ -896,7 +896,7 @@ function Footer({ context, adapters }: DefaultThemeProps) {
|
|
|
896
896
|
const extraLinks = moduleLinks(context);
|
|
897
897
|
return <footer className="store-footer">
|
|
898
898
|
<div className="store-container footer-grid">
|
|
899
|
-
<div><strong className="footer-brand">{name}</strong><p>{settings?.description || template.footerTagline}</p></div>
|
|
899
|
+
<div><strong className="footer-brand">{(settings?.footerLogo ?? settings?.logo)?.url ? <adapters.Image image={settings?.footerLogo ?? settings?.logo ?? null} fallbackAlt={name} className="footer-logo" /> : name}</strong><p>{settings?.description || template.footerTagline}</p></div>
|
|
900
900
|
<div><strong>Navegação</strong>{context.site.modules.includes("PRODUCTS") && <Link href="/produtos">Todos os produtos</Link>}{extraLinks.map((item) => <Link href={item.href} key={item.href}>{item.label}</Link>)}<Link href="/">Início</Link></div>
|
|
901
901
|
<div><strong>Atendimento</strong>{settings?.contact.email && <a href={`mailto:${settings.contact.email}`}>{settings.contact.email}</a>}{settings?.contact.phone && <a href={`tel:${settings.contact.phone}`}>{settings.contact.phone}</a>}{settings?.contact.address && <span>{settings.contact.address}</span>}</div>
|
|
902
902
|
</div>
|
|
@@ -944,7 +944,9 @@ export function DefaultTheme({ context, adapters, route = { type: "home" }, sdk
|
|
|
944
944
|
<Header adapters={adapters} context={context} />
|
|
945
945
|
<div className="store-page"><RouteContent adapters={adapters} context={context} route={route} sdk={sdk} home={<main>{sections.map((section, index) => {
|
|
946
946
|
const Renderer = defaultSectionRegistry[section.type];
|
|
947
|
-
|
|
947
|
+
if (!Renderer) return null;
|
|
948
|
+
const content = <Renderer adapters={adapters} context={context} key={`${section.type}-${section.order}-${index}`} sdk={sdk} section={section} />;
|
|
949
|
+
return section.reference ? <div id={section.reference} key={`${section.type}-${section.order}-${index}`} style={{ scrollMarginTop: "100px" }}>{content}</div> : content;
|
|
948
950
|
})}<section className="benefits-section"><div className="store-container benefits-grid">{template.benefits.map((benefit) => <div key={benefit.title}><strong>{benefit.title}</strong><span>{benefit.description}</span></div>)}</div></section></main>} /></div>
|
|
949
951
|
<Footer adapters={adapters} context={context} />
|
|
950
952
|
<FloatingWhatsapp context={context} />
|