@nuvler/cli 0.5.17 → 0.5.19
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.map +1 -1
- package/dist/commands/theme/create.js +1 -1
- package/dist/nuvler.js +10 -1
- package/dist/nuvler.js.map +1 -1
- package/dist/templates/nuvler-atelier/package.json +2 -2
- package/dist/templates/nuvler-default/README.md +4 -4
- 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/catalog-filters.tsx +169 -0
- package/dist/templates/nuvler-default/src/interaction-colors.ts +49 -0
- package/dist/templates/nuvler-default/src/kit-composition.ts +15 -0
- package/dist/templates/nuvler-default/src/not-found.tsx +288 -21
- package/dist/templates/nuvler-default/src/product-detail-interactive.tsx +24 -12
- package/dist/templates/nuvler-default/src/server-shell.tsx +21 -3
- package/dist/templates/nuvler-default/src/theme-component.tsx +100 -27
- package/dist/templates/nuvler-default/src/theme.css +599 -210
- package/dist/templates/nuvler-default/src/whatsapp-message.ts +82 -0
- package/dist/templates/nuvler-default/test/catalog-filters.test.mjs +44 -0
- package/dist/templates/nuvler-default/test/interaction-colors.test.mjs +74 -0
- package/dist/templates/nuvler-default/test/kit-composition.test.mjs +28 -0
- package/dist/templates/nuvler-default/test/kit-detail.test.mjs +3 -3
- package/dist/templates/nuvler-default/test/whatsapp-message.test.mjs +126 -0
- package/dist/templates/starter/package.json +2 -2
- package/package.json +3 -3
- package/preview-host/package.json +1 -1
- package/preview-host/vendor/theme-runtime/default-theme.tsx +15 -6
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
|
|
3
|
+
import {
|
|
4
|
+
formatWhatsappRequest,
|
|
5
|
+
whatsappRequestLabel,
|
|
6
|
+
whatsappRequestUrl,
|
|
7
|
+
} from "./whatsapp-message.js";
|
|
8
|
+
|
|
3
9
|
import {
|
|
4
10
|
createContext,
|
|
5
11
|
useEffect,
|
|
@@ -12,7 +18,6 @@ import {
|
|
|
12
18
|
} from "react";
|
|
13
19
|
import {
|
|
14
20
|
verifyKitCart,
|
|
15
|
-
kitCompositionText,
|
|
16
21
|
productUrl as relativeProductUrl,
|
|
17
22
|
type ProductDetailProps,
|
|
18
23
|
type ThemeCartItem,
|
|
@@ -89,7 +94,7 @@ export function ProductCardAction({
|
|
|
89
94
|
className="button button-primary button-block product-card-action"
|
|
90
95
|
onClick={() => onAddToCart(item)}
|
|
91
96
|
>
|
|
92
|
-
Adicionar ao
|
|
97
|
+
Adicionar ao Carrinho
|
|
93
98
|
</button>
|
|
94
99
|
);
|
|
95
100
|
}
|
|
@@ -222,14 +227,21 @@ export function ProductDetailInteractive({
|
|
|
222
227
|
"";
|
|
223
228
|
const unitPrice =
|
|
224
229
|
variant && !kitSize ? null : (product.promotionalPrice ?? product.price);
|
|
225
|
-
const
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
230
|
+
const message = formatWhatsappRequest(
|
|
231
|
+
[
|
|
232
|
+
{
|
|
233
|
+
...kitItem,
|
|
234
|
+
kitSize: kitSize || null,
|
|
235
|
+
variantName: kitSize ? "" : variantDescription,
|
|
236
|
+
sku: kitSize ? product.sku : variant?.sku || product.sku,
|
|
237
|
+
unitPrice: showPrices ? unitPrice : null,
|
|
238
|
+
productUrl: productUrl ?? undefined,
|
|
239
|
+
},
|
|
240
|
+
],
|
|
241
|
+
showPrices,
|
|
242
|
+
typeof window === "undefined" ? undefined : window.location.origin,
|
|
243
|
+
);
|
|
244
|
+
const whatsapp = phone ? whatsappRequestUrl(phone, message) : null;
|
|
233
245
|
const hasVariants = product.variantOptions.length > 0;
|
|
234
246
|
const outOfStock = product.stockQuantity === 0;
|
|
235
247
|
const canPurchase =
|
|
@@ -514,7 +526,7 @@ export function ProductDetailInteractive({
|
|
|
514
526
|
})
|
|
515
527
|
}
|
|
516
528
|
>
|
|
517
|
-
Adicionar ao
|
|
529
|
+
Adicionar ao Carrinho
|
|
518
530
|
</button>
|
|
519
531
|
)}
|
|
520
532
|
{canPurchase && whatsapp && (
|
|
@@ -537,7 +549,7 @@ export function ProductDetailInteractive({
|
|
|
537
549
|
target="_blank"
|
|
538
550
|
rel="noreferrer"
|
|
539
551
|
>
|
|
540
|
-
|
|
552
|
+
{whatsappRequestLabel}
|
|
541
553
|
</a>
|
|
542
554
|
)}
|
|
543
555
|
{canPurchase && !whatsapp && contact?.email && (
|
|
@@ -1,5 +1,12 @@
|
|
|
1
|
+
import { interactionColorVariables } from "./interaction-colors.js";
|
|
1
2
|
import type { CSSProperties, ReactNode } from "react";
|
|
2
|
-
import type {
|
|
3
|
+
import type {
|
|
4
|
+
ThemeCategory,
|
|
5
|
+
ThemeNavigationHeaderButton,
|
|
6
|
+
ThemeNavigationItem,
|
|
7
|
+
ThemePageSummary,
|
|
8
|
+
ThemeSite,
|
|
9
|
+
} from "@nuvler/theme-sdk";
|
|
3
10
|
|
|
4
11
|
import { Footer } from "./footer.js";
|
|
5
12
|
import { Header } from "./header.js";
|
|
@@ -42,9 +49,20 @@ export function NuvlerDefaultShell({
|
|
|
42
49
|
colors: { ...nuvlerDefaultTokens.colors, ...configured?.colors },
|
|
43
50
|
layout: { ...nuvlerDefaultTokens.layout, ...configured?.layout },
|
|
44
51
|
};
|
|
45
|
-
const containerWidth = Math.min(
|
|
46
|
-
|
|
52
|
+
const containerWidth = Math.min(
|
|
53
|
+
1600,
|
|
54
|
+
Math.max(
|
|
55
|
+
960,
|
|
56
|
+
Number(tokens.layout.containerWidth) ||
|
|
57
|
+
nuvlerDefaultTokens.layout.containerWidth,
|
|
58
|
+
),
|
|
59
|
+
);
|
|
60
|
+
const borderRadius = Math.min(
|
|
61
|
+
32,
|
|
62
|
+
Math.max(0, Number(tokens.layout.borderRadius) || 0),
|
|
63
|
+
);
|
|
47
64
|
const style = {
|
|
65
|
+
...interactionColorVariables(tokens.colors),
|
|
48
66
|
"--color-primary": tokens.colors.primary,
|
|
49
67
|
"--color-primary-text": tokens.colors.primaryText,
|
|
50
68
|
"--color-secondary": tokens.colors.secondary,
|
|
@@ -1,16 +1,25 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
|
|
3
|
+
import { interactionColorVariables } from "./interaction-colors.js";
|
|
4
|
+
import { CatalogFilters } from "./catalog-filters.js";
|
|
5
|
+
import { kitCompositionText } from "./kit-composition.js";
|
|
6
|
+
import {
|
|
7
|
+
formatWhatsappRequest,
|
|
8
|
+
whatsappRequestLabel,
|
|
9
|
+
whatsappRequestUrl,
|
|
10
|
+
} from "./whatsapp-message.js";
|
|
11
|
+
|
|
3
12
|
import {
|
|
4
13
|
useEffect,
|
|
5
14
|
useMemo,
|
|
6
15
|
useRef,
|
|
7
16
|
useState,
|
|
17
|
+
type ComponentType,
|
|
8
18
|
type CSSProperties,
|
|
9
19
|
} from "react";
|
|
10
20
|
import {
|
|
11
21
|
productUrl,
|
|
12
22
|
themeCartKey,
|
|
13
|
-
kitCompositionText,
|
|
14
23
|
verifyKitCart,
|
|
15
24
|
type NuvlerStoreThemeDefinition,
|
|
16
25
|
type ThemeCartItem,
|
|
@@ -18,6 +27,7 @@ import {
|
|
|
18
27
|
type ThemeEditorialItem,
|
|
19
28
|
type ThemeHomeSection,
|
|
20
29
|
type ThemeNavigationItem,
|
|
30
|
+
type ThemeNotFoundResource,
|
|
21
31
|
type ThemePageContent,
|
|
22
32
|
type ThemePageSummary,
|
|
23
33
|
type ThemeImage,
|
|
@@ -28,7 +38,25 @@ import {
|
|
|
28
38
|
} from "@nuvler/theme-sdk";
|
|
29
39
|
import { nuvlerDefaultTheme } from "./definition.js";
|
|
30
40
|
import { ThemeInteractionProvider } from "./product-detail-interactive.js";
|
|
31
|
-
import { plainText, ThemeImageView } from "./shared.js";
|
|
41
|
+
import { categoryUrl, plainText, ThemeImageView } from "./shared.js";
|
|
42
|
+
import type { NotFoundShortcut, NuvlerNotFoundProps } from "./not-found.js";
|
|
43
|
+
|
|
44
|
+
/** Atalhos do 404 genérico, conforme os módulos e conteúdos da loja. */
|
|
45
|
+
function notFoundShortcuts(context: PreviewContext): NotFoundShortcut[] {
|
|
46
|
+
const shortcuts: NotFoundShortcut[] = [];
|
|
47
|
+
if (context.site.modules.includes("PRODUCTS")) {
|
|
48
|
+
shortcuts.push({ label: "Produtos", href: "/produtos" });
|
|
49
|
+
for (const category of context.navigation.categories.slice(0, 2))
|
|
50
|
+
shortcuts.push({ label: category.name, href: categoryUrl([category.slug]) });
|
|
51
|
+
}
|
|
52
|
+
if (context.editorial.services.length)
|
|
53
|
+
shortcuts.push({ label: "Serviços", href: "/servicos" });
|
|
54
|
+
if (context.editorial.posts.length)
|
|
55
|
+
shortcuts.push({ label: "Blog", href: "/blog" });
|
|
56
|
+
if (context.editorial.cases.length)
|
|
57
|
+
shortcuts.push({ label: "Cases", href: "/cases" });
|
|
58
|
+
return shortcuts.slice(0, 5);
|
|
59
|
+
}
|
|
32
60
|
import { CustomHtmlContent } from "./custom-html-content.js";
|
|
33
61
|
|
|
34
62
|
interface PreviewContext {
|
|
@@ -56,7 +84,13 @@ type PreviewEditorialItem = ThemeEditorialItem & {
|
|
|
56
84
|
};
|
|
57
85
|
|
|
58
86
|
type PreviewRoute =
|
|
59
|
-
| { type: "home" | "loading"
|
|
87
|
+
| { type: "home" | "loading"; title?: string }
|
|
88
|
+
| {
|
|
89
|
+
type: "not-found";
|
|
90
|
+
title?: string;
|
|
91
|
+
pathname?: string;
|
|
92
|
+
resource?: ThemeNotFoundResource;
|
|
93
|
+
}
|
|
60
94
|
| { type: "page"; title: string; slug: string; content: ThemePageContent }
|
|
61
95
|
| {
|
|
62
96
|
type: "catalog";
|
|
@@ -405,9 +439,7 @@ export function createNuvlerDefaultRuntime(
|
|
|
405
439
|
null,
|
|
406
440
|
);
|
|
407
441
|
const [hydratedCartKey, setHydratedCartKey] = useState<string | null>(null);
|
|
408
|
-
const cartToastTimeout = useRef<
|
|
409
|
-
typeof window.setTimeout
|
|
410
|
-
> | null>(null);
|
|
442
|
+
const cartToastTimeout = useRef<number | null>(null);
|
|
411
443
|
const cartStorageKey = `nuvler:cart:${context.store.slug}`;
|
|
412
444
|
|
|
413
445
|
useEffect(() => {
|
|
@@ -456,6 +488,10 @@ export function createNuvlerDefaultRuntime(
|
|
|
456
488
|
|
|
457
489
|
const { Header, Footer, Home, ProductDetail, ProductGrid, NotFound } =
|
|
458
490
|
themeDefinition.components;
|
|
491
|
+
// O NotFound do tema aceita dados extras (sugestões, busca, atalhos).
|
|
492
|
+
const NotFoundView = NotFound as
|
|
493
|
+
| ComponentType<NuvlerNotFoundProps>
|
|
494
|
+
| undefined;
|
|
459
495
|
const site: ThemeSite = {
|
|
460
496
|
tenant: context.store,
|
|
461
497
|
modules: context.site.modules,
|
|
@@ -475,6 +511,7 @@ export function createNuvlerDefaultRuntime(
|
|
|
475
511
|
Math.max(0, Number(tokens.layout.borderRadius) || 0),
|
|
476
512
|
);
|
|
477
513
|
const style = {
|
|
514
|
+
...interactionColorVariables(tokens.colors),
|
|
478
515
|
"--color-primary": tokens.colors.primary,
|
|
479
516
|
"--color-primary-text": tokens.colors.primaryText,
|
|
480
517
|
"--color-secondary": tokens.colors.secondary,
|
|
@@ -505,24 +542,19 @@ export function createNuvlerDefaultRuntime(
|
|
|
505
542
|
const hasCompletePrices =
|
|
506
543
|
cartItems.length > 0 &&
|
|
507
544
|
cartItems.every(({ unitPrice }) => typeof unitPrice === "number");
|
|
508
|
-
const cartMessage = useMemo(
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
showPrices && hasCompletePrices
|
|
518
|
-
? `\n\nTotal estimado: ${money(cartTotal)}`
|
|
519
|
-
: "";
|
|
520
|
-
return `Olá! Gostaria de solicitar um orçamento para os itens abaixo:\n\n${lines.join("\n\n")}${summary}`;
|
|
521
|
-
}, [cartItems, cartTotal, hasCompletePrices, showPrices]);
|
|
545
|
+
const cartMessage = useMemo(
|
|
546
|
+
() =>
|
|
547
|
+
formatWhatsappRequest(
|
|
548
|
+
cartItems,
|
|
549
|
+
showPrices,
|
|
550
|
+
typeof window === "undefined" ? undefined : window.location.origin,
|
|
551
|
+
),
|
|
552
|
+
[cartItems, showPrices],
|
|
553
|
+
);
|
|
522
554
|
const whatsapp = site.settings?.contact.whatsapp?.replace(/\D/g, "");
|
|
523
555
|
const checkoutUrl =
|
|
524
556
|
whatsapp && cartItems.length
|
|
525
|
-
?
|
|
557
|
+
? whatsappRequestUrl(whatsapp, cartMessage)
|
|
526
558
|
: null;
|
|
527
559
|
const addToCart = (item: ThemeCartItem) => {
|
|
528
560
|
const key = themeCartKey(item);
|
|
@@ -610,7 +642,21 @@ export function createNuvlerDefaultRuntime(
|
|
|
610
642
|
</div>
|
|
611
643
|
</section>
|
|
612
644
|
<div className="store-container catalog-layout">
|
|
613
|
-
<
|
|
645
|
+
<CatalogFilters
|
|
646
|
+
key={JSON.stringify([
|
|
647
|
+
route.categoryPath,
|
|
648
|
+
route.search,
|
|
649
|
+
route.variants,
|
|
650
|
+
route.pagination.page,
|
|
651
|
+
])}
|
|
652
|
+
total={route.pagination.total}
|
|
653
|
+
activeCount={route.variants.length + (route.search ? 1 : 0)}
|
|
654
|
+
resetHref={
|
|
655
|
+
route.categoryPath.length
|
|
656
|
+
? `/${route.categoryPath.join("/")}`
|
|
657
|
+
: "/produtos"
|
|
658
|
+
}
|
|
659
|
+
>
|
|
614
660
|
<form
|
|
615
661
|
action={
|
|
616
662
|
route.categoryPath.length
|
|
@@ -619,6 +665,14 @@ export function createNuvlerDefaultRuntime(
|
|
|
619
665
|
}
|
|
620
666
|
className="catalog-filter-form"
|
|
621
667
|
>
|
|
668
|
+
{route.variants.map((token) => (
|
|
669
|
+
<input
|
|
670
|
+
key={token}
|
|
671
|
+
type="hidden"
|
|
672
|
+
name="variante"
|
|
673
|
+
value={token}
|
|
674
|
+
/>
|
|
675
|
+
))}
|
|
622
676
|
<label htmlFor="preview-catalog-search">
|
|
623
677
|
Buscar no catálogo
|
|
624
678
|
</label>
|
|
@@ -636,7 +690,14 @@ export function createNuvlerDefaultRuntime(
|
|
|
636
690
|
</div>
|
|
637
691
|
</form>
|
|
638
692
|
{route.facets.length > 0 && (
|
|
639
|
-
<form
|
|
693
|
+
<form
|
|
694
|
+
action={
|
|
695
|
+
route.categoryPath.length
|
|
696
|
+
? `/${route.categoryPath.join("/")}`
|
|
697
|
+
: "/produtos"
|
|
698
|
+
}
|
|
699
|
+
className="catalog-variant-filters"
|
|
700
|
+
>
|
|
640
701
|
{route.search && (
|
|
641
702
|
<input type="hidden" name="busca" value={route.search} />
|
|
642
703
|
)}
|
|
@@ -674,7 +735,7 @@ export function createNuvlerDefaultRuntime(
|
|
|
674
735
|
</button>
|
|
675
736
|
</form>
|
|
676
737
|
)}
|
|
677
|
-
</
|
|
738
|
+
</CatalogFilters>
|
|
678
739
|
<section className="catalog-results">
|
|
679
740
|
<ProductGrid
|
|
680
741
|
products={route.products}
|
|
@@ -692,6 +753,8 @@ export function createNuvlerDefaultRuntime(
|
|
|
692
753
|
className={
|
|
693
754
|
route.pagination.hasPreviousPage ? "" : "disabled"
|
|
694
755
|
}
|
|
756
|
+
aria-disabled={!route.pagination.hasPreviousPage}
|
|
757
|
+
tabIndex={route.pagination.hasPreviousPage ? undefined : -1}
|
|
695
758
|
href={catalogHref(
|
|
696
759
|
route,
|
|
697
760
|
Math.max(1, route.pagination.page - 1),
|
|
@@ -711,6 +774,8 @@ export function createNuvlerDefaultRuntime(
|
|
|
711
774
|
</div>
|
|
712
775
|
<a
|
|
713
776
|
className={route.pagination.hasNextPage ? "" : "disabled"}
|
|
777
|
+
aria-disabled={!route.pagination.hasNextPage}
|
|
778
|
+
tabIndex={route.pagination.hasNextPage ? undefined : -1}
|
|
714
779
|
href={catalogHref(
|
|
715
780
|
route,
|
|
716
781
|
Math.min(
|
|
@@ -830,8 +895,16 @@ export function createNuvlerDefaultRuntime(
|
|
|
830
895
|
</main>
|
|
831
896
|
);
|
|
832
897
|
else if (route.type === "not-found")
|
|
833
|
-
content =
|
|
834
|
-
<
|
|
898
|
+
content = NotFoundView ? (
|
|
899
|
+
<NotFoundView
|
|
900
|
+
homeHref="/"
|
|
901
|
+
resource={route.resource}
|
|
902
|
+
pathname={route.pathname}
|
|
903
|
+
suggestions={context.catalog.products}
|
|
904
|
+
searchProducts={adapters?.searchProducts}
|
|
905
|
+
shortcuts={notFoundShortcuts(context)}
|
|
906
|
+
showPrices={showPrices}
|
|
907
|
+
/>
|
|
835
908
|
) : (
|
|
836
909
|
<main className="not-found-page">
|
|
837
910
|
<div className="not-found-card">
|
|
@@ -1060,7 +1133,7 @@ export function createNuvlerDefaultRuntime(
|
|
|
1060
1133
|
target="_blank"
|
|
1061
1134
|
rel="noreferrer"
|
|
1062
1135
|
>
|
|
1063
|
-
|
|
1136
|
+
{whatsappRequestLabel}
|
|
1064
1137
|
</a>
|
|
1065
1138
|
) : (
|
|
1066
1139
|
<p className="cart-warning">
|