@volverjs/form-vue 1.0.0-beta.6 → 1.0.0-beta.8
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/index.es.js +312 -271
- package/dist/index.umd.js +1 -1
- package/dist/src/VvForm.d.ts +99 -110
- package/dist/src/VvFormField.d.ts +11 -1
- package/dist/src/VvFormTemplate.d.ts +22 -54
- package/dist/src/VvFormWrapper.d.ts +45 -80
- package/dist/src/index.d.ts +569 -773
- package/dist/src/types.d.ts +2 -0
- package/package.json +22 -22
- package/src/VvForm.ts +56 -7
- package/src/VvFormField.ts +14 -0
- package/src/index.ts +2 -0
- package/src/types.ts +12 -10
package/dist/src/types.d.ts
CHANGED
|
@@ -10,6 +10,7 @@ export type FormFieldComponentOptions = {
|
|
|
10
10
|
export type FormComponentOptions<Schema> = {
|
|
11
11
|
updateThrottle?: number;
|
|
12
12
|
continuosValidation?: boolean;
|
|
13
|
+
readonly?: boolean;
|
|
13
14
|
template?: Schema extends FormSchema ? FormTemplate<Schema> : never;
|
|
14
15
|
onUpdate?: Schema extends FormSchema ? (data: Partial<z.infer<Schema> | undefined>) => void : never;
|
|
15
16
|
onSubmit?: Schema extends FormSchema ? (data: z.infer<Schema>) => void : never;
|
|
@@ -30,6 +31,7 @@ export type InjectedFormData<Schema extends FormSchema> = {
|
|
|
30
31
|
stopUpdatesWatch: WatchStopHandle;
|
|
31
32
|
status: Readonly<Ref<FormStatus | undefined>>;
|
|
32
33
|
invalid: Readonly<Ref<boolean>>;
|
|
34
|
+
readonly: Ref<boolean>;
|
|
33
35
|
};
|
|
34
36
|
export type InjectedFormWrapperData<Schema extends FormSchema> = {
|
|
35
37
|
name: Ref<string>;
|
package/package.json
CHANGED
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
"bugs": {
|
|
20
20
|
"url": "https://github.com/volverjs/form-vue/issues"
|
|
21
21
|
},
|
|
22
|
-
"version": "1.0.0-beta.
|
|
22
|
+
"version": "1.0.0-beta.8",
|
|
23
23
|
"engines": {
|
|
24
24
|
"node": ">= 16.x"
|
|
25
25
|
},
|
|
@@ -35,35 +35,35 @@
|
|
|
35
35
|
"*.d.ts"
|
|
36
36
|
],
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@volverjs/ui-vue": "
|
|
39
|
-
"@vueuse/core": "^10.
|
|
38
|
+
"@volverjs/ui-vue": "0.0.10-beta.27",
|
|
39
|
+
"@vueuse/core": "^10.7.2",
|
|
40
40
|
"ts-dot-prop": "^2.1.3",
|
|
41
|
-
"vue": "^3.
|
|
41
|
+
"vue": "^3.4.15",
|
|
42
42
|
"zod": "^3.22.4"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
|
-
"@playwright/experimental-ct-vue": "1.
|
|
46
|
-
"@testing-library/vue": "^8.0.
|
|
47
|
-
"@typescript-eslint/eslint-plugin": "^6.
|
|
48
|
-
"@vitejs/plugin-vue": "^
|
|
45
|
+
"@playwright/experimental-ct-vue": "1.41.1",
|
|
46
|
+
"@testing-library/vue": "^8.0.1",
|
|
47
|
+
"@typescript-eslint/eslint-plugin": "^6.20.0",
|
|
48
|
+
"@vitejs/plugin-vue": "^5.0.3",
|
|
49
49
|
"@volverjs/style": "^0.1.11",
|
|
50
|
-
"@vue/compiler-sfc": "^3.
|
|
50
|
+
"@vue/compiler-sfc": "^3.4.15",
|
|
51
51
|
"@vue/eslint-config-typescript": "^12.0.0",
|
|
52
|
-
"@vue/runtime-core": "^3.
|
|
53
|
-
"@vue/test-utils": "^2.4.
|
|
52
|
+
"@vue/runtime-core": "^3.4.15",
|
|
53
|
+
"@vue/test-utils": "^2.4.4",
|
|
54
54
|
"copy": "^0.3.2",
|
|
55
|
-
"eslint": "^8.
|
|
56
|
-
"eslint-config-prettier": "^9.
|
|
57
|
-
"eslint-plugin-prettier": "^5.
|
|
58
|
-
"eslint-plugin-vue": "^9.
|
|
59
|
-
"happy-dom": "^
|
|
60
|
-
"prettier": "^3.
|
|
61
|
-
"typescript": "^5.
|
|
62
|
-
"vite": "^
|
|
63
|
-
"vite-plugin-dts": "^3.
|
|
55
|
+
"eslint": "^8.56.0",
|
|
56
|
+
"eslint-config-prettier": "^9.1.0",
|
|
57
|
+
"eslint-plugin-prettier": "^5.1.3",
|
|
58
|
+
"eslint-plugin-vue": "^9.21.0",
|
|
59
|
+
"happy-dom": "^13.3.5",
|
|
60
|
+
"prettier": "^3.2.4",
|
|
61
|
+
"typescript": "^5.3.3",
|
|
62
|
+
"vite": "^5.0.12",
|
|
63
|
+
"vite-plugin-dts": "^3.7.2",
|
|
64
64
|
"vite-plugin-eslint": "^1.8.1",
|
|
65
|
-
"vite-plugin-externalize-deps": "^0.
|
|
66
|
-
"vitest": "^
|
|
65
|
+
"vite-plugin-externalize-deps": "^0.8.0",
|
|
66
|
+
"vitest": "^1.2.2"
|
|
67
67
|
},
|
|
68
68
|
"typesVersions": {
|
|
69
69
|
"*": {
|
package/src/VvForm.ts
CHANGED
|
@@ -9,12 +9,13 @@ import {
|
|
|
9
9
|
defineComponent,
|
|
10
10
|
ref,
|
|
11
11
|
provide,
|
|
12
|
-
readonly,
|
|
12
|
+
readonly as makeReadonly,
|
|
13
13
|
watch,
|
|
14
14
|
h,
|
|
15
15
|
toRaw,
|
|
16
16
|
isProxy,
|
|
17
17
|
computed,
|
|
18
|
+
onMounted,
|
|
18
19
|
} from 'vue'
|
|
19
20
|
import {
|
|
20
21
|
watchIgnorable,
|
|
@@ -41,8 +42,12 @@ export const defineForm = <Schema extends FormSchema>(
|
|
|
41
42
|
const status = ref<FormStatus | undefined>()
|
|
42
43
|
const invalid = computed(() => status.value === FormStatus.invalid)
|
|
43
44
|
const formData = ref<Partial<z.infer<Schema> | undefined>>()
|
|
45
|
+
const readonly = ref<boolean>(false)
|
|
44
46
|
|
|
45
47
|
const validate = async (value = formData.value) => {
|
|
48
|
+
if (readonly.value) {
|
|
49
|
+
return true
|
|
50
|
+
}
|
|
46
51
|
const parseResult = await schema.safeParseAsync(value)
|
|
47
52
|
if (!parseResult.success) {
|
|
48
53
|
errors.value = parseResult.error.format() as ZodFormattedError<
|
|
@@ -58,6 +63,9 @@ export const defineForm = <Schema extends FormSchema>(
|
|
|
58
63
|
}
|
|
59
64
|
|
|
60
65
|
const submit = async () => {
|
|
66
|
+
if (readonly.value) {
|
|
67
|
+
return false
|
|
68
|
+
}
|
|
61
69
|
if (!(await validate())) {
|
|
62
70
|
return false
|
|
63
71
|
}
|
|
@@ -87,6 +95,10 @@ export const defineForm = <Schema extends FormSchema>(
|
|
|
87
95
|
type: Object,
|
|
88
96
|
default: () => ({}),
|
|
89
97
|
},
|
|
98
|
+
readonly: {
|
|
99
|
+
type: Boolean,
|
|
100
|
+
default: options?.readonly ?? false,
|
|
101
|
+
},
|
|
90
102
|
tag: {
|
|
91
103
|
type: String,
|
|
92
104
|
default: 'form',
|
|
@@ -96,8 +108,22 @@ export const defineForm = <Schema extends FormSchema>(
|
|
|
96
108
|
default: undefined,
|
|
97
109
|
},
|
|
98
110
|
},
|
|
99
|
-
emits: [
|
|
100
|
-
|
|
111
|
+
emits: [
|
|
112
|
+
'invalid',
|
|
113
|
+
'valid',
|
|
114
|
+
'submit',
|
|
115
|
+
'update:modelValue',
|
|
116
|
+
'update:readonly',
|
|
117
|
+
],
|
|
118
|
+
expose: [
|
|
119
|
+
'submit',
|
|
120
|
+
'validate',
|
|
121
|
+
'errors',
|
|
122
|
+
'status',
|
|
123
|
+
'valid',
|
|
124
|
+
'invalid',
|
|
125
|
+
'readonly',
|
|
126
|
+
],
|
|
101
127
|
setup(props, { emit }) {
|
|
102
128
|
formData.value = defaultObjectBySchema(
|
|
103
129
|
schema,
|
|
@@ -176,15 +202,34 @@ export const defineForm = <Schema extends FormSchema>(
|
|
|
176
202
|
}
|
|
177
203
|
})
|
|
178
204
|
|
|
205
|
+
onMounted(() => {
|
|
206
|
+
if (props.readonly && !readonly.value) {
|
|
207
|
+
readonly.value = props.readonly
|
|
208
|
+
}
|
|
209
|
+
})
|
|
210
|
+
|
|
211
|
+
watch(
|
|
212
|
+
() => props.readonly,
|
|
213
|
+
(newValue) => {
|
|
214
|
+
readonly.value = newValue
|
|
215
|
+
},
|
|
216
|
+
)
|
|
217
|
+
watch(readonly, (newValue) => {
|
|
218
|
+
if (newValue !== props.readonly) {
|
|
219
|
+
emit('update:readonly', readonly.value)
|
|
220
|
+
}
|
|
221
|
+
})
|
|
222
|
+
|
|
179
223
|
provide(provideKey, {
|
|
180
224
|
formData,
|
|
181
225
|
submit,
|
|
182
226
|
validate,
|
|
183
227
|
ignoreUpdates,
|
|
184
228
|
stopUpdatesWatch,
|
|
185
|
-
errors:
|
|
186
|
-
status:
|
|
229
|
+
errors: makeReadonly(errors),
|
|
230
|
+
status: makeReadonly(status),
|
|
187
231
|
invalid,
|
|
232
|
+
readonly,
|
|
188
233
|
})
|
|
189
234
|
|
|
190
235
|
return {
|
|
@@ -193,9 +238,10 @@ export const defineForm = <Schema extends FormSchema>(
|
|
|
193
238
|
validate,
|
|
194
239
|
ignoreUpdates,
|
|
195
240
|
stopUpdatesWatch,
|
|
196
|
-
errors:
|
|
197
|
-
status:
|
|
241
|
+
errors: makeReadonly(errors),
|
|
242
|
+
status: makeReadonly(status),
|
|
198
243
|
invalid,
|
|
244
|
+
isReadonly: readonly,
|
|
199
245
|
}
|
|
200
246
|
},
|
|
201
247
|
render() {
|
|
@@ -209,6 +255,7 @@ export const defineForm = <Schema extends FormSchema>(
|
|
|
209
255
|
errors: this.errors,
|
|
210
256
|
status: this.status,
|
|
211
257
|
invalid: this.invalid,
|
|
258
|
+
readonly: this.isReadonly,
|
|
212
259
|
}) ?? this.$slots.default
|
|
213
260
|
return h(
|
|
214
261
|
this.tag,
|
|
@@ -237,6 +284,7 @@ export const defineForm = <Schema extends FormSchema>(
|
|
|
237
284
|
errors,
|
|
238
285
|
status,
|
|
239
286
|
invalid,
|
|
287
|
+
readonly,
|
|
240
288
|
formData,
|
|
241
289
|
validate,
|
|
242
290
|
submit,
|
|
@@ -263,6 +311,7 @@ export const defineForm = <Schema extends FormSchema>(
|
|
|
263
311
|
>
|
|
264
312
|
status: Ref<DeepReadonly<`${FormStatus}` | undefined>>
|
|
265
313
|
invalid: Ref<DeepReadonly<boolean>>
|
|
314
|
+
readonly: Ref<boolean>
|
|
266
315
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
267
316
|
}) => any
|
|
268
317
|
}
|
package/src/VvFormField.ts
CHANGED
|
@@ -81,6 +81,10 @@ export const defineFormField = <Schema extends FormSchema>(
|
|
|
81
81
|
type: Boolean,
|
|
82
82
|
default: false,
|
|
83
83
|
},
|
|
84
|
+
readonly: {
|
|
85
|
+
type: Boolean,
|
|
86
|
+
default: undefined,
|
|
87
|
+
},
|
|
84
88
|
},
|
|
85
89
|
emits: ['invalid', 'valid', 'update:formData', 'update:modelValue'],
|
|
86
90
|
expose: ['invalid', 'invalidLabel', 'errors'],
|
|
@@ -186,6 +190,12 @@ export const defineFormField = <Schema extends FormSchema>(
|
|
|
186
190
|
{},
|
|
187
191
|
)
|
|
188
192
|
})
|
|
193
|
+
const isReadonly = computed(() => {
|
|
194
|
+
if (injectedFormData?.readonly.value) {
|
|
195
|
+
return true
|
|
196
|
+
}
|
|
197
|
+
return hasFieldProps.value.readonly ?? props.readonly
|
|
198
|
+
})
|
|
189
199
|
const hasProps = computed(() => ({
|
|
190
200
|
...hasFieldProps.value,
|
|
191
201
|
name: hasFieldProps.value.name ?? props.name,
|
|
@@ -217,14 +227,17 @@ export const defineFormField = <Schema extends FormSchema>(
|
|
|
217
227
|
})(props.type as FormFieldType),
|
|
218
228
|
invalidLabel: invalidLabel.value,
|
|
219
229
|
modelValue: modelValue.value,
|
|
230
|
+
readonly: isReadonly.value,
|
|
220
231
|
'onUpdate:modelValue': onUpdate,
|
|
221
232
|
}))
|
|
222
233
|
|
|
234
|
+
// provide data to children
|
|
223
235
|
provide(formFieldInjectionKey, {
|
|
224
236
|
name: readonly(fieldName as Ref<string>),
|
|
225
237
|
errors: readonly(errors),
|
|
226
238
|
})
|
|
227
239
|
|
|
240
|
+
// load component
|
|
228
241
|
const component = computed(() => {
|
|
229
242
|
if (props.type === FormFieldType.custom) {
|
|
230
243
|
return {
|
|
@@ -240,6 +253,7 @@ export const defineFormField = <Schema extends FormSchema>(
|
|
|
240
253
|
formData: injectedFormData?.formData.value,
|
|
241
254
|
formErrors: injectedFormData?.errors.value,
|
|
242
255
|
errors: errors.value,
|
|
256
|
+
readonly: isReadonly.value,
|
|
243
257
|
}) ?? slots.defalut
|
|
244
258
|
)
|
|
245
259
|
},
|
package/src/index.ts
CHANGED
|
@@ -53,6 +53,7 @@ const _formFactory = <Schema extends FormSchema>(
|
|
|
53
53
|
errors,
|
|
54
54
|
status,
|
|
55
55
|
invalid,
|
|
56
|
+
readonly,
|
|
56
57
|
formData,
|
|
57
58
|
validate,
|
|
58
59
|
submit,
|
|
@@ -71,6 +72,7 @@ const _formFactory = <Schema extends FormSchema>(
|
|
|
71
72
|
errors,
|
|
72
73
|
status,
|
|
73
74
|
invalid,
|
|
75
|
+
readonly,
|
|
74
76
|
formData,
|
|
75
77
|
validate,
|
|
76
78
|
submit,
|
package/src/types.ts
CHANGED
|
@@ -16,6 +16,7 @@ export type FormFieldComponentOptions = {
|
|
|
16
16
|
export type FormComponentOptions<Schema> = {
|
|
17
17
|
updateThrottle?: number
|
|
18
18
|
continuosValidation?: boolean
|
|
19
|
+
readonly?: boolean
|
|
19
20
|
template?: Schema extends FormSchema ? FormTemplate<Schema> : never
|
|
20
21
|
onUpdate?: Schema extends FormSchema
|
|
21
22
|
? (data: Partial<z.infer<Schema> | undefined>) => void
|
|
@@ -52,6 +53,7 @@ export type InjectedFormData<Schema extends FormSchema> = {
|
|
|
52
53
|
stopUpdatesWatch: WatchStopHandle
|
|
53
54
|
status: Readonly<Ref<FormStatus | undefined>>
|
|
54
55
|
invalid: Readonly<Ref<boolean>>
|
|
56
|
+
readonly: Ref<boolean>
|
|
55
57
|
}
|
|
56
58
|
|
|
57
59
|
export type InjectedFormWrapperData<Schema extends FormSchema> = {
|
|
@@ -107,17 +109,17 @@ export type PathValue<T, TPath extends Path<T> | Path<T>[]> = T extends any
|
|
|
107
109
|
: PathValue<T[K], R>
|
|
108
110
|
: never
|
|
109
111
|
: K extends `${number}`
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
112
|
+
? T extends readonly (infer V)[]
|
|
113
|
+
? PathValue<V, R & Path<V>>
|
|
114
|
+
: never
|
|
115
|
+
: never
|
|
114
116
|
: TPath extends keyof T
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
117
|
+
? T[TPath]
|
|
118
|
+
: TPath extends `${number}`
|
|
119
|
+
? T extends readonly (infer V)[]
|
|
120
|
+
? V
|
|
121
|
+
: never
|
|
122
|
+
: never
|
|
121
123
|
: never
|
|
122
124
|
|
|
123
125
|
export type AnyBoolean<Schema extends FormSchema> =
|