Skip to content

Commit b5186a0

Browse files
committed
fixes
1 parent 7138f1c commit b5186a0

File tree

4 files changed

+54
-23
lines changed

4 files changed

+54
-23
lines changed

app/providers.tsx

+5-2
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,12 @@ import { DragDropContext } from "@hello-pangea/dnd"
55

66
interface ProvidersProps {
77
children: React.ReactNode
8+
attribute?: string
9+
defaultTheme?: string
10+
enableSystem?: boolean
811
}
912

10-
export function Providers({ children }: ProvidersProps) {
13+
export function Providers({ children, attribute, defaultTheme, enableSystem }: ProvidersProps) {
1114
const onDragEnd = (result: any) => {
1215
// Handle drag end logic here
1316
if (!result.destination) return
@@ -17,7 +20,7 @@ export function Providers({ children }: ProvidersProps) {
1720
}
1821

1922
return (
20-
<ThemeProvider attribute="class" defaultTheme="system" enableSystem>
23+
<ThemeProvider attribute={attribute} defaultTheme={defaultTheme} enableSystem={enableSystem}>
2124
<DragDropContext onDragEnd={onDragEnd}>
2225
{children}
2326
</DragDropContext>

components/FormElementEditor.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { Input } from '@/components/ui/input'
55
import { Label } from '@/components/ui/label'
66
import { Button } from '@/components/ui/button'
77
import { Plus, Trash2 } from 'lucide-react'
8-
import { FormElement } from '@/types'
8+
import { FormElement, FormElementOption } from '@/types'
99
import { Checkbox } from '@radix-ui/react-checkbox'
1010
import { Select, SelectTrigger, SelectValue, SelectContent, SelectItem } from '@radix-ui/react-select'
1111
import { Textarea } from './ui/textarea'

components/Playground.tsx

+47-19
Original file line numberDiff line numberDiff line change
@@ -115,25 +115,52 @@ export function Playground() {
115115

116116
const handleImportSchema = (jsonSchema: JsonSchema, uiSchema: Record<string, any>) => {
117117
// Convert imported schema back to form elements
118-
const newFormElements: FormElement[] = Object.entries(jsonSchema.properties).map(([name, prop]) => ({
119-
type: prop.type === 'number' ? 'number' : 'string',
120-
label: prop.title || name,
121-
name,
122-
placeholder: prop.description,
123-
options: prop.enum?.map(value => ({ label: value, value })),
124-
validation: {
125-
required: jsonSchema.required?.includes(name),
126-
minLength: prop.minLength,
127-
maxLength: prop.maxLength,
128-
min: prop.minimum,
129-
max: prop.maximum,
130-
pattern: prop.pattern,
131-
},
132-
}))
133-
134-
setFormElements(newFormElements)
135-
setState(newFormElements)
136-
}
118+
const newFormElements: FormElement[] = Object.entries(jsonSchema.properties).map(([name, prop]: [string, any]) => {
119+
// Map the type correctly
120+
let formElementType: FormElement["type"];
121+
switch (prop.type) {
122+
case "string":
123+
formElementType = uiSchema[name]?.["ui:widget"] === "textarea" ? "textarea" : "text";
124+
break;
125+
case "number":
126+
formElementType = "number";
127+
break;
128+
case "boolean":
129+
formElementType = "checkbox";
130+
break;
131+
case "array":
132+
formElementType = "select";
133+
break;
134+
case "object":
135+
formElementType = "file"; // Default to file for complex types (adjust as needed)
136+
break;
137+
default:
138+
throw new Error(`Unsupported type: ${prop.type}`);
139+
}
140+
141+
return {
142+
type: formElementType,
143+
label: prop.title || name,
144+
name,
145+
placeholder: uiSchema[name]?.["ui:placeholder"] || undefined,
146+
options: prop.enum
147+
? prop.enum.map((value: string) => ({ label: value, value }))
148+
: undefined,
149+
validation: {
150+
required: jsonSchema.required?.includes(name) || false,
151+
minLength: prop.minLength || undefined,
152+
maxLength: prop.maxLength || undefined,
153+
min: prop.minimum || undefined,
154+
max: prop.maximum || undefined,
155+
pattern: prop.pattern || undefined,
156+
},
157+
};
158+
});
159+
160+
// Update state with new form elements
161+
setFormElements(newFormElements);
162+
setState(newFormElements);
163+
};
137164

138165
const handleFileUpload = (event: React.ChangeEvent<HTMLInputElement>, elementName: string) => {
139166
const file = event.target.files?.[0];
@@ -175,6 +202,7 @@ export function Playground() {
175202
className="flex-1 p-4 bg-gray-50 overflow-y-auto"
176203
>
177204
<Canvas
205+
onDragEnd={handleDragEnd}
178206
elements={formElements}
179207
onElementUpdate={handleElementUpdate}
180208
onElementDelete={handleElementDelete}

components/Preview.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ export function Preview({ elements, onFileUpload }: PreviewProps) {
5858
<div className="space-y-2">
5959
{element.options?.map((option, optionIndex) => (
6060
<div key={optionIndex} className="flex items-center space-x-2">
61-
<Checkbox id={`${element.name}-${optionIndex}`} {...commonProps} value={option.value} />
61+
<Checkbox {...commonProps} value={option.value} />
6262
<Label htmlFor={`${element.name}-${optionIndex}`}>{option.label}</Label>
6363
</div>
6464
))}

0 commit comments

Comments
 (0)