@nuvler/cli 0.5.13 → 0.5.15

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.
@@ -0,0 +1,47 @@
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 { Theme } from "../dist/src/theme-component.js";
6
+ import { ThemeEditorialItemSchema } from "@nuvler/theme-schema";
7
+
8
+ const context = {
9
+ store: { name: "Loja", slug: "loja" }, site: { modules: ["SERVICES"], settings: null },
10
+ navigation: { pages: [], categories: [] }, home: { content: { sections: [] } },
11
+ catalog: { products: [] }, editorial: { posts: [], services: [], cases: [] },
12
+ };
13
+ const item = { title: "Instalação", slug: "instalacao", description: "Resumo", image: null, category: null, publishedAt: null };
14
+ const content = { schemaVersion: 1, blocks: [
15
+ { type: "paragraph", data: { text: "Conteúdo completo do serviço" } },
16
+ { type: "header", data: { text: "Etapas do trabalho", level: 2 } },
17
+ { type: "list", data: { style: "ordered", items: ["Planejamento", { content: "Execução" }] } },
18
+ { type: "image", data: { file: { url: "https://example.com/etapas.png" }, caption: "Etapas ilustradas" } },
19
+ { type: "table", data: { content: [["Prazo", "Dois dias"]] } },
20
+ ] };
21
+ function render(body, basePath = "/servicos") {
22
+ return renderToStaticMarkup(createElement(Theme, { context, route: { type: "editorial-detail", basePath, item: { ...item, content: body } } }));
23
+ }
24
+
25
+ test("theme schema keeps published content and accepts legacy contexts", () => {
26
+ assert.deepEqual(ThemeEditorialItemSchema.parse({ ...item, content }).content, content);
27
+ assert.ok(ThemeEditorialItemSchema.safeParse(item).success);
28
+ assert.ok(ThemeEditorialItemSchema.safeParse({ ...item, content: null }).success);
29
+ assert.ok(ThemeEditorialItemSchema.safeParse({ ...item, content: "Texto antigo" }).success);
30
+ });
31
+
32
+ test("default theme renders full services, blog and cases rather than only summaries", () => {
33
+ for (const path of ["/servicos", "/blog", "/cases"]) {
34
+ const html = render(content, path);
35
+ for (const text of ["Conteúdo completo do serviço", "Etapas do trabalho", "Planejamento", "Execução", "Etapas ilustradas", "Dois dias"]) assert.ok(html.includes(text), text);
36
+ assert.ok(html.includes("<ol>"));
37
+ assert.ok(html.includes("https://example.com/etapas.png"));
38
+ assert.ok(html.includes("<table>"));
39
+ }
40
+ });
41
+
42
+ test("old plain HTML content is displayed as safe text; missing bodies still render", () => {
43
+ const html = render("<p>Texto antigo</p><img src=x onerror=alert(1)>");
44
+ assert.ok(html.includes("Texto antigo"));
45
+ assert.ok(!html.includes("onerror="));
46
+ for (const body of [undefined, null, { schemaVersion: 1, blocks: [] }]) assert.ok(render(body).includes("Instalação"));
47
+ });
@@ -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.type === "loading" ? "Carregando…" : route.type === "page" ? route.title : "Conteúdo não encontrado"}</h1></main>;
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
  }
