@@ -9,7 +9,7 @@ import { computed, ref, useAttrs } from "vue";
9
9
10
10
import { linkify } from " @/utils/utils" ;
11
11
12
- import type { FormParameterAttributes , FormParameterTypes , FormParameterValue } from " ./parameterTypes" ;
12
+ import type { FormParameterAttributes , FormParameterTypeMap , FormParameterTypes } from " ./parameterTypes" ;
13
13
14
14
import FormBoolean from " ./Elements/FormBoolean.vue" ;
15
15
import FormColor from " ./Elements/FormColor.vue" ;
@@ -36,10 +36,10 @@ const TYPE_TO_PLACEHOLDER: Record<string, string> = {
36
36
float: " a floating point number" ,
37
37
};
38
38
39
- interface FormElementProps {
39
+ interface FormElementProps < T extends FormParameterTypes > {
40
40
id? : string ;
41
- type? : FormParameterTypes ;
42
- value? : FormParameterValue ;
41
+ type? : T ;
42
+ value? : FormParameterTypeMap [ T ] ;
43
43
title? : string ;
44
44
refreshOnChange? : boolean ;
45
45
help? : string ;
@@ -48,7 +48,7 @@ interface FormElementProps {
48
48
warning? : string ;
49
49
disabled? : boolean ;
50
50
loading? : boolean ;
51
- attributes? : FormParameterAttributes ;
51
+ attributes? : FormParameterAttributes < T > ;
52
52
collapsedEnableText? : string ;
53
53
collapsedDisableText? : string ;
54
54
collapsedEnableIcon? : string ;
@@ -62,7 +62,9 @@ interface FormElementProps {
62
62
workflowRun? : boolean ;
63
63
}
64
64
65
- const props = withDefaults (defineProps <FormElementProps >(), {
65
+ const props = withDefaults (defineProps <FormElementProps <FormParameterTypes >>(), {
66
+ attributes: undefined ,
67
+ error: undefined ,
66
68
id: " identifier" ,
67
69
refreshOnChange: false ,
68
70
disabled: false ,
@@ -74,13 +76,18 @@ const props = withDefaults(defineProps<FormElementProps>(), {
74
76
connectedDisableText: " Add connection to module." ,
75
77
connectedEnableIcon: " fa fa-times" ,
76
78
connectedDisableIcon: " fa fa-arrows-alt-h" ,
79
+ help: undefined ,
77
80
helpFormat: " html" ,
81
+ title: undefined ,
82
+ type: undefined ,
83
+ value: undefined ,
84
+ warning: undefined ,
78
85
workflowBuildingMode: false ,
79
86
workflowRun: false ,
80
87
});
81
88
82
89
const emit = defineEmits <{
83
- (e : " input" , value : FormParameterValue , id : string ): void ;
90
+ (e : " input" , value : FormParameterTypeMap [ FormParameterTypes ] , id : string ): void ;
84
91
(e : " change" , shouldRefresh : boolean ): void ;
85
92
}>();
86
93
@@ -91,10 +98,14 @@ library.add(faExclamation, faTimes, faArrowsAltH, faCaretSquareDown, faCaretSqua
91
98
It is present for compatibility with the legacy "FormParameter" component,
92
99
but should be removed as soon as that component is removed.
93
100
*/
94
- const attrs: ComputedRef <FormParameterAttributes > = computed (() => props .attributes || useAttrs ());
95
- const collapsibleValue: ComputedRef <FormParameterValue > = computed (() => attrs .value [" collapsible_value" ]);
96
- const defaultValue: ComputedRef <FormParameterValue > = computed (() => attrs .value [" default_value" ]);
97
- const connectedValue: FormParameterValue = { __class__: " ConnectedValue" };
101
+ const attrs: ComputedRef <FormParameterAttributes <FormParameterTypes >> = computed (() => props .attributes || useAttrs ());
102
+ const collapsibleValue: ComputedRef <FormParameterTypeMap [FormParameterTypes ]> = computed (
103
+ () => attrs .value [" collapsible_value" ]
104
+ );
105
+ const defaultValue: ComputedRef <FormParameterTypeMap [FormParameterTypes ]> = computed (
106
+ () => attrs .value [" default_value" ]
107
+ );
108
+ const connectedValue: FormParameterTypeMap [FormParameterTypes ] = { __class__: " ConnectedValue" };
98
109
99
110
const computedPlaceholder = computed (() => {
100
111
if (! props .workflowRun ) {
@@ -132,7 +143,7 @@ const connectable = computed(() => collapsible.value && Boolean(attrs.value["con
132
143
}
133
144
134
145
/** Submits a changed value. */
135
- function setValue(value : FormParameterValue ) {
146
+ function setValue(value : FormParameterTypeMap [ FormParameterTypes ] ) {
136
147
emit (" input" , value , props .id );
137
148
emit (" change" , props .refreshOnChange );
138
149
}
@@ -171,7 +182,7 @@ const formDataField = computed(() =>
171
182
);
172
183
const isUriDataField = computed (() => {
173
184
const dataField = props .type == " data" ;
174
- if (dataField && props .value && " src" in props .value ) {
185
+ if (dataField && props .value && typeof props . value === " object " && " src" in props .value ) {
175
186
const src = props .value .src ;
176
187
return src == " url" ;
177
188
}
@@ -193,7 +204,7 @@ const nonMdHelp = computed(() =>
193
204
: " "
194
205
);
195
206
196
- const currentValue = computed ({
207
+ const currentValue = computed < FormParameterTypeMap [ FormParameterTypes ]> ({
197
208
get() {
198
209
return props .value ;
199
210
},
0 commit comments