@nuvler/cli 0.5.12 → 0.5.14
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/api/theme-context.js +3 -1
- package/dist/api/theme-context.js.map +1 -1
- package/dist/nuvler.js +6 -1
- package/dist/nuvler.js.map +1 -1
- package/dist/templates/nuvler-atelier/package.json +1 -1
- package/dist/templates/nuvler-atelier/src/definition.tsx +3 -3
- package/dist/templates/nuvler-atelier/src/theme.tsx +34 -1
- package/dist/templates/nuvler-default/README.md +5 -3
- package/dist/templates/nuvler-default/nuvler.theme.json +1 -1
- package/dist/templates/nuvler-default/package.json +1 -1
- package/dist/templates/nuvler-default/src/footer.tsx +2 -1
- package/dist/templates/nuvler-default/src/home.tsx +5 -0
- package/dist/templates/nuvler-default/src/not-found.tsx +9 -2
- package/dist/templates/nuvler-default/src/theme-component.tsx +114 -18
- package/dist/templates/nuvler-default/src/theme.css +991 -265
- package/dist/templates/nuvler-default/test/home-reference.test.mjs +42 -0
- package/dist/templates/starter/package.json +1 -1
- package/dist/templates/starter/src/theme.tsx +20 -2
- package/package.json +1 -1
- package/preview-host/vendor/theme-runtime/default-theme.tsx +4 -2
|
@@ -154,7 +154,7 @@ function Footer({ site, pages }: FooterProps) {
|
|
|
154
154
|
const contact = site.settings?.contact;
|
|
155
155
|
return <footer className="atelier-footer">
|
|
156
156
|
<div className="atelier-container atelier-footer-grid">
|
|
157
|
-
<div className="atelier-footer-brand"
|
|
157
|
+
<div className="atelier-footer-brand">{(site.settings?.footerLogo ?? site.settings?.logo)?.url ? <AtelierImage image={site.settings?.footerLogo ?? site.settings?.logo} alt={name} /> : <span className="atelier-brand-mark">N</span>}<h2>{name}</h2><p>{site.settings?.description || "Produtos selecionados, informação clara e atendimento próximo."}</p></div>
|
|
158
158
|
<div><small>Explore</small><a href="/produtos">Produtos</a><a href="/blog">Conteúdo</a><a href="/servicos">Serviços</a><a href="/cases">Cases</a></div>
|
|
159
159
|
<div><small>Institucional</small>{pages.slice(0, 5).map((page) => <a href={`/${page.slug}`} key={page.slug}>{page.title}</a>)}</div>
|
|
160
160
|
<div><small>Atendimento</small>{contact?.whatsapp && <a href={`https://wa.me/${contact.whatsapp.replace(/\D/g, "")}`}>WhatsApp</a>}{contact?.email && <a href={`mailto:${contact.email}`}>{contact.email}</a>}{contact?.phone && <a href={`tel:${contact.phone}`}>{contact.phone}</a>}<p>{contact?.address}</p></div>
|
|
@@ -186,7 +186,7 @@ function Home({ sections, products, posts, services, cases, site, template }: Ho
|
|
|
186
186
|
const editorial = [...posts, ...cases].slice(0, 3);
|
|
187
187
|
const bannerSections = sections.filter((section) => section.enabled && section.type === "banner-carousel");
|
|
188
188
|
return <main>
|
|
189
|
-
<section className="atelier-hero atelier-container">
|
|
189
|
+
<section id={hero?.reference} style={{ scrollMarginTop: "100px" }} className="atelier-hero atelier-container">
|
|
190
190
|
<div className="atelier-hero-copy"><span className="atelier-kicker">Nuvler Atelier · edição 01</span><h1>{heroTitle}</h1><p>{heroDescription}</p><div><a className="atelier-button atelier-button-light" href={heroUrl}>{heroButton}<b>↗</b></a><a className="atelier-text-link" href="/produtos">Ver catálogo completo →</a></div></div>
|
|
191
191
|
<div className="atelier-hero-visual">
|
|
192
192
|
<span className="atelier-orbit" /><span className="atelier-orbit second" />
|
|
@@ -194,7 +194,7 @@ function Home({ sections, products, posts, services, cases, site, template }: Ho
|
|
|
194
194
|
{highlight && <a href={productUrl(highlight)}><small>Destaque da semana</small><strong>{highlight.title}</strong><span>{showPrices ? price(highlight) || "Conheça o produto" : "Conheça o produto"} →</span></a>}
|
|
195
195
|
</div>
|
|
196
196
|
</section>
|
|
197
|
-
{bannerSections.map((section, index) => <AtelierBannerCarousel section={section} key={section.id || index} />)}
|
|
197
|
+
{bannerSections.map((section, index) => section.reference ? <div id={section.reference} style={{ scrollMarginTop: "100px" }} key={section.id || index}><AtelierBannerCarousel section={section} /></div> : <AtelierBannerCarousel section={section} key={section.id || index} />)}
|
|
198
198
|
<section className="atelier-marquee"><div>{template.benefits.concat(template.benefits).map((benefit, index) => <span key={`${benefit.title}-${index}`}><b>✦</b>{benefit.title}<small>{benefit.description}</small></span>)}</div></section>
|
|
199
199
|
<section className="atelier-section atelier-container">
|
|
200
200
|
<header className="atelier-section-heading"><div><span className="atelier-kicker">Seleção essencial</span><h2>Produtos que merecem atenção</h2></div><p>Uma vitrine com mais respiro, imagens protagonistas e as informações certas para decidir.</p><a href="/produtos">Explorar tudo ↗</a></header>
|
|
@@ -4,6 +4,7 @@ import type {
|
|
|
4
4
|
ThemeCartItem,
|
|
5
5
|
ThemeEditorialItem,
|
|
6
6
|
ThemeRoute,
|
|
7
|
+
ThemePageContent,
|
|
7
8
|
ThemeSite,
|
|
8
9
|
} from "@nuvler/theme-sdk";
|
|
9
10
|
import { AtelierImage, plainText, themeDefinition } from "./definition.js";
|
|
@@ -31,6 +32,38 @@ function catalogHref(route: Extract<ThemeRoute, { type: "catalog" }>, page: numb
|
|
|
31
32
|
return params.size ? `${pathname}?${params}` : pathname;
|
|
32
33
|
}
|
|
33
34
|
|
|
35
|
+
function PageBlocks({ content }: { content: ThemePageContent }) {
|
|
36
|
+
return <div className="atelier-page-content">{content.blocks.map((block, index) => {
|
|
37
|
+
const data = block.data;
|
|
38
|
+
const key = block.id || `${block.type}-${index}`;
|
|
39
|
+
const text = (value: unknown) => typeof value === "string" ? plainText(value) : "";
|
|
40
|
+
if (block.type === "header") return <h2 key={key}>{text(data.text)}</h2>;
|
|
41
|
+
if (block.type === "paragraph") return <p key={key}>{text(data.text)}</p>;
|
|
42
|
+
if (block.type === "delimiter") return <hr key={key} />;
|
|
43
|
+
if (block.type === "quote") return <blockquote key={key}><p>{text(data.text)}</p>{text(data.caption) && <cite>{text(data.caption)}</cite>}</blockquote>;
|
|
44
|
+
if (block.type === "list") {
|
|
45
|
+
const items = Array.isArray(data.items) ? data.items : [];
|
|
46
|
+
const List = data.style === "ordered" ? "ol" : "ul";
|
|
47
|
+
return <List key={key}>{items.map((item, itemIndex) => <li key={itemIndex}>{text(item && typeof item === "object" && "content" in item ? (item as { content: unknown }).content : item)}</li>)}</List>;
|
|
48
|
+
}
|
|
49
|
+
if (block.type === "image") {
|
|
50
|
+
const image = data.file && typeof data.file === "object" ? data.file as Record<string, unknown> : {};
|
|
51
|
+
const url = typeof image.url === "string" ? image.url : "";
|
|
52
|
+
return url ? <figure key={key}><img src={url} alt={text(data.caption)} loading="lazy" />{text(data.caption) && <figcaption>{text(data.caption)}</figcaption>}</figure> : null;
|
|
53
|
+
}
|
|
54
|
+
if (block.type === "imageText") {
|
|
55
|
+
const image = data.image && typeof data.image === "object" ? data.image as Record<string, unknown> : {};
|
|
56
|
+
const url = typeof image.url === "string" ? image.url : "";
|
|
57
|
+
return <section className="atelier-page-image-text" key={key}>{url && <img src={url} alt={text(image.alt)} loading="lazy" />}<div>{text(data.title) && <h2>{text(data.title)}</h2>}{text(data.text) && <p>{text(data.text)}</p>}</div></section>;
|
|
58
|
+
}
|
|
59
|
+
if (block.type === "table") {
|
|
60
|
+
const rows = Array.isArray(data.content) ? data.content : [];
|
|
61
|
+
return <div className="atelier-page-table" key={key}><table><tbody>{rows.map((row, rowIndex) => <tr key={rowIndex}>{Array.isArray(row) ? row.map((cell, cellIndex) => <td key={cellIndex}>{text(cell)}</td>) : null}</tr>)}</tbody></table></div>;
|
|
62
|
+
}
|
|
63
|
+
return null;
|
|
64
|
+
})}</div>;
|
|
65
|
+
}
|
|
66
|
+
|
|
34
67
|
function EditorialList({ title, basePath, items }: { title: string; basePath: string; items: ThemeEditorialItem[] }) {
|
|
35
68
|
return <main className="atelier-page atelier-container">
|
|
36
69
|
<header className="atelier-page-heading"><span className="atelier-kicker">Caderno Nuvler</span><h1>{title}</h1><p>Ideias, referências e histórias selecionadas para ajudar em cada escolha.</p></header>
|
|
@@ -115,7 +148,7 @@ export default function Theme({ context, route = { type: "home" }, sdk, adapters
|
|
|
115
148
|
} else if (route.type === "editorial-detail") {
|
|
116
149
|
content = <main className="atelier-page atelier-container"><article className="atelier-article"><span className="atelier-kicker">Caderno Nuvler</span><h1>{route.item.title}</h1><AtelierImage image={route.item.image || route.item.thumbnail || route.item.coverImage} alt={route.item.title} /><p>{route.item.description}</p><a href={route.basePath}>← Voltar</a></article></main>;
|
|
117
150
|
} else if (route.type === "page") {
|
|
118
|
-
content = <main className="atelier-page atelier-container"><header className="atelier-page-heading"><span className="atelier-kicker">Institucional</span><h1>{route.title}</h1></header
|
|
151
|
+
content = <main className="atelier-page atelier-container"><header className="atelier-page-heading"><span className="atelier-kicker">Institucional</span><h1>{route.title}</h1></header><PageBlocks content={route.content} /></main>;
|
|
119
152
|
} else {
|
|
120
153
|
content = <main className="atelier-page atelier-container"><header className="atelier-page-heading"><span className="atelier-kicker">{route.type === "loading" ? "Carregando" : "404"}</span><h1>{route.type === "loading" ? "Preparando sua experiência…" : "Essa página não foi encontrada."}</h1><a className="atelier-button atelier-button-dark" href="/">Voltar ao início</a></header></main>;
|
|
121
154
|
}
|
|
@@ -64,8 +64,10 @@ node packages/cli/dist/nuvler.js theme dev \
|
|
|
64
64
|
Para compilar, gerar o artefato ou publicar, execute na raiz do tooling:
|
|
65
65
|
|
|
66
66
|
```bash
|
|
67
|
-
npm run pack:
|
|
68
|
-
npm
|
|
67
|
+
npm run pack:cli
|
|
68
|
+
npm run pack:default
|
|
69
|
+
npm publish ./artifacts/nuvler-cli-0.5.13.tgz --access public
|
|
70
|
+
npm publish ./artifacts/nuvler-theme-default-1.1.7.tgz --access public
|
|
69
71
|
|
|
70
72
|
node packages/cli/dist/nuvler.js theme build --theme themes/nuvler-default
|
|
71
73
|
npm run pack:theme -- nuvler-default
|
|
@@ -73,7 +75,7 @@ node packages/cli/dist/nuvler.js theme publish --theme themes/nuvler-default --o
|
|
|
73
75
|
```
|
|
74
76
|
|
|
75
77
|
O pacote npm contém o renderer local e o CSS. O artefato do Theme Registry é
|
|
76
|
-
gerado separadamente como `artifacts/nuvler-default-1.1.
|
|
78
|
+
gerado separadamente como `artifacts/nuvler-default-1.1.7.nuvler-theme.tgz`.
|
|
77
79
|
|
|
78
80
|
Exemplo no App Router:
|
|
79
81
|
|
|
@@ -10,5 +10,6 @@ export interface NuvlerDefaultFooterProps extends FooterProps {
|
|
|
10
10
|
export function Footer({ site, pages, template, platformBrand, ImageComponent = ThemeImageView }: NuvlerDefaultFooterProps) {
|
|
11
11
|
const settings = site.settings;
|
|
12
12
|
const name = settings?.siteName || site.tenant.name;
|
|
13
|
-
|
|
13
|
+
const logo = settings?.footerLogo ?? settings?.logo;
|
|
14
|
+
return <footer className="store-footer"><div className="store-container footer-grid"><div className="footer-intro"><a className="footer-brand" href="/" aria-label={`${name} — início`}>{logo?.url ? <ImageComponent image={logo} fallbackAlt={name} className="footer-logo" sizes="200px" fallbackWidth={240} fallbackHeight={96} /> : name}</a><p>{settings?.description || template.footerTagline}</p>{settings?.contact.whatsapp && <a className="footer-contact-cta" href={`https://wa.me/${settings.contact.whatsapp.replace(/\D/g, "")}`} target="_blank" rel="noreferrer">Fale pelo WhatsApp <span aria-hidden="true">→</span></a>}</div><div><strong>{template.footerNavigationLabel}</strong>{site.modules.includes("PRODUCTS") && <a href="/produtos">Todos os produtos</a>}{site.modules.includes("BLOG") && <a href="/blog">Blog</a>}{site.modules.includes("SERVICES") && <a href="/servicos">Serviços</a>}{site.modules.includes("CASES") && <a href="/cases">Cases</a>}<a href="/">Início</a></div>{pages.length > 0 && <div><strong>Institucional</strong>{pages.slice(0, 6).map((page) => <a key={page.slug} href={`/${page.slug}`}>{page.title}</a>)}</div>}<div><strong>Atendimento</strong>{settings?.contact.email && <a href={`mailto:${settings.contact.email}`}>{settings.contact.email}</a>}{settings?.contact.phone && <a href={`tel:${settings.contact.phone}`}>{settings.contact.phone}</a>}{settings?.contact.address && <span>{settings.contact.address}</span>}</div>{settings?.social && Object.values(settings.social).some(Boolean) && <div className="footer-social"><strong>{template.socialLabel}</strong>{settings.social.instagram && <a href={settings.social.instagram} target="_blank" rel="noreferrer">Instagram</a>}{settings.social.facebook && <a href={settings.social.facebook} target="_blank" rel="noreferrer">Facebook</a>}{settings.social.youtube && <a href={settings.social.youtube} target="_blank" rel="noreferrer">YouTube</a>}{settings.social.tiktok && <a href={settings.social.tiktok} target="_blank" rel="noreferrer">TikTok</a>}</div>}</div><div className="store-container footer-bottom"><span>© {new Date().getFullYear()} {name}</span><span>{template.footerNote}</span>{platformBrand && <span data-nuvler-platform-brand-slot>{platformBrand}</span>}</div></footer>;
|
|
14
15
|
}
|
|
@@ -673,6 +673,7 @@ export function Home({
|
|
|
673
673
|
return (
|
|
674
674
|
<>
|
|
675
675
|
{visible.map((section, index) => {
|
|
676
|
+
const content = (() => {
|
|
676
677
|
if (section.type === "hero")
|
|
677
678
|
return (
|
|
678
679
|
<Hero
|
|
@@ -814,6 +815,10 @@ export function Home({
|
|
|
814
815
|
</div>
|
|
815
816
|
</section>
|
|
816
817
|
);
|
|
818
|
+
})();
|
|
819
|
+
return section.reference
|
|
820
|
+
? <div key={section.id || index} id={section.reference} style={{ scrollMarginTop: "100px" }}>{content}</div>
|
|
821
|
+
: content;
|
|
817
822
|
})}
|
|
818
823
|
</>
|
|
819
824
|
);
|
|
@@ -1,7 +1,14 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
|
|
3
3
|
import type { NotFoundProps } from "@nuvler/theme-sdk";
|
|
4
|
-
|
|
4
|
+
|
|
5
|
+
function SadCloudIllustration() {
|
|
6
|
+
return <svg className="nuvler-not-found-cloud-svg" viewBox="0 0 640 420" aria-hidden="true">
|
|
7
|
+
<path fill="currentColor" fillRule="evenodd" clipRule="evenodd" d="M124 319C75 319 36 282 36 236C36 195 67 161 108 155C112 100 158 58 215 58C242 58 267 67 287 83C316 45 362 22 413 22C488 22 550 77 559 148C605 154 640 192 640 238C640 283 603 319 556 319H124ZM250 183C239 183 232 194 232 210C232 226 239 237 250 237C261 237 268 226 268 210C268 194 261 183 250 183ZM391 183C380 183 373 194 373 210C373 226 380 237 391 237C402 237 409 226 409 210C409 194 402 183 391 183ZM210 164C224 160 238 152 250 140C254 136 260 137 263 141C267 145 266 151 262 155C248 169 231 178 215 181C210 182 206 179 205 174C204 169 206 166 210 164ZM432 164C418 160 404 152 392 140C388 136 382 137 379 141C375 145 376 151 380 155C394 169 411 178 427 181C432 182 436 179 437 174C438 169 436 166 432 164ZM282 260C292 241 307 232 321 232C336 232 351 241 360 260C362 265 360 270 355 272C350 274 346 271 344 267C338 254 330 247 321 247C312 247 304 254 297 267C295 271 290 274 285 272C280 270 279 265 282 260Z" />
|
|
8
|
+
<path fill="currentColor" fillRule="evenodd" clipRule="evenodd" d="M165 286C165 254 190 229 222 229C254 229 280 254 280 286C280 316 259 339 231 344C219 346 209 341 202 332C195 342 184 347 172 344C145 338 128 312 135 286C139 270 149 258 165 250V286ZM167 300C171 297 176 298 179 302C187 311 192 320 195 331C196 336 193 340 188 341C183 342 179 339 178 334C176 326 171 317 164 310C161 306 162 302 167 300ZM192 294C196 291 201 292 204 296C212 305 217 314 220 325C221 330 218 334 213 335C208 336 204 333 203 328C201 320 196 311 189 304C186 300 187 296 192 294Z" />
|
|
9
|
+
<path fill="currentColor" fillRule="evenodd" clipRule="evenodd" d="M360 286C360 254 386 229 418 229C450 229 476 254 476 286C476 316 455 339 427 344C415 346 405 341 398 332C391 342 380 347 368 344C341 338 324 312 331 286C335 270 345 258 360 250V286ZM362 300C366 297 371 298 374 302C382 311 387 320 390 331C391 336 388 340 383 341C378 342 374 339 373 334C371 326 366 317 359 310C356 306 357 302 362 300ZM387 294C391 291 396 292 399 296C407 305 412 314 415 325C416 330 413 334 408 335C403 336 399 333 398 328C396 320 391 311 384 304C381 300 382 296 387 294Z" />
|
|
10
|
+
</svg>;
|
|
11
|
+
}
|
|
5
12
|
|
|
6
13
|
export function NotFound({ homeHref = "/" }: NotFoundProps) {
|
|
7
14
|
const goBack = () => {
|
|
@@ -15,7 +22,7 @@ export function NotFound({ homeHref = "/" }: NotFoundProps) {
|
|
|
15
22
|
return <main className="nuvler-not-found">
|
|
16
23
|
<div className="nuvler-not-found-content">
|
|
17
24
|
<div className="nuvler-not-found-visual" aria-hidden="true">
|
|
18
|
-
<
|
|
25
|
+
<SadCloudIllustration />
|
|
19
26
|
<span className="nuvler-not-found-code">404</span>
|
|
20
27
|
</div>
|
|
21
28
|
<h1>Página não encontrada</h1>
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
|
|
3
|
-
import { useEffect, useMemo, useState, type CSSProperties } from "react";
|
|
3
|
+
import { useEffect, useMemo, useRef, useState, type CSSProperties } from "react";
|
|
4
4
|
import {
|
|
5
5
|
productUrl,
|
|
6
6
|
type NuvlerStoreThemeDefinition,
|
|
@@ -9,7 +9,9 @@ import {
|
|
|
9
9
|
type ThemeEditorialItem,
|
|
10
10
|
type ThemeHomeSection,
|
|
11
11
|
type ThemeNavigationItem,
|
|
12
|
+
type ThemePageContent,
|
|
12
13
|
type ThemePageSummary,
|
|
14
|
+
type ThemeImage,
|
|
13
15
|
type ThemeProduct,
|
|
14
16
|
type ThemeRuntimeAdapters,
|
|
15
17
|
type ThemeRuntimeSdk,
|
|
@@ -39,7 +41,8 @@ interface PreviewContext {
|
|
|
39
41
|
}
|
|
40
42
|
|
|
41
43
|
type PreviewRoute =
|
|
42
|
-
| { type: "home" | "loading" | "not-found"
|
|
44
|
+
| { type: "home" | "loading" | "not-found"; title?: string }
|
|
45
|
+
| { type: "page"; title: string; slug: string; content: ThemePageContent }
|
|
43
46
|
| {
|
|
44
47
|
type: "catalog";
|
|
45
48
|
products: ThemeProduct[];
|
|
@@ -68,6 +71,43 @@ type PreviewRoute =
|
|
|
68
71
|
}
|
|
69
72
|
| { type: "editorial-detail"; basePath: string; item: ThemeEditorialItem };
|
|
70
73
|
|
|
74
|
+
function PageBlocks({ content }: { content: ThemePageContent }) {
|
|
75
|
+
const text = (value: unknown): string => typeof value === "string" ? plainText(value) : "";
|
|
76
|
+
return <div className="article-content content-renderer">{content.blocks.map((block, index) => {
|
|
77
|
+
const data = block.data;
|
|
78
|
+
const key = block.id || `${block.type}-${index}`;
|
|
79
|
+
if (block.type === "header") {
|
|
80
|
+
const heading = text(data.text);
|
|
81
|
+
return Number(data.level) === 3 ? <h3 key={key}>{heading}</h3> : <h2 key={key}>{heading}</h2>;
|
|
82
|
+
}
|
|
83
|
+
if (block.type === "paragraph") return <p key={key}>{text(data.text)}</p>;
|
|
84
|
+
if (block.type === "delimiter") return <hr key={key} />;
|
|
85
|
+
if (block.type === "quote") return <blockquote key={key}><p>{text(data.text)}</p>{text(data.caption) && <cite>{text(data.caption)}</cite>}</blockquote>;
|
|
86
|
+
if (block.type === "list") {
|
|
87
|
+
const items = Array.isArray(data.items) ? data.items : [];
|
|
88
|
+
const List = data.style === "ordered" ? "ol" : "ul";
|
|
89
|
+
return <List key={key}>{items.map((item, itemIndex) => <li key={itemIndex}>{text(item && typeof item === "object" && "content" in item ? (item as { content: unknown }).content : item)}</li>)}</List>;
|
|
90
|
+
}
|
|
91
|
+
if (block.type === "image") {
|
|
92
|
+
const file = data.file && typeof data.file === "object" ? data.file as Record<string, unknown> : {};
|
|
93
|
+
const url = typeof file.url === "string" ? file.url : "";
|
|
94
|
+
const image: ThemeImage | null = url ? { url, alt: text(data.caption), width: null, height: null } : null;
|
|
95
|
+
return image ? <figure key={key}><ThemeImageView image={image} fallbackAlt={text(data.caption) || "Imagem do conteúdo"} />{text(data.caption) && <figcaption>{text(data.caption)}</figcaption>}</figure> : null;
|
|
96
|
+
}
|
|
97
|
+
if (block.type === "imageText") {
|
|
98
|
+
const rawImage = data.image && typeof data.image === "object" ? data.image as Record<string, unknown> : {};
|
|
99
|
+
const url = typeof rawImage.url === "string" ? rawImage.url : "";
|
|
100
|
+
const image: ThemeImage | null = url ? { url, alt: text(rawImage.alt), width: null, height: null } : null;
|
|
101
|
+
return <section className="content-image-text" key={key}>{image && <ThemeImageView image={image} fallbackAlt="Imagem do conteúdo" />}<div>{text(data.title) && <h2>{text(data.title)}</h2>}{text(data.text) && <p>{text(data.text)}</p>}</div></section>;
|
|
102
|
+
}
|
|
103
|
+
if (block.type === "table") {
|
|
104
|
+
const rows = Array.isArray(data.content) ? data.content : [];
|
|
105
|
+
return <div className="content-table" key={key}><table><tbody>{rows.map((row, rowIndex) => <tr key={rowIndex}>{Array.isArray(row) ? row.map((cell, cellIndex) => <td key={cellIndex}>{text(cell)}</td>) : null}</tr>)}</tbody></table></div>;
|
|
106
|
+
}
|
|
107
|
+
return null;
|
|
108
|
+
})}</div>;
|
|
109
|
+
}
|
|
110
|
+
|
|
71
111
|
export interface NuvlerDefaultThemeProps {
|
|
72
112
|
context: PreviewContext;
|
|
73
113
|
route?: PreviewRoute;
|
|
@@ -227,7 +267,10 @@ export function createNuvlerDefaultRuntime(
|
|
|
227
267
|
}: NuvlerDefaultThemeProps) {
|
|
228
268
|
const [cartItems, setCartItems] = useState<PreviewCartItem[]>([]);
|
|
229
269
|
const [cartOpen, setCartOpen] = useState(false);
|
|
270
|
+
const [cartToast, setCartToast] = useState<string | null>(null);
|
|
271
|
+
const [cartViewportHeight, setCartViewportHeight] = useState<number | null>(null);
|
|
230
272
|
const [hydratedCartKey, setHydratedCartKey] = useState<string | null>(null);
|
|
273
|
+
const cartToastTimeout = useRef<ReturnType<typeof window.setTimeout> | null>(null);
|
|
231
274
|
const cartStorageKey = `nuvler:cart:${context.store.slug}`;
|
|
232
275
|
|
|
233
276
|
useEffect(() => {
|
|
@@ -245,6 +288,29 @@ export function createNuvlerDefaultRuntime(
|
|
|
245
288
|
window.localStorage.setItem(cartStorageKey, JSON.stringify(cartItems));
|
|
246
289
|
}, [cartItems, cartStorageKey, hydratedCartKey]);
|
|
247
290
|
|
|
291
|
+
useEffect(() => () => {
|
|
292
|
+
if (cartToastTimeout.current) window.clearTimeout(cartToastTimeout.current);
|
|
293
|
+
}, []);
|
|
294
|
+
|
|
295
|
+
useEffect(() => {
|
|
296
|
+
if (!cartOpen) return;
|
|
297
|
+
|
|
298
|
+
const viewport = window.visualViewport;
|
|
299
|
+
const syncCartViewportHeight = () =>
|
|
300
|
+
setCartViewportHeight(Math.round(viewport?.height ?? window.innerHeight));
|
|
301
|
+
|
|
302
|
+
syncCartViewportHeight();
|
|
303
|
+
window.addEventListener("resize", syncCartViewportHeight);
|
|
304
|
+
viewport?.addEventListener("resize", syncCartViewportHeight);
|
|
305
|
+
viewport?.addEventListener("scroll", syncCartViewportHeight);
|
|
306
|
+
|
|
307
|
+
return () => {
|
|
308
|
+
window.removeEventListener("resize", syncCartViewportHeight);
|
|
309
|
+
viewport?.removeEventListener("resize", syncCartViewportHeight);
|
|
310
|
+
viewport?.removeEventListener("scroll", syncCartViewportHeight);
|
|
311
|
+
};
|
|
312
|
+
}, [cartOpen]);
|
|
313
|
+
|
|
248
314
|
const { Header, Footer, Home, ProductDetail, ProductGrid, NotFound } =
|
|
249
315
|
themeDefinition.components;
|
|
250
316
|
const site: ThemeSite = {
|
|
@@ -327,7 +393,12 @@ export function createNuvlerDefaultRuntime(
|
|
|
327
393
|
);
|
|
328
394
|
return [...current, { ...item, key, quantity: 1 }];
|
|
329
395
|
});
|
|
330
|
-
|
|
396
|
+
setCartToast(`“${item.title}” foi adicionado ao carrinho.`);
|
|
397
|
+
if (cartToastTimeout.current) window.clearTimeout(cartToastTimeout.current);
|
|
398
|
+
cartToastTimeout.current = window.setTimeout(() => {
|
|
399
|
+
setCartToast(null);
|
|
400
|
+
cartToastTimeout.current = null;
|
|
401
|
+
}, 3200);
|
|
331
402
|
};
|
|
332
403
|
const cartButton = (
|
|
333
404
|
<button
|
|
@@ -587,7 +658,19 @@ export function createNuvlerDefaultRuntime(
|
|
|
587
658
|
</article>
|
|
588
659
|
</main>
|
|
589
660
|
);
|
|
590
|
-
} else if (route.type === "
|
|
661
|
+
} else if (route.type === "page")
|
|
662
|
+
content = (
|
|
663
|
+
<main className="article-page">
|
|
664
|
+
<article className="store-container article-shell">
|
|
665
|
+
<header className="article-header">
|
|
666
|
+
<span>Página</span>
|
|
667
|
+
<h1>{route.title}</h1>
|
|
668
|
+
</header>
|
|
669
|
+
<PageBlocks content={route.content} />
|
|
670
|
+
</article>
|
|
671
|
+
</main>
|
|
672
|
+
);
|
|
673
|
+
else if (route.type === "not-found")
|
|
591
674
|
content = NotFound ? (
|
|
592
675
|
<NotFound homeHref="/" />
|
|
593
676
|
) : (
|
|
@@ -639,10 +722,24 @@ export function createNuvlerDefaultRuntime(
|
|
|
639
722
|
template={themeDefinition.template}
|
|
640
723
|
/>
|
|
641
724
|
)}
|
|
725
|
+
{cartToast && (
|
|
726
|
+
<div className="cart-toast" role="status" aria-live="polite">
|
|
727
|
+
<span aria-hidden="true">✓</span>
|
|
728
|
+
<p>{cartToast}</p>
|
|
729
|
+
<button type="button" onClick={() => setCartToast(null)} aria-label="Fechar aviso">×</button>
|
|
730
|
+
</div>
|
|
731
|
+
)}
|
|
642
732
|
{cartOpen && (
|
|
643
733
|
<div
|
|
644
734
|
className="cart-backdrop"
|
|
645
735
|
role="presentation"
|
|
736
|
+
style={
|
|
737
|
+
cartViewportHeight
|
|
738
|
+
? ({
|
|
739
|
+
"--cart-viewport-height": `${cartViewportHeight}px`,
|
|
740
|
+
} as CSSProperties)
|
|
741
|
+
: undefined
|
|
742
|
+
}
|
|
646
743
|
onPointerDown={(event) =>
|
|
647
744
|
event.target === event.currentTarget && setCartOpen(false)
|
|
648
745
|
}
|
|
@@ -699,6 +796,12 @@ export function createNuvlerDefaultRuntime(
|
|
|
699
796
|
<div className="cart-quantity">
|
|
700
797
|
<button
|
|
701
798
|
type="button"
|
|
799
|
+
className={item.quantity === 1 ? "cart-delete" : undefined}
|
|
800
|
+
aria-label={
|
|
801
|
+
item.quantity === 1
|
|
802
|
+
? `Remover ${item.title} do carrinho`
|
|
803
|
+
: `Diminuir quantidade de ${item.title}`
|
|
804
|
+
}
|
|
702
805
|
onClick={() =>
|
|
703
806
|
setCartItems((current) =>
|
|
704
807
|
current.flatMap((candidate) =>
|
|
@@ -716,7 +819,13 @@ export function createNuvlerDefaultRuntime(
|
|
|
716
819
|
)
|
|
717
820
|
}
|
|
718
821
|
>
|
|
719
|
-
|
|
822
|
+
{item.quantity === 1 ? (
|
|
823
|
+
<svg viewBox="0 0 24 24" aria-hidden="true">
|
|
824
|
+
<path d="M4 7h16M9 7V4h6v3m3 0-1 13H7L6 7m4 4v5m4-5v5" />
|
|
825
|
+
</svg>
|
|
826
|
+
) : (
|
|
827
|
+
"−"
|
|
828
|
+
)}
|
|
720
829
|
</button>
|
|
721
830
|
<span>{item.quantity}</span>
|
|
722
831
|
<button
|
|
@@ -739,19 +848,6 @@ export function createNuvlerDefaultRuntime(
|
|
|
739
848
|
>
|
|
740
849
|
+
|
|
741
850
|
</button>
|
|
742
|
-
<button
|
|
743
|
-
type="button"
|
|
744
|
-
className="cart-remove"
|
|
745
|
-
onClick={() =>
|
|
746
|
-
setCartItems((current) =>
|
|
747
|
-
current.filter(
|
|
748
|
-
(candidate) => candidate.key !== item.key,
|
|
749
|
-
),
|
|
750
|
-
)
|
|
751
|
-
}
|
|
752
|
-
>
|
|
753
|
-
Remover
|
|
754
|
-
</button>
|
|
755
851
|
</div>
|
|
756
852
|
</div>
|
|
757
853
|
</article>
|