@nuvler/cli 0.1.0
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 +25 -0
- package/dist/api/client.js +84 -0
- package/dist/api/client.js.map +1 -0
- package/dist/api/theme-context.js +190 -0
- package/dist/api/theme-context.js.map +1 -0
- package/dist/api/theme-registry.js +77 -0
- package/dist/api/theme-registry.js.map +1 -0
- package/dist/commands/theme/build.js +116 -0
- package/dist/commands/theme/build.js.map +1 -0
- package/dist/commands/theme/create.js +92 -0
- package/dist/commands/theme/create.js.map +1 -0
- package/dist/commands/theme/dev.js +46 -0
- package/dist/commands/theme/dev.js.map +1 -0
- package/dist/commands/theme/pack.js +75 -0
- package/dist/commands/theme/pack.js.map +1 -0
- package/dist/commands/theme/publish.js +37 -0
- package/dist/commands/theme/publish.js.map +1 -0
- package/dist/commands/theme/validate.js +15 -0
- package/dist/commands/theme/validate.js.map +1 -0
- package/dist/index.js +144 -0
- package/dist/index.js.map +1 -0
- package/dist/nuvler.js +7553 -0
- package/dist/nuvler.js.map +1 -0
- package/dist/preview/launcher.js +104 -0
- package/dist/preview/launcher.js.map +1 -0
- package/dist/theme/artifact-policy.js +119 -0
- package/dist/theme/artifact-policy.js.map +1 -0
- package/dist/theme/artifact.js +39 -0
- package/dist/theme/artifact.js.map +1 -0
- package/dist/theme/project.js +71 -0
- package/dist/theme/project.js.map +1 -0
- package/package.json +44 -0
- package/preview-host/index.html +13 -0
- package/preview-host/package.json +23 -0
- package/preview-host/src/app/globals.css +16 -0
- package/preview-host/src/fallback-context.json +53 -0
- package/preview-host/src/main.tsx +145 -0
- package/preview-host/src/virtual-modules.d.ts +11 -0
- package/preview-host/tsconfig.json +28 -0
- package/preview-host/vendor/theme-runtime/default-theme.tsx +577 -0
- package/preview-host/vendor/theme-runtime/index.ts +25 -0
- package/preview-host/vite.config.ts +125 -0
- package/templates/starter-theme/.env.example +3 -0
- package/templates/starter-theme/README.md +100 -0
- package/templates/starter-theme/gitignore.template +9 -0
- package/templates/starter-theme/nuvler.theme.json +10 -0
- package/templates/starter-theme/package.json +29 -0
- package/templates/starter-theme/src/definition.tsx +54 -0
- package/templates/starter-theme/src/styles.d.ts +1 -0
- package/templates/starter-theme/src/theme.css +21 -0
- package/templates/starter-theme/src/theme.tsx +34 -0
- package/templates/starter-theme/tsconfig.json +17 -0
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { readFile } from "node:fs/promises";
|
|
2
|
+
import { existsSync } from "node:fs";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { fileURLToPath } from "node:url";
|
|
5
|
+
import react from "@vitejs/plugin-react";
|
|
6
|
+
import { defineConfig, normalizePath, type Plugin } from "vite";
|
|
7
|
+
|
|
8
|
+
const activeThemeId = "\0virtual:nuvler-active-theme";
|
|
9
|
+
const themeContextId = "\0virtual:nuvler-theme-context";
|
|
10
|
+
|
|
11
|
+
function envPath(name: string, fallback: string): string {
|
|
12
|
+
const value = process.env[name]?.trim();
|
|
13
|
+
return path.resolve(value || fallback);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function readStylePaths(): string[] {
|
|
17
|
+
const raw = process.env.NUVLER_THEME_STYLES?.trim();
|
|
18
|
+
if (!raw) return [];
|
|
19
|
+
|
|
20
|
+
const value: unknown = JSON.parse(raw);
|
|
21
|
+
if (!Array.isArray(value) || value.some((item) => typeof item !== "string")) {
|
|
22
|
+
throw new Error("NUVLER_THEME_STYLES deve ser um array JSON de caminhos.");
|
|
23
|
+
}
|
|
24
|
+
return value.map((item) => path.resolve(item as string));
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function activeThemePlugin(
|
|
28
|
+
entryPath: string,
|
|
29
|
+
stylePaths: string[],
|
|
30
|
+
apiUrl: string | undefined,
|
|
31
|
+
store: string | undefined,
|
|
32
|
+
): Plugin {
|
|
33
|
+
return {
|
|
34
|
+
name: "nuvler-active-theme",
|
|
35
|
+
resolveId(id) {
|
|
36
|
+
if (id === "virtual:nuvler-active-theme") return activeThemeId;
|
|
37
|
+
if (id === "virtual:nuvler-theme-context") return themeContextId;
|
|
38
|
+
},
|
|
39
|
+
async load(id) {
|
|
40
|
+
if (id === activeThemeId) {
|
|
41
|
+
const imports = stylePaths
|
|
42
|
+
.map((stylePath) => `import ${JSON.stringify(normalizePath(stylePath))};`)
|
|
43
|
+
.join("\n");
|
|
44
|
+
return `${imports}\nexport { default } from ${JSON.stringify(normalizePath(entryPath))};`;
|
|
45
|
+
}
|
|
46
|
+
if (id === themeContextId) {
|
|
47
|
+
const raw = await readFile(contextFile, "utf8");
|
|
48
|
+
const context = JSON.parse(raw) as unknown;
|
|
49
|
+
return `export default ${JSON.stringify(context).replaceAll("<", "\\u003c")};`;
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
configureServer(server) {
|
|
53
|
+
server.middlewares.use("/__nuvler-api", async (request, response) => {
|
|
54
|
+
if (!apiUrl || !store || request.method !== "GET" || !request.url) {
|
|
55
|
+
response.statusCode = 404;
|
|
56
|
+
response.end("Preview API indisponível");
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
const relative = request.url.replace(/^\/+/, "");
|
|
60
|
+
if (!/^(products|product-categories|blog|services|cases|pages)(?:[/?]|$)/.test(relative)) {
|
|
61
|
+
response.statusCode = 403;
|
|
62
|
+
response.end("Endpoint não permitido");
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
try {
|
|
66
|
+
const upstream = await fetch(`${apiUrl.replace(/\/+$/, "")}/public/${encodeURIComponent(store)}/${relative}`, {
|
|
67
|
+
headers: { accept: "application/json" },
|
|
68
|
+
signal: AbortSignal.timeout(15_000),
|
|
69
|
+
});
|
|
70
|
+
response.statusCode = upstream.status;
|
|
71
|
+
response.setHeader("content-type", upstream.headers.get("content-type") || "application/json");
|
|
72
|
+
response.end(Buffer.from(await upstream.arrayBuffer()));
|
|
73
|
+
} catch (error) {
|
|
74
|
+
response.statusCode = 502;
|
|
75
|
+
response.setHeader("content-type", "application/json");
|
|
76
|
+
response.end(JSON.stringify({ error: error instanceof Error ? error.message : "Falha no proxy" }));
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
},
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
const previewHostDirectory = path.dirname(fileURLToPath(import.meta.url));
|
|
84
|
+
const toolingRoot = path.resolve(previewHostDirectory, "../..");
|
|
85
|
+
const isMonorepoPreview = existsSync(path.join(toolingRoot, "packages", "theme-runtime", "src", "index.ts"));
|
|
86
|
+
const runtimeEntry = isMonorepoPreview
|
|
87
|
+
? path.join(toolingRoot, "packages", "theme-runtime", "src", "index.ts")
|
|
88
|
+
: path.join(previewHostDirectory, "vendor", "theme-runtime", "index.ts");
|
|
89
|
+
const fallbackThemeDirectory = isMonorepoPreview
|
|
90
|
+
? path.join(toolingRoot, "themes", "nuvler-default")
|
|
91
|
+
: previewHostDirectory;
|
|
92
|
+
const themeDirectory = envPath("NUVLER_THEME_DIRECTORY", fallbackThemeDirectory);
|
|
93
|
+
const themeEntry = envPath(
|
|
94
|
+
"NUVLER_THEME_ENTRY",
|
|
95
|
+
path.join(fallbackThemeDirectory, "src", "theme.tsx"),
|
|
96
|
+
);
|
|
97
|
+
const contextFile = envPath(
|
|
98
|
+
"NUVLER_THEME_CONTEXT_FILE",
|
|
99
|
+
path.join(previewHostDirectory, "src", "fallback-context.json"),
|
|
100
|
+
);
|
|
101
|
+
const stylePaths = process.env.NUVLER_THEME_STYLES
|
|
102
|
+
? readStylePaths()
|
|
103
|
+
: [path.join(fallbackThemeDirectory, "src", "theme.css")];
|
|
104
|
+
|
|
105
|
+
export default defineConfig({
|
|
106
|
+
plugins: [activeThemePlugin(
|
|
107
|
+
themeEntry,
|
|
108
|
+
stylePaths,
|
|
109
|
+
process.env.NUVLER_API_URL?.trim(),
|
|
110
|
+
process.env.NUVLER_STORE_SLUG?.trim(),
|
|
111
|
+
), react()],
|
|
112
|
+
resolve: {
|
|
113
|
+
alias: {
|
|
114
|
+
"@nuvler/theme-runtime": runtimeEntry,
|
|
115
|
+
...(isMonorepoPreview ? {
|
|
116
|
+
"@nuvler/theme-sdk": path.join(toolingRoot, "packages", "theme-sdk", "src", "index.ts"),
|
|
117
|
+
"@nuvler/theme-schema": path.join(toolingRoot, "packages", "theme-schema", "src", "index.ts"),
|
|
118
|
+
} : {}),
|
|
119
|
+
},
|
|
120
|
+
dedupe: ["react", "react-dom"],
|
|
121
|
+
},
|
|
122
|
+
server: {
|
|
123
|
+
fs: { allow: [previewHostDirectory, themeDirectory, ...(isMonorepoPreview ? [toolingRoot] : [])] },
|
|
124
|
+
},
|
|
125
|
+
});
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
# __NUVLER_THEME_NAME__
|
|
2
|
+
|
|
3
|
+
Tema Nuvler com id `__NUVLER_THEME_ID__`.
|
|
4
|
+
|
|
5
|
+
O projeto depende somente do SDK e da CLI públicos. Temas não são publicados
|
|
6
|
+
no npm: `npm run pack` gera um artefato para o Theme Registry da Nuvler.
|
|
7
|
+
|
|
8
|
+
## Onde personalizar
|
|
9
|
+
|
|
10
|
+
```text
|
|
11
|
+
src/definition.tsx componentes Header, Footer, Home, ProductGrid e ProductDetail
|
|
12
|
+
src/theme.css cores, fontes, grid, responsividade e animações
|
|
13
|
+
src/theme.tsx composição da Home, catálogo, produto e páginas editoriais
|
|
14
|
+
nuvler.theme.json id, nome, versão e compatibilidade
|
|
15
|
+
assets/ imagens e fontes próprias, quando necessárias
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
Você pode separar o código em `src/components`, `src/pages`, `src/sections` e
|
|
19
|
+
`src/styles`. Importe esses arquivos por `definition.tsx` ou `theme.tsx`.
|
|
20
|
+
|
|
21
|
+
Não edite `dist` nem `artifacts`: essas pastas são geradas pela CLI.
|
|
22
|
+
|
|
23
|
+
## Objetos recebidos
|
|
24
|
+
|
|
25
|
+
O componente raiz recebe `NuvlerThemeProps`:
|
|
26
|
+
|
|
27
|
+
- `context`: loja, configurações, navegação, Home, produtos e conteúdo editorial;
|
|
28
|
+
- `route`: página atual (`home`, `catalog`, `product`, editorial ou página);
|
|
29
|
+
- `adapters`: componentes públicos de Link e Image e busca de produtos;
|
|
30
|
+
- `sdk`: carrinho, navegação, analytics, cliente e busca do catálogo;
|
|
31
|
+
- `settings`: tokens configurados para o tema.
|
|
32
|
+
|
|
33
|
+
Os componentes registrados por `defineTheme()` recebem props tipadas:
|
|
34
|
+
|
|
35
|
+
- `HeaderProps`;
|
|
36
|
+
- `FooterProps`;
|
|
37
|
+
- `HomeProps`;
|
|
38
|
+
- `ProductGridProps`;
|
|
39
|
+
- `ProductDetailProps`.
|
|
40
|
+
|
|
41
|
+
Tipos de dados mais usados:
|
|
42
|
+
|
|
43
|
+
```ts
|
|
44
|
+
ThemeContext
|
|
45
|
+
ThemeSite
|
|
46
|
+
ThemeProduct
|
|
47
|
+
ThemeCategory
|
|
48
|
+
ThemeImage
|
|
49
|
+
ThemeHomeSection
|
|
50
|
+
ThemeEditorialItem
|
|
51
|
+
ThemePagination
|
|
52
|
+
ThemeCartItem
|
|
53
|
+
ThemeRoute
|
|
54
|
+
ThemeRuntimeSdk
|
|
55
|
+
ThemeRuntimeAdapters
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
Capacidades públicas do runtime:
|
|
59
|
+
|
|
60
|
+
```ts
|
|
61
|
+
sdk.cart.add(item)
|
|
62
|
+
sdk.cart.remove(itemKey)
|
|
63
|
+
sdk.navigation.navigate(href)
|
|
64
|
+
sdk.analytics.track(event, properties)
|
|
65
|
+
sdk.customer.getCurrent()
|
|
66
|
+
sdk.catalog.searchProducts(query)
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
Use `adapters.Link` e `adapters.Image` em vez de importar componentes internos
|
|
70
|
+
do Store. O tema não deve importar caminhos como `@/lib/api`, `@/store/cart`,
|
|
71
|
+
`next/link` ou `next/image`.
|
|
72
|
+
|
|
73
|
+
O contrato completo está no
|
|
74
|
+
[guia de desenvolvimento de temas](https://github.com/ricardomesmo/nuvler/blob/main/docs/theme-development.md).
|
|
75
|
+
|
|
76
|
+
## Executar e publicar
|
|
77
|
+
|
|
78
|
+
```bash
|
|
79
|
+
npm install
|
|
80
|
+
cp .env.example .env
|
|
81
|
+
npm run validate
|
|
82
|
+
npm run dev
|
|
83
|
+
npm run build
|
|
84
|
+
npm run pack
|
|
85
|
+
npm run publish
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
Defina `NUVLER_STORE_SLUG`, `NUVLER_API_URL` e `NUVLER_TOKEN` no `.env`. Também
|
|
89
|
+
é possível sobrescrever esses valores com `--store`, `--api-url` e `--token`.
|
|
90
|
+
|
|
91
|
+
- `src/definition.tsx`: definição tipada do tema.
|
|
92
|
+
- `src/theme.tsx`: entrada usada pelo preview local.
|
|
93
|
+
- `src/theme.css`: CSS oficial seguido pelas personalizações deste tema.
|
|
94
|
+
- `nuvler.theme.json`: identidade, versão do runtime e compatibilidade do SDK.
|
|
95
|
+
|
|
96
|
+
O código-fonte deste projeto deve ser versionado em um repositório Git do tema.
|
|
97
|
+
Somente `manifest.json`, `theme.js`, `theme.css` e `assets/` entram no Registry.
|
|
98
|
+
|
|
99
|
+
O arquivo final será `artifacts/__NUVLER_THEME_ID__-0.1.0.nuvler-theme.tgz`.
|
|
100
|
+
`npm run publish` envia esse mesmo arquivo ao Theme Registry.
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "nuvler-theme-__NUVLER_THEME_ID__",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"private": true,
|
|
5
|
+
"type": "module",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"dev": "nuvler theme dev --theme .",
|
|
8
|
+
"validate": "nuvler theme validate --theme .",
|
|
9
|
+
"build": "nuvler theme build --theme .",
|
|
10
|
+
"pack": "nuvler theme pack --theme .",
|
|
11
|
+
"publish": "nuvler theme publish --theme .",
|
|
12
|
+
"typecheck": "tsc -p tsconfig.json --noEmit"
|
|
13
|
+
},
|
|
14
|
+
"dependencies": {
|
|
15
|
+
"@nuvler/theme-sdk": "^1.0.0"
|
|
16
|
+
},
|
|
17
|
+
"peerDependencies": {
|
|
18
|
+
"react": "^19.0.0"
|
|
19
|
+
},
|
|
20
|
+
"devDependencies": {
|
|
21
|
+
"@nuvler/cli": "^0.1.0",
|
|
22
|
+
"@types/react": "^19.0.0",
|
|
23
|
+
"react": "^19.0.0",
|
|
24
|
+
"typescript": "^5.9.0"
|
|
25
|
+
},
|
|
26
|
+
"engines": {
|
|
27
|
+
"node": "^20.19.0 || >=22.12.0"
|
|
28
|
+
}
|
|
29
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import manifestData from "../nuvler.theme.json" with { type: "json" };
|
|
2
|
+
import {
|
|
3
|
+
defineTheme,
|
|
4
|
+
type FooterProps,
|
|
5
|
+
type HeaderProps,
|
|
6
|
+
type HomeProps,
|
|
7
|
+
type ProductDetailProps,
|
|
8
|
+
type ProductGridProps,
|
|
9
|
+
type ThemeManifest,
|
|
10
|
+
} from "@nuvler/theme-sdk";
|
|
11
|
+
|
|
12
|
+
function Header({ site }: HeaderProps) {
|
|
13
|
+
const name = site.settings?.siteName || site.tenant.name;
|
|
14
|
+
return <header className="theme-header"><a href="/" className="theme-brand">{name}</a><form action="/produtos"><input name="busca" placeholder="Buscar produtos" /><button>Buscar</button></form></header>;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function Footer({ site }: FooterProps) {
|
|
18
|
+
const name = site.settings?.siteName || site.tenant.name;
|
|
19
|
+
return <footer className="theme-footer"><strong>{name}</strong><span>Tema __NUVLER_THEME_NAME__</span></footer>;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function ProductGrid({ products }: ProductGridProps) {
|
|
23
|
+
return <div className="theme-products">{products.map((product) => <article key={product.slug}><a href={`/produto/${product.slug}`}><strong>{product.title}</strong><span>{product.sku || "Ver produto"}</span></a></article>)}</div>;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function Home({ products, site }: HomeProps) {
|
|
27
|
+
const name = site.settings?.siteName || site.tenant.name;
|
|
28
|
+
return <main><section className="theme-hero"><span>__NUVLER_THEME_NAME__</span><h1>{name}</h1><p>{site.settings?.description || "Uma nova experiência de compra."}</p><a href="/produtos">Explorar produtos</a></section><section className="theme-section"><h2>Produtos em destaque</h2><ProductGrid products={products} /></section></main>;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function ProductDetail({ product, descriptionContent, onAddToCart }: ProductDetailProps) {
|
|
32
|
+
return <article className="theme-product-detail"><div><span>{product.categories[0]?.name || "Produto"}</span><h1>{product.title}</h1>{descriptionContent}</div><button type="button" onClick={() => onAddToCart?.({ productSlug: product.slug, title: product.title, sku: product.sku, image: product.image, unitPrice: product.promotionalPrice ?? product.price })}>Adicionar ao orçamento</button></article>;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export const manifest = manifestData as ThemeManifest;
|
|
36
|
+
|
|
37
|
+
export const themeDefinition = defineTheme({
|
|
38
|
+
manifest,
|
|
39
|
+
tokens: {
|
|
40
|
+
colors: { primary: "#1d4ed8", secondary: "#f59e0b", background: "#f8fafc", text: "#0f172a" },
|
|
41
|
+
layout: { containerWidth: 1200, borderRadius: 16 },
|
|
42
|
+
},
|
|
43
|
+
template: {
|
|
44
|
+
announcement: "Bem-vindo",
|
|
45
|
+
footerTagline: "Criado com a Nuvler",
|
|
46
|
+
footerNavigationLabel: "Navegação",
|
|
47
|
+
footerNote: "__NUVLER_THEME_NAME__",
|
|
48
|
+
socialLabel: "Redes sociais",
|
|
49
|
+
benefits: [],
|
|
50
|
+
fallbackSections: () => [],
|
|
51
|
+
primaryAction: () => ({ label: "Ver produtos", href: "/produtos" }),
|
|
52
|
+
},
|
|
53
|
+
components: { Header, Footer, Home, ProductGrid, ProductDetail },
|
|
54
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
declare module "*.css";
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
* { box-sizing: border-box; }
|
|
2
|
+
body { margin: 0; }
|
|
3
|
+
.nuvler-starter-theme { min-height: 100vh; background: var(--theme-background); color: var(--theme-text); font-family: Inter, system-ui, sans-serif; }
|
|
4
|
+
.theme-header, .theme-footer, .theme-section, .theme-hero { width: min(calc(100% - 32px), var(--theme-container)); margin-inline: auto; }
|
|
5
|
+
.theme-header { min-height: 72px; display: flex; align-items: center; justify-content: space-between; gap: 24px; }
|
|
6
|
+
.theme-brand { color: var(--theme-primary); font-size: 20px; font-weight: 800; text-decoration: none; }
|
|
7
|
+
.theme-header form { display: flex; gap: 8px; }
|
|
8
|
+
.theme-header input { min-width: 260px; border: 1px solid #cbd5e1; border-radius: var(--theme-radius); padding: 11px 14px; }
|
|
9
|
+
.theme-header button, .theme-product-detail button { border: 0; border-radius: var(--theme-radius); background: var(--theme-primary); color: white; padding: 12px 18px; font-weight: 700; }
|
|
10
|
+
.theme-hero { margin-block: 32px; border-radius: calc(var(--theme-radius) * 1.5); background: var(--theme-primary); color: white; padding: clamp(40px, 8vw, 96px); }
|
|
11
|
+
.theme-hero span { color: var(--theme-secondary); font-size: 12px; font-weight: 800; text-transform: uppercase; }
|
|
12
|
+
.theme-hero h1 { max-width: 760px; margin: 12px 0; font-size: clamp(40px, 7vw, 80px); line-height: .95; }
|
|
13
|
+
.theme-hero a { display: inline-block; margin-top: 16px; border-radius: var(--theme-radius); background: var(--theme-secondary); color: var(--theme-text); padding: 13px 18px; font-weight: 800; text-decoration: none; }
|
|
14
|
+
.theme-section { padding-block: 48px; }
|
|
15
|
+
.theme-products { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 16px; }
|
|
16
|
+
.theme-products article { min-height: 180px; border: 1px solid #e2e8f0; border-radius: var(--theme-radius); background: white; padding: 20px; }
|
|
17
|
+
.theme-products a { display: flex; height: 100%; flex-direction: column; justify-content: flex-end; color: inherit; text-decoration: none; }
|
|
18
|
+
.theme-products span { margin-top: 8px; color: #64748b; font-size: 13px; }
|
|
19
|
+
.theme-product-detail { display: grid; gap: 32px; grid-template-columns: 1fr auto; align-items: end; border-radius: var(--theme-radius); background: white; padding: clamp(24px, 5vw, 56px); }
|
|
20
|
+
.theme-footer { display: flex; justify-content: space-between; border-top: 1px solid #e2e8f0; padding-block: 32px; }
|
|
21
|
+
@media (max-width: 700px) { .theme-header { align-items: stretch; flex-direction: column; padding-block: 16px; } .theme-header form, .theme-header input { width: 100%; min-width: 0; } .theme-product-detail { grid-template-columns: 1fr; } }
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { CSSProperties } from "react";
|
|
2
|
+
import type { NuvlerThemeProps, ThemeSite } from "@nuvler/theme-sdk";
|
|
3
|
+
import { themeDefinition } from "./definition.js";
|
|
4
|
+
import "./theme.css";
|
|
5
|
+
|
|
6
|
+
export { manifest, themeDefinition } from "./definition.js";
|
|
7
|
+
|
|
8
|
+
export default function Theme({ context, route = { type: "home" }, sdk }: NuvlerThemeProps) {
|
|
9
|
+
const { Header, Footer, Home, ProductGrid, ProductDetail } = themeDefinition.components;
|
|
10
|
+
const site: ThemeSite = { tenant: context.store, ...context.site };
|
|
11
|
+
const configured = site.settings?.theme;
|
|
12
|
+
const tokens = {
|
|
13
|
+
colors: { ...themeDefinition.tokens.colors, ...configured?.colors },
|
|
14
|
+
layout: { ...themeDefinition.tokens.layout, ...configured?.layout },
|
|
15
|
+
};
|
|
16
|
+
const style = {
|
|
17
|
+
"--theme-primary": tokens.colors.primary,
|
|
18
|
+
"--theme-secondary": tokens.colors.secondary,
|
|
19
|
+
"--theme-background": tokens.colors.background,
|
|
20
|
+
"--theme-text": tokens.colors.text,
|
|
21
|
+
"--theme-radius": `${tokens.layout.borderRadius}px`,
|
|
22
|
+
"--theme-container": `${tokens.layout.containerWidth}px`,
|
|
23
|
+
} as CSSProperties;
|
|
24
|
+
|
|
25
|
+
let content;
|
|
26
|
+
if (route.type === "home") content = <Home sections={context.home.content.sections} products={context.catalog.products} posts={context.editorial.posts} services={context.editorial.services} cases={context.editorial.cases} site={site} template={themeDefinition.template} />;
|
|
27
|
+
else if (route.type === "catalog") content = <main className="theme-section"><h1>{route.search ? `Busca: ${route.search}` : "Produtos"}</h1><ProductGrid products={route.products} /></main>;
|
|
28
|
+
else if (route.type === "product") content = <main className="theme-section"><ProductDetail product={route.product} contact={site.settings?.contact} productUrl={null} descriptionContent={<p>{route.product.description}</p>} onAddToCart={sdk?.cart.add} /></main>;
|
|
29
|
+
else if (route.type === "editorial-list") content = <main className="theme-section"><h1>{route.title}</h1>{route.items.map((item) => <article key={item.slug}><h2>{item.title}</h2><p>{item.description}</p></article>)}</main>;
|
|
30
|
+
else if (route.type === "editorial-detail") content = <main className="theme-section"><h1>{route.item.title}</h1><p>{route.item.description}</p></main>;
|
|
31
|
+
else content = <main className="theme-section"><h1>{route.type === "loading" ? "Carregando…" : route.type === "page" ? route.title : "Conteúdo não encontrado"}</h1></main>;
|
|
32
|
+
|
|
33
|
+
return <div className="nuvler-starter-theme" style={style}><Header site={site} categories={context.navigation.categories} pages={context.navigation.pages} template={themeDefinition.template} /><div>{content}</div><Footer site={site} pages={context.navigation.pages} template={themeDefinition.template} /></div>;
|
|
34
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2022",
|
|
4
|
+
"module": "NodeNext",
|
|
5
|
+
"moduleResolution": "NodeNext",
|
|
6
|
+
"strict": true,
|
|
7
|
+
"esModuleInterop": true,
|
|
8
|
+
"skipLibCheck": true,
|
|
9
|
+
"declaration": true,
|
|
10
|
+
"sourceMap": true,
|
|
11
|
+
"jsx": "react-jsx",
|
|
12
|
+
"resolveJsonModule": true,
|
|
13
|
+
"rootDir": ".",
|
|
14
|
+
"outDir": "dist"
|
|
15
|
+
},
|
|
16
|
+
"include": ["src/**/*", "nuvler.theme.json"]
|
|
17
|
+
}
|