@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/index.ts
CHANGED
|
@@ -1,134 +1,158 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
type Plugin,
|
|
2
|
+
getCurrentInstance,
|
|
3
|
+
|
|
4
|
+
inject,
|
|
5
|
+
|
|
7
6
|
} from 'vue'
|
|
8
|
-
import {
|
|
7
|
+
import type { App, InjectionKey, Plugin } from 'vue'
|
|
8
|
+
import type { AnyZodObject } from 'zod'
|
|
9
9
|
import { defineForm } from './VvForm'
|
|
10
|
+
import { defineFormField } from './VvFormField'
|
|
11
|
+
import { defineFormFieldsGroup } from './VvFormFieldsGroup'
|
|
10
12
|
import { defineFormWrapper } from './VvFormWrapper'
|
|
11
13
|
import { defineFormTemplate } from './VvFormTemplate'
|
|
12
14
|
import type {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
15
|
+
InjectedFormData,
|
|
16
|
+
InjectedFormWrapperData,
|
|
17
|
+
InjectedFormFieldData,
|
|
18
|
+
InjectedFormFieldsGroupData,
|
|
19
|
+
FormComposableOptions,
|
|
20
|
+
FormPluginOptions,
|
|
21
|
+
FormTemplateItem,
|
|
22
|
+
Path,
|
|
23
|
+
PathValue,
|
|
24
|
+
FormSchema,
|
|
25
|
+
FormTemplate,
|
|
23
26
|
} from './types'
|
|
24
|
-
import type { AnyZodObject } from 'zod'
|
|
25
27
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
)
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
28
|
+
function _formType<Schema extends FormSchema, Type>(schema: Schema, options: FormComposableOptions<Schema, Type> = {}) {
|
|
29
|
+
// create injection keys
|
|
30
|
+
const formInjectionKey = Symbol('formInjectionKey') as InjectionKey<InjectedFormData<Schema, Type>>
|
|
31
|
+
const formWrapperInjectionKey = Symbol('formWrapperInjectionKey') as InjectionKey<
|
|
32
|
+
InjectedFormWrapperData<Schema>
|
|
33
|
+
>
|
|
34
|
+
const formFieldInjectionKey = Symbol('formFieldInjectionKey') as InjectionKey<
|
|
35
|
+
InjectedFormFieldData<Schema>
|
|
36
|
+
>
|
|
37
|
+
const formFieldsGroupInjectionKey = Symbol('formFieldsGroupInjectionKey') as InjectionKey<
|
|
38
|
+
InjectedFormFieldsGroupData<Schema>
|
|
39
|
+
>
|
|
38
40
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
41
|
+
// create components
|
|
42
|
+
const VvFormWrapper = defineFormWrapper<Schema, Type>(
|
|
43
|
+
formInjectionKey,
|
|
44
|
+
formWrapperInjectionKey,
|
|
45
|
+
)
|
|
46
|
+
const VvFormField = defineFormField<Schema, Type>(
|
|
47
|
+
formInjectionKey,
|
|
48
|
+
formWrapperInjectionKey,
|
|
49
|
+
formFieldInjectionKey,
|
|
50
|
+
options,
|
|
51
|
+
)
|
|
52
|
+
const VvFormFieldsGroup = defineFormFieldsGroup<Schema, Type>(
|
|
53
|
+
formInjectionKey,
|
|
54
|
+
formWrapperInjectionKey,
|
|
55
|
+
formFieldsGroupInjectionKey,
|
|
56
|
+
)
|
|
57
|
+
const VvFormTemplate = defineFormTemplate<Schema, Type>(formInjectionKey, VvFormField)
|
|
58
|
+
const wrappers = new Map<string, InjectedFormWrapperData<Schema>>()
|
|
59
|
+
const {
|
|
60
|
+
clear,
|
|
61
|
+
errors,
|
|
62
|
+
formData,
|
|
63
|
+
ignoreUpdates,
|
|
64
|
+
invalid,
|
|
65
|
+
readonly,
|
|
66
|
+
reset,
|
|
67
|
+
status,
|
|
68
|
+
stopUpdatesWatch,
|
|
69
|
+
submit,
|
|
70
|
+
validate,
|
|
71
|
+
VvForm,
|
|
72
|
+
} = defineForm(schema, formInjectionKey, options, VvFormTemplate, wrappers)
|
|
63
73
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
74
|
+
return {
|
|
75
|
+
clear,
|
|
76
|
+
errors,
|
|
77
|
+
formData,
|
|
78
|
+
formFieldInjectionKey,
|
|
79
|
+
formInjectionKey,
|
|
80
|
+
formWrapperInjectionKey,
|
|
81
|
+
ignoreUpdates,
|
|
82
|
+
invalid,
|
|
83
|
+
readonly,
|
|
84
|
+
reset,
|
|
85
|
+
status,
|
|
86
|
+
stopUpdatesWatch,
|
|
87
|
+
submit,
|
|
88
|
+
validate,
|
|
89
|
+
wrappers,
|
|
90
|
+
VvForm,
|
|
91
|
+
VvFormField,
|
|
92
|
+
VvFormFieldsGroup,
|
|
93
|
+
VvFormTemplate,
|
|
94
|
+
VvFormWrapper,
|
|
95
|
+
}
|
|
82
96
|
}
|
|
83
97
|
|
|
84
|
-
export const pluginInjectionKey = Symbol() as InjectionKey<FormPluginOptions>
|
|
98
|
+
export const pluginInjectionKey = Symbol('pluginInjectionKey') as InjectionKey<FormPluginOptions>
|
|
85
99
|
|
|
86
|
-
export
|
|
87
|
-
|
|
88
|
-
)
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
install(app: App, { global = false } = {}) {
|
|
96
|
-
app.provide(pluginInjectionKey, options)
|
|
100
|
+
export function createForm(options: FormPluginOptions): Plugin & Partial<ReturnType<typeof useForm>> {
|
|
101
|
+
let toReturn: Partial<ReturnType<typeof useForm>> = {}
|
|
102
|
+
if (options.schema) {
|
|
103
|
+
toReturn = _formType(options.schema as AnyZodObject, options)
|
|
104
|
+
}
|
|
105
|
+
return {
|
|
106
|
+
...toReturn,
|
|
107
|
+
install(app: App, { global = false } = {}) {
|
|
108
|
+
app.provide(pluginInjectionKey, options)
|
|
97
109
|
|
|
98
|
-
|
|
99
|
-
|
|
110
|
+
if (global) {
|
|
111
|
+
app.config.globalProperties.$vvForm = options
|
|
100
112
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
113
|
+
if (toReturn?.VvForm) {
|
|
114
|
+
app.component('VvForm', toReturn.VvForm)
|
|
115
|
+
}
|
|
116
|
+
if (toReturn?.VvFormWrapper) {
|
|
117
|
+
app.component('VvFormWrapper', toReturn.VvFormWrapper)
|
|
118
|
+
}
|
|
119
|
+
if (toReturn?.VvFormField) {
|
|
120
|
+
app.component('VvFormField', toReturn.VvFormField)
|
|
121
|
+
}
|
|
122
|
+
if (toReturn?.VvFormFieldsGroup) {
|
|
123
|
+
app.component('VvFormFieldsGroup', toReturn.VvFormFieldsGroup)
|
|
124
|
+
}
|
|
125
|
+
if (toReturn?.VvFormTemplate) {
|
|
126
|
+
app.component('VvFormTemplate', toReturn.VvFormTemplate)
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
},
|
|
130
|
+
}
|
|
116
131
|
}
|
|
117
132
|
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
)
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
133
|
+
const formInstances: Map<string, ReturnType<typeof _formType>> = new Map()
|
|
134
|
+
export function useForm<Schema extends FormSchema, Type>(schema: Schema, options: FormComposableOptions<Schema, Type> = {}): ReturnType <typeof _formType<Schema, Type>> {
|
|
135
|
+
if (options.scope && formInstances.has(options.scope)) {
|
|
136
|
+
return formInstances.get(options.scope)
|
|
137
|
+
}
|
|
138
|
+
if (!getCurrentInstance()) {
|
|
139
|
+
const toReturn = _formType(schema, options)
|
|
140
|
+
if (options.scope) {
|
|
141
|
+
formInstances.set(options.scope, toReturn)
|
|
142
|
+
}
|
|
143
|
+
return toReturn
|
|
144
|
+
}
|
|
145
|
+
const toReturn = _formType(
|
|
146
|
+
schema,
|
|
147
|
+
{
|
|
148
|
+
...inject(pluginInjectionKey, {}),
|
|
149
|
+
...options,
|
|
150
|
+
} as FormComposableOptions<Schema, Type>,
|
|
151
|
+
)
|
|
152
|
+
if (options.scope) {
|
|
153
|
+
formInstances.set(options.scope, toReturn)
|
|
154
|
+
}
|
|
155
|
+
return toReturn
|
|
132
156
|
}
|
|
133
157
|
|
|
134
158
|
export { FormFieldType } from './enums'
|
|
@@ -137,31 +161,30 @@ export { defaultObjectBySchema } from './utils'
|
|
|
137
161
|
type FormComponent = ReturnType<typeof defineForm>
|
|
138
162
|
type FormWrapperComponent = ReturnType<typeof defineFormWrapper>
|
|
139
163
|
type FormFieldComponent = ReturnType<typeof defineFormField>
|
|
140
|
-
type
|
|
164
|
+
type FormFieldsGroupComponent = ReturnType<typeof defineFormFieldsGroup>
|
|
165
|
+
type FormTemplateComponent = ReturnType<typeof defineFormFieldsGroup>
|
|
141
166
|
|
|
142
167
|
export type {
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
168
|
+
FormComponent,
|
|
169
|
+
FormComposableOptions,
|
|
170
|
+
FormFieldComponent,
|
|
171
|
+
FormFieldsGroupComponent,
|
|
172
|
+
FormPluginOptions,
|
|
173
|
+
FormSchema,
|
|
174
|
+
FormTemplate,
|
|
175
|
+
FormTemplateComponent,
|
|
176
|
+
FormTemplateItem,
|
|
177
|
+
FormWrapperComponent,
|
|
178
|
+
InjectedFormData,
|
|
179
|
+
InjectedFormFieldData,
|
|
180
|
+
InjectedFormWrapperData,
|
|
181
|
+
Path,
|
|
182
|
+
PathValue,
|
|
157
183
|
}
|
|
158
184
|
|
|
159
185
|
/**
|
|
160
186
|
* @deprecated Use `useForm()` instead
|
|
161
187
|
*/
|
|
162
|
-
export
|
|
163
|
-
|
|
164
|
-
options: FormComposableOptions<Schema> = {},
|
|
165
|
-
) => {
|
|
166
|
-
return _formFactory(schema, options)
|
|
188
|
+
export function formType<Schema extends FormSchema, Type>(schema: Schema, options: FormComposableOptions<Schema, Type> = {}) {
|
|
189
|
+
return _formType(schema, options)
|
|
167
190
|
}
|
package/src/types.ts
CHANGED
|
@@ -1,158 +1,195 @@
|
|
|
1
|
-
import type { Component, DeepReadonly, Ref, WatchStopHandle } from 'vue'
|
|
2
|
-
import type { z, AnyZodObject, ZodEffects,
|
|
1
|
+
import type { Component, DeepReadonly, Ref, RendererElement, RendererNode, VNode, WatchStopHandle } from 'vue'
|
|
2
|
+
import type { z, AnyZodObject, ZodEffects, ZodOptional, ZodTypeAny, RefinementCtx } from 'zod'
|
|
3
3
|
import type { IgnoredUpdater } from '@vueuse/core'
|
|
4
4
|
import type { FormFieldType, FormStatus } from './enums'
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
type Depth = [never, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10] // Adjust the depth limit as needed
|
|
7
|
+
|
|
8
|
+
type DecrementDepth<D extends Depth[number]> = Depth[D]
|
|
9
|
+
|
|
10
|
+
export type EffectType<T extends ZodTypeAny, D extends Depth[number] = 10>
|
|
11
|
+
= D extends 0
|
|
12
|
+
? T
|
|
13
|
+
: T | ZodOptional<T> | ZodEffects<EffectType<T, DecrementDepth<D>>>
|
|
14
|
+
|
|
15
|
+
export type FormSchema = EffectType<AnyZodObject>
|
|
10
16
|
|
|
11
17
|
export type FormFieldComponentOptions = {
|
|
12
|
-
|
|
13
|
-
|
|
18
|
+
lazyLoad?: boolean
|
|
19
|
+
sideEffects?: (type: `${FormFieldType}`) => Promise<void> | void
|
|
14
20
|
}
|
|
15
21
|
|
|
16
|
-
export type FormComponentOptions<Schema> = {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
22
|
+
export type FormComponentOptions<Schema, Type> = {
|
|
23
|
+
updateThrottle?: number
|
|
24
|
+
continuousValidation?: boolean
|
|
25
|
+
readonly?: boolean
|
|
26
|
+
template?: Schema extends FormSchema ? FormTemplate<Schema, Type> : never
|
|
27
|
+
class?: Schema extends FormSchema ? new (data?: Partial<z.infer<Schema>>) => Type : never
|
|
28
|
+
onUpdate?: Schema extends FormSchema
|
|
29
|
+
? (data?: undefined extends Type ? Partial<z.infer<Schema>> : Type) => void
|
|
30
|
+
: never
|
|
31
|
+
onSubmit?: Schema extends FormSchema
|
|
32
|
+
? (data?: undefined extends Type ? Partial<z.infer<Schema>> : Type) => void
|
|
33
|
+
: never
|
|
34
|
+
onReset?: Schema extends FormSchema ? (data?: undefined extends Type ? Partial<z.infer<Schema>> : Type) => void : never
|
|
35
|
+
onInvalid?: Schema extends FormSchema
|
|
36
|
+
? (error?: z.inferFormattedError<Schema>) => void
|
|
37
|
+
: never
|
|
38
|
+
onValid?: Schema extends FormSchema
|
|
39
|
+
? (data?: undefined extends Type ? Partial<z.infer<Schema>> : Type) => void
|
|
40
|
+
: never
|
|
33
41
|
}
|
|
34
42
|
|
|
35
|
-
export type FormComposableOptions<Schema> = FormFieldComponentOptions
|
|
36
|
-
|
|
43
|
+
export type FormComposableOptions<Schema, Type> = FormFieldComponentOptions
|
|
44
|
+
& FormComponentOptions<Schema, Type> & {
|
|
45
|
+
scope?: string
|
|
46
|
+
}
|
|
37
47
|
|
|
38
|
-
type FormPluginOptionsSchema = {
|
|
39
|
-
|
|
48
|
+
type FormPluginOptionsSchema<T = Partial<z.infer<FormSchema>>> = {
|
|
49
|
+
schema?: FormSchema
|
|
50
|
+
factory?: (data?: Partial<z.infer<FormSchema>>) => T
|
|
40
51
|
}
|
|
41
52
|
|
|
42
|
-
export type FormPluginOptions = FormPluginOptionsSchema
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
export type InjectedFormData<Schema extends FormSchema> = {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
53
|
+
export type FormPluginOptions = FormPluginOptionsSchema
|
|
54
|
+
& FormComposableOptions<FormPluginOptionsSchema['schema'], FormPluginOptionsSchema['factory']>
|
|
55
|
+
|
|
56
|
+
export type InjectedFormData<Schema extends FormSchema, Type> = {
|
|
57
|
+
formData: Ref<(undefined extends Type ? Partial<z.infer<Schema>> : Type) | undefined>
|
|
58
|
+
errors: Readonly<
|
|
59
|
+
Ref<DeepReadonly<z.inferFormattedError<Schema>> | undefined>
|
|
60
|
+
>
|
|
61
|
+
submit: () => Promise<boolean>
|
|
62
|
+
validate: (formData?: undefined extends Type ? Partial<z.infer<Schema>> : Type, options?: { fields?: Set<Path<z.infer<Schema>>>, superRefine?: (arg: z.infer<Schema>, ctx: RefinementCtx) => void | Promise<void> }) => Promise<boolean>
|
|
63
|
+
clear: () => void
|
|
64
|
+
reset: () => void
|
|
65
|
+
ignoreUpdates: IgnoredUpdater
|
|
66
|
+
stopUpdatesWatch: WatchStopHandle
|
|
67
|
+
status: Readonly<Ref<FormStatus | undefined>>
|
|
68
|
+
invalid: Readonly<Ref<boolean>>
|
|
69
|
+
readonly: Ref<boolean>
|
|
70
|
+
wrappers: Map<string, InjectedFormWrapperData<Schema>>
|
|
57
71
|
}
|
|
58
72
|
|
|
59
73
|
export type InjectedFormWrapperData<Schema extends FormSchema> = {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
74
|
+
name: Readonly<Ref<string>>
|
|
75
|
+
errors: Ref<Map<string, z.inferFormattedError<Schema>>>
|
|
76
|
+
invalid: Readonly<Ref<boolean>>
|
|
77
|
+
readonly: Readonly<Ref<boolean>>
|
|
78
|
+
fields: Ref<Map<string, string>>
|
|
63
79
|
}
|
|
64
80
|
|
|
65
81
|
export type InjectedFormFieldData<Schema extends FormSchema> = {
|
|
66
|
-
|
|
67
|
-
|
|
82
|
+
name: Readonly<Ref<Path<z.infer<Schema>>>>
|
|
83
|
+
errors: Readonly<Ref<DeepReadonly<z.inferFormattedError<Schema>>>>
|
|
68
84
|
}
|
|
69
85
|
|
|
70
|
-
export type
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
86
|
+
export type InjectedFormFieldsGroupData<Schema extends FormSchema> = {
|
|
87
|
+
names: DeepReadonly<Ref<Path<z.infer<Schema>>[]>>
|
|
88
|
+
errors: Readonly<Ref<DeepReadonly<Record<string, z.inferFormattedError<Schema>> | undefined>>>
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export type Primitive
|
|
92
|
+
= | null
|
|
93
|
+
| undefined
|
|
94
|
+
| string
|
|
95
|
+
| number
|
|
96
|
+
| boolean
|
|
97
|
+
| symbol
|
|
98
|
+
| bigint
|
|
78
99
|
|
|
79
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
80
100
|
type IsTuple<T extends readonly any[]> = number extends T['length']
|
|
81
|
-
|
|
82
|
-
|
|
101
|
+
? false
|
|
102
|
+
: true
|
|
83
103
|
|
|
84
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
85
104
|
type TupleKeys<T extends readonly any[]> = Exclude<keyof T, keyof any[]>
|
|
86
105
|
|
|
87
106
|
export type PathConcat<
|
|
88
|
-
|
|
89
|
-
|
|
107
|
+
TKey extends string | number,
|
|
108
|
+
TValue,
|
|
90
109
|
> = TValue extends Primitive ? `${TKey}` : `${TKey}` | `${TKey}.${Path<TValue>}`
|
|
91
110
|
|
|
92
111
|
export type Path<T> = T extends readonly (infer V)[]
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
112
|
+
? IsTuple<T> extends true
|
|
113
|
+
? {
|
|
114
|
+
[K in TupleKeys<T>]-?: PathConcat<K & string, T[K]>
|
|
115
|
+
}[TupleKeys<T>]
|
|
116
|
+
: PathConcat<number, V>
|
|
117
|
+
: {
|
|
118
|
+
[K in keyof T]-?: PathConcat<K & string, T[K]>
|
|
119
|
+
}[keyof T]
|
|
120
|
+
|
|
103
121
|
export type PathValue<T, TPath extends Path<T> | Path<T>[]> = T extends any
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
export type AnyBoolean<Schema extends FormSchema>
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
export type SimpleFormTemplateItem<Schema extends FormSchema> = Record<
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
any
|
|
122
|
+
? TPath extends `${infer K}.${infer R}`
|
|
123
|
+
? K extends keyof T
|
|
124
|
+
? R extends Path<T[K]>
|
|
125
|
+
? undefined extends T[K]
|
|
126
|
+
? PathValue<T[K], R> | undefined
|
|
127
|
+
: PathValue<T[K], R>
|
|
128
|
+
: never
|
|
129
|
+
: K extends `${number}`
|
|
130
|
+
? T extends readonly (infer V)[]
|
|
131
|
+
? PathValue<V, R & Path<V>>
|
|
132
|
+
: never
|
|
133
|
+
: never
|
|
134
|
+
: TPath extends keyof T
|
|
135
|
+
? T[TPath]
|
|
136
|
+
: TPath extends `${number}`
|
|
137
|
+
? T extends readonly (infer V)[]
|
|
138
|
+
? V
|
|
139
|
+
: never
|
|
140
|
+
: never
|
|
141
|
+
: never
|
|
142
|
+
|
|
143
|
+
export type AnyBoolean<Schema extends FormSchema, Type>
|
|
144
|
+
= | boolean
|
|
145
|
+
| Ref<boolean>
|
|
146
|
+
| ((data?: InjectedFormData<Schema, Type>) => boolean | Ref<boolean>)
|
|
147
|
+
|
|
148
|
+
export type SimpleFormTemplateItem<Schema extends FormSchema, Type> = Record<
|
|
149
|
+
string,
|
|
150
|
+
any
|
|
134
151
|
> & {
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
152
|
+
vvIs?: string | Component
|
|
153
|
+
vvName?: Path<z.infer<Schema>>
|
|
154
|
+
vvSlots?: Record<string, any>
|
|
155
|
+
vvChildren?:
|
|
156
|
+
| Array<
|
|
157
|
+
| SimpleFormTemplateItem<Schema, Type>
|
|
158
|
+
| ((
|
|
159
|
+
data?: InjectedFormData<Schema, Type>,
|
|
160
|
+
scope?: Record<string, unknown>,
|
|
161
|
+
) => SimpleFormTemplateItem<Schema, Type>)
|
|
162
|
+
>
|
|
163
|
+
| ((
|
|
164
|
+
data?: InjectedFormData<Schema, Type>,
|
|
165
|
+
scope?: Record<string, unknown>,
|
|
166
|
+
) => Array<
|
|
167
|
+
| SimpleFormTemplateItem<Schema, Type>
|
|
168
|
+
| ((
|
|
169
|
+
data?: InjectedFormData<Schema, Type>,
|
|
170
|
+
scope?: Record<string, unknown>,
|
|
171
|
+
) => SimpleFormTemplateItem<Schema, Type>)
|
|
172
|
+
>)
|
|
173
|
+
vvIf?: AnyBoolean<Schema, Type> | Path<z.infer<Schema>>
|
|
174
|
+
vvElseIf?: AnyBoolean<Schema, Type> | Path<z.infer<Schema>>
|
|
175
|
+
vvType?: `${FormFieldType}`
|
|
176
|
+
vvShowValid?: boolean
|
|
177
|
+
vvContent?: string
|
|
178
|
+
vvDefaultValue?: any
|
|
150
179
|
}
|
|
151
180
|
|
|
152
|
-
export type FormTemplateItem<Schema extends FormSchema
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
181
|
+
export type FormTemplateItem<Schema extends FormSchema, Type = undefined>
|
|
182
|
+
= | SimpleFormTemplateItem<Schema, Type>
|
|
183
|
+
| ((
|
|
184
|
+
data?: InjectedFormData<Schema, Type>,
|
|
185
|
+
scope?: Record<string, unknown>,
|
|
186
|
+
) => SimpleFormTemplateItem<Schema, Type>)
|
|
187
|
+
|
|
188
|
+
export type FormTemplate<Schema extends FormSchema, Type = undefined>
|
|
189
|
+
= | FormTemplateItem<Schema, Type>[]
|
|
190
|
+
| ((
|
|
191
|
+
data?: InjectedFormData<Schema, Type>,
|
|
192
|
+
scope?: Record<string, unknown>,
|
|
193
|
+
) => FormTemplateItem<Schema, Type>[])
|
|
194
|
+
|
|
195
|
+
export type RenderFunctionOutput = VNode<RendererNode, RendererElement, { [key: string]: any }>
|