@nuvler/cli 0.4.4 → 0.5.0

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 (46) hide show
  1. package/README.md +10 -5
  2. package/dist/commands/theme/create.js +2 -2
  3. package/dist/commands/theme/dev.js +3 -1
  4. package/dist/commands/theme/dev.js.map +1 -1
  5. package/dist/commands/theme/migrate.js +7 -0
  6. package/dist/commands/theme/migrate.js.map +1 -1
  7. package/dist/index.js +1 -1
  8. package/dist/migrate/analysis/dependency-classifier.js +41 -0
  9. package/dist/migrate/analysis/dependency-classifier.js.map +1 -0
  10. package/dist/migrate/analysis/dependency-graph.js +210 -0
  11. package/dist/migrate/analysis/dependency-graph.js.map +1 -0
  12. package/dist/migrate/analyzer.js +18 -8
  13. package/dist/migrate/analyzer.js.map +1 -1
  14. package/dist/migrate/asset-copier.js +2 -2
  15. package/dist/migrate/asset-copier.js.map +1 -1
  16. package/dist/migrate/classifier.js +4 -0
  17. package/dist/migrate/classifier.js.map +1 -1
  18. package/dist/migrate/generation/fidelity-pass.js +223 -0
  19. package/dist/migrate/generation/fidelity-pass.js.map +1 -0
  20. package/dist/migrate/generator.js +1413 -57
  21. package/dist/migrate/generator.js.map +1 -1
  22. package/dist/migrate/resolvers/import-resolver.js +91 -0
  23. package/dist/migrate/resolvers/import-resolver.js.map +1 -0
  24. package/dist/migrate/transform/source-transformer.js +373 -0
  25. package/dist/migrate/transform/source-transformer.js.map +1 -0
  26. package/dist/migrate/transformer.js +297 -11
  27. package/dist/migrate/transformer.js.map +1 -1
  28. package/dist/nuvler.js +3427 -303
  29. package/dist/nuvler.js.map +1 -1
  30. package/dist/preview/prepare.js +84 -1
  31. package/dist/preview/prepare.js.map +1 -1
  32. package/dist/templates/nuvler-atelier/nuvler.theme.json +1 -1
  33. package/dist/templates/nuvler-atelier/package.json +2 -2
  34. package/dist/templates/nuvler-default/nuvler.theme.json +1 -1
  35. package/dist/templates/nuvler-default/package.json +1 -1
  36. package/dist/templates/nuvler-default/src/home.tsx +79 -2
  37. package/dist/templates/nuvler-default/src/theme-component.tsx +4 -3
  38. package/dist/templates/nuvler-default/src/theme.css +149 -0
  39. package/dist/templates/starter/nuvler.theme.json +1 -1
  40. package/dist/templates/starter/package.json +2 -2
  41. package/package.json +4 -4
  42. package/preview-host/package.json +1 -1
  43. package/preview-host/src/app/globals.css +5 -15
  44. package/preview-host/src/main.tsx +55 -5
  45. package/preview-host/vendor/theme-runtime/default-theme.tsx +131 -3
  46. package/preview-host/vite.config.ts +4 -0
@@ -1,7 +1,83 @@
1
+ import { readFile } from "node:fs/promises";
2
+ import path from "node:path";
3
+ import { ThemeContextSchema } from "@nuvler/theme-schema";
1
4
  import { loadThemeContext } from "../api/theme-context.js";
2
5
  import { loadDeveloperSession, requireAuthorizedTenant, } from "../config/developer-session.js";
3
6
  import { readThemeProjectConfig } from "../config/project.js";
4
7
  import { loadThemeProject } from "../theme/project.js";
