@betterstart/cli 0.1.44 → 0.1.46

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/cli.js CHANGED
@@ -2261,13 +2261,6 @@ function resolveUiImport(cwd, componentName) {
2261
2261
  function escapeJsx(str) {
2262
2262
  return str.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
2263
2263
  }
2264
- function flattenFormFields(fields) {
2265
- return fields.flatMap((field) => {
2266
- if (field.type === "dynamicFields") return [];
2267
- if (field.type === "group" && field.fields) return flattenFormFields(field.fields);
2268
- return field.type === "group" ? [] : [field];
2269
- });
2270
- }
2271
2264
  function buildZodFields(fields) {
2272
2265
  return fields.filter((f) => f.name).map((f) => ` ${f.name}: ${formFieldToZodType(f)}`).join(",\n");
2273
2266
  }
@@ -2305,6 +2298,21 @@ function getListFields(fields) {
2305
2298
  (f) => f.name && f.type === "list" && f.fields && f.fields.length > 0
2306
2299
  );
2307
2300
  }
2301
+ function renderFieldsJSX(fields) {
2302
+ return fields.filter((f) => !f.hidden).map((f) => {
2303
+ if (f.type === "dynamicFields") return "";
2304
+ if (f.type === "group" && f.fields) {
2305
+ const cols = f.columns || 2;
2306
+ const innerJSX = renderFieldsJSX(f.fields);
2307
+ const groupJSX = ` <div className="grid grid-cols-1 md:grid-cols-${cols} gap-4">
2308
+ ${innerJSX}
2309
+ </div>`;
2310
+ return f.showWhen ? wrapShowWhen(f, groupJSX) : groupJSX;
2311
+ }
2312
+ if (!f.name) return "";
2313
+ return wrapShowWhen(f, generateFieldJSX(f));
2314
+ }).filter(Boolean).join("\n\n");
2315
+ }
2308
2316
  function wrapShowWhen(field, jsx) {
2309
2317
  if (!field.showWhen) return jsx;
2310
2318
  const watchVar = `${field.showWhen.field}Value`;
@@ -2347,10 +2355,10 @@ function generateFieldJSX(field) {
2347
2355
  case "radio":
2348
2356
  if (field.options && field.options.length > 0) {
2349
2357
  const radioItems = field.options.map(
2350
- (opt) => ` <label htmlFor="${name}-${opt.value}" className="flex items-center space-x-2 text-sm font-medium leading-none">
2358
+ (opt) => ` <FormLabel htmlFor="${name}-${opt.value}" className="flex items-center space-x-2 text-sm font-medium leading-none">
2351
2359
  <RadioGroupItem value="${opt.value}" id="${name}-${opt.value}" />
2352
2360
  <span>${escapeJsx(opt.label)}</span>
2353
- </label>`
2361
+ </FormLabel>`
2354
2362
  ).join("\n");
2355
2363
  return ` <FormField
2356
2364
  control={form.control}
@@ -2505,7 +2513,7 @@ ${selectItems}
2505
2513
  return `${nf.name}: ''`;
2506
2514
  }).join(", ");
2507
2515
  return ` <div className="space-y-4">
2508
- <label className="text-sm font-medium leading-none">${label}${requiredStar}</label>${hintJSX}
2516
+ <FormLabel className="text-sm font-medium leading-none">${label}${requiredStar}</FormLabel>${hintJSX}
2509
2517
  {${name}FieldArray.fields.map((item, index) => (
2510
2518
  <div key={item.id} className="flex items-end gap-2 rounded-lg border p-4">
2511
2519
  <div className="flex-1 space-y-4">
@@ -2551,8 +2559,7 @@ ${buildFieldArrayDecls(listFields)}
2551
2559
  ` : "";
2552
2560
  const stepsConst = buildStepsConstant(steps, schema);
2553
2561
  const stepContentBlocks = steps.map((step, index) => {
2554
- const stepFields = flattenFormFields(step.fields);
2555
- const fieldsJSX = stepFields.filter((f) => f.name && !f.hidden).map((f) => wrapShowWhen(f, generateFieldJSX(f))).join("\n\n");
2562
+ const fieldsJSX = renderFieldsJSX(step.fields);
2556
2563
  return ` {currentStep === ${index} && (
2557
2564
  <>
2558
2565
  ${fieldsJSX}
@@ -2815,7 +2822,8 @@ function generateSingleStepForm(schema, cwd, cmsDir, options) {
2815
2822
  const listFields = getListFields(fields);
2816
2823
  const hasListFields = listFields.length > 0;
2817
2824
  const { setup: watchSetup } = buildWatchDecls(fields);
2818
- const fieldJSX = fields.filter((f) => f.name && !f.hidden).map((f) => wrapShowWhen(f, generateFieldJSX(f))).join("\n\n");
2825
+ const rawFields = schema.fields || [];
2826
+ const fieldJSX = renderFieldsJSX(rawFields);
2819
2827
  const submitText = schema.submitButtonText || "Submit";
2820
2828
  const successMessage = escapeJsx(schema.successMessage || "Form submitted successfully!");
2821
2829
  const rhfImport = hasListFields ? `import { useFieldArray, useForm } from 'react-hook-form'` : `import { useForm } from 'react-hook-form'`;