@nuvler/cli 0.5.15 → 0.5.17
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 +52 -20
- package/dist/api/theme-context.js.map +1 -1
- package/dist/commands/theme/create.js +1 -1
- package/dist/nuvler.js +43 -3
- package/dist/nuvler.js.map +1 -1
- package/dist/templates/nuvler-atelier/package.json +2 -2
- package/dist/templates/nuvler-default/nuvler.theme.json +1 -1
- package/dist/templates/nuvler-default/package.json +2 -2
- package/dist/templates/nuvler-default/src/contact-form.tsx +172 -0
- package/dist/templates/nuvler-default/src/home-data.ts +30 -0
- package/dist/templates/nuvler-default/src/home.tsx +2 -196
- package/dist/templates/nuvler-default/src/kit-group-selector.tsx +230 -0
- package/dist/templates/nuvler-default/src/kit-selection.ts +39 -0
- package/dist/templates/nuvler-default/src/product-detail-interactive.tsx +407 -114
- package/dist/templates/nuvler-default/src/product-detail.tsx +141 -59
- package/dist/templates/nuvler-default/src/products.tsx +143 -12
- package/dist/templates/nuvler-default/src/theme-component.tsx +29 -3
- package/dist/templates/nuvler-default/src/theme.css +369 -5
- package/dist/templates/nuvler-default/test/kit-detail.test.mjs +292 -0
- package/dist/templates/starter/package.json +2 -2
- package/package.json +3 -3
|
@@ -13,13 +13,13 @@
|
|
|
13
13
|
"typecheck": "tsc -p tsconfig.json --noEmit"
|
|
14
14
|
},
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"@nuvler/theme-sdk": "^1.4.
|
|
16
|
+
"@nuvler/theme-sdk": "^1.4.7"
|
|
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.17",
|
|
23
23
|
"@types/react": "^19.0.0",
|
|
24
24
|
"react": "^19.0.0",
|
|
25
25
|
"typescript": "^5.9.0"
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nuvler/theme-default",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.15",
|
|
4
4
|
"description": "Tema padrão oficial da Nuvler",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": [
|
|
@@ -65,7 +65,7 @@
|
|
|
65
65
|
"react": "^19.0.0"
|
|
66
66
|
},
|
|
67
67
|
"dependencies": {
|
|
68
|
-
"@nuvler/theme-sdk": "^1.4.
|
|
68
|
+
"@nuvler/theme-sdk": "^1.4.7"
|
|
69
69
|
},
|
|
70
70
|
"devDependencies": {
|
|
71
71
|
"@types/react": "^19.0.0",
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { useState, type FormEvent } from "react";
|
|
4
|
+
import type { ThemeHomeSection, ThemeContactSubmissionInput } from "@nuvler/theme-sdk";
|
|
5
|
+
import { text, record, records } from "./home-data.js";
|
|
6
|
+
|
|
7
|
+
export function ContactForm({
|
|
8
|
+
section,
|
|
9
|
+
submitContact,
|
|
10
|
+
}: {
|
|
11
|
+
section: ThemeHomeSection;
|
|
12
|
+
submitContact?: (submission: ThemeContactSubmissionInput) => Promise<unknown>;
|
|
13
|
+
}) {
|
|
14
|
+
const props = record(section.data, "props");
|
|
15
|
+
const configured = records(props, "fields");
|
|
16
|
+
const fields = configured;
|
|
17
|
+
const [status, setStatus] = useState<
|
|
18
|
+
"idle" | "sending" | "success" | "error"
|
|
19
|
+
>("idle");
|
|
20
|
+
const [error, setError] = useState("");
|
|
21
|
+
const submit = async (event: FormEvent<HTMLFormElement>) => {
|
|
22
|
+
event.preventDefault();
|
|
23
|
+
if (!submitContact) {
|
|
24
|
+
setStatus("error");
|
|
25
|
+
setError("O envio de contatos ainda não está disponível.");
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
const formElement = event.currentTarget;
|
|
29
|
+
const form = new FormData(formElement);
|
|
30
|
+
const values: ThemeContactSubmissionInput["values"] = {};
|
|
31
|
+
fields.forEach((field) => {
|
|
32
|
+
const key = text(field, "key");
|
|
33
|
+
if (!key) return;
|
|
34
|
+
if (text(field, "type") === "checkbox") {
|
|
35
|
+
values[key] = form.has(key);
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
const entries = form.getAll(key).map(String);
|
|
39
|
+
values[key] = entries.length > 1 ? entries : (entries[0] ?? "");
|
|
40
|
+
});
|
|
41
|
+
setStatus("sending");
|
|
42
|
+
setError("");
|
|
43
|
+
try {
|
|
44
|
+
await submitContact({
|
|
45
|
+
formKey: text(section.data, "componentKey", "contact-form"),
|
|
46
|
+
sectionId: section.id,
|
|
47
|
+
values,
|
|
48
|
+
pathname:
|
|
49
|
+
typeof window === "undefined" ? undefined : window.location.pathname,
|
|
50
|
+
});
|
|
51
|
+
formElement.reset();
|
|
52
|
+
setStatus("success");
|
|
53
|
+
} catch (cause) {
|
|
54
|
+
setStatus("error");
|
|
55
|
+
setError(
|
|
56
|
+
cause instanceof Error
|
|
57
|
+
? cause.message
|
|
58
|
+
: "Não foi possível enviar o contato.",
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
return (
|
|
63
|
+
<section className="store-section theme-component-section contact-form-section">
|
|
64
|
+
<div className="store-container contact-form-layout">
|
|
65
|
+
<div className="contact-form-copy">
|
|
66
|
+
{text(props, "eyebrow") && <span>{text(props, "eyebrow")}</span>}
|
|
67
|
+
{text(props, "title") && <h2>{text(props, "title")}</h2>}
|
|
68
|
+
{text(props, "description") && <p>{text(props, "description")}</p>}
|
|
69
|
+
</div>
|
|
70
|
+
<form className="contact-form" onSubmit={(event) => void submit(event)}>
|
|
71
|
+
{fields.map((field) => {
|
|
72
|
+
const key = text(field, "key");
|
|
73
|
+
const type = text(field, "type", "text");
|
|
74
|
+
const label = text(field, "label", key);
|
|
75
|
+
const required = field.required === true;
|
|
76
|
+
if (!key) return null;
|
|
77
|
+
if (type === "checkbox")
|
|
78
|
+
return (
|
|
79
|
+
<label
|
|
80
|
+
className="contact-form-wide contact-form-checkbox"
|
|
81
|
+
key={key}
|
|
82
|
+
>
|
|
83
|
+
<input
|
|
84
|
+
name={key}
|
|
85
|
+
required={required}
|
|
86
|
+
type="checkbox"
|
|
87
|
+
value="true"
|
|
88
|
+
/>
|
|
89
|
+
<span>
|
|
90
|
+
{label}
|
|
91
|
+
{required && <small aria-hidden="true"> *</small>}
|
|
92
|
+
</span>
|
|
93
|
+
</label>
|
|
94
|
+
);
|
|
95
|
+
if (type === "select")
|
|
96
|
+
return (
|
|
97
|
+
<label key={key}>
|
|
98
|
+
<span>
|
|
99
|
+
{label}
|
|
100
|
+
{required && <small aria-hidden="true"> *</small>}
|
|
101
|
+
</span>
|
|
102
|
+
<select name={key} required={required}>
|
|
103
|
+
{records(field, "options").map((option) => (
|
|
104
|
+
<option
|
|
105
|
+
key={text(option, "value")}
|
|
106
|
+
value={text(option, "value")}
|
|
107
|
+
>
|
|
108
|
+
{text(option, "label", text(option, "value"))}
|
|
109
|
+
</option>
|
|
110
|
+
))}
|
|
111
|
+
</select>
|
|
112
|
+
</label>
|
|
113
|
+
);
|
|
114
|
+
return (
|
|
115
|
+
<label
|
|
116
|
+
className={type === "textarea" ? "contact-form-wide" : ""}
|
|
117
|
+
key={key}
|
|
118
|
+
>
|
|
119
|
+
<span>
|
|
120
|
+
{label}
|
|
121
|
+
{required && <small aria-hidden="true"> *</small>}
|
|
122
|
+
</span>
|
|
123
|
+
{type === "textarea" ? (
|
|
124
|
+
<textarea
|
|
125
|
+
name={key}
|
|
126
|
+
placeholder={text(field, "placeholder")}
|
|
127
|
+
required={required}
|
|
128
|
+
rows={5}
|
|
129
|
+
/>
|
|
130
|
+
) : (
|
|
131
|
+
<input
|
|
132
|
+
name={key}
|
|
133
|
+
placeholder={text(field, "placeholder")}
|
|
134
|
+
required={required}
|
|
135
|
+
type={
|
|
136
|
+
["email", "tel", "url", "number"].includes(type)
|
|
137
|
+
? type
|
|
138
|
+
: "text"
|
|
139
|
+
}
|
|
140
|
+
/>
|
|
141
|
+
)}
|
|
142
|
+
</label>
|
|
143
|
+
);
|
|
144
|
+
})}
|
|
145
|
+
<div className="contact-form-wide">
|
|
146
|
+
<button
|
|
147
|
+
className="button button-primary"
|
|
148
|
+
disabled={status === "sending"}
|
|
149
|
+
type="submit"
|
|
150
|
+
>
|
|
151
|
+
{status === "sending" ? "" : text(props, "submitLabel")}
|
|
152
|
+
</button>
|
|
153
|
+
{status === "success" && text(props, "successMessage") && (
|
|
154
|
+
<p className="contact-form-feedback" role="status">
|
|
155
|
+
{text(props, "successMessage")}
|
|
156
|
+
</p>
|
|
157
|
+
)}
|
|
158
|
+
{status === "error" && (
|
|
159
|
+
<p
|
|
160
|
+
className="contact-form-feedback contact-form-error"
|
|
161
|
+
role="alert"
|
|
162
|
+
>
|
|
163
|
+
{error}
|
|
164
|
+
</p>
|
|
165
|
+
)}
|
|
166
|
+
</div>
|
|
167
|
+
</form>
|
|
168
|
+
</div>
|
|
169
|
+
</section>
|
|
170
|
+
);
|
|
171
|
+
}
|
|
172
|
+
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
export function text(data: Record<string, unknown>, key: string, fallback = "") {
|
|
2
|
+
const value = data[key];
|
|
3
|
+
return typeof value === "string" && value.trim() ? value.trim() : fallback;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
export function record(
|
|
8
|
+
data: Record<string, unknown>,
|
|
9
|
+
key: string,
|
|
10
|
+
): Record<string, unknown> {
|
|
11
|
+
const value = data[key];
|
|
12
|
+
return value && typeof value === "object" && !Array.isArray(value)
|
|
13
|
+
? (value as Record<string, unknown>)
|
|
14
|
+
: {};
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
export function records(
|
|
19
|
+
data: Record<string, unknown>,
|
|
20
|
+
key: string,
|
|
21
|
+
): Record<string, unknown>[] {
|
|
22
|
+
const value = data[key];
|
|
23
|
+
return Array.isArray(value)
|
|
24
|
+
? value.filter(
|
|
25
|
+
(item): item is Record<string, unknown> =>
|
|
26
|
+
Boolean(item) && typeof item === "object" && !Array.isArray(item),
|
|
27
|
+
)
|
|
28
|
+
: [];
|
|
29
|
+
}
|
|
30
|
+
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ContactForm } from "./contact-form.js";
|
|
2
|
+
import { text, record, records } from "./home-data.js";
|
|
2
3
|
import type {
|
|
3
4
|
HomeProps,
|
|
4
|
-
ThemeContactSubmissionInput,
|
|
5
5
|
ThemeEditorialItem,
|
|
6
6
|
ThemeHomeSection,
|
|
7
7
|
ThemeImage,
|
|
@@ -18,11 +18,6 @@ import {
|
|
|
18
18
|
type ThemeImageComponent,
|
|
19
19
|
} from "./shared.js";
|
|
20
20
|
|
|
21
|
-
function text(data: Record<string, unknown>, key: string, fallback = "") {
|
|
22
|
-
const value = data[key];
|
|
23
|
-
return typeof value === "string" && value.trim() ? value.trim() : fallback;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
21
|
function limit(data: Record<string, unknown>) {
|
|
27
22
|
const value = Number(data.limit);
|
|
28
23
|
return Number.isInteger(value) ? Math.min(12, Math.max(1, value)) : 6;
|
|
@@ -34,29 +29,6 @@ function brandsGridColumns(data: Record<string, unknown>) {
|
|
|
34
29
|
return Number.isInteger(value) ? Math.min(6, Math.max(1, value)) : 5;
|
|
35
30
|
}
|
|
36
31
|
|
|
37
|
-
function record(
|
|
38
|
-
data: Record<string, unknown>,
|
|
39
|
-
key: string,
|
|
40
|
-
): Record<string, unknown> {
|
|
41
|
-
const value = data[key];
|
|
42
|
-
return value && typeof value === "object" && !Array.isArray(value)
|
|
43
|
-
? (value as Record<string, unknown>)
|
|
44
|
-
: {};
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
function records(
|
|
48
|
-
data: Record<string, unknown>,
|
|
49
|
-
key: string,
|
|
50
|
-
): Record<string, unknown>[] {
|
|
51
|
-
const value = data[key];
|
|
52
|
-
return Array.isArray(value)
|
|
53
|
-
? value.filter(
|
|
54
|
-
(item): item is Record<string, unknown> =>
|
|
55
|
-
Boolean(item) && typeof item === "object" && !Array.isArray(item),
|
|
56
|
-
)
|
|
57
|
-
: [];
|
|
58
|
-
}
|
|
59
|
-
|
|
60
32
|
function productCategory(data: Record<string, unknown>) {
|
|
61
33
|
const value = text(data, "categorySlug").toLocaleLowerCase("pt-BR");
|
|
62
34
|
if (
|
|
@@ -352,172 +324,6 @@ function TextSection({
|
|
|
352
324
|
);
|
|
353
325
|
}
|
|
354
326
|
|
|
355
|
-
function ContactForm({
|
|
356
|
-
section,
|
|
357
|
-
submitContact,
|
|
358
|
-
}: {
|
|
359
|
-
section: ThemeHomeSection;
|
|
360
|
-
submitContact?: (submission: ThemeContactSubmissionInput) => Promise<unknown>;
|
|
361
|
-
}) {
|
|
362
|
-
const props = record(section.data, "props");
|
|
363
|
-
const configured = records(props, "fields");
|
|
364
|
-
const fields = configured;
|
|
365
|
-
const [status, setStatus] = useState<
|
|
366
|
-
"idle" | "sending" | "success" | "error"
|
|
367
|
-
>("idle");
|
|
368
|
-
const [error, setError] = useState("");
|
|
369
|
-
const submit = async (event: FormEvent<HTMLFormElement>) => {
|
|
370
|
-
event.preventDefault();
|
|
371
|
-
if (!submitContact) {
|
|
372
|
-
setStatus("error");
|
|
373
|
-
setError("O envio de contatos ainda não está disponível.");
|
|
374
|
-
return;
|
|
375
|
-
}
|
|
376
|
-
const formElement = event.currentTarget;
|
|
377
|
-
const form = new FormData(formElement);
|
|
378
|
-
const values: ThemeContactSubmissionInput["values"] = {};
|
|
379
|
-
fields.forEach((field) => {
|
|
380
|
-
const key = text(field, "key");
|
|
381
|
-
if (!key) return;
|
|
382
|
-
if (text(field, "type") === "checkbox") {
|
|
383
|
-
values[key] = form.has(key);
|
|
384
|
-
return;
|
|
385
|
-
}
|
|
386
|
-
const entries = form.getAll(key).map(String);
|
|
387
|
-
values[key] = entries.length > 1 ? entries : (entries[0] ?? "");
|
|
388
|
-
});
|
|
389
|
-
setStatus("sending");
|
|
390
|
-
setError("");
|
|
391
|
-
try {
|
|
392
|
-
await submitContact({
|
|
393
|
-
formKey: text(section.data, "componentKey", "contact-form"),
|
|
394
|
-
sectionId: section.id,
|
|
395
|
-
values,
|
|
396
|
-
pathname:
|
|
397
|
-
typeof window === "undefined" ? undefined : window.location.pathname,
|
|
398
|
-
});
|
|
399
|
-
formElement.reset();
|
|
400
|
-
setStatus("success");
|
|
401
|
-
} catch (cause) {
|
|
402
|
-
setStatus("error");
|
|
403
|
-
setError(
|
|
404
|
-
cause instanceof Error
|
|
405
|
-
? cause.message
|
|
406
|
-
: "Não foi possível enviar o contato.",
|
|
407
|
-
);
|
|
408
|
-
}
|
|
409
|
-
};
|
|
410
|
-
return (
|
|
411
|
-
<section className="store-section theme-component-section contact-form-section">
|
|
412
|
-
<div className="store-container contact-form-layout">
|
|
413
|
-
<div className="contact-form-copy">
|
|
414
|
-
{text(props, "eyebrow") && <span>{text(props, "eyebrow")}</span>}
|
|
415
|
-
{text(props, "title") && <h2>{text(props, "title")}</h2>}
|
|
416
|
-
{text(props, "description") && <p>{text(props, "description")}</p>}
|
|
417
|
-
</div>
|
|
418
|
-
<form className="contact-form" onSubmit={(event) => void submit(event)}>
|
|
419
|
-
{fields.map((field) => {
|
|
420
|
-
const key = text(field, "key");
|
|
421
|
-
const type = text(field, "type", "text");
|
|
422
|
-
const label = text(field, "label", key);
|
|
423
|
-
const required = field.required === true;
|
|
424
|
-
if (!key) return null;
|
|
425
|
-
if (type === "checkbox")
|
|
426
|
-
return (
|
|
427
|
-
<label
|
|
428
|
-
className="contact-form-wide contact-form-checkbox"
|
|
429
|
-
key={key}
|
|
430
|
-
>
|
|
431
|
-
<input
|
|
432
|
-
name={key}
|
|
433
|
-
required={required}
|
|
434
|
-
type="checkbox"
|
|
435
|
-
value="true"
|
|
436
|
-
/>
|
|
437
|
-
<span>
|
|
438
|
-
{label}
|
|
439
|
-
{required && <small aria-hidden="true"> *</small>}
|
|
440
|
-
</span>
|
|
441
|
-
</label>
|
|
442
|
-
);
|
|
443
|
-
if (type === "select")
|
|
444
|
-
return (
|
|
445
|
-
<label key={key}>
|
|
446
|
-
<span>
|
|
447
|
-
{label}
|
|
448
|
-
{required && <small aria-hidden="true"> *</small>}
|
|
449
|
-
</span>
|
|
450
|
-
<select name={key} required={required}>
|
|
451
|
-
{records(field, "options").map((option) => (
|
|
452
|
-
<option
|
|
453
|
-
key={text(option, "value")}
|
|
454
|
-
value={text(option, "value")}
|
|
455
|
-
>
|
|
456
|
-
{text(option, "label", text(option, "value"))}
|
|
457
|
-
</option>
|
|
458
|
-
))}
|
|
459
|
-
</select>
|
|
460
|
-
</label>
|
|
461
|
-
);
|
|
462
|
-
return (
|
|
463
|
-
<label
|
|
464
|
-
className={type === "textarea" ? "contact-form-wide" : ""}
|
|
465
|
-
key={key}
|
|
466
|
-
>
|
|
467
|
-
<span>
|
|
468
|
-
{label}
|
|
469
|
-
{required && <small aria-hidden="true"> *</small>}
|
|
470
|
-
</span>
|
|
471
|
-
{type === "textarea" ? (
|
|
472
|
-
<textarea
|
|
473
|
-
name={key}
|
|
474
|
-
placeholder={text(field, "placeholder")}
|
|
475
|
-
required={required}
|
|
476
|
-
rows={5}
|
|
477
|
-
/>
|
|
478
|
-
) : (
|
|
479
|
-
<input
|
|
480
|
-
name={key}
|
|
481
|
-
placeholder={text(field, "placeholder")}
|
|
482
|
-
required={required}
|
|
483
|
-
type={
|
|
484
|
-
["email", "tel", "url", "number"].includes(type)
|
|
485
|
-
? type
|
|
486
|
-
: "text"
|
|
487
|
-
}
|
|
488
|
-
/>
|
|
489
|
-
)}
|
|
490
|
-
</label>
|
|
491
|
-
);
|
|
492
|
-
})}
|
|
493
|
-
<div className="contact-form-wide">
|
|
494
|
-
<button
|
|
495
|
-
className="button button-primary"
|
|
496
|
-
disabled={status === "sending"}
|
|
497
|
-
type="submit"
|
|
498
|
-
>
|
|
499
|
-
{status === "sending" ? "" : text(props, "submitLabel")}
|
|
500
|
-
</button>
|
|
501
|
-
{status === "success" && text(props, "successMessage") && (
|
|
502
|
-
<p className="contact-form-feedback" role="status">
|
|
503
|
-
{text(props, "successMessage")}
|
|
504
|
-
</p>
|
|
505
|
-
)}
|
|
506
|
-
{status === "error" && (
|
|
507
|
-
<p
|
|
508
|
-
className="contact-form-feedback contact-form-error"
|
|
509
|
-
role="alert"
|
|
510
|
-
>
|
|
511
|
-
{error}
|
|
512
|
-
</p>
|
|
513
|
-
)}
|
|
514
|
-
</div>
|
|
515
|
-
</form>
|
|
516
|
-
</div>
|
|
517
|
-
</section>
|
|
518
|
-
);
|
|
519
|
-
}
|
|
520
|
-
|
|
521
327
|
function ThemeComponent({
|
|
522
328
|
section,
|
|
523
329
|
submitContact,
|