@nuvler/cli 0.4.5 → 0.5.1
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 +102 -3
- 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/generation/fidelity-pass.js +233 -0
- package/dist/migrate/generation/fidelity-pass.js.map +1 -0
- package/dist/migrate/generator.js +1488 -64
- 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 +452 -0
- package/dist/migrate/transform/source-transformer.js.map +1 -0
- package/dist/migrate/transformer.js +326 -1
- package/dist/migrate/transformer.js.map +1 -1
- package/dist/nuvler.js +3601 -314
- package/dist/nuvler.js.map +1 -1
- package/dist/preview/prepare.js +8 -1
- package/dist/preview/prepare.js.map +1 -1
- package/dist/templates/nuvler-atelier/nuvler.theme.json +24 -10
- package/dist/templates/nuvler-atelier/package.json +3 -3
- package/dist/templates/nuvler-default/nuvler.theme.json +24 -10
- package/dist/templates/nuvler-default/package.json +9 -4
- package/dist/templates/nuvler-default/src/home.tsx +74 -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 +14 -0
package/dist/nuvler.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { Command } from "commander";
|
|
3
|
-
import { existsSync } from "node:fs";
|
|
3
|
+
import { existsSync, statSync } from "node:fs";
|
|
4
4
|
import { access, chmod, copyFile, cp, lstat, mkdir, mkdtemp, readFile, readdir, rename, rm, rmdir, stat, writeFile } from "node:fs/promises";
|
|
5
5
|
import path from "node:path";
|
|
6
6
|
import { fileURLToPath } from "node:url";
|
|
@@ -30,8 +30,8 @@ var __exportAll = (all, no_symbols) => {
|
|
|
30
30
|
//#region src/commands/theme/create.ts
|
|
31
31
|
var THEME_ID_PATTERN = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
|
|
32
32
|
var NEW_THEME_VERSION = "0.1.0";
|
|
33
|
-
var CLI_VERSION_RANGE = "^0.
|
|
34
|
-
var SDK_VERSION_RANGE = "^1.
|
|
33
|
+
var CLI_VERSION_RANGE = "^0.5.1";
|
|
34
|
+
var SDK_VERSION_RANGE = "^1.3.1";
|
|
35
35
|
var THEME_TEMPLATES = [
|
|
36
36
|
{
|
|
37
37
|
id: "starter",
|
|
@@ -241,7 +241,7 @@ async function themeCreate(options) {
|
|
|
241
241
|
var THEME_BUILD_DIRECTORY = "dist";
|
|
242
242
|
var THEME_BUILD_ENTRY = "theme.js";
|
|
243
243
|
var THEME_BUILD_STYLE = "theme.css";
|
|
244
|
-
async function isFile(file) {
|
|
244
|
+
async function isFile$1(file) {
|
|
245
245
|
try {
|
|
246
246
|
return (await stat(file)).isFile();
|
|
247
247
|
} catch {
|
|
@@ -252,11 +252,11 @@ async function loadThemeBuild(project) {
|
|
|
252
252
|
const directory = path.join(project.directory, THEME_BUILD_DIRECTORY);
|
|
253
253
|
const entryPath = path.join(directory, THEME_BUILD_ENTRY);
|
|
254
254
|
const styleCandidate = path.join(directory, THEME_BUILD_STYLE);
|
|
255
|
-
if (!await isFile(entryPath)) throw new Error(`Build do tema não encontrado em ${entryPath}. Execute "nuvler theme build".`);
|
|
255
|
+
if (!await isFile$1(entryPath)) throw new Error(`Build do tema não encontrado em ${entryPath}. Execute "nuvler theme build".`);
|
|
256
256
|
return {
|
|
257
257
|
directory,
|
|
258
258
|
entryPath,
|
|
259
|
-
stylePath: await isFile(styleCandidate) ? styleCandidate : null
|
|
259
|
+
stylePath: await isFile$1(styleCandidate) ? styleCandidate : null
|
|
260
260
|
};
|
|
261
261
|
}
|
|
262
262
|
function createArtifactManifest(project, build) {
|
|
@@ -6612,6 +6612,22 @@ function preprocess(fn, schema) {
|
|
|
6612
6612
|
out: schema
|
|
6613
6613
|
});
|
|
6614
6614
|
}
|
|
6615
|
+
//#endregion
|
|
6616
|
+
//#region ../../node_modules/zod/v4/classic/compat.js
|
|
6617
|
+
/** @deprecated Use the raw string literal codes instead, e.g. "invalid_type". */
|
|
6618
|
+
var ZodIssueCode = {
|
|
6619
|
+
invalid_type: "invalid_type",
|
|
6620
|
+
too_big: "too_big",
|
|
6621
|
+
too_small: "too_small",
|
|
6622
|
+
invalid_format: "invalid_format",
|
|
6623
|
+
not_multiple_of: "not_multiple_of",
|
|
6624
|
+
unrecognized_keys: "unrecognized_keys",
|
|
6625
|
+
invalid_union: "invalid_union",
|
|
6626
|
+
invalid_key: "invalid_key",
|
|
6627
|
+
invalid_element: "invalid_element",
|
|
6628
|
+
invalid_value: "invalid_value",
|
|
6629
|
+
custom: "custom"
|
|
6630
|
+
};
|
|
6615
6631
|
/** @deprecated Do not use. Stub definition, only included for zod-to-json-schema compatibility. */
|
|
6616
6632
|
var ZodFirstPartyTypeKind;
|
|
6617
6633
|
ZodFirstPartyTypeKind || (ZodFirstPartyTypeKind = {});
|
|
@@ -6641,6 +6657,131 @@ var ThemeSiteColorsSchema = object({
|
|
|
6641
6657
|
footerBackground: hexColorSchema.optional(),
|
|
6642
6658
|
footerText: hexColorSchema.optional()
|
|
6643
6659
|
}).strict();
|
|
6660
|
+
var componentKeySchema = string$1().trim().min(2).max(80).regex(/^[a-z0-9]+(?:-[a-z0-9]+)*$/, "Use um identificador em kebab-case");
|
|
6661
|
+
var fieldKeySchema = string$1().trim().min(1).max(64).regex(/^[a-z][a-zA-Z0-9-]*$/, "Use uma chave iniciada por letra, sem espaços");
|
|
6662
|
+
var fieldControlSchema = _enum([
|
|
6663
|
+
"text",
|
|
6664
|
+
"textarea",
|
|
6665
|
+
"rich-text",
|
|
6666
|
+
"url",
|
|
6667
|
+
"image",
|
|
6668
|
+
"video",
|
|
6669
|
+
"number",
|
|
6670
|
+
"boolean",
|
|
6671
|
+
"select",
|
|
6672
|
+
"repeater",
|
|
6673
|
+
"contact-fields"
|
|
6674
|
+
]);
|
|
6675
|
+
var fieldOptionSchema = object({
|
|
6676
|
+
label: string$1().trim().min(1).max(120),
|
|
6677
|
+
value: string$1().trim().min(1).max(120)
|
|
6678
|
+
}).strict();
|
|
6679
|
+
var fieldBaseShape = {
|
|
6680
|
+
key: fieldKeySchema,
|
|
6681
|
+
label: string$1().trim().min(1).max(120),
|
|
6682
|
+
control: fieldControlSchema,
|
|
6683
|
+
help: string$1().trim().min(1).max(300).optional(),
|
|
6684
|
+
placeholder: string$1().trim().max(200).optional(),
|
|
6685
|
+
required: boolean$1().optional(),
|
|
6686
|
+
defaultValue: union([
|
|
6687
|
+
string$1().max(5e3),
|
|
6688
|
+
number$1().finite(),
|
|
6689
|
+
boolean$1(),
|
|
6690
|
+
_null()
|
|
6691
|
+
]).optional(),
|
|
6692
|
+
options: array(fieldOptionSchema).min(1).max(100).optional(),
|
|
6693
|
+
min: number$1().finite().optional(),
|
|
6694
|
+
max: number$1().finite().optional(),
|
|
6695
|
+
maxLength: number$1().int().positive().max(1e5).optional(),
|
|
6696
|
+
maxItems: number$1().int().positive().max(100).optional()
|
|
6697
|
+
};
|
|
6698
|
+
var ThemeHomeComponentItemFieldSchema = object(fieldBaseShape).strict().superRefine((field, context) => {
|
|
6699
|
+
if (field.control === "repeater") context.addIssue({
|
|
6700
|
+
code: ZodIssueCode.custom,
|
|
6701
|
+
path: ["control"],
|
|
6702
|
+
message: "Repetidores aninhados não são permitidos"
|
|
6703
|
+
});
|
|
6704
|
+
if (field.control === "select" && !field.options?.length) context.addIssue({
|
|
6705
|
+
code: ZodIssueCode.custom,
|
|
6706
|
+
path: ["options"],
|
|
6707
|
+
message: "Campos select exigem opções"
|
|
6708
|
+
});
|
|
6709
|
+
});
|
|
6710
|
+
var ThemeHomeComponentFieldSchema = object({
|
|
6711
|
+
...fieldBaseShape,
|
|
6712
|
+
itemFields: array(ThemeHomeComponentItemFieldSchema).min(1).max(30).optional()
|
|
6713
|
+
}).strict().superRefine((field, context) => {
|
|
6714
|
+
if (field.control === "select" && !field.options?.length) context.addIssue({
|
|
6715
|
+
code: ZodIssueCode.custom,
|
|
6716
|
+
path: ["options"],
|
|
6717
|
+
message: "Campos select exigem opções"
|
|
6718
|
+
});
|
|
6719
|
+
if (field.control === "repeater" && !field.itemFields?.length) context.addIssue({
|
|
6720
|
+
code: ZodIssueCode.custom,
|
|
6721
|
+
path: ["itemFields"],
|
|
6722
|
+
message: "Campos repeater exigem os campos de cada item"
|
|
6723
|
+
});
|
|
6724
|
+
if (field.control !== "repeater" && field.itemFields) context.addIssue({
|
|
6725
|
+
code: ZodIssueCode.custom,
|
|
6726
|
+
path: ["itemFields"],
|
|
6727
|
+
message: "itemFields só pode ser usado em campos repeater"
|
|
6728
|
+
});
|
|
6729
|
+
if (field.min !== void 0 && field.max !== void 0 && field.min > field.max) context.addIssue({
|
|
6730
|
+
code: ZodIssueCode.custom,
|
|
6731
|
+
path: ["min"],
|
|
6732
|
+
message: "O valor mínimo não pode superar o máximo"
|
|
6733
|
+
});
|
|
6734
|
+
const itemKeys = /* @__PURE__ */ new Set();
|
|
6735
|
+
field.itemFields?.forEach((item, index) => {
|
|
6736
|
+
if (itemKeys.has(item.key)) context.addIssue({
|
|
6737
|
+
code: ZodIssueCode.custom,
|
|
6738
|
+
path: [
|
|
6739
|
+
"itemFields",
|
|
6740
|
+
index,
|
|
6741
|
+
"key"
|
|
6742
|
+
],
|
|
6743
|
+
message: "A chave do campo repetível deve ser única"
|
|
6744
|
+
});
|
|
6745
|
+
itemKeys.add(item.key);
|
|
6746
|
+
});
|
|
6747
|
+
});
|
|
6748
|
+
var ThemeHomeComponentDefinitionSchema = object({
|
|
6749
|
+
key: componentKeySchema,
|
|
6750
|
+
name: string$1().trim().min(2).max(120),
|
|
6751
|
+
description: string$1().trim().min(1).max(300),
|
|
6752
|
+
category: _enum([
|
|
6753
|
+
"Destaques",
|
|
6754
|
+
"Conteúdo",
|
|
6755
|
+
"Listas",
|
|
6756
|
+
"Mídia",
|
|
6757
|
+
"Formulários"
|
|
6758
|
+
]),
|
|
6759
|
+
schemaVersion: number$1().int().positive().max(1e3),
|
|
6760
|
+
fields: array(ThemeHomeComponentFieldSchema).max(40),
|
|
6761
|
+
action: object({
|
|
6762
|
+
type: literal("contact.submit"),
|
|
6763
|
+
formKey: componentKeySchema
|
|
6764
|
+
}).strict().optional()
|
|
6765
|
+
}).strict().superRefine((component, context) => {
|
|
6766
|
+
const keys = /* @__PURE__ */ new Set();
|
|
6767
|
+
component.fields.forEach((field, index) => {
|
|
6768
|
+
if (keys.has(field.key)) context.addIssue({
|
|
6769
|
+
code: ZodIssueCode.custom,
|
|
6770
|
+
path: [
|
|
6771
|
+
"fields",
|
|
6772
|
+
index,
|
|
6773
|
+
"key"
|
|
6774
|
+
],
|
|
6775
|
+
message: "A chave do campo deve ser única no componente"
|
|
6776
|
+
});
|
|
6777
|
+
keys.add(field.key);
|
|
6778
|
+
});
|
|
6779
|
+
if (component.fields.some(({ control }) => control === "contact-fields") && !component.action) context.addIssue({
|
|
6780
|
+
code: ZodIssueCode.custom,
|
|
6781
|
+
path: ["action"],
|
|
6782
|
+
message: "Componentes com campos de contato exigem a ação contact.submit"
|
|
6783
|
+
});
|
|
6784
|
+
});
|
|
6644
6785
|
var ThemePresentationSchema = object({
|
|
6645
6786
|
description: string$1().trim().min(1).max(500),
|
|
6646
6787
|
templateId: string$1().trim().min(1).max(80).optional(),
|
|
@@ -6648,8 +6789,23 @@ var ThemePresentationSchema = object({
|
|
|
6648
6789
|
layout: object({
|
|
6649
6790
|
containerWidth: number$1().int().min(960).max(1600),
|
|
6650
6791
|
borderRadius: number$1().int().min(0).max(32)
|
|
6651
|
-
}).strict()
|
|
6652
|
-
|
|
6792
|
+
}).strict(),
|
|
6793
|
+
homeComponents: array(ThemeHomeComponentDefinitionSchema).max(50).optional()
|
|
6794
|
+
}).strict().superRefine((presentation, context) => {
|
|
6795
|
+
const keys = /* @__PURE__ */ new Set();
|
|
6796
|
+
presentation.homeComponents?.forEach((component, index) => {
|
|
6797
|
+
if (keys.has(component.key)) context.addIssue({
|
|
6798
|
+
code: ZodIssueCode.custom,
|
|
6799
|
+
path: [
|
|
6800
|
+
"homeComponents",
|
|
6801
|
+
index,
|
|
6802
|
+
"key"
|
|
6803
|
+
],
|
|
6804
|
+
message: "A chave do componente deve ser única no tema"
|
|
6805
|
+
});
|
|
6806
|
+
keys.add(component.key);
|
|
6807
|
+
});
|
|
6808
|
+
});
|
|
6653
6809
|
var ThemeManifestSchema = object({
|
|
6654
6810
|
schemaVersion: literal(THEME_SCHEMA_VERSION),
|
|
6655
6811
|
id: string$1().trim().min(2).max(80).regex(/^[a-z0-9]+(?:-[a-z0-9]+)*$/, "Use um identificador em kebab-case"),
|
|
@@ -6718,6 +6874,11 @@ var ThemeSiteSchema = object({
|
|
|
6718
6874
|
}).strict().nullable().optional()
|
|
6719
6875
|
}).strict().nullable()
|
|
6720
6876
|
}).strict();
|
|
6877
|
+
var ThemeComponentSectionDataSchema = object({
|
|
6878
|
+
componentKey: componentKeySchema,
|
|
6879
|
+
schemaVersion: number$1().int().positive().max(1e3),
|
|
6880
|
+
props: record(string$1(), unknown())
|
|
6881
|
+
}).strict();
|
|
6721
6882
|
var ThemeHomeSectionSchema = object({
|
|
6722
6883
|
id: string$1().optional(),
|
|
6723
6884
|
type: _enum([
|
|
@@ -6730,12 +6891,22 @@ var ThemeHomeSectionSchema = object({
|
|
|
6730
6891
|
"blog-grid",
|
|
6731
6892
|
"cases-grid",
|
|
6732
6893
|
"products-grid",
|
|
6733
|
-
"products-carousel"
|
|
6894
|
+
"products-carousel",
|
|
6895
|
+
"theme-component"
|
|
6734
6896
|
]),
|
|
6735
6897
|
enabled: boolean$1(),
|
|
6736
6898
|
order: number$1().int().nonnegative(),
|
|
6737
6899
|
data: record(string$1(), unknown())
|
|
6738
|
-
}).strict()
|
|
6900
|
+
}).strict().superRefine((section, context) => {
|
|
6901
|
+
if (section.type !== "theme-component") return;
|
|
6902
|
+
const parsed = ThemeComponentSectionDataSchema.safeParse(section.data);
|
|
6903
|
+
if (parsed.success) return;
|
|
6904
|
+
parsed.error.issues.forEach((issue) => context.addIssue({
|
|
6905
|
+
code: ZodIssueCode.custom,
|
|
6906
|
+
path: ["data", ...issue.path],
|
|
6907
|
+
message: issue.message
|
|
6908
|
+
}));
|
|
6909
|
+
});
|
|
6739
6910
|
var ThemeHomeSchema = object({
|
|
6740
6911
|
title: string$1(),
|
|
6741
6912
|
slug: string$1(),
|
|
@@ -7577,9 +7748,10 @@ async function prepareThemePreview(options) {
|
|
|
7577
7748
|
if (context.store.slug !== tenant.slug) throw new Error(`A API retornou contexto do tenant "${context.store.slug}" para "${tenant.slug}".`);
|
|
7578
7749
|
return {
|
|
7579
7750
|
project,
|
|
7580
|
-
context,
|
|
7751
|
+
context: ThemeContextSchema.parse(context),
|
|
7581
7752
|
apiUrl: session.apiUrl,
|
|
7582
|
-
tenant
|
|
7753
|
+
tenant,
|
|
7754
|
+
migrationSeedSections: 0
|
|
7583
7755
|
};
|
|
7584
7756
|
}
|
|
7585
7757
|
//#endregion
|
|
@@ -7588,7 +7760,7 @@ function countCategories(categories) {
|
|
|
7588
7760
|
return categories.reduce((total, category) => total + 1 + countCategories(category.children), 0);
|
|
7589
7761
|
}
|
|
7590
7762
|
async function themeDev(options) {
|
|
7591
|
-
const { project, context, apiUrl, tenant } = await prepareThemePreview({
|
|
7763
|
+
const { project, context, apiUrl, tenant, migrationSeedSections } = await prepareThemePreview({
|
|
7592
7764
|
themeDirectory: options.themeDirectory,
|
|
7593
7765
|
store: options.store,
|
|
7594
7766
|
apiUrl: options.apiUrl
|
|
@@ -7609,6 +7781,7 @@ async function themeDev(options) {
|
|
|
7609
7781
|
console.log("");
|
|
7610
7782
|
console.log("✓ Site carregado");
|
|
7611
7783
|
console.log("✓ Home carregada");
|
|
7784
|
+
if (migrationSeedSections) console.log(`✓ ${migrationSeedSections} seção(ões) preenchida(s) com o conteúdo extraído para o preview local`);
|
|
7612
7785
|
console.log(`✓ ${context.catalog.products.length} produtos carregados`);
|
|
7613
7786
|
console.log(`✓ ${countCategories(context.navigation.categories)} categorias carregadas`);
|
|
7614
7787
|
console.log(`✓ ${context.navigation.pages.length} páginas carregadas`);
|
|
@@ -7903,6 +8076,405 @@ async function themePublish(options) {
|
|
|
7903
8076
|
console.log("");
|
|
7904
8077
|
}
|
|
7905
8078
|
//#endregion
|
|
8079
|
+
//#region src/migrate/resolvers/import-resolver.ts
|
|
8080
|
+
var SOURCE_EXTENSIONS$1 = [
|
|
8081
|
+
".tsx",
|
|
8082
|
+
".ts",
|
|
8083
|
+
".jsx",
|
|
8084
|
+
".js",
|
|
8085
|
+
".mts",
|
|
8086
|
+
".mjs",
|
|
8087
|
+
".cts",
|
|
8088
|
+
".cjs"
|
|
8089
|
+
];
|
|
8090
|
+
var STYLE_EXTENSIONS$1 = [
|
|
8091
|
+
".css",
|
|
8092
|
+
".scss",
|
|
8093
|
+
".sass",
|
|
8094
|
+
".less"
|
|
8095
|
+
];
|
|
8096
|
+
var ASSET_EXTENSIONS$1 = [
|
|
8097
|
+
".avif",
|
|
8098
|
+
".bmp",
|
|
8099
|
+
".eot",
|
|
8100
|
+
".gif",
|
|
8101
|
+
".ico",
|
|
8102
|
+
".jpeg",
|
|
8103
|
+
".jpg",
|
|
8104
|
+
".mp4",
|
|
8105
|
+
".ogg",
|
|
8106
|
+
".otf",
|
|
8107
|
+
".png",
|
|
8108
|
+
".svg",
|
|
8109
|
+
".ttf",
|
|
8110
|
+
".webm",
|
|
8111
|
+
".webp",
|
|
8112
|
+
".woff",
|
|
8113
|
+
".woff2"
|
|
8114
|
+
];
|
|
8115
|
+
var RESOLVABLE_EXTENSIONS = [
|
|
8116
|
+
...SOURCE_EXTENSIONS$1,
|
|
8117
|
+
...STYLE_EXTENSIONS$1,
|
|
8118
|
+
...ASSET_EXTENSIONS$1,
|
|
8119
|
+
".json"
|
|
8120
|
+
];
|
|
8121
|
+
function inside$2(root, candidate) {
|
|
8122
|
+
const relative = path.relative(root, candidate);
|
|
8123
|
+
return relative === "" || !relative.startsWith("..") && !path.isAbsolute(relative);
|
|
8124
|
+
}
|
|
8125
|
+
function isFile(file) {
|
|
8126
|
+
try {
|
|
8127
|
+
return statSync(file).isFile();
|
|
8128
|
+
} catch {
|
|
8129
|
+
return false;
|
|
8130
|
+
}
|
|
8131
|
+
}
|
|
8132
|
+
function cleanSpecifier(specifier) {
|
|
8133
|
+
return specifier.replace(/[?#].*$/, "");
|
|
8134
|
+
}
|
|
8135
|
+
function compilerOptions(sourceDirectory) {
|
|
8136
|
+
const configFile = ts.findConfigFile(sourceDirectory, ts.sys.fileExists, "tsconfig.json");
|
|
8137
|
+
if (!configFile) return {};
|
|
8138
|
+
const config = ts.readConfigFile(configFile, ts.sys.readFile);
|
|
8139
|
+
if (config.error) return {};
|
|
8140
|
+
return ts.parseJsonConfigFileContent(config.config, ts.sys, path.dirname(configFile)).options;
|
|
8141
|
+
}
|
|
8142
|
+
function packageNameOf(specifier) {
|
|
8143
|
+
if (specifier.startsWith(".") || specifier.startsWith("/") || specifier.startsWith("@/") || specifier.startsWith("~/")) return null;
|
|
8144
|
+
const parts = specifier.split("/");
|
|
8145
|
+
return specifier.startsWith("@") ? parts.slice(0, 2).join("/") : parts[0];
|
|
8146
|
+
}
|
|
8147
|
+
function extensionKind(file) {
|
|
8148
|
+
const extension = path.extname(file).toLowerCase();
|
|
8149
|
+
if (SOURCE_EXTENSIONS$1.includes(extension)) return "SOURCE";
|
|
8150
|
+
if (STYLE_EXTENSIONS$1.includes(extension)) return "STYLE";
|
|
8151
|
+
if (ASSET_EXTENSIONS$1.includes(extension)) return "ASSET";
|
|
8152
|
+
if (extension === ".json") return "JSON";
|
|
8153
|
+
return null;
|
|
8154
|
+
}
|
|
8155
|
+
function createImportResolver(sourceDirectory) {
|
|
8156
|
+
const root = path.resolve(sourceDirectory);
|
|
8157
|
+
const options = compilerOptions(root);
|
|
8158
|
+
function candidates(base) {
|
|
8159
|
+
return [
|
|
8160
|
+
base,
|
|
8161
|
+
...RESOLVABLE_EXTENSIONS.map((extension) => `${base}${extension}`),
|
|
8162
|
+
...[
|
|
8163
|
+
...SOURCE_EXTENSIONS$1,
|
|
8164
|
+
...STYLE_EXTENSIONS$1,
|
|
8165
|
+
".json"
|
|
8166
|
+
].map((extension) => path.join(base, `index${extension}`))
|
|
8167
|
+
];
|
|
8168
|
+
}
|
|
8169
|
+
return { resolve(importer, originalSpecifier) {
|
|
8170
|
+
const specifier = cleanSpecifier(originalSpecifier);
|
|
8171
|
+
const resolved = ts.resolveModuleName(specifier, importer, options, {
|
|
8172
|
+
fileExists: ts.sys.fileExists,
|
|
8173
|
+
readFile: ts.sys.readFile
|
|
8174
|
+
}).resolvedModule?.resolvedFileName;
|
|
8175
|
+
if (resolved && inside$2(root, resolved) && !resolved.includes(`${path.sep}node_modules${path.sep}`) && isFile(resolved)) return path.resolve(resolved);
|
|
8176
|
+
const bases = specifier.startsWith(".") ? [path.resolve(path.dirname(importer), specifier)] : specifier.startsWith("@/") || specifier.startsWith("~/") ? [path.resolve(root, "src", specifier.slice(2)), path.resolve(root, specifier.slice(2))] : specifier.startsWith("/") ? [path.resolve(root, "public", specifier.replace(/^\/+/, ""))] : [];
|
|
8177
|
+
for (const candidate of bases.flatMap(candidates)) if (inside$2(root, candidate) && isFile(candidate)) return candidate;
|
|
8178
|
+
return null;
|
|
8179
|
+
} };
|
|
8180
|
+
}
|
|
8181
|
+
//#endregion
|
|
8182
|
+
//#region src/migrate/analysis/dependency-classifier.ts
|
|
8183
|
+
var VISUAL_PACKAGES = [
|
|
8184
|
+
"framer-motion",
|
|
8185
|
+
"motion",
|
|
8186
|
+
"lucide-react",
|
|
8187
|
+
"react-icons",
|
|
8188
|
+
"@mui/material",
|
|
8189
|
+
"@mui/icons-material",
|
|
8190
|
+
"@emotion/react",
|
|
8191
|
+
"@emotion/styled",
|
|
8192
|
+
"@radix-ui/",
|
|
8193
|
+
"embla-carousel",
|
|
8194
|
+
"react-slick",
|
|
8195
|
+
"recharts",
|
|
8196
|
+
"sonner",
|
|
8197
|
+
"vaul"
|
|
8198
|
+
];
|
|
8199
|
+
var UTILITY_PACKAGES = [
|
|
8200
|
+
"clsx",
|
|
8201
|
+
"classnames",
|
|
8202
|
+
"class-variance-authority",
|
|
8203
|
+
"tailwind-merge",
|
|
8204
|
+
"date-fns"
|
|
8205
|
+
];
|
|
8206
|
+
var BUSINESS_PACKAGES = [
|
|
8207
|
+
"axios",
|
|
8208
|
+
"@tanstack/react-query",
|
|
8209
|
+
"react-query",
|
|
8210
|
+
"zustand",
|
|
8211
|
+
"redux",
|
|
8212
|
+
"@reduxjs/",
|
|
8213
|
+
"firebase",
|
|
8214
|
+
"supabase",
|
|
8215
|
+
"stripe",
|
|
8216
|
+
"auth",
|
|
8217
|
+
"checkout",
|
|
8218
|
+
"shopify"
|
|
8219
|
+
];
|
|
8220
|
+
function matches(packageName, candidates) {
|
|
8221
|
+
return candidates.some((candidate) => packageName === candidate || packageName.startsWith(candidate));
|
|
8222
|
+
}
|
|
8223
|
+
function classifyDependency(specifier, resolvedFile) {
|
|
8224
|
+
if (resolvedFile) {
|
|
8225
|
+
const kind = extensionKind(resolvedFile);
|
|
8226
|
+
if (kind === "ASSET") return "ASSET";
|
|
8227
|
+
if (kind === "STYLE") return "VISUAL";
|
|
8228
|
+
const normalized = resolvedFile.split(path.sep).join("/").toLowerCase();
|
|
8229
|
+
if (/(?:^|\/)(?:api|auth|checkout|cart|carrinho|store|services?)(?:\/|\.)/.test(normalized)) return "BUSINESS";
|
|
8230
|
+
return kind === "SOURCE" ? "UNKNOWN" : "UTILITY";
|
|
8231
|
+
}
|
|
8232
|
+
const packageName = packageNameOf(specifier);
|
|
8233
|
+
if (!packageName || packageName === "react" || packageName === "react-dom") return "UTILITY";
|
|
8234
|
+
if (matches(packageName, VISUAL_PACKAGES)) return "VISUAL";
|
|
8235
|
+
if (matches(packageName, UTILITY_PACKAGES)) return "UTILITY";
|
|
8236
|
+
if (matches(packageName, BUSINESS_PACKAGES)) return "BUSINESS";
|
|
8237
|
+
return "UNKNOWN";
|
|
8238
|
+
}
|
|
8239
|
+
//#endregion
|
|
8240
|
+
//#region src/migrate/analysis/dependency-graph.ts
|
|
8241
|
+
function portable$4(file) {
|
|
8242
|
+
return file.split(path.sep).join("/");
|
|
8243
|
+
}
|
|
8244
|
+
async function exists(file) {
|
|
8245
|
+
try {
|
|
8246
|
+
return (await stat(file)).isFile();
|
|
8247
|
+
} catch {
|
|
8248
|
+
return false;
|
|
8249
|
+
}
|
|
8250
|
+
}
|
|
8251
|
+
function sourceFile(file, content) {
|
|
8252
|
+
const extension = path.extname(file).toLowerCase();
|
|
8253
|
+
const kind = extension === ".tsx" ? ts.ScriptKind.TSX : extension === ".jsx" ? ts.ScriptKind.JSX : extension === ".js" || extension === ".mjs" || extension === ".cjs" ? ts.ScriptKind.JS : ts.ScriptKind.TS;
|
|
8254
|
+
return ts.createSourceFile(file, content, ts.ScriptTarget.Latest, true, kind);
|
|
8255
|
+
}
|
|
8256
|
+
function moduleSpecifiers(source) {
|
|
8257
|
+
const result = [];
|
|
8258
|
+
for (const statement of source.statements) {
|
|
8259
|
+
if (ts.isImportDeclaration(statement) && ts.isStringLiteralLike(statement.moduleSpecifier)) {
|
|
8260
|
+
const defaultBinding = statement.importClause?.name?.text ?? null;
|
|
8261
|
+
const firstNamed = statement.importClause?.namedBindings && ts.isNamedImports(statement.importClause.namedBindings) ? statement.importClause.namedBindings.elements[0] : null;
|
|
8262
|
+
result.push({
|
|
8263
|
+
specifier: statement.moduleSpecifier.text,
|
|
8264
|
+
dynamic: false,
|
|
8265
|
+
defaultBinding,
|
|
8266
|
+
importedName: firstNamed?.propertyName?.text ?? firstNamed?.name.text ?? null
|
|
8267
|
+
});
|
|
8268
|
+
}
|
|
8269
|
+
if (ts.isExportDeclaration(statement) && statement.moduleSpecifier && ts.isStringLiteralLike(statement.moduleSpecifier)) result.push({
|
|
8270
|
+
specifier: statement.moduleSpecifier.text,
|
|
8271
|
+
dynamic: false,
|
|
8272
|
+
defaultBinding: null,
|
|
8273
|
+
importedName: null
|
|
8274
|
+
});
|
|
8275
|
+
}
|
|
8276
|
+
function visit(node) {
|
|
8277
|
+
if (ts.isCallExpression(node) && node.expression.kind === ts.SyntaxKind.ImportKeyword) {
|
|
8278
|
+
const argument = node.arguments[0];
|
|
8279
|
+
if (argument && ts.isStringLiteralLike(argument)) result.push({
|
|
8280
|
+
specifier: argument.text,
|
|
8281
|
+
dynamic: true,
|
|
8282
|
+
defaultBinding: null,
|
|
8283
|
+
importedName: null
|
|
8284
|
+
});
|
|
8285
|
+
}
|
|
8286
|
+
ts.forEachChild(node, visit);
|
|
8287
|
+
}
|
|
8288
|
+
visit(source);
|
|
8289
|
+
return result;
|
|
8290
|
+
}
|
|
8291
|
+
function exportIdentity(source) {
|
|
8292
|
+
for (const statement of source.statements) {
|
|
8293
|
+
if (ts.isExportAssignment(statement) && !statement.isExportEquals) return {
|
|
8294
|
+
exportName: "default",
|
|
8295
|
+
defaultExport: true
|
|
8296
|
+
};
|
|
8297
|
+
if ((ts.isFunctionDeclaration(statement) || ts.isClassDeclaration(statement)) && statement.modifiers?.some((modifier) => modifier.kind === ts.SyntaxKind.DefaultKeyword)) return {
|
|
8298
|
+
exportName: statement.name?.text ?? "default",
|
|
8299
|
+
defaultExport: true
|
|
8300
|
+
};
|
|
8301
|
+
}
|
|
8302
|
+
for (const statement of source.statements) if (ts.isFunctionDeclaration(statement) && statement.name && statement.modifiers?.some((modifier) => modifier.kind === ts.SyntaxKind.ExportKeyword)) return {
|
|
8303
|
+
exportName: statement.name.text,
|
|
8304
|
+
defaultExport: false
|
|
8305
|
+
};
|
|
8306
|
+
return {
|
|
8307
|
+
exportName: "default",
|
|
8308
|
+
defaultExport: true
|
|
8309
|
+
};
|
|
8310
|
+
}
|
|
8311
|
+
async function viteEntrypoint(sourceDirectory) {
|
|
8312
|
+
const resolver = createImportResolver(sourceDirectory);
|
|
8313
|
+
for (const relative of [
|
|
8314
|
+
"src/main.tsx",
|
|
8315
|
+
"src/main.jsx",
|
|
8316
|
+
"src/index.tsx",
|
|
8317
|
+
"src/index.jsx",
|
|
8318
|
+
"main.tsx"
|
|
8319
|
+
]) {
|
|
8320
|
+
const bootstrap = path.join(sourceDirectory, relative);
|
|
8321
|
+
if (!await exists(bootstrap)) continue;
|
|
8322
|
+
const source = sourceFile(bootstrap, await readFile(bootstrap, "utf8"));
|
|
8323
|
+
const imports = moduleSpecifiers(source).map((item) => ({
|
|
8324
|
+
...item,
|
|
8325
|
+
resolved: resolver.resolve(bootstrap, item.specifier)
|
|
8326
|
+
})).filter((item) => item.resolved && extensionKind(item.resolved) === "SOURCE").sort((left, right) => Number(/app|home/i.test(path.basename(right.resolved))) - Number(/app|home/i.test(path.basename(left.resolved))));
|
|
8327
|
+
const rootImport = imports.find((item) => item.defaultBinding && new RegExp(`<${item.defaultBinding}\\b`).test(source.text)) ?? imports.find((item) => /app|home/i.test(path.basename(item.resolved)));
|
|
8328
|
+
if (rootImport?.resolved) return {
|
|
8329
|
+
bootstrapFile: portable$4(path.relative(sourceDirectory, bootstrap)),
|
|
8330
|
+
pageFile: portable$4(path.relative(sourceDirectory, rootImport.resolved)),
|
|
8331
|
+
exportName: rootImport.importedName ?? rootImport.defaultBinding ?? "default",
|
|
8332
|
+
defaultExport: Boolean(rootImport.defaultBinding),
|
|
8333
|
+
layoutFiles: []
|
|
8334
|
+
};
|
|
8335
|
+
}
|
|
8336
|
+
for (const relative of [
|
|
8337
|
+
"src/App.tsx",
|
|
8338
|
+
"src/app/App.tsx",
|
|
8339
|
+
"App.tsx",
|
|
8340
|
+
"src/Home.tsx"
|
|
8341
|
+
]) {
|
|
8342
|
+
const file = path.join(sourceDirectory, relative);
|
|
8343
|
+
if (!await exists(file)) continue;
|
|
8344
|
+
const identity = exportIdentity(sourceFile(file, await readFile(file, "utf8")));
|
|
8345
|
+
return {
|
|
8346
|
+
bootstrapFile: null,
|
|
8347
|
+
pageFile: portable$4(relative),
|
|
8348
|
+
...identity,
|
|
8349
|
+
layoutFiles: []
|
|
8350
|
+
};
|
|
8351
|
+
}
|
|
8352
|
+
return null;
|
|
8353
|
+
}
|
|
8354
|
+
async function nextEntrypoint(sourceDirectory) {
|
|
8355
|
+
for (const relative of [
|
|
8356
|
+
"src/app/page.tsx",
|
|
8357
|
+
"app/page.tsx",
|
|
8358
|
+
"src/pages/index.tsx",
|
|
8359
|
+
"pages/index.tsx"
|
|
8360
|
+
]) {
|
|
8361
|
+
const file = path.join(sourceDirectory, relative);
|
|
8362
|
+
if (!await exists(file)) continue;
|
|
8363
|
+
const identity = exportIdentity(sourceFile(file, await readFile(file, "utf8")));
|
|
8364
|
+
const layouts = [];
|
|
8365
|
+
if (relative.includes("/app/") || relative.startsWith("app/")) {
|
|
8366
|
+
let current = path.dirname(file);
|
|
8367
|
+
while (current.startsWith(sourceDirectory)) {
|
|
8368
|
+
const layout = path.join(current, "layout.tsx");
|
|
8369
|
+
if (await exists(layout)) layouts.unshift(portable$4(path.relative(sourceDirectory, layout)));
|
|
8370
|
+
if (current === sourceDirectory) break;
|
|
8371
|
+
current = path.dirname(current);
|
|
8372
|
+
}
|
|
8373
|
+
}
|
|
8374
|
+
return {
|
|
8375
|
+
bootstrapFile: null,
|
|
8376
|
+
pageFile: portable$4(relative),
|
|
8377
|
+
...identity,
|
|
8378
|
+
layoutFiles: layouts
|
|
8379
|
+
};
|
|
8380
|
+
}
|
|
8381
|
+
return null;
|
|
8382
|
+
}
|
|
8383
|
+
async function discoverEntrypoint(sourceDirectory, framework) {
|
|
8384
|
+
return framework === "next" ? nextEntrypoint(sourceDirectory) : viteEntrypoint(sourceDirectory);
|
|
8385
|
+
}
|
|
8386
|
+
function localLooking(specifier) {
|
|
8387
|
+
return specifier.startsWith(".") || specifier.startsWith("/") || specifier.startsWith("@/") || specifier.startsWith("~/");
|
|
8388
|
+
}
|
|
8389
|
+
async function buildSourceDependencyGraph(sourceDirectory, framework) {
|
|
8390
|
+
const root = path.resolve(sourceDirectory);
|
|
8391
|
+
const resolver = createImportResolver(root);
|
|
8392
|
+
const entrypoint = await discoverEntrypoint(root, framework);
|
|
8393
|
+
if (!entrypoint) return {
|
|
8394
|
+
entrypoint: null,
|
|
8395
|
+
modules: [],
|
|
8396
|
+
dependencies: [],
|
|
8397
|
+
unresolvedImports: []
|
|
8398
|
+
};
|
|
8399
|
+
const roots = [
|
|
8400
|
+
entrypoint.bootstrapFile,
|
|
8401
|
+
entrypoint.pageFile,
|
|
8402
|
+
...entrypoint.layoutFiles
|
|
8403
|
+
].filter((file) => Boolean(file)).map((file) => path.join(root, file));
|
|
8404
|
+
const queue = [...new Set(roots)];
|
|
8405
|
+
const visited = /* @__PURE__ */ new Set();
|
|
8406
|
+
const modules = [];
|
|
8407
|
+
const unresolvedImports = [];
|
|
8408
|
+
const external = /* @__PURE__ */ new Map();
|
|
8409
|
+
while (queue.length) {
|
|
8410
|
+
const absoluteFile = path.resolve(queue.shift());
|
|
8411
|
+
if (visited.has(absoluteFile) || !await exists(absoluteFile)) continue;
|
|
8412
|
+
visited.add(absoluteFile);
|
|
8413
|
+
const kind = extensionKind(absoluteFile);
|
|
8414
|
+
if (!kind) continue;
|
|
8415
|
+
const relativeFile = portable$4(path.relative(root, absoluteFile));
|
|
8416
|
+
const dependencies = [];
|
|
8417
|
+
let business = /(?:^|\/)(?:api|auth|checkout|cart|carrinho|store|services?)(?:\/|\.)/i.test(relativeFile);
|
|
8418
|
+
let visual = kind === "STYLE" || kind === "ASSET";
|
|
8419
|
+
if (kind === "SOURCE") {
|
|
8420
|
+
const content = await readFile(absoluteFile, "utf8");
|
|
8421
|
+
const source = sourceFile(absoluteFile, content);
|
|
8422
|
+
visual = /<\s*[A-Za-z][\w.]*(?:\s|\/?>)/.test(content);
|
|
8423
|
+
for (const item of moduleSpecifiers(source)) {
|
|
8424
|
+
const resolvedFile = resolver.resolve(absoluteFile, item.specifier);
|
|
8425
|
+
const type = classifyDependency(item.specifier, resolvedFile);
|
|
8426
|
+
const isExternal = !resolvedFile;
|
|
8427
|
+
dependencies.push({
|
|
8428
|
+
specifier: item.specifier,
|
|
8429
|
+
resolvedFile,
|
|
8430
|
+
type,
|
|
8431
|
+
external: isExternal,
|
|
8432
|
+
dynamic: item.dynamic
|
|
8433
|
+
});
|
|
8434
|
+
if (resolvedFile) {
|
|
8435
|
+
if (!visited.has(resolvedFile)) queue.push(resolvedFile);
|
|
8436
|
+
continue;
|
|
8437
|
+
}
|
|
8438
|
+
if (localLooking(item.specifier)) {
|
|
8439
|
+
unresolvedImports.push({
|
|
8440
|
+
importer: relativeFile,
|
|
8441
|
+
specifier: item.specifier
|
|
8442
|
+
});
|
|
8443
|
+
continue;
|
|
8444
|
+
}
|
|
8445
|
+
const packageName = packageNameOf(item.specifier);
|
|
8446
|
+
if (!packageName || packageName === "react" || packageName === "react-dom" || packageName === "react/jsx-runtime") continue;
|
|
8447
|
+
const dependency = external.get(packageName) ?? {
|
|
8448
|
+
specifier: item.specifier,
|
|
8449
|
+
packageName,
|
|
8450
|
+
type,
|
|
8451
|
+
resolvedFile: null,
|
|
8452
|
+
importedBy: []
|
|
8453
|
+
};
|
|
8454
|
+
if (!dependency.importedBy.includes(relativeFile)) dependency.importedBy.push(relativeFile);
|
|
8455
|
+
if (type === "BUSINESS") dependency.type = "BUSINESS";
|
|
8456
|
+
external.set(packageName, dependency);
|
|
8457
|
+
if (type === "BUSINESS") business = true;
|
|
8458
|
+
if (type === "VISUAL") visual = true;
|
|
8459
|
+
}
|
|
8460
|
+
}
|
|
8461
|
+
modules.push({
|
|
8462
|
+
file: relativeFile,
|
|
8463
|
+
absolutePath: absoluteFile,
|
|
8464
|
+
kind,
|
|
8465
|
+
dependencies,
|
|
8466
|
+
business,
|
|
8467
|
+
visual
|
|
8468
|
+
});
|
|
8469
|
+
}
|
|
8470
|
+
return {
|
|
8471
|
+
entrypoint,
|
|
8472
|
+
modules,
|
|
8473
|
+
dependencies: [...external.values()].sort((left, right) => (left.packageName ?? "").localeCompare(right.packageName ?? "")),
|
|
8474
|
+
unresolvedImports
|
|
8475
|
+
};
|
|
8476
|
+
}
|
|
8477
|
+
//#endregion
|
|
7906
8478
|
//#region src/migrate/analyzer.ts
|
|
7907
8479
|
var IGNORED_DIRECTORIES$1 = /* @__PURE__ */ new Set([
|
|
7908
8480
|
".git",
|
|
@@ -7944,7 +8516,7 @@ var ASSET_EXTENSIONS = /* @__PURE__ */ new Set([
|
|
|
7944
8516
|
]);
|
|
7945
8517
|
var MAX_SOURCE_FILES = 2e3;
|
|
7946
8518
|
var MAX_SOURCE_BYTES = 2097152;
|
|
7947
|
-
function portable$
|
|
8519
|
+
function portable$3(file) {
|
|
7948
8520
|
return file.split(path.sep).join("/");
|
|
7949
8521
|
}
|
|
7950
8522
|
function inside$1(root, candidate) {
|
|
@@ -8087,6 +8659,16 @@ function jsxAttributes(node) {
|
|
|
8087
8659
|
function analyzeJsx(root) {
|
|
8088
8660
|
const result = [];
|
|
8089
8661
|
function visit(node, depth) {
|
|
8662
|
+
if (ts.isJsxExpression(node) && !node.expression) {
|
|
8663
|
+
const commentedComponent = node.getText().match(/<([A-Z][A-Za-z0-9_$]*)\b[^>]*\/>/);
|
|
8664
|
+
if (commentedComponent) result.push({
|
|
8665
|
+
tag: commentedComponent[1],
|
|
8666
|
+
depth,
|
|
8667
|
+
classes: [],
|
|
8668
|
+
text: [],
|
|
8669
|
+
attributes: []
|
|
8670
|
+
});
|
|
8671
|
+
}
|
|
8090
8672
|
if (ts.isJsxElement(node) || ts.isJsxSelfClosingElement(node)) {
|
|
8091
8673
|
const attributes = jsxAttributes(node);
|
|
8092
8674
|
const text = [];
|
|
@@ -8121,6 +8703,74 @@ function containsJsx(node) {
|
|
|
8121
8703
|
visit(node);
|
|
8122
8704
|
return found;
|
|
8123
8705
|
}
|
|
8706
|
+
var PRESENTATION_FIELD = /^(?:icon|icons|color|colour|class|className|style|variant|layout|position|align|alignment|size|dot|shape|theme)$/i;
|
|
8707
|
+
function componentContentLists(node, source) {
|
|
8708
|
+
const declarations = /* @__PURE__ */ new Map();
|
|
8709
|
+
const candidates = [];
|
|
8710
|
+
const seenArrays = /* @__PURE__ */ new Set();
|
|
8711
|
+
function unwrap(expression) {
|
|
8712
|
+
if (ts.isAsExpression(expression) || ts.isTypeAssertionExpression(expression) || ts.isParenthesizedExpression(expression)) return unwrap(expression.expression);
|
|
8713
|
+
return expression;
|
|
8714
|
+
}
|
|
8715
|
+
function propertyName(name) {
|
|
8716
|
+
return ts.isIdentifier(name) || ts.isStringLiteralLike(name) || ts.isNumericLiteral(name) ? name.text : null;
|
|
8717
|
+
}
|
|
8718
|
+
function collect(child) {
|
|
8719
|
+
if (ts.isVariableDeclaration(child) && ts.isIdentifier(child.name) && child.initializer) {
|
|
8720
|
+
const initializer = unwrap(child.initializer);
|
|
8721
|
+
if (ts.isArrayLiteralExpression(initializer)) declarations.set(child.name.text, initializer);
|
|
8722
|
+
}
|
|
8723
|
+
ts.forEachChild(child, collect);
|
|
8724
|
+
}
|
|
8725
|
+
collect(source);
|
|
8726
|
+
function findMaps(child) {
|
|
8727
|
+
if (ts.isCallExpression(child) && ts.isPropertyAccessExpression(child.expression) && child.expression.name.text === "map") {
|
|
8728
|
+
const receiver = unwrap(child.expression.expression);
|
|
8729
|
+
const sourceName = ts.isIdentifier(receiver) ? receiver.text : null;
|
|
8730
|
+
const array = ts.isArrayLiteralExpression(receiver) ? receiver : sourceName ? declarations.get(sourceName) : void 0;
|
|
8731
|
+
if (array && !seenArrays.has(array.pos)) {
|
|
8732
|
+
seenArrays.add(array.pos);
|
|
8733
|
+
candidates.push({
|
|
8734
|
+
sourceName,
|
|
8735
|
+
array
|
|
8736
|
+
});
|
|
8737
|
+
}
|
|
8738
|
+
}
|
|
8739
|
+
ts.forEachChild(child, findMaps);
|
|
8740
|
+
}
|
|
8741
|
+
if (node.body) findMaps(node.body);
|
|
8742
|
+
let inlineIndex = 0;
|
|
8743
|
+
return candidates.flatMap(({ sourceName, array }) => {
|
|
8744
|
+
const fields = /* @__PURE__ */ new Set();
|
|
8745
|
+
const presentationFields = /* @__PURE__ */ new Set();
|
|
8746
|
+
let primitive = false;
|
|
8747
|
+
for (const element of array.elements) {
|
|
8748
|
+
const value = ts.isExpression(element) ? unwrap(element) : null;
|
|
8749
|
+
if (!value) continue;
|
|
8750
|
+
if (ts.isStringLiteralLike(value) || ts.isNoSubstitutionTemplateLiteral(value) || ts.isNumericLiteral(value)) {
|
|
8751
|
+
primitive = true;
|
|
8752
|
+
continue;
|
|
8753
|
+
}
|
|
8754
|
+
if (!ts.isObjectLiteralExpression(value)) continue;
|
|
8755
|
+
for (const property of value.properties) {
|
|
8756
|
+
if (!ts.isPropertyAssignment(property) && !ts.isShorthandPropertyAssignment(property)) continue;
|
|
8757
|
+
const name = propertyName(property.name);
|
|
8758
|
+
if (!name) continue;
|
|
8759
|
+
if (PRESENTATION_FIELD.test(name)) presentationFields.add(name);
|
|
8760
|
+
else fields.add(name);
|
|
8761
|
+
}
|
|
8762
|
+
}
|
|
8763
|
+
if (!primitive && !fields.size) return [];
|
|
8764
|
+
const fallbackKey = inlineIndex++ === 0 ? "items" : `items${inlineIndex}`;
|
|
8765
|
+
return [{
|
|
8766
|
+
sourceName,
|
|
8767
|
+
fieldKey: sourceName && /^[a-z][a-zA-Z0-9-]{0,63}$/.test(sourceName) ? sourceName : fallbackKey,
|
|
8768
|
+
itemFields: primitive ? ["title"] : [...fields].slice(0, 30),
|
|
8769
|
+
primitive,
|
|
8770
|
+
presentationFields: [...presentationFields]
|
|
8771
|
+
}];
|
|
8772
|
+
});
|
|
8773
|
+
}
|
|
8124
8774
|
function componentNodes(source) {
|
|
8125
8775
|
const result = [];
|
|
8126
8776
|
const defaultNames = /* @__PURE__ */ new Set();
|
|
@@ -8251,7 +8901,7 @@ async function analyzeComponentFile(absoluteFile, sourceDirectory, framework) {
|
|
|
8251
8901
|
const content = await readFile(absoluteFile, "utf8");
|
|
8252
8902
|
const source = ts.createSourceFile(absoluteFile, content, ts.ScriptTarget.Latest, true, ts.ScriptKind.TSX);
|
|
8253
8903
|
const imports = importsOf(source);
|
|
8254
|
-
const relativeFile = portable$
|
|
8904
|
+
const relativeFile = portable$3(path.relative(sourceDirectory, absoluteFile));
|
|
8255
8905
|
const styles = [];
|
|
8256
8906
|
const assets = [];
|
|
8257
8907
|
for (const item of imports) {
|
|
@@ -8282,11 +8932,12 @@ async function analyzeComponentFile(absoluteFile, sourceDirectory, framework) {
|
|
|
8282
8932
|
page: pageFile(relativeFile, framework),
|
|
8283
8933
|
line: source.getLineAndCharacterOfPosition(node.getStart(source)).line + 1,
|
|
8284
8934
|
imports,
|
|
8285
|
-
styleImports: styles.map((file) => portable$
|
|
8286
|
-
assetImports: assets.map((file) => portable$
|
|
8935
|
+
styleImports: styles.map((file) => portable$3(path.relative(sourceDirectory, file))),
|
|
8936
|
+
assetImports: assets.map((file) => portable$3(path.relative(sourceDirectory, file))),
|
|
8287
8937
|
jsx,
|
|
8288
8938
|
rootClasses: jsx.find(({ depth }) => depth === 0)?.classes ?? jsx[0]?.classes ?? [],
|
|
8289
8939
|
text: [...new Set(jsx.flatMap((item) => item.text))].slice(0, 30),
|
|
8940
|
+
contentLists: componentContentLists(node, source),
|
|
8290
8941
|
businessSignals: signals,
|
|
8291
8942
|
roles: []
|
|
8292
8943
|
};
|
|
@@ -8332,8 +8983,8 @@ function tailwindAnalysis(files, dependencies, sourceDirectory) {
|
|
|
8332
8983
|
detected: Boolean(version || config),
|
|
8333
8984
|
version,
|
|
8334
8985
|
major: match ? Number(match[1]) : null,
|
|
8335
|
-
configFile: config ? portable$
|
|
8336
|
-
postcssFile: postcss ? portable$
|
|
8986
|
+
configFile: config ? portable$3(path.relative(sourceDirectory, config)) : null,
|
|
8987
|
+
postcssFile: postcss ? portable$3(path.relative(sourceDirectory, postcss)) : null,
|
|
8337
8988
|
colors: tailwindColors(config)
|
|
8338
8989
|
};
|
|
8339
8990
|
}
|
|
@@ -8346,7 +8997,7 @@ function addAsset(target, absolutePath, sourceDirectory, referencedBy) {
|
|
|
8346
8997
|
return;
|
|
8347
8998
|
}
|
|
8348
8999
|
target.set(key, {
|
|
8349
|
-
file: portable$
|
|
9000
|
+
file: portable$3(path.relative(sourceDirectory, key)),
|
|
8350
9001
|
absolutePath: key,
|
|
8351
9002
|
kind: assetKind(path.extname(key).toLowerCase()),
|
|
8352
9003
|
referencedBy: [referencedBy]
|
|
@@ -8387,7 +9038,7 @@ async function analyzeReactProject(inputDirectory) {
|
|
|
8387
9038
|
const analyzed = await analyzeComponentFile(file, sourceDirectory, framework);
|
|
8388
9039
|
components.push(...analyzed.components);
|
|
8389
9040
|
analyzed.styles.forEach((style) => referencedStyles.add(path.resolve(style)));
|
|
8390
|
-
analyzed.assets.forEach((asset) => addAsset(assetMap, asset, sourceDirectory, portable$
|
|
9041
|
+
analyzed.assets.forEach((asset) => addAsset(assetMap, asset, sourceDirectory, portable$3(path.relative(sourceDirectory, file))));
|
|
8391
9042
|
}
|
|
8392
9043
|
for (const file of files.filter((candidate) => candidate.endsWith(".ts") && !candidate.endsWith(".d.ts"))) {
|
|
8393
9044
|
if ((await stat(file)).size > MAX_SOURCE_BYTES) continue;
|
|
@@ -8396,7 +9047,7 @@ async function analyzeReactProject(inputDirectory) {
|
|
|
8396
9047
|
const signals = businessSignals(source, importsOf(source));
|
|
8397
9048
|
if (!signals.length) continue;
|
|
8398
9049
|
ignoredFiles.push({
|
|
8399
|
-
file: portable$
|
|
9050
|
+
file: portable$3(path.relative(sourceDirectory, file)),
|
|
8400
9051
|
reason: signals.join(", ")
|
|
8401
9052
|
});
|
|
8402
9053
|
}
|
|
@@ -8404,7 +9055,7 @@ async function analyzeReactProject(inputDirectory) {
|
|
|
8404
9055
|
for (const file of files.filter((candidate) => STYLE_EXTENSIONS.has(path.extname(candidate).toLowerCase()))) {
|
|
8405
9056
|
const content = await readFile(file, "utf8");
|
|
8406
9057
|
colorLiterals(content).forEach((color) => detectedColors.add(color));
|
|
8407
|
-
const relativeFile = portable$
|
|
9058
|
+
const relativeFile = portable$3(path.relative(sourceDirectory, file));
|
|
8408
9059
|
styles.push({
|
|
8409
9060
|
file: relativeFile,
|
|
8410
9061
|
absolutePath: file,
|
|
@@ -8427,9 +9078,12 @@ async function analyzeReactProject(inputDirectory) {
|
|
|
8427
9078
|
}
|
|
8428
9079
|
}
|
|
8429
9080
|
}
|
|
9081
|
+
const projectName = typeof packageJson.name === "string" && packageJson.name.trim() ? packageJson.name.trim() : path.basename(sourceDirectory);
|
|
9082
|
+
const sourceGraph = await buildSourceDependencyGraph(sourceDirectory, framework);
|
|
9083
|
+
const graphWarnings = sourceGraph.entrypoint ? sourceGraph.unresolvedImports.map(({ importer, specifier }) => `${importer}: import local não resolvido (${specifier}).`) : ["Entrypoint visual da Home não identificado; será usado o adaptador estrutural legado."];
|
|
8430
9084
|
return {
|
|
8431
9085
|
sourceDirectory,
|
|
8432
|
-
projectName
|
|
9086
|
+
projectName,
|
|
8433
9087
|
framework,
|
|
8434
9088
|
sourceRoots: detectSourceRoots(sourceDirectory, files),
|
|
8435
9089
|
packageJson,
|
|
@@ -8440,7 +9094,8 @@ async function analyzeReactProject(inputDirectory) {
|
|
|
8440
9094
|
tailwind: tailwindAnalysis(files, dependencies, sourceDirectory),
|
|
8441
9095
|
colorLiterals: [...detectedColors],
|
|
8442
9096
|
ignoredFiles,
|
|
8443
|
-
warnings: styles.some(({ file }) => /\.(?:scss|sass|less)$/.test(file)) ? ["
|
|
9097
|
+
warnings: [...styles.some(({ file }) => /\.(?:scss|sass|less)$/.test(file)) ? ["Sass/Less detectado: os arquivos alcançáveis serão preservados, mas exigem o compilador correspondente no tema."] : [], ...graphWarnings],
|
|
9098
|
+
sourceGraph
|
|
8444
9099
|
};
|
|
8445
9100
|
}
|
|
8446
9101
|
//#endregion
|
|
@@ -8654,16 +9309,16 @@ function classifyProject(input) {
|
|
|
8654
9309
|
}
|
|
8655
9310
|
//#endregion
|
|
8656
9311
|
//#region src/migrate/asset-copier.ts
|
|
8657
|
-
function portable$
|
|
9312
|
+
function portable$2(file) {
|
|
8658
9313
|
return file.split(path.sep).join("/");
|
|
8659
9314
|
}
|
|
8660
9315
|
function safeRelative(file) {
|
|
8661
|
-
return portable$
|
|
9316
|
+
return portable$2(file).split("/").filter((part) => part && part !== "." && part !== "..").map((part) => part.replace(/[^a-zA-Z0-9._-]/g, "-")).join("/");
|
|
8662
9317
|
}
|
|
8663
|
-
async function copyMigrationAssets(plan, outputDirectory) {
|
|
9318
|
+
async function copyMigrationAssets(plan, outputDirectory, assets = plan.assets) {
|
|
8664
9319
|
const copied = [];
|
|
8665
9320
|
const destinationRoot = path.join(outputDirectory, "src", "assets");
|
|
8666
|
-
for (const asset of
|
|
9321
|
+
for (const asset of assets) {
|
|
8667
9322
|
try {
|
|
8668
9323
|
if (!(await stat(asset.absolutePath)).isFile()) continue;
|
|
8669
9324
|
} catch {
|
|
@@ -8678,118 +9333,752 @@ async function copyMigrationAssets(plan, outputDirectory) {
|
|
|
8678
9333
|
copied.push({
|
|
8679
9334
|
sourceFile: asset.absolutePath,
|
|
8680
9335
|
outputFile: destination,
|
|
8681
|
-
importPath: `../assets/${portable$
|
|
9336
|
+
importPath: `../assets/${portable$2(relative)}`,
|
|
8682
9337
|
kind: asset.kind
|
|
8683
9338
|
});
|
|
8684
9339
|
}
|
|
8685
9340
|
return copied;
|
|
8686
9341
|
}
|
|
8687
9342
|
//#endregion
|
|
8688
|
-
//#region src/migrate/
|
|
8689
|
-
function portable(file) {
|
|
9343
|
+
//#region src/migrate/transform/source-transformer.ts
|
|
9344
|
+
function portable$1(file) {
|
|
8690
9345
|
return file.split(path.sep).join("/");
|
|
8691
9346
|
}
|
|
8692
|
-
function
|
|
8693
|
-
|
|
8694
|
-
|
|
8695
|
-
|
|
8696
|
-
return plan.selected[role]?.classes ?? {
|
|
8697
|
-
root: "",
|
|
8698
|
-
brand: "",
|
|
8699
|
-
navigation: "",
|
|
8700
|
-
title: "",
|
|
8701
|
-
text: "",
|
|
8702
|
-
action: "",
|
|
8703
|
-
media: "",
|
|
8704
|
-
grid: "",
|
|
8705
|
-
card: "",
|
|
8706
|
-
content: ""
|
|
8707
|
-
};
|
|
8708
|
-
}
|
|
8709
|
-
function sourceText(plan, role, fallback) {
|
|
8710
|
-
return plan.selected[role]?.component.text.find((candidate) => candidate.length >= 3 && candidate.length <= 140) || fallback;
|
|
8711
|
-
}
|
|
8712
|
-
function headerSource(plan) {
|
|
8713
|
-
const style = profile(plan, "HEADER");
|
|
8714
|
-
return `import type { HeaderProps } from "@nuvler/theme-sdk";
|
|
8715
|
-
|
|
8716
|
-
export function Header({ site, categories, pages }: HeaderProps) {
|
|
8717
|
-
const name = site.settings?.siteName || site.tenant.name;
|
|
8718
|
-
return <header className=${classes("nuvler-migrated-header", style.root)}>
|
|
8719
|
-
<div className=${classes("nuvler-migrated-header-inner", style.content)}>
|
|
8720
|
-
<a className=${classes("nuvler-migrated-brand", style.brand)} href="/">
|
|
8721
|
-
{site.settings?.logo?.url ? <img src={site.settings.logo.url} alt={site.settings.logo.alt || name} /> : <span>{name}</span>}
|
|
8722
|
-
</a>
|
|
8723
|
-
<nav className=${classes("nuvler-migrated-nav", style.navigation)} aria-label="Navegação principal">
|
|
8724
|
-
<a href="/">Início</a>
|
|
8725
|
-
{site.modules.includes("PRODUCTS") && <a href="/produtos">Produtos</a>}
|
|
8726
|
-
{categories.slice(0, 6).map((category) => <a href={\`/\${category.slug}\`} key={category.slug}>{category.name}</a>)}
|
|
8727
|
-
{pages.slice(0, 4).map((page) => <a href={\`/\${page.slug}\`} key={page.slug}>{page.title}</a>)}
|
|
8728
|
-
</nav>
|
|
8729
|
-
{site.modules.includes("PRODUCTS") && <form className="nuvler-migrated-search" action="/produtos">
|
|
8730
|
-
<input name="busca" type="search" placeholder="Buscar produtos" />
|
|
8731
|
-
<button className=${classes("nuvler-migrated-action", style.action)} type="submit">Buscar</button>
|
|
8732
|
-
</form>}
|
|
8733
|
-
</div>
|
|
8734
|
-
</header>;
|
|
8735
|
-
}
|
|
8736
|
-
`;
|
|
8737
|
-
}
|
|
8738
|
-
function footerSource(plan) {
|
|
8739
|
-
const style = profile(plan, "FOOTER");
|
|
8740
|
-
return `import type { FooterProps } from "@nuvler/theme-sdk";
|
|
8741
|
-
|
|
8742
|
-
export function Footer({ site, pages, template }: FooterProps) {
|
|
8743
|
-
const name = site.settings?.siteName || site.tenant.name;
|
|
8744
|
-
return <footer className=${classes("nuvler-migrated-footer", style.root)}>
|
|
8745
|
-
<div className=${classes("nuvler-migrated-footer-inner", style.content)}>
|
|
8746
|
-
<div><strong className=${classes("nuvler-migrated-footer-brand", style.brand)}>{name}</strong><p className=${classes("nuvler-migrated-copy", style.text)}>{site.settings?.description || template.footerTagline}</p></div>
|
|
8747
|
-
<nav className=${classes("nuvler-migrated-footer-nav", style.navigation)} aria-label={template.footerNavigationLabel}>
|
|
8748
|
-
<a href="/">Início</a>
|
|
8749
|
-
{site.modules.includes("PRODUCTS") && <a href="/produtos">Produtos</a>}
|
|
8750
|
-
{pages.map((page) => <a href={\`/\${page.slug}\`} key={page.slug}>{page.title}</a>)}
|
|
8751
|
-
</nav>
|
|
8752
|
-
<div className="nuvler-migrated-contact">
|
|
8753
|
-
{site.settings?.contact.phone && <a href={\`tel:\${site.settings.contact.phone}\`}>{site.settings.contact.phone}</a>}
|
|
8754
|
-
{site.settings?.contact.email && <a href={\`mailto:\${site.settings.contact.email}\`}>{site.settings.contact.email}</a>}
|
|
8755
|
-
</div>
|
|
8756
|
-
</div>
|
|
8757
|
-
<small>{template.footerNote}</small>
|
|
8758
|
-
</footer>;
|
|
8759
|
-
}
|
|
8760
|
-
`;
|
|
8761
|
-
}
|
|
8762
|
-
function productCardSource(plan) {
|
|
8763
|
-
const style = profile(plan, "PRODUCT_CARD");
|
|
8764
|
-
return `import { productUrl, type ThemeProduct } from "@nuvler/theme-sdk";
|
|
8765
|
-
|
|
8766
|
-
function money(value: number | null): string {
|
|
8767
|
-
return value === null ? "Consulte" : new Intl.NumberFormat("pt-BR", { style: "currency", currency: "BRL" }).format(value);
|
|
9347
|
+
function relativeImport(fromFile, toFile) {
|
|
9348
|
+
let relative = portable$1(path.relative(path.dirname(fromFile), toFile));
|
|
9349
|
+
if (/\.(?:tsx?|jsx?|mts|cts)$/i.test(relative)) relative = relative.replace(/\.(?:tsx?|jsx?|mts|cts)$/i, "");
|
|
9350
|
+
return relative.startsWith(".") ? relative : `./${relative}`;
|
|
8768
9351
|
}
|
|
8769
|
-
|
|
8770
|
-
|
|
8771
|
-
const price = product.promotionalPrice ?? product.price;
|
|
8772
|
-
const href = productUrl(product);
|
|
8773
|
-
return <article className=${classes("nuvler-migrated-product-card", style.root || style.card)}>
|
|
8774
|
-
<a className=${classes("nuvler-migrated-product-media", style.media)} href={href}>
|
|
8775
|
-
{product.image?.url ? <img src={product.image.url} alt={product.image.alt || product.title} /> : <span aria-hidden="true" />}
|
|
8776
|
-
</a>
|
|
8777
|
-
<div className=${classes("nuvler-migrated-product-content", style.content)}>
|
|
8778
|
-
{showCategory && <small>{product.categories[0]?.name || product.brand || "Produto"}</small>}
|
|
8779
|
-
<h3 className=${classes("nuvler-migrated-product-title", style.title)}><a href={href}>{product.title}</a></h3>
|
|
8780
|
-
{showDescription && product.description && <p className=${classes("nuvler-migrated-copy", style.text)}>{product.description}</p>}
|
|
8781
|
-
<strong>{money(price)}</strong>
|
|
8782
|
-
<a className=${classes("nuvler-migrated-action", style.action)} href={href}>Ver produto</a>
|
|
8783
|
-
</div>
|
|
8784
|
-
</article>;
|
|
9352
|
+
function applyEdits(content, edits) {
|
|
9353
|
+
return edits.sort((left, right) => right.start - left.start).reduce((result, edit) => `${result.slice(0, edit.start)}${edit.text}${result.slice(edit.end)}`, content);
|
|
8785
9354
|
}
|
|
8786
|
-
|
|
9355
|
+
function scriptKind(file) {
|
|
9356
|
+
const extension = path.extname(file).toLowerCase();
|
|
9357
|
+
if (extension === ".tsx") return ts.ScriptKind.TSX;
|
|
9358
|
+
if (extension === ".jsx") return ts.ScriptKind.JSX;
|
|
9359
|
+
if ([
|
|
9360
|
+
".js",
|
|
9361
|
+
".mjs",
|
|
9362
|
+
".cjs"
|
|
9363
|
+
].includes(extension)) return ts.ScriptKind.JS;
|
|
9364
|
+
return ts.ScriptKind.TS;
|
|
9365
|
+
}
|
|
9366
|
+
function unwrappedExpression$1(expression) {
|
|
9367
|
+
if (ts.isAsExpression(expression) || ts.isTypeAssertionExpression(expression) || ts.isParenthesizedExpression(expression)) return unwrappedExpression$1(expression.expression);
|
|
9368
|
+
return expression;
|
|
9369
|
+
}
|
|
9370
|
+
function moduleLiteral(node) {
|
|
9371
|
+
if ((ts.isImportDeclaration(node) || ts.isExportDeclaration(node)) && node.moduleSpecifier && ts.isStringLiteralLike(node.moduleSpecifier)) return node.moduleSpecifier;
|
|
9372
|
+
if (ts.isCallExpression(node) && node.expression.kind === ts.SyntaxKind.ImportKeyword) {
|
|
9373
|
+
const argument = node.arguments[0];
|
|
9374
|
+
return argument && ts.isStringLiteralLike(argument) ? argument : null;
|
|
9375
|
+
}
|
|
9376
|
+
return null;
|
|
8787
9377
|
}
|
|
8788
|
-
function
|
|
8789
|
-
const
|
|
8790
|
-
|
|
8791
|
-
|
|
8792
|
-
|
|
9378
|
+
function transformMigratedSource(module, content, graph, destinationFile, destinationBySource, options = {}) {
|
|
9379
|
+
const source = ts.createSourceFile(module.absolutePath, content, ts.ScriptTarget.Latest, true, scriptKind(module.absolutePath));
|
|
9380
|
+
const edits = [];
|
|
9381
|
+
const dependencyBySpecifier = new Map(module.dependencies.map((dependency) => [dependency.specifier, dependency]));
|
|
9382
|
+
const contentByComponent = new Map((options.content ?? []).map((item) => [item.componentName, item]));
|
|
9383
|
+
const removedComponents = new Set(options.removeComponents ?? []);
|
|
9384
|
+
function componentName(node) {
|
|
9385
|
+
if ("name" in node && node.name && ts.isIdentifier(node.name)) return node.name.text;
|
|
9386
|
+
const parent = node.parent;
|
|
9387
|
+
return ts.isVariableDeclaration(parent) && ts.isIdentifier(parent.name) ? parent.name.text : null;
|
|
9388
|
+
}
|
|
9389
|
+
function mappedField(key) {
|
|
9390
|
+
const normalized = key.toLowerCase();
|
|
9391
|
+
const parts = normalized.split(".");
|
|
9392
|
+
const last = parts.at(-1) ?? normalized;
|
|
9393
|
+
if (/(?:^|\.)(?:eyebrow|overline|kicker)$/.test(normalized)) return "eyebrow";
|
|
9394
|
+
if (["headline", "title"].includes(last) && parts.length <= 2) return "title";
|
|
9395
|
+
if ([
|
|
9396
|
+
"subtitle",
|
|
9397
|
+
"subheadline",
|
|
9398
|
+
"description",
|
|
9399
|
+
"desc",
|
|
9400
|
+
"text",
|
|
9401
|
+
"rights"
|
|
9402
|
+
].includes(last) && parts.length <= 2) return "description";
|
|
9403
|
+
if (/(?:^|\.)(?:cta|button|action|login)(?:\.|$)/.test(normalized)) return "buttonLabel";
|
|
9404
|
+
return null;
|
|
9405
|
+
}
|
|
9406
|
+
function adaptFunction(node, adaptation) {
|
|
9407
|
+
if (!node.body || !ts.isBlock(node.body)) return;
|
|
9408
|
+
const { bindingId, componentKey, contentLists = [] } = adaptation;
|
|
9409
|
+
const hookName = "__nuvlerSection";
|
|
9410
|
+
const mapped = /* @__PURE__ */ new Set();
|
|
9411
|
+
const adaptedItemArrays = /* @__PURE__ */ new Set();
|
|
9412
|
+
function presentationItems(expression) {
|
|
9413
|
+
const array = unwrappedExpression$1(expression);
|
|
9414
|
+
if (!ts.isArrayLiteralExpression(array)) return null;
|
|
9415
|
+
let hasPresentation = false;
|
|
9416
|
+
const items = array.elements.map((element) => {
|
|
9417
|
+
const item = unwrappedExpression$1(element);
|
|
9418
|
+
if (!ts.isObjectLiteralExpression(item)) return "{}";
|
|
9419
|
+
return `{ ${item.properties.flatMap((property) => {
|
|
9420
|
+
if (ts.isShorthandPropertyAssignment(property)) {
|
|
9421
|
+
if (!/^(?:icon|icons|color|colour|class|className|style|variant|layout|position|align|alignment|size|dot|shape|theme)$/i.test(property.name.text)) return [];
|
|
9422
|
+
hasPresentation = true;
|
|
9423
|
+
return [property.getText(source)];
|
|
9424
|
+
}
|
|
9425
|
+
if (!ts.isPropertyAssignment(property)) return [];
|
|
9426
|
+
const name = property.name.getText(source).replace(/^["']|["']$/g, "");
|
|
9427
|
+
if (!/^(?:icon|icons|color|colour|class|className|style|variant|layout|position|align|alignment|size|dot|shape|theme)$/i.test(name)) return [];
|
|
9428
|
+
hasPresentation = true;
|
|
9429
|
+
return [property.getText(source)];
|
|
9430
|
+
}).join(", ")} }`;
|
|
9431
|
+
});
|
|
9432
|
+
return hasPresentation ? `[${items.join(", ")}]` : null;
|
|
9433
|
+
}
|
|
9434
|
+
function findMapped(child) {
|
|
9435
|
+
if (ts.isCallExpression(child) && ts.isIdentifier(child.expression) && child.expression.text === "t" && child.arguments[0] && ts.isStringLiteralLike(child.arguments[0])) {
|
|
9436
|
+
const field = mappedField(child.arguments[0].text);
|
|
9437
|
+
if (field) mapped.add(field);
|
|
9438
|
+
}
|
|
9439
|
+
ts.forEachChild(child, findMapped);
|
|
9440
|
+
}
|
|
9441
|
+
findMapped(node.body);
|
|
9442
|
+
const fallbackUsed = new Set(mapped);
|
|
9443
|
+
const literalFieldsUsed = new Set(mapped);
|
|
9444
|
+
edits.push({
|
|
9445
|
+
start: node.body.getStart(source) + 1,
|
|
9446
|
+
end: node.body.getStart(source) + 1,
|
|
9447
|
+
text: `\n const ${hookName} = useMigratedSection(${JSON.stringify(bindingId)});${componentKey === "contact-form" ? `\n const __nuvlerSubmitContact = useMigratedContactForm(${JSON.stringify(bindingId)});` : ""}`
|
|
9448
|
+
});
|
|
9449
|
+
function adapt(child) {
|
|
9450
|
+
function jsxField(parent, literal = "") {
|
|
9451
|
+
if (!ts.isJsxElement(parent)) return null;
|
|
9452
|
+
const tag = parent.openingElement.tagName.getText(source).toLowerCase();
|
|
9453
|
+
let field = null;
|
|
9454
|
+
if (/^h[1-6]$/.test(tag)) field = "title";
|
|
9455
|
+
else if (tag === "p" || tag === "blockquote") field = "description";
|
|
9456
|
+
else if (tag === "a" || tag === "button") field = "buttonLabel";
|
|
9457
|
+
else if (tag === "span" || tag === "small") field = "eyebrow";
|
|
9458
|
+
else if (tag === "div" && literal.trim().length <= 100 && literal.trim() === literal.trim().toLocaleUpperCase("pt-BR") && /[A-ZÀ-Ü]/.test(literal)) field = "eyebrow";
|
|
9459
|
+
if (!field || literalFieldsUsed.has(field)) return null;
|
|
9460
|
+
literalFieldsUsed.add(field);
|
|
9461
|
+
return field;
|
|
9462
|
+
}
|
|
9463
|
+
if (componentKey === "contact-form" && ts.isJsxElement(child) && child.openingElement.tagName.getText(source).toLowerCase() === "form") {
|
|
9464
|
+
const submit = child.openingElement.attributes.properties.find((attribute) => ts.isJsxAttribute(attribute) && attribute.name.getText(source) === "onSubmit");
|
|
9465
|
+
if (submit?.initializer) edits.push({
|
|
9466
|
+
start: submit.initializer.getStart(source),
|
|
9467
|
+
end: submit.initializer.getEnd(),
|
|
9468
|
+
text: "{__nuvlerSubmitContact}"
|
|
9469
|
+
});
|
|
9470
|
+
else if (!submit) edits.push({
|
|
9471
|
+
start: child.openingElement.tagName.getEnd(),
|
|
9472
|
+
end: child.openingElement.tagName.getEnd(),
|
|
9473
|
+
text: " onSubmit={__nuvlerSubmitContact}"
|
|
9474
|
+
});
|
|
9475
|
+
edits.push({
|
|
9476
|
+
start: child.openingElement.getEnd(),
|
|
9477
|
+
end: child.closingElement.getStart(source),
|
|
9478
|
+
text: `\n <MigratedContactFields data={${hookName}} />\n `
|
|
9479
|
+
});
|
|
9480
|
+
return;
|
|
9481
|
+
}
|
|
9482
|
+
if (ts.isVariableDeclaration(child) && ts.isIdentifier(child.name) && child.initializer && ts.isArrayLiteralExpression(unwrappedExpression$1(child.initializer))) {
|
|
9483
|
+
const sourceName = child.name.text;
|
|
9484
|
+
const list = contentLists.find((candidate) => candidate.sourceName === sourceName);
|
|
9485
|
+
if (!list) {
|
|
9486
|
+
ts.forEachChild(child, adapt);
|
|
9487
|
+
return;
|
|
9488
|
+
}
|
|
9489
|
+
const presentation = presentationItems(child.initializer);
|
|
9490
|
+
adaptedItemArrays.add(sourceName);
|
|
9491
|
+
const configured = presentation ? `migratedItems(${hookName}, ${JSON.stringify(list.fieldKey)}, ${presentation})` : `migratedItems(${hookName}, ${JSON.stringify(list.fieldKey)})`;
|
|
9492
|
+
edits.push({
|
|
9493
|
+
start: child.initializer.getStart(source),
|
|
9494
|
+
end: child.initializer.getEnd(),
|
|
9495
|
+
text: list.primitive ? `${configured}.map((item) => migratedText(item, "title"))` : configured
|
|
9496
|
+
});
|
|
9497
|
+
return;
|
|
9498
|
+
}
|
|
9499
|
+
if (ts.isPropertyAccessExpression(child) && child.name.text === "map" && ts.isIdentifier(child.expression)) {
|
|
9500
|
+
const sourceName = child.expression.text;
|
|
9501
|
+
const list = contentLists.find((candidate) => candidate.sourceName === sourceName);
|
|
9502
|
+
if (!list) {
|
|
9503
|
+
ts.forEachChild(child, adapt);
|
|
9504
|
+
return;
|
|
9505
|
+
}
|
|
9506
|
+
if (adaptedItemArrays.has(sourceName)) return;
|
|
9507
|
+
const configured = `migratedItems(${hookName}, ${JSON.stringify(list.fieldKey)})`;
|
|
9508
|
+
edits.push({
|
|
9509
|
+
start: child.expression.getStart(source),
|
|
9510
|
+
end: child.expression.getEnd(),
|
|
9511
|
+
text: list.primitive ? `${configured}.map((item) => migratedText(item, "title"))` : configured
|
|
9512
|
+
});
|
|
9513
|
+
return;
|
|
9514
|
+
}
|
|
9515
|
+
if (ts.isPropertyAccessExpression(child) && child.name.text === "map" && ts.isArrayLiteralExpression(unwrappedExpression$1(child.expression))) {
|
|
9516
|
+
const directLists = contentLists.filter((list) => list.sourceName === null);
|
|
9517
|
+
const directIndex = directLists.findIndex((_list, index) => {
|
|
9518
|
+
return directLists[index] && !adaptedItemArrays.has(`__direct_${index}`);
|
|
9519
|
+
});
|
|
9520
|
+
const list = directIndex >= 0 ? directLists[directIndex] : void 0;
|
|
9521
|
+
if (!list) {
|
|
9522
|
+
ts.forEachChild(child, adapt);
|
|
9523
|
+
return;
|
|
9524
|
+
}
|
|
9525
|
+
adaptedItemArrays.add(`__direct_${directIndex}`);
|
|
9526
|
+
const presentation = presentationItems(child.expression);
|
|
9527
|
+
const configured = presentation ? `migratedItems(${hookName}, ${JSON.stringify(list.fieldKey)}, ${presentation})` : `migratedItems(${hookName}, ${JSON.stringify(list.fieldKey)})`;
|
|
9528
|
+
edits.push({
|
|
9529
|
+
start: child.expression.getStart(source),
|
|
9530
|
+
end: child.expression.getEnd(),
|
|
9531
|
+
text: list.primitive ? `${configured}.map((item) => migratedText(item, "title"))` : configured
|
|
9532
|
+
});
|
|
9533
|
+
return;
|
|
9534
|
+
}
|
|
9535
|
+
if (ts.isCallExpression(child) && ts.isIdentifier(child.expression) && child.expression.text === "fetch") {
|
|
9536
|
+
edits.push({
|
|
9537
|
+
start: child.getStart(source),
|
|
9538
|
+
end: child.getEnd(),
|
|
9539
|
+
text: "Promise.reject(new Error(\"Fonte externa removida pela Nuvler Adaptation Pass\"))"
|
|
9540
|
+
});
|
|
9541
|
+
return;
|
|
9542
|
+
}
|
|
9543
|
+
if (ts.isCallExpression(child) && ts.isIdentifier(child.expression) && child.expression.text === "t" && child.arguments[0] && ts.isStringLiteralLike(child.arguments[0])) {
|
|
9544
|
+
let field = mappedField(child.arguments[0].text);
|
|
9545
|
+
if (!field) {
|
|
9546
|
+
const key = child.arguments[0].text.toLowerCase();
|
|
9547
|
+
const last = key.split(".").at(-1) ?? key;
|
|
9548
|
+
if (!fallbackUsed.has("description") && (/^(?:desc|description|subtitle|text|a\d+)$/.test(last) || key.includes(".typed."))) field = "description";
|
|
9549
|
+
else if (!fallbackUsed.has("title") && /^(?:title|headline|name|q\d+)$/.test(last)) field = "title";
|
|
9550
|
+
if (field) fallbackUsed.add(field);
|
|
9551
|
+
}
|
|
9552
|
+
edits.push({
|
|
9553
|
+
start: child.getStart(source),
|
|
9554
|
+
end: child.getEnd(),
|
|
9555
|
+
text: field ? `migratedText(${hookName}, ${JSON.stringify(field)})` : "\"\""
|
|
9556
|
+
});
|
|
9557
|
+
return;
|
|
9558
|
+
}
|
|
9559
|
+
if (ts.isJsxText(child) && child.text.trim()) {
|
|
9560
|
+
const field = jsxField(child.parent, child.text);
|
|
9561
|
+
const replacement = field ? `{migratedText(${hookName}, ${JSON.stringify(field)})}` : "{null}";
|
|
9562
|
+
edits.push({
|
|
9563
|
+
start: child.getStart(source),
|
|
9564
|
+
end: child.getEnd(),
|
|
9565
|
+
text: replacement
|
|
9566
|
+
});
|
|
9567
|
+
return;
|
|
9568
|
+
}
|
|
9569
|
+
if (ts.isJsxExpression(child) && child.expression && ts.isStringLiteralLike(child.expression)) {
|
|
9570
|
+
const field = jsxField(child.parent, child.expression.text);
|
|
9571
|
+
edits.push({
|
|
9572
|
+
start: child.getStart(source),
|
|
9573
|
+
end: child.getEnd(),
|
|
9574
|
+
text: field ? `{migratedText(${hookName}, ${JSON.stringify(field)})}` : "{null}"
|
|
9575
|
+
});
|
|
9576
|
+
return;
|
|
9577
|
+
}
|
|
9578
|
+
if (ts.isJsxAttribute(child)) {
|
|
9579
|
+
const name = child.name.getText(source);
|
|
9580
|
+
const tag = child.parent.parent.tagName.getText(source).toLowerCase();
|
|
9581
|
+
const imageTag = tag === "img" || tag === "image";
|
|
9582
|
+
if (child.initializer && (imageTag && name === "src" || tag === "video" && ["src", "poster"].includes(name) || ["source", "iframe"].includes(tag) && name === "src")) {
|
|
9583
|
+
edits.push({
|
|
9584
|
+
start: child.initializer.getStart(source),
|
|
9585
|
+
end: child.initializer.getEnd(),
|
|
9586
|
+
text: tag === "source" || tag === "iframe" || tag === "video" && name === "src" ? `{migratedVideo(${hookName})}` : `{migratedImage(${hookName})}`
|
|
9587
|
+
});
|
|
9588
|
+
return;
|
|
9589
|
+
}
|
|
9590
|
+
if (child.initializer && imageTag && name === "alt") {
|
|
9591
|
+
edits.push({
|
|
9592
|
+
start: child.initializer.getStart(source),
|
|
9593
|
+
end: child.initializer.getEnd(),
|
|
9594
|
+
text: `{migratedText(${hookName}, "imageAlt")}`
|
|
9595
|
+
});
|
|
9596
|
+
return;
|
|
9597
|
+
}
|
|
9598
|
+
if (child.initializer && tag === "a" && name === "href") {
|
|
9599
|
+
edits.push({
|
|
9600
|
+
start: child.initializer.getStart(source),
|
|
9601
|
+
end: child.initializer.getEnd(),
|
|
9602
|
+
text: `{migratedLink(${hookName})}`
|
|
9603
|
+
});
|
|
9604
|
+
return;
|
|
9605
|
+
}
|
|
9606
|
+
if (child.initializer && [
|
|
9607
|
+
"aria-label",
|
|
9608
|
+
"aria-description",
|
|
9609
|
+
"placeholder",
|
|
9610
|
+
"title"
|
|
9611
|
+
].includes(name) && (ts.isStringLiteral(child.initializer) || ts.isJsxExpression(child.initializer) && child.initializer.expression && ts.isStringLiteralLike(child.initializer.expression))) {
|
|
9612
|
+
edits.push({
|
|
9613
|
+
start: child.initializer.getStart(source),
|
|
9614
|
+
end: child.initializer.getEnd(),
|
|
9615
|
+
text: "{undefined}"
|
|
9616
|
+
});
|
|
9617
|
+
return;
|
|
9618
|
+
}
|
|
9619
|
+
}
|
|
9620
|
+
ts.forEachChild(child, adapt);
|
|
9621
|
+
}
|
|
9622
|
+
adapt(node.body);
|
|
9623
|
+
}
|
|
9624
|
+
function visit(node) {
|
|
9625
|
+
if (options.unwrapDocumentTags && ts.isJsxElement(node)) {
|
|
9626
|
+
const tag = node.openingElement.tagName.getText(source).toLowerCase();
|
|
9627
|
+
if (tag === "html" || tag === "body") {
|
|
9628
|
+
edits.push({
|
|
9629
|
+
start: node.openingElement.getStart(source),
|
|
9630
|
+
end: node.openingElement.getEnd(),
|
|
9631
|
+
text: "<>"
|
|
9632
|
+
});
|
|
9633
|
+
edits.push({
|
|
9634
|
+
start: node.closingElement.getStart(source),
|
|
9635
|
+
end: node.closingElement.getEnd(),
|
|
9636
|
+
text: "</>"
|
|
9637
|
+
});
|
|
9638
|
+
}
|
|
9639
|
+
}
|
|
9640
|
+
if (contentByComponent.size && ts.isVariableDeclaration(node) && ts.isIdentifier(node.name) && /^(?:translations?|messages?|dictionary|locales?)$/i.test(node.name.text) && node.initializer && ts.isObjectLiteralExpression(node.initializer)) {
|
|
9641
|
+
edits.push({
|
|
9642
|
+
start: node.initializer.getStart(source),
|
|
9643
|
+
end: node.initializer.getEnd(),
|
|
9644
|
+
text: "new Proxy({} as any, { get: () => new Proxy({}, { get: () => \" \" }) })"
|
|
9645
|
+
});
|
|
9646
|
+
return;
|
|
9647
|
+
}
|
|
9648
|
+
if (ts.isJsxSelfClosingElement(node) || ts.isJsxElement(node)) {
|
|
9649
|
+
const tagName = ts.isJsxElement(node) ? node.openingElement.tagName.getText(source) : node.tagName.getText(source);
|
|
9650
|
+
if (removedComponents.has(tagName)) {
|
|
9651
|
+
edits.push({
|
|
9652
|
+
start: node.getStart(source),
|
|
9653
|
+
end: node.getEnd(),
|
|
9654
|
+
text: "{null}"
|
|
9655
|
+
});
|
|
9656
|
+
return;
|
|
9657
|
+
}
|
|
9658
|
+
}
|
|
9659
|
+
if (ts.isFunctionDeclaration(node) || ts.isFunctionExpression(node) || ts.isArrowFunction(node)) {
|
|
9660
|
+
const name = componentName(node);
|
|
9661
|
+
const adaptation = name ? contentByComponent.get(name) : void 0;
|
|
9662
|
+
if (adaptation) adaptFunction(node, adaptation);
|
|
9663
|
+
}
|
|
9664
|
+
const literal = moduleLiteral(node);
|
|
9665
|
+
if (literal) {
|
|
9666
|
+
const dependency = dependencyBySpecifier.get(literal.text);
|
|
9667
|
+
if (ts.isImportDeclaration(node) && literal.text === "next/image" && options.nextImageAdapterFile) {
|
|
9668
|
+
const replacement = relativeImport(destinationFile, options.nextImageAdapterFile);
|
|
9669
|
+
edits.push({
|
|
9670
|
+
start: literal.getStart(source) + 1,
|
|
9671
|
+
end: literal.getEnd() - 1,
|
|
9672
|
+
text: replacement
|
|
9673
|
+
});
|
|
9674
|
+
} else if (dependency?.resolvedFile && ts.isImportDeclaration(node) && !node.importClause && /(?<!\.module)\.(?:css|scss|sass|less)$/i.test(dependency.resolvedFile)) edits.push({
|
|
9675
|
+
start: node.getFullStart(),
|
|
9676
|
+
end: node.getEnd(),
|
|
9677
|
+
text: ""
|
|
9678
|
+
});
|
|
9679
|
+
else if (dependency?.resolvedFile) {
|
|
9680
|
+
const target = destinationBySource.get(path.resolve(dependency.resolvedFile));
|
|
9681
|
+
if (target) {
|
|
9682
|
+
const replacement = relativeImport(destinationFile, target);
|
|
9683
|
+
edits.push({
|
|
9684
|
+
start: literal.getStart(source) + 1,
|
|
9685
|
+
end: literal.getEnd() - 1,
|
|
9686
|
+
text: replacement
|
|
9687
|
+
});
|
|
9688
|
+
}
|
|
9689
|
+
}
|
|
9690
|
+
}
|
|
9691
|
+
if (ts.isJsxAttribute(node) && !contentByComponent.size && ["src", "poster"].includes(node.name.getText(source)) && node.initializer && ts.isStringLiteral(node.initializer) && node.initializer.text.startsWith("/")) {
|
|
9692
|
+
const suffix = `${path.sep}public${node.initializer.text.split("/").join(path.sep)}`;
|
|
9693
|
+
const target = [...destinationBySource.entries()].find(([sourceFile]) => sourceFile.endsWith(suffix))?.[1];
|
|
9694
|
+
if (target) edits.push({
|
|
9695
|
+
start: node.initializer.getStart(source),
|
|
9696
|
+
end: node.initializer.getEnd(),
|
|
9697
|
+
text: `{new URL(${JSON.stringify(relativeImport(destinationFile, target))}, import.meta.url).href}`
|
|
9698
|
+
});
|
|
9699
|
+
}
|
|
9700
|
+
ts.forEachChild(node, visit);
|
|
9701
|
+
}
|
|
9702
|
+
visit(source);
|
|
9703
|
+
if (contentByComponent.size && options.contentAdapterFile) {
|
|
9704
|
+
const adapterImport = relativeImport(destinationFile, options.contentAdapterFile);
|
|
9705
|
+
edits.push({
|
|
9706
|
+
start: 0,
|
|
9707
|
+
end: 0,
|
|
9708
|
+
text: `import { MigratedContactFields, migratedImage, migratedItems, migratedLink, migratedText, migratedVideo, useMigratedContactForm, useMigratedSection } from ${JSON.stringify(adapterImport)};\n`
|
|
9709
|
+
});
|
|
9710
|
+
}
|
|
9711
|
+
let transformed = applyEdits(content, edits);
|
|
9712
|
+
for (const adaptation of options.content ?? []) {
|
|
9713
|
+
const escaped = adaptation.componentName.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
9714
|
+
const commentedSection = new RegExp(`\\{\\s*\\/\\*\\s*(<${escaped}\\s*\\/>)\\s*\\*\\/\\s*\\}`, "g");
|
|
9715
|
+
transformed = transformed.replace(commentedSection, "$1");
|
|
9716
|
+
}
|
|
9717
|
+
return transformed;
|
|
9718
|
+
}
|
|
9719
|
+
function exportedNames(source) {
|
|
9720
|
+
const values = /* @__PURE__ */ new Set();
|
|
9721
|
+
const types = /* @__PURE__ */ new Set();
|
|
9722
|
+
let hasDefault = false;
|
|
9723
|
+
for (const statement of source.statements) {
|
|
9724
|
+
const modifiers = "modifiers" in statement ? statement.modifiers : void 0;
|
|
9725
|
+
const exported = modifiers?.some((modifier) => modifier.kind === ts.SyntaxKind.ExportKeyword) ?? false;
|
|
9726
|
+
const isDefault = modifiers?.some((modifier) => modifier.kind === ts.SyntaxKind.DefaultKeyword) ?? false;
|
|
9727
|
+
if (ts.isExportAssignment(statement)) hasDefault = true;
|
|
9728
|
+
if (isDefault) hasDefault = true;
|
|
9729
|
+
if (!exported) continue;
|
|
9730
|
+
if (ts.isVariableStatement(statement)) {
|
|
9731
|
+
for (const declaration of statement.declarationList.declarations) if (ts.isIdentifier(declaration.name)) values.add(declaration.name.text);
|
|
9732
|
+
} else if (ts.isFunctionDeclaration(statement) || ts.isClassDeclaration(statement) || ts.isEnumDeclaration(statement)) {
|
|
9733
|
+
if (statement.name) values.add(statement.name.text);
|
|
9734
|
+
} else if (ts.isInterfaceDeclaration(statement) || ts.isTypeAliasDeclaration(statement)) types.add(statement.name.text);
|
|
9735
|
+
}
|
|
9736
|
+
for (const statement of source.statements.filter(ts.isExportDeclaration)) {
|
|
9737
|
+
if (!statement.exportClause || !ts.isNamedExports(statement.exportClause)) continue;
|
|
9738
|
+
for (const element of statement.exportClause.elements) values.add(element.name.text);
|
|
9739
|
+
}
|
|
9740
|
+
return {
|
|
9741
|
+
values,
|
|
9742
|
+
types,
|
|
9743
|
+
hasDefault
|
|
9744
|
+
};
|
|
9745
|
+
}
|
|
9746
|
+
function businessModuleStub(file, content) {
|
|
9747
|
+
const exported = exportedNames(ts.createSourceFile(file, content, ts.ScriptTarget.Latest, true, scriptKind(file)));
|
|
9748
|
+
const lines = [
|
|
9749
|
+
"/* Adaptador temporário: regra de negócio da aplicação original isolada da Fidelity Pass. */",
|
|
9750
|
+
...[...exported.types].map((name) => `export type ${name} = any;`),
|
|
9751
|
+
...[...exported.values].map((name) => `export const ${name}: any = (..._args: any[]) => undefined;`)
|
|
9752
|
+
];
|
|
9753
|
+
if (exported.hasDefault) lines.push("const migratedBusinessDefault: any = (..._args: any[]) => undefined;", "export default migratedBusinessDefault;");
|
|
9754
|
+
if (!exported.hasDefault && !exported.values.size && !exported.types.size) lines.push("export {};");
|
|
9755
|
+
return `${lines.join("\n")}\n`;
|
|
9756
|
+
}
|
|
9757
|
+
//#endregion
|
|
9758
|
+
//#region src/migrate/generation/fidelity-pass.ts
|
|
9759
|
+
function destinationFor(directory, sourceFile) {
|
|
9760
|
+
return path.join(directory, "src", "migrated", "source", sourceFile);
|
|
9761
|
+
}
|
|
9762
|
+
function importPath(fromDirectory, target) {
|
|
9763
|
+
let relative = path.relative(fromDirectory, target).split(path.sep).join("/");
|
|
9764
|
+
relative = relative.replace(/\.(?:tsx?|jsx?|mts|cts)$/i, "");
|
|
9765
|
+
return relative.startsWith(".") ? relative : `./${relative}`;
|
|
9766
|
+
}
|
|
9767
|
+
function sourceModule(plan, relativeFile) {
|
|
9768
|
+
return plan.analysis.sourceGraph.modules.find((module) => module.file === relativeFile);
|
|
9769
|
+
}
|
|
9770
|
+
function contentAdaptations(plan) {
|
|
9771
|
+
const result = /* @__PURE__ */ new Map();
|
|
9772
|
+
const modules = new Map(plan.analysis.sourceGraph.modules.map((module) => [path.resolve(module.absolutePath), module]));
|
|
9773
|
+
const componentsByFile = /* @__PURE__ */ new Map();
|
|
9774
|
+
for (const component of plan.analysis.components) {
|
|
9775
|
+
const components = componentsByFile.get(component.file) ?? [];
|
|
9776
|
+
components.push(component);
|
|
9777
|
+
componentsByFile.set(component.file, components);
|
|
9778
|
+
}
|
|
9779
|
+
const roots = [...plan.contentBindings.map((binding) => ({ binding }))];
|
|
9780
|
+
if (plan.selected.HEADER) roots.push({
|
|
9781
|
+
binding: {
|
|
9782
|
+
id: "__header",
|
|
9783
|
+
file: plan.selected.HEADER.component.file,
|
|
9784
|
+
component: plan.selected.HEADER.component.name,
|
|
9785
|
+
contentLists: plan.selected.HEADER.component.contentLists.map((list, index) => ({
|
|
9786
|
+
...list,
|
|
9787
|
+
fieldKey: index === 0 ? "items" : `items${index + 1}`
|
|
9788
|
+
}))
|
|
9789
|
+
},
|
|
9790
|
+
special: true
|
|
9791
|
+
});
|
|
9792
|
+
if (plan.selected.FOOTER) roots.push({
|
|
9793
|
+
binding: {
|
|
9794
|
+
id: "__footer",
|
|
9795
|
+
file: plan.selected.FOOTER.component.file,
|
|
9796
|
+
component: plan.selected.FOOTER.component.name,
|
|
9797
|
+
contentLists: plan.selected.FOOTER.component.contentLists.map((list, index) => ({
|
|
9798
|
+
...list,
|
|
9799
|
+
fieldKey: index === 0 ? "items" : `items${index + 1}`
|
|
9800
|
+
}))
|
|
9801
|
+
},
|
|
9802
|
+
special: true
|
|
9803
|
+
});
|
|
9804
|
+
const rootFiles = new Set(roots.map(({ binding }) => binding.file));
|
|
9805
|
+
const claimed = /* @__PURE__ */ new Map();
|
|
9806
|
+
for (const { binding } of roots) {
|
|
9807
|
+
const current = result.get(binding.file) ?? [];
|
|
9808
|
+
if (!current.some((item) => item.componentName === binding.component)) {
|
|
9809
|
+
current.push({
|
|
9810
|
+
componentName: binding.component,
|
|
9811
|
+
bindingId: binding.id,
|
|
9812
|
+
componentKey: binding.componentKey,
|
|
9813
|
+
contentLists: binding.contentLists
|
|
9814
|
+
});
|
|
9815
|
+
result.set(binding.file, current);
|
|
9816
|
+
}
|
|
9817
|
+
}
|
|
9818
|
+
const explicitRoots = new Set(roots.map(({ binding }) => `${binding.file}#${binding.component}`));
|
|
9819
|
+
for (const { binding } of roots) {
|
|
9820
|
+
const localComponents = componentsByFile.get(binding.file) ?? [];
|
|
9821
|
+
const localByName = new Map(localComponents.map((component) => [component.name, component]));
|
|
9822
|
+
const rootComponent = localByName.get(binding.component);
|
|
9823
|
+
if (!rootComponent) continue;
|
|
9824
|
+
const pending = [rootComponent];
|
|
9825
|
+
const visited = /* @__PURE__ */ new Set([rootComponent.name]);
|
|
9826
|
+
while (pending.length) {
|
|
9827
|
+
const owner = pending.shift();
|
|
9828
|
+
for (const node of owner.jsx) {
|
|
9829
|
+
const childName = node.tag.split(".")[0];
|
|
9830
|
+
const child = localByName.get(childName);
|
|
9831
|
+
if (!child || visited.has(child.name)) continue;
|
|
9832
|
+
visited.add(child.name);
|
|
9833
|
+
if (explicitRoots.has(`${binding.file}#${child.name}`)) continue;
|
|
9834
|
+
const current = result.get(binding.file) ?? [];
|
|
9835
|
+
if (!current.some((item) => item.componentName === child.name)) {
|
|
9836
|
+
current.push({
|
|
9837
|
+
componentName: child.name,
|
|
9838
|
+
bindingId: binding.id,
|
|
9839
|
+
componentKey: binding.componentKey
|
|
9840
|
+
});
|
|
9841
|
+
result.set(binding.file, current);
|
|
9842
|
+
pending.push(child);
|
|
9843
|
+
}
|
|
9844
|
+
}
|
|
9845
|
+
}
|
|
9846
|
+
}
|
|
9847
|
+
for (const { binding } of roots) {
|
|
9848
|
+
const root = plan.analysis.sourceGraph.modules.find((module) => module.file === binding.file);
|
|
9849
|
+
if (!root) continue;
|
|
9850
|
+
const queue = [root];
|
|
9851
|
+
const visited = /* @__PURE__ */ new Set();
|
|
9852
|
+
while (queue.length) {
|
|
9853
|
+
const module = queue.shift();
|
|
9854
|
+
if (visited.has(module.file)) continue;
|
|
9855
|
+
visited.add(module.file);
|
|
9856
|
+
if (module.file !== binding.file && rootFiles.has(module.file)) continue;
|
|
9857
|
+
const previousOwner = claimed.get(module.file);
|
|
9858
|
+
if (previousOwner && previousOwner !== binding.id) continue;
|
|
9859
|
+
claimed.set(module.file, binding.id);
|
|
9860
|
+
for (const component of module.file === binding.file ? [] : componentsByFile.get(module.file) ?? []) {
|
|
9861
|
+
const current = result.get(module.file) ?? [];
|
|
9862
|
+
if (!current.some((item) => item.componentName === component.name)) {
|
|
9863
|
+
current.push({
|
|
9864
|
+
componentName: component.name,
|
|
9865
|
+
bindingId: binding.id,
|
|
9866
|
+
componentKey: binding.componentKey
|
|
9867
|
+
});
|
|
9868
|
+
result.set(module.file, current);
|
|
9869
|
+
}
|
|
9870
|
+
}
|
|
9871
|
+
for (const dependency of module.dependencies) {
|
|
9872
|
+
if (!dependency.resolvedFile || dependency.type === "BUSINESS") continue;
|
|
9873
|
+
const target = modules.get(path.resolve(dependency.resolvedFile));
|
|
9874
|
+
if (target?.kind === "SOURCE") queue.push(target);
|
|
9875
|
+
}
|
|
9876
|
+
}
|
|
9877
|
+
}
|
|
9878
|
+
return result;
|
|
9879
|
+
}
|
|
9880
|
+
async function runFidelityPass(plan, directory) {
|
|
9881
|
+
const graph = plan.analysis.sourceGraph;
|
|
9882
|
+
const adaptations = contentAdaptations(plan);
|
|
9883
|
+
const destinationBySource = /* @__PURE__ */ new Map();
|
|
9884
|
+
const bootstrap = graph.entrypoint?.bootstrapFile;
|
|
9885
|
+
const modules = graph.modules.filter((module) => module.file !== bootstrap);
|
|
9886
|
+
for (const module of modules) destinationBySource.set(path.resolve(module.absolutePath), destinationFor(directory, module.file));
|
|
9887
|
+
const extraAssets = [];
|
|
9888
|
+
for (const asset of plan.assets.filter((candidate) => !destinationBySource.has(path.resolve(candidate.absolutePath)))) try {
|
|
9889
|
+
if ((await stat(asset.absolutePath)).isFile()) extraAssets.push(asset);
|
|
9890
|
+
else plan.warnings.push(`Asset não encontrado e ignorado: ${asset.file}`);
|
|
9891
|
+
} catch {
|
|
9892
|
+
plan.warnings.push(`Asset não encontrado e ignorado: ${asset.file}`);
|
|
9893
|
+
}
|
|
9894
|
+
for (const asset of extraAssets) destinationBySource.set(path.resolve(asset.absolutePath), destinationFor(directory, asset.file));
|
|
9895
|
+
const adaptedBusinessFiles = [];
|
|
9896
|
+
for (const module of modules) {
|
|
9897
|
+
const destination = destinationBySource.get(path.resolve(module.absolutePath));
|
|
9898
|
+
await mkdir(path.dirname(destination), { recursive: true });
|
|
9899
|
+
if (module.kind !== "SOURCE") {
|
|
9900
|
+
await writeFile(destination, await readFile(module.absolutePath));
|
|
9901
|
+
continue;
|
|
9902
|
+
}
|
|
9903
|
+
const content = await readFile(module.absolutePath, "utf8");
|
|
9904
|
+
const unwrapDocumentTags = graph.entrypoint?.layoutFiles.includes(module.file) ?? false;
|
|
9905
|
+
if (unwrapDocumentTags && /<(?:html|body)\b/i.test(content)) plan.warnings.push(`${module.file}: wrappers <html>/<body> do Next.js adaptados para o runtime do tema.`);
|
|
9906
|
+
const transformed = module.business && !module.visual ? businessModuleStub(module.absolutePath, content) : transformMigratedSource(module, content, graph, destination, destinationBySource, {
|
|
9907
|
+
contentAdapterFile: path.join(directory, "src", "migrated-content.tsx"),
|
|
9908
|
+
nextImageAdapterFile: path.join(directory, "src", "migrated-next-image.tsx"),
|
|
9909
|
+
content: adaptations.get(module.file),
|
|
9910
|
+
unwrapDocumentTags,
|
|
9911
|
+
removeComponents: plan.analysis.components.filter((component) => /(whatsapp|floating|float|chat|popup)/i.test(component.name)).map((component) => component.name)
|
|
9912
|
+
});
|
|
9913
|
+
if (module.business && !module.visual) adaptedBusinessFiles.push(module.file);
|
|
9914
|
+
await writeFile(destination, module.business && !module.visual ? transformed : `// @ts-nocheck -- código preservado pela Nuvler Fidelity Pass\n${transformed}`, "utf8");
|
|
9915
|
+
}
|
|
9916
|
+
for (const asset of extraAssets) {
|
|
9917
|
+
const destination = destinationBySource.get(path.resolve(asset.absolutePath));
|
|
9918
|
+
await mkdir(path.dirname(destination), { recursive: true });
|
|
9919
|
+
await writeFile(destination, await readFile(asset.absolutePath));
|
|
9920
|
+
}
|
|
9921
|
+
const homeDirectory = path.join(directory, "src", "sections");
|
|
9922
|
+
const entry = graph.entrypoint;
|
|
9923
|
+
const page = entry ? sourceModule(plan, entry.pageFile) : void 0;
|
|
9924
|
+
const pageDestination = page ? destinationBySource.get(path.resolve(page.absolutePath)) : void 0;
|
|
9925
|
+
const layoutImports = entry?.layoutFiles.flatMap((file) => {
|
|
9926
|
+
const layout = sourceModule(plan, file);
|
|
9927
|
+
const destination = layout ? destinationBySource.get(path.resolve(layout.absolutePath)) : void 0;
|
|
9928
|
+
if (!layout || !destination) return [];
|
|
9929
|
+
return [{
|
|
9930
|
+
importPath: importPath(homeDirectory, destination),
|
|
9931
|
+
exportName: "default",
|
|
9932
|
+
defaultExport: true
|
|
9933
|
+
}];
|
|
9934
|
+
}) ?? [];
|
|
9935
|
+
return {
|
|
9936
|
+
copiedFiles: modules.length + extraAssets.length,
|
|
9937
|
+
copiedAssets: modules.filter((module) => module.kind === "ASSET").length + extraAssets.length,
|
|
9938
|
+
entryImportPath: pageDestination ? importPath(homeDirectory, pageDestination) : null,
|
|
9939
|
+
entryExportName: entry?.exportName ?? null,
|
|
9940
|
+
entryDefaultExport: entry?.defaultExport ?? true,
|
|
9941
|
+
layoutImports,
|
|
9942
|
+
adaptedBusinessFiles
|
|
9943
|
+
};
|
|
9944
|
+
}
|
|
9945
|
+
async function mergeFidelityDependencies(plan, directory) {
|
|
9946
|
+
const packageFile = path.join(directory, "package.json");
|
|
9947
|
+
const generated = JSON.parse(await readFile(packageFile, "utf8"));
|
|
9948
|
+
const dependencies = { ...generated.dependencies };
|
|
9949
|
+
const skipped = /* @__PURE__ */ new Set([
|
|
9950
|
+
"react",
|
|
9951
|
+
"react-dom",
|
|
9952
|
+
"vite",
|
|
9953
|
+
"typescript",
|
|
9954
|
+
"@vitejs/plugin-react",
|
|
9955
|
+
"tailwindcss",
|
|
9956
|
+
"@tailwindcss/vite"
|
|
9957
|
+
]);
|
|
9958
|
+
for (const dependency of plan.analysis.sourceGraph.dependencies) {
|
|
9959
|
+
const name = dependency.packageName;
|
|
9960
|
+
if (!name || skipped.has(name)) continue;
|
|
9961
|
+
const version = plan.analysis.dependencies[name];
|
|
9962
|
+
if (version) dependencies[name] = version;
|
|
9963
|
+
else plan.warnings.push(`Dependência ${name} alcançada pela Home, mas sem versão declarada no projeto original.`);
|
|
9964
|
+
}
|
|
9965
|
+
const companions = /* @__PURE__ */ new Map([["@mui/icons-material", [
|
|
9966
|
+
"@mui/material",
|
|
9967
|
+
"@emotion/react",
|
|
9968
|
+
"@emotion/styled"
|
|
9969
|
+
]], ["@mui/material", ["@emotion/react", "@emotion/styled"]]]);
|
|
9970
|
+
for (const name of Object.keys(dependencies)) for (const companion of companions.get(name) ?? []) {
|
|
9971
|
+
const version = plan.analysis.dependencies[companion];
|
|
9972
|
+
if (version) dependencies[companion] = version;
|
|
9973
|
+
}
|
|
9974
|
+
generated.dependencies = dependencies;
|
|
9975
|
+
await writeFile(packageFile, `${JSON.stringify(generated, null, 2)}\n`, "utf8");
|
|
9976
|
+
const configFile = path.join(directory, "tsconfig.json");
|
|
9977
|
+
const config = JSON.parse(await readFile(configFile, "utf8"));
|
|
9978
|
+
config.compilerOptions = {
|
|
9979
|
+
...config.compilerOptions,
|
|
9980
|
+
module: "ESNext",
|
|
9981
|
+
moduleResolution: "Bundler",
|
|
9982
|
+
allowJs: true,
|
|
9983
|
+
noEmit: true
|
|
9984
|
+
};
|
|
9985
|
+
await writeFile(configFile, `${JSON.stringify(config, null, 2)}\n`, "utf8");
|
|
9986
|
+
}
|
|
9987
|
+
//#endregion
|
|
9988
|
+
//#region src/migrate/generator.ts
|
|
9989
|
+
function portable(file) {
|
|
9990
|
+
return file.split(path.sep).join("/");
|
|
9991
|
+
}
|
|
9992
|
+
function classes(base, source = "") {
|
|
9993
|
+
return JSON.stringify([base, source].filter(Boolean).join(" "));
|
|
9994
|
+
}
|
|
9995
|
+
function profile(plan, role) {
|
|
9996
|
+
return plan.selected[role]?.classes ?? {
|
|
9997
|
+
root: "",
|
|
9998
|
+
brand: "",
|
|
9999
|
+
navigation: "",
|
|
10000
|
+
title: "",
|
|
10001
|
+
text: "",
|
|
10002
|
+
action: "",
|
|
10003
|
+
media: "",
|
|
10004
|
+
grid: "",
|
|
10005
|
+
card: "",
|
|
10006
|
+
content: ""
|
|
10007
|
+
};
|
|
10008
|
+
}
|
|
10009
|
+
function headerSource(plan) {
|
|
10010
|
+
const style = profile(plan, "HEADER");
|
|
10011
|
+
return `import type { HeaderProps } from "@nuvler/theme-sdk";
|
|
10012
|
+
|
|
10013
|
+
export function Header({ site, categories, pages }: HeaderProps) {
|
|
10014
|
+
const name = site.settings?.siteName || site.tenant.name;
|
|
10015
|
+
return <header className=${classes("nuvler-migrated-header", style.root)}>
|
|
10016
|
+
<div className=${classes("nuvler-migrated-header-inner", style.content)}>
|
|
10017
|
+
<a className=${classes("nuvler-migrated-brand", style.brand)} href="/">
|
|
10018
|
+
{site.settings?.logo?.url ? <img src={site.settings.logo.url} alt={site.settings.logo.alt || name} /> : <span>{name}</span>}
|
|
10019
|
+
</a>
|
|
10020
|
+
<nav className=${classes("nuvler-migrated-nav", style.navigation)}>
|
|
10021
|
+
{categories.slice(0, 6).map((category) => <a href={\`/\${category.slug}\`} key={category.slug}>{category.name}</a>)}
|
|
10022
|
+
{pages.slice(0, 4).map((page) => <a href={\`/\${page.slug}\`} key={page.slug}>{page.title}</a>)}
|
|
10023
|
+
</nav>
|
|
10024
|
+
</div>
|
|
10025
|
+
</header>;
|
|
10026
|
+
}
|
|
10027
|
+
`;
|
|
10028
|
+
}
|
|
10029
|
+
function footerSource(plan) {
|
|
10030
|
+
const style = profile(plan, "FOOTER");
|
|
10031
|
+
return `import type { FooterProps } from "@nuvler/theme-sdk";
|
|
10032
|
+
|
|
10033
|
+
export function Footer({ site, pages, template }: FooterProps) {
|
|
10034
|
+
const name = site.settings?.siteName || site.tenant.name;
|
|
10035
|
+
return <footer className=${classes("nuvler-migrated-footer", style.root)}>
|
|
10036
|
+
<div className=${classes("nuvler-migrated-footer-inner", style.content)}>
|
|
10037
|
+
<div><strong className=${classes("nuvler-migrated-footer-brand", style.brand)}>{name}</strong>{site.settings?.description && <p className=${classes("nuvler-migrated-copy", style.text)}>{site.settings.description}</p>}</div>
|
|
10038
|
+
<nav className=${classes("nuvler-migrated-footer-nav", style.navigation)} aria-label={template.footerNavigationLabel}>
|
|
10039
|
+
{pages.map((page) => <a href={\`/\${page.slug}\`} key={page.slug}>{page.title}</a>)}
|
|
10040
|
+
</nav>
|
|
10041
|
+
<div className="nuvler-migrated-contact">
|
|
10042
|
+
{site.settings?.contact.phone && <a href={\`tel:\${site.settings.contact.phone}\`}>{site.settings.contact.phone}</a>}
|
|
10043
|
+
{site.settings?.contact.email && <a href={\`mailto:\${site.settings.contact.email}\`}>{site.settings.contact.email}</a>}
|
|
10044
|
+
</div>
|
|
10045
|
+
</div>
|
|
10046
|
+
{template.footerNote && <small>{template.footerNote}</small>}
|
|
10047
|
+
</footer>;
|
|
10048
|
+
}
|
|
10049
|
+
`;
|
|
10050
|
+
}
|
|
10051
|
+
function productCardSource(plan) {
|
|
10052
|
+
const style = profile(plan, "PRODUCT_CARD");
|
|
10053
|
+
return `import { productUrl, type ThemeProduct } from "@nuvler/theme-sdk";
|
|
10054
|
+
|
|
10055
|
+
function money(value: number | null): string {
|
|
10056
|
+
return value === null ? "Consulte" : new Intl.NumberFormat("pt-BR", { style: "currency", currency: "BRL" }).format(value);
|
|
10057
|
+
}
|
|
10058
|
+
|
|
10059
|
+
export function ProductCard({ product, showCategory = true, showDescription = true }: { product: ThemeProduct; showCategory?: boolean; showDescription?: boolean }) {
|
|
10060
|
+
const price = product.promotionalPrice ?? product.price;
|
|
10061
|
+
const href = productUrl(product);
|
|
10062
|
+
return <article className=${classes("nuvler-migrated-product-card", style.root || style.card)}>
|
|
10063
|
+
<a className=${classes("nuvler-migrated-product-media", style.media)} href={href}>
|
|
10064
|
+
{product.image?.url ? <img src={product.image.url} alt={product.image.alt || product.title} /> : <span aria-hidden="true" />}
|
|
10065
|
+
</a>
|
|
10066
|
+
<div className=${classes("nuvler-migrated-product-content", style.content)}>
|
|
10067
|
+
{showCategory && <small>{product.categories[0]?.name || product.brand || "Produto"}</small>}
|
|
10068
|
+
<h3 className=${classes("nuvler-migrated-product-title", style.title)}><a href={href}>{product.title}</a></h3>
|
|
10069
|
+
{showDescription && product.description && <p className=${classes("nuvler-migrated-copy", style.text)}>{product.description}</p>}
|
|
10070
|
+
<strong>{money(price)}</strong>
|
|
10071
|
+
<a className=${classes("nuvler-migrated-action", style.action)} href={href}>Ver produto</a>
|
|
10072
|
+
</div>
|
|
10073
|
+
</article>;
|
|
10074
|
+
}
|
|
10075
|
+
`;
|
|
10076
|
+
}
|
|
10077
|
+
function productGridSource(plan) {
|
|
10078
|
+
const style = profile(plan, "PRODUCT_GRID");
|
|
10079
|
+
return `import type { ProductGridProps } from "@nuvler/theme-sdk";
|
|
10080
|
+
import { ProductCard } from "./ProductCard.js";
|
|
10081
|
+
|
|
8793
10082
|
export function ProductGrid({ products, columns = 3, showCategory, showDescription }: ProductGridProps) {
|
|
8794
10083
|
return <div className=${classes("nuvler-migrated-product-grid", style.root || style.grid)} data-columns={columns}>
|
|
8795
10084
|
{products.map((product) => <ProductCard product={product} showCategory={showCategory} showDescription={showDescription} key={product.slug} />)}
|
|
@@ -8818,192 +10107,1626 @@ export function ProductDetail({ product, descriptionContent, onAddToCart }: Prod
|
|
|
8818
10107
|
</div>
|
|
8819
10108
|
</article>;
|
|
8820
10109
|
}
|
|
8821
|
-
`;
|
|
10110
|
+
`;
|
|
10111
|
+
}
|
|
10112
|
+
function fidelityHomeSource(fidelity) {
|
|
10113
|
+
if (!fidelity.entryImportPath || !fidelity.entryExportName) return null;
|
|
10114
|
+
return `import type { HomeProps } from "@nuvler/theme-sdk";
|
|
10115
|
+
import { MigratedContentProvider } from "../migrated-content.js";
|
|
10116
|
+
${fidelity.entryDefaultExport ? `import MigratedPage from ${JSON.stringify(fidelity.entryImportPath)};` : `import { ${fidelity.entryExportName} as MigratedPage } from ${JSON.stringify(fidelity.entryImportPath)};`}
|
|
10117
|
+
${fidelity.layoutImports.map((layout, index) => layout.defaultExport ? `import MigratedLayout${index} from ${JSON.stringify(layout.importPath)};` : `import { ${layout.exportName} as MigratedLayout${index} } from ${JSON.stringify(layout.importPath)};`).join("\n")}
|
|
10118
|
+
|
|
10119
|
+
/** Fidelity Pass: a árvore original permanece ativa; somente o conteúdo é fornecido pelo Nuvler. */
|
|
10120
|
+
export function Home(props: HomeProps) {
|
|
10121
|
+
return <MigratedContentProvider {...props}>${fidelity.layoutImports.reduceRight((child, _layout, index) => `<MigratedLayout${index}>${child}</MigratedLayout${index}>`, "<MigratedPage />")}</MigratedContentProvider>;
|
|
10122
|
+
}
|
|
10123
|
+
`;
|
|
10124
|
+
}
|
|
10125
|
+
function homeSource(plan, fidelity) {
|
|
10126
|
+
const preserved = fidelityHomeSource(fidelity);
|
|
10127
|
+
if (preserved) return preserved;
|
|
10128
|
+
const home = profile(plan, "HOME");
|
|
10129
|
+
profile(plan, "SECTION");
|
|
10130
|
+
const bindings = plan.contentBindings.map(({ id, type, order, componentKey, classes: bindingClasses }) => ({
|
|
10131
|
+
id,
|
|
10132
|
+
type,
|
|
10133
|
+
order,
|
|
10134
|
+
componentKey,
|
|
10135
|
+
classes: bindingClasses
|
|
10136
|
+
}));
|
|
10137
|
+
return `import { useState, type FormEvent } from "react";
|
|
10138
|
+
import type { HomeProps, ThemeContactSubmissionInput, ThemeEditorialItem, ThemeHomeSection } from "@nuvler/theme-sdk";
|
|
10139
|
+
import { ProductGrid } from "../components/ProductGrid.js";
|
|
10140
|
+
|
|
10141
|
+
type Binding = {
|
|
10142
|
+
id: string;
|
|
10143
|
+
type: ThemeHomeSection["type"];
|
|
10144
|
+
order: number;
|
|
10145
|
+
componentKey?: string;
|
|
10146
|
+
classes: Record<"root" | "brand" | "navigation" | "title" | "text" | "action" | "media" | "grid" | "card" | "content", string>;
|
|
10147
|
+
};
|
|
10148
|
+
|
|
10149
|
+
const migratedBindings: Binding[] = ${JSON.stringify(bindings, null, 2)};
|
|
10150
|
+
|
|
10151
|
+
function cx(...values: Array<string | undefined>): string {
|
|
10152
|
+
return values.filter(Boolean).join(" ");
|
|
10153
|
+
}
|
|
10154
|
+
|
|
10155
|
+
function value(data: Record<string, unknown>, key: string): string {
|
|
10156
|
+
const candidate = data[key];
|
|
10157
|
+
return typeof candidate === "string" ? candidate : "";
|
|
10158
|
+
}
|
|
10159
|
+
|
|
10160
|
+
function limit(data: Record<string, unknown>): number {
|
|
10161
|
+
const candidate = data.limit;
|
|
10162
|
+
return typeof candidate === "number" && candidate > 0 ? Math.min(candidate, 24) : 8;
|
|
10163
|
+
}
|
|
10164
|
+
|
|
10165
|
+
function record(value: unknown): Record<string, unknown> | null {
|
|
10166
|
+
return value && typeof value === "object" && !Array.isArray(value) ? value as Record<string, unknown> : null;
|
|
10167
|
+
}
|
|
10168
|
+
|
|
10169
|
+
function media(data: Record<string, unknown>): { url: string; alt: string } | null {
|
|
10170
|
+
const image = record(data.image);
|
|
10171
|
+
const url = image ? value(image, "url") : value(data, "imageUrl");
|
|
10172
|
+
if (!url) return null;
|
|
10173
|
+
return { url, alt: (image ? value(image, "alt") : "") || value(data, "imageAlt") };
|
|
10174
|
+
}
|
|
10175
|
+
|
|
10176
|
+
function bindingFor(section: ThemeHomeSection, index: number, sections: ThemeHomeSection[]): Binding | undefined {
|
|
10177
|
+
if (section.id) {
|
|
10178
|
+
const exact = migratedBindings.find((binding) => binding.id === section.id);
|
|
10179
|
+
if (exact) return exact;
|
|
10180
|
+
}
|
|
10181
|
+
if (section.type === "theme-component" && typeof section.data.componentKey === "string") {
|
|
10182
|
+
const custom = migratedBindings.find((binding) => binding.componentKey === section.data.componentKey);
|
|
10183
|
+
if (custom) return custom;
|
|
10184
|
+
}
|
|
10185
|
+
const occurrence = sections.slice(0, index).filter((candidate) => candidate.type === section.type).length;
|
|
10186
|
+
return migratedBindings.filter((binding) => binding.type === section.type)[occurrence]
|
|
10187
|
+
?? migratedBindings[index];
|
|
10188
|
+
}
|
|
10189
|
+
|
|
10190
|
+
function heading(section: ThemeHomeSection, binding: Binding | undefined) {
|
|
10191
|
+
const eyebrow = value(section.data, "eyebrow");
|
|
10192
|
+
const title = value(section.data, "title");
|
|
10193
|
+
if (!eyebrow && !title) return null;
|
|
10194
|
+
return <header className="nuvler-migrated-section-heading">
|
|
10195
|
+
{eyebrow && <span>{eyebrow}</span>}
|
|
10196
|
+
{title && <h2 className={cx("nuvler-migrated-section-title", binding?.classes.title)}>{title}</h2>}
|
|
10197
|
+
</header>;
|
|
10198
|
+
}
|
|
10199
|
+
|
|
10200
|
+
function TextSection({ section, binding }: { section: ThemeHomeSection; binding?: Binding }) {
|
|
10201
|
+
const eyebrow = value(section.data, "eyebrow");
|
|
10202
|
+
const title = value(section.data, "title");
|
|
10203
|
+
const description = value(section.data, "description") || value(section.data, "text") || value(section.data, "content");
|
|
10204
|
+
const buttonLabel = value(section.data, "buttonLabel");
|
|
10205
|
+
const buttonUrl = value(section.data, "buttonUrl");
|
|
10206
|
+
const image = media(section.data);
|
|
10207
|
+
if (!eyebrow && !title && !description && !image && !(buttonLabel && buttonUrl)) return null;
|
|
10208
|
+
const hero = section.type === "hero";
|
|
10209
|
+
return <section className={cx(hero ? "nuvler-migrated-hero" : "nuvler-migrated-section nuvler-migrated-generic", binding?.classes.root)} data-image-position={value(section.data, "imagePosition") || undefined}>
|
|
10210
|
+
<div className={cx(hero ? "nuvler-migrated-hero-content" : "nuvler-migrated-section-content", binding?.classes.content)}>
|
|
10211
|
+
{eyebrow && <span>{eyebrow}</span>}
|
|
10212
|
+
{title && (hero
|
|
10213
|
+
? <h1 className={cx("nuvler-migrated-hero-title", binding?.classes.title)}>{title}</h1>
|
|
10214
|
+
: <h2 className={cx("nuvler-migrated-section-title", binding?.classes.title)}>{title}</h2>)}
|
|
10215
|
+
{description && <p className={cx("nuvler-migrated-copy", binding?.classes.text)}>{description}</p>}
|
|
10216
|
+
{buttonLabel && buttonUrl && <a className={cx("nuvler-migrated-action", binding?.classes.action)} href={buttonUrl}>{buttonLabel}</a>}
|
|
10217
|
+
</div>
|
|
10218
|
+
{image && <div className={cx(hero ? "nuvler-migrated-hero-media" : "nuvler-migrated-section-media", binding?.classes.media)}><img src={image.url} alt={image.alt || title} /></div>}
|
|
10219
|
+
</section>;
|
|
10220
|
+
}
|
|
10221
|
+
|
|
10222
|
+
function ThemeComponent({ section, binding, submitContact }: { section: ThemeHomeSection; binding?: Binding; submitContact?: HomeProps["submitContact"] }) {
|
|
10223
|
+
const props = record(section.data.props) ?? {};
|
|
10224
|
+
const componentKey = value(section.data, "componentKey");
|
|
10225
|
+
if (componentKey === "video") return <section className={cx("nuvler-migrated-section", binding?.classes.root)}><div className={binding?.classes.content}>{value(props, "eyebrow") && <span>{value(props, "eyebrow")}</span>}{value(props, "title") && <h2>{value(props, "title")}</h2>}{value(props, "description") && <p>{value(props, "description")}</p>}{value(props, "videoUrl") && <video className="nuvler-migrated-video" controls playsInline poster={value(props, "posterImageUrl") || undefined} src={value(props, "videoUrl")} />}</div></section>;
|
|
10226
|
+
if (componentKey !== "contact-form") return <TextSection section={{ ...section, data: props }} binding={binding} />;
|
|
10227
|
+
const configuredFields = Array.isArray(props.fields)
|
|
10228
|
+
? props.fields.map(record).filter((field): field is Record<string, unknown> => Boolean(field))
|
|
10229
|
+
: [];
|
|
10230
|
+
const fields = configuredFields.length ? configuredFields : [
|
|
10231
|
+
{ key: "name", label: "Nome", type: "text", required: true },
|
|
10232
|
+
{ key: "email", label: "E-mail", type: "email", required: true },
|
|
10233
|
+
{ key: "phone", label: "Telefone", type: "tel", required: false },
|
|
10234
|
+
{ key: "message", label: "Mensagem", type: "textarea", required: true },
|
|
10235
|
+
];
|
|
10236
|
+
const [status, setStatus] = useState<"idle" | "sending" | "success" | "error">("idle");
|
|
10237
|
+
const [error, setError] = useState("");
|
|
10238
|
+
const submit = async (event: FormEvent<HTMLFormElement>) => {
|
|
10239
|
+
event.preventDefault();
|
|
10240
|
+
if (!submitContact) { setStatus("error"); setError("O envio de contatos ainda não está disponível."); return; }
|
|
10241
|
+
const element = event.currentTarget;
|
|
10242
|
+
const form = new FormData(element);
|
|
10243
|
+
const values: ThemeContactSubmissionInput["values"] = {};
|
|
10244
|
+
fields.forEach((field) => {
|
|
10245
|
+
const key = value(field, "key");
|
|
10246
|
+
if (!key) return;
|
|
10247
|
+
if (value(field, "type") === "checkbox") { values[key] = form.has(key); return; }
|
|
10248
|
+
const entries = form.getAll(key).map(String);
|
|
10249
|
+
values[key] = entries.length > 1 ? entries : entries[0] ?? "";
|
|
10250
|
+
});
|
|
10251
|
+
setStatus("sending"); setError("");
|
|
10252
|
+
try {
|
|
10253
|
+
await submitContact({ formKey: componentKey, sectionId: section.id, values, pathname: typeof window === "undefined" ? undefined : window.location.pathname });
|
|
10254
|
+
element.reset(); setStatus("success");
|
|
10255
|
+
} catch (cause) {
|
|
10256
|
+
setStatus("error"); setError(cause instanceof Error ? cause.message : "Não foi possível enviar o contato.");
|
|
10257
|
+
}
|
|
10258
|
+
};
|
|
10259
|
+
return <section className={cx("nuvler-migrated-section nuvler-migrated-contact-form-section", binding?.classes.root)}>
|
|
10260
|
+
<div className="nuvler-migrated-contact-form-copy">{value(props, "eyebrow") && <span>{value(props, "eyebrow")}</span>}<h2>{value(props, "title") || "Fale com nossa equipe"}</h2>{value(props, "description") && <p>{value(props, "description")}</p>}</div>
|
|
10261
|
+
<form className="nuvler-migrated-contact-form" onSubmit={(event) => void submit(event)}>{fields.map((field) => {
|
|
10262
|
+
const key = value(field, "key"); const type = value(field, "type") || "text"; const label = value(field, "label") || key; const required = field.required === true;
|
|
10263
|
+
if (!key) return null;
|
|
10264
|
+
if (type === "checkbox") return <label className="nuvler-migrated-form-wide nuvler-migrated-checkbox" key={key}><input name={key} required={required} type="checkbox" value="true" /><span>{label}</span></label>;
|
|
10265
|
+
if (type === "select") { const options = Array.isArray(field.options) ? field.options.map(record).filter((item): item is Record<string, unknown> => Boolean(item)) : []; return <label key={key}><span>{label}</span><select name={key} required={required}>{options.map((option) => <option key={value(option, "value")} value={value(option, "value")}>{value(option, "label") || value(option, "value")}</option>)}</select></label>; }
|
|
10266
|
+
return <label className={type === "textarea" ? "nuvler-migrated-form-wide" : ""} key={key}><span>{label}</span>{type === "textarea" ? <textarea name={key} placeholder={value(field, "placeholder")} required={required} rows={5} /> : <input name={key} placeholder={value(field, "placeholder")} required={required} type={["email", "tel", "url", "number"].includes(type) ? type : "text"} />}</label>;
|
|
10267
|
+
})}<div className="nuvler-migrated-form-wide"><button className="nuvler-migrated-action" disabled={status === "sending"} type="submit">{status === "sending" ? "" : value(props, "submitLabel")}</button>{status === "success" && value(props, "successMessage") && <p role="status">{value(props, "successMessage")}</p>}{status === "error" && <p role="alert">{error}</p>}</div></form>
|
|
10268
|
+
</section>;
|
|
10269
|
+
}
|
|
10270
|
+
|
|
10271
|
+
function Banners({ section, binding }: { section: ThemeHomeSection; binding?: Binding }) {
|
|
10272
|
+
const banners = Array.isArray(section.data.banners)
|
|
10273
|
+
? section.data.banners.map(record).filter((item): item is Record<string, unknown> => Boolean(item))
|
|
10274
|
+
: [];
|
|
10275
|
+
const configured = banners.map((banner) => ({ banner, image: media(banner) })).filter(({ image }) => Boolean(image));
|
|
10276
|
+
if (!configured.length) return null;
|
|
10277
|
+
return <section className={cx("nuvler-migrated-banners", binding?.classes.root)}>
|
|
10278
|
+
{configured.map(({ banner, image }, index) => <article className={cx("nuvler-migrated-banner", binding?.classes.card)} key={value(banner, "id") || index}>
|
|
10279
|
+
<img className={cx("nuvler-migrated-banner-media", binding?.classes.media)} src={image!.url} alt={image!.alt || value(banner, "title")} />
|
|
10280
|
+
<div className={cx("nuvler-migrated-banner-content", binding?.classes.content)}>
|
|
10281
|
+
{value(banner, "title") && <h2 className={binding?.classes.title}>{value(banner, "title")}</h2>}
|
|
10282
|
+
{value(banner, "description") && <p className={binding?.classes.text}>{value(banner, "description")}</p>}
|
|
10283
|
+
{value(banner, "buttonLabel") && value(banner, "buttonUrl") && <a className={cx("nuvler-migrated-action", binding?.classes.action)} href={value(banner, "buttonUrl")}>{value(banner, "buttonLabel")}</a>}
|
|
10284
|
+
</div>
|
|
10285
|
+
</article>)}
|
|
10286
|
+
</section>;
|
|
10287
|
+
}
|
|
10288
|
+
|
|
10289
|
+
function Products({ section, binding, products, site }: { section: ThemeHomeSection; binding?: Binding; products: HomeProps["products"]; site: HomeProps["site"] }) {
|
|
10290
|
+
const category = value(section.data, "categorySlug");
|
|
10291
|
+
const visible = products.filter((product) => !category || product.categories.some((item) => item.slug === category) || product.categoryPath?.includes(category)).slice(0, limit(section.data));
|
|
10292
|
+
if (!visible.length) return null;
|
|
10293
|
+
return <section className={cx("nuvler-migrated-section", binding?.classes.root)}>
|
|
10294
|
+
{heading(section, binding)}
|
|
10295
|
+
<div className={binding?.classes.grid}><ProductGrid products={visible} columns={site.settings?.catalog?.desktopColumns || 3} showCategory={site.settings?.catalog?.showCategory} showDescription={site.settings?.catalog?.showDescription} /></div>
|
|
10296
|
+
</section>;
|
|
10297
|
+
}
|
|
10298
|
+
|
|
10299
|
+
function EditorialCards({ section, binding, items, basePath }: { section: ThemeHomeSection; binding?: Binding; items: ThemeEditorialItem[]; basePath: string }) {
|
|
10300
|
+
const visible = items.slice(0, limit(section.data));
|
|
10301
|
+
if (!visible.length) return null;
|
|
10302
|
+
return <section className={cx("nuvler-migrated-section", binding?.classes.root)}>
|
|
10303
|
+
{heading(section, binding)}
|
|
10304
|
+
<div className={cx("nuvler-migrated-editorial-grid", binding?.classes.grid)}>{visible.map((item) => {
|
|
10305
|
+
const image = item.image ?? item.thumbnail ?? item.coverImage;
|
|
10306
|
+
return <article className={cx("nuvler-migrated-editorial-card", binding?.classes.card)} key={item.slug}>
|
|
10307
|
+
{image?.url && <a className={binding?.classes.media} href={\`\${basePath}/\${item.slug}\`}><img src={image.url} alt={image.alt || item.title} /></a>}
|
|
10308
|
+
<div className={binding?.classes.content}><h3 className={binding?.classes.title}><a href={\`\${basePath}/\${item.slug}\`}>{item.title}</a></h3>{item.description && <p className={binding?.classes.text}>{item.description}</p>}</div>
|
|
10309
|
+
</article>;
|
|
10310
|
+
})}</div>
|
|
10311
|
+
</section>;
|
|
10312
|
+
}
|
|
10313
|
+
|
|
10314
|
+
function ConfiguredSection({ section, binding, products, posts, services, cases, site, submitContact }: { section: ThemeHomeSection; binding?: Binding } & Pick<HomeProps, "products" | "posts" | "services" | "cases" | "site" | "submitContact">) {
|
|
10315
|
+
if (section.type === "theme-component") return <ThemeComponent section={section} binding={binding} submitContact={submitContact} />;
|
|
10316
|
+
if (section.type === "banner-carousel") return <Banners section={section} binding={binding} />;
|
|
10317
|
+
if (section.type === "products-grid" || section.type === "products-carousel") return <Products section={section} binding={binding} products={products} site={site} />;
|
|
10318
|
+
if (section.type === "services-grid") return <EditorialCards section={section} binding={binding} items={services} basePath="/servicos" />;
|
|
10319
|
+
if (section.type === "blog-grid") return <EditorialCards section={section} binding={binding} items={posts} basePath="/blog" />;
|
|
10320
|
+
if (section.type === "cases-grid") return <EditorialCards section={section} binding={binding} items={cases} basePath="/cases" />;
|
|
10321
|
+
return <TextSection section={section} binding={binding} />;
|
|
10322
|
+
}
|
|
10323
|
+
|
|
10324
|
+
export function Home({ sections, products, posts, services, cases, site, submitContact }: HomeProps) {
|
|
10325
|
+
const enabled = sections.filter((item) => item.enabled).sort((left, right) => left.order - right.order);
|
|
10326
|
+
return <main className=${classes("nuvler-migrated-home", home.root)}>
|
|
10327
|
+
{enabled.map((item, index) => <ConfiguredSection section={item} binding={bindingFor(item, index, enabled)} products={products} posts={posts} services={services} cases={cases} site={site} submitContact={submitContact} key={item.id || \`\${item.type}-\${item.order}\`} />)}
|
|
10328
|
+
</main>;
|
|
10329
|
+
}
|
|
10330
|
+
`;
|
|
10331
|
+
}
|
|
10332
|
+
function migratedContentSource(plan) {
|
|
10333
|
+
const metadata = plan.contentBindings.map(({ id, type, order, componentKey }) => ({
|
|
10334
|
+
id,
|
|
10335
|
+
type,
|
|
10336
|
+
order,
|
|
10337
|
+
componentKey
|
|
10338
|
+
}));
|
|
10339
|
+
return `import { createContext, useContext, type FormEvent, type ReactNode } from "react";
|
|
10340
|
+
import type { HomeProps, ThemeHomeSection } from "@nuvler/theme-sdk";
|
|
10341
|
+
|
|
10342
|
+
const MigratedContentContext = createContext<HomeProps | null>(null);
|
|
10343
|
+
const bindingMetadata: ReadonlyArray<{ id: string; type: ThemeHomeSection["type"]; order: number; componentKey?: string }> = ${JSON.stringify(metadata, null, 2)};
|
|
10344
|
+
|
|
10345
|
+
export function MigratedContentProvider({ children, ...props }: HomeProps & { children: ReactNode }) {
|
|
10346
|
+
return <MigratedContentContext.Provider value={props}>{children}</MigratedContentContext.Provider>;
|
|
10347
|
+
}
|
|
10348
|
+
|
|
10349
|
+
function configuredSection(id: string, sections: ThemeHomeSection[]): ThemeHomeSection | undefined {
|
|
10350
|
+
const exact = sections.find((section) => section.id === id);
|
|
10351
|
+
if (exact) return exact;
|
|
10352
|
+
const binding = bindingMetadata.find((candidate) => candidate.id === id);
|
|
10353
|
+
if (!binding) return undefined;
|
|
10354
|
+
if (binding.type === "theme-component" && binding.componentKey) {
|
|
10355
|
+
const custom = sections.find((section) => section.enabled
|
|
10356
|
+
&& section.type === "theme-component"
|
|
10357
|
+
&& section.data.componentKey === binding.componentKey);
|
|
10358
|
+
return custom;
|
|
10359
|
+
}
|
|
10360
|
+
const occurrence = bindingMetadata.filter((candidate) => candidate.type === binding.type && candidate.order < binding.order).length;
|
|
10361
|
+
return sections.filter((section) => section.enabled && section.type === binding.type).sort((left, right) => left.order - right.order)[occurrence];
|
|
10362
|
+
}
|
|
10363
|
+
|
|
10364
|
+
export function useMigratedSection(id: string): Record<string, unknown> {
|
|
10365
|
+
const context = useContext(MigratedContentContext);
|
|
10366
|
+
if (!context) return {};
|
|
10367
|
+
if (id === "__header" || id === "__footer") {
|
|
10368
|
+
const name = context.site.settings?.siteName || context.site.tenant.name;
|
|
10369
|
+
const items = (context.menu ?? []).map((item) => ({ label: item.label, title: item.label, href: item.href, url: item.href }));
|
|
10370
|
+
return {
|
|
10371
|
+
title: name,
|
|
10372
|
+
description: context.site.settings?.description || "",
|
|
10373
|
+
image: context.site.settings?.logo || null,
|
|
10374
|
+
imageUrl: context.site.settings?.logo?.url || "",
|
|
10375
|
+
imageAlt: context.site.settings?.logo?.alt || name,
|
|
10376
|
+
buttonLabel: "",
|
|
10377
|
+
buttonUrl: "",
|
|
10378
|
+
items,
|
|
10379
|
+
};
|
|
10380
|
+
}
|
|
10381
|
+
const section = configuredSection(id, context.sections);
|
|
10382
|
+
if (!section) return {};
|
|
10383
|
+
if (section.type === "theme-component") {
|
|
10384
|
+
const props = section.data.props;
|
|
10385
|
+
return props && typeof props === "object" && !Array.isArray(props)
|
|
10386
|
+
? props as Record<string, unknown>
|
|
10387
|
+
: {};
|
|
10388
|
+
}
|
|
10389
|
+
return section.data;
|
|
10390
|
+
}
|
|
10391
|
+
|
|
10392
|
+
export function useMigratedContactForm(id: string) {
|
|
10393
|
+
const context = useContext(MigratedContentContext);
|
|
10394
|
+
return async (event: FormEvent<HTMLFormElement>): Promise<void> => {
|
|
10395
|
+
event.preventDefault();
|
|
10396
|
+
const element = event.currentTarget;
|
|
10397
|
+
if (!context?.submitContact) {
|
|
10398
|
+
element.dataset.nuvlerStatus = "unavailable";
|
|
10399
|
+
element.dispatchEvent(new CustomEvent("nuvler:contact-error", { detail: { message: "Envio de contatos indisponível." } }));
|
|
10400
|
+
return;
|
|
10401
|
+
}
|
|
10402
|
+
const section = configuredSection(id, context.sections);
|
|
10403
|
+
const form = new FormData(element);
|
|
10404
|
+
const values: Record<string, string | boolean | string[]> = {};
|
|
10405
|
+
const configuredFields = section?.type === "theme-component" && section.data.props && typeof section.data.props === "object" && !Array.isArray(section.data.props)
|
|
10406
|
+
? migratedItems(section.data.props as Record<string, unknown>, "fields")
|
|
10407
|
+
: [];
|
|
10408
|
+
for (const field of configuredFields) {
|
|
10409
|
+
const key = stringValue(field, "key");
|
|
10410
|
+
if (key && stringValue(field, "type") === "checkbox") values[key] = form.has(key);
|
|
10411
|
+
}
|
|
10412
|
+
for (const key of new Set([...form.keys()])) {
|
|
10413
|
+
const entries = form.getAll(key).filter((value): value is string => typeof value === "string");
|
|
10414
|
+
values[key] = entries.length > 1 ? entries : entries[0] ?? "";
|
|
10415
|
+
}
|
|
10416
|
+
element.dataset.nuvlerStatus = "sending";
|
|
10417
|
+
try {
|
|
10418
|
+
const result = await context.submitContact({
|
|
10419
|
+
formKey: section?.type === "theme-component" && typeof section.data.componentKey === "string" ? section.data.componentKey : "contact-form",
|
|
10420
|
+
sectionId: section?.id,
|
|
10421
|
+
values,
|
|
10422
|
+
pathname: typeof window === "undefined" ? undefined : window.location.pathname,
|
|
10423
|
+
});
|
|
10424
|
+
element.reset();
|
|
10425
|
+
element.dataset.nuvlerStatus = "success";
|
|
10426
|
+
element.dispatchEvent(new CustomEvent("nuvler:contact-success", { detail: result }));
|
|
10427
|
+
} catch (cause) {
|
|
10428
|
+
const message = cause instanceof Error ? cause.message : "Não foi possível enviar o contato.";
|
|
10429
|
+
element.dataset.nuvlerStatus = "error";
|
|
10430
|
+
element.dispatchEvent(new CustomEvent("nuvler:contact-error", { detail: { message } }));
|
|
10431
|
+
}
|
|
10432
|
+
};
|
|
10433
|
+
}
|
|
10434
|
+
|
|
10435
|
+
export function migratedItems(
|
|
10436
|
+
data: Record<string, unknown>,
|
|
10437
|
+
field = "items",
|
|
10438
|
+
presentation: Record<string, unknown>[] = [],
|
|
10439
|
+
): Record<string, unknown>[] {
|
|
10440
|
+
const value = data[field];
|
|
10441
|
+
return Array.isArray(value)
|
|
10442
|
+
? value
|
|
10443
|
+
.filter((item): item is Record<string, unknown> => Boolean(item) && typeof item === "object" && !Array.isArray(item))
|
|
10444
|
+
.map((item, index) => {
|
|
10445
|
+
const title = item.title ?? item.label ?? item.name;
|
|
10446
|
+
const description = item.description ?? item.desc ?? item.text ?? item.sub;
|
|
10447
|
+
const normalized = {
|
|
10448
|
+
...item,
|
|
10449
|
+
...(title === undefined ? {} : { title, label: item.label ?? title }),
|
|
10450
|
+
...(description === undefined ? {} : {
|
|
10451
|
+
description,
|
|
10452
|
+
desc: item.desc ?? description,
|
|
10453
|
+
sub: item.sub ?? description,
|
|
10454
|
+
}),
|
|
10455
|
+
};
|
|
10456
|
+
return presentation.length
|
|
10457
|
+
? { ...presentation[index % presentation.length], ...normalized }
|
|
10458
|
+
: normalized;
|
|
10459
|
+
})
|
|
10460
|
+
: [];
|
|
10461
|
+
}
|
|
10462
|
+
|
|
10463
|
+
export function MigratedContactFields({ data }: { data: Record<string, unknown> }) {
|
|
10464
|
+
const configured = migratedItems(data, "fields");
|
|
10465
|
+
const fields = configured;
|
|
10466
|
+
return <>
|
|
10467
|
+
{fields.map((field) => {
|
|
10468
|
+
const key = stringValue(field, "key");
|
|
10469
|
+
const type = stringValue(field, "type") || "text";
|
|
10470
|
+
if (!key) return null;
|
|
10471
|
+
if (type === "checkbox") return <label className="nuvler-migrated-form-wide nuvler-migrated-checkbox" data-field-key={key} key={key}>
|
|
10472
|
+
<input name={key} required={field.required === true} type="checkbox" value="true" />
|
|
10473
|
+
<span>{stringValue(field, "label") || key}{field.required === true ? " *" : ""}</span>
|
|
10474
|
+
</label>;
|
|
10475
|
+
if (type === "select") return <label data-field-key={key} key={key}>
|
|
10476
|
+
<span>{stringValue(field, "label") || key}{field.required === true ? " *" : ""}</span>
|
|
10477
|
+
<select name={key} required={field.required === true}>{migratedItems(field, "options").map((option) => <option key={stringValue(option, "value")} value={stringValue(option, "value")}>{stringValue(option, "label") || stringValue(option, "value")}</option>)}</select>
|
|
10478
|
+
</label>;
|
|
10479
|
+
return <label data-field-key={key} key={key}>
|
|
10480
|
+
<span>{stringValue(field, "label") || key}{field.required === true ? " *" : ""}</span>
|
|
10481
|
+
{type === "textarea"
|
|
10482
|
+
? <textarea name={key} placeholder={stringValue(field, "placeholder")} required={field.required === true} rows={5} />
|
|
10483
|
+
: <input name={key} placeholder={stringValue(field, "placeholder")} required={field.required === true} type={["email", "tel", "url", "number"].includes(type) ? type : "text"} />}
|
|
10484
|
+
</label>;
|
|
10485
|
+
})}
|
|
10486
|
+
<button type="submit">{stringValue(data, "submitLabel")}</button>
|
|
10487
|
+
</>;
|
|
10488
|
+
}
|
|
10489
|
+
|
|
10490
|
+
function stringValue(data: Record<string, unknown>, key: string): string {
|
|
10491
|
+
const candidate = data[key];
|
|
10492
|
+
return typeof candidate === "string" ? candidate : "";
|
|
10493
|
+
}
|
|
10494
|
+
|
|
10495
|
+
export function migratedText(data: Record<string, unknown>, field: string): string {
|
|
10496
|
+
if (field === "description") return stringValue(data, "description") || stringValue(data, "text") || stringValue(data, "content");
|
|
10497
|
+
return stringValue(data, field);
|
|
10498
|
+
}
|
|
10499
|
+
|
|
10500
|
+
export function migratedImage(data: Record<string, unknown>): string | undefined {
|
|
10501
|
+
const image = data.image && typeof data.image === "object" && !Array.isArray(data.image)
|
|
10502
|
+
? data.image as Record<string, unknown>
|
|
10503
|
+
: null;
|
|
10504
|
+
return (image ? stringValue(image, "url") : "") || stringValue(data, "imageUrl") || stringValue(data, "posterImageUrl") || undefined;
|
|
10505
|
+
}
|
|
10506
|
+
|
|
10507
|
+
export function migratedVideo(data: Record<string, unknown>): string | undefined {
|
|
10508
|
+
return stringValue(data, "videoUrl") || undefined;
|
|
10509
|
+
}
|
|
10510
|
+
|
|
10511
|
+
export function migratedLink(data: Record<string, unknown>): string | undefined {
|
|
10512
|
+
return stringValue(data, "buttonUrl") || undefined;
|
|
10513
|
+
}
|
|
10514
|
+
`;
|
|
10515
|
+
}
|
|
10516
|
+
function migratedNextImageSource() {
|
|
10517
|
+
return `import type { CSSProperties, ImgHTMLAttributes } from "react";
|
|
10518
|
+
|
|
10519
|
+
type StaticImage = { src: string; width?: number; height?: number };
|
|
10520
|
+
type MigratedNextImageProps = Omit<ImgHTMLAttributes<HTMLImageElement>, "src"> & {
|
|
10521
|
+
src: string | StaticImage;
|
|
10522
|
+
alt: string;
|
|
10523
|
+
fill?: boolean;
|
|
10524
|
+
priority?: boolean;
|
|
10525
|
+
quality?: number;
|
|
10526
|
+
placeholder?: string;
|
|
10527
|
+
blurDataURL?: string;
|
|
10528
|
+
onLoadingComplete?: (image: HTMLImageElement) => void;
|
|
10529
|
+
};
|
|
10530
|
+
|
|
10531
|
+
/** Adaptador browser-safe para projetos Next.js executados no preview Vite. */
|
|
10532
|
+
export default function MigratedNextImage({
|
|
10533
|
+
src, alt, fill, priority, quality: _quality, placeholder: _placeholder,
|
|
10534
|
+
blurDataURL: _blurDataURL, onLoadingComplete, style, ...props
|
|
10535
|
+
}: MigratedNextImageProps) {
|
|
10536
|
+
const url = typeof src === "string" ? src : src?.src;
|
|
10537
|
+
if (!url) return null;
|
|
10538
|
+
const fillStyle: CSSProperties | undefined = fill
|
|
10539
|
+
? { position: "absolute", inset: 0, width: "100%", height: "100%", ...style }
|
|
10540
|
+
: style;
|
|
10541
|
+
return <img
|
|
10542
|
+
{...props}
|
|
10543
|
+
src={url}
|
|
10544
|
+
alt={alt || ""}
|
|
10545
|
+
loading={priority ? "eager" : props.loading}
|
|
10546
|
+
style={fillStyle}
|
|
10547
|
+
onLoad={onLoadingComplete ? (event) => onLoadingComplete(event.currentTarget) : props.onLoad}
|
|
10548
|
+
/>;
|
|
10549
|
+
}
|
|
10550
|
+
`;
|
|
10551
|
+
}
|
|
10552
|
+
function definitionSource(plan) {
|
|
10553
|
+
const tokens = plan.tokens;
|
|
10554
|
+
const fallbackSections = plan.contentBindings.map((binding) => ({
|
|
10555
|
+
id: binding.id,
|
|
10556
|
+
type: binding.type,
|
|
10557
|
+
enabled: true,
|
|
10558
|
+
order: binding.order,
|
|
10559
|
+
data: blankBindingData(binding)
|
|
10560
|
+
}));
|
|
10561
|
+
return `import manifestData from "../nuvler.theme.json" with { type: "json" };
|
|
10562
|
+
import { defineTheme, type ThemeHomeSection, type ThemeManifest } from "@nuvler/theme-sdk";
|
|
10563
|
+
import { Footer } from "./components/Footer.js";
|
|
10564
|
+
import { Header } from "./components/Header.js";
|
|
10565
|
+
import { ProductDetail } from "./components/ProductDetail.js";
|
|
10566
|
+
import { ProductGrid } from "./components/ProductGrid.js";
|
|
10567
|
+
import { Home } from "./sections/Home.js";
|
|
10568
|
+
|
|
10569
|
+
const migratedSections: ThemeHomeSection[] = ${JSON.stringify(fallbackSections, null, 2)};
|
|
10570
|
+
|
|
10571
|
+
export const manifest = manifestData as ThemeManifest;
|
|
10572
|
+
export const themeDefinition = defineTheme({
|
|
10573
|
+
manifest,
|
|
10574
|
+
tokens: {
|
|
10575
|
+
colors: ${JSON.stringify({
|
|
10576
|
+
primary: tokens.primary,
|
|
10577
|
+
primaryText: tokens.primaryText,
|
|
10578
|
+
secondary: tokens.secondary,
|
|
10579
|
+
secondaryText: tokens.secondaryText,
|
|
10580
|
+
accent: tokens.accent,
|
|
10581
|
+
background: tokens.background,
|
|
10582
|
+
surface: tokens.surface,
|
|
10583
|
+
surfaceAlt: tokens.surfaceAlt,
|
|
10584
|
+
text: tokens.text,
|
|
10585
|
+
textMuted: tokens.textMuted,
|
|
10586
|
+
border: tokens.border,
|
|
10587
|
+
headerBackground: tokens.headerBackground,
|
|
10588
|
+
headerText: tokens.headerText,
|
|
10589
|
+
footerBackground: tokens.footerBackground,
|
|
10590
|
+
footerText: tokens.footerText
|
|
10591
|
+
})},
|
|
10592
|
+
layout: ${JSON.stringify({
|
|
10593
|
+
containerWidth: tokens.containerWidth,
|
|
10594
|
+
borderRadius: tokens.borderRadius
|
|
10595
|
+
})},
|
|
10596
|
+
},
|
|
10597
|
+
template: {
|
|
10598
|
+
announcement: "",
|
|
10599
|
+
footerTagline: "",
|
|
10600
|
+
footerNavigationLabel: "Navegação",
|
|
10601
|
+
footerNote: "",
|
|
10602
|
+
socialLabel: "Redes sociais",
|
|
10603
|
+
benefits: [],
|
|
10604
|
+
fallbackSections: () => migratedSections.map((section) => ({ ...section, data: { ...section.data } })),
|
|
10605
|
+
primaryAction: (modules) => modules.includes("PRODUCTS") ? { label: "Ver produtos", href: "/produtos" } : { label: "Saiba mais", href: "/" },
|
|
10606
|
+
},
|
|
10607
|
+
components: { Header, Footer, Home, ProductGrid, ProductDetail },
|
|
10608
|
+
});
|
|
10609
|
+
`;
|
|
10610
|
+
}
|
|
10611
|
+
function catalogPageSource() {
|
|
10612
|
+
return `import type { ThemeRoute, ThemeSite } from "@nuvler/theme-sdk";
|
|
10613
|
+
import { ProductGrid } from "../components/ProductGrid.js";
|
|
10614
|
+
|
|
10615
|
+
type CatalogRoute = Extract<ThemeRoute, { type: "catalog" }>;
|
|
10616
|
+
|
|
10617
|
+
export function CatalogPage({ route, site }: { route: CatalogRoute; site: ThemeSite }) {
|
|
10618
|
+
return <main className="nuvler-migrated-section nuvler-migrated-catalog">
|
|
10619
|
+
<header><span>Catálogo</span><h1>{route.search ? \`Busca: \${route.search}\` : "Produtos"}</h1><p>{route.pagination.total} produto(s)</p></header>
|
|
10620
|
+
<ProductGrid products={route.products} columns={site.settings?.catalog?.desktopColumns || 3} showCategory={site.settings?.catalog?.showCategory} showDescription={site.settings?.catalog?.showDescription} />
|
|
10621
|
+
</main>;
|
|
10622
|
+
}
|
|
10623
|
+
`;
|
|
10624
|
+
}
|
|
10625
|
+
function productPageSource() {
|
|
10626
|
+
return `import type { ThemeRoute, ThemeRuntimeSdk, ThemeSite } from "@nuvler/theme-sdk";
|
|
10627
|
+
import { ProductDetail } from "../components/ProductDetail.js";
|
|
10628
|
+
|
|
10629
|
+
type ProductRoute = Extract<ThemeRoute, { type: "product" }>;
|
|
10630
|
+
|
|
10631
|
+
export function ProductPage({ route, site, cart }: { route: ProductRoute; site: ThemeSite; cart?: ThemeRuntimeSdk["cart"] }) {
|
|
10632
|
+
return <main className="nuvler-migrated-section"><ProductDetail product={route.product} contact={site.settings?.contact} productUrl={null} descriptionContent={<p>{route.product.description}</p>} onAddToCart={cart?.add} /></main>;
|
|
10633
|
+
}
|
|
10634
|
+
`;
|
|
10635
|
+
}
|
|
10636
|
+
function editorialPageSource() {
|
|
10637
|
+
return `import type { ThemeRoute } from "@nuvler/theme-sdk";
|
|
10638
|
+
|
|
10639
|
+
type EditorialRoute = Extract<ThemeRoute, { type: "editorial-list" | "editorial-detail" }>;
|
|
10640
|
+
|
|
10641
|
+
export function EditorialPage({ route }: { route: EditorialRoute }) {
|
|
10642
|
+
if (route.type === "editorial-detail") return <main className="nuvler-migrated-section"><article><span>Conteúdo</span><h1>{route.item.title}</h1><p>{route.item.description}</p></article></main>;
|
|
10643
|
+
return <main className="nuvler-migrated-section"><h1>{route.title}</h1><div className="nuvler-migrated-editorial-grid">{route.items.map((item) => <article key={item.slug}><h2><a href={\`\${route.basePath}/\${item.slug}\`}>{item.title}</a></h2><p>{item.description}</p></article>)}</div></main>;
|
|
10644
|
+
}
|
|
10645
|
+
`;
|
|
10646
|
+
}
|
|
10647
|
+
function statePageSource() {
|
|
10648
|
+
return `export function StatePage({ title, pathname }: { title: string; pathname?: string }) {
|
|
10649
|
+
return <main className="nuvler-migrated-section nuvler-migrated-state"><span>{pathname || "Nuvler"}</span><h1>{title}</h1></main>;
|
|
10650
|
+
}
|
|
10651
|
+
`;
|
|
10652
|
+
}
|
|
10653
|
+
function themeSource(hasFidelityHome) {
|
|
10654
|
+
return `import type { CSSProperties } from "react";
|
|
10655
|
+
import type { NuvlerThemeProps, ThemeSite } from "@nuvler/theme-sdk";
|
|
10656
|
+
import { themeDefinition } from "./definition.js";
|
|
10657
|
+
import { CatalogPage } from "./pages/CatalogPage.js";
|
|
10658
|
+
import { EditorialPage } from "./pages/EditorialPage.js";
|
|
10659
|
+
import { ProductPage } from "./pages/ProductPage.js";
|
|
10660
|
+
import { StatePage } from "./pages/StatePage.js";
|
|
10661
|
+
import "./styles/theme.css";
|
|
10662
|
+
|
|
10663
|
+
export { manifest, themeDefinition } from "./definition.js";
|
|
10664
|
+
|
|
10665
|
+
export default function Theme({ context, route = { type: "home" }, sdk }: NuvlerThemeProps) {
|
|
10666
|
+
const { Header, Footer, Home } = themeDefinition.components;
|
|
10667
|
+
const site: ThemeSite = { tenant: context.store, ...context.site };
|
|
10668
|
+
const configured = site.settings?.theme;
|
|
10669
|
+
const tokens = {
|
|
10670
|
+
colors: { ...themeDefinition.tokens.colors, ...configured?.colors },
|
|
10671
|
+
layout: { ...themeDefinition.tokens.layout, ...configured?.layout },
|
|
10672
|
+
};
|
|
10673
|
+
const style = {
|
|
10674
|
+
"--theme-primary": tokens.colors.primary,
|
|
10675
|
+
"--theme-primary-text": tokens.colors.primaryText,
|
|
10676
|
+
"--theme-secondary": tokens.colors.secondary,
|
|
10677
|
+
"--theme-secondary-text": tokens.colors.secondaryText,
|
|
10678
|
+
"--theme-accent": tokens.colors.accent,
|
|
10679
|
+
"--theme-background": tokens.colors.background,
|
|
10680
|
+
"--theme-surface": tokens.colors.surface,
|
|
10681
|
+
"--theme-surface-alt": tokens.colors.surfaceAlt,
|
|
10682
|
+
"--theme-text": tokens.colors.text,
|
|
10683
|
+
"--theme-text-muted": tokens.colors.textMuted,
|
|
10684
|
+
"--theme-border": tokens.colors.border,
|
|
10685
|
+
"--theme-header-background": tokens.colors.headerBackground,
|
|
10686
|
+
"--theme-header-text": tokens.colors.headerText,
|
|
10687
|
+
"--theme-footer-background": tokens.colors.footerBackground,
|
|
10688
|
+
"--theme-footer-text": tokens.colors.footerText,
|
|
10689
|
+
"--theme-radius": \`\${tokens.layout.borderRadius}px\`,
|
|
10690
|
+
"--theme-container": \`\${tokens.layout.containerWidth}px\`,
|
|
10691
|
+
} as CSSProperties;
|
|
10692
|
+
const homeSections = context.home.content.sections.length
|
|
10693
|
+
? context.home.content.sections
|
|
10694
|
+
: themeDefinition.template.fallbackSections();
|
|
10695
|
+
let content;
|
|
10696
|
+
if (route.type === "home") content = <Home sections={homeSections} products={context.catalog.products} posts={context.editorial.posts} services={context.editorial.services} cases={context.editorial.cases} site={site} menu={context.navigation.menu} pages={context.navigation.pages} submitContact={sdk?.contact?.submit} template={themeDefinition.template} />;
|
|
10697
|
+
else if (route.type === "catalog") content = <CatalogPage route={route} site={site} />;
|
|
10698
|
+
else if (route.type === "product") content = <ProductPage route={route} site={site} cart={sdk?.cart} />;
|
|
10699
|
+
else if (route.type === "editorial-list" || route.type === "editorial-detail") content = <EditorialPage route={route} />;
|
|
10700
|
+
else content = <StatePage title={route.type === "loading" ? "Carregando…" : route.type === "page" ? route.title : "Conteúdo não encontrado"} pathname={"pathname" in route ? route.pathname : undefined} />;
|
|
10701
|
+
if (${JSON.stringify(hasFidelityHome)} && route.type === "home") {
|
|
10702
|
+
return <div className="nuvler-migrated-theme nuvler-migrated-fidelity" style={style}>{content}</div>;
|
|
10703
|
+
}
|
|
10704
|
+
return <div className="nuvler-migrated-theme" style={style}><Header site={site} categories={context.navigation.categories} pages={context.navigation.pages} template={themeDefinition.template} /><div className="nuvler-migrated-page">{content}</div><Footer site={site} pages={context.navigation.pages} template={themeDefinition.template} /></div>;
|
|
10705
|
+
}
|
|
10706
|
+
`;
|
|
10707
|
+
}
|
|
10708
|
+
function blankSectionData(type) {
|
|
10709
|
+
if (type === "banner-carousel") return {
|
|
10710
|
+
banners: [],
|
|
10711
|
+
autoplay: true
|
|
10712
|
+
};
|
|
10713
|
+
if (type === "hero") return {
|
|
10714
|
+
eyebrow: "",
|
|
10715
|
+
title: "",
|
|
10716
|
+
description: "",
|
|
10717
|
+
imageId: "",
|
|
10718
|
+
imageUrl: "",
|
|
10719
|
+
imageAlt: "",
|
|
10720
|
+
buttonLabel: "",
|
|
10721
|
+
buttonUrl: ""
|
|
10722
|
+
};
|
|
10723
|
+
if (type === "image-text") return {
|
|
10724
|
+
eyebrow: "",
|
|
10725
|
+
title: "",
|
|
10726
|
+
description: "",
|
|
10727
|
+
imageId: "",
|
|
10728
|
+
imageUrl: "",
|
|
10729
|
+
imageAlt: "",
|
|
10730
|
+
imagePosition: "left"
|
|
10731
|
+
};
|
|
10732
|
+
if (type === "rich-text") return {
|
|
10733
|
+
eyebrow: "",
|
|
10734
|
+
title: "",
|
|
10735
|
+
text: ""
|
|
10736
|
+
};
|
|
10737
|
+
if (type === "cta") return {
|
|
10738
|
+
eyebrow: "",
|
|
10739
|
+
title: "",
|
|
10740
|
+
description: "",
|
|
10741
|
+
buttonLabel: "",
|
|
10742
|
+
buttonUrl: ""
|
|
10743
|
+
};
|
|
10744
|
+
if (type === "products-grid" || type === "products-carousel") return {
|
|
10745
|
+
eyebrow: "",
|
|
10746
|
+
title: "",
|
|
10747
|
+
limit: 6,
|
|
10748
|
+
categorySlug: ""
|
|
10749
|
+
};
|
|
10750
|
+
if (type === "theme-component") return {
|
|
10751
|
+
componentKey: "custom-component",
|
|
10752
|
+
schemaVersion: 1,
|
|
10753
|
+
props: {}
|
|
10754
|
+
};
|
|
10755
|
+
return {
|
|
10756
|
+
eyebrow: "",
|
|
10757
|
+
title: "",
|
|
10758
|
+
limit: 6
|
|
10759
|
+
};
|
|
10760
|
+
}
|
|
10761
|
+
function blankBindingData(binding) {
|
|
10762
|
+
if (binding.type !== "theme-component" || !binding.componentDefinition || !binding.componentKey) return blankSectionData(binding.type);
|
|
10763
|
+
const props = {};
|
|
10764
|
+
for (const field of binding.componentDefinition.fields) if (field.defaultValue !== void 0) props[field.key] = field.defaultValue;
|
|
10765
|
+
else if (field.control === "repeater") props[field.key] = [];
|
|
10766
|
+
else if (field.control === "contact-fields") props[field.key] = [];
|
|
10767
|
+
else if (field.control === "boolean") props[field.key] = false;
|
|
10768
|
+
else if (field.control === "number") props[field.key] = field.min ?? 0;
|
|
10769
|
+
else props[field.key] = "";
|
|
10770
|
+
return {
|
|
10771
|
+
componentKey: binding.componentKey,
|
|
10772
|
+
schemaVersion: binding.componentDefinition.schemaVersion,
|
|
10773
|
+
props
|
|
10774
|
+
};
|
|
10775
|
+
}
|
|
10776
|
+
/** Mirrors the labels shown by the Gestão Home builder. */
|
|
10777
|
+
var PANEL_SECTION_DEFINITIONS = {
|
|
10778
|
+
hero: {
|
|
10779
|
+
name: "Banner principal",
|
|
10780
|
+
category: "Destaques",
|
|
10781
|
+
description: "Uma abertura marcante com imagem, texto e botão.",
|
|
10782
|
+
controls: [
|
|
10783
|
+
{
|
|
10784
|
+
label: "Imagem do banner principal",
|
|
10785
|
+
fields: [
|
|
10786
|
+
"imageId",
|
|
10787
|
+
"imageUrl",
|
|
10788
|
+
"imageAlt"
|
|
10789
|
+
],
|
|
10790
|
+
note: "Ao escolher a imagem, URL e texto alternativo são preenchidos pelo painel."
|
|
10791
|
+
},
|
|
10792
|
+
{
|
|
10793
|
+
label: "Chamada pequena",
|
|
10794
|
+
fields: ["eyebrow"]
|
|
10795
|
+
},
|
|
10796
|
+
{
|
|
10797
|
+
label: "Título da seção",
|
|
10798
|
+
fields: ["title"]
|
|
10799
|
+
},
|
|
10800
|
+
{
|
|
10801
|
+
label: "Descrição",
|
|
10802
|
+
fields: ["description"]
|
|
10803
|
+
},
|
|
10804
|
+
{
|
|
10805
|
+
label: "Texto do botão",
|
|
10806
|
+
fields: ["buttonLabel"]
|
|
10807
|
+
},
|
|
10808
|
+
{
|
|
10809
|
+
label: "Destino do botão",
|
|
10810
|
+
fields: ["buttonUrl"]
|
|
10811
|
+
}
|
|
10812
|
+
]
|
|
10813
|
+
},
|
|
10814
|
+
"banner-carousel": {
|
|
10815
|
+
name: "Carrossel de banners",
|
|
10816
|
+
category: "Destaques",
|
|
10817
|
+
description: "Vários destaques alternando no topo da página.",
|
|
10818
|
+
controls: [{
|
|
10819
|
+
label: "Troca automática",
|
|
10820
|
+
fields: ["autoplay"]
|
|
10821
|
+
}, {
|
|
10822
|
+
label: "Banner 1, Banner 2…",
|
|
10823
|
+
fields: ["banners"],
|
|
10824
|
+
note: "Em cada banner: Imagem, Título, Descrição, Texto do botão e Destino do botão."
|
|
10825
|
+
}]
|
|
10826
|
+
},
|
|
10827
|
+
"image-text": {
|
|
10828
|
+
name: "Imagem e texto",
|
|
10829
|
+
category: "Conteúdo",
|
|
10830
|
+
description: "Apresente uma história com conteúdo lado a lado.",
|
|
10831
|
+
controls: [
|
|
10832
|
+
{
|
|
10833
|
+
label: "Imagem da seção",
|
|
10834
|
+
fields: [
|
|
10835
|
+
"imageId",
|
|
10836
|
+
"imageUrl",
|
|
10837
|
+
"imageAlt"
|
|
10838
|
+
],
|
|
10839
|
+
note: "Ao escolher a imagem, URL e texto alternativo são preenchidos pelo painel."
|
|
10840
|
+
},
|
|
10841
|
+
{
|
|
10842
|
+
label: "Chamada pequena",
|
|
10843
|
+
fields: ["eyebrow"]
|
|
10844
|
+
},
|
|
10845
|
+
{
|
|
10846
|
+
label: "Título da seção",
|
|
10847
|
+
fields: ["title"]
|
|
10848
|
+
},
|
|
10849
|
+
{
|
|
10850
|
+
label: "Texto",
|
|
10851
|
+
fields: ["description"]
|
|
10852
|
+
},
|
|
10853
|
+
{
|
|
10854
|
+
label: "Posição da imagem",
|
|
10855
|
+
fields: ["imagePosition"]
|
|
10856
|
+
}
|
|
10857
|
+
]
|
|
10858
|
+
},
|
|
10859
|
+
"rich-text": {
|
|
10860
|
+
name: "Bloco de texto",
|
|
10861
|
+
category: "Conteúdo",
|
|
10862
|
+
description: "Um título e texto livre para explicar o que quiser.",
|
|
10863
|
+
controls: [
|
|
10864
|
+
{
|
|
10865
|
+
label: "Chamada pequena",
|
|
10866
|
+
fields: ["eyebrow"]
|
|
10867
|
+
},
|
|
10868
|
+
{
|
|
10869
|
+
label: "Título da seção",
|
|
10870
|
+
fields: ["title"]
|
|
10871
|
+
},
|
|
10872
|
+
{
|
|
10873
|
+
label: "Conteúdo",
|
|
10874
|
+
fields: ["text"]
|
|
10875
|
+
}
|
|
10876
|
+
]
|
|
10877
|
+
},
|
|
10878
|
+
cta: {
|
|
10879
|
+
name: "Chamada para ação",
|
|
10880
|
+
category: "Conteúdo",
|
|
10881
|
+
description: "Convide a pessoa a dar o próximo passo.",
|
|
10882
|
+
controls: [
|
|
10883
|
+
{
|
|
10884
|
+
label: "Chamada pequena",
|
|
10885
|
+
fields: ["eyebrow"]
|
|
10886
|
+
},
|
|
10887
|
+
{
|
|
10888
|
+
label: "Título da seção",
|
|
10889
|
+
fields: ["title"]
|
|
10890
|
+
},
|
|
10891
|
+
{
|
|
10892
|
+
label: "Descrição",
|
|
10893
|
+
fields: ["description"]
|
|
10894
|
+
},
|
|
10895
|
+
{
|
|
10896
|
+
label: "Texto do botão",
|
|
10897
|
+
fields: ["buttonLabel"]
|
|
10898
|
+
},
|
|
10899
|
+
{
|
|
10900
|
+
label: "Destino do botão",
|
|
10901
|
+
fields: ["buttonUrl"]
|
|
10902
|
+
}
|
|
10903
|
+
]
|
|
10904
|
+
},
|
|
10905
|
+
"services-grid": {
|
|
10906
|
+
name: "Grade de serviços",
|
|
10907
|
+
category: "Conteúdo automático",
|
|
10908
|
+
description: "Mostra automaticamente os serviços cadastrados.",
|
|
10909
|
+
controls: [
|
|
10910
|
+
{
|
|
10911
|
+
label: "Chamada pequena",
|
|
10912
|
+
fields: ["eyebrow"]
|
|
10913
|
+
},
|
|
10914
|
+
{
|
|
10915
|
+
label: "Título da seção",
|
|
10916
|
+
fields: ["title"]
|
|
10917
|
+
},
|
|
10918
|
+
{
|
|
10919
|
+
label: "Quantidade de itens",
|
|
10920
|
+
fields: ["limit"]
|
|
10921
|
+
}
|
|
10922
|
+
],
|
|
10923
|
+
contentSource: {
|
|
10924
|
+
location: "Serviços → Lista de serviços",
|
|
10925
|
+
description: "Os cards, textos e imagens da grade vêm dos serviços cadastrados."
|
|
10926
|
+
}
|
|
10927
|
+
},
|
|
10928
|
+
"blog-grid": {
|
|
10929
|
+
name: "Últimos do blog",
|
|
10930
|
+
category: "Conteúdo automático",
|
|
10931
|
+
description: "Mantém as publicações recentes em evidência.",
|
|
10932
|
+
controls: [
|
|
10933
|
+
{
|
|
10934
|
+
label: "Chamada pequena",
|
|
10935
|
+
fields: ["eyebrow"]
|
|
10936
|
+
},
|
|
10937
|
+
{
|
|
10938
|
+
label: "Título da seção",
|
|
10939
|
+
fields: ["title"]
|
|
10940
|
+
},
|
|
10941
|
+
{
|
|
10942
|
+
label: "Quantidade de itens",
|
|
10943
|
+
fields: ["limit"]
|
|
10944
|
+
}
|
|
10945
|
+
],
|
|
10946
|
+
contentSource: {
|
|
10947
|
+
location: "Blog → Postagens",
|
|
10948
|
+
description: "Os cards, textos e imagens da grade vêm das postagens publicadas."
|
|
10949
|
+
}
|
|
10950
|
+
},
|
|
10951
|
+
"cases-grid": {
|
|
10952
|
+
name: "Cases de sucesso",
|
|
10953
|
+
category: "Conteúdo automático",
|
|
10954
|
+
description: "Exibe projetos e resultados já cadastrados.",
|
|
10955
|
+
controls: [
|
|
10956
|
+
{
|
|
10957
|
+
label: "Chamada pequena",
|
|
10958
|
+
fields: ["eyebrow"]
|
|
10959
|
+
},
|
|
10960
|
+
{
|
|
10961
|
+
label: "Título da seção",
|
|
10962
|
+
fields: ["title"]
|
|
10963
|
+
},
|
|
10964
|
+
{
|
|
10965
|
+
label: "Quantidade de itens",
|
|
10966
|
+
fields: ["limit"]
|
|
10967
|
+
}
|
|
10968
|
+
],
|
|
10969
|
+
contentSource: {
|
|
10970
|
+
location: "Cases → Cases",
|
|
10971
|
+
description: "Os cards, textos e imagens da grade vêm dos cases publicados."
|
|
10972
|
+
}
|
|
10973
|
+
},
|
|
10974
|
+
"products-grid": {
|
|
10975
|
+
name: "Grade de produtos",
|
|
10976
|
+
category: "Conteúdo automático",
|
|
10977
|
+
description: "Uma vitrine organizada de produtos cadastrados.",
|
|
10978
|
+
controls: [
|
|
10979
|
+
{
|
|
10980
|
+
label: "Chamada pequena",
|
|
10981
|
+
fields: ["eyebrow"]
|
|
10982
|
+
},
|
|
10983
|
+
{
|
|
10984
|
+
label: "Título da seção",
|
|
10985
|
+
fields: ["title"]
|
|
10986
|
+
},
|
|
10987
|
+
{
|
|
10988
|
+
label: "Quantidade de itens",
|
|
10989
|
+
fields: ["limit"]
|
|
10990
|
+
},
|
|
10991
|
+
{
|
|
10992
|
+
label: "Categoria de produtos",
|
|
10993
|
+
fields: ["categorySlug"]
|
|
10994
|
+
}
|
|
10995
|
+
],
|
|
10996
|
+
contentSource: {
|
|
10997
|
+
location: "Produtos → Produtos",
|
|
10998
|
+
description: "Os cards, textos e imagens da grade vêm dos produtos cadastrados."
|
|
10999
|
+
}
|
|
11000
|
+
},
|
|
11001
|
+
"products-carousel": {
|
|
11002
|
+
name: "Carrossel de produtos",
|
|
11003
|
+
category: "Conteúdo automático",
|
|
11004
|
+
description: "Uma vitrine compacta para navegar pelos produtos.",
|
|
11005
|
+
controls: [
|
|
11006
|
+
{
|
|
11007
|
+
label: "Chamada pequena",
|
|
11008
|
+
fields: ["eyebrow"]
|
|
11009
|
+
},
|
|
11010
|
+
{
|
|
11011
|
+
label: "Título da seção",
|
|
11012
|
+
fields: ["title"]
|
|
11013
|
+
},
|
|
11014
|
+
{
|
|
11015
|
+
label: "Quantidade de itens",
|
|
11016
|
+
fields: ["limit"]
|
|
11017
|
+
},
|
|
11018
|
+
{
|
|
11019
|
+
label: "Categoria de produtos",
|
|
11020
|
+
fields: ["categorySlug"]
|
|
11021
|
+
}
|
|
11022
|
+
],
|
|
11023
|
+
contentSource: {
|
|
11024
|
+
location: "Produtos → Produtos",
|
|
11025
|
+
description: "Os cards, textos e imagens do carrossel vêm dos produtos cadastrados."
|
|
11026
|
+
}
|
|
11027
|
+
},
|
|
11028
|
+
"theme-component": {
|
|
11029
|
+
name: "Componente do tema",
|
|
11030
|
+
category: "Conteúdo",
|
|
11031
|
+
description: "Componente configurável declarado pelo tema ativo.",
|
|
11032
|
+
controls: []
|
|
11033
|
+
}
|
|
11034
|
+
};
|
|
11035
|
+
function panelDefinition(binding) {
|
|
11036
|
+
const custom = binding.componentDefinition;
|
|
11037
|
+
if (!custom) return PANEL_SECTION_DEFINITIONS[binding.type];
|
|
11038
|
+
return {
|
|
11039
|
+
name: custom.name,
|
|
11040
|
+
category: custom.category,
|
|
11041
|
+
description: custom.description,
|
|
11042
|
+
controls: custom.fields.map((field) => ({
|
|
11043
|
+
label: field.label,
|
|
11044
|
+
fields: [field.key],
|
|
11045
|
+
note: field.control === "repeater" ? "Lista repetível controlada pelo cliente no Gestão." : field.control === "contact-fields" ? "Permite escolher, ordenar e tornar obrigatórios os campos do formulário." : void 0
|
|
11046
|
+
}))
|
|
11047
|
+
};
|
|
11048
|
+
}
|
|
11049
|
+
function panelCompatibility(binding) {
|
|
11050
|
+
if (binding.type === "theme-component") return {
|
|
11051
|
+
level: "direct",
|
|
11052
|
+
label: "Direto",
|
|
11053
|
+
note: "O tema declara este componente e seus campos editáveis para o Construtor da Home."
|
|
11054
|
+
};
|
|
11055
|
+
if (binding.type !== "rich-text") return {
|
|
11056
|
+
level: "direct",
|
|
11057
|
+
label: "Direto",
|
|
11058
|
+
note: "Existe um bloco equivalente no Construtor da Home."
|
|
11059
|
+
};
|
|
11060
|
+
const component = binding.component.toLowerCase();
|
|
11061
|
+
if (/(video|faq|form|benefit|number|stat|metric|feature|evaluation|avali|app|forwhom|quem)/.test(component)) return {
|
|
11062
|
+
level: "v1-fallback",
|
|
11063
|
+
label: "Fallback V1",
|
|
11064
|
+
note: "O Gestão ainda não possui um bloco nativo para esta estrutura; na V1 apenas título e texto ficam configuráveis como Bloco de texto."
|
|
11065
|
+
};
|
|
11066
|
+
return {
|
|
11067
|
+
level: "direct",
|
|
11068
|
+
label: "Direto",
|
|
11069
|
+
note: "O conteúdo textual pode ser configurado diretamente como Bloco de texto."
|
|
11070
|
+
};
|
|
11071
|
+
}
|
|
11072
|
+
function sourceKind(file) {
|
|
11073
|
+
const extension = path.extname(file).toLowerCase();
|
|
11074
|
+
if (extension === ".tsx") return ts.ScriptKind.TSX;
|
|
11075
|
+
if (extension === ".jsx") return ts.ScriptKind.JSX;
|
|
11076
|
+
if ([
|
|
11077
|
+
".js",
|
|
11078
|
+
".mjs",
|
|
11079
|
+
".cjs"
|
|
11080
|
+
].includes(extension)) return ts.ScriptKind.JS;
|
|
11081
|
+
return ts.ScriptKind.TS;
|
|
11082
|
+
}
|
|
11083
|
+
function unwrappedExpression(expression) {
|
|
11084
|
+
if (ts.isAsExpression(expression) || ts.isTypeAssertionExpression(expression) || ts.isParenthesizedExpression(expression)) return unwrappedExpression(expression.expression);
|
|
11085
|
+
return expression;
|
|
11086
|
+
}
|
|
11087
|
+
function propertyKey(property) {
|
|
11088
|
+
if (!(ts.isPropertyAssignment(property) || ts.isShorthandPropertyAssignment(property))) return null;
|
|
11089
|
+
const name = property.name;
|
|
11090
|
+
return ts.isIdentifier(name) || ts.isStringLiteralLike(name) || ts.isNumericLiteral(name) ? name.text : null;
|
|
11091
|
+
}
|
|
11092
|
+
function propertyValue(object, key) {
|
|
11093
|
+
const property = object.properties.find((candidate) => propertyKey(candidate) === key);
|
|
11094
|
+
return property && ts.isPropertyAssignment(property) ? property.initializer : null;
|
|
11095
|
+
}
|
|
11096
|
+
function flattenStringObject(object, prefix = "", result = /* @__PURE__ */ new Map()) {
|
|
11097
|
+
for (const property of object.properties) {
|
|
11098
|
+
if (!ts.isPropertyAssignment(property)) continue;
|
|
11099
|
+
const key = propertyKey(property);
|
|
11100
|
+
if (!key) continue;
|
|
11101
|
+
const compound = prefix ? `${prefix}.${key}` : key;
|
|
11102
|
+
const value = unwrappedExpression(property.initializer);
|
|
11103
|
+
if (ts.isStringLiteralLike(value) || ts.isNoSubstitutionTemplateLiteral(value)) result.set(compound, value.text);
|
|
11104
|
+
else if (ts.isObjectLiteralExpression(value)) flattenStringObject(value, compound, result);
|
|
11105
|
+
}
|
|
11106
|
+
return result;
|
|
11107
|
+
}
|
|
11108
|
+
function translationValues(source) {
|
|
11109
|
+
const result = /* @__PURE__ */ new Map();
|
|
11110
|
+
function visit(node) {
|
|
11111
|
+
if (ts.isVariableDeclaration(node) && ts.isIdentifier(node.name) && /^(?:translations?|messages?|dictionary|locales?)$/i.test(node.name.text) && node.initializer) {
|
|
11112
|
+
const initializer = unwrappedExpression(node.initializer);
|
|
11113
|
+
if (ts.isObjectLiteralExpression(initializer)) {
|
|
11114
|
+
const locale = [
|
|
11115
|
+
"pt",
|
|
11116
|
+
"pt-BR",
|
|
11117
|
+
"pt_BR",
|
|
11118
|
+
"default"
|
|
11119
|
+
].map((key) => propertyValue(initializer, key)).find((value) => Boolean(value));
|
|
11120
|
+
const selected = locale ? unwrappedExpression(locale) : initializer;
|
|
11121
|
+
if (ts.isObjectLiteralExpression(selected)) for (const [key, value] of flattenStringObject(selected)) result.set(key, value);
|
|
11122
|
+
}
|
|
11123
|
+
}
|
|
11124
|
+
ts.forEachChild(node, visit);
|
|
11125
|
+
}
|
|
11126
|
+
visit(source);
|
|
11127
|
+
return result;
|
|
11128
|
+
}
|
|
11129
|
+
function contentField(key) {
|
|
11130
|
+
const normalized = key.toLowerCase();
|
|
11131
|
+
const last = normalized.split(".").at(-1) ?? normalized;
|
|
11132
|
+
if (/^(?:eyebrow|overline|kicker)$/.test(last)) return "eyebrow";
|
|
11133
|
+
if (/^(?:title|headline|heading)$/.test(last)) return "title";
|
|
11134
|
+
if (/^(?:subtitle|subheadline|description|desc|text|content)$/.test(last)) return "description";
|
|
11135
|
+
if (/(?:^|\.)(?:cta|button|action)(?:\.|$)/.test(normalized) || /^(?:cta|button|label)$/.test(last)) return "buttonLabel";
|
|
11136
|
+
}
|
|
11137
|
+
function jsxTagForText(node) {
|
|
11138
|
+
const parent = node.parent;
|
|
11139
|
+
return ts.isJsxElement(parent) ? parent.openingElement.tagName.getText() : "text";
|
|
11140
|
+
}
|
|
11141
|
+
function fieldForTag(tag) {
|
|
11142
|
+
if (/^h[1-6]$/i.test(tag)) return "title";
|
|
11143
|
+
if (/^(?:p|blockquote)$/i.test(tag)) return "description";
|
|
11144
|
+
if (/^(?:a|button)$/i.test(tag)) return "buttonLabel";
|
|
11145
|
+
if (/^(?:span|small)$/i.test(tag)) return "eyebrow";
|
|
11146
|
+
}
|
|
11147
|
+
function markdownCell(value) {
|
|
11148
|
+
return value.replace(/\|/g, "\\|").replace(/\r?\n/g, "<br>");
|
|
11149
|
+
}
|
|
11150
|
+
async function extractContentCatalog(plan) {
|
|
11151
|
+
const sources = /* @__PURE__ */ new Map();
|
|
11152
|
+
const translations = /* @__PURE__ */ new Map();
|
|
11153
|
+
const constantNodes = /* @__PURE__ */ new Map();
|
|
11154
|
+
const constants = /* @__PURE__ */ new Map();
|
|
11155
|
+
for (const module of plan.analysis.sourceGraph.modules.filter(({ kind }) => kind === "SOURCE")) {
|
|
11156
|
+
const content = await readFile(module.absolutePath, "utf8");
|
|
11157
|
+
const source = ts.createSourceFile(module.absolutePath, content, ts.ScriptTarget.Latest, true, sourceKind(module.absolutePath));
|
|
11158
|
+
sources.set(module.file, {
|
|
11159
|
+
source,
|
|
11160
|
+
content
|
|
11161
|
+
});
|
|
11162
|
+
for (const [key, value] of translationValues(source)) translations.set(key, value);
|
|
11163
|
+
function collectConstants(node) {
|
|
11164
|
+
if (ts.isVariableDeclaration(node) && ts.isIdentifier(node.name) && node.initializer) constantNodes.set(node.name.text, node.initializer);
|
|
11165
|
+
ts.forEachChild(node, collectConstants);
|
|
11166
|
+
}
|
|
11167
|
+
collectConstants(source);
|
|
11168
|
+
}
|
|
11169
|
+
function resolvedString(expression, stack = /* @__PURE__ */ new Set()) {
|
|
11170
|
+
const value = unwrappedExpression(expression);
|
|
11171
|
+
if (ts.isStringLiteralLike(value) || ts.isNoSubstitutionTemplateLiteral(value)) return value.text;
|
|
11172
|
+
if (ts.isIdentifier(value)) {
|
|
11173
|
+
if (constants.has(value.text)) return constants.get(value.text);
|
|
11174
|
+
if (stack.has(value.text)) return null;
|
|
11175
|
+
const initializer = constantNodes.get(value.text);
|
|
11176
|
+
if (!initializer) return null;
|
|
11177
|
+
const resolved = resolvedString(initializer, new Set(stack).add(value.text));
|
|
11178
|
+
if (resolved !== null) constants.set(value.text, resolved);
|
|
11179
|
+
return resolved;
|
|
11180
|
+
}
|
|
11181
|
+
if (ts.isTemplateExpression(value)) {
|
|
11182
|
+
let output = value.head.text;
|
|
11183
|
+
for (const span of value.templateSpans) {
|
|
11184
|
+
const resolved = resolvedString(span.expression, stack);
|
|
11185
|
+
if (resolved === null) return null;
|
|
11186
|
+
output += resolved + span.literal.text;
|
|
11187
|
+
}
|
|
11188
|
+
return output;
|
|
11189
|
+
}
|
|
11190
|
+
if (ts.isBinaryExpression(value) && value.operatorToken.kind === ts.SyntaxKind.PlusToken) {
|
|
11191
|
+
const left = resolvedString(value.left, stack);
|
|
11192
|
+
const right = resolvedString(value.right, stack);
|
|
11193
|
+
return left === null || right === null ? null : left + right;
|
|
11194
|
+
}
|
|
11195
|
+
return null;
|
|
11196
|
+
}
|
|
11197
|
+
for (const [name, expression] of constantNodes) {
|
|
11198
|
+
const value = resolvedString(expression);
|
|
11199
|
+
if (value !== null) constants.set(name, value);
|
|
11200
|
+
}
|
|
11201
|
+
const sections = plan.contentBindings.map((binding) => {
|
|
11202
|
+
const parsed = sources.get(binding.file);
|
|
11203
|
+
const componentAnalysis = plan.analysis.components.find((component) => component.file === binding.file && component.name === binding.component);
|
|
11204
|
+
const values = [];
|
|
11205
|
+
const extractedRepeaters = /* @__PURE__ */ new Map();
|
|
11206
|
+
const formFields = [];
|
|
11207
|
+
const seen = /* @__PURE__ */ new Set();
|
|
11208
|
+
const counters = /* @__PURE__ */ new Map();
|
|
11209
|
+
const importedAssets = /* @__PURE__ */ new Map();
|
|
11210
|
+
const add = (candidate) => {
|
|
11211
|
+
const value = candidate.value.trim().replace(/\s+/g, " ");
|
|
11212
|
+
if (!value || seen.has(`${candidate.kind}:${candidate.key}:${value}`)) return;
|
|
11213
|
+
seen.add(`${candidate.kind}:${candidate.key}:${value}`);
|
|
11214
|
+
values.push({
|
|
11215
|
+
...candidate,
|
|
11216
|
+
value
|
|
11217
|
+
});
|
|
11218
|
+
};
|
|
11219
|
+
if (parsed) {
|
|
11220
|
+
const source = parsed.source;
|
|
11221
|
+
const attributeValue = (attributes, name) => {
|
|
11222
|
+
const attribute = attributes.properties.find((candidate) => ts.isJsxAttribute(candidate) && candidate.name.getText(source) === name);
|
|
11223
|
+
if (!attribute?.initializer) return null;
|
|
11224
|
+
if (ts.isStringLiteral(attribute.initializer)) return attribute.initializer.text;
|
|
11225
|
+
if (ts.isJsxExpression(attribute.initializer) && attribute.initializer.expression) return resolvedString(attribute.initializer.expression);
|
|
11226
|
+
return null;
|
|
11227
|
+
};
|
|
11228
|
+
const hasAttribute = (attributes, name) => attributes.properties.some((candidate) => ts.isJsxAttribute(candidate) && candidate.name.getText(source) === name);
|
|
11229
|
+
const nodeText = (node) => {
|
|
11230
|
+
const chunks = [];
|
|
11231
|
+
const collect = (candidate) => {
|
|
11232
|
+
if (ts.isJsxText(candidate) && candidate.text.trim()) chunks.push(candidate.text);
|
|
11233
|
+
else if (ts.isJsxExpression(candidate) && candidate.expression) {
|
|
11234
|
+
const value = resolvedString(candidate.expression);
|
|
11235
|
+
if (value) chunks.push(value);
|
|
11236
|
+
}
|
|
11237
|
+
ts.forEachChild(candidate, collect);
|
|
11238
|
+
};
|
|
11239
|
+
collect(node);
|
|
11240
|
+
return chunks.join(" ").trim().replace(/\s+/g, " ");
|
|
11241
|
+
};
|
|
11242
|
+
const fieldLabelText = (node) => {
|
|
11243
|
+
const chunks = [];
|
|
11244
|
+
const collect = (candidate) => {
|
|
11245
|
+
if (ts.isJsxElement(candidate) || ts.isJsxSelfClosingElement(candidate)) {
|
|
11246
|
+
const tag = (ts.isJsxElement(candidate) ? candidate.openingElement.tagName : candidate.tagName).getText(source).toLowerCase();
|
|
11247
|
+
if ([
|
|
11248
|
+
"input",
|
|
11249
|
+
"textarea",
|
|
11250
|
+
"select",
|
|
11251
|
+
"option"
|
|
11252
|
+
].includes(tag)) return;
|
|
11253
|
+
}
|
|
11254
|
+
if (ts.isJsxText(candidate) && candidate.text.trim()) chunks.push(candidate.text);
|
|
11255
|
+
else if (ts.isJsxExpression(candidate) && candidate.expression) {
|
|
11256
|
+
const value = resolvedString(candidate.expression);
|
|
11257
|
+
if (value) chunks.push(value);
|
|
11258
|
+
}
|
|
11259
|
+
ts.forEachChild(candidate, collect);
|
|
11260
|
+
};
|
|
11261
|
+
collect(node);
|
|
11262
|
+
return chunks.join(" ").trim().replace(/\s+/g, " ");
|
|
11263
|
+
};
|
|
11264
|
+
const nearbyFieldLabel = (node, type) => {
|
|
11265
|
+
let ancestor = node.parent;
|
|
11266
|
+
while (ancestor && !ts.isFunctionLike(ancestor)) {
|
|
11267
|
+
if (ts.isJsxElement(ancestor) && ancestor.openingElement.tagName.getText(source).toLowerCase() === "label") {
|
|
11268
|
+
const label = fieldLabelText(ancestor);
|
|
11269
|
+
if (label) return label;
|
|
11270
|
+
}
|
|
11271
|
+
if (ts.isJsxElement(ancestor)) {
|
|
11272
|
+
const index = ancestor.children.findIndex((child) => child === node || child.pos <= node.pos && child.end >= node.end);
|
|
11273
|
+
if (index >= 0) {
|
|
11274
|
+
const before = ancestor.children.slice(0, index).reverse();
|
|
11275
|
+
const after = ancestor.children.slice(index + 1);
|
|
11276
|
+
const siblings = type === "checkbox" ? [...after, ...before] : [...before, ...after];
|
|
11277
|
+
for (const sibling of siblings) {
|
|
11278
|
+
if (!sibling) continue;
|
|
11279
|
+
const label = fieldLabelText(sibling);
|
|
11280
|
+
if (label) return label;
|
|
11281
|
+
}
|
|
11282
|
+
}
|
|
11283
|
+
}
|
|
11284
|
+
ancestor = ancestor.parent;
|
|
11285
|
+
}
|
|
11286
|
+
return "";
|
|
11287
|
+
};
|
|
11288
|
+
const collectFormField = (node) => {
|
|
11289
|
+
if (binding.componentKey !== "contact-form") return;
|
|
11290
|
+
const opening = ts.isJsxElement(node) ? node.openingElement : node;
|
|
11291
|
+
const tag = opening.tagName.getText(source).toLowerCase();
|
|
11292
|
+
if (![
|
|
11293
|
+
"input",
|
|
11294
|
+
"textarea",
|
|
11295
|
+
"select"
|
|
11296
|
+
].includes(tag)) return;
|
|
11297
|
+
const key = attributeValue(opening.attributes, "name")?.trim();
|
|
11298
|
+
if (!key || formFields.some((field) => field.key === key)) return;
|
|
11299
|
+
const rawType = tag === "textarea" ? "textarea" : tag === "select" ? "select" : attributeValue(opening.attributes, "type") ?? "text";
|
|
11300
|
+
const type = [
|
|
11301
|
+
"text",
|
|
11302
|
+
"email",
|
|
11303
|
+
"tel",
|
|
11304
|
+
"url",
|
|
11305
|
+
"number",
|
|
11306
|
+
"textarea",
|
|
11307
|
+
"select",
|
|
11308
|
+
"checkbox"
|
|
11309
|
+
].includes(rawType) ? rawType : "text";
|
|
11310
|
+
const field = {
|
|
11311
|
+
key,
|
|
11312
|
+
label: nearbyFieldLabel(node, type) || key,
|
|
11313
|
+
type,
|
|
11314
|
+
required: hasAttribute(opening.attributes, "required")
|
|
11315
|
+
};
|
|
11316
|
+
const placeholder = attributeValue(opening.attributes, "placeholder")?.trim();
|
|
11317
|
+
if (placeholder) field.placeholder = placeholder;
|
|
11318
|
+
if (tag === "select" && ts.isJsxElement(node)) {
|
|
11319
|
+
const options = [];
|
|
11320
|
+
const visitOption = (candidate) => {
|
|
11321
|
+
if (ts.isJsxElement(candidate) && candidate.openingElement.tagName.getText(source).toLowerCase() === "option") {
|
|
11322
|
+
const optionLabel = nodeText(candidate);
|
|
11323
|
+
const optionValue = attributeValue(candidate.openingElement.attributes, "value") ?? optionLabel;
|
|
11324
|
+
if (optionLabel) options.push({
|
|
11325
|
+
label: optionLabel,
|
|
11326
|
+
value: optionValue
|
|
11327
|
+
});
|
|
11328
|
+
return;
|
|
11329
|
+
}
|
|
11330
|
+
ts.forEachChild(candidate, visitOption);
|
|
11331
|
+
};
|
|
11332
|
+
visitOption(node);
|
|
11333
|
+
if (options.length) field.options = options;
|
|
11334
|
+
}
|
|
11335
|
+
formFields.push(field);
|
|
11336
|
+
};
|
|
11337
|
+
for (const statement of source.statements.filter(ts.isImportDeclaration)) {
|
|
11338
|
+
const specifier = statement.moduleSpecifier;
|
|
11339
|
+
if (!ts.isStringLiteralLike(specifier) || !statement.importClause) continue;
|
|
11340
|
+
const extension = path.extname(specifier.text).toLowerCase();
|
|
11341
|
+
if (!/[.](?:avif|gif|jpe?g|png|svg|webp|mp4|webm|ogg)$/i.test(extension)) continue;
|
|
11342
|
+
const assetReference = specifier.text.startsWith(".") ? portable(path.normalize(path.join(path.dirname(binding.file), specifier.text))) : specifier.text;
|
|
11343
|
+
if (statement.importClause.name) importedAssets.set(statement.importClause.name.text, assetReference);
|
|
11344
|
+
if (statement.importClause.namedBindings && ts.isNamedImports(statement.importClause.namedBindings)) for (const item of statement.importClause.namedBindings.elements) importedAssets.set(item.name.text, assetReference);
|
|
11345
|
+
}
|
|
11346
|
+
function componentName(node) {
|
|
11347
|
+
if ("name" in node && node.name && ts.isIdentifier(node.name)) return node.name.text;
|
|
11348
|
+
const parent = node.parent;
|
|
11349
|
+
return ts.isVariableDeclaration(parent) && ts.isIdentifier(parent.name) ? parent.name.text : null;
|
|
11350
|
+
}
|
|
11351
|
+
function extractRepeaters(body) {
|
|
11352
|
+
const contentLists = binding.contentLists ?? componentAnalysis?.contentLists ?? [];
|
|
11353
|
+
if (!contentLists.length) return;
|
|
11354
|
+
const declarations = /* @__PURE__ */ new Map();
|
|
11355
|
+
function collectDeclarations(candidate) {
|
|
11356
|
+
if (ts.isVariableDeclaration(candidate) && ts.isIdentifier(candidate.name) && candidate.initializer) {
|
|
11357
|
+
const initializer = unwrappedExpression(candidate.initializer);
|
|
11358
|
+
if (ts.isArrayLiteralExpression(initializer)) declarations.set(candidate.name.text, initializer);
|
|
11359
|
+
}
|
|
11360
|
+
ts.forEachChild(candidate, collectDeclarations);
|
|
11361
|
+
}
|
|
11362
|
+
collectDeclarations(source);
|
|
11363
|
+
const directArrays = [];
|
|
11364
|
+
function collectDirectArrays(candidate) {
|
|
11365
|
+
if (ts.isCallExpression(candidate) && ts.isPropertyAccessExpression(candidate.expression) && candidate.expression.name.text === "map") {
|
|
11366
|
+
const receiver = unwrappedExpression(candidate.expression.expression);
|
|
11367
|
+
if (ts.isArrayLiteralExpression(receiver)) directArrays.push(receiver);
|
|
11368
|
+
}
|
|
11369
|
+
ts.forEachChild(candidate, collectDirectArrays);
|
|
11370
|
+
}
|
|
11371
|
+
collectDirectArrays(body);
|
|
11372
|
+
let directIndex = 0;
|
|
11373
|
+
for (const list of contentLists) {
|
|
11374
|
+
const array = list.sourceName ? declarations.get(list.sourceName) : directArrays[directIndex++];
|
|
11375
|
+
if (!array) continue;
|
|
11376
|
+
const items = [];
|
|
11377
|
+
for (const element of array.elements) {
|
|
11378
|
+
if (!ts.isExpression(element)) continue;
|
|
11379
|
+
const value = unwrappedExpression(element);
|
|
11380
|
+
if (list.primitive) {
|
|
11381
|
+
const item = resolvedString(value) ?? (ts.isNumericLiteral(value) ? value.text : null);
|
|
11382
|
+
if (item !== null) items.push({ title: item });
|
|
11383
|
+
continue;
|
|
11384
|
+
}
|
|
11385
|
+
if (!ts.isObjectLiteralExpression(value)) continue;
|
|
11386
|
+
const item = {};
|
|
11387
|
+
for (const property of value.properties) {
|
|
11388
|
+
if (!ts.isPropertyAssignment(property)) continue;
|
|
11389
|
+
const key = propertyKey(property);
|
|
11390
|
+
if (!key || !list.itemFields.includes(key)) continue;
|
|
11391
|
+
const itemValue = resolvedString(property.initializer) ?? (ts.isNumericLiteral(unwrappedExpression(property.initializer)) ? unwrappedExpression(property.initializer).getText(source) : null);
|
|
11392
|
+
if (itemValue !== null) item[key] = itemValue;
|
|
11393
|
+
}
|
|
11394
|
+
if (Object.keys(item).length) items.push(item);
|
|
11395
|
+
}
|
|
11396
|
+
extractedRepeaters.set(list.fieldKey, items);
|
|
11397
|
+
}
|
|
11398
|
+
}
|
|
11399
|
+
function visitContent(node) {
|
|
11400
|
+
if (ts.isJsxElement(node) || ts.isJsxSelfClosingElement(node)) collectFormField(node);
|
|
11401
|
+
if (binding.componentKey === "feature-list" && ts.isArrayLiteralExpression(node)) for (const element of node.elements) {
|
|
11402
|
+
const item = resolvedString(element);
|
|
11403
|
+
if (item) add({
|
|
11404
|
+
key: "data.item",
|
|
11405
|
+
value: item,
|
|
11406
|
+
kind: "text"
|
|
11407
|
+
});
|
|
11408
|
+
}
|
|
11409
|
+
if (ts.isCallExpression(node) && ts.isIdentifier(node.expression) && node.expression.text === "t" && node.arguments[0] && ts.isStringLiteralLike(node.arguments[0])) {
|
|
11410
|
+
const key = node.arguments[0].text;
|
|
11411
|
+
add({
|
|
11412
|
+
key,
|
|
11413
|
+
value: translations.get(key) ?? `[tradução não localizada: ${key}]`,
|
|
11414
|
+
kind: "text",
|
|
11415
|
+
field: contentField(key)
|
|
11416
|
+
});
|
|
11417
|
+
return;
|
|
11418
|
+
}
|
|
11419
|
+
if (ts.isJsxText(node) && node.text.trim()) {
|
|
11420
|
+
const tag = jsxTagForText(node);
|
|
11421
|
+
const count = (counters.get(tag) ?? 0) + 1;
|
|
11422
|
+
counters.set(tag, count);
|
|
11423
|
+
add({
|
|
11424
|
+
key: `jsx.${tag}.${count}`,
|
|
11425
|
+
value: node.text,
|
|
11426
|
+
kind: "text",
|
|
11427
|
+
field: fieldForTag(tag)
|
|
11428
|
+
});
|
|
11429
|
+
return;
|
|
11430
|
+
}
|
|
11431
|
+
if (ts.isPropertyAssignment(node)) {
|
|
11432
|
+
const key = propertyKey(node);
|
|
11433
|
+
const value = resolvedString(node.initializer);
|
|
11434
|
+
if (key && value !== null && /^(?:title|headline|heading|subtitle|description|desc|text|content|label|cta|price|period|badge|question|answer|q|a|name|value|number|metric|num|role|email|phone|tel)$/i.test(key)) add({
|
|
11435
|
+
key: `data.${key}`,
|
|
11436
|
+
value,
|
|
11437
|
+
kind: "text",
|
|
11438
|
+
field: contentField(key)
|
|
11439
|
+
});
|
|
11440
|
+
}
|
|
11441
|
+
if (ts.isJsxAttribute(node) && node.initializer) {
|
|
11442
|
+
const name = node.name.getText(source);
|
|
11443
|
+
const tag = node.parent.parent.tagName.getText(source).toLowerCase();
|
|
11444
|
+
let expression = null;
|
|
11445
|
+
if (ts.isStringLiteral(node.initializer)) expression = node.initializer;
|
|
11446
|
+
else if (ts.isJsxExpression(node.initializer) && node.initializer.expression) expression = node.initializer.expression;
|
|
11447
|
+
const literal = expression ? resolvedString(expression) : null;
|
|
11448
|
+
const imported = expression && ts.isIdentifier(expression) ? importedAssets.get(expression.text) : void 0;
|
|
11449
|
+
const value = literal ?? imported ?? null;
|
|
11450
|
+
if (value && name === "href" && (tag === "a" || tag === "button")) add({
|
|
11451
|
+
key: `${tag}.href`,
|
|
11452
|
+
value,
|
|
11453
|
+
kind: "link",
|
|
11454
|
+
field: "buttonUrl"
|
|
11455
|
+
});
|
|
11456
|
+
if (value && ["src", "poster"].includes(name) && [
|
|
11457
|
+
"img",
|
|
11458
|
+
"image",
|
|
11459
|
+
"video",
|
|
11460
|
+
"source",
|
|
11461
|
+
"iframe"
|
|
11462
|
+
].includes(tag)) {
|
|
11463
|
+
const field = name === "poster" ? "posterImageUrl" : binding.componentKey === "video" && (tag === "video" || tag === "source" || tag === "iframe") ? "videoUrl" : "imageUrl";
|
|
11464
|
+
add({
|
|
11465
|
+
key: `${tag}.${name}`,
|
|
11466
|
+
value,
|
|
11467
|
+
kind: "media",
|
|
11468
|
+
field
|
|
11469
|
+
});
|
|
11470
|
+
}
|
|
11471
|
+
if (value && name === "alt" && ["img", "image"].includes(tag)) add({
|
|
11472
|
+
key: `${tag}.alt`,
|
|
11473
|
+
value,
|
|
11474
|
+
kind: "text",
|
|
11475
|
+
field: "imageAlt"
|
|
11476
|
+
});
|
|
11477
|
+
}
|
|
11478
|
+
ts.forEachChild(node, visitContent);
|
|
11479
|
+
}
|
|
11480
|
+
function findComponent(node) {
|
|
11481
|
+
if ((ts.isFunctionDeclaration(node) || ts.isFunctionExpression(node) || ts.isArrowFunction(node)) && componentName(node) === binding.component && node.body) {
|
|
11482
|
+
extractRepeaters(node.body);
|
|
11483
|
+
visitContent(node.body);
|
|
11484
|
+
return;
|
|
11485
|
+
}
|
|
11486
|
+
ts.forEachChild(node, findComponent);
|
|
11487
|
+
}
|
|
11488
|
+
findComponent(source);
|
|
11489
|
+
}
|
|
11490
|
+
const sectionData = blankBindingData(binding);
|
|
11491
|
+
const data = binding.type === "theme-component" ? sectionData.props : sectionData;
|
|
11492
|
+
const availableFields = new Set(binding.fields);
|
|
11493
|
+
const selected = /* @__PURE__ */ new Set();
|
|
11494
|
+
const assign = (field, candidate) => {
|
|
11495
|
+
if (!candidate || !availableFields.has(field)) return;
|
|
11496
|
+
data[field] = candidate.kind === "media" ? "" : candidate.value;
|
|
11497
|
+
selected.add(candidate.key);
|
|
11498
|
+
};
|
|
11499
|
+
const rank = (field, item) => {
|
|
11500
|
+
if (field === "title" && /^jsx\.h[1-6]\./.test(item.key)) return 0;
|
|
11501
|
+
if (field === "description" && /^jsx\.(?:p|blockquote)\./.test(item.key)) return 0;
|
|
11502
|
+
if (field === "buttonLabel" && /^jsx\.(?:button|a)\./.test(item.key)) return 0;
|
|
11503
|
+
if (field === "eyebrow" && /^jsx\.(?:span|small)\./.test(item.key)) return 0;
|
|
11504
|
+
if (item.key.startsWith("jsx.")) return 1;
|
|
11505
|
+
if (item.key.startsWith("data.")) return 3;
|
|
11506
|
+
return 2;
|
|
11507
|
+
};
|
|
11508
|
+
const ranked = (field) => values.filter((item) => item.field === field && !(field === "eyebrow" && /(?:lgpd|consent|privacidade|tratamento dos meus dados|autorizo)/i.test(item.value))).sort((left, right) => rank(field, left) - rank(field, right) || left.key.split(".").length - right.key.split(".").length)[0];
|
|
11509
|
+
assign("eyebrow", ranked("eyebrow") ?? values.find((item) => /^jsx\.div\./.test(item.key) && item.value.length <= 100 && item.value === item.value.toLocaleUpperCase("pt-BR") && /[A-ZÀ-Ü]/.test(item.value) && !/(?:lgpd|consent|privacidade|tratamento dos meus dados|autorizo)/i.test(item.value)));
|
|
11510
|
+
assign("title", ranked("title"));
|
|
11511
|
+
const description = ranked("description");
|
|
11512
|
+
assign(availableFields.has("description") ? "description" : "text", description);
|
|
11513
|
+
assign("buttonLabel", ranked("buttonLabel"));
|
|
11514
|
+
assign("buttonUrl", ranked("buttonUrl"));
|
|
11515
|
+
assign("imageAlt", ranked("imageAlt"));
|
|
11516
|
+
assign("videoUrl", ranked("videoUrl"));
|
|
11517
|
+
assign("posterImageUrl", ranked("posterImageUrl"));
|
|
11518
|
+
if (binding.componentKey === "contact-form" && formFields.length && availableFields.has("fields")) data.fields = formFields;
|
|
11519
|
+
for (const [field, items] of extractedRepeaters) if (availableFields.has(field)) data[field] = items;
|
|
11520
|
+
const media = ranked("imageUrl");
|
|
11521
|
+
if (media && availableFields.has("imageUrl")) selected.add(media.key);
|
|
11522
|
+
if (availableFields.has("text") && !data.text) data.text = values.filter(({ kind, key }) => kind === "text" && !selected.has(key) && !key.includes("tradução não localizada")).map(({ value }) => value).join("\n\n");
|
|
11523
|
+
if (binding.type === "theme-component" && availableFields.has("items")) {
|
|
11524
|
+
const properties = values.filter(({ key, kind }) => key.startsWith("data.") && kind === "text");
|
|
11525
|
+
const items = [];
|
|
11526
|
+
if (binding.componentKey === "faq") for (let index = 0; index < properties.length; index += 1) {
|
|
11527
|
+
const question = properties[index];
|
|
11528
|
+
if (!/(?:question|q)$/.test(question.key.toLowerCase())) continue;
|
|
11529
|
+
const answer = properties.slice(index + 1).find(({ key }) => /(?:answer|a)$/.test(key.toLowerCase()));
|
|
11530
|
+
items.push({
|
|
11531
|
+
question: question.value,
|
|
11532
|
+
answer: answer?.value ?? ""
|
|
11533
|
+
});
|
|
11534
|
+
}
|
|
11535
|
+
else if (binding.componentKey === "metrics") {
|
|
11536
|
+
let current = {};
|
|
11537
|
+
for (const property of properties) {
|
|
11538
|
+
const key = property.key.toLowerCase();
|
|
11539
|
+
if (/(?:value|number|metric)$/.test(key)) {
|
|
11540
|
+
if (Object.keys(current).length) items.push(current);
|
|
11541
|
+
current = { value: property.value };
|
|
11542
|
+
} else if (/(?:title|label|name)$/.test(key) && !current.title) current.title = property.value;
|
|
11543
|
+
else if (/(?:description|desc|text)$/.test(key) && !current.description) current.description = property.value;
|
|
11544
|
+
}
|
|
11545
|
+
if (Object.keys(current).length) items.push(current);
|
|
11546
|
+
} else if (binding.componentKey === "steps") {
|
|
11547
|
+
let current = {};
|
|
11548
|
+
for (const property of properties) {
|
|
11549
|
+
const key = property.key.toLowerCase();
|
|
11550
|
+
if (/(?:num|number|value)$/.test(key)) {
|
|
11551
|
+
if (Object.keys(current).length) items.push(current);
|
|
11552
|
+
current = { num: property.value };
|
|
11553
|
+
} else if (/(?:title|label|name)$/.test(key)) current.title = property.value;
|
|
11554
|
+
else if (/(?:description|desc|text)$/.test(key)) current.desc = property.value;
|
|
11555
|
+
}
|
|
11556
|
+
if (Object.keys(current).length) items.push(current);
|
|
11557
|
+
} else if (binding.componentKey === "contacts") {
|
|
11558
|
+
let current = {};
|
|
11559
|
+
for (const property of properties) {
|
|
11560
|
+
const key = property.key.toLowerCase();
|
|
11561
|
+
if (/(?:role)$/.test(key)) {
|
|
11562
|
+
if (Object.keys(current).length) items.push(current);
|
|
11563
|
+
current = { role: property.value };
|
|
11564
|
+
} else if (/(?:name)$/.test(key)) current.name = property.value;
|
|
11565
|
+
else if (/(?:email)$/.test(key)) current.email = property.value;
|
|
11566
|
+
else if (/(?:phone|tel)$/.test(key)) current.phone = property.value;
|
|
11567
|
+
}
|
|
11568
|
+
if (Object.keys(current).length) items.push(current);
|
|
11569
|
+
} else if (binding.componentKey === "feature-list") items.push(...values.filter(({ key }) => key === "data.item").map(({ value }) => ({ title: value })));
|
|
11570
|
+
else {
|
|
11571
|
+
let current = {};
|
|
11572
|
+
for (const property of properties) {
|
|
11573
|
+
const key = property.key.toLowerCase();
|
|
11574
|
+
if (/(?:title|label|name)$/.test(key)) {
|
|
11575
|
+
if (current.title) items.push(current);
|
|
11576
|
+
current = { title: property.value };
|
|
11577
|
+
} else if (/(?:description|desc|text)$/.test(key) && current.title && !current.description) current.description = property.value;
|
|
11578
|
+
}
|
|
11579
|
+
if (Object.keys(current).length) items.push(current);
|
|
11580
|
+
}
|
|
11581
|
+
data.items = items;
|
|
11582
|
+
}
|
|
11583
|
+
return {
|
|
11584
|
+
id: binding.id,
|
|
11585
|
+
component: binding.component,
|
|
11586
|
+
file: binding.file,
|
|
11587
|
+
type: binding.type,
|
|
11588
|
+
order: binding.order,
|
|
11589
|
+
data: sectionData,
|
|
11590
|
+
sourceContent: values
|
|
11591
|
+
};
|
|
11592
|
+
});
|
|
11593
|
+
return {
|
|
11594
|
+
version: 1,
|
|
11595
|
+
locale: translations.size ? "pt" : "original",
|
|
11596
|
+
note: "Conteúdo de referência extraído do projeto original. Cadastre-o no painel; este arquivo não é carregado pelo tema em runtime.",
|
|
11597
|
+
sections
|
|
11598
|
+
};
|
|
11599
|
+
}
|
|
11600
|
+
function homeConfiguration(plan) {
|
|
11601
|
+
return `${JSON.stringify({
|
|
11602
|
+
version: 1,
|
|
11603
|
+
sections: plan.contentBindings.map((binding) => ({
|
|
11604
|
+
id: binding.id,
|
|
11605
|
+
type: binding.type,
|
|
11606
|
+
enabled: true,
|
|
11607
|
+
order: binding.order,
|
|
11608
|
+
data: blankBindingData(binding)
|
|
11609
|
+
}))
|
|
11610
|
+
}, null, 2)}\n`;
|
|
8822
11611
|
}
|
|
8823
|
-
function
|
|
8824
|
-
|
|
8825
|
-
|
|
8826
|
-
|
|
8827
|
-
|
|
8828
|
-
|
|
8829
|
-
|
|
8830
|
-
|
|
11612
|
+
function contentMap(plan, catalog) {
|
|
11613
|
+
return `${JSON.stringify({
|
|
11614
|
+
version: 1,
|
|
11615
|
+
sourceProject: plan.analysis.projectName,
|
|
11616
|
+
note: "Preencha estes campos no painel Nuvler. Os valores extraídos estão em migration-content-seed.json; o tema não os publica hardcoded.",
|
|
11617
|
+
management: {
|
|
11618
|
+
location: "Home → Construtor",
|
|
11619
|
+
mode: "Montar",
|
|
11620
|
+
finalAction: "Salvar rascunho e Publicar"
|
|
11621
|
+
},
|
|
11622
|
+
sections: plan.contentBindings.map((binding) => {
|
|
11623
|
+
const serializableBinding = {
|
|
11624
|
+
id: binding.id,
|
|
11625
|
+
component: binding.component,
|
|
11626
|
+
file: binding.file,
|
|
11627
|
+
type: binding.type,
|
|
11628
|
+
order: binding.order,
|
|
11629
|
+
fields: binding.fields,
|
|
11630
|
+
componentKey: binding.componentKey,
|
|
11631
|
+
componentDefinition: binding.componentDefinition
|
|
11632
|
+
};
|
|
11633
|
+
const definition = panelDefinition(binding);
|
|
11634
|
+
const compatibility = panelCompatibility(binding);
|
|
11635
|
+
return {
|
|
11636
|
+
...serializableBinding,
|
|
11637
|
+
visualLink: `${binding.component} → ${definition.name} → ${binding.type}`,
|
|
11638
|
+
panel: {
|
|
11639
|
+
location: "Home → Construtor → Montar",
|
|
11640
|
+
category: definition.category,
|
|
11641
|
+
name: definition.name,
|
|
11642
|
+
description: definition.description,
|
|
11643
|
+
sectionId: binding.id,
|
|
11644
|
+
type: binding.type,
|
|
11645
|
+
order: binding.order,
|
|
11646
|
+
compatibility,
|
|
11647
|
+
controls: definition.controls,
|
|
11648
|
+
contentSource: definition.contentSource ?? null,
|
|
11649
|
+
data: blankBindingData(binding)
|
|
11650
|
+
},
|
|
11651
|
+
template: {
|
|
11652
|
+
hook: `useMigratedSection(${JSON.stringify(binding.id)})`,
|
|
11653
|
+
reads: binding.fields.map((field) => ({
|
|
11654
|
+
field,
|
|
11655
|
+
accessor: binding.type === "theme-component" ? `section.data.props.${field}` : `section.data.${field}`
|
|
11656
|
+
}))
|
|
11657
|
+
},
|
|
11658
|
+
extractedContent: catalog.sections.find(({ id }) => id === binding.id)?.sourceContent ?? []
|
|
11659
|
+
};
|
|
11660
|
+
})
|
|
11661
|
+
}, null, 2)}\n`;
|
|
11662
|
+
}
|
|
11663
|
+
function contentGuide(plan, catalog) {
|
|
11664
|
+
const rows = plan.contentBindings.map((binding) => {
|
|
11665
|
+
const definition = panelDefinition(binding);
|
|
11666
|
+
const compatibility = panelCompatibility(binding);
|
|
11667
|
+
const source = definition.contentSource?.location ?? "Nesta própria seção";
|
|
11668
|
+
return `| ${binding.order + 1} | ${binding.component} | **${definition.name}** | \`${binding.type}\` | ${compatibility.label} | ${source} |`;
|
|
11669
|
+
}).join("\n");
|
|
11670
|
+
const details = catalog.sections.map((section) => {
|
|
11671
|
+
const binding = plan.contentBindings.find(({ id }) => id === section.id);
|
|
11672
|
+
const definition = binding ? panelDefinition(binding) : PANEL_SECTION_DEFINITIONS[section.type];
|
|
11673
|
+
const compatibility = binding ? panelCompatibility(binding) : null;
|
|
11674
|
+
const populatedData = Object.fromEntries(Object.entries(section.data).filter(([, value]) => value !== ""));
|
|
11675
|
+
const detected = section.sourceContent.map(({ key, value, kind, field }) => `| \`${markdownCell(key)}\` | ${markdownCell(value)} | ${kind === "media" ? "mídia: faça upload no painel" : field ? `\`${field}\`` : "conteúdo adicional"} |`).join("\n");
|
|
11676
|
+
const controls = definition.controls.map((control) => `| ${control.label} | ${control.fields.map((field) => `\`${field}\``).join(", ")} | ${control.note ?? "-"} |`).join("\n");
|
|
11677
|
+
const contentSource = definition.contentSource ? `\n**Conteúdo dos itens:** abra **${definition.contentSource.location}**. ${definition.contentSource.description}\n` : "";
|
|
11678
|
+
return `## ${section.order + 1}. ${section.component} → ${definition.name}
|
|
8831
11679
|
|
|
8832
|
-
|
|
11680
|
+
No Gestão: **Home → Construtor → Montar → ${definition.category} → ${definition.name}**.
|
|
11681
|
+
O nome técnico enviado pela API é \`${section.type}\`.
|
|
11682
|
+
${compatibility ? `\n**Compatibilidade:** ${compatibility.label}. ${compatibility.note}\n` : ""}
|
|
11683
|
+
${contentSource}
|
|
11684
|
+
| Rótulo que aparece no Gestão | Chave na API | Observação |
|
|
11685
|
+
| --- | --- | --- |
|
|
11686
|
+
${controls}
|
|
8833
11687
|
|
|
8834
|
-
|
|
8835
|
-
const candidate = section?.data[key];
|
|
8836
|
-
return typeof candidate === "string" ? candidate : "";
|
|
8837
|
-
}
|
|
11688
|
+
Valores encontrados no projeto original para copiar no painel:
|
|
8838
11689
|
|
|
8839
|
-
|
|
8840
|
-
|
|
8841
|
-
|
|
8842
|
-
const productSection = enabled.find((item) => item.type === "products-grid" || item.type === "products-carousel");
|
|
8843
|
-
const name = site.settings?.siteName || site.tenant.name;
|
|
8844
|
-
const action = template.primaryAction(site.modules);
|
|
8845
|
-
return <main className=${classes("nuvler-migrated-home", home.root)}>
|
|
8846
|
-
<section className=${classes("nuvler-migrated-hero", hero.root || home.content)}>
|
|
8847
|
-
<div className=${classes("nuvler-migrated-hero-content", hero.content)}>
|
|
8848
|
-
<span>{${JSON.stringify(heroText)}}</span>
|
|
8849
|
-
<h1 className=${classes("nuvler-migrated-hero-title", hero.title)}>{value(heroSection, "title") || name}</h1>
|
|
8850
|
-
<p className=${classes("nuvler-migrated-copy", hero.text)}>{value(heroSection, "description") || site.settings?.description || "Conheça nossos produtos e soluções."}</p>
|
|
8851
|
-
<a className=${classes("nuvler-migrated-action", hero.action)} href={value(heroSection, "buttonUrl") || action.href}>{value(heroSection, "buttonLabel") || action.label}</a>
|
|
8852
|
-
</div>
|
|
8853
|
-
{migratedHeroAsset && <div className=${classes("nuvler-migrated-hero-media", hero.media)}><img src={migratedHeroAsset} alt="" /></div>}
|
|
8854
|
-
</section>
|
|
8855
|
-
{site.modules.includes("PRODUCTS") && <section className=${classes("nuvler-migrated-section", section.root)}>
|
|
8856
|
-
<header><span>Destaques</span><h2 className=${classes("nuvler-migrated-section-title", section.title)}>{value(productSection, "title") || "Produtos em destaque"}</h2></header>
|
|
8857
|
-
<ProductGrid products={products} columns={site.settings?.catalog?.desktopColumns || 3} showCategory={site.settings?.catalog?.showCategory} showDescription={site.settings?.catalog?.showDescription} />
|
|
8858
|
-
</section>}
|
|
8859
|
-
{enabled.filter((item) => ["image-text", "rich-text", "cta"].includes(item.type)).map((item) => <section className=${classes("nuvler-migrated-section nuvler-migrated-generic", section.content)} key={item.id || \`\${item.type}-\${item.order}\`}><h2>{value(item, "title")}</h2><p>{value(item, "description") || value(item, "content")}</p>{value(item, "buttonUrl") && <a className="nuvler-migrated-action" href={value(item, "buttonUrl")}>{value(item, "buttonLabel") || "Saiba mais"}</a>}</section>)}
|
|
8860
|
-
</main>;
|
|
8861
|
-
}
|
|
8862
|
-
`;
|
|
8863
|
-
}
|
|
8864
|
-
function definitionSource(plan) {
|
|
8865
|
-
const tokens = plan.tokens;
|
|
8866
|
-
return `import manifestData from "../nuvler.theme.json" with { type: "json" };
|
|
8867
|
-
import { defineTheme, type ThemeHomeSection, type ThemeManifest } from "@nuvler/theme-sdk";
|
|
8868
|
-
import { Footer } from "./components/Footer.js";
|
|
8869
|
-
import { Header } from "./components/Header.js";
|
|
8870
|
-
import { ProductDetail } from "./components/ProductDetail.js";
|
|
8871
|
-
import { ProductGrid } from "./components/ProductGrid.js";
|
|
8872
|
-
import { Home } from "./sections/Home.js";
|
|
11690
|
+
\`\`\`json
|
|
11691
|
+
${JSON.stringify(populatedData, null, 2)}
|
|
11692
|
+
\`\`\`
|
|
8873
11693
|
|
|
8874
|
-
|
|
8875
|
-
return { id, type, enabled: true, order, data: {} };
|
|
8876
|
-
}
|
|
11694
|
+
Conteúdo encontrado no projeto original:
|
|
8877
11695
|
|
|
8878
|
-
|
|
8879
|
-
|
|
8880
|
-
|
|
8881
|
-
tokens: {
|
|
8882
|
-
colors: ${JSON.stringify({
|
|
8883
|
-
primary: tokens.primary,
|
|
8884
|
-
primaryText: tokens.primaryText,
|
|
8885
|
-
secondary: tokens.secondary,
|
|
8886
|
-
secondaryText: tokens.secondaryText,
|
|
8887
|
-
accent: tokens.accent,
|
|
8888
|
-
background: tokens.background,
|
|
8889
|
-
surface: tokens.surface,
|
|
8890
|
-
surfaceAlt: tokens.surfaceAlt,
|
|
8891
|
-
text: tokens.text,
|
|
8892
|
-
textMuted: tokens.textMuted,
|
|
8893
|
-
border: tokens.border,
|
|
8894
|
-
headerBackground: tokens.headerBackground,
|
|
8895
|
-
headerText: tokens.headerText,
|
|
8896
|
-
footerBackground: tokens.footerBackground,
|
|
8897
|
-
footerText: tokens.footerText
|
|
8898
|
-
})},
|
|
8899
|
-
layout: ${JSON.stringify({
|
|
8900
|
-
containerWidth: tokens.containerWidth,
|
|
8901
|
-
borderRadius: tokens.borderRadius
|
|
8902
|
-
})},
|
|
8903
|
-
},
|
|
8904
|
-
template: {
|
|
8905
|
-
announcement: ${JSON.stringify(plan.themeName)},
|
|
8906
|
-
footerTagline: "Experiência visual migrada para a plataforma Nuvler.",
|
|
8907
|
-
footerNavigationLabel: "Navegação",
|
|
8908
|
-
footerNote: ${JSON.stringify(plan.themeName)},
|
|
8909
|
-
socialLabel: "Redes sociais",
|
|
8910
|
-
benefits: [],
|
|
8911
|
-
fallbackSections: () => [section("migrated-hero", "hero", 0), section("migrated-products", "products-grid", 1)],
|
|
8912
|
-
primaryAction: (modules) => modules.includes("PRODUCTS") ? { label: "Ver produtos", href: "/produtos" } : { label: "Saiba mais", href: "/" },
|
|
8913
|
-
},
|
|
8914
|
-
components: { Header, Footer, Home, ProductGrid, ProductDetail },
|
|
8915
|
-
});
|
|
11696
|
+
| Origem | Valor original | Destino sugerido |
|
|
11697
|
+
| --- | --- | --- |
|
|
11698
|
+
${detected || "| - | Nenhum valor literal localizado | revise o componente original |"}
|
|
8916
11699
|
`;
|
|
8917
|
-
}
|
|
8918
|
-
|
|
8919
|
-
return `import type { ThemeRoute, ThemeSite } from "@nuvler/theme-sdk";
|
|
8920
|
-
import { ProductGrid } from "../components/ProductGrid.js";
|
|
11700
|
+
}).join("\n");
|
|
11701
|
+
return `# Configuração de conteúdo no Nuvler
|
|
8921
11702
|
|
|
8922
|
-
|
|
8923
|
-
|
|
8924
|
-
export function CatalogPage({ route, site }: { route: CatalogRoute; site: ThemeSite }) {
|
|
8925
|
-
return <main className="nuvler-migrated-section nuvler-migrated-catalog">
|
|
8926
|
-
<header><span>Catálogo</span><h1>{route.search ? \`Busca: \${route.search}\` : "Produtos"}</h1><p>{route.pagination.total} produto(s)</p></header>
|
|
8927
|
-
<ProductGrid products={route.products} columns={site.settings?.catalog?.desktopColumns || 3} showCategory={site.settings?.catalog?.showCategory} showDescription={site.settings?.catalog?.showDescription} />
|
|
8928
|
-
</main>;
|
|
8929
|
-
}
|
|
8930
|
-
`;
|
|
8931
|
-
}
|
|
8932
|
-
function productPageSource() {
|
|
8933
|
-
return `import type { ThemeRoute, ThemeRuntimeSdk, ThemeSite } from "@nuvler/theme-sdk";
|
|
8934
|
-
import { ProductDetail } from "../components/ProductDetail.js";
|
|
11703
|
+
Este tema mantém os componentes e a estilização do projeto original. Textos,
|
|
11704
|
+
imagens e links são lidos das seções configuradas em **Home** no painel Nuvler.
|
|
8935
11705
|
|
|
8936
|
-
|
|
11706
|
+
No Gestão, abra **Home → Construtor**, mantenha o modo **Montar** e escolha os
|
|
11707
|
+
blocos pelos nomes da coluna **Bloco no Gestão**. Depois use **Salvar rascunho**
|
|
11708
|
+
e **Publicar**. Não procure por nomes técnicos como \`hero\`: na tela ele aparece
|
|
11709
|
+
como **Banner principal**.
|
|
8937
11710
|
|
|
8938
|
-
|
|
8939
|
-
|
|
8940
|
-
|
|
8941
|
-
`;
|
|
8942
|
-
}
|
|
8943
|
-
function editorialPageSource() {
|
|
8944
|
-
return `import type { ThemeRoute } from "@nuvler/theme-sdk";
|
|
11711
|
+
Crie as seções abaixo na mesma ordem. O tema prioriza o ID descrito em
|
|
11712
|
+
\`nuvler.home.json\`; quando o painel gerar outro ID, ele associa por tipo e
|
|
11713
|
+
ocorrência na ordem da Home.
|
|
8945
11714
|
|
|
8946
|
-
|
|
11715
|
+
| Ordem | Componente no projeto | Bloco no Gestão | Tipo técnico/API | Compatibilidade | Onde cadastrar os itens |
|
|
11716
|
+
| ---: | --- | --- | --- | --- | --- |
|
|
11717
|
+
${rows || "| - | Nenhuma seção detectada | - | - | - | - |"}
|
|
8947
11718
|
|
|
8948
|
-
|
|
8949
|
-
|
|
8950
|
-
|
|
8951
|
-
|
|
8952
|
-
`;
|
|
8953
|
-
}
|
|
8954
|
-
function statePageSource() {
|
|
8955
|
-
return `export function StatePage({ title, pathname }: { title: string; pathname?: string }) {
|
|
8956
|
-
return <main className="nuvler-migrated-section nuvler-migrated-state"><span>{pathname || "Nuvler"}</span><h1>{title}</h1></main>;
|
|
8957
|
-
}
|
|
8958
|
-
`;
|
|
8959
|
-
}
|
|
8960
|
-
function themeSource() {
|
|
8961
|
-
return `import type { CSSProperties } from "react";
|
|
8962
|
-
import type { NuvlerThemeProps, ThemeSite } from "@nuvler/theme-sdk";
|
|
8963
|
-
import { themeDefinition } from "./definition.js";
|
|
8964
|
-
import { CatalogPage } from "./pages/CatalogPage.js";
|
|
8965
|
-
import { EditorialPage } from "./pages/EditorialPage.js";
|
|
8966
|
-
import { ProductPage } from "./pages/ProductPage.js";
|
|
8967
|
-
import { StatePage } from "./pages/StatePage.js";
|
|
8968
|
-
import "./styles/theme.css";
|
|
11719
|
+
O arquivo \`nuvler.home.json\` é o blueprint vazio usado para conferir a estrutura.
|
|
11720
|
+
\`migration-content-seed.json\` guarda os valores extraídos para cadastro no painel,
|
|
11721
|
+
sem incluí-los no runtime do tema. \`migration-content-map.json\` documenta a ligação
|
|
11722
|
+
entre o componente, o painel e o template.
|
|
8969
11723
|
|
|
8970
|
-
|
|
11724
|
+
Referências de mídia apontam para o arquivo do projeto original. Faça o upload no
|
|
11725
|
+
painel e use a URL ou o ID retornado pelo Nuvler. Conteúdos adicionais sem campo
|
|
11726
|
+
equivalente ficam documentados abaixo; repeaters e schemas customizados continuam
|
|
11727
|
+
fora da V1.
|
|
8971
11728
|
|
|
8972
|
-
|
|
8973
|
-
const { Header, Footer, Home } = themeDefinition.components;
|
|
8974
|
-
const site: ThemeSite = { tenant: context.store, ...context.site };
|
|
8975
|
-
const configured = site.settings?.theme;
|
|
8976
|
-
const tokens = {
|
|
8977
|
-
colors: { ...themeDefinition.tokens.colors, ...configured?.colors },
|
|
8978
|
-
layout: { ...themeDefinition.tokens.layout, ...configured?.layout },
|
|
8979
|
-
};
|
|
8980
|
-
const style = {
|
|
8981
|
-
"--theme-primary": tokens.colors.primary,
|
|
8982
|
-
"--theme-primary-text": tokens.colors.primaryText,
|
|
8983
|
-
"--theme-secondary": tokens.colors.secondary,
|
|
8984
|
-
"--theme-secondary-text": tokens.colors.secondaryText,
|
|
8985
|
-
"--theme-accent": tokens.colors.accent,
|
|
8986
|
-
"--theme-background": tokens.colors.background,
|
|
8987
|
-
"--theme-surface": tokens.colors.surface,
|
|
8988
|
-
"--theme-surface-alt": tokens.colors.surfaceAlt,
|
|
8989
|
-
"--theme-text": tokens.colors.text,
|
|
8990
|
-
"--theme-text-muted": tokens.colors.textMuted,
|
|
8991
|
-
"--theme-border": tokens.colors.border,
|
|
8992
|
-
"--theme-header-background": tokens.colors.headerBackground,
|
|
8993
|
-
"--theme-header-text": tokens.colors.headerText,
|
|
8994
|
-
"--theme-footer-background": tokens.colors.footerBackground,
|
|
8995
|
-
"--theme-footer-text": tokens.colors.footerText,
|
|
8996
|
-
"--theme-radius": \`\${tokens.layout.borderRadius}px\`,
|
|
8997
|
-
"--theme-container": \`\${tokens.layout.containerWidth}px\`,
|
|
8998
|
-
} as CSSProperties;
|
|
8999
|
-
let content;
|
|
9000
|
-
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} />;
|
|
9001
|
-
else if (route.type === "catalog") content = <CatalogPage route={route} site={site} />;
|
|
9002
|
-
else if (route.type === "product") content = <ProductPage route={route} site={site} cart={sdk?.cart} />;
|
|
9003
|
-
else if (route.type === "editorial-list" || route.type === "editorial-detail") content = <EditorialPage route={route} />;
|
|
9004
|
-
else content = <StatePage title={route.type === "loading" ? "Carregando…" : route.type === "page" ? route.title : "Conteúdo não encontrado"} pathname={"pathname" in route ? route.pathname : undefined} />;
|
|
9005
|
-
return <div className="nuvler-migrated-theme" style={style}><Header site={site} categories={context.navigation.categories} pages={context.navigation.pages} template={themeDefinition.template} /><div className="nuvler-migrated-page">{content}</div><Footer site={site} pages={context.navigation.pages} template={themeDefinition.template} /></div>;
|
|
9006
|
-
}
|
|
11729
|
+
${details}
|
|
9007
11730
|
`;
|
|
9008
11731
|
}
|
|
9009
11732
|
function baseCss(plan) {
|
|
@@ -9025,6 +11748,16 @@ body { margin: 0; }
|
|
|
9025
11748
|
.nuvler-migrated-hero-media, .nuvler-migrated-product-media, .nuvler-migrated-detail-media { overflow: hidden; border-radius: var(--theme-radius); }
|
|
9026
11749
|
.nuvler-migrated-hero-media img, .nuvler-migrated-product-media img, .nuvler-migrated-detail-media img { display: block; width: 100%; height: 100%; object-fit: cover; }
|
|
9027
11750
|
.nuvler-migrated-section { padding-block: 56px; }
|
|
11751
|
+
.nuvler-migrated-contact-form-section { display: grid; grid-template-columns: minmax(0, .8fr) minmax(0, 1.2fr); align-items: start; gap: 48px; }
|
|
11752
|
+
.nuvler-migrated-contact-form-copy h2 { margin-block: 10px; }
|
|
11753
|
+
.nuvler-migrated-contact-form-copy p { color: var(--theme-text-muted); line-height: 1.7; }
|
|
11754
|
+
.nuvler-migrated-contact-form { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; border: 1px solid var(--theme-border); border-radius: var(--theme-radius); background: var(--theme-surface); padding: 24px; }
|
|
11755
|
+
.nuvler-migrated-contact-form label { display: grid; gap: 7px; }
|
|
11756
|
+
.nuvler-migrated-contact-form input, .nuvler-migrated-contact-form textarea, .nuvler-migrated-contact-form select { width: 100%; border: 1px solid var(--theme-border); border-radius: var(--theme-radius); background: var(--theme-background); color: var(--theme-text); padding: 12px 14px; font: inherit; }
|
|
11757
|
+
.nuvler-migrated-form-wide { grid-column: 1 / -1; }
|
|
11758
|
+
.nuvler-migrated-contact-form .nuvler-migrated-checkbox { display: flex; flex-direction: row; align-items: flex-start; gap: 10px; line-height: 1.55; }
|
|
11759
|
+
.nuvler-migrated-contact-form .nuvler-migrated-checkbox input { width: 18px; height: 18px; margin-top: 2px; padding: 0; accent-color: var(--theme-primary); }
|
|
11760
|
+
.nuvler-migrated-video { display: block; width: 100%; max-height: 720px; margin-top: 24px; border-radius: var(--theme-radius); background: #000; }
|
|
9028
11761
|
.nuvler-migrated-product-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 20px; }
|
|
9029
11762
|
.nuvler-migrated-product-grid[data-columns="4"] { grid-template-columns: repeat(4, minmax(0, 1fr)); }
|
|
9030
11763
|
.nuvler-migrated-product-card { overflow: hidden; border: 1px solid var(--theme-border); border-radius: var(--theme-radius); background: var(--theme-surface); }
|
|
@@ -9036,7 +11769,7 @@ body { margin: 0; }
|
|
|
9036
11769
|
.nuvler-migrated-footer { margin-top: 64px; background: var(--theme-footer-background); color: var(--theme-footer-text); padding: 56px max(16px, calc((100% - var(--theme-container)) / 2)); }
|
|
9037
11770
|
.nuvler-migrated-footer-inner { width: 100%; display: grid; grid-template-columns: 2fr 1fr 1fr; gap: 40px; }
|
|
9038
11771
|
.nuvler-migrated-footer-nav, .nuvler-migrated-contact { display: grid; gap: 8px; }
|
|
9039
|
-
@media (max-width: 850px) { .nuvler-migrated-header-inner, .nuvler-migrated-hero { grid-template-columns: 1fr; flex-direction: column; align-items: stretch; } .nuvler-migrated-nav { overflow-x: auto; flex-wrap: nowrap; } .nuvler-migrated-search input { width: 100%; min-width: 0; } .nuvler-migrated-product-grid, .nuvler-migrated-product-grid[data-columns="4"], .nuvler-migrated-product-detail, .nuvler-migrated-footer-inner { grid-template-columns: 1fr; } }
|
|
11772
|
+
@media (max-width: 850px) { .nuvler-migrated-header-inner, .nuvler-migrated-hero, .nuvler-migrated-contact-form-section, .nuvler-migrated-contact-form { grid-template-columns: 1fr; flex-direction: column; align-items: stretch; } .nuvler-migrated-form-wide { grid-column: auto; } .nuvler-migrated-nav { overflow-x: auto; flex-wrap: nowrap; } .nuvler-migrated-search input { width: 100%; min-width: 0; } .nuvler-migrated-product-grid, .nuvler-migrated-product-grid[data-columns="4"], .nuvler-migrated-product-detail, .nuvler-migrated-footer-inner { grid-template-columns: 1fr; } }
|
|
9040
11773
|
|
|
9041
11774
|
:root {
|
|
9042
11775
|
--theme-primary: ${plan.tokens.primary};
|
|
@@ -9073,6 +11806,8 @@ function preservedCss(plan, copied) {
|
|
|
9073
11806
|
content = content.replace(/:global\(([^)]+)\)/g, "$1");
|
|
9074
11807
|
content = content.replace(/url\(\s*(["']?)([^)'"\s]+)\1\s*\)/gi, (full, _quote, reference) => {
|
|
9075
11808
|
if (/^(?:data:|https?:|#)/i.test(reference)) return full;
|
|
11809
|
+
const sourceAsset = sourceAssetFor(style, reference, plan);
|
|
11810
|
+
if (sourceAsset && sourceAsset.kind !== "font") return "none";
|
|
9076
11811
|
const asset = copiedAssetFor(style, reference, plan, copied);
|
|
9077
11812
|
if (!asset) return full;
|
|
9078
11813
|
const output = portable(asset.outputFile);
|
|
@@ -9083,6 +11818,14 @@ function preservedCss(plan, copied) {
|
|
|
9083
11818
|
return `/* Origem: ${style.file}${style.module ? " (CSS Module convertido para CSS comum)" : ""} */\n${content}`;
|
|
9084
11819
|
}).join("\n\n");
|
|
9085
11820
|
}
|
|
11821
|
+
function sourceAssetFor(style, reference, plan) {
|
|
11822
|
+
const absolute = reference.startsWith("/") ? path.join(plan.analysis.sourceDirectory, "public", reference.replace(/^\/+/, "")) : path.resolve(path.dirname(style.absolutePath), reference);
|
|
11823
|
+
return plan.assets.find((asset) => path.resolve(asset.absolutePath) === path.resolve(absolute));
|
|
11824
|
+
}
|
|
11825
|
+
function classCatalog(plan) {
|
|
11826
|
+
const classNames = plan.analysis.components.flatMap((component) => component.jsx.flatMap((node) => node.classes)).filter((className) => !className.includes("url("));
|
|
11827
|
+
return `/** Classes observadas no projeto original. Mantém utilitários visuais sem copiar conteúdo. */\nexport const migratedClassCatalog = ${JSON.stringify([...new Set(classNames)].join(" "))};\n`;
|
|
11828
|
+
}
|
|
9086
11829
|
function externalCssImports(plan) {
|
|
9087
11830
|
const imports = plan.styles.flatMap(({ content }) => [...content.matchAll(/@import\s+(?:url\(\s*)?(["'])(?:https?:\/\/[^"']+)\1\s*\)?[^;]*;?/gi)].map((match) => match[0].trim()));
|
|
9088
11831
|
return [...new Set(imports)].join("\n");
|
|
@@ -9099,7 +11842,7 @@ async function configureTailwind(plan, directory) {
|
|
|
9099
11842
|
metadata.devDependencies["@tailwindcss/postcss"] = plan.analysis.dependencies["@tailwindcss/postcss"] || "^4.0.0";
|
|
9100
11843
|
await writeFile(path.join(directory, "postcss.config.mjs"), "export default { plugins: { \"@tailwindcss/postcss\": {} } };\n", "utf8");
|
|
9101
11844
|
await writeFile(packageFile, `${JSON.stringify(metadata, null, 2)}\n`, "utf8");
|
|
9102
|
-
return "@import \"tailwindcss\";\n";
|
|
11845
|
+
return "@import \"tailwindcss\";\n@source \"../**/*.{ts,tsx,js,jsx}\";\n";
|
|
9103
11846
|
}
|
|
9104
11847
|
metadata.devDependencies.autoprefixer = plan.analysis.dependencies.autoprefixer || "^10.4.0";
|
|
9105
11848
|
const migratedColors = JSON.stringify(plan.analysis.tailwind.colors);
|
|
@@ -9126,26 +11869,53 @@ async function generateMigratedTheme(plan, directory) {
|
|
|
9126
11869
|
mkdir(path.join(directory, "src", "styles"), { recursive: true }),
|
|
9127
11870
|
mkdir(path.join(directory, "src", "pages"), { recursive: true })
|
|
9128
11871
|
]);
|
|
9129
|
-
const
|
|
11872
|
+
const fidelityEnabled = Boolean(plan.analysis.sourceGraph.entrypoint);
|
|
11873
|
+
const styleFiles = new Set(plan.styles.map((style) => style.file));
|
|
11874
|
+
const copiedAssets = await copyMigrationAssets(plan, directory, fidelityEnabled ? plan.assets.filter((asset) => asset.kind === "font" && asset.referencedBy.some((file) => styleFiles.has(file))) : plan.assets);
|
|
11875
|
+
const fidelity = await runFidelityPass(plan, directory);
|
|
11876
|
+
await mergeFidelityDependencies(plan, directory);
|
|
11877
|
+
for (const file of fidelity.adaptedBusinessFiles) plan.warnings.push(`${file}: regra de negócio isolada pela Nuvler Adaptation Pass; apresentação dependente preservada.`);
|
|
9130
11878
|
const tailwindHeader = await configureTailwind(plan, directory);
|
|
11879
|
+
const extractedContent = await extractContentCatalog(plan);
|
|
9131
11880
|
await Promise.all([
|
|
9132
11881
|
writeFile(path.join(directory, "src/components/Header.tsx"), headerSource(plan), "utf8"),
|
|
9133
11882
|
writeFile(path.join(directory, "src/components/Footer.tsx"), footerSource(plan), "utf8"),
|
|
9134
11883
|
writeFile(path.join(directory, "src/components/ProductCard.tsx"), productCardSource(plan), "utf8"),
|
|
9135
11884
|
writeFile(path.join(directory, "src/components/ProductGrid.tsx"), productGridSource(plan), "utf8"),
|
|
9136
11885
|
writeFile(path.join(directory, "src/components/ProductDetail.tsx"), productDetailSource(plan), "utf8"),
|
|
9137
|
-
writeFile(path.join(directory, "src/sections/Home.tsx"), homeSource(plan,
|
|
11886
|
+
writeFile(path.join(directory, "src/sections/Home.tsx"), homeSource(plan, fidelity), "utf8"),
|
|
9138
11887
|
writeFile(path.join(directory, "src/pages/CatalogPage.tsx"), catalogPageSource(), "utf8"),
|
|
9139
11888
|
writeFile(path.join(directory, "src/pages/ProductPage.tsx"), productPageSource(), "utf8"),
|
|
9140
11889
|
writeFile(path.join(directory, "src/pages/EditorialPage.tsx"), editorialPageSource(), "utf8"),
|
|
9141
11890
|
writeFile(path.join(directory, "src/pages/StatePage.tsx"), statePageSource(), "utf8"),
|
|
9142
11891
|
writeFile(path.join(directory, "src/definition.tsx"), definitionSource(plan), "utf8"),
|
|
9143
|
-
writeFile(path.join(directory, "src/theme.tsx"), themeSource(), "utf8"),
|
|
9144
|
-
writeFile(path.join(directory, "src/
|
|
9145
|
-
writeFile(path.join(directory, "src/
|
|
11892
|
+
writeFile(path.join(directory, "src/theme.tsx"), themeSource(Boolean(fidelity.entryImportPath)), "utf8"),
|
|
11893
|
+
writeFile(path.join(directory, "src/migrated-content.tsx"), migratedContentSource(plan), "utf8"),
|
|
11894
|
+
writeFile(path.join(directory, "src/migrated-next-image.tsx"), migratedNextImageSource(), "utf8"),
|
|
11895
|
+
writeFile(path.join(directory, "src/migrated-class-catalog.ts"), classCatalog(plan), "utf8"),
|
|
11896
|
+
writeFile(path.join(directory, "nuvler.home.json"), homeConfiguration(plan), "utf8"),
|
|
11897
|
+
writeFile(path.join(directory, "migration-content-seed.json"), `${JSON.stringify(extractedContent, null, 2)}\n`, "utf8"),
|
|
11898
|
+
writeFile(path.join(directory, "migration-content-map.json"), contentMap(plan, extractedContent), "utf8"),
|
|
11899
|
+
writeFile(path.join(directory, "CONTENT_SETUP.md"), contentGuide(plan, extractedContent), "utf8"),
|
|
11900
|
+
writeFile(path.join(directory, "src/styles/theme.css"), `${externalCssImports(plan)}\n${tailwindHeader}${baseCss(plan)}\n${preservedCss(plan, copiedAssets)}\n`, "utf8"),
|
|
11901
|
+
writeFile(path.join(directory, "src/styles.d.ts"), `declare module "*.module.css" { const classes: Record<string, string>; export default classes; }
|
|
11902
|
+
declare module "*.css";
|
|
11903
|
+
declare module "*.scss";
|
|
11904
|
+
declare module "*.sass";
|
|
11905
|
+
declare module "*.less";
|
|
11906
|
+
declare module "*.svg" { const url: string; export default url; }
|
|
11907
|
+
declare module "*.png" { const url: string; export default url; }
|
|
11908
|
+
declare module "*.jpg" { const url: string; export default url; }
|
|
11909
|
+
declare module "*.jpeg" { const url: string; export default url; }
|
|
11910
|
+
declare module "*.webp" { const url: string; export default url; }
|
|
11911
|
+
declare module "*.gif" { const url: string; export default url; }
|
|
11912
|
+
declare module "*.mp4" { const url: string; export default url; }
|
|
11913
|
+
declare module "*.webm" { const url: string; export default url; }
|
|
11914
|
+
`, "utf8")
|
|
9146
11915
|
]);
|
|
9147
11916
|
const manifestFile = path.join(directory, "nuvler.theme.json");
|
|
9148
11917
|
const manifest = JSON.parse(await readFile(manifestFile, "utf8"));
|
|
11918
|
+
const homeComponents = [...new Map(plan.contentBindings.flatMap((binding) => binding.componentDefinition ? [[binding.componentDefinition.key, binding.componentDefinition]] : [])).values()];
|
|
9149
11919
|
manifest.entry = "src/theme.tsx";
|
|
9150
11920
|
manifest.styles = ["src/styles/theme.css"];
|
|
9151
11921
|
manifest.presentation = {
|
|
@@ -9171,7 +11941,8 @@ async function generateMigratedTheme(plan, directory) {
|
|
|
9171
11941
|
layout: {
|
|
9172
11942
|
containerWidth: plan.tokens.containerWidth,
|
|
9173
11943
|
borderRadius: plan.tokens.borderRadius
|
|
9174
|
-
}
|
|
11944
|
+
},
|
|
11945
|
+
...homeComponents.length ? { homeComponents } : {}
|
|
9175
11946
|
};
|
|
9176
11947
|
await writeFile(manifestFile, `${JSON.stringify(manifest, null, 2)}\n`, "utf8");
|
|
9177
11948
|
const selectedComponents = {};
|
|
@@ -9186,8 +11957,12 @@ async function generateMigratedTheme(plan, directory) {
|
|
|
9186
11957
|
sourceRoots: plan.analysis.sourceRoots,
|
|
9187
11958
|
componentsAnalyzed: plan.analysis.components.length,
|
|
9188
11959
|
selectedComponents,
|
|
9189
|
-
|
|
9190
|
-
|
|
11960
|
+
contentBindings: plan.contentBindings.map(({ classes: _classes, ...binding }) => binding),
|
|
11961
|
+
assetsCopied: fidelity.copiedAssets + copiedAssets.length,
|
|
11962
|
+
styleFilesPreserved: (/* @__PURE__ */ new Set([...plan.styles.map((style) => style.file), ...plan.analysis.sourceGraph.modules.filter((module) => module.kind === "STYLE").map((module) => module.file)])).size,
|
|
11963
|
+
sourceFilesPreserved: fidelity.copiedFiles,
|
|
11964
|
+
entrypoint: plan.analysis.sourceGraph.entrypoint,
|
|
11965
|
+
dependencies: plan.analysis.sourceGraph.dependencies,
|
|
9191
11966
|
tailwind: plan.analysis.tailwind,
|
|
9192
11967
|
ignoredFiles: plan.analysis.ignoredFiles,
|
|
9193
11968
|
warnings: [...new Set(plan.warnings)],
|
|
@@ -9539,6 +12314,511 @@ function safeThemeId(value) {
|
|
|
9539
12314
|
function themeName(value) {
|
|
9540
12315
|
return value.replace(/^@[^/]+\//, "").split(/[-_\s]+/).filter(Boolean).map((part) => `${part[0]?.toUpperCase() ?? ""}${part.slice(1)}`).join(" ").slice(0, 120) || "Tema Migrado";
|
|
9541
12316
|
}
|
|
12317
|
+
var CONTENT_FIELDS = {
|
|
12318
|
+
hero: [
|
|
12319
|
+
"eyebrow",
|
|
12320
|
+
"title",
|
|
12321
|
+
"description",
|
|
12322
|
+
"imageId",
|
|
12323
|
+
"imageUrl",
|
|
12324
|
+
"imageAlt",
|
|
12325
|
+
"buttonLabel",
|
|
12326
|
+
"buttonUrl"
|
|
12327
|
+
],
|
|
12328
|
+
"banner-carousel": ["banners"],
|
|
12329
|
+
"image-text": [
|
|
12330
|
+
"eyebrow",
|
|
12331
|
+
"title",
|
|
12332
|
+
"description",
|
|
12333
|
+
"imageId",
|
|
12334
|
+
"imageUrl",
|
|
12335
|
+
"imageAlt",
|
|
12336
|
+
"imagePosition"
|
|
12337
|
+
],
|
|
12338
|
+
"rich-text": [
|
|
12339
|
+
"eyebrow",
|
|
12340
|
+
"title",
|
|
12341
|
+
"text"
|
|
12342
|
+
],
|
|
12343
|
+
cta: [
|
|
12344
|
+
"eyebrow",
|
|
12345
|
+
"title",
|
|
12346
|
+
"description",
|
|
12347
|
+
"buttonLabel",
|
|
12348
|
+
"buttonUrl"
|
|
12349
|
+
],
|
|
12350
|
+
"services-grid": [
|
|
12351
|
+
"eyebrow",
|
|
12352
|
+
"title",
|
|
12353
|
+
"limit"
|
|
12354
|
+
],
|
|
12355
|
+
"blog-grid": [
|
|
12356
|
+
"eyebrow",
|
|
12357
|
+
"title",
|
|
12358
|
+
"limit"
|
|
12359
|
+
],
|
|
12360
|
+
"cases-grid": [
|
|
12361
|
+
"eyebrow",
|
|
12362
|
+
"title",
|
|
12363
|
+
"limit"
|
|
12364
|
+
],
|
|
12365
|
+
"products-grid": [
|
|
12366
|
+
"eyebrow",
|
|
12367
|
+
"title",
|
|
12368
|
+
"limit",
|
|
12369
|
+
"categorySlug"
|
|
12370
|
+
],
|
|
12371
|
+
"products-carousel": [
|
|
12372
|
+
"eyebrow",
|
|
12373
|
+
"title",
|
|
12374
|
+
"limit",
|
|
12375
|
+
"categorySlug"
|
|
12376
|
+
],
|
|
12377
|
+
"theme-component": [
|
|
12378
|
+
"eyebrow",
|
|
12379
|
+
"title",
|
|
12380
|
+
"description",
|
|
12381
|
+
"items",
|
|
12382
|
+
"fields",
|
|
12383
|
+
"submitLabel",
|
|
12384
|
+
"successMessage",
|
|
12385
|
+
"videoUrl",
|
|
12386
|
+
"posterImageId",
|
|
12387
|
+
"posterImageUrl",
|
|
12388
|
+
"posterImageAlt"
|
|
12389
|
+
]
|
|
12390
|
+
};
|
|
12391
|
+
function customComponentKind(component) {
|
|
12392
|
+
const name = normalized(component.name);
|
|
12393
|
+
const tags = new Set(component.jsx.map(({ tag }) => tag.toLowerCase()));
|
|
12394
|
+
if (/(form|formulario)/.test(name) || [
|
|
12395
|
+
"form",
|
|
12396
|
+
"input",
|
|
12397
|
+
"textarea",
|
|
12398
|
+
"select"
|
|
12399
|
+
].some((tag) => tags.has(tag))) return "contact-form";
|
|
12400
|
+
if (/(faq|frequent|pergunta)/.test(name)) return "faq";
|
|
12401
|
+
if (/(evaluation|avaliacao|process|etapa|steps)/.test(name)) return "steps";
|
|
12402
|
+
if (/(number|numero|stat|metric|indicador)/.test(name)) return "metrics";
|
|
12403
|
+
if (/(benefit|beneficio|feature|vantagem)/.test(name)) return "benefits";
|
|
12404
|
+
if (/(video)/.test(name) || tags.has("video") || tags.has("iframe")) return "video";
|
|
12405
|
+
if (/(forwhom|paraquem|audience|publico)/.test(name)) return "audience";
|
|
12406
|
+
if (/(Contacts|Contatos|ContactList)/.test(component.name) || /(contact|contato)/.test(name) && component.jsx.filter(({ tag }) => tag.toLowerCase() === "a").length >= 2 && component.text.some((text) => /contatos?/i.test(text))) return "contacts";
|
|
12407
|
+
if (/(appsection|monitoring|monitoramento)/.test(name)) return "feature-list";
|
|
12408
|
+
return null;
|
|
12409
|
+
}
|
|
12410
|
+
function listComponentDefinition(kind) {
|
|
12411
|
+
const definition = {
|
|
12412
|
+
faq: {
|
|
12413
|
+
name: "Perguntas frequentes",
|
|
12414
|
+
description: "Lista editável de perguntas e respostas.",
|
|
12415
|
+
itemFields: [{
|
|
12416
|
+
key: "question",
|
|
12417
|
+
label: "Pergunta",
|
|
12418
|
+
control: "text",
|
|
12419
|
+
required: true
|
|
12420
|
+
}, {
|
|
12421
|
+
key: "answer",
|
|
12422
|
+
label: "Resposta",
|
|
12423
|
+
control: "textarea",
|
|
12424
|
+
required: true
|
|
12425
|
+
}]
|
|
12426
|
+
},
|
|
12427
|
+
metrics: {
|
|
12428
|
+
name: "Métricas e números",
|
|
12429
|
+
description: "Indicadores, números e pequenos destaques.",
|
|
12430
|
+
itemFields: [
|
|
12431
|
+
{
|
|
12432
|
+
key: "value",
|
|
12433
|
+
label: "Valor",
|
|
12434
|
+
control: "text",
|
|
12435
|
+
required: true
|
|
12436
|
+
},
|
|
12437
|
+
{
|
|
12438
|
+
key: "title",
|
|
12439
|
+
label: "Rótulo",
|
|
12440
|
+
control: "text",
|
|
12441
|
+
required: true
|
|
12442
|
+
},
|
|
12443
|
+
{
|
|
12444
|
+
key: "description",
|
|
12445
|
+
label: "Descrição",
|
|
12446
|
+
control: "textarea"
|
|
12447
|
+
}
|
|
12448
|
+
]
|
|
12449
|
+
},
|
|
12450
|
+
benefits: {
|
|
12451
|
+
name: "Lista de benefícios",
|
|
12452
|
+
description: "Benefícios ou diferenciais apresentados em cards.",
|
|
12453
|
+
itemFields: [{
|
|
12454
|
+
key: "title",
|
|
12455
|
+
label: "Título",
|
|
12456
|
+
control: "text",
|
|
12457
|
+
required: true
|
|
12458
|
+
}, {
|
|
12459
|
+
key: "description",
|
|
12460
|
+
label: "Descrição",
|
|
12461
|
+
control: "textarea"
|
|
12462
|
+
}]
|
|
12463
|
+
},
|
|
12464
|
+
audience: {
|
|
12465
|
+
name: "Para quem é",
|
|
12466
|
+
description: "Públicos, perfis ou cenários atendidos.",
|
|
12467
|
+
itemFields: [{
|
|
12468
|
+
key: "title",
|
|
12469
|
+
label: "Público",
|
|
12470
|
+
control: "text",
|
|
12471
|
+
required: true
|
|
12472
|
+
}, {
|
|
12473
|
+
key: "description",
|
|
12474
|
+
label: "Descrição",
|
|
12475
|
+
control: "textarea"
|
|
12476
|
+
}]
|
|
12477
|
+
},
|
|
12478
|
+
steps: {
|
|
12479
|
+
name: "Etapas do processo",
|
|
12480
|
+
description: "Etapas numeradas de uma avaliação ou processo.",
|
|
12481
|
+
itemFields: [
|
|
12482
|
+
{
|
|
12483
|
+
key: "num",
|
|
12484
|
+
label: "Número",
|
|
12485
|
+
control: "text"
|
|
12486
|
+
},
|
|
12487
|
+
{
|
|
12488
|
+
key: "title",
|
|
12489
|
+
label: "Título",
|
|
12490
|
+
control: "text",
|
|
12491
|
+
required: true
|
|
12492
|
+
},
|
|
12493
|
+
{
|
|
12494
|
+
key: "desc",
|
|
12495
|
+
label: "Descrição",
|
|
12496
|
+
control: "textarea"
|
|
12497
|
+
}
|
|
12498
|
+
]
|
|
12499
|
+
},
|
|
12500
|
+
contacts: {
|
|
12501
|
+
name: "Lista de contatos",
|
|
12502
|
+
description: "Pessoas e canais de atendimento exibidos na Home.",
|
|
12503
|
+
itemFields: [
|
|
12504
|
+
{
|
|
12505
|
+
key: "role",
|
|
12506
|
+
label: "Função",
|
|
12507
|
+
control: "text"
|
|
12508
|
+
},
|
|
12509
|
+
{
|
|
12510
|
+
key: "name",
|
|
12511
|
+
label: "Nome",
|
|
12512
|
+
control: "text",
|
|
12513
|
+
required: true
|
|
12514
|
+
},
|
|
12515
|
+
{
|
|
12516
|
+
key: "email",
|
|
12517
|
+
label: "E-mail",
|
|
12518
|
+
control: "text"
|
|
12519
|
+
},
|
|
12520
|
+
{
|
|
12521
|
+
key: "phone",
|
|
12522
|
+
label: "Telefone",
|
|
12523
|
+
control: "text"
|
|
12524
|
+
}
|
|
12525
|
+
]
|
|
12526
|
+
},
|
|
12527
|
+
"feature-list": {
|
|
12528
|
+
name: "Lista de recursos",
|
|
12529
|
+
description: "Recursos ou funcionalidades apresentados em uma seção.",
|
|
12530
|
+
itemFields: [{
|
|
12531
|
+
key: "title",
|
|
12532
|
+
label: "Recurso",
|
|
12533
|
+
control: "text",
|
|
12534
|
+
required: true
|
|
12535
|
+
}]
|
|
12536
|
+
}
|
|
12537
|
+
}[kind];
|
|
12538
|
+
return {
|
|
12539
|
+
key: kind,
|
|
12540
|
+
name: definition.name,
|
|
12541
|
+
description: definition.description,
|
|
12542
|
+
category: "Listas",
|
|
12543
|
+
schemaVersion: 1,
|
|
12544
|
+
fields: [
|
|
12545
|
+
{
|
|
12546
|
+
key: "eyebrow",
|
|
12547
|
+
label: "Chamada pequena",
|
|
12548
|
+
control: "text"
|
|
12549
|
+
},
|
|
12550
|
+
{
|
|
12551
|
+
key: "title",
|
|
12552
|
+
label: "Título da seção",
|
|
12553
|
+
control: "text",
|
|
12554
|
+
required: true
|
|
12555
|
+
},
|
|
12556
|
+
{
|
|
12557
|
+
key: "description",
|
|
12558
|
+
label: "Descrição",
|
|
12559
|
+
control: "textarea"
|
|
12560
|
+
},
|
|
12561
|
+
{
|
|
12562
|
+
key: "items",
|
|
12563
|
+
label: definition.name,
|
|
12564
|
+
control: "repeater",
|
|
12565
|
+
maxItems: 30,
|
|
12566
|
+
itemFields: [...definition.itemFields]
|
|
12567
|
+
}
|
|
12568
|
+
]
|
|
12569
|
+
};
|
|
12570
|
+
}
|
|
12571
|
+
function customComponentDefinition(kind) {
|
|
12572
|
+
if (kind === "contact-form") return {
|
|
12573
|
+
key: kind,
|
|
12574
|
+
name: "Formulário de contato",
|
|
12575
|
+
description: "Formulário configurável com envios salvos em Contatos.",
|
|
12576
|
+
category: "Formulários",
|
|
12577
|
+
schemaVersion: 1,
|
|
12578
|
+
fields: [
|
|
12579
|
+
{
|
|
12580
|
+
key: "eyebrow",
|
|
12581
|
+
label: "Chamada pequena",
|
|
12582
|
+
control: "text"
|
|
12583
|
+
},
|
|
12584
|
+
{
|
|
12585
|
+
key: "title",
|
|
12586
|
+
label: "Título da seção",
|
|
12587
|
+
control: "text",
|
|
12588
|
+
required: true
|
|
12589
|
+
},
|
|
12590
|
+
{
|
|
12591
|
+
key: "description",
|
|
12592
|
+
label: "Descrição",
|
|
12593
|
+
control: "textarea"
|
|
12594
|
+
},
|
|
12595
|
+
{
|
|
12596
|
+
key: "fields",
|
|
12597
|
+
label: "Campos do formulário",
|
|
12598
|
+
control: "contact-fields",
|
|
12599
|
+
required: true
|
|
12600
|
+
},
|
|
12601
|
+
{
|
|
12602
|
+
key: "submitLabel",
|
|
12603
|
+
label: "Texto do botão",
|
|
12604
|
+
control: "text",
|
|
12605
|
+
required: true
|
|
12606
|
+
},
|
|
12607
|
+
{
|
|
12608
|
+
key: "successMessage",
|
|
12609
|
+
label: "Mensagem de sucesso",
|
|
12610
|
+
control: "text"
|
|
12611
|
+
}
|
|
12612
|
+
],
|
|
12613
|
+
action: {
|
|
12614
|
+
type: "contact.submit",
|
|
12615
|
+
formKey: kind
|
|
12616
|
+
}
|
|
12617
|
+
};
|
|
12618
|
+
if (kind === "video") return {
|
|
12619
|
+
key: kind,
|
|
12620
|
+
name: "Vídeo",
|
|
12621
|
+
description: "Vídeo com título, descrição e imagem de capa.",
|
|
12622
|
+
category: "Mídia",
|
|
12623
|
+
schemaVersion: 1,
|
|
12624
|
+
fields: [
|
|
12625
|
+
{
|
|
12626
|
+
key: "eyebrow",
|
|
12627
|
+
label: "Chamada pequena",
|
|
12628
|
+
control: "text"
|
|
12629
|
+
},
|
|
12630
|
+
{
|
|
12631
|
+
key: "title",
|
|
12632
|
+
label: "Título da seção",
|
|
12633
|
+
control: "text",
|
|
12634
|
+
required: true
|
|
12635
|
+
},
|
|
12636
|
+
{
|
|
12637
|
+
key: "description",
|
|
12638
|
+
label: "Descrição",
|
|
12639
|
+
control: "textarea"
|
|
12640
|
+
},
|
|
12641
|
+
{
|
|
12642
|
+
key: "videoUrl",
|
|
12643
|
+
label: "URL do vídeo",
|
|
12644
|
+
control: "video",
|
|
12645
|
+
required: true
|
|
12646
|
+
},
|
|
12647
|
+
{
|
|
12648
|
+
key: "posterImageId",
|
|
12649
|
+
label: "Imagem de capa",
|
|
12650
|
+
control: "image"
|
|
12651
|
+
}
|
|
12652
|
+
]
|
|
12653
|
+
};
|
|
12654
|
+
return listComponentDefinition(kind);
|
|
12655
|
+
}
|
|
12656
|
+
function generatedListComponentDefinition(component) {
|
|
12657
|
+
const hasImage = component.jsx.some(({ tag }) => [
|
|
12658
|
+
"img",
|
|
12659
|
+
"image",
|
|
12660
|
+
"picture"
|
|
12661
|
+
].includes(tag.toLowerCase()));
|
|
12662
|
+
const hasVideo = component.jsx.some(({ tag }) => [
|
|
12663
|
+
"video",
|
|
12664
|
+
"source",
|
|
12665
|
+
"iframe"
|
|
12666
|
+
].includes(tag.toLowerCase()));
|
|
12667
|
+
const hasAction = component.jsx.some(({ tag }) => ["a", "button"].includes(tag.toLowerCase()));
|
|
12668
|
+
const label = component.name.replace(/([a-z\d])([A-Z])/g, "$1 $2").replace(/[-_]+/g, " ").trim();
|
|
12669
|
+
const fields = [
|
|
12670
|
+
{
|
|
12671
|
+
key: "eyebrow",
|
|
12672
|
+
label: "Chamada pequena",
|
|
12673
|
+
control: "text"
|
|
12674
|
+
},
|
|
12675
|
+
{
|
|
12676
|
+
key: "title",
|
|
12677
|
+
label: "Título da seção",
|
|
12678
|
+
control: "text"
|
|
12679
|
+
},
|
|
12680
|
+
{
|
|
12681
|
+
key: "description",
|
|
12682
|
+
label: "Descrição",
|
|
12683
|
+
control: "textarea"
|
|
12684
|
+
}
|
|
12685
|
+
];
|
|
12686
|
+
if (hasImage) fields.push({
|
|
12687
|
+
key: "imageId",
|
|
12688
|
+
label: "Imagem",
|
|
12689
|
+
control: "image"
|
|
12690
|
+
}, {
|
|
12691
|
+
key: "imageAlt",
|
|
12692
|
+
label: "Texto alternativo da imagem",
|
|
12693
|
+
control: "text"
|
|
12694
|
+
});
|
|
12695
|
+
if (hasVideo) fields.push({
|
|
12696
|
+
key: "videoUrl",
|
|
12697
|
+
label: "Vídeo",
|
|
12698
|
+
control: "video"
|
|
12699
|
+
});
|
|
12700
|
+
if (hasAction) fields.push({
|
|
12701
|
+
key: "buttonLabel",
|
|
12702
|
+
label: "Texto do botão",
|
|
12703
|
+
control: "text"
|
|
12704
|
+
}, {
|
|
12705
|
+
key: "buttonUrl",
|
|
12706
|
+
label: "Link do botão",
|
|
12707
|
+
control: "url"
|
|
12708
|
+
});
|
|
12709
|
+
for (const list of component.contentLists) fields.push({
|
|
12710
|
+
key: list.fieldKey,
|
|
12711
|
+
label: list.sourceName ? `Itens de ${list.sourceName}` : "Itens",
|
|
12712
|
+
control: "repeater",
|
|
12713
|
+
maxItems: 100,
|
|
12714
|
+
itemFields: list.itemFields.map((key) => ({
|
|
12715
|
+
key,
|
|
12716
|
+
label: key.replace(/([a-z\d])([A-Z])/g, "$1 $2").replace(/[-_]+/g, " "),
|
|
12717
|
+
control: /(?:url|href|link)$/i.test(key) ? "url" : /(?:description|desc|text|sub|answer|content)$/i.test(key) ? "textarea" : "text"
|
|
12718
|
+
}))
|
|
12719
|
+
});
|
|
12720
|
+
return {
|
|
12721
|
+
key: `migrated-${safeThemeId(component.name)}`,
|
|
12722
|
+
name: label || component.name,
|
|
12723
|
+
description: "Componente visual migrado; todo o conteúdo é configurado pelo painel.",
|
|
12724
|
+
category: "Listas",
|
|
12725
|
+
schemaVersion: 1,
|
|
12726
|
+
fields
|
|
12727
|
+
};
|
|
12728
|
+
}
|
|
12729
|
+
function contentType(component) {
|
|
12730
|
+
const name = normalized(component.name);
|
|
12731
|
+
const hasRole = (role) => component.roles.some((candidate) => candidate.role === role);
|
|
12732
|
+
const hasEditorialImage = component.jsx.some(({ tag }) => [
|
|
12733
|
+
"img",
|
|
12734
|
+
"image",
|
|
12735
|
+
"picture"
|
|
12736
|
+
].includes(tag.toLowerCase()));
|
|
12737
|
+
if (name.includes("carousel") && /(product|produto|catalog)/.test(name)) return "products-carousel";
|
|
12738
|
+
if (hasRole("PRODUCT_GRID") || /(product|produto|catalog|vitrine)/.test(name)) return "products-grid";
|
|
12739
|
+
if (/(service|servico)/.test(name)) return "services-grid";
|
|
12740
|
+
if (/(blog|post|article|artigo)/.test(name)) return "blog-grid";
|
|
12741
|
+
if (/(case|project|projeto|portfolio|testimonial|depoimento)/.test(name)) return "cases-grid";
|
|
12742
|
+
if (name.includes("banner") && /(carousel|slider|slide)/.test(name)) return "banner-carousel";
|
|
12743
|
+
if (component.contentLists.length) return "theme-component";
|
|
12744
|
+
if (/(hero|banner|masthead)/.test(name)) return "hero";
|
|
12745
|
+
if (customComponentKind(component)) return "theme-component";
|
|
12746
|
+
if (/(cta|calltoaction|contact|contato|newsletter|final)/.test(name)) return "cta";
|
|
12747
|
+
if (/(image|imagem|showcase|dashboard|integration|integracao|widget|media|about|sobre)/.test(name)) return "image-text";
|
|
12748
|
+
if (hasEditorialImage) return "image-text";
|
|
12749
|
+
return "rich-text";
|
|
12750
|
+
}
|
|
12751
|
+
function contentBindings(analysis, selected) {
|
|
12752
|
+
const home = selected.HOME?.component;
|
|
12753
|
+
const excluded = new Set([
|
|
12754
|
+
selected.HEADER?.component.id,
|
|
12755
|
+
selected.FOOTER?.component.id,
|
|
12756
|
+
selected.PRODUCT_DETAIL?.component.id
|
|
12757
|
+
].filter((id) => Boolean(id)));
|
|
12758
|
+
if (selected.PRODUCT_CARD?.component.id !== selected.PRODUCT_GRID?.component.id) excluded.add(selected.PRODUCT_CARD?.component.id ?? "");
|
|
12759
|
+
const byName = new Map(analysis.components.map((component) => [normalized(component.name), component]));
|
|
12760
|
+
const candidates = [];
|
|
12761
|
+
const add = (component) => {
|
|
12762
|
+
if (!component || excluded.has(component.id) || candidates.some((candidate) => candidate.id === component.id)) return;
|
|
12763
|
+
candidates.push(component);
|
|
12764
|
+
};
|
|
12765
|
+
if (home) for (const node of home.jsx) {
|
|
12766
|
+
const componentName = node.tag.split(".")[0];
|
|
12767
|
+
const component = byName.get(normalized(componentName));
|
|
12768
|
+
if (!component || component.id === home.id) continue;
|
|
12769
|
+
const name = normalized(component.name);
|
|
12770
|
+
if (/^(suspense|fragment|provider|layout|router|route|link|image)$/.test(name)) continue;
|
|
12771
|
+
if (/(whatsapp|floating|modal|dialog|toast|tooltip|provider|deferred|fallback|skeleton|boundary|loader)/.test(name)) continue;
|
|
12772
|
+
add(component);
|
|
12773
|
+
}
|
|
12774
|
+
const reachableFiles = /* @__PURE__ */ new Set();
|
|
12775
|
+
const modulesByFile = new Map(analysis.sourceGraph.modules.map((module) => [module.file, module]));
|
|
12776
|
+
const pendingFiles = analysis.sourceGraph.entrypoint?.pageFile ? [analysis.sourceGraph.entrypoint.pageFile] : home ? [home.file] : [];
|
|
12777
|
+
while (pendingFiles.length) {
|
|
12778
|
+
const file = pendingFiles.shift();
|
|
12779
|
+
if (reachableFiles.has(file)) continue;
|
|
12780
|
+
reachableFiles.add(file);
|
|
12781
|
+
const module = modulesByFile.get(file);
|
|
12782
|
+
for (const dependency of module?.dependencies ?? []) {
|
|
12783
|
+
if (!dependency.resolvedFile || dependency.type === "BUSINESS") continue;
|
|
12784
|
+
const target = analysis.sourceGraph.modules.find((candidate) => path.resolve(candidate.absolutePath) === path.resolve(dependency.resolvedFile));
|
|
12785
|
+
if (target?.kind === "SOURCE" && !reachableFiles.has(target.file)) pendingFiles.push(target.file);
|
|
12786
|
+
}
|
|
12787
|
+
}
|
|
12788
|
+
for (const component of analysis.components) {
|
|
12789
|
+
if (!reachableFiles.has(component.file) || component.id === home?.id) continue;
|
|
12790
|
+
if (!component.jsx.some(({ tag }) => tag.toLowerCase() === "section")) continue;
|
|
12791
|
+
add(component);
|
|
12792
|
+
}
|
|
12793
|
+
if (!candidates.length) {
|
|
12794
|
+
add(selected.HERO?.component);
|
|
12795
|
+
add(selected.PRODUCT_GRID?.component);
|
|
12796
|
+
add(selected.SECTION?.component);
|
|
12797
|
+
}
|
|
12798
|
+
if (!candidates.length && home) add(home);
|
|
12799
|
+
return candidates.map((component, order) => {
|
|
12800
|
+
const type = contentType(component);
|
|
12801
|
+
const slug = safeThemeId(component.name);
|
|
12802
|
+
const customKind = type === "theme-component" ? customComponentKind(component) : null;
|
|
12803
|
+
const contentLists = customKind ? component.contentLists.map((list, index) => ({
|
|
12804
|
+
...list,
|
|
12805
|
+
fieldKey: index === 0 ? "items" : `items${index + 1}`
|
|
12806
|
+
})) : component.contentLists;
|
|
12807
|
+
const componentDefinition = type !== "theme-component" ? void 0 : customKind ? customComponentDefinition(customKind) : component.contentLists.length ? generatedListComponentDefinition(component) : void 0;
|
|
12808
|
+
return {
|
|
12809
|
+
id: `migrated-${slug}-${order + 1}`,
|
|
12810
|
+
component: component.name,
|
|
12811
|
+
file: component.file,
|
|
12812
|
+
type,
|
|
12813
|
+
order,
|
|
12814
|
+
fields: componentDefinition?.fields.map(({ key }) => key) ?? CONTENT_FIELDS[type],
|
|
12815
|
+
classes: classProfile(component),
|
|
12816
|
+
componentKey: componentDefinition?.key,
|
|
12817
|
+
componentDefinition,
|
|
12818
|
+
contentLists
|
|
12819
|
+
};
|
|
12820
|
+
});
|
|
12821
|
+
}
|
|
9542
12822
|
function createMigrationPlan(analysis, options) {
|
|
9543
12823
|
const selected = {};
|
|
9544
12824
|
for (const role of ROLES) {
|
|
@@ -9559,12 +12839,15 @@ function createMigrationPlan(analysis, options) {
|
|
|
9559
12839
|
if (!selected.PRODUCT_CARD) warnings.push("ProductCard não identificado; será usado o card do tema base.");
|
|
9560
12840
|
if (analysis.tailwind.detected) warnings.push("Tailwind detectado: classes observadas serão preservadas e recompiladas no tema gerado.");
|
|
9561
12841
|
const outputName = path.basename(path.resolve(options.outputDirectory));
|
|
12842
|
+
const bindings = contentBindings(analysis, selected);
|
|
12843
|
+
if (bindings.length) warnings.push(`${bindings.length} seção(ões) visual(is) convertida(s) para conteúdo configurável pelo painel Nuvler; textos e imagens originais não serão publicados como dados do tema.`);
|
|
9562
12844
|
return {
|
|
9563
12845
|
analysis,
|
|
9564
12846
|
themeId: safeThemeId(options.id?.trim() || outputName),
|
|
9565
12847
|
themeName: options.name?.trim() || themeName(analysis.projectName),
|
|
9566
12848
|
selected,
|
|
9567
|
-
|
|
12849
|
+
contentBindings: bindings,
|
|
12850
|
+
styles: analysis.styles.filter(({ imported, file, module }) => imported && file.endsWith(".css") && (!analysis.sourceGraph.entrypoint || !module)),
|
|
9568
12851
|
assets: analysis.assets,
|
|
9569
12852
|
tokens: inferredTokens(analysis, selected),
|
|
9570
12853
|
warnings: [...new Set(warnings)]
|
|
@@ -9658,6 +12941,9 @@ function printReport(report, outputDirectory) {
|
|
|
9658
12941
|
for (const [role, label] of Object.entries(ROLE_LABELS)) if (report.selectedComponents[role]) console.log(`✓ ${label}`);
|
|
9659
12942
|
console.log(`✓ ${report.assetsCopied} asset(s) copiado(s)`);
|
|
9660
12943
|
console.log(`✓ ${report.styleFilesPreserved} arquivo(s) de estilo preservado(s)`);
|
|
12944
|
+
if (report.entrypoint) console.log(`✓ Árvore visual preservada a partir de ${report.entrypoint.pageFile}`);
|
|
12945
|
+
if (report.sourceFilesPreserved) console.log(`✓ ${report.sourceFilesPreserved} arquivo(s) fonte preservado(s)`);
|
|
12946
|
+
if (report.contentBindings.length) console.log(`✓ ${report.contentBindings.length} seção(ões) preparada(s) para o painel Nuvler`);
|
|
9661
12947
|
if (report.tailwind.detected) console.log("✓ Tailwind detectado e configurado");
|
|
9662
12948
|
for (const ignored of report.ignoredFiles) console.log(`⚠ ${ignored.file} ignorado: ${ignored.reason}`);
|
|
9663
12949
|
for (const warning of report.warnings) console.log(`⚠ ${warning}`);
|
|
@@ -9665,6 +12951,7 @@ function printReport(report, outputDirectory) {
|
|
|
9665
12951
|
console.log("✓ Manifesto Nuvler validado");
|
|
9666
12952
|
if (report.validation.typecheck) console.log("✓ Typecheck concluído");
|
|
9667
12953
|
if (report.validation.build) console.log("✓ Build do tema concluído");
|
|
12954
|
+
console.log("✓ Conteúdo extraído em CONTENT_SETUP.md e migration-content-seed.json");
|
|
9668
12955
|
console.log(`✓ Tema Nuvler gerado em ${outputDirectory}`);
|
|
9669
12956
|
console.log("");
|
|
9670
12957
|
}
|
|
@@ -10025,7 +13312,7 @@ async function authLogout() {
|
|
|
10025
13312
|
//#endregion
|
|
10026
13313
|
//#region src/index.ts
|
|
10027
13314
|
var program = new Command();
|
|
10028
|
-
program.name("nuvler").description("Nuvler Theme Development CLI").version("0.
|
|
13315
|
+
program.name("nuvler").description("Nuvler Theme Development CLI").version("0.5.1");
|
|
10029
13316
|
var theme = program.command("theme").description("Manage Nuvler themes");
|
|
10030
13317
|
var auth = program.command("auth").description("Manage developer authentication");
|
|
10031
13318
|
auth.command("login").requiredOption("--token <token>", "Developer token").option("--api-url <url>", "Nuvler API base URL (or use NUVLER_API_URL)").action(async (options) => {
|