8
+ function record(value) {
9
+ return value && typeof value === "object" && !Array.isArray(value)
10
+ ? value
11
+ : null;
12
+ }
13
+ function meaningful(value) {
14
+ if (typeof value === "string")
15
+ return Boolean(value.trim());
16
+ if (Array.isArray(value))
17
+ return value.length > 0;
18
+ return value !== null && value !== undefined;
19
+ }
20
+ async function migrationSeedContext(directory, context) {
21
+ let parsed;
22
+ try {
23
+ parsed = JSON.parse(await readFile(path.join(directory, "migration-content-seed.json"), "utf8"));
24
+ }
25
+ catch (error) {
26
+ if (error.code === "ENOENT")
27
+ return { context, sections: 0 };
28
+ throw new Error("migration-content-seed.json inválido; regenere o tema migrado.", { cause: error });
29
+ }
30
+ const seed = record(parsed);
31
+ const rawSections = Array.isArray(seed?.sections) ? seed.sections : [];
32
+ const supported = new Set([
33
+ "hero", "banner-carousel", "image-text", "rich-text", "cta",
34
+ "services-grid", "blog-grid", "cases-grid", "products-grid", "products-carousel",
35
+ ]);
36
+ const seeds = rawSections.flatMap((candidate) => {
37
+ const section = record(candidate);
38
+ const data = record(section?.data);
39
+ if (!section || !data || typeof section.id !== "string" || typeof section.type !== "string" || !supported.has(section.type))
40
+ return [];
41
+ return [{
42
+ id: section.id,
43
+ type: section.type,
44
+ enabled: true,
45
+ order: typeof section.order === "number" ? section.order : 0,
46
+ data,
47
+ }];
48
+ });
49
+ if (!seeds.length)
50
+ return { context, sections: 0 };
51
+ const merged = context.home.content.sections.map((section) => ({ ...section, data: { ...section.data } }));
52
+ const claimed = new Set();
53
+ for (const seedSection of seeds) {
54
+ const exact = merged.findIndex(({ id }) => id === seedSection.id);
55
+ const compatible = exact >= 0
56
+ ? exact
57
+ : merged.findIndex((section, index) => !claimed.has(index) && section.type === seedSection.type);
58
+ if (compatible < 0) {
59
+ merged.push(seedSection);
60
+ continue;
61
+ }
62
+ claimed.add(compatible);
63
+ const configured = merged[compatible];
64
+ const configuredValues = Object.fromEntries(Object.entries(configured.data).filter(([, value]) => meaningful(value)));
65
+ // The public Home currently does not expose section IDs. Attach the
66
+ // migrated ID to the matching type/occurrence so the preserved component
67
+ // can find it, while always giving panel data priority over the dev seed.
68
+ merged[compatible] = {
69
+ ...configured,
70
+ id: seedSection.id,
71
+ data: { ...seedSection.data, ...configuredValues },
72
+ };
73
+ }
74
+ merged.sort((left, right) => left.order - right.order);
75
+ const seeded = ThemeContextSchema.parse({
76
+ ...context,
77
+ home: { ...context.home, content: { ...context.home.content, sections: merged } },
78
+ });
79
+ return { context: seeded, sections: seeds.length };
80
+ }
5
81
  export async function prepareThemePreview(options) {
6
82
  const project = await loadThemeProject(options.themeDirectory);
7
83
  const configured = await readThemeProjectConfig(project.directory);
@@ -14,6 +90,13 @@ export async function prepareThemePreview(options) {
14
90
  if (context.store.slug !== tenant.slug) {
15
91
  throw new Error(`A API retornou contexto do tenant "${context.store.slug}" para "${tenant.slug}".`);
16
92
  }
17
- return { project, context, apiUrl: session.apiUrl, tenant };
93
+ const preview = await migrationSeedContext(project.directory, context);
94
+ return {
95
+ project,
96
+ context: preview.context,
97
+ apiUrl: session.apiUrl,
98
+ tenant,
99
+ migrationSeedSections: preview.sections,
100
+ };
18
101
  }
19
102
  //# sourceMappingURL=prepare.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"prepare.js","sourceRoot":"","sources":["../../src/preview/prepare.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAC3D,OAAO,EACL,oBAAoB,EACpB,uBAAuB,GACxB,MAAM,gCAAgC,CAAC;AACxC,OAAO,EAAE,sBAAsB,EAAE,MAAM,sBAAsB,CAAC;AAC9D,OAAO,EAAE,gBAAgB,EAAqB,MAAM,qBAAqB,CAAC;AAa1E,MAAM,CAAC,KAAK,UAAU,mBAAmB,CAAC,OAIzC;IACC,MAAM,OAAO,GAAG,MAAM,gBAAgB,CAAC,OAAO,CAAC,cAAc,CAAC,CAAC;IAC/D,MAAM,UAAU,GAAG,MAAM,sBAAsB,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;IACnE,IAAI,CAAC,UAAU,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,IAAI,EAAE,EAAE,CAAC;QAC1C,MAAM,IAAI,KAAK,CAAC,0DAA0D,CAAC,CAAC;IAC9E,CAAC;IACD,MAAM,OAAO,GAAG,MAAM,oBAAoB,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;IACvE,MAAM,MAAM,GAAG,uBAAuB,CACpC,OAAO,CAAC,OAAO,EACf,OAAO,CAAC,KAAK,EAAE,IAAI,EAAE,IAAI,UAAW,CAAC,MAAM,CAAC,EAAE,CAC/C,CAAC;IACF,MAAM,OAAO,GAAG,MAAM,gBAAgB,CAAC,EAAE,KAAK,EAAE,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;IACvF,IAAI,OAAO,CAAC,KAAK,CAAC,IAAI,KAAK,MAAM,CAAC,IAAI,EAAE,CAAC;QACvC,MAAM,IAAI,KAAK,C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A0D,CAAC,CAAC;IAC9E,CAAC;IACD,MAAM,OAAO,GAAG,MAAM,oBAAoB,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;IACvE,MAAM,MAAM,GAAG,uBAAuB,CACpC,OAAO,CAAC,OAAO,EACf,OAAO,CAAC,KAAK,EAAE,IAAI,EAAE,IAAI,UAAW,CAAC,MAAM,CAAC,EAAE,CAC/C,CAAC;IACF,MAAM,OAAO,GAAG,MAAM,gBAAgB,CAAC,EAAE,KAAK,EAAE,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;IACvF,IAAI,OAAO,CAAC,KAAK,CAAC,IAAI,KAAK,MAAM,CAAC,IAAI,EAAE,CAAC;QACvC,MAAM,IAAI,KAAK,CACb,sCAAsC,OAAO,CAAC,KAAK,CAAC,IAAI,WAAW,MAAM,CAAC,IAAI,IAAI,CACnF,CAAC;IACJ,CAAC;IACD,MAAM,OAAO,GAAG,MAAM,oBAAoB,CAAC,OAAO,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC;IACvE,OAAO;QACL,OAAO;QACP,OAAO,EAAE,OAAO,CAAC,OAAO;QACxB,MAAM,EAAE,OAAO,CAAC,MAAM;QACtB,MAAM;QACN,qBAAqB,EAAE,OAAO,CAAC,QAAQ;KACxC,CAAC;AACJ,CAAC"}
@@ -4,7 +4,7 @@
4
4
  "name": "Nuvler Atelier",
5
5
  "version": "0.1.2",
6
6
  "runtimeVersion": "1",
7
- "sdkVersion": "^1.2.2",
7
+ "sdkVersion": "^1.3.0",
8
8
  "entry": "src/theme.tsx",
9
9
  "styles": ["src/theme.css"],
10
10
  "presentation": {
@@ -13,13 +13,13 @@
13
13
  "typecheck": "tsc -p tsconfig.json --noEmit"
14
14
  },
15
15
  "dependencies": {
16
- "@nuvler/theme-sdk": "^1.2.2"
16
+ "@nuvler/theme-sdk": "^1.3.0"
17
17
  },
18
18
  "peerDependencies": {
19
19
  "react": "^19.0.0"
20
20
  },
21
21
  "devDependencies": {
22
- "@nuvler/cli": "^0.4.4",
22
+ "@nuvler/cli": "^0.5.0",
23
23
  "@types/react": "^19.0.0",
24
24
  "react": "^19.0.0",
25
25
  "typescript": "^5.9.0"
@@ -4,7 +4,7 @@
4
4
  "name": "Nuvler Default",
5
5
  "version": "1.0.4",
6
6
  "runtimeVersion": "1",
7
- "sdkVersion": "^1.2.2",
7
+ "sdkVersion": "^1.3.0",
8
8
  "entry": "src/theme.tsx",
9
9
  "styles": ["src/theme.css"],
10
10
  "presentation": {
@@ -59,7 +59,7 @@
59
59
  "react": "^19.0.0"
60
60
  },
61
61
  "dependencies": {
62
- "@nuvler/theme-sdk": "^1.2.2"
62
+ "@nuvler/theme-sdk": "^1.3.0"
63
63
  },
64
64
  "devDependencies": {
65
65
  "@types/react": "^19.0.0",
@@ -1,4 +1,5 @@
1
- import type { HomeProps, ThemeEditorialItem, ThemeHomeSection, ThemeImage, ThemeSite } from "@nuvler/theme-sdk";
1
+ import { useState, type FormEvent } from "react";
2
+ import type { HomeProps, ThemeContactSubmissionInput, ThemeEditorialItem, ThemeHomeSection, ThemeImage, ThemeSite } from "@nuvler/theme-sdk";
2
3
  import { BannerCarousel, type ThemeBanner } from "./banner-carousel.js";
3
4
  import { ProductCarousel } from "./product-carousel.js";
4
5
  import { ProductGrid } from "./products.js";
@@ -14,6 +15,18 @@ function limit(data: Record<string, unknown>) {
14
15
  return Number.isInteger(value) ? Math.min(12, Math.max(1, value)) : 6;
15
16
  }
16
17
 
18
+ function record(data: Record<string, unknown>, key: string): Record<string, unknown> {
19
+ const value = data[key];
20
+ return value && typeof value === "object" && !Array.isArray(value) ? value as Record<string, unknown> : {};
21
+ }
22
+
23
+ function records(data: Record<string, unknown>, key: string): Record<string, unknown>[] {
24
+ const value = data[key];
25
+ return Array.isArray(value)
26
+ ? value.filter((item): item is Record<string, unknown> => Boolean(item) && typeof item === "object" && !Array.isArray(item))
27
+ : [];
28
+ }
29
+
17
30
  function productCategory(data: Record<string, unknown>) {
18
31
  const value = text(data, "categorySlug").toLocaleLowerCase("pt-BR");
19
32
  if (["", "all", "todos", "todas", "all-categories", "todas-as-categorias"].includes(value)) return "";
@@ -81,13 +94,77 @@ function TextSection({ section, ImageComponent = ThemeImageView }: { section: Th
81
94
  return <section className="store-section editorial-section"><div className="store-container editorial-content">{text(section.data, "eyebrow") && <span>{text(section.data, "eyebrow")}</span>}<h2>{title}</h2>{description && <p>{description}</p>}{section.type === "cta" && text(section.data, "buttonLabel") && text(section.data, "buttonUrl") && <a className="button button-primary" href={text(section.data, "buttonUrl")}>{text(section.data, "buttonLabel")}</a>}</div></section>;
82
95
  }
83
96
 
84
- export function Home({ sections, products, posts, services, cases, site, template, ImageComponent = ThemeImageView }: HomeProps & { ImageComponent?: ThemeImageComponent }) {
97
+ function ContactForm({ section, submitContact }: { section: ThemeHomeSection; submitContact?: (submission: ThemeContactSubmissionInput) => Promise<unknown> }) {
98
+ const props = record(section.data, "props");
99
+ const configured = records(props, "fields");
100
+ const fields = configured.length ? configured : [
101
+ { key: "name", label: "Nome", type: "text", required: true },
102
+ { key: "email", label: "E-mail", type: "email", required: true },
103
+ { key: "phone", label: "Telefone", type: "tel" },
104
+ { key: "message", label: "Mensagem", type: "textarea", required: true },
105
+ ];
106
+ const [status, setStatus] = useState<"idle" | "sending" | "success" | "error">("idle");
107
+ const [error, setError] = useState("");
108
+ const submit = async (event: FormEvent<HTMLFormElement>) => {
109
+ event.preventDefault();
110
+ if (!submitContact) {
111
+ setStatus("error");
112
+ setError("O envio de contatos ainda não está disponível.");
113
+ return;
114
+ }
115
+ const formElement = event.currentTarget;
116
+ const form = new FormData(formElement);
117
+ const values: ThemeContactSubmissionInput["values"] = {};
118
+ fields.forEach((field) => {
119
+ const key = text(field, "key");
120
+ if (!key) return;
121
+ if (text(field, "type") === "checkbox") {
122
+ values[key] = form.has(key);
123
+ return;
124
+ }
125
+ const entries = form.getAll(key).map(String);
126
+ values[key] = entries.length > 1 ? entries : entries[0] ?? "";
127
+ });
128
+ setStatus("sending");
129
+ setError("");
130
+ try {
131
+ await submitContact({ formKey: text(section.data, "componentKey", "contact-form"), sectionId: section.id, values, pathname: typeof window === "undefined" ? undefined : window.location.pathname });
132
+ formElement.reset();
133
+ setStatus("success");
134
+ } catch (cause) {
135
+ setStatus("error");
136
+ setError(cause instanceof Error ? cause.message : "Não foi possível enviar o contato.");
137
+ }
138
+ };
139
+ return <section className="store-section theme-component-section contact-form-section"><div className="store-container contact-form-layout"><div className="contact-form-copy">{text(props, "eyebrow") && <span>{text(props, "eyebrow")}</span>}<h2>{text(props, "title", "Fale com nossa equipe")}</h2>{text(props, "description") && <p>{text(props, "description")}</p>}</div><form className="contact-form" onSubmit={(event) => void submit(event)}>{fields.map((field) => {
140
+ const key = text(field, "key");
141
+ const type = text(field, "type", "text");
142
+ const label = text(field, "label", key);
143
+ const required = field.required === true;
144
+ if (!key) return null;
145
+ if (type === "checkbox") return <label className="contact-form-wide contact-form-checkbox" key={key}><input name={key} required={required} type="checkbox" value="true" /><span>{label}{required && <small aria-hidden="true"> *</small>}</span></label>;
146
+ if (type === "select") return <label key={key}><span>{label}{required && <small aria-hidden="true"> *</small>}</span><select name={key} required={required}>{records(field, "options").map((option) => <option key={text(option, "value")} value={text(option, "value")}>{text(option, "label", text(option, "value"))}</option>)}</select></label>;
147
+ return <label className={type === "textarea" ? "contact-form-wide" : ""} key={key}><span>{label}{required && <small aria-hidden="true"> *</small>}</span>{type === "textarea" ? <textarea name={key} placeholder={text(field, "placeholder")} required={required} rows={5} /> : <input name={key} placeholder={text(field, "placeholder")} required={required} type={["email", "tel", "url", "number"].includes(type) ? type : "text"} />}</label>;
148
+ })}<div className="contact-form-wide"><button className="button button-primary" disabled={status === "sending"} type="submit">{status === "sending" ? "Enviando…" : text(props, "submitLabel", "Enviar contato")}</button>{status === "success" && <p className="contact-form-feedback" role="status">{text(props, "successMessage", "Contato enviado com sucesso.")}</p>}{status === "error" && <p className="contact-form-feedback contact-form-error" role="alert">{error}</p>}</div></form></div></section>;
149
+ }
150
+
151
+ function ThemeComponent({ section, submitContact }: { section: ThemeHomeSection; submitContact?: HomeProps["submitContact"] }) {
152
+ const componentKey = text(section.data, "componentKey");
153
+ const props = record(section.data, "props");
154
+ if (componentKey === "contact-form" || componentKey.endsWith("-form")) return <ContactForm section={section} submitContact={submitContact} />;
155
+ if (componentKey === "video") return <section className="store-section theme-component-section" data-component-key="video"><div className="store-container">{text(props, "eyebrow") && <span>{text(props, "eyebrow")}</span>}{text(props, "title") && <h2>{text(props, "title")}</h2>}{text(props, "description") && <p>{text(props, "description")}</p>}{text(props, "videoUrl") && <video className="theme-component-video" controls playsInline poster={text(props, "posterImageUrl") || undefined} src={text(props, "videoUrl")} />}</div></section>;
156
+ const items = records(props, "items");
157
+ return <section className="store-section theme-component-section" data-component-key={componentKey || undefined}><div className="store-container">{text(props, "eyebrow") && <span>{text(props, "eyebrow")}</span>}{text(props, "title") && <h2>{text(props, "title")}</h2>}{text(props, "description") && <p>{text(props, "description")}</p>}{items.length > 0 && <div className="theme-component-items">{items.map((item, index) => <article key={index}><strong>{text(item, "value", text(item, "title", text(item, "question", `Item ${index + 1}`)))}</strong>{text(item, "description", text(item, "answer")) && <p>{text(item, "description", text(item, "answer"))}</p>}</article>)}</div>}</div></section>;
158
+ }
159
+
160
+ export function Home({ sections, products, posts, services, cases, site, template, submitContact, ImageComponent = ThemeImageView }: HomeProps & { ImageComponent?: ThemeImageComponent }) {
85
161
  const visible = [...sections].filter((section) => section.enabled).sort((a, b) => a.order - b.order);
86
162
  const rendered = visible.length ? visible : template.fallbackSections(site.modules);
87
163
  const catalog = site.settings?.catalog ?? { showCategory: true, showDescription: true, desktopColumns: 4 as const };
88
164
  return <>{rendered.map((section, index) => {
89
165
  if (section.type === "hero") return <Hero key={section.id || index} section={section} site={site} action={template.primaryAction(site.modules)} priority={index === 0} ImageComponent={ImageComponent} />;
90
166
  if (section.type === "banner-carousel") return <BannerCarousel key={section.id || index} banners={banners(section.data)} autoplay={section.data.autoplay !== false} priority={index === 0} ImageComponent={ImageComponent} />;
167
+ if (section.type === "theme-component") return <ThemeComponent key={section.id || index} section={section} submitContact={submitContact} />;
91
168
  if (["image-text", "rich-text", "cta"].includes(section.type)) return <TextSection key={section.id || index} section={section} ImageComponent={ImageComponent} />;
92
169
  if (section.type === "products-grid" || section.type === "products-carousel") {
93
170
  const category = productCategory(section.data);
@@ -1,7 +1,7 @@
1
1
  "use client";
2
2
 
3
3
  import { useMemo, useState, type CSSProperties } from "react";
4
- import { productUrl, type NuvlerStoreThemeDefinition, type ThemeCartItem, type ThemeCategory, type ThemeEditorialItem, type ThemeHomeSection, type ThemeNavigationItem, type ThemePageSummary, type ThemeProduct, type ThemeRuntimeAdapters, type ThemeSite } from "@nuvler/theme-sdk";
4
+ import { productUrl, type NuvlerStoreThemeDefinition, type ThemeCartItem, type ThemeCategory, type ThemeEditorialItem, type ThemeHomeSection, type ThemeNavigationItem, type ThemePageSummary, type ThemeProduct, type ThemeRuntimeAdapters, type ThemeRuntimeSdk, type ThemeSite } from "@nuvler/theme-sdk";
5
5
  import { nuvlerDefaultTheme } from "./definition.js";
6
6
  import { ThemeInteractionProvider } from "./product-detail-interactive.js";
7
7
  import { plainText, ThemeImageView } from "./shared.js";
@@ -26,6 +26,7 @@ export interface NuvlerDefaultThemeProps {
26
26
  context: PreviewContext;
27
27
  route?: PreviewRoute;
28
28
  adapters?: ThemeRuntimeAdapters;
29
+ sdk?: ThemeRuntimeSdk;
29
30
  }
30
31
 
31
32
  interface PreviewCartItem extends ThemeCartItem {
@@ -47,7 +48,7 @@ function EditorialPreview({ items, basePath }: { items: ThemeEditorialItem[]; ba
47
48
  }
48
49
 
49
50
  export function createNuvlerDefaultRuntime(themeDefinition: NuvlerStoreThemeDefinition) {
50
- function Theme({ context, route = { type: "home" }, adapters }: NuvlerDefaultThemeProps) {
51
+ function Theme({ context, route = { type: "home" }, adapters, sdk }: NuvlerDefaultThemeProps) {
51
52
  const [cartItems, setCartItems] = useState<PreviewCartItem[]>([]);
52
53
  const [cartOpen, setCartOpen] = useState(false);
53
54
  const { Header, Footer, Home, ProductDetail, ProductGrid } = themeDefinition.components;
@@ -93,7 +94,7 @@ export function createNuvlerDefaultRuntime(themeDefinition: NuvlerStoreThemeDefi
93
94
  };
94
95
  const cartButton = <button type="button" className="cart-button" onClick={() => setCartOpen(true)} aria-label={`Abrir carrinho com ${cartCount} itens`}><svg viewBox="0 0 24 24" aria-hidden="true"><path d="M3 4h2l2 11h10l2-8H6M9 20h.01M17 20h.01" /></svg>{cartCount > 0 && <span>{Math.min(cartCount, 99)}</span>}</button>;
95
96
  let content;
96
- if (route.type === "home") content = <main><Home sections={context.home.content.sections} products={context.catalog.products} posts={context.editorial.posts} services={context.editorial.services} cases={context.editorial.cases} site={site} template={themeDefinition.template} /></main>;
97
+ if (route.type === "home") content = <main><Home sections={context.home.content.sections} products={context.catalog.products} posts={context.editorial.posts} services={context.editorial.services} cases={context.editorial.cases} site={site} submitContact={sdk?.contact?.submit} template={themeDefinition.template} /></main>;
97
98
  else if (route.type === "product") content = <main className="product-page"><div className="store-container"><nav className="breadcrumbs" aria-label="Navegação estrutural"><a href="/">Início</a><span>/</span><a href="/produtos">Produtos</a><span>/</span><strong>{route.product.title}</strong></nav><ProductDetail product={route.product} contact={site.settings?.contact} productUrl={window.location.href} descriptionContent={<p>{plainText(route.product.description)}</p>} onAddToCart={addToCart} /></div></main>;
98
99
  else if (route.type === "catalog") content = <main className="catalog-page"><section className="catalog-hero"><div className="store-container"><span>Nosso catálogo</span><h1>{route.search ? `Busca por “${route.search}”` : "Todos os produtos"}</h1><p>{route.pagination.total} produto(s)</p></div></section><div className="store-container catalog-layout"><aside className="category-filter catalog-filters"><form action={route.categoryPath.length ? `/${route.categoryPath.join("/")}` : "/produtos"} className="catalog-filter-form"><label htmlFor="preview-catalog-search">Buscar no catálogo</label><div className="catalog-filter-search"><input id="preview-catalog-search" name="busca" type="search" defaultValue={route.search} placeholder="Nome do produto" /><button type="submit" aria-label="Pesquisar">⌕</button></div></form>{route.facets.length > 0 && <form className="catalog-variant-filters">{route.search && <input type="hidden" name="busca" value={route.search} />}{route.facets.map((facet) => <fieldset className="catalog-filter-section" key={facet.name}><legend>{facet.name}</legend>{facet.values.map(({ value, count }) => { const token = `${facet.name}::${value}`; return <label className="catalog-filter-checkbox" key={token}><input type="checkbox" name="variante" value={token} defaultChecked={route.variants.includes(token)} /><span>{value}</span><small>{count}</small></label>; })}</fieldset>)}<button type="submit" className="button button-primary button-block">Aplicar filtros</button></form>}</aside><section className="catalog-results"><ProductGrid products={route.products} columns={site.settings?.catalog?.desktopColumns || 3} showCategory={site.settings?.catalog?.showCategory} showDescription={site.settings?.catalog?.showDescription} />{route.pagination.totalPages > 1 && <nav className="catalog-pagination" aria-label="Paginação dos produtos"><a className={route.pagination.hasPreviousPage ? "" : "disabled"} href={catalogHref(route, Math.max(1, route.pagination.page - 1))}><span>‹</span> Anterior</a><div className="catalog-pagination-pages"><span className="catalog-pagination-item"><a className="active" href={catalogHref(route, route.pagination.page)}>{route.pagination.page}</a></span></div><a className={route.pagination.hasNextPage ? "" : "disabled"} href={catalogHref(route, Math.min(route.pagination.totalPages, route.pagination.page + 1))}>Próxima <span>›</span></a></nav>}</section></div></main>;
99
100
  else if (route.type === "editorial-list") content = <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"><EditorialPreview items={route.items} basePath={route.basePath} /></div></section></main>;
@@ -1525,6 +1525,137 @@ select {
1525
1525
  margin-top: 28px;
1526
1526
  }
1527
1527
 
1528
+ .theme-component-section {
1529
+ border-top: 1px solid var(--store-line);
1530
+ background: var(--store-surface);
1531
+ }
1532
+
1533
+ .theme-component-section > .store-container > span,
1534
+ .contact-form-copy > span {
1535
+ display: block;
1536
+ margin-bottom: 10px;
1537
+ color: var(--color-primary);
1538
+ font-size: 11px;
1539
+ font-weight: 900;
1540
+ letter-spacing: .14em;
1541
+ text-transform: uppercase;
1542
+ }
1543
+
1544
+ .theme-component-section h2 {
1545
+ margin: 0;
1546
+ font-size: clamp(30px, 4vw, 48px);
1547
+ letter-spacing: -.04em;
1548
+ }
1549
+
1550
+ .theme-component-section p {
1551
+ color: var(--store-muted);
1552
+ line-height: 1.7;
1553
+ }
1554
+
1555
+ .theme-component-items {
1556
+ display: grid;
1557
+ grid-template-columns: repeat(3, minmax(0, 1fr));
1558
+ gap: 18px;
1559
+ margin-top: 32px;
1560
+ }
1561
+
1562
+ .theme-component-items article {
1563
+ border: 1px solid var(--store-line);
1564
+ border-radius: var(--border-radius);
1565
+ background: var(--store-background);
1566
+ padding: 24px;
1567
+ }
1568
+
1569
+ .theme-component-video {
1570
+ display: block;
1571
+ width: 100%;
1572
+ max-height: 720px;
1573
+ margin-top: 32px;
1574
+ border-radius: var(--border-radius);
1575
+ background: #000;
1576
+ }
1577
+
1578
+ .contact-form-layout {
1579
+ display: grid;
1580
+ grid-template-columns: minmax(0, .8fr) minmax(0, 1.2fr);
1581
+ align-items: start;
1582
+ gap: 64px;
1583
+ }
1584
+
1585
+ .contact-form-copy p {
1586
+ max-width: 520px;
1587
+ margin-top: 18px;
1588
+ }
1589
+
1590
+ .contact-form {
1591
+ display: grid;
1592
+ grid-template-columns: repeat(2, minmax(0, 1fr));
1593
+ gap: 18px;
1594
+ border: 1px solid var(--store-line);
1595
+ border-radius: var(--border-radius);
1596
+ background: var(--store-background);
1597
+ padding: 28px;
1598
+ }
1599
+
1600
+ .contact-form label {
1601
+ display: grid;
1602
+ gap: 8px;
1603
+ color: var(--store-text);
1604
+ font-size: 13px;
1605
+ font-weight: 750;
1606
+ }
1607
+
1608
+ .contact-form input,
1609
+ .contact-form textarea,
1610
+ .contact-form select {
1611
+ width: 100%;
1612
+ border: 1px solid var(--store-line);
1613
+ border-radius: calc(var(--border-radius) * .65);
1614
+ background: var(--store-surface);
1615
+ padding: 12px 14px;
1616
+ color: var(--store-text);
1617
+ font: inherit;
1618
+ }
1619
+
1620
+ .contact-form input:focus,
1621
+ .contact-form textarea:focus,
1622
+ .contact-form select:focus {
1623
+ border-color: var(--color-primary);
1624
+ outline: 3px solid color-mix(in srgb, var(--color-primary), transparent 84%);
1625
+ }
1626
+
1627
+ .contact-form-wide {
1628
+ grid-column: 1 / -1;
1629
+ }
1630
+
1631
+ .contact-form .contact-form-checkbox {
1632
+ display: flex;
1633
+ flex-direction: row;
1634
+ align-items: flex-start;
1635
+ gap: 10px;
1636
+ font-weight: 500;
1637
+ line-height: 1.55;
1638
+ }
1639
+
1640
+ .contact-form .contact-form-checkbox input {
1641
+ width: 18px;
1642
+ height: 18px;
1643
+ margin-top: 2px;
1644
+ padding: 0;
1645
+ accent-color: var(--color-primary);
1646
+ }
1647
+
1648
+ .contact-form-feedback {
1649
+ margin: 12px 0 0;
1650
+ color: var(--color-primary);
1651
+ font-size: 13px;
1652
+ font-weight: 700;
1653
+ }
1654
+
1655
+ .contact-form-error {
1656
+ color: #b42318;
1657
+ }
1658
+
1528
1659
  .image-text-section {
1529
1660
  background: var(--store-surface);
1530
1661
  }
@@ -2908,6 +3039,24 @@ select {
2908
3039
  padding: 62px 0;
2909
3040
  }
2910
3041
 
3042
+ .contact-form-layout,
3043
+ .theme-component-items {
3044
+ grid-template-columns: 1fr;
3045
+ }
3046
+
3047
+ .contact-form-layout {
3048
+ gap: 32px;
3049
+ }
3050
+
3051
+ .contact-form {
3052
+ grid-template-columns: 1fr;
3053
+ padding: 20px;
3054
+ }
3055
+
3056
+ .contact-form-wide {
3057
+ grid-column: auto;
3058
+ }
3059
+
2911
3060
  .section-heading {
2912
3061
  align-items: flex-start;
2913
3062
  flex-direction: column;
@@ -4,7 +4,7 @@
4
4
  "name": "__NUVLER_THEME_NAME__",
5
5
  "version": "0.1.0",
6
6
  "runtimeVersion": "1",
7
- "sdkVersion": "^1.2.2",
7
+ "sdkVersion": "^1.3.0",
8
8
  "entry": "src/theme.tsx",
9
9
  "styles": ["src/theme.css"],
10
10
  "presentation": {
@@ -13,13 +13,13 @@
13
13
  "typecheck": "tsc -p tsconfig.json --noEmit"
14
14
  },
15
15
  "dependencies": {
16
- "@nuvler/theme-sdk": "^1.2.2"
16
+ "@nuvler/theme-sdk": "^1.3.0"
17
17
  },
18
18
  "peerDependencies": {
19
19
  "react": "^19.0.0"
20
20
  },
21
21
  "devDependencies": {
22
- "@nuvler/cli": "^0.4.4",
22
+ "@nuvler/cli": "^0.5.0",
23
23
  "@types/react": "^19.0.0",
24
24
  "react": "^19.0.0",
25
25
  "typescript": "^5.9.0"
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "@nuvler/cli",
3
- "version": "0.4.4",
3
+ "version": "0.5.0",
4
4
  "description": "CLI oficial para criação, validação, preview e empacotamento de temas Nuvler",
5
5
  "type": "module",
6
6
  "bin": {
7
- "nuvler": "./dist/nuvler.js"
7
+ "nuvler": "dist/nuvler.js"
8
8
  },
9
9
  "main": "./dist/nuvler.js",
10
10
  "exports": {
@@ -20,8 +20,8 @@
20
20
  "typecheck": "tsc -p tsconfig.json --noEmit"
21
21
  },
22
22
  "dependencies": {
23
- "@nuvler/theme-schema": "^1.2.0",
24
- "@nuvler/theme-sdk": "^1.2.2",
23
+ "@nuvler/theme-schema": "^1.3.0",
24
+ "@nuvler/theme-sdk": "^1.3.0",
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.2.2",
13
+ "@nuvler/theme-sdk": "1.3.0",
14
14
  "react": "19.2.8",
15
15
  "react-dom": "19.2.8"
16
16
  },
@@ -15,30 +15,20 @@ img {
15
15
  max-width: 100%;
16
16
  }
17
17
 
18
- .nuvler-platform-footer {
19
- position: relative;
20
- z-index: 1;
21
- display: flex;
22
- min-height: 76px;
18
+ .nuvler-platform-brand {
19
+ display: inline-flex;
23
20
  align-items: center;
24
21
  justify-content: center;
25
- border-top: 1px solid rgb(255 255 255 / 10%);
26
- background: #0b1220;
27
- padding: 20px 24px;
22
+ margin-left: auto;
28
23
  }
29
24
 
30
- .nuvler-platform-footer img {
25
+ .nuvler-platform-brand img {
31
26
  width: 132px;
32
27
  height: auto;
33
28
  }
34
29
 
35
30
  @media (max-width: 640px) {
36
- .nuvler-platform-footer {
37
- min-height: 68px;
38
- padding-block: 18px;
39
- }
40
-
41
- .nuvler-platform-footer img {
31
+ .nuvler-platform-brand img {
42
32
  width: 116px;
43
33
  }
44
34
  }