@betterstart/cli 0.1.44 → 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 +18 -10
- 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`;
|
|
@@ -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}
|
|
@@ -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
|
|
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'`;
|