@betterstart/cli 0.1.45 → 0.1.47
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 +38 -6
- package/dist/cli.js.map +1 -1
- package/package.json +1 -1
- package/templates/ui/media-upload-field.tsx +18 -4
package/dist/cli.js
CHANGED
|
@@ -2355,10 +2355,10 @@ function generateFieldJSX(field) {
|
|
|
2355
2355
|
case "radio":
|
|
2356
2356
|
if (field.options && field.options.length > 0) {
|
|
2357
2357
|
const radioItems = field.options.map(
|
|
2358
|
-
(opt) => ` <
|
|
2358
|
+
(opt) => ` <FormLabel htmlFor="${name}-${opt.value}" className="flex items-center space-x-2 text-sm font-medium leading-none">
|
|
2359
2359
|
<RadioGroupItem value="${opt.value}" id="${name}-${opt.value}" />
|
|
2360
2360
|
<span>${escapeJsx(opt.label)}</span>
|
|
2361
|
-
</
|
|
2361
|
+
</FormLabel>`
|
|
2362
2362
|
).join("\n");
|
|
2363
2363
|
return ` <FormField
|
|
2364
2364
|
control={form.control}
|
|
@@ -2437,7 +2437,7 @@ ${optionItems}
|
|
|
2437
2437
|
return generateTextFieldJSX(name, label, placeholder || "+1 (555) 000-0000", hintJSX, requiredStar, "tel");
|
|
2438
2438
|
case "file":
|
|
2439
2439
|
case "upload":
|
|
2440
|
-
return
|
|
2440
|
+
return generateFileUploadFieldJSX(field, name, label, hintJSX, requiredStar);
|
|
2441
2441
|
case "list":
|
|
2442
2442
|
return generateListFieldJSX(field, name, label, hintPlainJSX, requiredStar);
|
|
2443
2443
|
default:
|
|
@@ -2459,6 +2459,30 @@ function generateTextFieldJSX(name, label, placeholder, hintJSX, requiredStar, i
|
|
|
2459
2459
|
)}
|
|
2460
2460
|
/>`;
|
|
2461
2461
|
}
|
|
2462
|
+
function generateFileUploadFieldJSX(field, name, label, hintJSX, requiredStar) {
|
|
2463
|
+
const accept = field.accept || "*/*";
|
|
2464
|
+
const maxSize = field.maxFileSize || 10;
|
|
2465
|
+
return ` <FormField
|
|
2466
|
+
control={form.control}
|
|
2467
|
+
name="${name}"
|
|
2468
|
+
render={({ field }) => (
|
|
2469
|
+
<FormItem>
|
|
2470
|
+
<FormLabel>${label}${requiredStar}</FormLabel>
|
|
2471
|
+
<FormControl>
|
|
2472
|
+
<MediaUploadField
|
|
2473
|
+
value={field.value}
|
|
2474
|
+
onChange={field.onChange}
|
|
2475
|
+
onBlur={field.onBlur}
|
|
2476
|
+
accept="${accept}"
|
|
2477
|
+
maxSizeInMB={${maxSize}}
|
|
2478
|
+
label=""
|
|
2479
|
+
/>
|
|
2480
|
+
</FormControl>${hintJSX}
|
|
2481
|
+
<FormMessage />
|
|
2482
|
+
</FormItem>
|
|
2483
|
+
)}
|
|
2484
|
+
/>`;
|
|
2485
|
+
}
|
|
2462
2486
|
function generateListFieldJSX(field, name, label, hintJSX, requiredStar) {
|
|
2463
2487
|
if (!field.fields || field.fields.length === 0) {
|
|
2464
2488
|
return generateTextFieldJSX(name, label, field.placeholder || "", hintJSX, requiredStar, "text");
|
|
@@ -2513,7 +2537,7 @@ ${selectItems}
|
|
|
2513
2537
|
return `${nf.name}: ''`;
|
|
2514
2538
|
}).join(", ");
|
|
2515
2539
|
return ` <div className="space-y-4">
|
|
2516
|
-
<
|
|
2540
|
+
<FormLabel className="text-sm font-medium leading-none">${label}${requiredStar}</FormLabel>${hintJSX}
|
|
2517
2541
|
{${name}FieldArray.fields.map((item, index) => (
|
|
2518
2542
|
<div key={item.id} className="flex items-end gap-2 rounded-lg border p-4">
|
|
2519
2543
|
<div className="flex-1 space-y-4">
|
|
@@ -2569,6 +2593,7 @@ ${fieldsJSX}
|
|
|
2569
2593
|
const submitText = schema.submitButtonText || "Submit";
|
|
2570
2594
|
const successMessage = escapeJsx(schema.successMessage || "Form submitted successfully!");
|
|
2571
2595
|
const hasRadio = allFields.some((f) => f.type === "radio");
|
|
2596
|
+
const hasFileUpload = allFields.some((f) => f.type === "file" || f.type === "upload");
|
|
2572
2597
|
const buttonImport = resolveUiImport(cwd, "button");
|
|
2573
2598
|
const formImport = resolveUiImport(cwd, "form");
|
|
2574
2599
|
const inputImport = resolveUiImport(cwd, "input");
|
|
@@ -2576,11 +2601,13 @@ ${fieldsJSX}
|
|
|
2576
2601
|
const selectImport = resolveUiImport(cwd, "select");
|
|
2577
2602
|
const radioGroupImport = resolveUiImport(cwd, "radio-group");
|
|
2578
2603
|
const progressImport = resolveUiImport(cwd, "progress");
|
|
2604
|
+
const mediaUploadImport = resolveUiImport(cwd, "media-upload-field");
|
|
2579
2605
|
const content = buildComponentSource({
|
|
2580
2606
|
pascal,
|
|
2581
2607
|
kebab,
|
|
2582
2608
|
rhfImport,
|
|
2583
2609
|
hasRadio,
|
|
2610
|
+
hasFileUpload,
|
|
2584
2611
|
buttonImport,
|
|
2585
2612
|
formImport,
|
|
2586
2613
|
inputImport,
|
|
@@ -2588,6 +2615,7 @@ ${fieldsJSX}
|
|
|
2588
2615
|
selectImport,
|
|
2589
2616
|
radioGroupImport,
|
|
2590
2617
|
progressImport,
|
|
2618
|
+
mediaUploadImport,
|
|
2591
2619
|
zodFields,
|
|
2592
2620
|
defaults,
|
|
2593
2621
|
stepsConst,
|
|
@@ -2633,7 +2661,8 @@ import {
|
|
|
2633
2661
|
FormLabel,
|
|
2634
2662
|
FormMessage,
|
|
2635
2663
|
} from '${p7.formImport}'
|
|
2636
|
-
import { Input } from '${p7.inputImport}'
|
|
2664
|
+
import { Input } from '${p7.inputImport}'${p7.hasFileUpload ? `
|
|
2665
|
+
import { MediaUploadField } from '${p7.mediaUploadImport}'` : ""}
|
|
2637
2666
|
import { Progress } from '${p7.progressImport}'${p7.hasRadio ? `
|
|
2638
2667
|
import { RadioGroup, RadioGroupItem } from '${p7.radioGroupImport}'` : ""}
|
|
2639
2668
|
import { Textarea } from '${p7.textareaImport}'
|
|
@@ -2831,12 +2860,14 @@ function generateSingleStepForm(schema, cwd, cmsDir, options) {
|
|
|
2831
2860
|
${buildFieldArrayDecls(listFields)}
|
|
2832
2861
|
` : "";
|
|
2833
2862
|
const hasRadio = fields.some((f) => f.type === "radio");
|
|
2863
|
+
const hasFileUpload = fields.some((f) => f.type === "file" || f.type === "upload");
|
|
2834
2864
|
const buttonImport = resolveUiImport(cwd, "button");
|
|
2835
2865
|
const formImport = resolveUiImport(cwd, "form");
|
|
2836
2866
|
const inputImport = resolveUiImport(cwd, "input");
|
|
2837
2867
|
const textareaImport = resolveUiImport(cwd, "textarea");
|
|
2838
2868
|
const selectImport = resolveUiImport(cwd, "select");
|
|
2839
2869
|
const radioGroupImport = resolveUiImport(cwd, "radio-group");
|
|
2870
|
+
const mediaUploadImport = resolveUiImport(cwd, "media-upload-field");
|
|
2840
2871
|
const content = `'use client'
|
|
2841
2872
|
|
|
2842
2873
|
import { zodResolver } from '@hookform/resolvers/zod'
|
|
@@ -2854,7 +2885,8 @@ import {
|
|
|
2854
2885
|
FormLabel,
|
|
2855
2886
|
FormMessage,
|
|
2856
2887
|
} from '${formImport}'
|
|
2857
|
-
import { Input } from '${inputImport}'${
|
|
2888
|
+
import { Input } from '${inputImport}'${hasFileUpload ? `
|
|
2889
|
+
import { MediaUploadField } from '${mediaUploadImport}'` : ""}${hasRadio ? `
|
|
2858
2890
|
import { RadioGroup, RadioGroupItem } from '${radioGroupImport}'` : ""}
|
|
2859
2891
|
import { Textarea } from '${textareaImport}'
|
|
2860
2892
|
import {
|