@@ -32,24 +32,52 @@ def get_input_model_from_fields(name: str, input_fields: list) -> Type['BaseMode
3232 'list' : list ,
3333 'file' : str ,
3434 'image' : str ,
35- 'text' : str
35+ 'text' : str ,
36+ 'richtext' : str ,
37+ 'datasource' : str ,
38+ 'color' : str ,
39+ 'voice' : str ,
3640 }
3741
3842 fields = {}
3943 for field in input_fields :
40- datatype = datatype_map [ field ['type' ]
41- ] if 'type' in field and field [ 'type' ] in datatype_map else str
44+ field_type = field ['type' ] if 'type' in field else 'string'
45+ datatype = datatype_map [ field_type ] if field_type in datatype_map else str
4246
43- if 'type' in field and field [ 'type' ] == 'file' :
47+ if field_type == 'file' :
4448 field ['widget' ] = 'file'
4549 field ['format' ] = 'data-url'
4650 field ['pattern' ] = "data:(.*);name=(.*);base64,(.*)"
47- elif 'type' in field and field [ 'type' ] == 'image' :
51+ elif field_type == 'image' :
4852 field ['widget' ] = 'file'
4953 field ['format' ] = 'data-url'
5054 field ['pattern' ] = "data:(.*);name=(.*);base64,(.*)"
51- elif 'type' in field and field [ 'type' ] == 'text' :
55+ elif field_type == 'text' :
5256 field ['widget' ] = 'textarea'
57+ elif field_type == 'richtext' :
58+ field ['widget' ] = 'richtext'
59+ elif field_type == 'datasource' :
60+ field ['widget' ] = 'datasource'
61+ if 'default' not in field :
62+ field ['default' ] = []
63+ elif field_type == 'color' :
64+ field ['widget' ] = 'color'
65+ elif field_type == 'voice' :
66+ field ['widget' ] = 'voice'
67+ field ['format' ] = 'data-url'
68+ field ['pattern' ] = "data:(.*);name=(.*);base64,(.*)"
69+
70+ if field_type == 'select' and 'options' in field and len (field ['options' ]) > 0 :
71+ field ['enumNames' ] = [option ['label' ]
72+ or '' for option in field ['options' ]]
73+ field ['enum' ] = [option ['value' ]
74+ or None for option in field ['options' ]]
75+ field ['widget' ] = 'select'
76+
77+ # For select fields, the datatype is the type of the first option
78+ datatype = type (field ['options' ][0 ]['value' ])
79+
80+ field .pop ('options' , None )
5381
5482 fields [field ['name' ]] = (datatype , Field (
5583 ** {k : field [k ] for k in field }))
0 commit comments