@volverjs/form-vue 1.0.0-beta.9 → 1.0.0
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/LICENSE +1 -1
- package/README.md +412 -245
- package/dist/VvForm.d.ts +135 -0
- package/dist/VvFormField.d.ts +130 -0
- package/dist/VvFormFieldsGroup.d.ts +109 -0
- package/dist/VvFormTemplate.d.ts +40 -0
- package/dist/VvFormWrapper.d.ts +65 -0
- package/dist/{src/enums.d.ts → enums.d.ts} +1 -0
- package/dist/index.d.ts +972 -1
- package/dist/index.es.js +944 -593
- package/dist/index.umd.js +1 -1
- package/dist/types.d.ts +93 -0
- package/dist/utils.d.ts +3 -0
- package/package.json +61 -60
- package/src/VvForm.ts +359 -300
- package/src/VvFormField.ts +366 -334
- package/src/VvFormFieldsGroup.ts +381 -0
- package/src/VvFormTemplate.ts +185 -171
- package/src/VvFormWrapper.ts +198 -161
- package/src/enums.ts +27 -26
- package/src/index.ts +157 -134
- package/src/types.ts +162 -125
- package/src/utils.ts +121 -100
- package/dist/src/VvForm.d.ts +0 -202
- package/dist/src/VvFormField.d.ts +0 -116
- package/dist/src/VvFormTemplate.d.ts +0 -60
- package/dist/src/VvFormWrapper.d.ts +0 -107
- package/dist/src/index.d.ts +0 -1498
- package/dist/src/types.d.ts +0 -70
- package/dist/src/utils.d.ts +0 -3
- package/dist/test-playwright/VvForm.spec.d.ts +0 -1
- package/dist/test-playwright/VvFormField.spec.d.ts +0 -1
- package/dist/test-playwright/VvFormWrapper.spec.d.ts +0 -1
- package/dist/test-vitest/defaultObjectBySchema.test.d.ts +0 -1
- package/dist/test-vitest/useForm.test.d.ts +0 -1
package/src/VvFormField.ts
CHANGED
|
@@ -1,347 +1,379 @@
|
|
|
1
|
+
import type { Component, ConcreteComponent, DeepReadonly, InjectionKey, PropType, Ref, SlotsType } from 'vue'
|
|
2
|
+
import type { z } from 'zod'
|
|
3
|
+
import type {
|
|
4
|
+
FormFieldComponentOptions,
|
|
5
|
+
FormSchema,
|
|
6
|
+
InjectedFormData,
|
|
7
|
+
InjectedFormFieldData,
|
|
8
|
+
InjectedFormWrapperData,
|
|
9
|
+
Path,
|
|
10
|
+
} from './types'
|
|
1
11
|
import { get, set } from 'ts-dot-prop'
|
|
2
12
|
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
watch,
|
|
18
|
-
defineComponent,
|
|
19
|
-
onBeforeUnmount,
|
|
20
|
-
unref,
|
|
13
|
+
computed,
|
|
14
|
+
defineAsyncComponent,
|
|
15
|
+
defineComponent,
|
|
16
|
+
h,
|
|
17
|
+
inject,
|
|
18
|
+
onBeforeUnmount,
|
|
19
|
+
onMounted,
|
|
20
|
+
provide,
|
|
21
|
+
readonly,
|
|
22
|
+
resolveComponent,
|
|
23
|
+
toRefs,
|
|
24
|
+
unref,
|
|
25
|
+
watch,
|
|
26
|
+
useId,
|
|
21
27
|
} from 'vue'
|
|
22
|
-
import type { z } from 'zod'
|
|
23
28
|
import { FormFieldType } from './enums'
|
|
24
|
-
import type {
|
|
25
|
-
InjectedFormData,
|
|
26
|
-
InjectedFormWrapperData,
|
|
27
|
-
InjectedFormFieldData,
|
|
28
|
-
FormFieldComponentOptions,
|
|
29
|
-
Path,
|
|
30
|
-
FormSchema,
|
|
31
|
-
} from './types'
|
|
32
29
|
|
|
33
|
-
export
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
modelValue.value === undefined &&
|
|
117
|
-
props.defaultValue !== undefined
|
|
118
|
-
) {
|
|
119
|
-
modelValue.value = props.defaultValue
|
|
120
|
-
}
|
|
121
|
-
})
|
|
30
|
+
export function defineFormField<Schema extends FormSchema, Type = undefined>(formProvideKey: InjectionKey<InjectedFormData<Schema, Type>>, wrapperProvideKey: InjectionKey<InjectedFormWrapperData<Schema>>, formFieldInjectionKey: InjectionKey<InjectedFormFieldData<Schema>>, options?: FormFieldComponentOptions) {
|
|
31
|
+
return defineComponent({
|
|
32
|
+
name: 'VvFormField',
|
|
33
|
+
props: {
|
|
34
|
+
type: {
|
|
35
|
+
type: String as PropType<`${FormFieldType}`>,
|
|
36
|
+
validator: (value: FormFieldType) => {
|
|
37
|
+
return Object.values(FormFieldType).includes(value)
|
|
38
|
+
},
|
|
39
|
+
default: FormFieldType.custom,
|
|
40
|
+
},
|
|
41
|
+
is: {
|
|
42
|
+
type: [Object, String] as PropType<Component | string>,
|
|
43
|
+
default: undefined,
|
|
44
|
+
},
|
|
45
|
+
name: {
|
|
46
|
+
type: [String, Number, Boolean, Symbol] as PropType<
|
|
47
|
+
Path<z.infer<Schema>>
|
|
48
|
+
>,
|
|
49
|
+
required: true,
|
|
50
|
+
},
|
|
51
|
+
props: {
|
|
52
|
+
type: [Object, Function] as PropType<
|
|
53
|
+
Partial<
|
|
54
|
+
| z.infer<Schema>
|
|
55
|
+
| undefined
|
|
56
|
+
| ((
|
|
57
|
+
formData?: Ref<ObjectConstructor>,
|
|
58
|
+
) => Partial<z.infer<Schema>> | undefined)
|
|
59
|
+
>
|
|
60
|
+
>,
|
|
61
|
+
default: () => ({}),
|
|
62
|
+
},
|
|
63
|
+
showValid: {
|
|
64
|
+
type: Boolean,
|
|
65
|
+
default: false,
|
|
66
|
+
},
|
|
67
|
+
defaultValue: {
|
|
68
|
+
type: [String, Number, Boolean, Array, Object],
|
|
69
|
+
default: undefined,
|
|
70
|
+
},
|
|
71
|
+
lazyLoad: {
|
|
72
|
+
type: Boolean,
|
|
73
|
+
default: false,
|
|
74
|
+
},
|
|
75
|
+
readonly: {
|
|
76
|
+
type: Boolean,
|
|
77
|
+
default: undefined,
|
|
78
|
+
},
|
|
79
|
+
},
|
|
80
|
+
emits: [
|
|
81
|
+
'invalid',
|
|
82
|
+
'update:formData',
|
|
83
|
+
'update:modelValue',
|
|
84
|
+
'valid',
|
|
85
|
+
],
|
|
86
|
+
expose: [
|
|
87
|
+
'component',
|
|
88
|
+
'errors',
|
|
89
|
+
'hasProps',
|
|
90
|
+
'invalid',
|
|
91
|
+
'invalidLabel',
|
|
92
|
+
'is',
|
|
93
|
+
'type',
|
|
94
|
+
],
|
|
95
|
+
slots: Object as SlotsType<{
|
|
96
|
+
[key: string]: any
|
|
97
|
+
default: {
|
|
98
|
+
errors: DeepReadonly<z.inferFormattedError<Schema>>
|
|
99
|
+
formData?: undefined extends Type ? Partial<z.infer<Schema>> : Type
|
|
100
|
+
formErrors?: DeepReadonly<z.inferFormattedError<Schema, string>>
|
|
101
|
+
invalid: boolean
|
|
102
|
+
invalidLabel?: string[]
|
|
103
|
+
modelValue: any
|
|
104
|
+
readonly: boolean
|
|
105
|
+
onUpdate: (value: unknown) => void
|
|
106
|
+
submit?: InjectedFormData<Schema, Type>['submit']
|
|
107
|
+
validate?: InjectedFormData<Schema, Type>['validate']
|
|
108
|
+
}
|
|
109
|
+
}>,
|
|
110
|
+
setup(props, { slots, emit }) {
|
|
111
|
+
const { props: fieldProps, name: fieldName } = toRefs(props)
|
|
112
|
+
const fieldId = useId()
|
|
122
113
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
114
|
+
// inject data from parent form wrapper
|
|
115
|
+
const injectedWrapperData = inject(wrapperProvideKey, undefined)
|
|
116
|
+
if (injectedWrapperData) {
|
|
117
|
+
injectedWrapperData.fields.value.set(fieldId, props.name as string)
|
|
118
|
+
}
|
|
127
119
|
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
if (injectedWrapperData) {
|
|
131
|
-
injectedWrapperData.fields.value.add(props.name as string)
|
|
132
|
-
}
|
|
120
|
+
// inject data from parent form
|
|
121
|
+
const injectedFormData = inject(formProvideKey)
|
|
133
122
|
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
123
|
+
// v-model
|
|
124
|
+
const modelValue = computed({
|
|
125
|
+
get() {
|
|
126
|
+
if (!injectedFormData?.formData) {
|
|
127
|
+
return
|
|
128
|
+
}
|
|
129
|
+
return get(
|
|
130
|
+
new Object(injectedFormData.formData.value),
|
|
131
|
+
String(props.name),
|
|
132
|
+
)
|
|
133
|
+
},
|
|
134
|
+
set(value) {
|
|
135
|
+
if (!injectedFormData?.formData) {
|
|
136
|
+
return
|
|
137
|
+
}
|
|
138
|
+
set(
|
|
139
|
+
new Object(injectedFormData.formData.value),
|
|
140
|
+
String(props.name),
|
|
141
|
+
value,
|
|
142
|
+
)
|
|
143
|
+
emit('update:modelValue', {
|
|
144
|
+
newValue: modelValue.value,
|
|
145
|
+
formData: injectedFormData?.formData,
|
|
146
|
+
})
|
|
147
|
+
},
|
|
148
|
+
})
|
|
149
|
+
onMounted(() => {
|
|
150
|
+
if (
|
|
151
|
+
modelValue.value === undefined
|
|
152
|
+
&& props.defaultValue !== undefined
|
|
153
|
+
) {
|
|
154
|
+
modelValue.value = props.defaultValue
|
|
155
|
+
}
|
|
156
|
+
})
|
|
157
|
+
onBeforeUnmount(() => {
|
|
158
|
+
if (injectedWrapperData) {
|
|
159
|
+
injectedWrapperData.fields.value.delete(fieldId)
|
|
160
|
+
}
|
|
161
|
+
})
|
|
137
162
|
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
163
|
+
const errors = computed(() => {
|
|
164
|
+
if (!injectedFormData?.errors.value) {
|
|
165
|
+
return undefined
|
|
166
|
+
}
|
|
167
|
+
return get(injectedFormData.errors.value, String(props.name))
|
|
168
|
+
})
|
|
169
|
+
const invalidLabel = computed(() => {
|
|
170
|
+
return errors.value?._errors
|
|
171
|
+
})
|
|
172
|
+
const isInvalid = computed(() => {
|
|
173
|
+
return errors.value !== undefined
|
|
174
|
+
})
|
|
175
|
+
const unwatchInvalid = watch(isInvalid, (newValue) => {
|
|
176
|
+
if (newValue) {
|
|
177
|
+
emit('invalid', errors.value)
|
|
178
|
+
if (injectedWrapperData) {
|
|
179
|
+
injectedWrapperData.errors.value.set(
|
|
180
|
+
String(props.name),
|
|
181
|
+
errors.value,
|
|
182
|
+
)
|
|
183
|
+
}
|
|
184
|
+
return
|
|
185
|
+
}
|
|
186
|
+
emit('valid', modelValue.value)
|
|
187
|
+
if (injectedWrapperData) {
|
|
188
|
+
injectedWrapperData.errors.value.delete(
|
|
189
|
+
props.name as string,
|
|
190
|
+
)
|
|
191
|
+
}
|
|
192
|
+
})
|
|
193
|
+
const unwatchInjectedFormData = watch(
|
|
194
|
+
() => injectedFormData?.formData,
|
|
195
|
+
() => {
|
|
196
|
+
emit('update:formData', injectedFormData?.formData)
|
|
197
|
+
},
|
|
198
|
+
{ deep: true },
|
|
199
|
+
)
|
|
200
|
+
onBeforeUnmount(() => {
|
|
201
|
+
unwatchInvalid()
|
|
202
|
+
unwatchInjectedFormData()
|
|
203
|
+
})
|
|
204
|
+
const onUpdate = (value: unknown) => {
|
|
205
|
+
if (value instanceof InputEvent) {
|
|
206
|
+
value = (value.target as HTMLInputElement).value
|
|
207
|
+
}
|
|
208
|
+
modelValue.value = value
|
|
209
|
+
}
|
|
210
|
+
const hasFieldProps = computed(() => {
|
|
211
|
+
let toReturn = fieldProps.value
|
|
212
|
+
if (typeof toReturn === 'function') {
|
|
213
|
+
toReturn = toReturn(injectedFormData?.formData)
|
|
214
|
+
}
|
|
215
|
+
return Object.keys(toReturn).reduce<Record<string, unknown>>(
|
|
216
|
+
(acc, key) => {
|
|
217
|
+
acc[key] = unref(toReturn[key])
|
|
218
|
+
return acc
|
|
219
|
+
},
|
|
220
|
+
{},
|
|
221
|
+
)
|
|
222
|
+
})
|
|
223
|
+
const isReadonly = computed(() => {
|
|
224
|
+
if (injectedFormData?.readonly.value) {
|
|
225
|
+
return true
|
|
226
|
+
}
|
|
227
|
+
if (injectedWrapperData?.readonly.value) {
|
|
228
|
+
return true
|
|
229
|
+
}
|
|
230
|
+
return (hasFieldProps.value.readonly ?? props.readonly) as boolean
|
|
231
|
+
})
|
|
232
|
+
const hasProps = computed(() => ({
|
|
233
|
+
...hasFieldProps.value,
|
|
234
|
+
'name': hasFieldProps.value.name ?? props.name,
|
|
235
|
+
'invalid': isInvalid.value,
|
|
236
|
+
'valid': props.showValid
|
|
237
|
+
? Boolean(!isInvalid.value && modelValue.value)
|
|
238
|
+
: undefined,
|
|
239
|
+
'type': ((type: FormFieldType) => {
|
|
240
|
+
if (
|
|
241
|
+
[
|
|
242
|
+
FormFieldType.color,
|
|
243
|
+
FormFieldType.date,
|
|
244
|
+
FormFieldType.datetimeLocal,
|
|
245
|
+
FormFieldType.email,
|
|
246
|
+
FormFieldType.month,
|
|
247
|
+
FormFieldType.number,
|
|
248
|
+
FormFieldType.password,
|
|
249
|
+
FormFieldType.search,
|
|
250
|
+
FormFieldType.tel,
|
|
251
|
+
FormFieldType.text,
|
|
252
|
+
FormFieldType.time,
|
|
253
|
+
FormFieldType.url,
|
|
254
|
+
FormFieldType.week,
|
|
255
|
+
].includes(type)
|
|
256
|
+
) {
|
|
257
|
+
return type
|
|
258
|
+
}
|
|
259
|
+
return undefined
|
|
260
|
+
})(props.type as FormFieldType),
|
|
261
|
+
'invalidLabel': invalidLabel.value,
|
|
262
|
+
'modelValue': modelValue.value,
|
|
263
|
+
'readonly': isReadonly.value,
|
|
264
|
+
'onUpdate:modelValue': onUpdate,
|
|
265
|
+
}))
|
|
233
266
|
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
267
|
+
// provide data to children
|
|
268
|
+
provide(formFieldInjectionKey, {
|
|
269
|
+
name: readonly(fieldName) as Readonly<Ref<Path<z.infer<Schema>>>>,
|
|
270
|
+
errors: readonly(errors),
|
|
271
|
+
})
|
|
239
272
|
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
})
|
|
273
|
+
// load component
|
|
274
|
+
const component = computed(() => {
|
|
275
|
+
if (props.type === FormFieldType.custom) {
|
|
276
|
+
return {
|
|
277
|
+
render() {
|
|
278
|
+
return (
|
|
279
|
+
slots.default?.({
|
|
280
|
+
errors: errors.value,
|
|
281
|
+
formData: injectedFormData?.formData.value,
|
|
282
|
+
formErrors: injectedFormData?.errors.value,
|
|
283
|
+
invalid: isInvalid.value,
|
|
284
|
+
invalidLabel: invalidLabel.value,
|
|
285
|
+
modelValue: modelValue.value,
|
|
286
|
+
readonly: isReadonly.value,
|
|
287
|
+
onUpdate,
|
|
288
|
+
submit: injectedFormData?.submit,
|
|
289
|
+
validate: injectedFormData?.validate,
|
|
290
|
+
}) ?? slots.default
|
|
291
|
+
)
|
|
292
|
+
},
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
if (!(options?.lazyLoad ?? props.lazyLoad)) {
|
|
296
|
+
let component: string | ConcreteComponent
|
|
297
|
+
switch (props.type) {
|
|
298
|
+
case FormFieldType.select:
|
|
299
|
+
component = resolveComponent('VvSelect')
|
|
300
|
+
break
|
|
301
|
+
case FormFieldType.checkbox:
|
|
302
|
+
component = resolveComponent('VvCheckbox')
|
|
303
|
+
break
|
|
304
|
+
case FormFieldType.radio:
|
|
305
|
+
component = resolveComponent('VvRadio')
|
|
306
|
+
break
|
|
307
|
+
case FormFieldType.textarea:
|
|
308
|
+
component = resolveComponent('VvTextarea')
|
|
309
|
+
break
|
|
310
|
+
case FormFieldType.radioGroup:
|
|
311
|
+
component = resolveComponent('VvRadioGroup')
|
|
312
|
+
break
|
|
313
|
+
case FormFieldType.checkboxGroup:
|
|
314
|
+
component = resolveComponent('VvCheckboxGroup')
|
|
315
|
+
break
|
|
316
|
+
case FormFieldType.combobox:
|
|
317
|
+
component = resolveComponent('VvCombobox')
|
|
318
|
+
break
|
|
319
|
+
default:
|
|
320
|
+
component = resolveComponent('VvInputText')
|
|
321
|
+
}
|
|
322
|
+
if (typeof component !== 'string') {
|
|
323
|
+
return component
|
|
324
|
+
}
|
|
325
|
+
console.warn(
|
|
326
|
+
`[@volverjs/form-vue]: ${component} not found, the component will be loaded asynchronously. To avoid this warning, please set "lazyLoad" option.`,
|
|
327
|
+
)
|
|
328
|
+
}
|
|
329
|
+
return defineAsyncComponent(async () => {
|
|
330
|
+
if (options?.sideEffects) {
|
|
331
|
+
await Promise.resolve(options.sideEffects(props.type))
|
|
332
|
+
}
|
|
333
|
+
switch (props.type) {
|
|
334
|
+
case FormFieldType.textarea:
|
|
335
|
+
return import(
|
|
336
|
+
'@volverjs/ui-vue/vv-textarea'
|
|
337
|
+
) as Component
|
|
338
|
+
case FormFieldType.radio:
|
|
339
|
+
return import(
|
|
340
|
+
'@volverjs/ui-vue/vv-radio'
|
|
341
|
+
) as Component
|
|
342
|
+
case FormFieldType.radioGroup:
|
|
343
|
+
return import(
|
|
344
|
+
'@volverjs/ui-vue/vv-radio-group'
|
|
345
|
+
) as Component
|
|
346
|
+
case FormFieldType.checkbox:
|
|
347
|
+
return import(
|
|
348
|
+
'@volverjs/ui-vue/vv-checkbox'
|
|
349
|
+
) as Component
|
|
350
|
+
case FormFieldType.checkboxGroup:
|
|
351
|
+
return import(
|
|
352
|
+
'@volverjs/ui-vue/vv-checkbox-group'
|
|
353
|
+
) as Component
|
|
354
|
+
case FormFieldType.select:
|
|
355
|
+
return import(
|
|
356
|
+
'@volverjs/ui-vue/vv-select'
|
|
357
|
+
) as Component
|
|
358
|
+
case FormFieldType.combobox:
|
|
359
|
+
return import(
|
|
360
|
+
'@volverjs/ui-vue/vv-combobox'
|
|
361
|
+
) as Component
|
|
362
|
+
}
|
|
363
|
+
return import('@volverjs/ui-vue/vv-input-text') as Component
|
|
364
|
+
})
|
|
365
|
+
})
|
|
334
366
|
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
367
|
+
return { component, hasProps, invalid: isInvalid }
|
|
368
|
+
},
|
|
369
|
+
render() {
|
|
370
|
+
if (this.is) {
|
|
371
|
+
return h(this.is, this.hasProps, this.$slots)
|
|
372
|
+
}
|
|
373
|
+
if (this.type === FormFieldType.custom) {
|
|
374
|
+
return h(this.component, null, this.$slots)
|
|
375
|
+
}
|
|
376
|
+
return h(this.component, this.hasProps, this.$slots)
|
|
377
|
+
},
|
|
378
|
+
})
|
|
347
379
|
}
|