@nuvler/cli 0.5.0 → 0.5.2
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/commands/theme/create.js +2 -2
- package/dist/index.js +1 -1
- package/dist/migrate/analyzer.js +90 -0
- package/dist/migrate/analyzer.js.map +1 -1
- package/dist/migrate/generation/fidelity-pass.js +16 -6
- package/dist/migrate/generation/fidelity-pass.js.map +1 -1
- package/dist/migrate/generator.js +101 -27
- package/dist/migrate/generator.js.map +1 -1
- package/dist/migrate/transform/source-transformer.js +92 -13
- package/dist/migrate/transform/source-transformer.js.map +1 -1
- package/dist/migrate/transformer.js +57 -3
- package/dist/migrate/transformer.js.map +1 -1
- package/dist/nuvler.js +378 -164
- package/dist/nuvler.js.map +1 -1
- package/dist/preview/prepare.js +2 -78
- package/dist/preview/prepare.js.map +1 -1
- package/dist/templates/nuvler-atelier/nuvler.theme.json +24 -10
- package/dist/templates/nuvler-atelier/package.json +3 -3
- package/dist/templates/nuvler-default/nuvler.theme.json +24 -10
- package/dist/templates/nuvler-default/package.json +9 -4
- package/dist/templates/nuvler-default/src/home.tsx +4 -9
- package/dist/templates/starter/nuvler.theme.json +1 -1
- package/dist/templates/starter/package.json +2 -2
- package/package.json +3 -3
- package/preview-host/package.json +1 -1
- package/preview-host/src/main.tsx +7 -2
- package/preview-host/vendor/theme-runtime/default-theme.tsx +35 -11
- package/preview-host/vite.config.ts +10 -0
package/dist/preview/prepare.js
CHANGED
|
@@ -1,83 +1,8 @@
|
|
|
1
|
-
import { readFile } from "node:fs/promises";
|
|
2
|
-
import path from "node:path";
|
|
3
1
|
import { ThemeContextSchema } from "@nuvler/theme-schema";
|
|
4
2
|
import { loadThemeContext } from "../api/theme-context.js";
|
|
5
3
|
import { loadDeveloperSession, requireAuthorizedTenant, } from "../config/developer-session.js";
|
|
6
4
|
import { readThemeProjectConfig } from "../config/project.js";
|
|
7
5
|
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
|
-
}
|
|
81
6
|
export async function prepareThemePreview(options) {
|
|
82
7
|
const project = await loadThemeProject(options.themeDirectory);
|
|
83
8
|
const configured = await readThemeProjectConfig(project.directory);
|
|
@@ -90,13 +15,12 @@ export async function prepareThemePreview(options) {
|
|
|
90
15
|
if (context.store.slug !== tenant.slug) {
|
|
91
16
|
throw new Error(`A API retornou contexto do tenant "${context.store.slug}" para "${tenant.slug}".`);
|
|
92
17
|
}
|
|
93
|
-
const preview = await migrationSeedContext(project.directory, context);
|
|
94
18
|
return {
|
|
95
19
|
project,
|
|
96
|
-
context:
|
|
20
|
+
context: ThemeContextSchema.parse(context),
|
|
97
21
|
apiUrl: session.apiUrl,
|
|
98
22
|
tenant,
|
|
99
|
-
migrationSeedSections:
|
|
23
|
+
migrationSeedSections: 0,
|
|
100
24
|
};
|
|
101
25
|
}
|
|
102
26
|
//# sourceMappingURL=prepare.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prepare.js","sourceRoot":"","sources":["../../src/preview/prepare.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"prepare.js","sourceRoot":"","sources":["../../src/preview/prepare.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAqB,MAAM,sBAAsB,CAAC;AAC7E,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;AAc1E,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,CACb,sCAAsC,OAAO,CAAC,KAAK,CAAC,IAAI,WAAW,MAAM,CAAC,IAAI,IAAI,CACnF,CAAC;IACJ,CAAC;IACD,OAAO;QACL,OAAO;QACP,OAAO,EAAE,kBAAkB,CAAC,KAAK,CAAC,OAAO,CAAC;QAC1C,MAAM,EAAE,OAAO,CAAC,MAAM;QACtB,MAAM;QACN,qBAAqB,EAAE,CAAC;KACzB,CAAC;AACJ,CAAC"}
|
|
@@ -2,22 +2,36 @@
|
|
|
2
2
|
"schemaVersion": 1,
|
|
3
3
|
"id": "nuvler-atelier",
|
|
4
4
|
"name": "Nuvler Atelier",
|
|
5
|
-
"version": "0.1.
|
|
5
|
+
"version": "0.1.4",
|
|
6
6
|
"runtimeVersion": "1",
|
|
7
|
-
"sdkVersion": "^1.3.
|
|
7
|
+
"sdkVersion": "^1.3.2",
|
|
8
8
|
"entry": "src/theme.tsx",
|
|
9
|
-
"styles": [
|
|
9
|
+
"styles": [
|
|
10
|
+
"src/theme.css"
|
|
11
|
+
],
|
|
10
12
|
"presentation": {
|
|
11
13
|
"description": "Tema editorial com composição assimétrica, imagens protagonistas e navegação refinada.",
|
|
12
14
|
"templateId": "nuvler-atelier",
|
|
13
15
|
"colors": {
|
|
14
|
-
"primary": "#153f3a",
|
|
15
|
-
"secondary": "#ff6b3d",
|
|
16
|
-
"background": "#f3efe5",
|
|
17
|
-
"text": "#17201e",
|
|
18
|
-
"
|
|
19
|
-
"
|
|
16
|
+
"primary": "#153f3a",
|
|
17
|
+
"secondary": "#ff6b3d",
|
|
18
|
+
"background": "#f3efe5",
|
|
19
|
+
"text": "#17201e",
|
|
20
|
+
"primaryText": "#ffffff",
|
|
21
|
+
"secondaryText": "#17201e",
|
|
22
|
+
"accent": "#ff6b3d",
|
|
23
|
+
"surface": "#fffaf0",
|
|
24
|
+
"surfaceAlt": "#e8e1d3",
|
|
25
|
+
"textMuted": "#6b716e",
|
|
26
|
+
"border": "#d5cdbd",
|
|
27
|
+
"headerBackground": "#f3efe5",
|
|
28
|
+
"headerText": "#17201e",
|
|
29
|
+
"footerBackground": "#101c1a",
|
|
30
|
+
"footerText": "#ffffff"
|
|
20
31
|
},
|
|
21
|
-
"layout": {
|
|
32
|
+
"layout": {
|
|
33
|
+
"containerWidth": 1380,
|
|
34
|
+
"borderRadius": 8
|
|
35
|
+
}
|
|
22
36
|
}
|
|
23
37
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nuvler-theme-nuvler-atelier",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.4",
|
|
4
4
|
"private": true,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"scripts": {
|
|
@@ -13,13 +13,13 @@
|
|
|
13
13
|
"typecheck": "tsc -p tsconfig.json --noEmit"
|
|
14
14
|
},
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"@nuvler/theme-sdk": "^1.3.
|
|
16
|
+
"@nuvler/theme-sdk": "^1.3.2"
|
|
17
17
|
},
|
|
18
18
|
"peerDependencies": {
|
|
19
19
|
"react": "^19.0.0"
|
|
20
20
|
},
|
|
21
21
|
"devDependencies": {
|
|
22
|
-
"@nuvler/cli": "^0.5.
|
|
22
|
+
"@nuvler/cli": "^0.5.2",
|
|
23
23
|
"@types/react": "^19.0.0",
|
|
24
24
|
"react": "^19.0.0",
|
|
25
25
|
"typescript": "^5.9.0"
|
|
@@ -2,22 +2,36 @@
|
|
|
2
2
|
"schemaVersion": 1,
|
|
3
3
|
"id": "nuvler-default",
|
|
4
4
|
"name": "Nuvler Default",
|
|
5
|
-
"version": "1.0.
|
|
5
|
+
"version": "1.0.7",
|
|
6
6
|
"runtimeVersion": "1",
|
|
7
|
-
"sdkVersion": "^1.3.
|
|
7
|
+
"sdkVersion": "^1.3.2",
|
|
8
8
|
"entry": "src/theme.tsx",
|
|
9
|
-
"styles": [
|
|
9
|
+
"styles": [
|
|
10
|
+
"src/theme.css"
|
|
11
|
+
],
|
|
10
12
|
"presentation": {
|
|
11
13
|
"description": "Tema oficial completo, indicado para produção e usado como base confiável.",
|
|
12
14
|
"templateId": "nuvler-default",
|
|
13
15
|
"colors": {
|
|
14
|
-
"primary": "#176b3a",
|
|
15
|
-
"secondary": "#d99b31",
|
|
16
|
-
"background": "#f7f7f2",
|
|
17
|
-
"text": "#18221b",
|
|
18
|
-
"
|
|
19
|
-
"
|
|
16
|
+
"primary": "#176b3a",
|
|
17
|
+
"secondary": "#d99b31",
|
|
18
|
+
"background": "#f7f7f2",
|
|
19
|
+
"text": "#18221b",
|
|
20
|
+
"primaryText": "#ffffff",
|
|
21
|
+
"secondaryText": "#18221b",
|
|
22
|
+
"accent": "#b45309",
|
|
23
|
+
"surface": "#ffffff",
|
|
24
|
+
"surfaceAlt": "#eef2e9",
|
|
25
|
+
"textMuted": "#657068",
|
|
26
|
+
"border": "#dfe4dd",
|
|
27
|
+
"headerBackground": "#ffffff",
|
|
28
|
+
"headerText": "#18221b",
|
|
29
|
+
"footerBackground": "#14251a",
|
|
30
|
+
"footerText": "#f7f7f2"
|
|
20
31
|
},
|
|
21
|
-
"layout": {
|
|
32
|
+
"layout": {
|
|
33
|
+
"containerWidth": 1280,
|
|
34
|
+
"borderRadius": 18
|
|
35
|
+
}
|
|
22
36
|
}
|
|
23
37
|
}
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nuvler/theme-default",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.7",
|
|
4
4
|
"description": "Tema padrão oficial da Nuvler",
|
|
5
5
|
"type": "module",
|
|
6
|
-
"sideEffects": [
|
|
6
|
+
"sideEffects": [
|
|
7
|
+
"**/*.css"
|
|
8
|
+
],
|
|
7
9
|
"main": "./dist/src/index.js",
|
|
8
10
|
"types": "./dist/src/index.d.ts",
|
|
9
11
|
"exports": {
|
|
@@ -45,7 +47,10 @@
|
|
|
45
47
|
"./styles.css": "./dist/theme.css",
|
|
46
48
|
"./manifest": "./dist/nuvler.theme.json"
|
|
47
49
|
},
|
|
48
|
-
"files": [
|
|
50
|
+
"files": [
|
|
51
|
+
"dist",
|
|
52
|
+
"README.md"
|
|
53
|
+
],
|
|
49
54
|
"scripts": {
|
|
50
55
|
"dev": "nuvler theme dev --theme .",
|
|
51
56
|
"validate": "nuvler theme validate --theme .",
|
|
@@ -59,7 +64,7 @@
|
|
|
59
64
|
"react": "^19.0.0"
|
|
60
65
|
},
|
|
61
66
|
"dependencies": {
|
|
62
|
-
"@nuvler/theme-sdk": "^1.3.
|
|
67
|
+
"@nuvler/theme-sdk": "^1.3.2"
|
|
63
68
|
},
|
|
64
69
|
"devDependencies": {
|
|
65
70
|
"@types/react": "^19.0.0",
|
|
@@ -97,12 +97,7 @@ function TextSection({ section, ImageComponent = ThemeImageView }: { section: Th
|
|
|
97
97
|
function ContactForm({ section, submitContact }: { section: ThemeHomeSection; submitContact?: (submission: ThemeContactSubmissionInput) => Promise<unknown> }) {
|
|
98
98
|
const props = record(section.data, "props");
|
|
99
99
|
const configured = records(props, "fields");
|
|
100
|
-
const fields = 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
|
-
];
|
|
100
|
+
const fields = configured;
|
|
106
101
|
const [status, setStatus] = useState<"idle" | "sending" | "success" | "error">("idle");
|
|
107
102
|
const [error, setError] = useState("");
|
|
108
103
|
const submit = async (event: FormEvent<HTMLFormElement>) => {
|
|
@@ -136,7 +131,7 @@ function ContactForm({ section, submitContact }: { section: ThemeHomeSection; su
|
|
|
136
131
|
setError(cause instanceof Error ? cause.message : "Não foi possível enviar o contato.");
|
|
137
132
|
}
|
|
138
133
|
};
|
|
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>}
|
|
134
|
+
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>}{text(props, "title") && <h2>{text(props, "title")}</h2>}{text(props, "description") && <p>{text(props, "description")}</p>}</div><form className="contact-form" onSubmit={(event) => void submit(event)}>{fields.map((field) => {
|
|
140
135
|
const key = text(field, "key");
|
|
141
136
|
const type = text(field, "type", "text");
|
|
142
137
|
const label = text(field, "label", key);
|
|
@@ -145,7 +140,7 @@ function ContactForm({ section, submitContact }: { section: ThemeHomeSection; su
|
|
|
145
140
|
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
141
|
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
142
|
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" ? "
|
|
143
|
+
})}<div className="contact-form-wide"><button className="button button-primary" disabled={status === "sending"} type="submit">{status === "sending" ? "" : text(props, "submitLabel")}</button>{status === "success" && text(props, "successMessage") && <p className="contact-form-feedback" role="status">{text(props, "successMessage")}</p>}{status === "error" && <p className="contact-form-feedback contact-form-error" role="alert">{error}</p>}</div></form></div></section>;
|
|
149
144
|
}
|
|
150
145
|
|
|
151
146
|
function ThemeComponent({ section, submitContact }: { section: ThemeHomeSection; submitContact?: HomeProps["submitContact"] }) {
|
|
@@ -154,7 +149,7 @@ function ThemeComponent({ section, submitContact }: { section: ThemeHomeSection;
|
|
|
154
149
|
if (componentKey === "contact-form" || componentKey.endsWith("-form")) return <ContactForm section={section} submitContact={submitContact} />;
|
|
155
150
|
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
151
|
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) =>
|
|
152
|
+
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) => { const itemTitle = text(item, "value", text(item, "title", text(item, "question"))); return <article key={index}>{itemTitle && <strong>{itemTitle}</strong>}{text(item, "description", text(item, "answer")) && <p>{text(item, "description", text(item, "answer"))}</p>}</article>; })}</div>}</div></section>;
|
|
158
153
|
}
|
|
159
154
|
|
|
160
155
|
export function Home({ sections, products, posts, services, cases, site, template, submitContact, ImageComponent = ThemeImageView }: HomeProps & { ImageComponent?: ThemeImageComponent }) {
|
|
@@ -13,13 +13,13 @@
|
|
|
13
13
|
"typecheck": "tsc -p tsconfig.json --noEmit"
|
|
14
14
|
},
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"@nuvler/theme-sdk": "^1.3.
|
|
16
|
+
"@nuvler/theme-sdk": "^1.3.2"
|
|
17
17
|
},
|
|
18
18
|
"peerDependencies": {
|
|
19
19
|
"react": "^19.0.0"
|
|
20
20
|
},
|
|
21
21
|
"devDependencies": {
|
|
22
|
-
"@nuvler/cli": "^0.5.
|
|
22
|
+
"@nuvler/cli": "^0.5.2",
|
|
23
23
|
"@types/react": "^19.0.0",
|
|
24
24
|
"react": "^19.0.0",
|
|
25
25
|
"typescript": "^5.9.0"
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nuvler/cli",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.2",
|
|
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.1",
|
|
24
|
+
"@nuvler/theme-sdk": "^1.3.2",
|
|
25
25
|
"@vitejs/plugin-react": "^6.0.5",
|
|
26
26
|
"commander": "^15.0.0",
|
|
27
27
|
"react": "19.2.8",
|
|
@@ -87,8 +87,7 @@ function routeFromLocalData(url: URL): ThemeRoute | null {
|
|
|
87
87
|
return item ? { type: "editorial-detail", basePath: group.basePath, item } : { type: "not-found", pathname: url.pathname };
|
|
88
88
|
}
|
|
89
89
|
}
|
|
90
|
-
|
|
91
|
-
return page ? { type: "page", title: page.title } : null;
|
|
90
|
+
return null;
|
|
92
91
|
}
|
|
93
92
|
|
|
94
93
|
function PreviewApp() {
|
|
@@ -112,6 +111,12 @@ function PreviewApp() {
|
|
|
112
111
|
if (currentRequest === requestId.current) setRoute({ type: "product", product });
|
|
113
112
|
return;
|
|
114
113
|
}
|
|
114
|
+
if (url.pathname.split("/").filter(Boolean).length === 1) {
|
|
115
|
+
const slug = decodeURIComponent(url.pathname.slice(1));
|
|
116
|
+
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
|
+
if (currentRequest === requestId.current) setRoute({ type: "page", title: page.title, slug: page.slug, content: page.content });
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
115
120
|
if (url.pathname === "/produtos" || url.pathname.startsWith("/categoria/")) {
|
|
116
121
|
const categoryPath = url.pathname.startsWith("/categoria/")
|
|
117
122
|
? url.pathname.slice("/categoria/".length).split("/").filter(Boolean).map(decodeURIComponent)
|
|
@@ -385,15 +385,20 @@ function dataRecords(data: Record<string, unknown>, field: string): Record<strin
|
|
|
385
385
|
: [];
|
|
386
386
|
}
|
|
387
387
|
|
|
388
|
+
function formatWhatsapp(value: string): string {
|
|
389
|
+
const digits = value.replace(/\D/g, "").slice(0, 11);
|
|
390
|
+
if (!digits) return "";
|
|
391
|
+
if (digits.length <= 2) return `(${digits}`;
|
|
392
|
+
const number = digits.slice(2);
|
|
393
|
+
return number.length <= 5
|
|
394
|
+
? `(${digits.slice(0, 2)}) ${number}`
|
|
395
|
+
: `(${digits.slice(0, 2)}) ${number.slice(0, 5)}-${number.slice(5)}`;
|
|
396
|
+
}
|
|
397
|
+
|
|
388
398
|
function ContactFormComponent({ section, sdk }: ThemeSectionRendererProps) {
|
|
389
399
|
const props = dataRecord(section.data, "props");
|
|
390
400
|
const configuredFields = dataRecords(props, "fields");
|
|
391
|
-
const fields = configuredFields
|
|
392
|
-
{ key: "name", label: "Nome", type: "text", required: true },
|
|
393
|
-
{ key: "email", label: "E-mail", type: "email", required: true },
|
|
394
|
-
{ key: "phone", label: "Telefone", type: "tel", required: false },
|
|
395
|
-
{ key: "message", label: "Mensagem", type: "textarea", required: true },
|
|
396
|
-
];
|
|
401
|
+
const fields = configuredFields;
|
|
397
402
|
const [status, setStatus] = useState<"idle" | "sending" | "success" | "error">("idle");
|
|
398
403
|
const [error, setError] = useState("");
|
|
399
404
|
|
|
@@ -458,7 +463,7 @@ function ContactFormComponent({ section, sdk }: ThemeSectionRendererProps) {
|
|
|
458
463
|
<span>{label}{required && <small aria-hidden="true"> *</small>}</span>
|
|
459
464
|
{type === "textarea"
|
|
460
465
|
? <textarea name={key} placeholder={dataString(field, "placeholder")} required={required} rows={5} />
|
|
461
|
-
: <input name={key} placeholder={dataString(field, "placeholder")} required={required} type={["email", "tel", "url", "number"].includes(type) ? type : "text"} />}
|
|
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} />}
|
|
462
467
|
</label>;
|
|
463
468
|
})}
|
|
464
469
|
<div className="contact-form-wide">
|
|
@@ -472,6 +477,24 @@ function ContactFormComponent({ section, sdk }: ThemeSectionRendererProps) {
|
|
|
472
477
|
</div></section>;
|
|
473
478
|
}
|
|
474
479
|
|
|
480
|
+
function PageContent({ route, context, adapters, sdk }: {
|
|
481
|
+
route: Extract<ThemeRoute, { type: "page" }>;
|
|
482
|
+
context: ThemeContext;
|
|
483
|
+
adapters: ThemeRuntimeAdapters;
|
|
484
|
+
sdk?: ThemeRuntimeSdk;
|
|
485
|
+
}) {
|
|
486
|
+
return <main className="store-section"><article className="store-container editorial-content">
|
|
487
|
+
<h1>{route.title}</h1>
|
|
488
|
+
{route.content.blocks.map((block, index) => {
|
|
489
|
+
if (block.type === "theme-component") return <ThemeComponentSection key={block.id || index} section={{ id: block.id, type: "theme-component", enabled: true, order: index, data: block.data }} context={context} adapters={adapters} sdk={sdk} />;
|
|
490
|
+
if (block.type === "header") return <h2 key={block.id || index}>{plainText(dataString(block.data, "text"))}</h2>;
|
|
491
|
+
if (block.type === "paragraph") return <p key={block.id || index}>{plainText(dataString(block.data, "text"))}</p>;
|
|
492
|
+
if (block.type === "delimiter") return <hr key={block.id || index} />;
|
|
493
|
+
return null;
|
|
494
|
+
})}
|
|
495
|
+
</article></main>;
|
|
496
|
+
}
|
|
497
|
+
|
|
475
498
|
function ThemeComponentSection(props: ThemeSectionRendererProps) {
|
|
476
499
|
const { section } = props;
|
|
477
500
|
const componentKey = dataString(section.data, "componentKey");
|
|
@@ -649,11 +672,12 @@ function ProductPage({ product, context, adapters }: {
|
|
|
649
672
|
</div></main>;
|
|
650
673
|
}
|
|
651
674
|
|
|
652
|
-
function RouteContent({ route, context, adapters, home }: {
|
|
675
|
+
function RouteContent({ route, context, adapters, home, sdk }: {
|
|
653
676
|
route: ThemeRoute;
|
|
654
677
|
context: ThemeContext;
|
|
655
678
|
adapters: ThemeRuntimeAdapters;
|
|
656
679
|
home: ReactNode;
|
|
680
|
+
sdk?: ThemeRuntimeSdk;
|
|
657
681
|
}) {
|
|
658
682
|
if (route.type === "home") return home;
|
|
659
683
|
if (route.type === "loading") return <main className="not-found-page"><div className="not-found-card"><span>Carregando</span><h1>Buscando conteúdo da loja</h1></div></main>;
|
|
@@ -662,7 +686,7 @@ function RouteContent({ route, context, adapters, home }: {
|
|
|
662
686
|
if (route.type === "product") return <ProductPage adapters={adapters} context={context} product={route.product} />;
|
|
663
687
|
if (route.type === "editorial-list") return <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"><EditorialCards adapters={adapters} basePath={route.basePath} items={route.items} /></div></section></main>;
|
|
664
688
|
if (route.type === "editorial-detail") return <main className="store-section"><article className="store-container editorial-content"><span>Conteúdo</span><h1>{route.item.title}</h1><p>{route.item.description}</p></article></main>;
|
|
665
|
-
return <
|
|
689
|
+
return <PageContent adapters={adapters} context={context} route={route} sdk={sdk} />;
|
|
666
690
|
}
|
|
667
691
|
|
|
668
692
|
function Footer({ context, adapters }: DefaultThemeProps) {
|
|
@@ -716,9 +740,9 @@ export function DefaultTheme({ context, adapters, route = { type: "home" }, sdk
|
|
|
716
740
|
const visible = context.home.content.sections.filter((section) => section.enabled).sort((a, b) => a.order - b.order);
|
|
717
741
|
const sections = visible.length ? visible : fallbackSections(context);
|
|
718
742
|
|
|
719
|
-
return <div className="store-shell nuvler-default-theme" data-theme-id="nuvler-default" data-theme-version="1.0.
|
|
743
|
+
return <div className="store-shell nuvler-default-theme" data-theme-id="nuvler-default" data-theme-version="1.0.7" style={style}>
|
|
720
744
|
<Header adapters={adapters} context={context} />
|
|
721
|
-
<div className="store-page"><RouteContent adapters={adapters} context={context} route={route} home={<main>{sections.map((section, index) => {
|
|
745
|
+
<div className="store-page"><RouteContent adapters={adapters} context={context} route={route} sdk={sdk} home={<main>{sections.map((section, index) => {
|
|
722
746
|
const Renderer = defaultSectionRegistry[section.type];
|
|
723
747
|
return Renderer ? <Renderer adapters={adapters} context={context} key={`${section.type}-${section.order}-${index}`} sdk={sdk} section={section} /> : null;
|
|
724
748
|
})}<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>
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { readFile } from "node:fs/promises";
|
|
2
2
|
import { existsSync } from "node:fs";
|
|
3
|
+
import { createRequire } from "node:module";
|
|
3
4
|
import path from "node:path";
|
|
4
5
|
import { fileURLToPath } from "node:url";
|
|
5
6
|
import react from "@vitejs/plugin-react";
|
|
@@ -82,6 +83,9 @@ function activeThemePlugin(
|
|
|
82
83
|
}
|
|
83
84
|
|
|
84
85
|
const previewHostDirectory = path.dirname(fileURLToPath(import.meta.url));
|
|
86
|
+
const moduleRequire = createRequire(import.meta.url);
|
|
87
|
+
const reactDirectory = path.dirname(moduleRequire.resolve("react/package.json"));
|
|
88
|
+
const reactDomDirectory = path.dirname(moduleRequire.resolve("react-dom/package.json"));
|
|
85
89
|
const toolingRoot = path.resolve(previewHostDirectory, "../..");
|
|
86
90
|
const isMonorepoPreview = existsSync(path.join(toolingRoot, "packages", "theme-runtime", "src", "index.ts"));
|
|
87
91
|
const runtimeEntry = isMonorepoPreview
|
|
@@ -117,6 +121,12 @@ export default defineConfig({
|
|
|
117
121
|
), react()],
|
|
118
122
|
resolve: {
|
|
119
123
|
alias: {
|
|
124
|
+
// Dependencies preserved from the migrated project (icons, UI kits,
|
|
125
|
+
// motion libraries) may resolve React from the theme's node_modules.
|
|
126
|
+
// Pin every React import to the preview host so hooks and the renderer
|
|
127
|
+
// always share the same module instance.
|
|
128
|
+
react: reactDirectory,
|
|
129
|
+
"react-dom": reactDomDirectory,
|
|
120
130
|
"@nuvler/theme-runtime": runtimeEntry,
|
|
121
131
|
...(isMonorepoPreview ? {
|
|
122
132
|
"@nuvler/theme-sdk": path.join(toolingRoot, "packages", "theme-sdk", "src", "index.ts"),
|