@betterstart/cli 0.1.43 → 0.1.45
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 +23 -20
- package/dist/cli.js.map +1 -1
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -2261,13 +2261,6 @@ function resolveUiImport(cwd, componentName) {
|
|
|
2261
2261
|
function escapeJsx(str) {
|
|
2262
2262
|
return str.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
|
|
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) => ` <
|
|
2358
|
+
(opt) => ` <label 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
|
-
<
|
|
2353
|
-
</
|
|
2360
|
+
<span>${escapeJsx(opt.label)}</span>
|
|
2361
|
+
</label>`
|
|
2354
2362
|
).join("\n");
|
|
2355
2363
|
return ` <FormField
|
|
2356
2364
|
control={form.control}
|
|
@@ -2359,7 +2367,7 @@ function generateFieldJSX(field) {
|
|
|
2359
2367
|
<FormItem className="space-y-3">
|
|
2360
2368
|
<FormLabel>${label}${requiredStar}</FormLabel>
|
|
2361
2369
|
<FormControl>
|
|
2362
|
-
<RadioGroup onValueChange={field.onChange} defaultValue={field.value} className="flex
|
|
2370
|
+
<RadioGroup onValueChange={field.onChange} defaultValue={field.value} className="flex items-center space-x-2">
|
|
2363
2371
|
${radioItems}
|
|
2364
2372
|
</RadioGroup>
|
|
2365
2373
|
</FormControl>${hintJSX}
|
|
@@ -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
|
|
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}
|
|
@@ -2565,7 +2572,6 @@ ${fieldsJSX}
|
|
|
2565
2572
|
const buttonImport = resolveUiImport(cwd, "button");
|
|
2566
2573
|
const formImport = resolveUiImport(cwd, "form");
|
|
2567
2574
|
const inputImport = resolveUiImport(cwd, "input");
|
|
2568
|
-
const labelImport = resolveUiImport(cwd, "label");
|
|
2569
2575
|
const textareaImport = resolveUiImport(cwd, "textarea");
|
|
2570
2576
|
const selectImport = resolveUiImport(cwd, "select");
|
|
2571
2577
|
const radioGroupImport = resolveUiImport(cwd, "radio-group");
|
|
@@ -2578,7 +2584,6 @@ ${fieldsJSX}
|
|
|
2578
2584
|
buttonImport,
|
|
2579
2585
|
formImport,
|
|
2580
2586
|
inputImport,
|
|
2581
|
-
labelImport,
|
|
2582
2587
|
textareaImport,
|
|
2583
2588
|
selectImport,
|
|
2584
2589
|
radioGroupImport,
|
|
@@ -2629,7 +2634,6 @@ import {
|
|
|
2629
2634
|
FormMessage,
|
|
2630
2635
|
} from '${p7.formImport}'
|
|
2631
2636
|
import { Input } from '${p7.inputImport}'
|
|
2632
|
-
import { Label } from '${p7.labelImport}'
|
|
2633
2637
|
import { Progress } from '${p7.progressImport}'${p7.hasRadio ? `
|
|
2634
2638
|
import { RadioGroup, RadioGroupItem } from '${p7.radioGroupImport}'` : ""}
|
|
2635
2639
|
import { Textarea } from '${p7.textareaImport}'
|
|
@@ -2818,7 +2822,8 @@ function generateSingleStepForm(schema, cwd, cmsDir, options) {
|
|
|
2818
2822
|
const listFields = getListFields(fields);
|
|
2819
2823
|
const hasListFields = listFields.length > 0;
|
|
2820
2824
|
const { setup: watchSetup } = buildWatchDecls(fields);
|
|
2821
|
-
const
|
|
2825
|
+
const rawFields = schema.fields || [];
|
|
2826
|
+
const fieldJSX = renderFieldsJSX(rawFields);
|
|
2822
2827
|
const submitText = schema.submitButtonText || "Submit";
|
|
2823
2828
|
const successMessage = escapeJsx(schema.successMessage || "Form submitted successfully!");
|
|
2824
2829
|
const rhfImport = hasListFields ? `import { useFieldArray, useForm } from 'react-hook-form'` : `import { useForm } from 'react-hook-form'`;
|
|
@@ -2829,7 +2834,6 @@ ${buildFieldArrayDecls(listFields)}
|
|
|
2829
2834
|
const buttonImport = resolveUiImport(cwd, "button");
|
|
2830
2835
|
const formImport = resolveUiImport(cwd, "form");
|
|
2831
2836
|
const inputImport = resolveUiImport(cwd, "input");
|
|
2832
|
-
const labelImport = resolveUiImport(cwd, "label");
|
|
2833
2837
|
const textareaImport = resolveUiImport(cwd, "textarea");
|
|
2834
2838
|
const selectImport = resolveUiImport(cwd, "select");
|
|
2835
2839
|
const radioGroupImport = resolveUiImport(cwd, "radio-group");
|
|
@@ -2850,8 +2854,7 @@ import {
|
|
|
2850
2854
|
FormLabel,
|
|
2851
2855
|
FormMessage,
|
|
2852
2856
|
} from '${formImport}'
|
|
2853
|
-
import { Input } from '${inputImport}'
|
|
2854
|
-
import { Label } from '${labelImport}'${hasRadio ? `
|
|
2857
|
+
import { Input } from '${inputImport}'${hasRadio ? `
|
|
2855
2858
|
import { RadioGroup, RadioGroupItem } from '${radioGroupImport}'` : ""}
|
|
2856
2859
|
import { Textarea } from '${textareaImport}'
|
|
2857
2860
|
import {
|