@nuvler/cli 0.5.0 → 0.5.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/nuvler.js CHANGED
@@ -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.5.0";
34
- var SDK_VERSION_RANGE = "^1.3.0";
33
+ var CLI_VERSION_RANGE = "^0.5.2";
34
+ var SDK_VERSION_RANGE = "^1.3.2";
35
35
  var THEME_TEMPLATES = [
36
36
  {
37
37
  id: "starter",
@@ -5288,7 +5288,7 @@ var schemas_exports = /* @__PURE__ */ __exportAll({
5288
5288
  preprocess: () => preprocess,
5289
5289
  promise: () => promise,
5290
5290
  readonly: () => readonly,
5291
- record: () => record$1,
5291
+ record: () => record,
5292
5292
  refine: () => refine,
5293
5293
  set: () => set,
5294
5294
  strictObject: () => strictObject,
@@ -6147,7 +6147,7 @@ var ZodRecord = /*@__PURE__*/ $constructor("ZodRecord", (inst, def) => {
6147
6147
  inst.keyType = def.keyType;
6148
6148
  inst.valueType = def.valueType;
6149
6149
  });
6150
- function record$1(keyType, valueType, params) {
6150
+ function record(keyType, valueType, params) {
6151
6151
  if (!valueType || !valueType._zod) return new ZodRecord({
6152
6152
  type: "record",
6153
6153
  keyType: string$1(),
@@ -6600,7 +6600,7 @@ function json(params) {
6600
6600
  boolean$1(),
6601
6601
  _null(),
6602
6602
  array(jsonSchema),
6603
- record$1(string$1(), jsonSchema)
6603
+ record(string$1(), jsonSchema)
6604
6604
  ]);
6605
6605
  });
6606
6606
  return jsonSchema;
@@ -6676,6 +6676,24 @@ var fieldOptionSchema = object({
6676
6676
  label: string$1().trim().min(1).max(120),
6677
6677
  value: string$1().trim().min(1).max(120)
6678
6678
  }).strict();
6679
+ var ThemeContactFieldDefinitionSchema = object({
6680
+ key: fieldKeySchema,
6681
+ label: string$1().trim().min(1).max(500),
6682
+ type: _enum([
6683
+ "text",
6684
+ "email",
6685
+ "tel",
6686
+ "url",
6687
+ "number",
6688
+ "textarea",
6689
+ "select",
6690
+ "checkbox"
6691
+ ]),
6692
+ required: boolean$1().optional(),
6693
+ placeholder: string$1().trim().max(300).optional(),
6694
+ options: array(fieldOptionSchema).max(100).optional(),
6695
+ mask: literal("whatsapp-br").optional()
6696
+ }).strict();
6679
6697
  var fieldBaseShape = {
6680
6698
  key: fieldKeySchema,
6681
6699
  label: string$1().trim().min(1).max(120),
@@ -6687,7 +6705,8 @@ var fieldBaseShape = {
6687
6705
  string$1().max(5e3),
6688
6706
  number$1().finite(),
6689
6707
  boolean$1(),
6690
- _null()
6708
+ _null(),
6709
+ array(ThemeContactFieldDefinitionSchema).max(50)
6691
6710
  ]).optional(),
6692
6711
  options: array(fieldOptionSchema).min(1).max(100).optional(),
6693
6712
  min: number$1().finite().optional(),
@@ -6711,6 +6730,16 @@ var ThemeHomeComponentFieldSchema = object({
6711
6730
  ...fieldBaseShape,
6712
6731
  itemFields: array(ThemeHomeComponentItemFieldSchema).min(1).max(30).optional()
6713
6732
  }).strict().superRefine((field, context) => {
6733
+ if (Array.isArray(field.defaultValue) && field.control !== "contact-fields") context.addIssue({
6734
+ code: ZodIssueCode.custom,
6735
+ path: ["defaultValue"],
6736
+ message: "Padrões de campos de contato só podem ser usados em contact-fields"
6737
+ });
6738
+ if (field.control === "contact-fields" && field.defaultValue !== void 0 && !Array.isArray(field.defaultValue)) context.addIssue({
6739
+ code: ZodIssueCode.custom,
6740
+ path: ["defaultValue"],
6741
+ message: "O padrão de contact-fields deve ser uma lista"
6742
+ });
6714
6743
  if (field.control === "select" && !field.options?.length) context.addIssue({
6715
6744
  code: ZodIssueCode.custom,
6716
6745
  path: ["options"],
@@ -6877,7 +6906,7 @@ var ThemeSiteSchema = object({
6877
6906
  var ThemeComponentSectionDataSchema = object({
6878
6907
  componentKey: componentKeySchema,
6879
6908
  schemaVersion: number$1().int().positive().max(1e3),
6880
- props: record$1(string$1(), unknown())
6909
+ props: record(string$1(), unknown())
6881
6910
  }).strict();
6882
6911
  var ThemeHomeSectionSchema = object({
6883
6912
  id: string$1().optional(),
@@ -6896,7 +6925,7 @@ var ThemeHomeSectionSchema = object({
6896
6925
  ]),
6897
6926
  enabled: boolean$1(),
6898
6927
  order: number$1().int().nonnegative(),
6899
- data: record$1(string$1(), unknown())
6928
+ data: record(string$1(), unknown())
6900
6929
  }).strict().superRefine((section, context) => {
6901
6930
  if (section.type !== "theme-component") return;
6902
6931
  const parsed = ThemeComponentSectionDataSchema.safeParse(section.data);
@@ -7735,94 +7764,6 @@ async function loadThemeContext({ store, apiUrl }) {
7735
7764
  }
7736
7765
  //#endregion
7737
7766
  //#region src/preview/prepare.ts
7738
- function record(value) {
7739
- return value && typeof value === "object" && !Array.isArray(value) ? value : null;
7740
- }
7741
- function meaningful(value) {
7742
- if (typeof value === "string") return Boolean(value.trim());
7743
- if (Array.isArray(value)) return value.length > 0;
7744
- return value !== null && value !== void 0;
7745
- }
7746
- async function migrationSeedContext(directory, context) {
7747
- let parsed;
7748
- try {
7749
- parsed = JSON.parse(await readFile(path.join(directory, "migration-content-seed.json"), "utf8"));
7750
- } catch (error) {
7751
- if (error.code === "ENOENT") return {
7752
- context,
7753
- sections: 0
7754
- };
7755
- throw new Error("migration-content-seed.json inválido; regenere o tema migrado.", { cause: error });
7756
- }
7757
- const seed = record(parsed);
7758
- const rawSections = Array.isArray(seed?.sections) ? seed.sections : [];
7759
- const supported = /* @__PURE__ */ new Set([
7760
- "hero",
7761
- "banner-carousel",
7762
- "image-text",
7763
- "rich-text",
7764
- "cta",
7765
- "services-grid",
7766
- "blog-grid",
7767
- "cases-grid",
7768
- "products-grid",
7769
- "products-carousel"
7770
- ]);
7771
- const seeds = rawSections.flatMap((candidate) => {
7772
- const section = record(candidate);
7773
- const data = record(section?.data);
7774
- if (!section || !data || typeof section.id !== "string" || typeof section.type !== "string" || !supported.has(section.type)) return [];
7775
- return [{
7776
- id: section.id,
7777
- type: section.type,
7778
- enabled: true,
7779
- order: typeof section.order === "number" ? section.order : 0,
7780
- data
7781
- }];
7782
- });
7783
- if (!seeds.length) return {
7784
- context,
7785
- sections: 0
7786
- };
7787
- const merged = context.home.content.sections.map((section) => ({
7788
- ...section,
7789
- data: { ...section.data }
7790
- }));
7791
- const claimed = /* @__PURE__ */ new Set();
7792
- for (const seedSection of seeds) {
7793
- const exact = merged.findIndex(({ id }) => id === seedSection.id);
7794
- const compatible = exact >= 0 ? exact : merged.findIndex((section, index) => !claimed.has(index) && section.type === seedSection.type);
7795
- if (compatible < 0) {
7796
- merged.push(seedSection);
7797
- continue;
7798
- }
7799
- claimed.add(compatible);
7800
- const configured = merged[compatible];
7801
- const configuredValues = Object.fromEntries(Object.entries(configured.data).filter(([, value]) => meaningful(value)));
7802
- merged[compatible] = {
7803
- ...configured,
7804
- id: seedSection.id,
7805
- data: {
7806
- ...seedSection.data,
7807
- ...configuredValues
7808
- }
7809
- };
7810
- }
7811
- merged.sort((left, right) => left.order - right.order);
7812
- return {
7813
- context: ThemeContextSchema.parse({
7814
- ...context,
7815
- home: {
7816
- ...context.home,
7817
- content: {
7818
- ...context.home.content,
7819
- sections: merged
7820
- }
7821
- }
7822
- }),
7823
- sections: seeds.length
7824
- };
7825
- }
7826
7767
  async function prepareThemePreview(options) {
7827
7768
  const project = await loadThemeProject(options.themeDirectory);
7828
7769
  const configured = await readThemeProjectConfig(project.directory);
@@ -7834,13 +7775,12 @@ async function prepareThemePreview(options) {
7834
7775
  apiUrl: session.apiUrl
7835
7776
  });
7836
7777
  if (context.store.slug !== tenant.slug) throw new Error(`A API retornou contexto do tenant "${context.store.slug}" para "${tenant.slug}".`);
7837
- const preview = await migrationSeedContext(project.directory, context);
7838
7778
  return {
7839
7779
  project,
7840
- context: preview.context,
7780
+ context: ThemeContextSchema.parse(context),
7841
7781
  apiUrl: session.apiUrl,
7842
7782
  tenant,
7843
- migrationSeedSections: preview.sections
7783
+ migrationSeedSections: 0
7844
7784
  };
7845
7785
  }
7846
7786
  //#endregion
@@ -8748,6 +8688,16 @@ function jsxAttributes(node) {
8748
8688
  function analyzeJsx(root) {
8749
8689
  const result = [];
8750
8690
  function visit(node, depth) {
8691
+ if (ts.isJsxExpression(node) && !node.expression) {
8692
+ const commentedComponent = node.getText().match(/<([A-Z][A-Za-z0-9_$]*)\b[^>]*\/>/);
8693
+ if (commentedComponent) result.push({
8694
+ tag: commentedComponent[1],
8695
+ depth,
8696
+ classes: [],
8697
+ text: [],
8698
+ attributes: []
8699
+ });
8700
+ }
8751
8701
  if (ts.isJsxElement(node) || ts.isJsxSelfClosingElement(node)) {
8752
8702
  const attributes = jsxAttributes(node);
8753
8703
  const text = [];
@@ -8782,6 +8732,74 @@ function containsJsx(node) {
8782
8732
  visit(node);
8783
8733
  return found;
8784
8734
  }
8735
+ var PRESENTATION_FIELD = /^(?:icon|icons|color|colour|class|className|style|variant|layout|position|align|alignment|size|dot|shape|theme)$/i;
8736
+ function componentContentLists(node, source) {
8737
+ const declarations = /* @__PURE__ */ new Map();
8738
+ const candidates = [];
8739
+ const seenArrays = /* @__PURE__ */ new Set();
8740
+ function unwrap(expression) {
8741
+ if (ts.isAsExpression(expression) || ts.isTypeAssertionExpression(expression) || ts.isParenthesizedExpression(expression)) return unwrap(expression.expression);
8742
+ return expression;
8743
+ }
8744
+ function propertyName(name) {
8745
+ return ts.isIdentifier(name) || ts.isStringLiteralLike(name) || ts.isNumericLiteral(name) ? name.text : null;
8746
+ }
8747
+ function collect(child) {
8748
+ if (ts.isVariableDeclaration(child) && ts.isIdentifier(child.name) && child.initializer) {
8749
+ const initializer = unwrap(child.initializer);
8750
+ if (ts.isArrayLiteralExpression(initializer)) declarations.set(child.name.text, initializer);
8751
+ }
8752
+ ts.forEachChild(child, collect);
8753
+ }
8754
+ collect(source);
8755
+ function findMaps(child) {
8756
+ if (ts.isCallExpression(child) && ts.isPropertyAccessExpression(child.expression) && child.expression.name.text === "map") {
8757
+ const receiver = unwrap(child.expression.expression);
8758
+ const sourceName = ts.isIdentifier(receiver) ? receiver.text : null;
8759
+ const array = ts.isArrayLiteralExpression(receiver) ? receiver : sourceName ? declarations.get(sourceName) : void 0;
8760
+ if (array && !seenArrays.has(array.pos)) {
8761
+ seenArrays.add(array.pos);
8762
+ candidates.push({
8763
+ sourceName,
8764
+ array
8765
+ });
8766
+ }
8767
+ }
8768
+ ts.forEachChild(child, findMaps);
8769
+ }
8770
+ if (node.body) findMaps(node.body);
8771
+ let inlineIndex = 0;
8772
+ return candidates.flatMap(({ sourceName, array }) => {
8773
+ const fields = /* @__PURE__ */ new Set();
8774
+ const presentationFields = /* @__PURE__ */ new Set();
8775
+ let primitive = false;
8776
+ for (const element of array.elements) {
8777
+ const value = ts.isExpression(element) ? unwrap(element) : null;
8778
+ if (!value) continue;
8779
+ if (ts.isStringLiteralLike(value) || ts.isNoSubstitutionTemplateLiteral(value) || ts.isNumericLiteral(value)) {
8780
+ primitive = true;
8781
+ continue;
8782
+ }
8783
+ if (!ts.isObjectLiteralExpression(value)) continue;
8784
+ for (const property of value.properties) {
8785
+ if (!ts.isPropertyAssignment(property) && !ts.isShorthandPropertyAssignment(property)) continue;
8786
+ const name = propertyName(property.name);
8787
+ if (!name) continue;
8788
+ if (PRESENTATION_FIELD.test(name)) presentationFields.add(name);
8789
+ else fields.add(name);
8790
+ }
8791
+ }
8792
+ if (!primitive && !fields.size) return [];
8793
+ const fallbackKey = inlineIndex++ === 0 ? "items" : `items${inlineIndex}`;
8794
+ return [{
8795
+ sourceName,
8796
+ fieldKey: sourceName && /^[a-z][a-zA-Z0-9-]{0,63}$/.test(sourceName) ? sourceName : fallbackKey,
8797
+ itemFields: primitive ? ["title"] : [...fields].slice(0, 30),
8798
+ primitive,
8799
+ presentationFields: [...presentationFields]
8800
+ }];
8801
+ });
8802
+ }
8785
8803
  function componentNodes(source) {
8786
8804
  const result = [];
8787
8805
  const defaultNames = /* @__PURE__ */ new Set();
@@ -8948,6 +8966,7 @@ async function analyzeComponentFile(absoluteFile, sourceDirectory, framework) {
8948
8966
  jsx,
8949
8967
  rootClasses: jsx.find(({ depth }) => depth === 0)?.classes ?? jsx[0]?.classes ?? [],
8950
8968
  text: [...new Set(jsx.flatMap((item) => item.text))].slice(0, 30),
8969
+ contentLists: componentContentLists(node, source),
8951
8970
  businessSignals: signals,
8952
8971
  roles: []
8953
8972
  };
@@ -9415,9 +9434,32 @@ function transformMigratedSource(module, content, graph, destinationFile, destin
9415
9434
  }
9416
9435
  function adaptFunction(node, adaptation) {
9417
9436
  if (!node.body || !ts.isBlock(node.body)) return;
9418
- const { bindingId, componentKey } = adaptation;
9437
+ const { bindingId, componentKey, contentLists = [] } = adaptation;
9419
9438
  const hookName = "__nuvlerSection";
9420
9439
  const mapped = /* @__PURE__ */ new Set();
9440
+ const adaptedItemArrays = /* @__PURE__ */ new Set();
9441
+ function presentationItems(expression) {
9442
+ const array = unwrappedExpression$1(expression);
9443
+ if (!ts.isArrayLiteralExpression(array)) return null;
9444
+ let hasPresentation = false;
9445
+ const items = array.elements.map((element) => {
9446
+ const item = unwrappedExpression$1(element);
9447
+ if (!ts.isObjectLiteralExpression(item)) return "{}";
9448
+ return `{ ${item.properties.flatMap((property) => {
9449
+ if (ts.isShorthandPropertyAssignment(property)) {
9450
+ if (!/^(?:icon|icons|color|colour|class|className|style|variant|layout|position|align|alignment|size|dot|shape|theme)$/i.test(property.name.text)) return [];
9451
+ hasPresentation = true;
9452
+ return [property.getText(source)];
9453
+ }
9454
+ if (!ts.isPropertyAssignment(property)) return [];
9455
+ const name = property.name.getText(source).replace(/^["']|["']$/g, "");
9456
+ if (!/^(?:icon|icons|color|colour|class|className|style|variant|layout|position|align|alignment|size|dot|shape|theme)$/i.test(name)) return [];
9457
+ hasPresentation = true;
9458
+ return [property.getText(source)];
9459
+ }).join(", ")} }`;
9460
+ });
9461
+ return hasPresentation ? `[${items.join(", ")}]` : null;
9462
+ }
9421
9463
  function findMapped(child) {
9422
9464
  if (ts.isCallExpression(child) && ts.isIdentifier(child.expression) && child.expression.text === "t" && child.arguments[0] && ts.isStringLiteralLike(child.arguments[0])) {
9423
9465
  const field = mappedField(child.arguments[0].text);
@@ -9466,27 +9508,56 @@ function transformMigratedSource(module, content, graph, destinationFile, destin
9466
9508
  });
9467
9509
  return;
9468
9510
  }
9469
- if (ts.isVariableDeclaration(child) && ts.isIdentifier(child.name) && child.initializer && ts.isArrayLiteralExpression(unwrappedExpression$1(child.initializer)) && (/(?:items?|faqs?|questions?|benefits?|features?|stats?|metrics?|numbers?|audiences?|profiles?|steps?)/i.test(child.name.text) || componentKey === "contacts" && /contacts?/i.test(child.name.text))) {
9511
+ if (ts.isVariableDeclaration(child) && ts.isIdentifier(child.name) && child.initializer && ts.isArrayLiteralExpression(unwrappedExpression$1(child.initializer))) {
9512
+ const sourceName = child.name.text;
9513
+ const list = contentLists.find((candidate) => candidate.sourceName === sourceName);
9514
+ if (!list) {
9515
+ ts.forEachChild(child, adapt);
9516
+ return;
9517
+ }
9518
+ const presentation = presentationItems(child.initializer);
9519
+ adaptedItemArrays.add(sourceName);
9520
+ const configured = presentation ? `migratedItems(${hookName}, ${JSON.stringify(list.fieldKey)}, ${presentation})` : `migratedItems(${hookName}, ${JSON.stringify(list.fieldKey)})`;
9470
9521
  edits.push({
9471
9522
  start: child.initializer.getStart(source),
9472
9523
  end: child.initializer.getEnd(),
9473
- text: `migratedItems(${hookName})`
9524
+ text: list.primitive ? `${configured}.map((item) => migratedText(item, "title"))` : configured
9474
9525
  });
9475
9526
  return;
9476
9527
  }
9477
- if (ts.isPropertyAccessExpression(child) && child.name.text === "map" && ts.isIdentifier(child.expression) && (/(?:items?|faqs?|questions?|benefits?|features?|stats?|metrics?|numbers?|audiences?|profiles?|steps?)/i.test(child.expression.text) || componentKey === "contacts" && /contacts?/i.test(child.expression.text))) {
9528
+ if (ts.isPropertyAccessExpression(child) && child.name.text === "map" && ts.isIdentifier(child.expression)) {
9529
+ const sourceName = child.expression.text;
9530
+ const list = contentLists.find((candidate) => candidate.sourceName === sourceName);
9531
+ if (!list) {
9532
+ ts.forEachChild(child, adapt);
9533
+ return;
9534
+ }
9535
+ if (adaptedItemArrays.has(sourceName)) return;
9536
+ const configured = `migratedItems(${hookName}, ${JSON.stringify(list.fieldKey)})`;
9478
9537
  edits.push({
9479
9538
  start: child.expression.getStart(source),
9480
9539
  end: child.expression.getEnd(),
9481
- text: `migratedItems(${hookName})`
9540
+ text: list.primitive ? `${configured}.map((item) => migratedText(item, "title"))` : configured
9482
9541
  });
9483
9542
  return;
9484
9543
  }
9485
- if (componentKey === "feature-list" && ts.isPropertyAccessExpression(child) && child.name.text === "map" && ts.isArrayLiteralExpression(unwrappedExpression$1(child.expression))) {
9544
+ if (ts.isPropertyAccessExpression(child) && child.name.text === "map" && ts.isArrayLiteralExpression(unwrappedExpression$1(child.expression))) {
9545
+ const directLists = contentLists.filter((list) => list.sourceName === null);
9546
+ const directIndex = directLists.findIndex((_list, index) => {
9547
+ return directLists[index] && !adaptedItemArrays.has(`__direct_${index}`);
9548
+ });
9549
+ const list = directIndex >= 0 ? directLists[directIndex] : void 0;
9550
+ if (!list) {
9551
+ ts.forEachChild(child, adapt);
9552
+ return;
9553
+ }
9554
+ adaptedItemArrays.add(`__direct_${directIndex}`);
9555
+ const presentation = presentationItems(child.expression);
9556
+ const configured = presentation ? `migratedItems(${hookName}, ${JSON.stringify(list.fieldKey)}, ${presentation})` : `migratedItems(${hookName}, ${JSON.stringify(list.fieldKey)})`;
9486
9557
  edits.push({
9487
9558
  start: child.expression.getStart(source),
9488
9559
  end: child.expression.getEnd(),
9489
- text: `migratedItems(${hookName}).map((item) => migratedText(item, "title"))`
9560
+ text: list.primitive ? `${configured}.map((item) => migratedText(item, "title"))` : configured
9490
9561
  });
9491
9562
  return;
9492
9563
  }
@@ -9561,6 +9632,19 @@ function transformMigratedSource(module, content, graph, destinationFile, destin
9561
9632
  });
9562
9633
  return;
9563
9634
  }
9635
+ if (child.initializer && [
9636
+ "aria-label",
9637
+ "aria-description",
9638
+ "placeholder",
9639
+ "title"
9640
+ ].includes(name) && (ts.isStringLiteral(child.initializer) || ts.isJsxExpression(child.initializer) && child.initializer.expression && ts.isStringLiteralLike(child.initializer.expression))) {
9641
+ edits.push({
9642
+ start: child.initializer.getStart(source),
9643
+ end: child.initializer.getEnd(),
9644
+ text: "{undefined}"
9645
+ });
9646
+ return;
9647
+ }
9564
9648
  }
9565
9649
  ts.forEachChild(child, adapt);
9566
9650
  }
@@ -9653,7 +9737,13 @@ function transformMigratedSource(module, content, graph, destinationFile, destin
9653
9737
  text: `import { MigratedContactFields, migratedImage, migratedItems, migratedLink, migratedText, migratedVideo, useMigratedContactForm, useMigratedSection } from ${JSON.stringify(adapterImport)};\n`
9654
9738
  });
9655
9739
  }
9656
- return applyEdits(content, edits);
9740
+ let transformed = applyEdits(content, edits);
9741
+ for (const adaptation of options.content ?? []) {
9742
+ const escaped = adaptation.componentName.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
9743
+ const commentedSection = new RegExp(`\\{\\s*\\/\\*\\s*(<${escaped}\\s*\\/>)\\s*\\*\\/\\s*\\}`, "g");
9744
+ transformed = transformed.replace(commentedSection, "$1");
9745
+ }
9746
+ return transformed;
9657
9747
  }
9658
9748
  function exportedNames(source) {
9659
9749
  const values = /* @__PURE__ */ new Set();
@@ -9720,7 +9810,11 @@ function contentAdaptations(plan) {
9720
9810
  binding: {
9721
9811
  id: "__header",
9722
9812
  file: plan.selected.HEADER.component.file,
9723
- component: plan.selected.HEADER.component.name
9813
+ component: plan.selected.HEADER.component.name,
9814
+ contentLists: plan.selected.HEADER.component.contentLists.map((list, index) => ({
9815
+ ...list,
9816
+ fieldKey: index === 0 ? "items" : `items${index + 1}`
9817
+ }))
9724
9818
  },
9725
9819
  special: true
9726
9820
  });
@@ -9728,7 +9822,11 @@ function contentAdaptations(plan) {
9728
9822
  binding: {
9729
9823
  id: "__footer",
9730
9824
  file: plan.selected.FOOTER.component.file,
9731
- component: plan.selected.FOOTER.component.name
9825
+ component: plan.selected.FOOTER.component.name,
9826
+ contentLists: plan.selected.FOOTER.component.contentLists.map((list, index) => ({
9827
+ ...list,
9828
+ fieldKey: index === 0 ? "items" : `items${index + 1}`
9829
+ }))
9732
9830
  },
9733
9831
  special: true
9734
9832
  });
@@ -9740,7 +9838,8 @@ function contentAdaptations(plan) {
9740
9838
  current.push({
9741
9839
  componentName: binding.component,
9742
9840
  bindingId: binding.id,
9743
- componentKey: binding.componentKey
9841
+ componentKey: binding.componentKey,
9842
+ contentLists: binding.contentLists
9744
9843
  });
9745
9844
  result.set(binding.file, current);
9746
9845
  }
@@ -9838,7 +9937,7 @@ async function runFidelityPass(plan, directory) {
9838
9937
  nextImageAdapterFile: path.join(directory, "src", "migrated-next-image.tsx"),
9839
9938
  content: adaptations.get(module.file),
9840
9939
  unwrapDocumentTags,
9841
- removeComponents: module.file === graph.entrypoint?.pageFile ? plan.analysis.components.filter((component) => /(whatsapp|floating|float|chat|popup)/i.test(component.name)).map((component) => component.name) : []
9940
+ removeComponents: plan.analysis.components.filter((component) => /(whatsapp|floating|float|chat|popup)/i.test(component.name)).map((component) => component.name)
9842
9941
  });
9843
9942
  if (module.business && !module.visual) adaptedBusinessFiles.push(module.file);
9844
9943
  await writeFile(destination, module.business && !module.visual ? transformed : `// @ts-nocheck -- código preservado pela Nuvler Fidelity Pass\n${transformed}`, "utf8");
@@ -9947,16 +10046,10 @@ export function Header({ site, categories, pages }: HeaderProps) {
9947
10046
  <a className=${classes("nuvler-migrated-brand", style.brand)} href="/">
9948
10047
  {site.settings?.logo?.url ? <img src={site.settings.logo.url} alt={site.settings.logo.alt || name} /> : <span>{name}</span>}
9949
10048
  </a>
9950
- <nav className=${classes("nuvler-migrated-nav", style.navigation)} aria-label="Navegação principal">
9951
- <a href="/">Início</a>
9952
- {site.modules.includes("PRODUCTS") && <a href="/produtos">Produtos</a>}
10049
+ <nav className=${classes("nuvler-migrated-nav", style.navigation)}>
9953
10050
  {categories.slice(0, 6).map((category) => <a href={\`/\${category.slug}\`} key={category.slug}>{category.name}</a>)}
9954
10051
  {pages.slice(0, 4).map((page) => <a href={\`/\${page.slug}\`} key={page.slug}>{page.title}</a>)}
9955
10052
  </nav>
9956
- {site.modules.includes("PRODUCTS") && <form className="nuvler-migrated-search" action="/produtos">
9957
- <input name="busca" type="search" placeholder="Buscar produtos" />
9958
- <button className=${classes("nuvler-migrated-action", style.action)} type="submit">Buscar</button>
9959
- </form>}
9960
10053
  </div>
9961
10054
  </header>;
9962
10055
  }
@@ -9972,8 +10065,6 @@ export function Footer({ site, pages, template }: FooterProps) {
9972
10065
  <div className=${classes("nuvler-migrated-footer-inner", style.content)}>
9973
10066
  <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>
9974
10067
  <nav className=${classes("nuvler-migrated-footer-nav", style.navigation)} aria-label={template.footerNavigationLabel}>
9975
- <a href="/">Início</a>
9976
- {site.modules.includes("PRODUCTS") && <a href="/produtos">Produtos</a>}
9977
10068
  {pages.map((page) => <a href={\`/\${page.slug}\`} key={page.slug}>{page.title}</a>)}
9978
10069
  </nav>
9979
10070
  <div className="nuvler-migrated-contact">
@@ -10202,7 +10293,7 @@ function ThemeComponent({ section, binding, submitContact }: { section: ThemeHom
10202
10293
  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>;
10203
10294
  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>; }
10204
10295
  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>;
10205
- })}<div className="nuvler-migrated-form-wide"><button className="nuvler-migrated-action" disabled={status === "sending"} type="submit">{status === "sending" ? "Enviando…" : value(props, "submitLabel") || "Enviar contato"}</button>{status === "success" && <p role="status">{value(props, "successMessage") || "Contato enviado com sucesso."}</p>}{status === "error" && <p role="alert">{error}</p>}</div></form>
10296
+ })}<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>
10206
10297
  </section>;
10207
10298
  }
10208
10299
 
@@ -10293,7 +10384,7 @@ function configuredSection(id: string, sections: ThemeHomeSection[]): ThemeHomeS
10293
10384
  const custom = sections.find((section) => section.enabled
10294
10385
  && section.type === "theme-component"
10295
10386
  && section.data.componentKey === binding.componentKey);
10296
- if (custom) return custom;
10387
+ return custom;
10297
10388
  }
10298
10389
  const occurrence = bindingMetadata.filter((candidate) => candidate.type === binding.type && candidate.order < binding.order).length;
10299
10390
  return sections.filter((section) => section.enabled && section.type === binding.type).sort((left, right) => left.order - right.order)[occurrence];
@@ -10304,6 +10395,7 @@ export function useMigratedSection(id: string): Record<string, unknown> {
10304
10395
  if (!context) return {};
10305
10396
  if (id === "__header" || id === "__footer") {
10306
10397
  const name = context.site.settings?.siteName || context.site.tenant.name;
10398
+ const items = (context.menu ?? []).map((item) => ({ label: item.label, title: item.label, href: item.href, url: item.href }));
10307
10399
  return {
10308
10400
  title: name,
10309
10401
  description: context.site.settings?.description || "",
@@ -10312,6 +10404,7 @@ export function useMigratedSection(id: string): Record<string, unknown> {
10312
10404
  imageAlt: context.site.settings?.logo?.alt || name,
10313
10405
  buttonLabel: "",
10314
10406
  buttonUrl: "",
10407
+ items,
10315
10408
  };
10316
10409
  }
10317
10410
  const section = configuredSection(id, context.sections);
@@ -10368,21 +10461,37 @@ export function useMigratedContactForm(id: string) {
10368
10461
  };
10369
10462
  }
10370
10463
 
10371
- export function migratedItems(data: Record<string, unknown>, field = "items"): Record<string, unknown>[] {
10464
+ export function migratedItems(
10465
+ data: Record<string, unknown>,
10466
+ field = "items",
10467
+ presentation: Record<string, unknown>[] = [],
10468
+ ): Record<string, unknown>[] {
10372
10469
  const value = data[field];
10373
10470
  return Array.isArray(value)
10374
- ? value.filter((item): item is Record<string, unknown> => Boolean(item) && typeof item === "object" && !Array.isArray(item))
10471
+ ? value
10472
+ .filter((item): item is Record<string, unknown> => Boolean(item) && typeof item === "object" && !Array.isArray(item))
10473
+ .map((item, index) => {
10474
+ const title = item.title ?? item.label ?? item.name;
10475
+ const description = item.description ?? item.desc ?? item.text ?? item.sub;
10476
+ const normalized = {
10477
+ ...item,
10478
+ ...(title === undefined ? {} : { title, label: item.label ?? title }),
10479
+ ...(description === undefined ? {} : {
10480
+ description,
10481
+ desc: item.desc ?? description,
10482
+ sub: item.sub ?? description,
10483
+ }),
10484
+ };
10485
+ return presentation.length
10486
+ ? { ...presentation[index % presentation.length], ...normalized }
10487
+ : normalized;
10488
+ })
10375
10489
  : [];
10376
10490
  }
10377
10491
 
10378
10492
  export function MigratedContactFields({ data }: { data: Record<string, unknown> }) {
10379
10493
  const configured = migratedItems(data, "fields");
10380
- const fields = configured.length ? configured : [
10381
- { key: "name", label: "Nome", type: "text", required: true },
10382
- { key: "email", label: "E-mail", type: "email", required: true },
10383
- { key: "phone", label: "Telefone", type: "tel", required: false },
10384
- { key: "message", label: "Mensagem", type: "textarea", required: true },
10385
- ];
10494
+ const fields = configured;
10386
10495
  return <>
10387
10496
  {fields.map((field) => {
10388
10497
  const key = stringValue(field, "key");
@@ -10403,7 +10512,7 @@ export function MigratedContactFields({ data }: { data: Record<string, unknown>
10403
10512
  : <input name={key} placeholder={stringValue(field, "placeholder")} required={field.required === true} type={["email", "tel", "url", "number"].includes(type) ? type : "text"} />}
10404
10513
  </label>;
10405
10514
  })}
10406
- <button type="submit">{stringValue(data, "submitLabel") || "Enviar contato"}</button>
10515
+ <button type="submit">{stringValue(data, "submitLabel")}</button>
10407
10516
  </>;
10408
10517
  }
10409
10518
 
@@ -10613,7 +10722,7 @@ export default function Theme({ context, route = { type: "home" }, sdk }: Nuvler
10613
10722
  ? context.home.content.sections
10614
10723
  : themeDefinition.template.fallbackSections();
10615
10724
  let content;
10616
- 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} submitContact={sdk?.contact?.submit} template={themeDefinition.template} />;
10725
+ 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} />;
10617
10726
  else if (route.type === "catalog") content = <CatalogPage route={route} site={site} />;
10618
10727
  else if (route.type === "product") content = <ProductPage route={route} site={site} cart={sdk?.cart} />;
10619
10728
  else if (route.type === "editorial-list" || route.type === "editorial-detail") content = <EditorialPage route={route} />;
@@ -10683,32 +10792,7 @@ function blankBindingData(binding) {
10683
10792
  const props = {};
10684
10793
  for (const field of binding.componentDefinition.fields) if (field.defaultValue !== void 0) props[field.key] = field.defaultValue;
10685
10794
  else if (field.control === "repeater") props[field.key] = [];
10686
- else if (field.control === "contact-fields") props[field.key] = [
10687
- {
10688
- key: "name",
10689
- label: "Nome",
10690
- type: "text",
10691
- required: true
10692
- },
10693
- {
10694
- key: "email",
10695
- label: "E-mail",
10696
- type: "email",
10697
- required: true
10698
- },
10699
- {
10700
- key: "phone",
10701
- label: "Telefone",
10702
- type: "tel",
10703
- required: false
10704
- },
10705
- {
10706
- key: "message",
10707
- label: "Mensagem",
10708
- type: "textarea",
10709
- required: true
10710
- }
10711
- ];
10795
+ else if (field.control === "contact-fields") props[field.key] = [];
10712
10796
  else if (field.control === "boolean") props[field.key] = false;
10713
10797
  else if (field.control === "number") props[field.key] = field.min ?? 0;
10714
10798
  else props[field.key] = "";
@@ -11145,7 +11229,9 @@ async function extractContentCatalog(plan) {
11145
11229
  }
11146
11230
  const sections = plan.contentBindings.map((binding) => {
11147
11231
  const parsed = sources.get(binding.file);
11232
+ const componentAnalysis = plan.analysis.components.find((component) => component.file === binding.file && component.name === binding.component);
11148
11233
  const values = [];
11234
+ const extractedRepeaters = /* @__PURE__ */ new Map();
11149
11235
  const formFields = [];
11150
11236
  const seen = /* @__PURE__ */ new Set();
11151
11237
  const counters = /* @__PURE__ */ new Map();
@@ -11291,6 +11377,54 @@ async function extractContentCatalog(plan) {
11291
11377
  const parent = node.parent;
11292
11378
  return ts.isVariableDeclaration(parent) && ts.isIdentifier(parent.name) ? parent.name.text : null;
11293
11379
  }
11380
+ function extractRepeaters(body) {
11381
+ const contentLists = binding.contentLists ?? componentAnalysis?.contentLists ?? [];
11382
+ if (!contentLists.length) return;
11383
+ const declarations = /* @__PURE__ */ new Map();
11384
+ function collectDeclarations(candidate) {
11385
+ if (ts.isVariableDeclaration(candidate) && ts.isIdentifier(candidate.name) && candidate.initializer) {
11386
+ const initializer = unwrappedExpression(candidate.initializer);
11387
+ if (ts.isArrayLiteralExpression(initializer)) declarations.set(candidate.name.text, initializer);
11388
+ }
11389
+ ts.forEachChild(candidate, collectDeclarations);
11390
+ }
11391
+ collectDeclarations(source);
11392
+ const directArrays = [];
11393
+ function collectDirectArrays(candidate) {
11394
+ if (ts.isCallExpression(candidate) && ts.isPropertyAccessExpression(candidate.expression) && candidate.expression.name.text === "map") {
11395
+ const receiver = unwrappedExpression(candidate.expression.expression);
11396
+ if (ts.isArrayLiteralExpression(receiver)) directArrays.push(receiver);
11397
+ }
11398
+ ts.forEachChild(candidate, collectDirectArrays);
11399
+ }
11400
+ collectDirectArrays(body);
11401
+ let directIndex = 0;
11402
+ for (const list of contentLists) {
11403
+ const array = list.sourceName ? declarations.get(list.sourceName) : directArrays[directIndex++];
11404
+ if (!array) continue;
11405
+ const items = [];
11406
+ for (const element of array.elements) {
11407
+ if (!ts.isExpression(element)) continue;
11408
+ const value = unwrappedExpression(element);
11409
+ if (list.primitive) {
11410
+ const item = resolvedString(value) ?? (ts.isNumericLiteral(value) ? value.text : null);
11411
+ if (item !== null) items.push({ title: item });
11412
+ continue;
11413
+ }
11414
+ if (!ts.isObjectLiteralExpression(value)) continue;
11415
+ const item = {};
11416
+ for (const property of value.properties) {
11417
+ if (!ts.isPropertyAssignment(property)) continue;
11418
+ const key = propertyKey(property);
11419
+ if (!key || !list.itemFields.includes(key)) continue;
11420
+ const itemValue = resolvedString(property.initializer) ?? (ts.isNumericLiteral(unwrappedExpression(property.initializer)) ? unwrappedExpression(property.initializer).getText(source) : null);
11421
+ if (itemValue !== null) item[key] = itemValue;
11422
+ }
11423
+ if (Object.keys(item).length) items.push(item);
11424
+ }
11425
+ extractedRepeaters.set(list.fieldKey, items);
11426
+ }
11427
+ }
11294
11428
  function visitContent(node) {
11295
11429
  if (ts.isJsxElement(node) || ts.isJsxSelfClosingElement(node)) collectFormField(node);
11296
11430
  if (binding.componentKey === "feature-list" && ts.isArrayLiteralExpression(node)) for (const element of node.elements) {
@@ -11374,6 +11508,7 @@ async function extractContentCatalog(plan) {
11374
11508
  }
11375
11509
  function findComponent(node) {
11376
11510
  if ((ts.isFunctionDeclaration(node) || ts.isFunctionExpression(node) || ts.isArrowFunction(node)) && componentName(node) === binding.component && node.body) {
11511
+ extractRepeaters(node.body);
11377
11512
  visitContent(node.body);
11378
11513
  return;
11379
11514
  }
@@ -11410,6 +11545,7 @@ async function extractContentCatalog(plan) {
11410
11545
  assign("videoUrl", ranked("videoUrl"));
11411
11546
  assign("posterImageUrl", ranked("posterImageUrl"));
11412
11547
  if (binding.componentKey === "contact-form" && formFields.length && availableFields.has("fields")) data.fields = formFields;
11548
+ for (const [field, items] of extractedRepeaters) if (availableFields.has(field)) data[field] = items;
11413
11549
  const media = ranked("imageUrl");
11414
11550
  if (media && availableFields.has("imageUrl")) selected.add(media.key);
11415
11551
  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");
@@ -12495,13 +12631,12 @@ function customComponentDefinition(kind) {
12495
12631
  key: "submitLabel",
12496
12632
  label: "Texto do botão",
12497
12633
  control: "text",
12498
- defaultValue: "Enviar contato"
12634
+ required: true
12499
12635
  },
12500
12636
  {
12501
12637
  key: "successMessage",
12502
12638
  label: "Mensagem de sucesso",
12503
- control: "text",
12504
- defaultValue: "Contato enviado com sucesso."
12639
+ control: "text"
12505
12640
  }
12506
12641
  ],
12507
12642
  action: {
@@ -12547,6 +12682,79 @@ function customComponentDefinition(kind) {
12547
12682
  };
12548
12683
  return listComponentDefinition(kind);
12549
12684
  }
12685
+ function generatedListComponentDefinition(component) {
12686
+ const hasImage = component.jsx.some(({ tag }) => [
12687
+ "img",
12688
+ "image",
12689
+ "picture"
12690
+ ].includes(tag.toLowerCase()));
12691
+ const hasVideo = component.jsx.some(({ tag }) => [
12692
+ "video",
12693
+ "source",
12694
+ "iframe"
12695
+ ].includes(tag.toLowerCase()));
12696
+ const hasAction = component.jsx.some(({ tag }) => ["a", "button"].includes(tag.toLowerCase()));
12697
+ const label = component.name.replace(/([a-z\d])([A-Z])/g, "$1 $2").replace(/[-_]+/g, " ").trim();
12698
+ const fields = [
12699
+ {
12700
+ key: "eyebrow",
12701
+ label: "Chamada pequena",
12702
+ control: "text"
12703
+ },
12704
+ {
12705
+ key: "title",
12706
+ label: "Título da seção",
12707
+ control: "text"
12708
+ },
12709
+ {
12710
+ key: "description",
12711
+ label: "Descrição",
12712
+ control: "textarea"
12713
+ }
12714
+ ];
12715
+ if (hasImage) fields.push({
12716
+ key: "imageId",
12717
+ label: "Imagem",
12718
+ control: "image"
12719
+ }, {
12720
+ key: "imageAlt",
12721
+ label: "Texto alternativo da imagem",
12722
+ control: "text"
12723
+ });
12724
+ if (hasVideo) fields.push({
12725
+ key: "videoUrl",
12726
+ label: "Vídeo",
12727
+ control: "video"
12728
+ });
12729
+ if (hasAction) fields.push({
12730
+ key: "buttonLabel",
12731
+ label: "Texto do botão",
12732
+ control: "text"
12733
+ }, {
12734
+ key: "buttonUrl",
12735
+ label: "Link do botão",
12736
+ control: "url"
12737
+ });
12738
+ for (const list of component.contentLists) fields.push({
12739
+ key: list.fieldKey,
12740
+ label: list.sourceName ? `Itens de ${list.sourceName}` : "Itens",
12741
+ control: "repeater",
12742
+ maxItems: 100,
12743
+ itemFields: list.itemFields.map((key) => ({
12744
+ key,
12745
+ label: key.replace(/([a-z\d])([A-Z])/g, "$1 $2").replace(/[-_]+/g, " "),
12746
+ control: /(?:url|href|link)$/i.test(key) ? "url" : /(?:description|desc|text|sub|answer|content)$/i.test(key) ? "textarea" : "text"
12747
+ }))
12748
+ });
12749
+ return {
12750
+ key: `migrated-${safeThemeId(component.name)}`,
12751
+ name: label || component.name,
12752
+ description: "Componente visual migrado; todo o conteúdo é configurado pelo painel.",
12753
+ category: "Listas",
12754
+ schemaVersion: 1,
12755
+ fields
12756
+ };
12757
+ }
12550
12758
  function contentType(component) {
12551
12759
  const name = normalized(component.name);
12552
12760
  const hasRole = (role) => component.roles.some((candidate) => candidate.role === role);
@@ -12561,6 +12769,7 @@ function contentType(component) {
12561
12769
  if (/(blog|post|article|artigo)/.test(name)) return "blog-grid";
12562
12770
  if (/(case|project|projeto|portfolio|testimonial|depoimento)/.test(name)) return "cases-grid";
12563
12771
  if (name.includes("banner") && /(carousel|slider|slide)/.test(name)) return "banner-carousel";
12772
+ if (component.contentLists.length) return "theme-component";
12564
12773
  if (/(hero|banner|masthead)/.test(name)) return "hero";
12565
12774
  if (customComponentKind(component)) return "theme-component";
12566
12775
  if (/(cta|calltoaction|contact|contato|newsletter|final)/.test(name)) return "cta";
@@ -12620,7 +12829,11 @@ function contentBindings(analysis, selected) {
12620
12829
  const type = contentType(component);
12621
12830
  const slug = safeThemeId(component.name);
12622
12831
  const customKind = type === "theme-component" ? customComponentKind(component) : null;
12623
- const componentDefinition = customKind ? customComponentDefinition(customKind) : void 0;
12832
+ const contentLists = customKind ? component.contentLists.map((list, index) => ({
12833
+ ...list,
12834
+ fieldKey: index === 0 ? "items" : `items${index + 1}`
12835
+ })) : component.contentLists;
12836
+ const componentDefinition = type !== "theme-component" ? void 0 : customKind ? customComponentDefinition(customKind) : component.contentLists.length ? generatedListComponentDefinition(component) : void 0;
12624
12837
  return {
12625
12838
  id: `migrated-${slug}-${order + 1}`,
12626
12839
  component: component.name,
@@ -12630,7 +12843,8 @@ function contentBindings(analysis, selected) {
12630
12843
  fields: componentDefinition?.fields.map(({ key }) => key) ?? CONTENT_FIELDS[type],
12631
12844
  classes: classProfile(component),
12632
12845
  componentKey: componentDefinition?.key,
12633
- componentDefinition
12846
+ componentDefinition,
12847
+ contentLists
12634
12848
  };
12635
12849
  });
12636
12850
  }
@@ -13127,7 +13341,7 @@ async function authLogout() {
13127
13341
  //#endregion
13128
13342
  //#region src/index.ts
13129
13343
  var program = new Command();
13130
- program.name("nuvler").description("Nuvler Theme Development CLI").version("0.5.0");
13344
+ program.name("nuvler").description("Nuvler Theme Development CLI").version("0.5.2");
13131
13345
  var theme = program.command("theme").description("Manage Nuvler themes");
13132
13346
  var auth = program.command("auth").description("Manage developer authentication");
13133
13347
  auth.command("login").requiredOption("--token <token>", "Developer token").option("--api-url <url>", "Nuvler API base URL (or use NUVLER_API_URL)").action(async (options) => {