@movk/nuxt 1.1.1 → 1.2.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/README.md +5 -29
- package/dist/module.d.mts +3 -31
- package/dist/module.json +3 -3
- package/dist/module.mjs +135 -77
- package/dist/runtime/auto-form/controls.d.ts +221 -0
- package/dist/runtime/auto-form/controls.js +70 -0
- package/dist/runtime/{utils → auto-form}/field-utils.d.ts +4 -20
- package/dist/runtime/{utils → auto-form}/field-utils.js +1 -2
- package/dist/runtime/auto-form/metadata.d.ts +22 -0
- package/dist/runtime/auto-form/metadata.js +53 -0
- package/dist/runtime/auto-form/provider.d.ts +27 -0
- package/dist/runtime/{internal/useAutoFormProvider.js → auto-form/provider.js} +1 -1
- package/dist/runtime/{utils → auto-form}/reactive-utils.d.ts +4 -22
- package/dist/runtime/{utils → auto-form}/schema-introspector.d.ts +3 -9
- package/dist/runtime/{utils → auto-form}/schema-introspector.js +11 -9
- package/dist/runtime/components/AutoForm.d.vue.ts +4 -5
- package/dist/runtime/components/AutoForm.vue +12 -35
- package/dist/runtime/components/AutoForm.vue.d.ts +4 -5
- package/dist/runtime/components/ColorChooser.d.vue.ts +10 -6
- package/dist/runtime/components/ColorChooser.vue +4 -7
- package/dist/runtime/components/ColorChooser.vue.d.ts +10 -6
- package/dist/runtime/components/DatePicker.d.vue.ts +16 -10
- package/dist/runtime/components/DatePicker.vue.d.ts +16 -10
- package/dist/runtime/components/SearchForm.d.vue.ts +171 -0
- package/dist/runtime/components/SearchForm.vue +216 -0
- package/dist/runtime/components/SearchForm.vue.d.ts +171 -0
- package/dist/runtime/components/SlideVerify.d.vue.ts +5 -32
- package/dist/runtime/components/SlideVerify.vue +4 -4
- package/dist/runtime/components/SlideVerify.vue.d.ts +5 -32
- package/dist/runtime/components/StarRating.d.vue.ts +8 -16
- package/dist/runtime/components/StarRating.vue +50 -65
- package/dist/runtime/components/StarRating.vue.d.ts +8 -16
- package/dist/runtime/components/auto-form-renderer/AutoFormRendererArray.d.vue.ts +10 -2
- package/dist/runtime/components/auto-form-renderer/AutoFormRendererArray.vue +16 -23
- package/dist/runtime/components/auto-form-renderer/AutoFormRendererArray.vue.d.ts +10 -2
- package/dist/runtime/components/auto-form-renderer/AutoFormRendererChildren.d.vue.ts +26 -0
- package/dist/runtime/components/auto-form-renderer/AutoFormRendererChildren.vue +50 -0
- package/dist/runtime/components/auto-form-renderer/AutoFormRendererChildren.vue.d.ts +26 -0
- package/dist/runtime/components/auto-form-renderer/AutoFormRendererField.d.vue.ts +8 -2
- package/dist/runtime/components/auto-form-renderer/AutoFormRendererField.vue +2 -2
- package/dist/runtime/components/auto-form-renderer/AutoFormRendererField.vue.d.ts +8 -2
- package/dist/runtime/components/auto-form-renderer/AutoFormRendererLayout.d.vue.ts +8 -2
- package/dist/runtime/components/auto-form-renderer/AutoFormRendererLayout.vue +29 -64
- package/dist/runtime/components/auto-form-renderer/AutoFormRendererLayout.vue.d.ts +8 -2
- package/dist/runtime/components/auto-form-renderer/AutoFormRendererNested.d.vue.ts +8 -2
- package/dist/runtime/components/auto-form-renderer/AutoFormRendererNested.vue +15 -69
- package/dist/runtime/components/auto-form-renderer/AutoFormRendererNested.vue.d.ts +8 -2
- package/dist/runtime/components/input/AsPhoneNumberInput.d.vue.ts +36 -0
- package/dist/runtime/components/input/AsPhoneNumberInput.vue +35 -0
- package/dist/runtime/components/input/AsPhoneNumberInput.vue.d.ts +36 -0
- package/dist/runtime/components/input/WithCharacterLimit.d.vue.ts +17 -9
- package/dist/runtime/components/input/WithCharacterLimit.vue +5 -5
- package/dist/runtime/components/input/WithCharacterLimit.vue.d.ts +17 -9
- package/dist/runtime/components/input/WithClear.d.vue.ts +13 -9
- package/dist/runtime/components/input/WithClear.vue +2 -2
- package/dist/runtime/components/input/WithClear.vue.d.ts +13 -9
- package/dist/runtime/components/input/WithCopy.d.vue.ts +16 -10
- package/dist/runtime/components/input/WithCopy.vue +3 -3
- package/dist/runtime/components/input/WithCopy.vue.d.ts +16 -10
- package/dist/runtime/components/input/WithFloatingLabel.d.vue.ts +36 -0
- package/dist/runtime/components/input/WithFloatingLabel.vue +67 -0
- package/dist/runtime/components/input/WithFloatingLabel.vue.d.ts +36 -0
- package/dist/runtime/components/input/WithPasswordToggle.d.vue.ts +11 -9
- package/dist/runtime/components/input/WithPasswordToggle.vue +3 -3
- package/dist/runtime/components/input/WithPasswordToggle.vue.d.ts +11 -9
- package/dist/runtime/components/theme-picker/ThemePicker.d.vue.ts +1 -1
- package/dist/runtime/components/theme-picker/ThemePicker.vue +19 -25
- package/dist/runtime/components/theme-picker/ThemePicker.vue.d.ts +1 -1
- package/dist/runtime/components/theme-picker/ThemePickerButton.d.vue.ts +1 -7
- package/dist/runtime/components/theme-picker/ThemePickerButton.vue.d.ts +1 -7
- package/dist/runtime/composables/index.d.ts +8 -0
- package/dist/runtime/composables/index.js +8 -0
- package/dist/runtime/composables/useApiFetch.d.ts +17 -14
- package/dist/runtime/composables/useApiFetch.js +3 -28
- package/dist/runtime/composables/useAutoForm.d.ts +14 -98
- package/dist/runtime/composables/useAutoForm.js +37 -157
- package/dist/runtime/composables/useClientApiFetch.d.ts +5 -6
- package/dist/runtime/composables/useDownloadWithProgress.js +5 -6
- package/dist/runtime/composables/useLazyApiFetch.d.ts +18 -0
- package/dist/runtime/composables/useLazyApiFetch.js +4 -0
- package/dist/runtime/composables/useTheme.d.ts +17 -14
- package/dist/runtime/composables/useTheme.js +68 -72
- package/dist/runtime/composables/useUploadWithProgress.d.ts +2 -2
- package/dist/runtime/composables/useUploadWithProgress.js +7 -7
- package/dist/runtime/constants/api-defaults.d.ts +9 -0
- package/dist/runtime/constants/api-defaults.js +32 -0
- package/dist/runtime/constants/auto-form.d.ts +0 -2
- package/dist/runtime/constants/auto-form.js +0 -25
- package/dist/runtime/constants/grid-cols.d.ts +7 -0
- package/dist/runtime/constants/grid-cols.js +44 -0
- package/dist/runtime/plugins/api.factory.js +78 -121
- package/dist/runtime/plugins/theme.js +44 -64
- package/dist/runtime/style.css +1 -1
- package/dist/runtime/types/api.d.ts +277 -146
- package/dist/runtime/types/auto-form.d.ts +122 -411
- package/dist/runtime/types/index.d.ts +3 -2
- package/dist/runtime/types/index.js +3 -2
- package/dist/runtime/types/module.d.ts +96 -0
- package/dist/runtime/types/theme.d.ts +2 -0
- package/dist/runtime/types/zod.d.ts +11 -10
- package/dist/runtime/utils/api-utils.d.ts +27 -48
- package/dist/runtime/utils/api-utils.js +18 -47
- package/dist/runtime/utils/meta.d.ts +7 -0
- package/dist/runtime/utils/meta.js +16 -0
- package/dist/types.d.mts +6 -2
- package/package.json +68 -37
- package/dist/runtime/composables/useApiAuth.d.ts +0 -47
- package/dist/runtime/composables/useApiAuth.js +0 -66
- package/dist/runtime/internal/useAutoFormProvider.d.ts +0 -50
- package/dist/runtime/schemas/api.d.ts +0 -590
- package/dist/runtime/schemas/api.js +0 -228
- package/dist/runtime/server/api/_movk/session.post.d.ts +0 -10
- package/dist/runtime/server/api/_movk/session.post.js +0 -18
- package/dist/runtime/types/auth.d.ts +0 -34
- package/dist/runtime/types/auto-form-renderer.d.ts +0 -22
- package/dist/runtime/types/components.d.ts +0 -43
- package/dist/runtime/utils/auto-form.d.ts +0 -3
- package/dist/runtime/utils/auto-form.js +0 -18
- /package/dist/runtime/{utils → auto-form}/reactive-utils.js +0 -0
- /package/dist/runtime/types/{auto-form-renderer.js → module.js} +0 -0
- /package/dist/runtime/types/{components.js → theme.js} +0 -0
|
@@ -1,69 +1,34 @@
|
|
|
1
1
|
import type { CollapsibleRootProps, DateRange } from 'reka-ui';
|
|
2
|
-
import type { ClassNameValue } from '
|
|
3
|
-
import type { z } from 'zod
|
|
4
|
-
import type { ArrayFieldKeys, ComponentProps,
|
|
2
|
+
import type { ClassNameValue } from './theme.js';
|
|
3
|
+
import type { z } from 'zod';
|
|
4
|
+
import type { ArrayFieldKeys, ComponentProps, ComponentSlots, GetFieldValue, IsAny, IsComponent, KnownKeys, NonObjectFieldKeys, ObjectFieldKeys, Prettify, ReactiveValue, UnionToIntersection, WidenLiteral } from '@movk/core';
|
|
5
5
|
import type { FormError } from '@nuxt/ui';
|
|
6
6
|
import type { AUTOFORM_META } from '../constants/auto-form.js';
|
|
7
7
|
import type { CalendarDate, DateValue, Time } from '@internationalized/date';
|
|
8
8
|
import type { ZodAutoFormFieldMeta } from './zod.js';
|
|
9
9
|
type FieldValueType<S, P extends string> = P extends string ? (string extends P ? S[keyof S] : GetFieldValue<S, P>) : S[keyof S];
|
|
10
10
|
type NonUndefinedFieldValue<S, P extends string> = Exclude<FieldValueType<S, P>, undefined>;
|
|
11
|
-
/**
|
|
12
|
-
* 相对路径类型 - 根据字段值类型自动推断可用路径
|
|
13
|
-
* @template T - 字段值类型
|
|
14
|
-
* @description
|
|
15
|
-
* - 对象类型:返回对象的键('name' | 'email' | 'bio')
|
|
16
|
-
* - 数组类型:返回 string(支持任意索引路径如 '[0].title')
|
|
17
|
-
*/
|
|
18
11
|
type RelativePath<T> = T extends readonly any[] ? string : T extends Record<string, any> ? Extract<keyof T, string> : string;
|
|
19
|
-
/**
|
|
20
|
-
* 表单字段上下文
|
|
21
|
-
* @template S - 表单数据类型
|
|
22
|
-
* @template P - 字段路径
|
|
23
|
-
*/
|
|
24
12
|
export interface AutoFormFieldContext<S = any, P extends string = string> {
|
|
25
|
-
/** 表单数据 */
|
|
26
13
|
readonly state: S;
|
|
27
|
-
/** 字段路径 */
|
|
28
14
|
readonly path: P;
|
|
29
|
-
/** 字段值(可能为 undefined) */
|
|
30
15
|
readonly value: FieldValueType<S, P>;
|
|
31
16
|
/**
|
|
32
|
-
* 设置字段值的回调函数
|
|
33
|
-
* @description 支持多种调用方式:
|
|
34
|
-
* 1. setValue(value) - 设置当前字段的整个值
|
|
35
|
-
* 2. setValue(key, value) - 设置子字段值(对象)或元素属性(数组)
|
|
36
|
-
* 3. setValue(path, value) - 设置任意路径的值(字符串回退)
|
|
37
17
|
* @example
|
|
38
|
-
* // 对象字段 profile: { name, email, bio }
|
|
39
18
|
* setValue({ name: '张三', email: 'test@example.com' }) // 设置整个对象
|
|
40
|
-
* setValue('name', '张三') // key
|
|
41
|
-
*
|
|
42
|
-
* // 数组字段 tasks: [{ title, priority, completed }]
|
|
43
|
-
* setValue([...tasks, newTask]) // 设置整个数组
|
|
44
|
-
* setValue('[0].title', '新标题') // 使用索引路径字符串
|
|
45
|
-
*
|
|
46
|
-
* // 或者在遍历中直接使用属性名(推荐)
|
|
47
|
-
* v-for="(task, index) in tasks"
|
|
48
|
-
* setValue(`[${index}].title`, value) // 动态索引
|
|
19
|
+
* setValue('name', '张三') // key 自动推断
|
|
20
|
+
* setValue('[0].title', '新标题') // 数组索引路径
|
|
49
21
|
*/
|
|
50
22
|
setValue: {
|
|
51
23
|
(value: FieldValueType<S, P>): void;
|
|
52
24
|
<K extends RelativePath<NonUndefinedFieldValue<S, P>>>(relativePath: K extends never ? string : K, value: any): void;
|
|
53
25
|
(relativePath: string, value: any): void;
|
|
54
26
|
};
|
|
55
|
-
/** 字段错误列表 */
|
|
56
27
|
readonly errors: unknown[];
|
|
57
|
-
/** 表单提交加载状态 */
|
|
58
28
|
readonly loading: boolean;
|
|
59
|
-
/** 字段折叠状态 */
|
|
60
29
|
readonly open?: boolean;
|
|
61
|
-
/** 数组元素下标 */
|
|
62
30
|
readonly count?: number;
|
|
63
31
|
}
|
|
64
|
-
/**
|
|
65
|
-
* 表单字段插槽定义 - 支持自定义渲染各个部分
|
|
66
|
-
*/
|
|
67
32
|
export interface AutoFormFieldSlots {
|
|
68
33
|
label: (props: {
|
|
69
34
|
label?: string;
|
|
@@ -84,465 +49,211 @@ export interface AutoFormFieldSlots {
|
|
|
84
49
|
error?: boolean | string;
|
|
85
50
|
} & AutoFormFieldContext) => unknown;
|
|
86
51
|
}
|
|
87
|
-
|
|
88
|
-
type
|
|
89
|
-
label
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
52
|
+
/** 插槽附加 props 查找表 */
|
|
53
|
+
type SlotExtraPropsMap = {
|
|
54
|
+
label: {
|
|
55
|
+
label?: string;
|
|
56
|
+
};
|
|
57
|
+
hint: {
|
|
58
|
+
hint?: string;
|
|
59
|
+
};
|
|
60
|
+
description: {
|
|
61
|
+
description?: string;
|
|
62
|
+
};
|
|
63
|
+
help: {
|
|
64
|
+
help?: string;
|
|
65
|
+
};
|
|
66
|
+
error: {
|
|
67
|
+
error?: boolean | string;
|
|
68
|
+
};
|
|
69
|
+
default: {
|
|
70
|
+
error?: boolean | string;
|
|
71
|
+
};
|
|
104
72
|
};
|
|
105
73
|
/**
|
|
106
74
|
* 动态表单插槽类型
|
|
107
|
-
* @template T - 表单数据类型
|
|
108
75
|
*
|
|
109
76
|
* 插槽命名:
|
|
110
77
|
* - 通用:`field-{slotType}`
|
|
111
|
-
* - 字段:`field-{slotType}:{fieldKey}`
|
|
78
|
+
* - 字段:`field-{slotType}:{fieldKey}` — 精确推导字段类型
|
|
112
79
|
* - 嵌套:`field-{content|before|after}:{objectKey|arrayKey}`
|
|
113
80
|
*/
|
|
114
81
|
export type DynamicFormSlots<T> = Record<string, (props: AutoFormFieldContext<T>) => unknown> & {
|
|
115
|
-
[K in
|
|
116
|
-
} &
|
|
82
|
+
[K in keyof AutoFormFieldSlots as `field-${K}`]: (props: SlotExtraPropsMap[K] & AutoFormFieldContext<T>) => unknown;
|
|
83
|
+
} & {
|
|
84
|
+
[Key in `field-${keyof AutoFormFieldSlots}:${NonObjectFieldKeys<T> | ObjectFieldKeys<T>}`]: Key extends `field-${infer K extends keyof AutoFormFieldSlots}:${infer P extends string & (NonObjectFieldKeys<T> | ObjectFieldKeys<T>)}` ? (props: SlotExtraPropsMap[K] & AutoFormFieldContext<T, P>) => unknown : never;
|
|
85
|
+
} & {
|
|
117
86
|
[P in ObjectFieldKeys<T> | ArrayFieldKeys<T> as `field-${'content' | 'before' | 'after'}:${P}`]: (props: AutoFormFieldContext<T, P>) => unknown;
|
|
118
87
|
};
|
|
119
|
-
/**
|
|
120
|
-
* 表单级插槽属性
|
|
121
|
-
* @template T - 表单对象类型
|
|
122
|
-
*/
|
|
123
88
|
export interface AutoFormSlotProps<T extends object> {
|
|
124
|
-
/** 表单错误列表 */
|
|
125
89
|
errors: FormError[];
|
|
126
|
-
/** 表单提交加载状态 */
|
|
127
90
|
loading: boolean;
|
|
128
|
-
/** 字段配置列表 */
|
|
129
91
|
fields: AutoFormField[];
|
|
130
|
-
/** 表单当前状态 */
|
|
131
92
|
state: T;
|
|
132
93
|
}
|
|
133
|
-
/**
|
|
134
|
-
* 控件元数据统一模型 - 支持响应式属性
|
|
135
|
-
* @template C - 组件类型
|
|
136
|
-
*/
|
|
137
94
|
export interface AutoFormControlsMeta<C extends IsComponent = IsComponent> {
|
|
138
|
-
/** 控件类型(从注册的控件中选择) */
|
|
139
95
|
type?: string;
|
|
140
|
-
/** 控件组件(直接传入组件实例时使用) */
|
|
141
96
|
component?: C;
|
|
142
|
-
/** 控件属性(支持响应式函数) */
|
|
143
97
|
controlProps?: ReactiveValue<ComponentProps<C>, AutoFormFieldContext>;
|
|
144
|
-
/** 控件插槽(支持部分覆盖,支持响应式函数) */
|
|
145
98
|
controlSlots?: ReactiveValue<Partial<ComponentSlots<C>>, AutoFormFieldContext> | Record<string, unknown>;
|
|
146
|
-
/** Zod 验证错误消息 */
|
|
147
99
|
error?: string;
|
|
148
100
|
}
|
|
149
|
-
/**
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
export interface AutoFormControl<C extends IsComponent = IsComponent> {
|
|
154
|
-
/** 控件组件实例 */
|
|
101
|
+
/** 幻影类型哨兵:标记 P/S 未被覆写 */
|
|
102
|
+
export type _Unset = {
|
|
103
|
+
readonly __brand: 'AutoFormControlUnset';
|
|
104
|
+
};
|
|
105
|
+
export interface AutoFormControl<C extends IsComponent = IsComponent, _P = _Unset, _S = _Unset> {
|
|
155
106
|
component: C;
|
|
156
|
-
/** 控件静态属性 */
|
|
157
107
|
controlProps?: ComponentProps<C>;
|
|
158
|
-
/** 控件静态插槽 */
|
|
159
108
|
controlSlots?: Partial<ComponentSlots<C>>;
|
|
160
109
|
}
|
|
161
|
-
|
|
162
|
-
* 控件注册表类型 - 字符串键映射到控件配置
|
|
163
|
-
*/
|
|
164
|
-
export type AutoFormControls = Record<string, AutoFormControl>;
|
|
165
|
-
/**
|
|
166
|
-
* 自动表单布局配置 - 支持自定义布局容器
|
|
167
|
-
* @template C - 布局组件类型
|
|
168
|
-
*/
|
|
110
|
+
export type AutoFormControls = Record<string, AutoFormControl<any, any, any>>;
|
|
169
111
|
export interface AutoFormLayoutConfig<C extends IsComponent = IsComponent> {
|
|
170
|
-
/** 布局容器组件 */
|
|
171
112
|
component?: C;
|
|
172
|
-
/** 布局组件属性(根据组件类型自动推断,支持响应式) */
|
|
173
113
|
props?: ReactiveValue<ComponentProps<C>, AutoFormFieldContext>;
|
|
174
|
-
/** 布局组件 CSS 类名(支持响应式) */
|
|
175
114
|
class?: ReactiveValue<ClassNameValue, AutoFormFieldContext>;
|
|
176
|
-
/** 布局组件插槽(根据组件类型自动推断,支持响应式) */
|
|
177
115
|
slots?: ReactiveValue<Partial<ComponentSlots<C>>, AutoFormFieldContext>;
|
|
178
|
-
/** 布局内的字段定义(类似 z.object() 的 shape) */
|
|
179
116
|
fields: Record<string, z.ZodType>;
|
|
180
|
-
/** 所有字段统一渲染到的插槽名称(支持响应式) */
|
|
181
117
|
fieldSlot?: ReactiveValue<keyof ComponentSlots<C> & string, AutoFormFieldContext>;
|
|
182
|
-
/** 字段到插槽的映射关系(支持响应式,优先级高于 fieldSlot) */
|
|
183
118
|
fieldSlots?: ReactiveValue<Partial<Record<string, keyof ComponentSlots<C> & string>>, AutoFormFieldContext>;
|
|
184
119
|
}
|
|
185
|
-
/**
|
|
186
|
-
* 合并后的元数据类型 - 包含全局元数据、控件元数据、布局和覆写
|
|
187
|
-
*/
|
|
188
120
|
export type AutoFormMergeMeta = ZodAutoFormFieldMeta & AutoFormControlsMeta & {
|
|
189
|
-
/** 已映射的控件实例(运行时生成) */
|
|
190
121
|
mapped?: AutoFormControl;
|
|
191
|
-
/** 布局配置 */
|
|
192
122
|
layout?: AutoFormLayoutConfig;
|
|
193
|
-
/** 覆写元数据(优先级最高) */
|
|
194
123
|
overwrite?: AutoFormControlsMeta;
|
|
195
124
|
};
|
|
196
|
-
/**
|
|
197
|
-
* 自动表单字段配置 - 描述单个表单字段的完整信息
|
|
198
|
-
*/
|
|
199
125
|
export interface AutoFormField {
|
|
200
|
-
/** 字段路径(点分隔符格式) */
|
|
201
126
|
path: string;
|
|
202
|
-
/** 字段的 Zod schema 定义 */
|
|
203
127
|
schema: z.ZodType;
|
|
204
|
-
/** 字段元数据(包含控件配置、布局等) */
|
|
205
128
|
meta: AutoFormMergeMeta;
|
|
206
|
-
/** 字段装饰器信息(可选性、只读、默认值等) */
|
|
207
129
|
decorators: {
|
|
208
|
-
/** 是否为可选字段 */
|
|
209
130
|
isOptional?: boolean;
|
|
210
|
-
/** 是否为只读字段 */
|
|
211
131
|
isReadonly?: boolean;
|
|
212
|
-
/** 默认值 */
|
|
213
132
|
defaultValue?: unknown;
|
|
214
|
-
/** 字段描述 */
|
|
215
133
|
description?: string;
|
|
216
134
|
};
|
|
217
|
-
/** 子字段列表(仅对象类型字段有效) */
|
|
218
135
|
children?: AutoFormField[];
|
|
219
|
-
/** 数组元素模板(仅数组类型字段有效) */
|
|
220
136
|
arrayElement?: AutoFormField;
|
|
221
137
|
}
|
|
222
|
-
/**
|
|
223
|
-
* 嵌套字段折叠配置 - 控制对象/数组字段的展开/收起行为
|
|
224
|
-
*/
|
|
225
138
|
export interface AutoFormNestedCollapsible extends Pick<CollapsibleRootProps, 'defaultOpen' | 'open' | 'disabled' | 'unmountOnHide'> {
|
|
226
|
-
/**
|
|
227
|
-
* 是否启用折叠功能
|
|
228
|
-
* @defaultValue true
|
|
229
|
-
* @description 当设置为 false 时将直接渲染内容,不使用折叠组件
|
|
230
|
-
*/
|
|
231
139
|
enabled?: boolean;
|
|
232
|
-
/**
|
|
233
|
-
* 渲染的元素或组件类型
|
|
234
|
-
* @defaultValue 'div'
|
|
235
|
-
*/
|
|
236
140
|
as?: unknown;
|
|
237
|
-
/** CSS 类名 */
|
|
238
141
|
class?: unknown;
|
|
239
|
-
/** UI 配置 */
|
|
240
142
|
ui?: {
|
|
241
|
-
/** 根元素类名 */
|
|
242
143
|
root?: ClassNameValue;
|
|
243
|
-
/** 内容区域类名 */
|
|
244
144
|
content?: ClassNameValue;
|
|
245
145
|
};
|
|
246
146
|
}
|
|
247
|
-
/**
|
|
248
|
-
* 提取对象的已知键(剔除索引签名)
|
|
249
|
-
* @template T - 源对象类型
|
|
250
|
-
*/
|
|
251
|
-
type KnownKeys<T> = {
|
|
252
|
-
[K in keyof T]-?: string extends K ? never : number extends K ? never : symbol extends K ? never : K;
|
|
253
|
-
}[keyof T];
|
|
254
|
-
type KeysOf<T> = Extract<keyof T, string>;
|
|
255
|
-
/**
|
|
256
|
-
* 提取控件类型键的简化类型
|
|
257
|
-
* @template TControls - 控件注册表类型
|
|
258
|
-
*/
|
|
259
|
-
type ControlTypeKey<TControls> = KnownKeys<TControls> & keyof TControls & string;
|
|
260
|
-
/**
|
|
261
|
-
* 排除 component 和 type 的控件元数据
|
|
262
|
-
* @template T - 组件类型
|
|
263
|
-
*/
|
|
264
|
-
type OmitControlMeta<T extends IsComponent> = OmitByKey<AutoFormControlsMeta<T>, 'component' | 'type'>;
|
|
265
|
-
/**
|
|
266
|
-
* 根据控件类型键获取对应的元数据类型
|
|
267
|
-
* @template TControls - 控件注册表类型
|
|
268
|
-
* @template K - 控件类型键
|
|
269
|
-
*/
|
|
270
|
-
type MetaByType<TControls, K extends keyof TControls> = TControls[K] extends AutoFormControl<infer C> ? OmitControlMeta<C> : OmitControlMeta<IsComponent>;
|
|
271
|
-
/**
|
|
272
|
-
* 根据 Zod 类型字符串获取对应的元数据类型
|
|
273
|
-
* @template TControls - 控件注册表类型
|
|
274
|
-
* @template TZod - Zod 类型名称
|
|
275
|
-
*/
|
|
276
|
-
type MetaByZod<TControls, TZod extends string> = TZod extends KnownKeys<TControls> ? TControls[TZod] extends AutoFormControl<infer C> ? OmitControlMeta<C> : OmitControlMeta<IsComponent> : OmitControlMeta<IsComponent>;
|
|
277
|
-
/**
|
|
278
|
-
* 联合类型转交叉类型
|
|
279
|
-
* @template U - 联合类型
|
|
280
|
-
* @description 此类型可能导致大型联合类型的性能问题,建议限制联合成员数量
|
|
281
|
-
*/
|
|
282
|
-
type UnionToIntersection<U> = (U extends unknown ? (k: U) => void : never) extends ((k: infer I) => void) ? I : never;
|
|
283
|
-
/**
|
|
284
|
-
* 布局标记类型 - 用于类型层面识别布局字段
|
|
285
|
-
* @template Fields - 布局内的字段定义
|
|
286
|
-
* @description 运行时会被替换为 ZodCustom,仅用于类型推导
|
|
287
|
-
*/
|
|
288
147
|
interface LayoutFieldMarker<Fields extends Record<string, z.ZodType>> extends z.ZodType<AutoFormLayoutConfig<any>, any, any> {
|
|
289
148
|
__brand: typeof AUTOFORM_META.LAYOUT_KEY;
|
|
290
149
|
fields: Fields;
|
|
291
150
|
}
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
*/
|
|
298
|
-
type ExtractLayoutShape<S extends Record<string, any>, Depth extends number[] = []> = Depth['length'] extends 5 ? S : {
|
|
299
|
-
[K in keyof S as S[K] extends LayoutFieldMarker<any> ? never : K]: S[K];
|
|
300
|
-
} & UnionToIntersection<{
|
|
301
|
-
[K in keyof S]: S[K] extends LayoutFieldMarker<infer F> ? ExtractLayoutShape<F, [...Depth, 1]> : {};
|
|
151
|
+
type LayoutRestShape<S extends Record<string, any>> = {
|
|
152
|
+
[P in keyof S as S[P] extends LayoutFieldMarker<any> ? never : P]: S[P];
|
|
153
|
+
};
|
|
154
|
+
type LayoutExpandedShape<S extends Record<string, any>> = UnionToIntersection<{
|
|
155
|
+
[P in keyof S]: S[P] extends LayoutFieldMarker<infer Fields> ? ExtractLayoutShape<Fields> : {};
|
|
302
156
|
}[keyof S]>;
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
type
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
157
|
+
type ExtractLayoutShape<S extends Record<string, any>> = LayoutRestShape<S> & LayoutExpandedShape<S>;
|
|
158
|
+
type StrictComponentProps<C extends IsComponent> = {
|
|
159
|
+
[K in keyof ComponentProps<C> as {} extends Record<K, unknown> ? never : K]: ComponentProps<C>[K];
|
|
160
|
+
};
|
|
161
|
+
type StrictComponentSlots<C extends IsComponent> = IsAny<ComponentSlots<C>> extends true ? {} : ComponentSlots<C>;
|
|
162
|
+
type ControlKey<TControls extends AutoFormControls> = Extract<KnownKeys<TControls>, string>;
|
|
163
|
+
type ControlEntryByKey<TControls extends AutoFormControls, K extends string> = K extends keyof TControls ? TControls[K] : never;
|
|
164
|
+
type _WidenForFactory<T> = {
|
|
165
|
+
[K in keyof T]+?: WidenLiteral<T[K]>;
|
|
166
|
+
};
|
|
167
|
+
type ResolveControlProps<C extends IsComponent, P> = [P] extends [_Unset] ? StrictComponentProps<C> : IsAny<P> extends true ? StrictComponentProps<C> : [unknown] extends [P] ? StrictComponentProps<C> : [keyof P] extends [never] ? StrictComponentProps<C> : Prettify<_WidenForFactory<P> & {}>;
|
|
168
|
+
type ExtractControlProps<T> = T extends AutoFormControl<infer C, infer P, any> ? ResolveControlProps<C, P> : T extends {
|
|
169
|
+
component: infer C extends IsComponent;
|
|
170
|
+
} ? StrictComponentProps<C> : {};
|
|
171
|
+
type ResolveControlSlots<C extends IsComponent, S> = [S] extends [_Unset] ? StrictComponentSlots<C> : IsAny<S> extends true ? StrictComponentSlots<C> : [unknown] extends [S] ? StrictComponentSlots<C> : [keyof S] extends [never] ? StrictComponentSlots<C> : S;
|
|
172
|
+
type ExtractControlSlots<T> = T extends AutoFormControl<infer C, any, infer S> ? ResolveControlSlots<C, S> : T extends {
|
|
173
|
+
component: infer C extends IsComponent;
|
|
174
|
+
} ? StrictComponentSlots<C> : {};
|
|
175
|
+
type FallbackToRecordIfEmpty<T> = [keyof T] extends [never] ? Record<string, unknown> : Prettify<T & {}>;
|
|
176
|
+
type ControlPropsByKey<TControls extends AutoFormControls, K extends ControlKey<TControls>> = FallbackToRecordIfEmpty<ExtractControlProps<ControlEntryByKey<TControls, K>>>;
|
|
177
|
+
type ControlSlotsByKey<TControls extends AutoFormControls, K extends ControlKey<TControls>> = Partial<ExtractControlSlots<ControlEntryByKey<TControls, K>>>;
|
|
178
|
+
type MetaPropsFor<TControls extends AutoFormControls, K extends ControlKey<TControls>> = {
|
|
179
|
+
controlProps?: ReactiveValue<ControlPropsByKey<TControls, K>, AutoFormFieldContext>;
|
|
180
|
+
controlSlots?: ReactiveValue<ControlSlotsByKey<TControls, K>, AutoFormFieldContext> | Record<string, unknown>;
|
|
181
|
+
error?: string;
|
|
182
|
+
};
|
|
183
|
+
type MetaByControlKey<TControls extends AutoFormControls, K extends ControlKey<TControls>> = {
|
|
184
|
+
type: K;
|
|
313
185
|
component?: never;
|
|
186
|
+
} & MetaPropsFor<TControls, K>;
|
|
187
|
+
type MetaByComponent<C extends IsComponent> = {
|
|
188
|
+
component: C;
|
|
314
189
|
type?: never;
|
|
315
|
-
} &
|
|
316
|
-
|
|
317
|
-
* 对象工厂元数据类型 - 带 type
|
|
318
|
-
*/
|
|
319
|
-
type ObjectMetaWithType<TC extends AutoFormControls, DFTC extends AutoFormControls, K extends ControlTypeKey<WithDefaultControls<TC, DFTC>>> = {
|
|
320
|
-
type: Suggest<K>;
|
|
190
|
+
} & Omit<AutoFormControlsMeta<C>, 'component' | 'type'>;
|
|
191
|
+
type MetaByDefaultIfExists<TControls extends AutoFormControls, TDefaultKey extends string> = TDefaultKey extends ControlKey<TControls> ? {
|
|
321
192
|
component?: never;
|
|
322
|
-
} & MetaByType<WithDefaultControls<TC, DFTC>, K>;
|
|
323
|
-
/**
|
|
324
|
-
* 对象工厂元数据类型 - 带 component
|
|
325
|
-
*/
|
|
326
|
-
type ObjectMetaWithComponent<C extends IsComponent> = {
|
|
327
|
-
component: C;
|
|
328
193
|
type?: never;
|
|
329
|
-
} &
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
<S extends Record<string, any>, K extends ControlTypeKey<WithDefaultControls<TC, DFTC>>>(shape: S & Partial<Record<KeysOf<T>, any>>, meta?: ObjectMetaWithType<TC, DFTC, K>): z.ZodObject<ExtractLayoutShape<S>, Mode>;
|
|
336
|
-
<S extends Record<string, any>, C extends IsComponent>(shape: S & Partial<Record<KeysOf<T>, any>>, meta?: ObjectMetaWithComponent<C>): z.ZodObject<ExtractLayoutShape<S>, Mode>;
|
|
194
|
+
} & MetaPropsFor<TControls, TDefaultKey> : never;
|
|
195
|
+
export type AutoFormFactoryMethod<TControls extends AutoFormControls, TResult, TDefaultKey extends string, TExtraArgs extends unknown[] = []> = {
|
|
196
|
+
<K extends ControlKey<TControls>>(...args: [...TExtraArgs, MetaByControlKey<TControls, K>]): TResult;
|
|
197
|
+
(...args: [...TExtraArgs, MetaByDefaultIfExists<TControls, TDefaultKey>]): TResult;
|
|
198
|
+
<C extends IsComponent>(...args: [...TExtraArgs, MetaByComponent<C>]): TResult;
|
|
199
|
+
(...args: [...TExtraArgs, string?]): TResult;
|
|
337
200
|
};
|
|
338
|
-
/**
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
<S extends Record<string,
|
|
343
|
-
<S extends Record<string, any>, K extends ControlTypeKey<WithDefaultControls<TC, DFTC>>>(shape: S, meta?: ObjectMetaWithType<TC, DFTC, K>): z.ZodObject<ExtractLayoutShape<S>, Mode>;
|
|
344
|
-
<S extends Record<string, any>, C extends IsComponent>(shape: S, meta?: ObjectMetaWithComponent<C>): z.ZodObject<ExtractLayoutShape<S>, Mode>;
|
|
201
|
+
/** 对象工厂重载 */
|
|
202
|
+
type ObjectFactoryOverloads<TControls extends AutoFormControls, Mode extends z.core.$strip | z.core.$loose | z.core.$strict, TDefaultKey extends string, ShapeConstraint = {}> = {
|
|
203
|
+
<S extends Record<string, z.ZodType>, K extends ControlKey<TControls>>(shape: S & ShapeConstraint, meta?: MetaByControlKey<TControls, K>): z.ZodObject<ExtractLayoutShape<S>, Mode>;
|
|
204
|
+
<S extends Record<string, z.ZodType>>(shape: S & ShapeConstraint, meta: MetaByDefaultIfExists<TControls, TDefaultKey>): z.ZodObject<ExtractLayoutShape<S>, Mode>;
|
|
205
|
+
<S extends Record<string, z.ZodType>, C extends IsComponent>(shape: S & ShapeConstraint, meta: MetaByComponent<C>): z.ZodObject<ExtractLayoutShape<S>, Mode>;
|
|
345
206
|
};
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
* 1. 传入错误消息字符串
|
|
355
|
-
* 2. 传入基础元数据对象
|
|
356
|
-
* 3. 传入带 type 的元数据(指定控件类型)
|
|
357
|
-
* 4. 传入带 component 的元数据(直接指定组件)
|
|
358
|
-
*/
|
|
359
|
-
export type AutoFormFactoryMethod<TControls, TZod extends string, TResult, TExtraParams extends unknown[] = []> = {
|
|
360
|
-
/** 调用方式 1: 仅传入错误消息或额外参数 */
|
|
361
|
-
(...args: [...TExtraParams, string?]): TResult;
|
|
362
|
-
/** 调用方式 2: 传入基础元数据(不指定 type 或 component) */
|
|
363
|
-
(...args: [...TExtraParams, ({
|
|
364
|
-
component?: never;
|
|
365
|
-
type?: never;
|
|
366
|
-
} & MetaByZod<TControls, TZod>)?]): TResult;
|
|
367
|
-
/** 调用方式 3: 传入带 type 的元数据 */
|
|
368
|
-
<K extends ControlTypeKey<TControls>>(...args: [...TExtraParams, ({
|
|
369
|
-
type: Suggest<K>;
|
|
370
|
-
component?: never;
|
|
371
|
-
} & MetaByType<TControls, K>)?]): TResult;
|
|
372
|
-
/** 调用方式 4: 传入带 component 的元数据 */
|
|
373
|
-
<C extends IsComponent>(...args: [...TExtraParams, ({
|
|
374
|
-
component: C;
|
|
375
|
-
type?: never;
|
|
376
|
-
} & OmitControlMeta<C>)?]): TResult;
|
|
377
|
-
};
|
|
378
|
-
/**
|
|
379
|
-
* 类型化的 Zod 工厂接口 - 提供类型安全的 schema 构建方法
|
|
380
|
-
* @template TC - 自定义控件注册表
|
|
381
|
-
* @template DFTC - 默认控件注册表
|
|
382
|
-
*
|
|
383
|
-
* @description 此接口提供了一套类型安全的 API 来构建 Zod schema,
|
|
384
|
-
* 支持自动推导控件类型和元数据,并与 AutoForm 无缝集成
|
|
385
|
-
*/
|
|
386
|
-
export interface TypedZodFactory<TC extends AutoFormControls, DFTC extends AutoFormControls> {
|
|
387
|
-
/** 字符串类型工厂 */
|
|
388
|
-
string: AutoFormFactoryMethod<WithDefaultControls<TC, DFTC>, 'string', z.ZodString>;
|
|
389
|
-
/** 数字类型工厂 */
|
|
390
|
-
number: AutoFormFactoryMethod<WithDefaultControls<TC, DFTC>, 'number', z.ZodNumber>;
|
|
391
|
-
/** 布尔类型工厂 */
|
|
392
|
-
boolean: AutoFormFactoryMethod<WithDefaultControls<TC, DFTC>, 'boolean', z.ZodBoolean>;
|
|
393
|
-
/** 文件类型工厂 */
|
|
394
|
-
file: AutoFormFactoryMethod<WithDefaultControls<TC, DFTC>, 'file', z.ZodType<File>>;
|
|
395
|
-
/** 电子邮件验证工厂 */
|
|
396
|
-
email: AutoFormFactoryMethod<WithDefaultControls<TC, DFTC>, 'string', z.ZodString>;
|
|
397
|
-
/** URL 验证工厂 */
|
|
398
|
-
url: AutoFormFactoryMethod<WithDefaultControls<TC, DFTC>, 'string', z.ZodString>;
|
|
399
|
-
/** UUID 验证工厂 */
|
|
400
|
-
uuid: AutoFormFactoryMethod<WithDefaultControls<TC, DFTC>, 'string', z.ZodString>;
|
|
401
|
-
/**
|
|
402
|
-
* 枚举类型工厂 - 支持字符串数组或枚举对象
|
|
403
|
-
* @description 重载顺序:空数组 > 字符串数组 > 枚举对象
|
|
404
|
-
*/
|
|
207
|
+
export interface TypedZodFactory<TControls extends AutoFormControls> {
|
|
208
|
+
string: AutoFormFactoryMethod<TControls, z.ZodString, 'string'>;
|
|
209
|
+
number: AutoFormFactoryMethod<TControls, z.ZodNumber, 'number'>;
|
|
210
|
+
boolean: AutoFormFactoryMethod<TControls, z.ZodBoolean, 'boolean'>;
|
|
211
|
+
file: AutoFormFactoryMethod<TControls, z.ZodType<File>, 'file'>;
|
|
212
|
+
email: AutoFormFactoryMethod<TControls, z.ZodString, 'string'>;
|
|
213
|
+
url: AutoFormFactoryMethod<TControls, z.ZodString, 'string'>;
|
|
214
|
+
uuid: AutoFormFactoryMethod<TControls, z.ZodString, 'string'>;
|
|
405
215
|
enum: {
|
|
406
|
-
(values: [], overwrite?:
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
<C extends IsComponent>(values:
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
<const T extends ReadonlyArray<string>>(values: T, overwrite?: MetaByZod<WithDefaultControls<TC, DFTC>, 'enum'>): z.ZodEnum<z.core.util.ToEnum<T[number]>>;
|
|
416
|
-
<const T extends ReadonlyArray<string>, K extends ControlTypeKey<WithDefaultControls<TC, DFTC>>>(values: T, overwrite?: {
|
|
417
|
-
type: Suggest<K>;
|
|
418
|
-
component?: never;
|
|
419
|
-
} & MetaByType<WithDefaultControls<TC, DFTC>, K>): z.ZodEnum<z.core.util.ToEnum<T[number]>>;
|
|
420
|
-
<const T extends ReadonlyArray<string>, C extends IsComponent>(values: T, overwrite?: {
|
|
421
|
-
component: C;
|
|
422
|
-
type?: never;
|
|
423
|
-
} & OmitControlMeta<C>): z.ZodEnum<z.core.util.ToEnum<T[number]>>;
|
|
424
|
-
<const T extends z.core.util.EnumLike>(values: T, overwrite?: MetaByZod<WithDefaultControls<TC, DFTC>, 'enum'>): z.ZodEnum<T>;
|
|
425
|
-
<const T extends z.core.util.EnumLike, K extends ControlTypeKey<WithDefaultControls<TC, DFTC>>>(values: T, overwrite?: {
|
|
426
|
-
type: Suggest<K>;
|
|
427
|
-
component?: never;
|
|
428
|
-
} & MetaByType<WithDefaultControls<TC, DFTC>, K>): z.ZodEnum<T>;
|
|
429
|
-
<const T extends z.core.util.EnumLike, C extends IsComponent>(values: T, overwrite?: {
|
|
430
|
-
component: C;
|
|
431
|
-
type?: never;
|
|
432
|
-
} & OmitControlMeta<C>): z.ZodEnum<T>;
|
|
216
|
+
<K extends ControlKey<TControls>>(values: [], overwrite?: MetaByControlKey<TControls, K>): z.ZodString;
|
|
217
|
+
(values: [], overwrite: MetaByDefaultIfExists<TControls, 'enum'>): z.ZodString;
|
|
218
|
+
<C extends IsComponent>(values: [], overwrite: MetaByComponent<C>): z.ZodString;
|
|
219
|
+
<const T extends readonly [string, ...string[]], K extends ControlKey<TControls>>(values: T, overwrite?: MetaByControlKey<TControls, K>): z.ZodEnum<z.core.util.ToEnum<T[number]>>;
|
|
220
|
+
<const T extends readonly [string, ...string[]]>(values: T, overwrite: MetaByDefaultIfExists<TControls, 'enum'>): z.ZodEnum<z.core.util.ToEnum<T[number]>>;
|
|
221
|
+
<const T extends readonly [string, ...string[]], C extends IsComponent>(values: T, overwrite: MetaByComponent<C>): z.ZodEnum<z.core.util.ToEnum<T[number]>>;
|
|
222
|
+
<const T extends z.core.util.EnumLike, K extends ControlKey<TControls>>(values: T, overwrite?: MetaByControlKey<TControls, K>): z.ZodEnum<T>;
|
|
223
|
+
<const T extends z.core.util.EnumLike>(values: T, overwrite: MetaByDefaultIfExists<TControls, 'enum'>): z.ZodEnum<T>;
|
|
224
|
+
<const T extends z.core.util.EnumLike, C extends IsComponent>(values: T, overwrite: MetaByComponent<C>): z.ZodEnum<T>;
|
|
433
225
|
};
|
|
434
|
-
/**
|
|
435
|
-
* 日期类型工厂 - 用于 DatePicker/Calendar
|
|
436
|
-
* 支持 CalendarDate、DateRange、CalendarDate[]
|
|
437
|
-
* @template T - 日期值类型(默认 CalendarDate)
|
|
438
|
-
*/
|
|
439
226
|
calendarDate: {
|
|
440
|
-
<T extends DateValue | DateRange | DateValue[] = CalendarDate>(meta?:
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
} & MetaByZod<WithDefaultControls<TC, DFTC>, 'date'>)): z.ZodType<T>;
|
|
444
|
-
<K extends ControlTypeKey<WithDefaultControls<TC, DFTC>>, T extends DateValue | DateRange | DateValue[] = CalendarDate>(meta?: {
|
|
445
|
-
type: Suggest<K>;
|
|
446
|
-
component?: never;
|
|
447
|
-
} & MetaByType<WithDefaultControls<TC, DFTC>, K>): z.ZodType<T>;
|
|
448
|
-
<C extends IsComponent, T extends DateValue | DateRange | DateValue[] = CalendarDate>(meta?: {
|
|
449
|
-
component: C;
|
|
450
|
-
type?: never;
|
|
451
|
-
} & OmitControlMeta<C>): z.ZodType<T>;
|
|
227
|
+
<T extends DateValue | DateRange | DateValue[] = CalendarDate, K extends ControlKey<TControls> = never>(meta?: MetaByControlKey<TControls, K>): z.ZodType<T>;
|
|
228
|
+
<T extends DateValue | DateRange | DateValue[] = CalendarDate>(meta: MetaByDefaultIfExists<TControls, 'calendarDate'>): z.ZodType<T>;
|
|
229
|
+
<C extends IsComponent, T extends DateValue | DateRange | DateValue[] = CalendarDate>(meta: MetaByComponent<C>): z.ZodType<T>;
|
|
452
230
|
};
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
/**
|
|
459
|
-
* 输入时间工厂 - 用于 UInputTime 组件
|
|
460
|
-
* 返回 Time 类型
|
|
461
|
-
*/
|
|
462
|
-
inputTime: AutoFormFactoryMethod<WithDefaultControls<TC, DFTC>, 'inputTime', z.ZodType<Time>>;
|
|
463
|
-
/**
|
|
464
|
-
* ISO 日期时间字符串工厂
|
|
465
|
-
* 验证 ISO 8601 格式(如 "2025-12-01T06:15:00Z")
|
|
466
|
-
*/
|
|
467
|
-
isoDatetime: AutoFormFactoryMethod<WithDefaultControls<TC, DFTC>, 'string', z.ZodType<string>>;
|
|
468
|
-
/**
|
|
469
|
-
* ISO 日期字符串工厂
|
|
470
|
-
* 验证 YYYY-MM-DD 格式(如 "2025-12-01")
|
|
471
|
-
*/
|
|
472
|
-
isoDate: AutoFormFactoryMethod<WithDefaultControls<TC, DFTC>, 'string', z.ZodType<string>>;
|
|
473
|
-
/**
|
|
474
|
-
* ISO 时间字符串工厂
|
|
475
|
-
* 验证 HH:MM[:SS[.s+]] 格式(如 "14:30:00")
|
|
476
|
-
*/
|
|
477
|
-
isoTime: AutoFormFactoryMethod<WithDefaultControls<TC, DFTC>, 'string', z.ZodType<string>>;
|
|
478
|
-
/**
|
|
479
|
-
* 数组类型工厂
|
|
480
|
-
* @template T - 数组元素的 Zod 类型
|
|
481
|
-
*/
|
|
231
|
+
inputDate: AutoFormFactoryMethod<TControls, z.ZodType<CalendarDate>, 'inputDate'>;
|
|
232
|
+
inputTime: AutoFormFactoryMethod<TControls, z.ZodType<Time>, 'inputTime'>;
|
|
233
|
+
isoDatetime: AutoFormFactoryMethod<TControls, z.ZodType<string>, 'string'>;
|
|
234
|
+
isoDate: AutoFormFactoryMethod<TControls, z.ZodType<string>, 'string'>;
|
|
235
|
+
isoTime: AutoFormFactoryMethod<TControls, z.ZodType<string>, 'string'>;
|
|
482
236
|
array: {
|
|
483
|
-
<T extends z.ZodType
|
|
484
|
-
<T extends z.ZodType,
|
|
485
|
-
|
|
486
|
-
component?: never;
|
|
487
|
-
} & MetaByType<WithDefaultControls<TC, DFTC>, K>): z.ZodArray<T>;
|
|
488
|
-
<T extends z.ZodType, C extends IsComponent>(schema: T, overwrite?: {
|
|
489
|
-
component: C;
|
|
490
|
-
type?: never;
|
|
491
|
-
} & OmitControlMeta<C>): z.ZodArray<T>;
|
|
237
|
+
<T extends z.ZodType, K extends ControlKey<TControls>>(schema: T, overwrite?: MetaByControlKey<TControls, K>): z.ZodArray<T>;
|
|
238
|
+
<T extends z.ZodType>(schema: T, overwrite: MetaByDefaultIfExists<TControls, 'array'>): z.ZodArray<T>;
|
|
239
|
+
<T extends z.ZodType, C extends IsComponent>(schema: T, overwrite: MetaByComponent<C>): z.ZodArray<T>;
|
|
492
240
|
};
|
|
493
|
-
/**
|
|
494
|
-
* 元组类型工厂
|
|
495
|
-
* @template T - 元组元素的 Zod 类型数组
|
|
496
|
-
*/
|
|
497
241
|
tuple: {
|
|
498
|
-
<T extends readonly [z.ZodType, ...z.ZodType[]]
|
|
499
|
-
<T extends readonly [z.ZodType, ...z.ZodType[]],
|
|
500
|
-
|
|
501
|
-
component?: never;
|
|
502
|
-
} & MetaByType<WithDefaultControls<TC, DFTC>, K>): z.ZodTuple<T>;
|
|
503
|
-
<T extends readonly [z.ZodType, ...z.ZodType[]], C extends IsComponent>(schemas: T, overwrite?: {
|
|
504
|
-
component: C;
|
|
505
|
-
type?: never;
|
|
506
|
-
} & OmitControlMeta<C>): z.ZodTuple<T>;
|
|
242
|
+
<T extends readonly [z.ZodType, ...z.ZodType[]], K extends ControlKey<TControls>>(schemas: T, overwrite?: MetaByControlKey<TControls, K>): z.ZodTuple<T>;
|
|
243
|
+
<T extends readonly [z.ZodType, ...z.ZodType[]]>(schemas: T, overwrite: MetaByDefaultIfExists<TControls, 'tuple'>): z.ZodTuple<T>;
|
|
244
|
+
<T extends readonly [z.ZodType, ...z.ZodType[]], C extends IsComponent>(schemas: T, overwrite: MetaByComponent<C>): z.ZodTuple<T>;
|
|
507
245
|
};
|
|
508
|
-
/**
|
|
509
|
-
* 布局工厂 - 创建表单布局容器
|
|
510
|
-
* @template C - 布局组件类型
|
|
511
|
-
* @template Fields - 布局内字段定义
|
|
512
|
-
* @returns 布局标记类型(运行时为 ZodCustom)
|
|
513
|
-
*/
|
|
514
246
|
layout: <C extends IsComponent = IsComponent, Fields extends Record<string, z.ZodType> = Record<string, z.ZodType>>(config: Omit<AutoFormLayoutConfig<C>, 'fields'> & {
|
|
515
247
|
fields: Fields;
|
|
516
248
|
}) => LayoutFieldMarker<Fields>;
|
|
517
|
-
/**
|
|
518
|
-
* 对象工厂 - 支持柯里化和直接调用
|
|
519
|
-
* @description
|
|
520
|
-
* - 柯里化: afz.object<State>()({ name: afz.string() }, { type: 'input' })
|
|
521
|
-
* - 直接调用: afz.object({ name: afz.string() }, { type: 'input' })
|
|
522
|
-
*/
|
|
523
249
|
object: {
|
|
524
|
-
<T extends object>():
|
|
525
|
-
|
|
526
|
-
<S extends Record<string, any>, K extends ControlTypeKey<WithDefaultControls<TC, DFTC>>>(shape: S, meta?: ObjectMetaWithType<TC, DFTC, K>): z.ZodObject<ExtractLayoutShape<S>, z.core.$strip>;
|
|
527
|
-
<S extends Record<string, any>, C extends IsComponent>(shape: S, meta?: ObjectMetaWithComponent<C>): z.ZodObject<ExtractLayoutShape<S>, z.core.$strip>;
|
|
528
|
-
} & ObjectFactoryDirect<TC, DFTC, z.core.$strip>;
|
|
529
|
-
/**
|
|
530
|
-
* 松散对象工厂 - 允许额外属性
|
|
531
|
-
*/
|
|
250
|
+
<T extends object>(): ObjectFactoryOverloads<TControls, z.core.$strip, 'object', Partial<Record<Extract<keyof T, string>, z.ZodType>>>;
|
|
251
|
+
} & ObjectFactoryOverloads<TControls, z.core.$strip, 'object'>;
|
|
532
252
|
looseObject: {
|
|
533
|
-
<T extends object>():
|
|
534
|
-
|
|
535
|
-
<S extends Record<string, any>, K extends ControlTypeKey<WithDefaultControls<TC, DFTC>>>(shape: S, meta?: ObjectMetaWithType<TC, DFTC, K>): z.ZodObject<ExtractLayoutShape<S>, z.core.$loose>;
|
|
536
|
-
<S extends Record<string, any>, C extends IsComponent>(shape: S, meta?: ObjectMetaWithComponent<C>): z.ZodObject<ExtractLayoutShape<S>, z.core.$loose>;
|
|
537
|
-
} & ObjectFactoryDirect<TC, DFTC, z.core.$loose>;
|
|
538
|
-
/**
|
|
539
|
-
* 严格对象工厂 - 禁止额外属性
|
|
540
|
-
*/
|
|
253
|
+
<T extends object>(): ObjectFactoryOverloads<TControls, z.core.$loose, 'looseObject', Partial<Record<Extract<keyof T, string>, z.ZodType>>>;
|
|
254
|
+
} & ObjectFactoryOverloads<TControls, z.core.$loose, 'looseObject'>;
|
|
541
255
|
strictObject: {
|
|
542
|
-
<T extends object>():
|
|
543
|
-
|
|
544
|
-
<S extends Record<string, any>, K extends ControlTypeKey<WithDefaultControls<TC, DFTC>>>(shape: S, meta?: ObjectMetaWithType<TC, DFTC, K>): z.ZodObject<ExtractLayoutShape<S>, z.core.$strict>;
|
|
545
|
-
<S extends Record<string, any>, C extends IsComponent>(shape: S, meta?: ObjectMetaWithComponent<C>): z.ZodObject<ExtractLayoutShape<S>, z.core.$strict>;
|
|
546
|
-
} & ObjectFactoryDirect<TC, DFTC, z.core.$strict>;
|
|
256
|
+
<T extends object>(): ObjectFactoryOverloads<TControls, z.core.$strict, 'strictObject', Partial<Record<Extract<keyof T, string>, z.ZodType>>>;
|
|
257
|
+
} & ObjectFactoryOverloads<TControls, z.core.$strict, 'strictObject'>;
|
|
547
258
|
}
|
|
548
259
|
export {};
|