@nuvler/cli 0.5.9 → 0.5.11

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 (39) hide show
  1. package/README.md +7 -5
  2. package/dist/api/theme-context.js.map +1 -1
  3. package/dist/commands/theme/create.js +1 -1
  4. package/dist/commands/theme/upgrade.js +2 -1
  5. package/dist/commands/theme/upgrade.js.map +1 -1
  6. package/dist/migrate/generator.js +21 -10
  7. package/dist/migrate/generator.js.map +1 -1
  8. package/dist/migrate/transformer.js +2 -1
  9. package/dist/migrate/transformer.js.map +1 -1
  10. package/dist/nuvler.js +118 -16
  11. package/dist/nuvler.js.map +1 -1
  12. package/dist/templates/nuvler-atelier/nuvler.theme.json +1 -1
  13. package/dist/templates/nuvler-atelier/package.json +3 -3
  14. package/dist/templates/nuvler-atelier/src/definition.tsx +16 -8
  15. package/dist/templates/nuvler-atelier/src/theme.css +3 -0
  16. package/dist/templates/nuvler-atelier/src/theme.tsx +24 -4
  17. package/dist/templates/nuvler-default/README.md +2 -2
  18. package/dist/templates/nuvler-default/nuvler.theme.json +22 -4
  19. package/dist/templates/nuvler-default/package.json +6 -5
  20. package/dist/templates/nuvler-default/scripts/verify-release.mjs +34 -0
  21. package/dist/templates/nuvler-default/src/carousel-frame.tsx +125 -20
  22. package/dist/templates/nuvler-default/src/header-interactions.tsx +2 -2
  23. package/dist/templates/nuvler-default/src/header.tsx +1 -1
  24. package/dist/templates/nuvler-default/src/home.tsx +700 -76
  25. package/dist/templates/nuvler-default/src/mini-banners.tsx +45 -0
  26. package/dist/templates/nuvler-default/src/product-carousel.tsx +2 -2
  27. package/dist/templates/nuvler-default/src/product-detail-interactive.tsx +7 -2
  28. package/dist/templates/nuvler-default/src/product-detail.tsx +3 -1
  29. package/dist/templates/nuvler-default/src/products.tsx +6 -5
  30. package/dist/templates/nuvler-default/src/shared.tsx +9 -1
  31. package/dist/templates/nuvler-default/src/theme-component.tsx +18 -4
  32. package/dist/templates/nuvler-default/src/theme.css +201 -7
  33. package/dist/templates/starter/package.json +2 -2
  34. package/dist/templates/starter/src/definition.tsx +5 -5
  35. package/dist/templates/starter/src/theme.tsx +2 -2
  36. package/package.json +3 -3
  37. package/preview-host/package.json +1 -1
  38. package/preview-host/src/fallback-context.json +1 -0
  39. package/preview-host/vendor/theme-runtime/default-theme.tsx +42 -6
@@ -1,9 +1,22 @@
1
1
  import { useState, type FormEvent } from "react";
2
- import type { HomeProps, ThemeContactSubmissionInput, ThemeEditorialItem, ThemeHomeSection, ThemeImage, ThemeSite } from "@nuvler/theme-sdk";
2
+ import type {
3
+ HomeProps,
4
+ ThemeContactSubmissionInput,
5
+ ThemeEditorialItem,
6
+ ThemeHomeSection,
7
+ ThemeImage,
8
+ ThemeSite,
9
+ } from "@nuvler/theme-sdk";
3
10
  import { BannerCarousel, type ThemeBanner } from "./banner-carousel.js";
11
+ import { MiniBanners } from "./mini-banners.js";
4
12
  import { ProductCarousel } from "./product-carousel.js";
13
+ import { BrandsCarouselFrame } from "./carousel-frame.js";
5
14
  import { ProductGrid } from "./products.js";
6
- import { categoryUrl, ThemeImageView, type ThemeImageComponent } from "./shared.js";
15
+ import {
16
+ categoryUrl,
17
+ ThemeImageView,
18
+ type ThemeImageComponent,
19
+ } from "./shared.js";
7
20
 