@@ -15,13 +15,13 @@ export async function loadThemeBuild(project) {
15
15
  const directory = path.join(project.directory, THEME_BUILD_DIRECTORY);
16
16
  const entryPath = path.join(directory, THEME_BUILD_ENTRY);
17
17
  const styleCandidate = path.join(directory, THEME_BUILD_STYLE);
18
- if (!await isFile(entryPath)) {
18
+ if (!(await isFile(entryPath))) {
19
19
  throw new Error(`Build do tema não encontrado em ${entryPath}. Execute "nuvler theme build".`);
20
20
  }
21
21
  return {
22
22
  directory,
23
23
  entryPath,
24
- stylePath: await isFile(styleCandidate) ? styleCandidate : null,
24
+ stylePath: (await isFile(styleCandidate)) ? styleCandidate : null,
25
25
  };
26
26
  }
27
27
  export function createArtifactManifest(project, build) {
@@ -34,6 +34,7 @@ export function createArtifactManifest(project, build) {
34
34
  sdkVersion: project.manifest.sdkVersion,
35
35
  entry: "./theme.js",
36
36
  style: build.stylePath ? "./theme.css" : undefined,
37
+ capabilities: project.manifest.capabilities,
37
38
  presentation: project.manifest.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AG,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,iBAAiB,CAAC,CAAC;IAE/D,IAAI,CAAC,CAAC,MAAM,MAAM,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC;QAC/B,MAAM,IAAI,KAAK,CACb,mCAAmC,SAAS,iCAAiC,CAC9E,CAAC;IACJ,CAAC;IAED,OAAO;QACL,SAAS;QACT,SAAS;QACT,SAAS,EAAE,CAAC,MAAM,MAAM,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC,IAAI;KAClE,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,sBAAsB,CACpC,OAAqB,EACrB,KAAuB;IAEvB,OAAO;QACL,aAAa,EAAE,OAAO,CAAC,QAAQ,CAAC,aAAa;QAC7C,EAAE,EAAE,OAAO,CAAC,QAAQ,CAAC,EAAE;QACvB,IAAI,EAAE,OAAO,CAAC,QAAQ,CAAC,IAAI;QAC3B,OAAO,EAAE,OAAO,CAAC,QAAQ,CAAC,OAAO;QACjC,cAAc,EAAE,OAAO,CAAC,QAAQ,CAAC,cAAc;QAC/C,UAAU,EAAE,OAAO,CAAC,QAAQ,CAAC,UAAU;QACvC,KAAK,EAAE,YAAY;QACnB,KAAK,EAAE,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,SAAS;QAClD,YAAY,EAAE,OAAO,CAAC,QAAQ,CAAC,YAAY;QAC3C,YAAY,EAAE,OAAO,CAAC,QAAQ,CAAC,YAAY;KAC5C,CAAC;AACJ,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nuvler/cli",
3
- "version": "0.5.13",
3
+ "version": "0.5.15",
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.4.1",
24
- "@nuvler/theme-sdk": "^1.4.3",
23
+ "@nuvler/theme-schema": "^1.4.3",
24
+ "@nuvler/theme-sdk": "^1.4.5",
25
25
  "@vitejs/plugin-react": "^6.0.5",
26
26
  "commander": "^15.0.0",
27
27
  "react": "19.2.8",
@@ -124,6 +124,20 @@ function PreviewApp() {
124
124
  const currentRequest = ++requestId.current;
125
125
  setRouteError(null);
126
126
  const localRoute = routeFromLocalData(url);
127
+ if (localRoute?.type === "editorial-list") {
128
+ setRoute({ type: "loading", pathname: url.pathname });
129
+ try {
130
+ const page = context.site.modules.includes("NAVIGATION")
131
+ ? await previewApi<{ title: string; description?: string; content: import("@nuvler/theme-sdk").ThemePageContent }>(`pages/${localRoute.basePath.slice(1)}`)
132
+ : null;
133
+ if (currentRequest === requestId.current) setRoute({ ...localRoute, ...(page ? { title: page.title, description: page.description ?? "", content: page.content } : {}) });
134
+ } catch (error) {
135
+ if (currentRequest !== requestId.current) return;
136
+ if (error instanceof PreviewHttpError && error.status === 404) setRoute(localRoute);
137
+ else setRouteError("Não foi possível carregar o conteúdo da listagem. Tente novamente.");
138
+ }
139
+ return;
140
+ }
127
141
  if (localRoute) { setRoute(localRoute); return; }
128
142
  setRoute({ type: "loading", pathname: url.pathname });
129
143
  try {