@nuvler/cli 0.4.4 → 0.5.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 +10 -5
- package/dist/commands/theme/create.js +2 -2
- package/dist/commands/theme/dev.js +3 -1
- package/dist/commands/theme/dev.js.map +1 -1
- package/dist/commands/theme/migrate.js +7 -0
- package/dist/commands/theme/migrate.js.map +1 -1
- package/dist/index.js +1 -1
- package/dist/migrate/analysis/dependency-classifier.js +41 -0
- package/dist/migrate/analysis/dependency-classifier.js.map +1 -0
- package/dist/migrate/analysis/dependency-graph.js +210 -0
- package/dist/migrate/analysis/dependency-graph.js.map +1 -0
- package/dist/migrate/analyzer.js +18 -8
- package/dist/migrate/analyzer.js.map +1 -1
- package/dist/migrate/asset-copier.js +2 -2
- package/dist/migrate/asset-copier.js.map +1 -1
- package/dist/migrate/classifier.js +4 -0
- package/dist/migrate/classifier.js.map +1 -1
- package/dist/migrate/generation/fidelity-pass.js +223 -0
- package/dist/migrate/generation/fidelity-pass.js.map +1 -0
- package/dist/migrate/generator.js +1413 -57
- package/dist/migrate/generator.js.map +1 -1
- package/dist/migrate/resolvers/import-resolver.js +91 -0
- package/dist/migrate/resolvers/import-resolver.js.map +1 -0
- package/dist/migrate/transform/source-transformer.js +373 -0
- package/dist/migrate/transform/source-transformer.js.map +1 -0
- package/dist/migrate/transformer.js +297 -11
- package/dist/migrate/transformer.js.map +1 -1
- package/dist/nuvler.js +3427 -303
- package/dist/nuvler.js.map +1 -1
- package/dist/preview/prepare.js +84 -1
- package/dist/preview/prepare.js.map +1 -1
- package/dist/templates/nuvler-atelier/nuvler.theme.json +1 -1
- package/dist/templates/nuvler-atelier/package.json +2 -2
- package/dist/templates/nuvler-default/nuvler.theme.json +1 -1
- package/dist/templates/nuvler-default/package.json +1 -1
- package/dist/templates/nuvler-default/src/home.tsx +79 -2
- package/dist/templates/nuvler-default/src/theme-component.tsx +4 -3
- package/dist/templates/nuvler-default/src/theme.css +149 -0
- package/dist/templates/starter/nuvler.theme.json +1 -1
- package/dist/templates/starter/package.json +2 -2
- package/package.json +4 -4
- package/preview-host/package.json +1 -1
- package/preview-host/src/app/globals.css +5 -15
- package/preview-host/src/main.tsx +55 -5
- package/preview-host/vendor/theme-runtime/default-theme.tsx +131 -3
- package/preview-host/vite.config.ts +4 -0
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { StrictMode, useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|
2
2
|
import { createRoot } from "react-dom/client";
|
|
3
|
+
import { createPortal } from "react-dom";
|
|
3
4
|
import "./app/globals.css";
|
|
4
5
|
import type {
|
|
5
6
|
ThemeImageProps,
|
|
@@ -7,7 +8,7 @@ import type {
|
|
|
7
8
|
ThemeRoute,
|
|
8
9
|
ThemeRuntimeAdapters,
|
|
9
10
|
} from "@nuvler/theme-runtime";
|
|
10
|
-
import type { ThemePagination, ThemeProduct } from "@nuvler/theme-sdk";
|
|
11
|
+
import type { ThemePagination, ThemeProduct, ThemeRuntimeSdk } from "@nuvler/theme-sdk";
|
|
11
12
|
import ActiveTheme from "virtual:nuvler-active-theme";
|
|
12
13
|
import context from "virtual:nuvler-theme-context";
|
|
13
14
|
|
|
@@ -38,6 +39,31 @@ function normalizeProduct(value: unknown): ThemeProduct {
|
|
|
38
39
|
};
|
|
39
40
|
}
|
|
40
41
|
|
|
42
|
+
function PlatformBrand({ routeKey }: { routeKey: string }) {
|
|
43
|
+
const [target, setTarget] = useState<HTMLElement | null>(null);
|
|
44
|
+
|
|
45
|
+
useEffect(() => {
|
|
46
|
+
const explicit = document.querySelector<HTMLElement>("[data-nuvler-platform-brand-slot]");
|
|
47
|
+
if (explicit) {
|
|
48
|
+
setTarget(explicit);
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
const footers = [...document.querySelectorAll<HTMLElement>("footer")];
|
|
52
|
+
const footer = footers.at(-1) ?? null;
|
|
53
|
+
const inferred = footer?.querySelector<HTMLElement>(
|
|
54
|
+
'[class*="footer-bottom"], [class*="footer-note"]',
|
|
55
|
+
) ?? footer?.lastElementChild as HTMLElement | null ?? footer;
|
|
56
|
+
setTarget(inferred);
|
|
57
|
+
}, [routeKey]);
|
|
58
|
+
|
|
59
|
+
return target ? createPortal(
|
|
60
|
+
<span className="nuvler-platform-brand" aria-label="Nuvler">
|
|
61
|
+
<img src="/nuvler-logo-white.png" alt="Nuvler" width="1532" height="289" />
|
|
62
|
+
</span>,
|
|
63
|
+
target,
|
|
64
|
+
) : null;
|
|
65
|
+
}
|
|
66
|
+
|
|
41
67
|
async function previewApi<T>(path: string): Promise<T> {
|
|
42
68
|
const response = await fetch(`/__nuvler-api/${path.replace(/^\/+/, "")}`, {
|
|
43
69
|
headers: { accept: "application/json" },
|
|
@@ -142,11 +168,35 @@ function PreviewApp() {
|
|
|
142
168
|
};
|
|
143
169
|
}, [loadRoute]);
|
|
144
170
|
|
|
171
|
+
const sdk = useMemo<ThemeRuntimeSdk>(() => ({
|
|
172
|
+
cart: { add: () => undefined, remove: () => undefined },
|
|
173
|
+
navigation: {
|
|
174
|
+
navigate: (href) => {
|
|
175
|
+
const next = new URL(href, window.location.origin);
|
|
176
|
+
window.history.pushState({}, "", next);
|
|
177
|
+
void loadRoute(next);
|
|
178
|
+
},
|
|
179
|
+
},
|
|
180
|
+
analytics: { track: () => undefined },
|
|
181
|
+
customer: { getCurrent: async () => null },
|
|
182
|
+
catalog: {
|
|
183
|
+
searchProducts: async (query) => {
|
|
184
|
+
const results = await previewApi<unknown[]>(`products/suggestions?search=${encodeURIComponent(query)}`);
|
|
185
|
+
return results.map(normalizeProduct).slice(0, 5);
|
|
186
|
+
},
|
|
187
|
+
},
|
|
188
|
+
contact: {
|
|
189
|
+
submit: async () => ({
|
|
190
|
+
id: `preview-${crypto.randomUUID()}`,
|
|
191
|
+
status: "received",
|
|
192
|
+
receivedAt: new Date().toISOString(),
|
|
193
|
+
}),
|
|
194
|
+
},
|
|
195
|
+
}), [loadRoute]);
|
|
196
|
+
|
|
145
197
|
return <>
|
|
146
|
-
<ActiveTheme adapters={adapters} context={context} route={route} />
|
|
147
|
-
<
|
|
148
|
-
<img src="/nuvler-logo-white.png" alt="Nuvler" width="1532" height="289" />
|
|
149
|
-
</footer>
|
|
198
|
+
<ActiveTheme adapters={adapters} context={context} route={route} sdk={sdk} />
|
|
199
|
+
<PlatformBrand routeKey={`${route.type}:${window.location.pathname}`} />
|
|
150
200
|
</>;
|
|
151
201
|
}
|
|
152
202
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { useEffect, useMemo, useRef, useState, type CSSProperties, type ReactNode } from "react";
|
|
1
|
+
import { useEffect, useMemo, useRef, useState, type CSSProperties, type FormEvent, type ReactNode } from "react";
|
|
2
2
|
import type {
|
|
3
3
|
ThemeCategory,
|
|
4
4
|
ThemeContext,
|
|
@@ -6,6 +6,7 @@ import type {
|
|
|
6
6
|
ThemeHomeSectionType,
|
|
7
7
|
ThemeEditorialItem,
|
|
8
8
|
ThemeProduct,
|
|
9
|
+
ThemeRuntimeSdk,
|
|
9
10
|
ThemeSiteColors,
|
|
10
11
|
} from "@nuvler/theme-sdk";
|
|
11
12
|
import { htmlToPlainText, productUrl } from "@nuvler/theme-sdk";
|
|
@@ -290,6 +291,7 @@ export interface ThemeSectionRendererProps {
|
|
|
290
291
|
section: ThemeHomeSection;
|
|
291
292
|
context: ThemeContext;
|
|
292
293
|
adapters: ThemeRuntimeAdapters;
|
|
294
|
+
sdk?: ThemeRuntimeSdk;
|
|
293
295
|
}
|
|
294
296
|
|
|
295
297
|
export type ThemeSectionRenderer = (props: ThemeSectionRendererProps) => ReactNode;
|
|
@@ -369,6 +371,131 @@ function TextSection({ section, adapters }: ThemeSectionRendererProps) {
|
|
|
369
371
|
</div></section>;
|
|
370
372
|
}
|
|
371
373
|
|
|
374
|
+
function dataRecord(data: Record<string, unknown>, field: string): Record<string, unknown> {
|
|
375
|
+
const value = data[field];
|
|
376
|
+
return value && typeof value === "object" && !Array.isArray(value)
|
|
377
|
+
? value as Record<string, unknown>
|
|
378
|
+
: {};
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
function dataRecords(data: Record<string, unknown>, field: string): Record<string, unknown>[] {
|
|
382
|
+
const value = data[field];
|
|
383
|
+
return Array.isArray(value)
|
|
384
|
+
? value.filter((item): item is Record<string, unknown> => Boolean(item) && typeof item === "object" && !Array.isArray(item))
|
|
385
|
+
: [];
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
function ContactFormComponent({ section, sdk }: ThemeSectionRendererProps) {
|
|
389
|
+
const props = dataRecord(section.data, "props");
|
|
390
|
+
const configuredFields = dataRecords(props, "fields");
|
|
391
|
+
const fields = configuredFields.length ? configuredFields : [
|
|
392
|
+
{ key: "name", label: "Nome", type: "text", required: true },
|
|
393
|
+
{ key: "email", label: "E-mail", type: "email", required: true },
|
|
394
|
+
{ key: "phone", label: "Telefone", type: "tel", required: false },
|
|
395
|
+
{ key: "message", label: "Mensagem", type: "textarea", required: true },
|
|
396
|
+
];
|
|
397
|
+
const [status, setStatus] = useState<"idle" | "sending" | "success" | "error">("idle");
|
|
398
|
+
const [error, setError] = useState("");
|
|
399
|
+
|
|
400
|
+
const submit = async (event: FormEvent<HTMLFormElement>) => {
|
|
401
|
+
event.preventDefault();
|
|
402
|
+
if (!sdk?.contact) {
|
|
403
|
+
setStatus("error");
|
|
404
|
+
setError("O envio de contatos ainda não está disponível neste ambiente.");
|
|
405
|
+
return;
|
|
406
|
+
}
|
|
407
|
+
setStatus("sending");
|
|
408
|
+
setError("");
|
|
409
|
+
const form = new FormData(event.currentTarget);
|
|
410
|
+
const values: Record<string, string | boolean | string[]> = {};
|
|
411
|
+
for (const field of fields) {
|
|
412
|
+
const key = dataString(field, "key");
|
|
413
|
+
if (!key) continue;
|
|
414
|
+
if (dataString(field, "type") === "checkbox") {
|
|
415
|
+
values[key] = form.has(key);
|
|
416
|
+
continue;
|
|
417
|
+
}
|
|
418
|
+
const all = form.getAll(key).map(String);
|
|
419
|
+
values[key] = all.length > 1 ? all : all[0] ?? "";
|
|
420
|
+
}
|
|
421
|
+
try {
|
|
422
|
+
await sdk.contact.submit({
|
|
423
|
+
formKey: dataString(section.data, "componentKey", "contact-form"),
|
|
424
|
+
sectionId: section.id,
|
|
425
|
+
values,
|
|
426
|
+
pathname: typeof window === "undefined" ? undefined : window.location.pathname,
|
|
427
|
+
});
|
|
428
|
+
event.currentTarget.reset();
|
|
429
|
+
setStatus("success");
|
|
430
|
+
} catch (cause) {
|
|
431
|
+
setStatus("error");
|
|
432
|
+
setError(cause instanceof Error ? cause.message : "Não foi possível enviar o contato.");
|
|
433
|
+
}
|
|
434
|
+
};
|
|
435
|
+
|
|
436
|
+
return <section className="store-section theme-component-section contact-form-section"><div className="store-container contact-form-layout">
|
|
437
|
+
<div className="contact-form-copy">
|
|
438
|
+
{dataString(props, "eyebrow") && <span>{dataString(props, "eyebrow")}</span>}
|
|
439
|
+
<h2>{dataString(props, "title", "Fale com nossa equipe")}</h2>
|
|
440
|
+
{dataString(props, "description") && <p>{dataString(props, "description")}</p>}
|
|
441
|
+
</div>
|
|
442
|
+
<form className="contact-form" onSubmit={(event) => void submit(event)}>
|
|
443
|
+
{fields.map((field) => {
|
|
444
|
+
const key = dataString(field, "key");
|
|
445
|
+
if (!key) return null;
|
|
446
|
+
const type = dataString(field, "type", "text");
|
|
447
|
+
const label = dataString(field, "label", key);
|
|
448
|
+
const required = field.required === true;
|
|
449
|
+
if (type === "checkbox") return <label className="contact-form-wide contact-form-checkbox" key={key}>
|
|
450
|
+
<input name={key} required={required} type="checkbox" value="true" />
|
|
451
|
+
<span>{label}{required && <small aria-hidden="true"> *</small>}</span>
|
|
452
|
+
</label>;
|
|
453
|
+
if (type === "select") return <label key={key}>
|
|
454
|
+
<span>{label}{required && <small aria-hidden="true"> *</small>}</span>
|
|
455
|
+
<select name={key} required={required}>{dataRecords(field, "options").map((option) => <option key={dataString(option, "value")} value={dataString(option, "value")}>{dataString(option, "label", dataString(option, "value"))}</option>)}</select>
|
|
456
|
+
</label>;
|
|
457
|
+
return <label className={type === "textarea" ? "contact-form-wide" : ""} key={key}>
|
|
458
|
+
<span>{label}{required && <small aria-hidden="true"> *</small>}</span>
|
|
459
|
+
{type === "textarea"
|
|
460
|
+
? <textarea name={key} placeholder={dataString(field, "placeholder")} required={required} rows={5} />
|
|
461
|
+
: <input name={key} placeholder={dataString(field, "placeholder")} required={required} type={["email", "tel", "url", "number"].includes(type) ? type : "text"} />}
|
|
462
|
+
</label>;
|
|
463
|
+
})}
|
|
464
|
+
<div className="contact-form-wide">
|
|
465
|
+
<button className="button button-primary" disabled={status === "sending"} type="submit">
|
|
466
|
+
{status === "sending" ? "Enviando…" : dataString(props, "submitLabel", "Enviar contato")}
|
|
467
|
+
</button>
|
|
468
|
+
{status === "success" && <p className="contact-form-feedback" role="status">{dataString(props, "successMessage", "Contato enviado com sucesso.")}</p>}
|
|
469
|
+
{status === "error" && <p className="contact-form-feedback contact-form-error" role="alert">{error}</p>}
|
|
470
|
+
</div>
|
|
471
|
+
</form>
|
|
472
|
+
</div></section>;
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
function ThemeComponentSection(props: ThemeSectionRendererProps) {
|
|
476
|
+
const { section } = props;
|
|
477
|
+
const componentKey = dataString(section.data, "componentKey");
|
|
478
|
+
const values = dataRecord(section.data, "props");
|
|
479
|
+
if (componentKey === "contact-form" || componentKey.endsWith("-form")) return <ContactFormComponent {...props} />;
|
|
480
|
+
if (componentKey === "video") return <section className="store-section theme-component-section" data-component-key="video"><div className="store-container">
|
|
481
|
+
{dataString(values, "eyebrow") && <span>{dataString(values, "eyebrow")}</span>}
|
|
482
|
+
{dataString(values, "title") && <h2>{dataString(values, "title")}</h2>}
|
|
483
|
+
{dataString(values, "description") && <p>{dataString(values, "description")}</p>}
|
|
484
|
+
{dataString(values, "videoUrl") && <video className="theme-component-video" controls playsInline poster={dataString(values, "posterImageUrl") || undefined} src={dataString(values, "videoUrl")} />}
|
|
485
|
+
</div></section>;
|
|
486
|
+
|
|
487
|
+
const items = dataRecords(values, "items");
|
|
488
|
+
return <section className="store-section theme-component-section" data-component-key={componentKey || undefined}><div className="store-container">
|
|
489
|
+
{dataString(values, "eyebrow") && <span>{dataString(values, "eyebrow")}</span>}
|
|
490
|
+
{dataString(values, "title") && <h2>{dataString(values, "title")}</h2>}
|
|
491
|
+
{dataString(values, "description") && <p>{dataString(values, "description")}</p>}
|
|
492
|
+
{items.length > 0 && <div className="theme-component-items">{items.map((item, index) => <article key={index}>
|
|
493
|
+
<strong>{dataString(item, "value", dataString(item, "title", dataString(item, "question", `Item ${index + 1}`)))}</strong>
|
|
494
|
+
{dataString(item, "description", dataString(item, "answer")) && <p>{dataString(item, "description", dataString(item, "answer"))}</p>}
|
|
495
|
+
</article>)}</div>}
|
|
496
|
+
</div></section>;
|
|
497
|
+
}
|
|
498
|
+
|
|
372
499
|
function ProductsSection({ section, context, adapters }: ThemeSectionRendererProps) {
|
|
373
500
|
const categorySlug = dataString(section.data, "categorySlug");
|
|
374
501
|
const products = context.catalog.products
|
|
@@ -422,6 +549,7 @@ export const defaultSectionRegistry: ThemeSectionRegistry = {
|
|
|
422
549
|
"cases-grid": AutomaticSection,
|
|
423
550
|
"products-grid": ProductsSection,
|
|
424
551
|
"products-carousel": ProductsSection,
|
|
552
|
+
"theme-component": ThemeComponentSection,
|
|
425
553
|
};
|
|
426
554
|
|
|
427
555
|
function fallbackSections(context: ThemeContext): ThemeHomeSection[] {
|
|
@@ -562,7 +690,7 @@ function FloatingWhatsapp({ context }: { context: ThemeContext }) {
|
|
|
562
690
|
return <a className="floating-whatsapp" href={url} target="_blank" rel="noreferrer" aria-label={`${label} pelo WhatsApp`}><svg viewBox="0 0 24 24" aria-hidden="true"><path d="M17.472 14.382c-.297-.149-1.758-.867-2.03-.967-.273-.099-.471-.148-.67.15-.197.297-.767.966-.94 1.164-.173.199-.347.223-.644.075-.297-.15-1.255-.463-2.39-1.475-.883-.788-1.48-1.761-1.653-2.059-.173-.297-.018-.458.13-.606.134-.133.298-.347.446-.52.149-.174.198-.298.298-.497.099-.198.05-.371-.025-.52-.075-.149-.669-1.612-.916-2.207-.242-.579-.487-.5-.669-.51-.173-.008-.371-.01-.57-.01-.198 0-.52.074-.792.372-.272.297-1.04 1.016-1.04 2.479s1.065 2.875 1.213 3.074c.149.198 2.095 3.2 5.076 4.487.709.306 1.262.489 1.694.626.712.227 1.36.195 1.871.118.571-.085 1.758-.719 2.006-1.413.248-.694.248-1.29.173-1.414-.074-.123-.272-.198-.57-.347m-5.421 7.403h-.004a9.87 9.87 0 0 1-5.031-1.378l-.361-.214-3.741.981.998-3.648-.235-.374a9.86 9.86 0 0 1-1.51-5.26c.001-5.45 4.436-9.884 9.888-9.884 2.64 0 5.122 1.03 6.988 2.898a9.825 9.825 0 0 1 2.9 6.986c-.002 5.45-4.437 9.884-9.892 9.884m8.413-18.297A11.815 11.815 0 0 0 12.05 0C5.495 0 .16 5.335.157 11.892c0 2.096.547 4.142 1.588 5.945L.057 24l6.3-1.654a11.882 11.882 0 0 0 5.689 1.448h.005c6.554 0 11.89-5.335 11.893-11.893a11.821 11.821 0 0 0-3.48-8.413Z" /></svg><span>{label}</span></a>;
|
|
563
691
|
}
|
|
564
692
|
|
|
565
|
-
export function DefaultTheme({ context, adapters, route = { type: "home" } }: DefaultThemeProps) {
|
|
693
|
+
export function DefaultTheme({ context, adapters, route = { type: "home" }, sdk }: DefaultThemeProps) {
|
|
566
694
|
const configured = context.site.settings?.theme;
|
|
567
695
|
const colors = { ...fallbackColors, ...configured?.colors };
|
|
568
696
|
const layout = configured?.layout;
|
|
@@ -592,7 +720,7 @@ export function DefaultTheme({ context, adapters, route = { type: "home" } }: De
|
|
|
592
720
|
<Header adapters={adapters} context={context} />
|
|
593
721
|
<div className="store-page"><RouteContent adapters={adapters} context={context} route={route} home={<main>{sections.map((section, index) => {
|
|
594
722
|
const Renderer = defaultSectionRegistry[section.type];
|
|
595
|
-
return Renderer ? <Renderer adapters={adapters} context={context} key={`${section.type}-${section.order}-${index}`} section={section} /> : null;
|
|
723
|
+
return Renderer ? <Renderer adapters={adapters} context={context} key={`${section.type}-${section.order}-${index}`} sdk={sdk} section={section} /> : null;
|
|
596
724
|
})}<section className="benefits-section"><div className="store-container benefits-grid">{template.benefits.map((benefit) => <div key={benefit.title}><strong>{benefit.title}</strong><span>{benefit.description}</span></div>)}</div></section></main>} /></div>
|
|
597
725
|
<Footer adapters={adapters} context={context} />
|
|
598
726
|
<FloatingWhatsapp context={context} />
|
|
@@ -105,6 +105,10 @@ const stylePaths = process.env.NUVLER_THEME_STYLES
|
|
|
105
105
|
|
|
106
106
|
export default defineConfig({
|
|
107
107
|
cacheDir: process.env.NUVLER_PREVIEW_CACHE_DIR?.trim() || undefined,
|
|
108
|
+
// O preview roda dentro do package da CLI, mas o pipeline CSS pertence ao
|
|
109
|
+
// tema ativo (Tailwind/PostCSS inclusive). Sem este search path, o Vite
|
|
110
|
+
// ignora o postcss.config do tema e serve apenas o CSS estrutural.
|
|
111
|
+
css: { postcss: themeDirectory },
|
|
108
112
|
plugins: [activeThemePlugin(
|
|
109
113
|
themeEntry,
|
|
110
114
|
stylePaths,
|