8
21
  function text(data: Record<string, unknown>, key: string, fallback = "") {
9
22
  const value = data[key];
@@ -15,21 +28,48 @@ function limit(data: Record<string, unknown>) {
15
28
  return Number.isInteger(value) ? Math.min(12, Math.max(1, value)) : 6;
16
29
  }
17
30
 
18
- function record(data: Record<string, unknown>, key: string): Record<string, unknown> {
31
+ function brandsGridColumns(data: Record<string, unknown>) {
32
+ const value = Number(data.gridColumns);
33
+
34
+ return Number.isInteger(value) ? Math.min(6, Math.max(1, value)) : 5;
35
+ }
36
+
37
+ function record(
38
+ data: Record<string, unknown>,
39
+ key: string,
40
+ ): Record<string, unknown> {
19
41
  const value = data[key];
20
- return value && typeof value === "object" && !Array.isArray(value) ? value as Record<string, unknown> : {};
42
+ return value && typeof value === "object" && !Array.isArray(value)
43
+ ? (value as Record<string, unknown>)
44
+ : {};
21
45
  }
22
46
 
23
- function records(data: Record<string, unknown>, key: string): Record<string, unknown>[] {
47
+ function records(
48
+ data: Record<string, unknown>,
49
+ key: string,
50
+ ): Record<string, unknown>[] {
24
51
  const value = data[key];
25
52
  return Array.isArray(value)
26
- ? value.filter((item): item is Record<string, unknown> => Boolean(item) && typeof item === "object" && !Array.isArray(item))
53
+ ? value.filter(
54
+ (item): item is Record<string, unknown> =>
55
+ Boolean(item) && typeof item === "object" && !Array.isArray(item),
56
+ )
27
57
  : [];
28
58
  }
29
59
 
30
60
  function productCategory(data: Record<string, unknown>) {
31
61
  const value = text(data, "categorySlug").toLocaleLowerCase("pt-BR");
32
- if (["", "all", "todos", "todas", "all-categories", "todas-as-categorias"].includes(value)) return "";
62
+ if (
63
+ [
64
+ "",
65
+ "all",
66
+ "todos",
67
+ "todas",
68
+ "all-categories",
69
+ "todas-as-categorias",
70
+ ].includes(value)
71
+ )
72
+ return "";
33
73
  return value;
34
74
  }
35
75
 
@@ -45,16 +85,21 @@ function imageValue(value: unknown): ThemeImage | null {
45
85
  };
46
86
  }
47
87
 
48
- function sectionImage(data: Record<string, unknown>, fallbackAlt: string): ThemeImage | null {
88
+ function sectionImage(
89
+ data: Record<string, unknown>,
90
+ fallbackAlt: string,
91
+ ): ThemeImage | null {
49
92
  const enriched = imageValue(data.image);
50
93
  if (enriched) return enriched;
51
94
  const imageUrl = text(data, "imageUrl");
52
- return imageUrl ? {
53
- url: imageUrl,
54
- alt: text(data, "imageAlt", fallbackAlt),
55
- width: null,
56
- height: null,
57
- } : null;
95
+ return imageUrl
96
+ ? {
97
+ url: imageUrl,
98
+ alt: text(data, "imageAlt", fallbackAlt),
99
+ width: null,
100
+ height: null,
101
+ }
102
+ : null;
58
103
  }
59
104
 
60
105
  function banners(data: Record<string, unknown>): ThemeBanner[] {
@@ -63,51 +108,263 @@ function banners(data: Record<string, unknown>): ThemeBanner[] {
63
108
  if (!entry || typeof entry !== "object") return [];
64
109
  const item = entry as Record<string, unknown>;
65
110
  const image = imageValue(item.image);
66
- const imageUrl = image?.url || (typeof item.imageUrl === "string" ? item.imageUrl : "");
111
+ const imageUrl =
112
+ image?.url || (typeof item.imageUrl === "string" ? item.imageUrl : "");
113
+ if (!imageUrl) return [];
114
+ return [
115
+ {
116
+ imageUrl,
117
+ image,
118
+ imageAlt: typeof item.imageAlt === "string" ? item.imageAlt : undefined,
119
+ mobileImageUrl:
120
+ typeof item.mobileImageUrl === "string"
121
+ ? item.mobileImageUrl
122
+ : undefined,
123
+ mobileImage: imageValue(item.mobileImage),
124
+ mobileImageAlt:
125
+ typeof item.mobileImageAlt === "string"
126
+ ? item.mobileImageAlt
127
+ : undefined,
128
+ title: typeof item.title === "string" ? item.title : undefined,
129
+ description:
130
+ typeof item.description === "string" ? item.description : undefined,
131
+ buttonLabel:
132
+ typeof item.buttonLabel === "string" ? item.buttonLabel : undefined,
133
+ buttonUrl:
134
+ typeof item.buttonUrl === "string" ? item.buttonUrl : undefined,
135
+ },
136
+ ];
137
+ });
138
+ }
139
+
140
+ function miniBanners(data: Record<string, unknown>) {
141
+ return records(data, "items").flatMap((item) => {
142
+ const image = imageValue(item.image);
143
+ const imageUrl = image?.url || text(item, "imageUrl");
67
144
  if (!imageUrl) return [];
68
- return [{ imageUrl, image, imageAlt: typeof item.imageAlt === "string" ? item.imageAlt : undefined, mobileImageUrl: typeof item.mobileImageUrl === "string" ? item.mobileImageUrl : undefined, mobileImage: imageValue(item.mobileImage), mobileImageAlt: typeof item.mobileImageAlt === "string" ? item.mobileImageAlt : undefined, title: typeof item.title === "string" ? item.title : undefined, description: typeof item.description === "string" ? item.description : undefined, buttonLabel: typeof item.buttonLabel === "string" ? item.buttonLabel : undefined, buttonUrl: typeof item.buttonUrl === "string" ? item.buttonUrl : undefined }];
145
+ return [
146
+ {
147
+ image,
148
+ imageUrl,
149
+ imageAlt: text(item, "imageAlt") || undefined,
150
+ title: text(item, "title") || undefined,
151
+ linkLabel: text(item, "linkLabel") || undefined,
152
+ link: text(item, "link") || undefined,
153
+ },
154
+ ];
69
155
  });
70
156
  }
71
157
 
72
- function Heading({ data, href }: { data: Record<string, unknown>; href: string }) {
158
+ function Heading({
159
+ data,
160
+ href,
161
+ }: {
162
+ data: Record<string, unknown>;
163
+ href: string;
164
+ }) {
73
165
  const eyebrow = text(data, "eyebrow");
74
166
  const title = text(data, "title");
75
167
  const actionLabel = text(data, "buttonLabel");
76
168
  const actionHref = text(data, "buttonUrl", href);
77
169
  if (!eyebrow && !title && !actionLabel) return null;
78
- return <div className="section-heading"><div>{eyebrow && <span>{eyebrow}</span>}{title && <h2>{title}</h2>}</div>{actionLabel && actionHref && <a href={actionHref}>{actionLabel}</a>}</div>;
170
+ return (
171
+ <div className="section-heading">
172
+ <div>
173
+ {eyebrow && <span>{eyebrow}</span>}
174
+ {title && <h2>{title}</h2>}
175
+ </div>
176
+ {actionLabel && actionHref && <a href={actionHref}>{actionLabel}</a>}
177
+ </div>
178
+ );
79
179
  }
80
180
 
81
- function Hero({ section, priority, ImageComponent = ThemeImageView }: { section: ThemeHomeSection; priority: boolean; ImageComponent?: ThemeImageComponent }) {
181
+ function Hero({
182
+ section,
183
+ priority,
184
+ ImageComponent = ThemeImageView,
185
+ }: {
186
+ section: ThemeHomeSection;
187
+ priority: boolean;
188
+ ImageComponent?: ThemeImageComponent;
189
+ }) {
82
190
  const title = text(section.data, "title");
83
191
  const description = text(section.data, "description");
84
192
  const eyebrow = text(section.data, "eyebrow");
85
193
  const buttonLabel = text(section.data, "buttonLabel");
86
194
  const buttonUrl = text(section.data, "buttonUrl");
87
195
  const image = sectionImage(section.data, title);
88
- const copy = <div className="hero-copy">{eyebrow && <span className="hero-eyebrow">{eyebrow}</span>}{title && <h1>{title}</h1>}{description && <p>{description}</p>}{buttonLabel && buttonUrl && <div className="hero-actions"><a className="button button-primary" href={buttonUrl}>{buttonLabel}</a></div>}</div>;
89
- if (image) return <section className="hero-section hero-section-image"><ImageComponent image={image} fallbackAlt={title} className="hero-background-image" priority={priority} sizes="100vw" fallbackWidth={1600} fallbackHeight={700} /><div className="hero-background-overlay" aria-hidden="true" /><div className="store-container hero-image-content">{copy}</div></section>;
90
- return <section className="hero-section"><div className="store-container hero-grid">{copy}<div className="hero-art" aria-hidden="true"><div className="hero-orbit hero-orbit-one" /><div className="hero-orbit hero-orbit-two" /><div className="hero-seven">7</div></div></div></section>;
196
+ const copy = (
197
+ <div className="hero-copy">
198
+ {eyebrow && <span className="hero-eyebrow">{eyebrow}</span>}
199
+ {title && <h1>{title}</h1>}
200
+ {description && <p>{description}</p>}
201
+ {buttonLabel && buttonUrl && (
202
+ <div className="hero-actions">
203
+ <a className="button button-primary" href={buttonUrl}>
204
+ {buttonLabel}
205
+ </a>
206
+ </div>
207
+ )}
208
+ </div>
209
+ );
210
+ if (image)
211
+ return (
212
+ <section className="hero-section hero-section-image">
213
+ <ImageComponent
214
+ image={image}
215
+ fallbackAlt={title}
216
+ className="hero-background-image"
217
+ priority={priority}
218
+ sizes="100vw"
219
+ fallbackWidth={1600}
220
+ fallbackHeight={700}
221
+ />
222
+ <div className="hero-background-overlay" aria-hidden="true" />
223
+ <div className="store-container hero-image-content">{copy}</div>
224
+ </section>
225
+ );
226
+ return (
227
+ <section className="hero-section">
228
+ <div className="store-container hero-grid">
229
+ {copy}
230
+ <div className="hero-art" aria-hidden="true">
231
+ <div className="hero-orbit hero-orbit-one" />
232
+ <div className="hero-orbit hero-orbit-two" />
233
+ <div className="hero-seven">7</div>
234
+ </div>
235
+ </div>
236
+ </section>
237
+ );
91
238
  }
92
239
 
93
- function EditorialGrid({ items, basePath, ImageComponent = ThemeImageView }: { items: ThemeEditorialItem[]; basePath: string; ImageComponent?: ThemeImageComponent }) {
94
- if (!items.length) return <div className="empty-state"><span>7</span><h2>Nenhum conteúdo publicado</h2><p>As publicações aparecerão aqui quando estiverem disponíveis.</p></div>;
95
- return <div className="editorial-grid">{items.map((item) => <article className="editorial-card" key={item.slug}><a className="editorial-card-image" href={`${basePath}/${item.slug}`}><ImageComponent image={item.image || item.thumbnail || item.coverImage} fallbackAlt={item.title} sizes="(max-width: 720px) 92vw, 33vw" fallbackWidth={720} fallbackHeight={480} /></a><div className="editorial-card-content">{(item.category?.title || item.category?.name) && <span>{item.category.title || item.category.name}</span>}<h2><a href={`${basePath}/${item.slug}`}>{item.title}</a></h2><p>{item.description}</p><a className="text-link" href={`${basePath}/${item.slug}`}>Saiba mais <span>→</span></a></div></article>)}</div>;
240
+ function EditorialGrid({
241
+ items,
242
+ basePath,
243
+ ImageComponent = ThemeImageView,
244
+ }: {
245
+ items: ThemeEditorialItem[];
246
+ basePath: string;
247
+ ImageComponent?: ThemeImageComponent;
248
+ }) {
249
+ if (!items.length)
250
+ return (
251
+ <div className="empty-state">
252
+ <span>7</span>
253
+ <h2>Nenhum conteúdo publicado</h2>
254
+ <p>As publicações aparecerão aqui quando estiverem disponíveis.</p>
255
+ </div>
256
+ );
257
+ return (
258
+ <div className="editorial-grid">
259
+ {items.map((item) => (
260
+ <article className="editorial-card" key={item.slug}>
261
+ <a className="editorial-card-image" href={`${basePath}/${item.slug}`}>
262
+ <ImageComponent
263
+ image={item.image || item.thumbnail || item.coverImage}
264
+ fallbackAlt={item.title}
265
+ sizes="(max-width: 720px) 92vw, 33vw"
266
+ fallbackWidth={720}
267
+ fallbackHeight={480}
268
+ />
269
+ </a>
270
+ <div className="editorial-card-content">
271
+ {(item.category?.title || item.category?.name) && (
272
+ <span>{item.category.title || item.category.name}</span>
273
+ )}
274
+ <h2>
275
+ <a href={`${basePath}/${item.slug}`}>{item.title}</a>
276
+ </h2>
277
+ <p>{item.description}</p>
278
+ <a className="text-link" href={`${basePath}/${item.slug}`}>
279
+ Saiba mais <span>→</span>
280
+ </a>
281
+ </div>
282
+ </article>
283
+ ))}
284
+ </div>
285
+ );
96
286
  }
97
287
 
98
- function TextSection({ section, ImageComponent = ThemeImageView }: { section: ThemeHomeSection; ImageComponent?: ThemeImageComponent }) {
288
+ function TextSection({
289
+ section,
290
+ ImageComponent = ThemeImageView,
291
+ }: {
292
+ section: ThemeHomeSection;
293
+ ImageComponent?: ThemeImageComponent;
294
+ }) {
99
295
  const title = text(section.data, "title");
100
- const description = text(section.data, "description", text(section.data, "text"));
296
+ const description = text(
297
+ section.data,
298
+ "description",
299
+ text(section.data, "text"),
300
+ );
101
301
  const image = sectionImage(section.data, title);
102
- if (section.type === "image-text") return <section className="store-section image-text-section"><div className="store-container image-text-layout" data-position={section.data.imagePosition === "right" ? "right" : "left"}>{image && <div className="image-text-media"><ImageComponent image={image} fallbackAlt={title} sizes="(max-width: 900px) 100vw, 50vw" fallbackWidth={800} fallbackHeight={600} /></div>}<div className="image-text-copy">{text(section.data, "eyebrow") && <span>{text(section.data, "eyebrow")}</span>}{title && <h2>{title}</h2>}{description && <p>{description}</p>}</div></div></section>;
103
- return <section className="store-section editorial-section"><div className="store-container editorial-content">{text(section.data, "eyebrow") && <span>{text(section.data, "eyebrow")}</span>}{title && <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>;
302
+ if (section.type === "image-text")
303
+ return (
304
+ <section className="store-section image-text-section">
305
+ <div
306
+ className="store-container image-text-layout"
307
+ data-position={
308
+ section.data.imagePosition === "right" ? "right" : "left"
309
+ }
310
+ >
311
+ {image && (
312
+ <div className="image-text-media">
313
+ <ImageComponent
314
+ image={image}
315
+ fallbackAlt={title}
316
+ sizes="(max-width: 900px) 100vw, 50vw"
317
+ fallbackWidth={800}
318
+ fallbackHeight={600}
319
+ />
320
+ </div>
321
+ )}
322
+ <div className="image-text-copy">
323
+ {text(section.data, "eyebrow") && (
324
+ <span>{text(section.data, "eyebrow")}</span>
325
+ )}
326
+ {title && <h2>{title}</h2>}
327
+ {description && <p>{description}</p>}
328
+ </div>
329
+ </div>
330
+ </section>
331
+ );
332
+ return (
333
+ <section className="store-section editorial-section">
334
+ <div className="store-container editorial-content">
335
+ {text(section.data, "eyebrow") && (
336
+ <span>{text(section.data, "eyebrow")}</span>
337
+ )}
338
+ {title && <h2>{title}</h2>}
339
+ {description && <p>{description}</p>}
340
+ {section.type === "cta" &&
341
+ text(section.data, "buttonLabel") &&
342
+ text(section.data, "buttonUrl") && (
343
+ <a
344
+ className="button button-primary"
345
+ href={text(section.data, "buttonUrl")}
346
+ >
347
+ {text(section.data, "buttonLabel")}
348
+ </a>
349
+ )}
350
+ </div>
351
+ </section>
352
+ );
104
353
  }
105
354
 
106
- function ContactForm({ section, submitContact }: { section: ThemeHomeSection; submitContact?: (submission: ThemeContactSubmissionInput) => Promise<unknown> }) {
355
+ function ContactForm({
356
+ section,
357
+ submitContact,
358
+ }: {
359
+ section: ThemeHomeSection;
360
+ submitContact?: (submission: ThemeContactSubmissionInput) => Promise<unknown>;
361
+ }) {
107
362
  const props = record(section.data, "props");
108
363
  const configured = records(props, "fields");
109
364
  const fields = configured;
110
- const [status, setStatus] = useState<"idle" | "sending" | "success" | "error">("idle");
365
+ const [status, setStatus] = useState<
366
+ "idle" | "sending" | "success" | "error"
367
+ >("idle");
111
368
  const [error, setError] = useState("");
112
369
  const submit = async (event: FormEvent<HTMLFormElement>) => {
113
370
  event.preventDefault();
@@ -127,70 +384,437 @@ function ContactForm({ section, submitContact }: { section: ThemeHomeSection; su
127
384
  return;
128
385
  }
129
386
  const entries = form.getAll(key).map(String);
130
- values[key] = entries.length > 1 ? entries : entries[0] ?? "";
387
+ values[key] = entries.length > 1 ? entries : (entries[0] ?? "");
131
388
  });
132
389
  setStatus("sending");
133
390
  setError("");
134
391
  try {
135
- await submitContact({ formKey: text(section.data, "componentKey", "contact-form"), sectionId: section.id, values, pathname: typeof window === "undefined" ? undefined : window.location.pathname });
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
+ });
136
399
  formElement.reset();
137
400
  setStatus("success");
138
401
  } catch (cause) {
139
402
  setStatus("error");
140
- setError(cause instanceof Error ? cause.message : "Não foi possível enviar o contato.");
403
+ setError(
404
+ cause instanceof Error
405
+ ? cause.message
406
+ : "Não foi possível enviar o contato.",
407
+ );
141
408
  }
142
409
  };
143
- 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) => {
144
- const key = text(field, "key");
145
- const type = text(field, "type", "text");
146
- const label = text(field, "label", key);
147
- const required = field.required === true;
148
- if (!key) return null;
149
- 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>;
150
- 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>;
151
- 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>;
152
- })}<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>;
153
- }
154
-
155
- function ThemeComponent({ section, submitContact, ImageComponent = ThemeImageView }: { section: ThemeHomeSection; submitContact?: HomeProps["submitContact"]; ImageComponent?: ThemeImageComponent }) {
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
+ function ThemeComponent({
522
+ section,
523
+ submitContact,
524
+ ImageComponent = ThemeImageView,
525
+ }: {
526
+ section: ThemeHomeSection;
527
+ submitContact?: HomeProps["submitContact"];
528
+ ImageComponent?: ThemeImageComponent;
529
+ }) {
156
530
  const componentKey = text(section.data, "componentKey");
157
531
  const props = record(section.data, "props");
158
- if (componentKey === "contact-form" || componentKey.endsWith("-form")) return <ContactForm section={section} submitContact={submitContact} />;
532
+ if (componentKey === "contact-form" || componentKey.endsWith("-form"))
533
+ return <ContactForm section={section} submitContact={submitContact} />;
159
534
  if (componentKey === "benefits" || componentKey === "brands") {
160
535
  const items = records(props, "items");
161
536
  if (!items.length) return null;
162
537
  const isBrands = componentKey === "brands";
163
- return <section className={`store-section home-${componentKey}-section`}><div className="store-container">{(text(props, "eyebrow") || text(props, "title")) && <div className="section-heading"><div>{text(props, "eyebrow") && <span>{text(props, "eyebrow")}</span>}{text(props, "title") && <h2>{text(props, "title")}</h2>}</div></div>}<div className={isBrands ? "home-brands-grid" : "home-benefits-grid"}>{items.map((item, index) => { const title = text(item, "title", text(item, "value")); const image = imageValue(item.image); const href = text(item, "url"); const content = <>{isBrands && image ? <ImageComponent image={image} fallbackAlt={title} sizes="160px" fallbackWidth={320} fallbackHeight={160} /> : null}{!isBrands && <span className="home-benefit-index" aria-hidden="true">{String(index + 1).padStart(2, "0")}</span>}{title && <strong>{title}</strong>}{text(item, "description") && <p>{text(item, "description")}</p>}</>; return href ? <a href={href} key={`${title}-${index}`}>{content}</a> : <article key={`${title}-${index}`}>{content}</article>; })}</div></div></section>;
538
+ const gridColumns = isBrands ? brandsGridColumns(props) : undefined;
539
+ const brandsLayout =
540
+ text(props, "layout", "grid") === "carousel" ? "carousel" : "grid";
541
+
542
+ const renderedItems = items.map((item, index) => {
543
+ const title = text(item, "title", text(item, "value"));
544
+ const image = sectionImage(item, title);
545
+ const href = text(item, "url");
546
+ const content = (
547
+ <>
548
+ {isBrands && image ? (
549
+ <ImageComponent
550
+ image={image}
551
+ fallbackAlt={title}
552
+ sizes="160px"
553
+ fallbackWidth={320}
554
+ fallbackHeight={160}
555
+ />
556
+ ) : null}
557
+ {!isBrands && (
558
+ <span className="home-benefit-index" aria-hidden="true">
559
+ {String(index + 1).padStart(2, "0")}
560
+ </span>
561
+ )}
562
+ {title && <strong>{title}</strong>}
563
+ {text(item, "description") && <p>{text(item, "description")}</p>}
564
+ </>
565
+ );
566
+ return href ? (
567
+ <a href={href} key={`${title}-${index}`}>
568
+ {content}
569
+ </a>
570
+ ) : (
571
+ <article key={`${title}-${index}`}>{content}</article>
572
+ );
573
+ });
574
+ return (
575
+ <section className={`store-section home-${componentKey}-section`}>
576
+ <div className="store-container">
577
+ {(text(props, "eyebrow") || text(props, "title")) && (
578
+ <div className="section-heading">
579
+ <div>
580
+ {text(props, "eyebrow") && (
581
+ <span>{text(props, "eyebrow")}</span>
582
+ )}
583
+ {text(props, "title") && <h2>{text(props, "title")}</h2>}
584
+ </div>
585
+ </div>
586
+ )}
587
+ {isBrands && brandsLayout === "carousel" ? (
588
+ <BrandsCarouselFrame count={items.length}>
589
+ {renderedItems}
590
+ </BrandsCarouselFrame>
591
+ ) : (
592
+ <div
593
+ className={isBrands ? "home-brands-grid" : "home-benefits-grid"}
594
+ data-columns={gridColumns}
595
+ >
596
+ {renderedItems}
597
+ </div>
598
+ )}
599
+ </div>
600
+ </section>
601
+ );
164
602
  }
165
- 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>;
603
+ if (componentKey === "video")
604
+ return (
605
+ <section
606
+ className="store-section theme-component-section"
607
+ data-component-key="video"
608
+ >
609
+ <div className="store-container">
610
+ {text(props, "eyebrow") && <span>{text(props, "eyebrow")}</span>}
611
+ {text(props, "title") && <h2>{text(props, "title")}</h2>}
612
+ {text(props, "description") && <p>{text(props, "description")}</p>}
613
+ {text(props, "videoUrl") && (
614
+ <video
615
+ className="theme-component-video"
616
+ controls
617
+ playsInline
618
+ poster={text(props, "posterImageUrl") || undefined}
619
+ src={text(props, "videoUrl")}
620
+ />
621
+ )}
622
+ </div>
623
+ </section>
624
+ );
166
625
  const items = records(props, "items");
167
- 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>;
626
+ return (
627
+ <section
628
+ className="store-section theme-component-section"
629
+ data-component-key={componentKey || undefined}
630
+ >
631
+ <div className="store-container">
632
+ {text(props, "eyebrow") && <span>{text(props, "eyebrow")}</span>}
633
+ {text(props, "title") && <h2>{text(props, "title")}</h2>}
634
+ {text(props, "description") && <p>{text(props, "description")}</p>}
635
+ {items.length > 0 && (
636
+ <div className="theme-component-items">
637
+ {items.map((item, index) => {
638
+ const itemTitle = text(
639
+ item,
640
+ "value",
641
+ text(item, "title", text(item, "question")),
642
+ );
643
+ return (
644
+ <article key={index}>
645
+ {itemTitle && <strong>{itemTitle}</strong>}
646
+ {text(item, "description", text(item, "answer")) && (
647
+ <p>{text(item, "description", text(item, "answer"))}</p>
648
+ )}
649
+ </article>
650
+ );
651
+ })}
652
+ </div>
653
+ )}
654
+ </div>
655
+ </section>
656
+ );
168
657
  }
169
658
 
170
- export function Home({ sections, products, posts, services, cases, site, submitContact, ImageComponent = ThemeImageView }: HomeProps & { ImageComponent?: ThemeImageComponent }) {
171
- const visible = [...sections].filter((section) => section.enabled).sort((a, b) => a.order - b.order);
659
+ export function Home({
660
+ sections,
661
+ products,
662
+ posts,
663
+ services,
664
+ cases,
665
+ site,
666
+ submitContact,
667
+ ImageComponent = ThemeImageView,
668
+ }: HomeProps & { ImageComponent?: ThemeImageComponent }) {
669
+ const visible = [...sections]
670
+ .filter((section) => section.enabled)
671
+ .sort((a, b) => a.order - b.order);
172
672
  const catalog = site.settings?.catalog;
173
- return <>{visible.map((section, index) => {
174
- if (section.type === "hero") return <Hero key={section.id || index} section={section} priority={index === 0} ImageComponent={ImageComponent} />;
175
- if (section.type === "banner-carousel") return <section className="home-banner-section" key={section.id || index}><BannerCarousel banners={banners(section.data)} autoplay={section.data.autoplay !== false} desktopHeight={typeof section.data.desktopHeight === "number" ? section.data.desktopHeight : undefined} mobileHeight={typeof section.data.mobileHeight === "number" ? section.data.mobileHeight : undefined} imageFit={section.data.imageFit === "CONTAIN" || section.data.imageFit === "NATURAL" ? section.data.imageFit : "COVER"} priority={index === 0} ImageComponent={ImageComponent} /></section>;
176
- if (section.type === "theme-component") return <ThemeComponent key={section.id || index} section={section} submitContact={submitContact} ImageComponent={ImageComponent} />;
177
- if (["image-text", "rich-text", "cta"].includes(section.type)) return <TextSection key={section.id || index} section={section} ImageComponent={ImageComponent} />;
178
- if (section.type === "products-grid" || section.type === "products-carousel") {
179
- const category = productCategory(section.data);
180
- const items = products.filter((product) => !category || product.categories.some(({ slug }) => slug === category) || product.categoryPath?.includes(category)).slice(0, limit(section.data));
181
- const matchingPath = category
182
- ? items.find((product) => product.categoryPath?.includes(category))?.categoryPath
183
- : undefined;
184
- const categoryIndex = matchingPath?.indexOf(category) ?? -1;
185
- const allProductsHref = categoryIndex >= 0 && matchingPath
186
- ? categoryUrl(matchingPath.slice(0, categoryIndex + 1))
187
- : category ? `/produtos?categoria=${encodeURIComponent(category)}` : "/produtos";
188
- const productsView = section.type === "products-grid"
189
- ? <ProductGrid products={items} columns={catalog?.desktopColumns} showCategory={catalog?.showCategory} showDescription={catalog?.showDescription} ImageComponent={ImageComponent} />
190
- : <ProductCarousel products={items} showCategory={catalog?.showCategory} showDescription={catalog?.showDescription} ImageComponent={ImageComponent} />;
191
- return <section className="store-section home-products-section" data-layout={section.type === "products-carousel" ? "carousel" : "grid"} key={section.id || index}><div className="store-container"><Heading data={section.data} href={allProductsHref} />{productsView}</div></section>;
192
- }
193
- const map = section.type === "services-grid" ? { items: services, path: "/servicos" } : section.type === "cases-grid" ? { items: cases, path: "/cases" } : { items: posts, path: "/blog" };
194
- return <section className="store-section home-editorial-section" key={section.id || index}><div className="store-container"><Heading data={section.data} href={map.path} /><EditorialGrid items={map.items.slice(0, limit(section.data))} basePath={map.path} ImageComponent={ImageComponent} /></div></section>;
195
- })}</>;
673
+ return (
674
+ <>
675
+ {visible.map((section, index) => {
676
+ if (section.type === "hero")
677
+ return (
678
+ <Hero
679
+ key={section.id || index}
680
+ section={section}
681
+ priority={index === 0}
682
+ ImageComponent={ImageComponent}
683
+ />
684
+ );
685
+ if (section.type === "banner-carousel")
686
+ return (
687
+ <section className="home-banner-section" key={section.id || index}>
688
+ <BannerCarousel
689
+ banners={banners(section.data)}
690
+ autoplay={section.data.autoplay !== false}
691
+ desktopHeight={
692
+ typeof section.data.desktopHeight === "number"
693
+ ? section.data.desktopHeight
694
+ : undefined
695
+ }
696
+ mobileHeight={
697
+ typeof section.data.mobileHeight === "number"
698
+ ? section.data.mobileHeight
699
+ : undefined
700
+ }
701
+ imageFit={
702
+ section.data.imageFit === "CONTAIN" ||
703
+ section.data.imageFit === "NATURAL"
704
+ ? section.data.imageFit
705
+ : "COVER"
706
+ }
707
+ priority={index === 0}
708
+ ImageComponent={ImageComponent}
709
+ />
710
+ </section>
711
+ );
712
+ if (section.type === "mini-banners")
713
+ return (
714
+ <MiniBanners
715
+ key={section.id || index}
716
+ layout={section.data.layout === "3x1" ? "3x1" : "2x1"}
717
+ items={miniBanners(section.data)}
718
+ ImageComponent={ImageComponent}
719
+ />
720
+ );
721
+ if (section.type === "theme-component")
722
+ return (
723
+ <ThemeComponent
724
+ key={section.id || index}
725
+ section={section}
726
+ submitContact={submitContact}
727
+ ImageComponent={ImageComponent}
728
+ />
729
+ );
730
+ if (["image-text", "rich-text", "cta"].includes(section.type))
731
+ return (
732
+ <TextSection
733
+ key={section.id || index}
734
+ section={section}
735
+ ImageComponent={ImageComponent}
736
+ />
737
+ );
738
+ if (
739
+ section.type === "products-grid" ||
740
+ section.type === "products-carousel"
741
+ ) {
742
+ const category = productCategory(section.data);
743
+ const items = products
744
+ .filter(
745
+ (product) =>
746
+ !category ||
747
+ product.categories.some(({ slug }) => slug === category) ||
748
+ product.categoryPath?.includes(category),
749
+ )
750
+ .slice(0, limit(section.data));
751
+ const matchingPath = category
752
+ ? items.find((product) => product.categoryPath?.includes(category))
753
+ ?.categoryPath
754
+ : undefined;
755
+ const categoryIndex = matchingPath?.indexOf(category) ?? -1;
756
+ const allProductsHref =
757
+ categoryIndex >= 0 && matchingPath
758
+ ? categoryUrl(matchingPath.slice(0, categoryIndex + 1))
759
+ : category
760
+ ? `/produtos?categoria=${encodeURIComponent(category)}`
761
+ : "/produtos";
762
+ const productsView =
763
+ section.type === "products-grid" ? (
764
+ <ProductGrid
765
+ products={items}
766
+ columns={catalog?.desktopColumns}
767
+ showPrices={catalog?.showPrices}
768
+ showCategory={catalog?.showCategory}
769
+ showDescription={catalog?.showDescription}
770
+ ImageComponent={ImageComponent}
771
+ />
772
+ ) : (
773
+ <ProductCarousel
774
+ products={items}
775
+ showPrices={catalog?.showPrices}
776
+ showCategory={catalog?.showCategory}
777
+ showDescription={catalog?.showDescription}
778
+ ImageComponent={ImageComponent}
779
+ />
780
+ );
781
+ return (
782
+ <section
783
+ className="store-section home-products-section"
784
+ data-layout={
785
+ section.type === "products-carousel" ? "carousel" : "grid"
786
+ }
787
+ key={section.id || index}
788
+ >
789
+ <div className="store-container">
790
+ <Heading data={section.data} href={allProductsHref} />
791
+ {productsView}
792
+ </div>
793
+ </section>
794
+ );
795
+ }
796
+ const map =
797
+ section.type === "services-grid"
798
+ ? { items: services, path: "/servicos" }
799
+ : section.type === "cases-grid"
800
+ ? { items: cases, path: "/cases" }
801
+ : { items: posts, path: "/blog" };
802
+ return (
803
+ <section
804
+ className="store-section home-editorial-section"
805
+ key={section.id || index}
806
+ >
807
+ <div className="store-container">
808
+ <Heading data={section.data} href={map.path} />
809
+ <EditorialGrid
810
+ items={map.items.slice(0, limit(section.data))}
811
+ basePath={map.path}
812
+ ImageComponent={ImageComponent}
813
+ />
814
+ </div>
815
+ </section>
816
+ );
817
+ })}
818
+ </>
819
+ );
196
820
  }