@tmagic/form 1.8.0-manmanyu.9 → 1.8.1
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/es/Form.vue_vue_type_script_setup_true_lang.js +88 -107
- package/dist/es/FormBox.vue_vue_type_script_setup_true_lang.js +21 -5
- package/dist/es/FormDialog.vue_vue_type_script_setup_true_lang.js +21 -5
- package/dist/es/FormDrawer.vue_vue_type_script_setup_true_lang.js +46 -12
- package/dist/es/containers/Col.vue_vue_type_script_setup_true_lang.js +6 -2
- package/dist/es/containers/Container.vue_vue_type_script_setup_true_lang.js +44 -47
- package/dist/es/containers/Fieldset.vue_vue_type_script_setup_true_lang.js +7 -1
- package/dist/es/containers/FlexLayout.vue_vue_type_script_setup_true_lang.js +5 -2
- package/dist/es/containers/FormLabel.vue_vue_type_script_setup_true_lang.js +1 -1
- package/dist/es/containers/GroupList.vue_vue_type_script_setup_true_lang.js +59 -22
- package/dist/es/containers/GroupListItem.vue_vue_type_script_setup_true_lang.js +118 -100
- package/dist/es/containers/Panel.vue_vue_type_script_setup_true_lang.js +8 -3
- package/dist/es/containers/Row.vue_vue_type_script_setup_true_lang.js +4 -1
- package/dist/es/containers/Step.vue_vue_type_script_setup_true_lang.js +5 -2
- package/dist/es/containers/Tabs.vue_vue_type_script_setup_true_lang.js +8 -1
- package/dist/es/containers/table/ActionsColumn.vue_vue_type_script_setup_true_lang.js +1 -1
- package/dist/es/containers/table/SortColumn.vue_vue_type_script_setup_true_lang.js +1 -1
- package/dist/es/containers/table/Table.vue_vue_type_script_setup_true_lang.js +14 -10
- package/dist/es/containers/table/useTableColumns.js +10 -15
- package/dist/es/containers/table-group-list/TableGroupList.vue_vue_type_script_setup_true_lang.js +72 -79
- package/dist/es/containers/table-group-list/useAdd.js +26 -16
- package/dist/es/containers/table-group-list/useScrollLastItemIntoView.js +72 -0
- package/dist/es/fields/Cascader.vue_vue_type_script_setup_true_lang.js +2 -2
- package/dist/es/fields/Checkbox.vue_vue_type_script_setup_true_lang.js +1 -1
- package/dist/es/fields/CheckboxGroup/Index.js +5 -0
- package/dist/es/fields/{CheckboxGroup.vue_vue_type_script_setup_true_lang.js → CheckboxGroup/Index.vue_vue_type_script_setup_true_lang.js} +6 -7
- package/dist/es/fields/CheckboxGroup/effect.js +8 -0
- package/dist/es/fields/ColorPicker.vue_vue_type_script_setup_true_lang.js +1 -1
- package/dist/es/fields/Date/Index.js +5 -0
- package/dist/es/fields/{Date.vue_vue_type_script_setup_true_lang.js → Date/Index.vue_vue_type_script_setup_true_lang.js} +5 -7
- package/dist/es/fields/Date/effect.js +10 -0
- package/dist/es/fields/DateTime/Index.js +5 -0
- package/dist/es/fields/{DateTime.vue_vue_type_script_setup_true_lang.js → DateTime/Index.vue_vue_type_script_setup_true_lang.js} +5 -9
- package/dist/es/fields/DateTime/effect.js +15 -0
- package/dist/es/fields/Daterange.vue_vue_type_script_setup_true_lang.js +2 -2
- package/dist/es/fields/Display/Index.js +5 -0
- package/dist/es/fields/{Display.vue_vue_type_script_setup_true_lang.js → Display/Index.vue_vue_type_script_setup_true_lang.js} +6 -7
- package/dist/es/fields/Display/effect.js +8 -0
- package/dist/es/fields/DynamicField/Index.js +5 -0
- package/dist/es/fields/{DynamicField.vue_vue_type_script_setup_true_lang.js → DynamicField/Index.vue_vue_type_script_setup_true_lang.js} +11 -15
- package/dist/es/fields/DynamicField/effect.js +40 -0
- package/dist/es/fields/Hidden.vue_vue_type_script_setup_true_lang.js +1 -1
- package/dist/es/fields/Link.vue_vue_type_script_setup_true_lang.js +4 -4
- package/dist/es/fields/Number.vue_vue_type_script_setup_true_lang.js +4 -2
- package/dist/es/fields/NumberRange/Index.js +5 -0
- package/dist/es/fields/{NumberRange.vue_vue_type_script_setup_true_lang.js → NumberRange/Index.vue_vue_type_script_setup_true_lang.js} +5 -6
- package/dist/es/fields/NumberRange/effect.js +8 -0
- package/dist/es/fields/RadioGroup.vue_vue_type_script_setup_true_lang.js +5 -2
- package/dist/es/fields/Select.vue_vue_type_script_setup_true_lang.js +14 -6
- package/dist/es/fields/Switch.vue_vue_type_script_setup_true_lang.js +1 -1
- package/dist/es/fields/Text.vue_vue_type_script_setup_true_lang.js +13 -10
- package/dist/es/fields/Textarea.vue_vue_type_script_setup_true_lang.js +1 -1
- package/dist/es/fields/Time.vue_vue_type_script_setup_true_lang.js +1 -1
- package/dist/es/fields/Timerange.vue_vue_type_script_setup_true_lang.js +3 -3
- package/dist/es/headless.js +13 -0
- package/dist/es/index.js +19 -12
- package/dist/es/plugin.js +57 -39
- package/dist/es/schema.js +11 -2
- package/dist/es/style.css +123 -3
- package/dist/es/submitForm.js +270 -72
- package/dist/es/utils/builtInFields.js +49 -0
- package/dist/es/utils/collectFields.js +407 -0
- package/dist/es/utils/config.js +4 -8
- package/dist/es/utils/fieldInnerConfig.js +42 -0
- package/dist/es/utils/fieldValueEffects.js +80 -0
- package/dist/es/utils/form.js +154 -19
- package/dist/es/utils/formStateProxy.js +111 -0
- package/dist/es/utils/registerField.js +158 -0
- package/dist/es/utils/submitHeadless.js +54 -0
- package/dist/es/utils/tableGroupList.js +104 -0
- package/dist/es/utils/typeMatch.js +532 -0
- package/dist/es/utils/validateError.js +57 -0
- package/dist/es/utils/validateValues.js +115 -0
- package/dist/style.css +123 -3
- package/dist/themes/magic-admin.css +576 -14
- package/dist/tmagic-form-headless.umd.cjs +4515 -0
- package/dist/tmagic-form.umd.cjs +3444 -983
- package/package.json +16 -10
- package/src/Form.vue +113 -129
- package/src/FormBox.vue +16 -4
- package/src/FormDialog.vue +16 -5
- package/src/FormDrawer.vue +41 -13
- package/src/containers/Col.vue +3 -0
- package/src/containers/Container.vue +40 -45
- package/src/containers/Fieldset.vue +5 -0
- package/src/containers/FlexLayout.vue +2 -0
- package/src/containers/GroupList.vue +64 -13
- package/src/containers/GroupListItem.vue +88 -81
- package/src/containers/Panel.vue +3 -0
- package/src/containers/Row.vue +2 -0
- package/src/containers/Step.vue +2 -0
- package/src/containers/Tabs.vue +13 -0
- package/src/containers/table/ActionsColumn.vue +1 -1
- package/src/containers/table/Table.vue +5 -3
- package/src/containers/table/usePagination.ts +1 -1
- package/src/containers/table/useSortable.ts +1 -1
- package/src/containers/table/useTableColumns.ts +15 -22
- package/src/containers/table-group-list/TableGroupList.vue +46 -72
- package/src/containers/table-group-list/useAdd.ts +40 -25
- package/src/containers/table-group-list/useScrollLastItemIntoView.ts +94 -0
- package/src/fields/{CheckboxGroup.vue → CheckboxGroup/Index.vue} +3 -8
- package/src/fields/CheckboxGroup/effect.ts +27 -0
- package/src/fields/{Date.vue → Date/Index.vue} +2 -5
- package/src/fields/Date/effect.ts +29 -0
- package/src/fields/{DateTime.vue → DateTime/Index.vue} +2 -16
- package/src/fields/DateTime/effect.ts +36 -0
- package/src/fields/{Display.vue → Display/Index.vue} +3 -7
- package/src/fields/Display/effect.ts +28 -0
- package/src/fields/{DynamicField.vue → DynamicField/Index.vue} +11 -11
- package/src/fields/DynamicField/effect.ts +74 -0
- package/src/fields/Link.vue +3 -4
- package/src/fields/Number.vue +2 -1
- package/src/fields/{NumberRange.vue → NumberRange/Index.vue} +2 -6
- package/src/fields/NumberRange/effect.ts +27 -0
- package/src/fields/RadioGroup.vue +13 -1
- package/src/fields/Select.vue +13 -4
- package/src/headless.ts +78 -0
- package/src/index.ts +46 -9
- package/src/plugin.ts +68 -37
- package/src/schema.ts +13 -2
- package/src/submitForm.ts +410 -131
- package/src/theme/fieldset.scss +1 -0
- package/src/theme/form-box.scss +5 -0
- package/src/theme/form-dialog.scss +1 -1
- package/src/theme/group-list.scss +143 -2
- package/src/theme/table.scss +11 -1
- package/src/theme/themes/magic-admin/index.scss +27 -16
- package/src/utils/builtInFields.ts +69 -0
- package/src/utils/collectFields.ts +561 -0
- package/src/utils/config.ts +7 -15
- package/src/utils/fieldInnerConfig.ts +127 -0
- package/src/utils/fieldValueEffects.ts +140 -0
- package/src/utils/form.ts +230 -30
- package/src/utils/formStateProxy.ts +149 -0
- package/src/utils/registerField.ts +308 -0
- package/src/utils/submitHeadless.ts +206 -0
- package/src/utils/tableGroupList.ts +147 -0
- package/src/utils/typeMatch.ts +948 -0
- package/src/utils/validateError.ts +92 -0
- package/src/utils/validateValues.ts +177 -0
- package/types/headless.d.ts +682 -0
- package/types/index.d.ts +900 -180
- package/dist/es/_virtual/_rolldown/runtime.js +0 -27
- package/dist/es/fields/CheckboxGroup.js +0 -5
- package/dist/es/fields/Date.js +0 -5
- package/dist/es/fields/DateTime.js +0 -5
- package/dist/es/fields/Display.js +0 -5
- package/dist/es/fields/DynamicField.js +0 -5
- package/dist/es/fields/NumberRange.js +0 -5
|
@@ -0,0 +1,682 @@
|
|
|
1
|
+
import { App, AppContext, Component, ComputedRef, InjectionKey, MaybeRef, Ref } from "vue";
|
|
2
|
+
import { FormContext, FormItemConfig } from "@tmagic/form-schema";
|
|
3
|
+
export * from "@tmagic/form-schema";
|
|
4
|
+
declare namespace schema_d_exports {
|
|
5
|
+
export { ChangeRecord, ContainerChangeEventData, FORM_CONTEXT_KEY, FORM_DIFF_CONFIG_KEY, FORM_TYPE_MATCH_VALID_KEY, FormDiffConfig, FormLabelSlotProps, FormSlots, ValidateError };
|
|
6
|
+
}
|
|
7
|
+
import * as import__tmagic_form_schema from "@tmagic/form-schema";
|
|
8
|
+
/**
|
|
9
|
+
* 对比模式相关配置,由 `MForm` 通过 `provide` 注入,
|
|
10
|
+
* 所有层级的 Container(含嵌套在 fieldset / panel 等容器组件内部的 Container)通过 `inject` 获取,
|
|
11
|
+
* 无需逐层透传 prop。
|
|
12
|
+
*/
|
|
13
|
+
export interface FormDiffConfig {
|
|
14
|
+
/**
|
|
15
|
+
* 自定义"是否展示对比内容"的判断函数(仅在对比模式下生效)。
|
|
16
|
+
*
|
|
17
|
+
* - 不传:使用默认逻辑 `!isEqual(curValue, lastValue)`;
|
|
18
|
+
* - 传函数:完全以函数返回值为准,返回 `true` 才展示前后两份对比内容。
|
|
19
|
+
*/
|
|
20
|
+
showDiff?: (_data: {
|
|
21
|
+
curValue: any;
|
|
22
|
+
lastValue: any;
|
|
23
|
+
config: FormItemConfig;
|
|
24
|
+
}) => boolean;
|
|
25
|
+
/**
|
|
26
|
+
* 自定义「自接管对比」的字段类型(仅在对比模式下生效)。
|
|
27
|
+
*
|
|
28
|
+
* - 传数组:在内置类型基础上「追加」这些类型;
|
|
29
|
+
* - 传函数:入参为内置类型数组,返回值作为「最终」完整类型列表(可完全替换内置项)。
|
|
30
|
+
*/
|
|
31
|
+
selfDiffFieldTypes?: string[] | ((_defaultTypes: string[]) => string[]);
|
|
32
|
+
}
|
|
33
|
+
export declare const FORM_DIFF_CONFIG_KEY: InjectionKey<FormDiffConfig>;
|
|
34
|
+
export declare const FORM_TYPE_MATCH_VALID_KEY: InjectionKey<ComputedRef<boolean>>;
|
|
35
|
+
/**
|
|
36
|
+
* 宿主业务上下文,由 `MForm`(或更外层的 Editor)通过 `provide` 下发。
|
|
37
|
+
*
|
|
38
|
+
* 嵌套表单(Link 子表单、FormBox、临时校验表单等)会自动继承最近祖先的 context,
|
|
39
|
+
* 无需层层透传。
|
|
40
|
+
*
|
|
41
|
+
* 配置回调统一通过 `mForm.xxx` 读取,由 formState 的读穿 Proxy 落到这里。
|
|
42
|
+
*/
|
|
43
|
+
export declare const FORM_CONTEXT_KEY: InjectionKey<ComputedRef<FormContext>>;
|
|
44
|
+
export interface ValidateError {
|
|
45
|
+
message: string;
|
|
46
|
+
field: string;
|
|
47
|
+
}
|
|
48
|
+
export interface ChangeRecord {
|
|
49
|
+
propPath?: string;
|
|
50
|
+
value: any;
|
|
51
|
+
}
|
|
52
|
+
export interface ContainerChangeEventData {
|
|
53
|
+
modifyKey?: string;
|
|
54
|
+
changeRecords?: ChangeRecord[];
|
|
55
|
+
}
|
|
56
|
+
/** 自定义 label slot 的作用域参数 */
|
|
57
|
+
export interface FormLabelSlotProps {
|
|
58
|
+
/** 当前表单项配置 */
|
|
59
|
+
config: FormItemConfig;
|
|
60
|
+
/** 经处理后的类型 */
|
|
61
|
+
type: string;
|
|
62
|
+
/** 经 filterFunction 处理后的 label 文案 */
|
|
63
|
+
text?: string;
|
|
64
|
+
/** 完整字段路径(包含父级前缀) */
|
|
65
|
+
prop: string;
|
|
66
|
+
/** 经 filterFunction 处理后的最终禁用状态 */
|
|
67
|
+
disabled?: boolean;
|
|
68
|
+
}
|
|
69
|
+
/** Form / Container 暴露的具名 slot 定义 */
|
|
70
|
+
export interface FormSlots {
|
|
71
|
+
label(_props: FormLabelSlotProps): any;
|
|
72
|
+
}
|
|
73
|
+
//#endregion
|
|
74
|
+
//#region temp/packages/form/src/utils/formStateProxy.d.ts
|
|
75
|
+
/**
|
|
76
|
+
* 按优先级分层合并上下文,**靠后的层优先**。
|
|
77
|
+
*
|
|
78
|
+
* 用读穿 Proxy 而非 `{ ...a, ...b }`:展开会立即执行 accessor,
|
|
79
|
+
* 而宿主允许用 `{ get stage() { ... } }` 这类读时求值的描述符。
|
|
80
|
+
*/
|
|
81
|
+
export declare const mergeFormContexts: (...layers: (schema_d_exports.FormContext | undefined | null)[]) => schema_d_exports.FormContext;
|
|
82
|
+
/**
|
|
83
|
+
* 将 coreState 与宿主业务上下文关联:读取时优先 core,miss 再读穿到 context。
|
|
84
|
+
*
|
|
85
|
+
* - `get` 用属性访问而非 `Reflect.get(t, k, receiver)`,避免破坏 Vue reactive 的 `__v_raw`;
|
|
86
|
+
* - symbol 键一律只走 core,四个 trap 保持一致。context 是业务数据袋,不承载 symbol 键,
|
|
87
|
+
* 把 Vue / 工具链的内部 symbol 隔离在 core 上才能让 `toRaw` / `isReactive` 判定正确;
|
|
88
|
+
* - `ownKeys` + `getOwnPropertyDescriptor` 保证 `Object.entries(formState)` 能枚举到扩展字段
|
|
89
|
+
* (admin-web-next 的 `pickPanelFormStateExtendFields` 依赖此语义);
|
|
90
|
+
* - `set` 写入 coreState,第三方 `formState.xxx = v` 仍生效且优先于 context。
|
|
91
|
+
*
|
|
92
|
+
* 独立成文件,避免与 `form.ts` ↔ `typeMatch.ts` 形成循环依赖。
|
|
93
|
+
*/
|
|
94
|
+
export declare const createFormStateProxy: (coreState: schema_d_exports.FormState, getContext: (() => schema_d_exports.FormContext) | Ref<schema_d_exports.FormContext>) => schema_d_exports.FormState;
|
|
95
|
+
//#endregion
|
|
96
|
+
//#region temp/packages/form/src/utils/form.d.ts
|
|
97
|
+
type AsyncValidatorFn = (rule: any, value: any, callback: Function, source?: any, options?: any) => any;
|
|
98
|
+
/**
|
|
99
|
+
* 将 async-validator(Element Plus)风格的 validator 适配到当前 UI 库。
|
|
100
|
+
* TDesign 调用签名为 `(val) => boolean | CustomValidateObj | Promise`,无 callback。
|
|
101
|
+
*/
|
|
102
|
+
export declare const adaptFormValidator: (validator: AsyncValidatorFn) => AsyncValidatorFn;
|
|
103
|
+
export declare const createValues: (mForm: schema_d_exports.FormState | undefined, config?: schema_d_exports.FormConfig | schema_d_exports.TabPaneConfig[], initValue?: schema_d_exports.FormValue, value?: schema_d_exports.FormValue) => schema_d_exports.FormValue;
|
|
104
|
+
export declare const createFormStateBase: (ui?: {
|
|
105
|
+
$message?: any;
|
|
106
|
+
$messageBox?: any;
|
|
107
|
+
}) => {
|
|
108
|
+
fields: Map<string, any>;
|
|
109
|
+
setField: (prop: string, field: any) => Map<string, any>;
|
|
110
|
+
getField: (prop: string) => any;
|
|
111
|
+
deleteField: (prop: string) => boolean;
|
|
112
|
+
$messageBox: any;
|
|
113
|
+
$message: any;
|
|
114
|
+
post: (options: any) => any;
|
|
115
|
+
};
|
|
116
|
+
/**
|
|
117
|
+
* 配置项的 `name` 是否可用于从 model 中下钻取值。
|
|
118
|
+
*
|
|
119
|
+
* 供 `Container.vue` 与无渲染校验(`collectValidatableFields`)共用,两者对「该不该下钻」
|
|
120
|
+
* 的判断必须一致。
|
|
121
|
+
*/
|
|
122
|
+
export declare const isValidName: (name: unknown) => boolean;
|
|
123
|
+
/**
|
|
124
|
+
* 在 `prop` 后追加一段路径。
|
|
125
|
+
*
|
|
126
|
+
* 用于容器把 `prop` 透传给子级时再拼上索引 / key(如 group-list 的行、table 的行)。
|
|
127
|
+
*/
|
|
128
|
+
export declare const appendProp: (prop: string | undefined, key: string | number) => string;
|
|
129
|
+
/**
|
|
130
|
+
* 由父级 `prop` 与配置项 `name` 拼出该配置项的完整 `prop`(即 FormItem 的 prop)。
|
|
131
|
+
*
|
|
132
|
+
* 调用方传入的 name 已按 `config.name || ''` 归一化,空 name 表示该配置项不占据值路径上的一层,
|
|
133
|
+
* 此时沿用父级 `prop`。
|
|
134
|
+
*/
|
|
135
|
+
export declare const getItemProp: (prop?: string | undefined, name?: string | number | undefined) => string;
|
|
136
|
+
/**
|
|
137
|
+
* 归一化配置项的 `type`:求值动态 type、剥离容器语义的 type、驼峰转中划线、补默认值。
|
|
138
|
+
*
|
|
139
|
+
* 供 `Container.vue` 与无渲染校验共用,保证两者分派到的 type 完全一致。
|
|
140
|
+
*/
|
|
141
|
+
export declare const resolveItemType: (mForm: schema_d_exports.FormState | undefined, config: any, props: any) => string;
|
|
142
|
+
export declare const filterFunction: <T = any>(mForm: schema_d_exports.FormState | undefined, config: T | schema_d_exports.FilterFunction<T> | undefined, props: any) => T | undefined;
|
|
143
|
+
export declare const display: (mForm: schema_d_exports.FormState | undefined, config: any, props: any) => any;
|
|
144
|
+
export declare const getRules: (mForm: schema_d_exports.FormState | undefined, r: (schema_d_exports.Rule[] | schema_d_exports.Rule) | undefined, props: any, typeMatchValid?: MaybeRef<boolean>) => schema_d_exports.Rule[];
|
|
145
|
+
/**
|
|
146
|
+
* 与 `getRules` 相同,但 validator 保持 async-validator(Element Plus)原生签名,不做 UI 库适配。
|
|
147
|
+
*
|
|
148
|
+
* 供无渲染校验(`validateValues`)使用:它直接把规则交给 async-validator 执行,
|
|
149
|
+
* 不经过 TDesign 的 `validator(val)` 调用约定,因此不能套 `adaptFormValidator`。
|
|
150
|
+
*/
|
|
151
|
+
export declare const getNativeRules: (mForm: schema_d_exports.FormState | undefined, r: (schema_d_exports.Rule[] | schema_d_exports.Rule) | undefined, props: any, typeMatchValid?: MaybeRef<boolean>) => schema_d_exports.Rule[];
|
|
152
|
+
export declare const initValue: (mForm: schema_d_exports.FormState | undefined, { initValues, config }: {
|
|
153
|
+
initValues: schema_d_exports.FormValue;
|
|
154
|
+
config: schema_d_exports.FormConfig;
|
|
155
|
+
}) => Promise<schema_d_exports.FormValue>;
|
|
156
|
+
export declare const datetimeFormatter: (v: string | Date, defaultValue?: string, format?: string) => string | number;
|
|
157
|
+
export declare const getDataByPage: (data: any[] | undefined, pagecontext: number, pagesize: number) => any[];
|
|
158
|
+
export declare const sortArray: (data: any[], newIndex: number, oldIndex: number, sortKey?: string) => any[];
|
|
159
|
+
export declare const sortChange: (data: any[], { prop, order }: schema_d_exports.SortProp) => void;
|
|
160
|
+
export declare const createObjectProp: (prop: string, key: string, name?: string | number) => string;
|
|
161
|
+
//#endregion
|
|
162
|
+
//#region temp/packages/form/src/utils/collectFields.d.ts
|
|
163
|
+
/** 一个参与校验的字段:与渲染式校验中「一个带 rules 的 TMagicFormItem」一一对应 */
|
|
164
|
+
interface CollectedField {
|
|
165
|
+
/** 字段的完整 prop 路径(从表单根 values 起算,与 FormItem 的 prop 一致) */
|
|
166
|
+
prop: string;
|
|
167
|
+
/** 经 `getNativeRules` 处理后的规则(validator 为 async-validator 原生签名) */
|
|
168
|
+
rules: schema_d_exports.Rule[];
|
|
169
|
+
/** 字段配置 */
|
|
170
|
+
config: schema_d_exports.FormItemConfig;
|
|
171
|
+
/** 字段所在层级的 model 切片 */
|
|
172
|
+
model: schema_d_exports.FormValue;
|
|
173
|
+
}
|
|
174
|
+
/** 已登记的 innerConfig 回调自身抛错时抛出(机制故障,不是漏登记) */
|
|
175
|
+
export declare class FieldInnerConfigError extends Error {
|
|
176
|
+
readonly code = "FIELD_INNER_CONFIG";
|
|
177
|
+
readonly type: string;
|
|
178
|
+
readonly prop: string;
|
|
179
|
+
constructor(type: string, prop: string, cause: unknown);
|
|
180
|
+
}
|
|
181
|
+
export declare const isFieldInnerConfigError: (error: unknown) => error is FieldInnerConfigError;
|
|
182
|
+
/**
|
|
183
|
+
* 遍历模式。同一套遍历规则服务两个用途,避免两条链路各写一份而产生偏差:
|
|
184
|
+
*
|
|
185
|
+
* - `collect`:收集带 rules 的字段,按 `display` 过滤(对应「渲染出来的 FormItem 集合」);
|
|
186
|
+
* - `effects`:执行字段登记的值初始化写入,不收集字段,且不看 `display`
|
|
187
|
+
* (`display: false` 的字段同样要规整;`type: 'hidden'` 在该节点停止,不往下分派)。
|
|
188
|
+
*/
|
|
189
|
+
type WalkMode = 'collect' | 'effects';
|
|
190
|
+
interface WalkContext {
|
|
191
|
+
mForm: schema_d_exports.FormState | undefined;
|
|
192
|
+
/**
|
|
193
|
+
* 是否自动给字段注入 typeMatch 规则,对应 MForm 的 `typeMatchValid`。
|
|
194
|
+
*
|
|
195
|
+
* 只在 `collect` 模式下有用:`addField` 把它交给 `getNativeRules`。为 true 且字段
|
|
196
|
+
* rules 尚未显式声明 `typeMatch`(true / false)时,自动补一条 `{ typeMatch: true }`,
|
|
197
|
+
* 按字段 `type` 校验当前值形态是否合法(空值放行,必填仍靠 `required`)。
|
|
198
|
+
* 单字段可在 rules 里写 `typeMatch: false` 关闭自动注入。
|
|
199
|
+
*
|
|
200
|
+
* `effects` 模式不收集规则,无需传入。
|
|
201
|
+
*/
|
|
202
|
+
typeMatchValid?: boolean;
|
|
203
|
+
fields: CollectedField[];
|
|
204
|
+
/** 本次遍历处理的表单值根对象(对比模式下为 lastValues 那一份) */
|
|
205
|
+
values: schema_d_exports.FormValue;
|
|
206
|
+
mode: WalkMode;
|
|
207
|
+
}
|
|
208
|
+
interface WalkNode {
|
|
209
|
+
config: schema_d_exports.FormItemConfig;
|
|
210
|
+
/** 所在层级的 model 切片(对应 Container 的 `props.model`) */
|
|
211
|
+
model: schema_d_exports.FormValue;
|
|
212
|
+
/** 父级 prop(对应 Container 的 `props.prop`) */
|
|
213
|
+
prop: string;
|
|
214
|
+
}
|
|
215
|
+
type ContainerWalker = (_ctx: WalkContext, _node: WalkNode, _itemProp: string) => void;
|
|
216
|
+
/**
|
|
217
|
+
* 纯逻辑收集「一份 config + 一份 values」中所有参与校验的字段。
|
|
218
|
+
*
|
|
219
|
+
* 遍历规则与 `Container.vue` 及各容器组件的模板一一对应,因此产出的 prop / rules
|
|
220
|
+
* 与渲染式校验(挂载 MForm 后调用 `validate()`)等价,无需任何 DOM 或组件实例。
|
|
221
|
+
*
|
|
222
|
+
* 本函数只读不写。字段的值初始化副作用由 `applyMountValueEffects` 负责,
|
|
223
|
+
* 调用方需在初始化表单值之后、收集字段之前执行一次(`validateValues` 已经这么做)。
|
|
224
|
+
*
|
|
225
|
+
* @param mForm - 表单状态;无渲染时由 `createHeadlessFormState` 构造
|
|
226
|
+
* @param config - 表单配置
|
|
227
|
+
* @param values - 表单值
|
|
228
|
+
* @param [typeMatchValid] - 是否自动注入 typeMatch 规则;为 true 时,未显式声明
|
|
229
|
+
* `typeMatch` 的字段会补上 `{ typeMatch: true }`,按字段 type 校验值形态
|
|
230
|
+
* @returns 带规则的字段列表
|
|
231
|
+
*/
|
|
232
|
+
export declare const collectValidatableFields: (mForm: schema_d_exports.FormState | undefined, config: schema_d_exports.FormConfig, values: schema_d_exports.FormValue, typeMatchValid?: boolean) => CollectedField[];
|
|
233
|
+
/**
|
|
234
|
+
* 执行「一份 config + 一份 values」中所有叶子字段登记的值初始化写入,就地改写 `values`。
|
|
235
|
+
*
|
|
236
|
+
* 渲染与无渲染两条链路共用的唯一执行点:字段组件自身不再在 setup 里改写 model,
|
|
237
|
+
* 由持有完整表单值的一方(`Form.vue` / `validateValues`)在表单值初始化完成、
|
|
238
|
+
* 且已挂到 `mForm.values` 之后调用一次。这样 effect 与动态 `type` 回调读到的
|
|
239
|
+
* `formValue` 就是最新值,而不是上一轮的旧值。
|
|
240
|
+
*
|
|
241
|
+
* 与 `collectValidatableFields` 的差异:不看 `display`(`display: false` 的字段也会规整)。
|
|
242
|
+
* `type: 'hidden'` 会在该节点停止遍历,内部字段不执行 effect。
|
|
243
|
+
*
|
|
244
|
+
* `prop` 与 `values` 都以传入的 `values` 为根,因此也可以用于 tab / table 新增行这类
|
|
245
|
+
* 「先构造一份子树的值,再挂到表单上」的场景:传入子树配置与该行的值即可。
|
|
246
|
+
*
|
|
247
|
+
* @param mForm - 表单状态;无渲染时由 `createHeadlessFormState` 构造
|
|
248
|
+
* @param config - 表单配置
|
|
249
|
+
* @param values - 表单值(会被就地修改)
|
|
250
|
+
*/
|
|
251
|
+
export declare const applyMountValueEffects: (mForm: schema_d_exports.FormState | undefined, config: schema_d_exports.FormConfig, values: schema_d_exports.FormValue) => void;
|
|
252
|
+
//#endregion
|
|
253
|
+
//#region temp/packages/form/src/utils/fieldInnerConfig.d.ts
|
|
254
|
+
/** innerConfig 回调的入参:字段自身的配置、所在层级的 model、完整字段路径与表单状态 */
|
|
255
|
+
interface FieldInnerConfigContext {
|
|
256
|
+
/** 字段自身的配置(已经过 filterFunction 之外的原样配置) */
|
|
257
|
+
config: schema_d_exports.FormItemConfig;
|
|
258
|
+
/** 字段所在层级的 model 切片 */
|
|
259
|
+
model: schema_d_exports.FormValue;
|
|
260
|
+
/** 字段的完整 prop 路径(含父级前缀),即字段组件拿到的 `props.prop` */
|
|
261
|
+
prop: string;
|
|
262
|
+
/** 字段所在层级的 prop 基准(父级 Container 的 `props.prop`),即 `prop` 去掉自身 name 的部分 */
|
|
263
|
+
parentProp: string;
|
|
264
|
+
/** 表单状态 */
|
|
265
|
+
mForm: schema_d_exports.FormState | undefined;
|
|
266
|
+
}
|
|
267
|
+
/** innerConfig 回调的返回值:需要继续遍历的内部配置及其 model / prop 基准 */
|
|
268
|
+
interface FieldInnerConfigResult {
|
|
269
|
+
/** 内部配置(对应字段组件内部渲染的 `MContainer` 的 `config`) */
|
|
270
|
+
config: schema_d_exports.FormItemConfig | schema_d_exports.FormItemConfig[];
|
|
271
|
+
/**
|
|
272
|
+
* 内部配置对应的 model 切片,默认沿用字段所在层级的 `model`。
|
|
273
|
+
*
|
|
274
|
+
* 例如 `code-select` 内部是 `:model="model[name]"`,就应返回 `model[config.name]`。
|
|
275
|
+
*/
|
|
276
|
+
model?: schema_d_exports.FormValue;
|
|
277
|
+
/**
|
|
278
|
+
* 内部配置对应的 prop 基准,默认沿用字段自身的 `prop`。
|
|
279
|
+
*
|
|
280
|
+
* 返回的 config 的 `name` 会被追加到这个基准上。所以当内部配置复用了字段自身的 `name`
|
|
281
|
+
* (如 `display-conds` 内部的 group-list 就叫 `props.name`)时,要返回 `parentProp`,
|
|
282
|
+
* 否则 name 会被拼两次。
|
|
283
|
+
*/
|
|
284
|
+
prop?: string;
|
|
285
|
+
}
|
|
286
|
+
/**
|
|
287
|
+
* 复合字段的内部配置回调。
|
|
288
|
+
*
|
|
289
|
+
* 有一类字段组件会在自身内部再渲染 `MContainer` 并传入组件内部临时算出来的 config
|
|
290
|
+
* (如编辑器的 `code-select` / `event-select` / `style-setter`),这些内部字段同样会向
|
|
291
|
+
* 父级表单注册 FormItem、参与父表单校验。无渲染校验(`validateValues`)只遍历调用方
|
|
292
|
+
* 传入的 config 树,看不到这些运行期才产生的配置,因此需要字段作者通过
|
|
293
|
+
* `registerField(type, { innerConfig })` 把内部配置交出来。
|
|
294
|
+
*
|
|
295
|
+
* 返回 `null` / `undefined` 表示该字段本次没有内部配置(例如某些分支下不渲染子表单)。
|
|
296
|
+
*
|
|
297
|
+
* 既未登记 innerConfig、也不在叶子字段表里的 type:配置里有 `items` 会下钻子项,
|
|
298
|
+
* 自身有 `rules` 会校验自身。
|
|
299
|
+
*/
|
|
300
|
+
type FieldInnerConfig = (_ctx: FieldInnerConfigContext) => FieldInnerConfigResult | null | undefined | void;
|
|
301
|
+
//#endregion
|
|
302
|
+
//#region temp/packages/form/src/utils/fieldValueEffects.d.ts
|
|
303
|
+
/** effect 的入参:字段自身的配置、所在层级的 model、完整字段路径、表单值根对象与表单状态 */
|
|
304
|
+
interface FieldMountValueEffectContext {
|
|
305
|
+
/** 字段自身的配置 */
|
|
306
|
+
config: schema_d_exports.FormItemConfig;
|
|
307
|
+
/** 字段所在层级的 model 切片 */
|
|
308
|
+
model: schema_d_exports.FormValue;
|
|
309
|
+
/** 字段的完整 prop 路径(含父级前缀),对应 Container 的 `itemProp` */
|
|
310
|
+
prop: string;
|
|
311
|
+
/**
|
|
312
|
+
* 本次处理的表单值根对象,`prop` 即以它为根。
|
|
313
|
+
*
|
|
314
|
+
* 需要按路径跨层级写值时用它,不要用 `mForm.values`:对比模式下处理的是 lastValues 那一份,
|
|
315
|
+
* tab / table 新增行处理的则是还没挂到表单上的一行值,两者都与 `mForm.values` 不是同一个对象。
|
|
316
|
+
*/
|
|
317
|
+
values: schema_d_exports.FormValue;
|
|
318
|
+
/** 表单状态 */
|
|
319
|
+
mForm: schema_d_exports.FormState | undefined;
|
|
320
|
+
}
|
|
321
|
+
/**
|
|
322
|
+
* 字段对表单值的初始化写入(如 `display` 的 `initValue`、`date` 的格式归一化)。
|
|
323
|
+
*
|
|
324
|
+
* 由 `applyMountValueEffects` 在表单值初始化完成后统一执行一次,渲染与无渲染共用。
|
|
325
|
+
* 因为可能对同一份值重复执行(如 `initValues` 变化后重新初始化),实现必须幂等。
|
|
326
|
+
*/
|
|
327
|
+
type FieldMountValueEffect = (_ctx: FieldMountValueEffectContext) => void;
|
|
328
|
+
/**
|
|
329
|
+
* 是否为叶子字段 type(内置 ∪ 已登记)。
|
|
330
|
+
*
|
|
331
|
+
* @param type - 字段 type
|
|
332
|
+
* @returns 是否为叶子
|
|
333
|
+
*/
|
|
334
|
+
export declare const isLeafFieldType: (type: string) => boolean;
|
|
335
|
+
//#endregion
|
|
336
|
+
//#region temp/packages/form/src/utils/typeMatch.d.ts
|
|
337
|
+
interface TypeMatchValidateContext {
|
|
338
|
+
fieldType: string;
|
|
339
|
+
mForm: schema_d_exports.FormState | undefined;
|
|
340
|
+
props: any;
|
|
341
|
+
message?: string;
|
|
342
|
+
}
|
|
343
|
+
/**
|
|
344
|
+
* 自定义 type 校验器:返回错误文案;通过则返回 undefined。
|
|
345
|
+
*
|
|
346
|
+
* 支持返回 Promise,用于需要异步确认取值是否合法的场景(如请求接口校验 id 是否存在)。
|
|
347
|
+
*/
|
|
348
|
+
type TypeMatchValidator = (value: any, context: TypeMatchValidateContext) => string | undefined | Promise<string | undefined>;
|
|
349
|
+
/** 获取某个字段 type 的 typeMatch 校验规则(业务侧优先于内置) */
|
|
350
|
+
export declare const getTypeMatchRule: (type: string) => TypeMatchValidator | undefined;
|
|
351
|
+
/** 删除业务侧 typeMatch 校验规则(不影响内置) */
|
|
352
|
+
export declare const deleteTypeMatchRule: (type: string) => boolean;
|
|
353
|
+
/** 清空业务侧 typeMatch 校验规则(不影响内置) */
|
|
354
|
+
export declare const clearTypeMatchRules: () => void;
|
|
355
|
+
/**
|
|
356
|
+
* 将值格式化为可读的参考示例字符串。
|
|
357
|
+
*/
|
|
358
|
+
export declare const stringifyExampleValue: (value: any) => string;
|
|
359
|
+
/** 参考建议中可选值全量展示上限;超出时仅举例 EXAMPLE_SUGGESTION_COUNT 个并标明总数。 */
|
|
360
|
+
export declare const MAX_SUGGESTION_OPTIONS = 20;
|
|
361
|
+
/**
|
|
362
|
+
* 生成可选项参考建议;无可选值时返回空字符串(不追加建议)。
|
|
363
|
+
* 未超过 MAX_SUGGESTION_OPTIONS 时全部列举;超过时仅举例前 EXAMPLE_SUGGESTION_COUNT 个并标明总数,避免 AI 误以为仅有举例值合法。
|
|
364
|
+
*/
|
|
365
|
+
export declare const optionSuggestion: (optionValues: any[]) => string;
|
|
366
|
+
/**
|
|
367
|
+
* 校验取值与字段 type 是否匹配;通过返回 undefined,否则返回错误文案。
|
|
368
|
+
*
|
|
369
|
+
* 命中的自定义规则是异步校验器时返回 Promise,内置规则始终同步返回。
|
|
370
|
+
*/
|
|
371
|
+
export declare const validateTypeMatch: (value: any, mForm: schema_d_exports.FormState | undefined, props: any, message?: string) => string | undefined | Promise<string | undefined>;
|
|
372
|
+
//#endregion
|
|
373
|
+
//#region temp/packages/form/src/utils/registerField.d.ts
|
|
374
|
+
/**
|
|
375
|
+
* 自定义字段 type 的登记项。
|
|
376
|
+
*
|
|
377
|
+
* 不传或只传空对象:当作叶子,不再下钻 `items`。
|
|
378
|
+
*/
|
|
379
|
+
interface FieldOptions {
|
|
380
|
+
/**
|
|
381
|
+
* 渲染用的 Vue 组件,写入字段注册表。
|
|
382
|
+
* 传入 `app` 时同时 `app.component('m-fields-*')`。
|
|
383
|
+
*/
|
|
384
|
+
component?: Component;
|
|
385
|
+
/**
|
|
386
|
+
* 容器组件,写入字段注册表。
|
|
387
|
+
* 传入 `app` 时同时 `app.component('m-form-*')`。
|
|
388
|
+
*/
|
|
389
|
+
container?: Component;
|
|
390
|
+
/** 字段挂载时改写 model 的副作用。可与 `innerConfig` 同时登记。 */
|
|
391
|
+
effect?: FieldMountValueEffect;
|
|
392
|
+
/**
|
|
393
|
+
* 按容器模板遍历(tab / table 等)。
|
|
394
|
+
* 与 `innerConfig` / `effect` 同时传入时 `walk` 优先。
|
|
395
|
+
*/
|
|
396
|
+
walk?: ContainerWalker;
|
|
397
|
+
/**
|
|
398
|
+
* 把内部会挂到父表单的配置交出来。
|
|
399
|
+
* 可与 `effect` 同时传入:`effect` 负责本字段的值初始化,`innerConfig` 只做配置派生。
|
|
400
|
+
*/
|
|
401
|
+
innerConfig?: FieldInnerConfig;
|
|
402
|
+
/** 该 type 的 typeMatch 校验;可与叶子、walk 或 innerConfig 同时登记。 */
|
|
403
|
+
typeMatch?: TypeMatchValidator;
|
|
404
|
+
}
|
|
405
|
+
/**
|
|
406
|
+
* 无渲染校验用的登记项,不含 Vue 组件。
|
|
407
|
+
*
|
|
408
|
+
* 给 Node / `validateForm` / `submitForm` 用。
|
|
409
|
+
*/
|
|
410
|
+
type HeadlessFieldOptions = Omit<FieldOptions, 'component' | 'container'>;
|
|
411
|
+
/**
|
|
412
|
+
* 把多份字段登记表按 type 浅合并。后一份只覆盖自己带了的 key,未出现的 key 保留前一份。
|
|
413
|
+
*
|
|
414
|
+
* 安装插件时用:Node 侧只登记 `headless`,浏览器再补 `component` / `container`。
|
|
415
|
+
*
|
|
416
|
+
* @param tables - 待合并的登记表,`undefined` 会被跳过
|
|
417
|
+
* @returns 合并后的登记表
|
|
418
|
+
*/
|
|
419
|
+
export declare const mergeFieldOptions: (...tables: Array<Record<string, HeadlessFieldOptions | FieldOptions> | undefined>) => Record<string, FieldOptions>;
|
|
420
|
+
/**
|
|
421
|
+
* 按字段 type 取已登记的渲染组件(`codeSelect` 与 `code-select` 等价)。
|
|
422
|
+
*
|
|
423
|
+
* @param type - 字段 type
|
|
424
|
+
* @returns 已登记的 Vue 组件;未登记则为 `undefined`
|
|
425
|
+
*/
|
|
426
|
+
declare const getField: (type: string) => Component | undefined;
|
|
427
|
+
/**
|
|
428
|
+
* 登记一个字段 type 在无渲染校验里的行为,以及可选的渲染组件。
|
|
429
|
+
*
|
|
430
|
+
* `type` 会按 Container 的规则归一化为中划线形式(`codeSelect` 与 `code-select` 等价)。
|
|
431
|
+
* 对同一 type 重复登记按字段浅合并:后一次只覆盖自己传入的 key,未传入的 key 保留。
|
|
432
|
+
* 传入 `app` 且带了 `component` / `container` 时,会同步 `app.component('m-fields-*'` / `'m-form-*')`。
|
|
433
|
+
*
|
|
434
|
+
* @param type - 字段 type
|
|
435
|
+
* @param [options] - 登记项;省略或空对象视为叶子
|
|
436
|
+
* @param [app] - Vue 应用;省略则不调用 `app.component`
|
|
437
|
+
*/
|
|
438
|
+
export declare const registerField: (type: string, options?: FieldOptions, app?: App) => void;
|
|
439
|
+
/**
|
|
440
|
+
* 批量登记字段。
|
|
441
|
+
*
|
|
442
|
+
* @param fields - type 到登记项的映射
|
|
443
|
+
* @param [app] - Vue 应用;省略则不调用 `app.component`
|
|
444
|
+
*/
|
|
445
|
+
export declare const registerFields: (fields: Record<string, FieldOptions>, app?: App) => void;
|
|
446
|
+
/**
|
|
447
|
+
* 登记内置字段(`clearFields` / `unregisterField` 不会清掉)。
|
|
448
|
+
*
|
|
449
|
+
* @param fields - type 到登记项的映射
|
|
450
|
+
* @param [app] - Vue 应用;省略则不调用 `app.component`
|
|
451
|
+
*/
|
|
452
|
+
export declare const registerBuiltInFields: (fields: Record<string, FieldOptions>, app?: App) => void;
|
|
453
|
+
/**
|
|
454
|
+
* 删除业务侧对指定 type 的登记(不影响内置;主要用于单测)。
|
|
455
|
+
*
|
|
456
|
+
* @param type - 字段 type
|
|
457
|
+
*/
|
|
458
|
+
export declare const unregisterField: (type: string) => void;
|
|
459
|
+
/** 清空业务侧登记(不影响内置;主要用于单测)。 */
|
|
460
|
+
export declare const clearFields: () => void;
|
|
461
|
+
//#endregion
|
|
462
|
+
//#region temp/packages/form/src/utils/builtInFields.d.ts
|
|
463
|
+
/**
|
|
464
|
+
* 内置字段的无渲染登记表(不含 Vue 组件)。
|
|
465
|
+
*
|
|
466
|
+
* 本模块只导出数据,不登记。调用方自行 `registerBuiltInFields(builtInFields)`,
|
|
467
|
+
* 或 `app.use(MagicForm)`(install 里会登记叠上 Vue 组件后的表)。
|
|
468
|
+
*/
|
|
469
|
+
export declare const builtInFields: Record<string, HeadlessFieldOptions>;
|
|
470
|
+
//#endregion
|
|
471
|
+
//#region temp/packages/form/src/utils/validateValues.d.ts
|
|
472
|
+
/** 构造无渲染 formState 所需的参数(与 MForm 的同名 props 对齐) */
|
|
473
|
+
interface HeadlessFormStateOptions {
|
|
474
|
+
config: schema_d_exports.FormConfig;
|
|
475
|
+
initValues?: schema_d_exports.FormValue;
|
|
476
|
+
parentValues?: schema_d_exports.FormValue;
|
|
477
|
+
keyProp?: string;
|
|
478
|
+
popperClass?: string;
|
|
479
|
+
/** 宿主业务上下文,与 MForm 的同名 prop 语义一致 */
|
|
480
|
+
context?: schema_d_exports.FormContext;
|
|
481
|
+
}
|
|
482
|
+
/**
|
|
483
|
+
* 构造一个不依赖组件实例的 `formState`。
|
|
484
|
+
*
|
|
485
|
+
* 字段结构与 `Form.vue` 中 provide 给子树的 `mForm` 保持一致,使配置里的
|
|
486
|
+
* `display` / `rules.validator` / `filter` 等回调拿到的上下文与渲染式校验相同。
|
|
487
|
+
*
|
|
488
|
+
* 差异:没有真实的表单实例,因此 `$emit` 为空实现、`fields` 注册表始终为空
|
|
489
|
+
* (该注册表在整个仓库中只写不读,不参与校验)。
|
|
490
|
+
*/
|
|
491
|
+
export declare const createHeadlessFormState: (options: HeadlessFormStateOptions) => schema_d_exports.FormState;
|
|
492
|
+
/** `validateValues` 参数 */
|
|
493
|
+
interface ValidateValuesOptions extends HeadlessFormStateOptions {
|
|
494
|
+
/** 是否开启类型匹配校验 */
|
|
495
|
+
typeMatchValid?: boolean;
|
|
496
|
+
/**
|
|
497
|
+
* 校验失败时错误提示前缀是否使用字段的 text 文案。默认 `true`。
|
|
498
|
+
*/
|
|
499
|
+
useFieldTextInError?: boolean;
|
|
500
|
+
}
|
|
501
|
+
/** `validateValues` 结果 */
|
|
502
|
+
interface ValidateValuesResult {
|
|
503
|
+
/** 经 `initValue` 初始化并执行字段值初始化写入后的表单值 */
|
|
504
|
+
values: schema_d_exports.FormValue;
|
|
505
|
+
/** 汇总后的错误文案(多条以 `<br>` 拼接),校验通过为空字符串 */
|
|
506
|
+
error: string;
|
|
507
|
+
/** 原始错误映射,形如 `{ [prop]: [{ field, message }] }` */
|
|
508
|
+
invalidFields: Record<string, any>;
|
|
509
|
+
}
|
|
510
|
+
/**
|
|
511
|
+
* 不挂载任何组件,纯逻辑地对「一份 config + 一份值」执行一次完整校验。
|
|
512
|
+
*
|
|
513
|
+
* 流程与渲染式校验一一对应,但不需要 DOM,也不会实例化任何字段组件:
|
|
514
|
+
*
|
|
515
|
+
* 1. 构造 headless `formState` 并挂上 `context` 读穿;
|
|
516
|
+
* 2. `initValue` 初始化表单值(默认值、嵌套结构、`onInitValue` 等);
|
|
517
|
+
* 3. `applyMountValueEffects` 执行字段登记的值初始化写入(与渲染式共用同一份登记表);
|
|
518
|
+
* 4. 遍历 config 树收集所有带规则的字段(等价于渲染出的 FormItem 集合);
|
|
519
|
+
* 5. 逐字段交给 async-validator 执行,汇总错误文案。
|
|
520
|
+
*
|
|
521
|
+
* @example
|
|
522
|
+
* ```ts
|
|
523
|
+
* const { error, values } = await validateValues({
|
|
524
|
+
* config: [...],
|
|
525
|
+
* initValues: { name: '' },
|
|
526
|
+
* typeMatchValid: true,
|
|
527
|
+
* });
|
|
528
|
+
* ```
|
|
529
|
+
*/
|
|
530
|
+
export declare const validateValues: (options: ValidateValuesOptions) => Promise<ValidateValuesResult>;
|
|
531
|
+
//#endregion
|
|
532
|
+
//#region temp/packages/form/src/utils/validateError.d.ts
|
|
533
|
+
/**
|
|
534
|
+
* 通过 name 从 config 中查找对应的 text
|
|
535
|
+
*
|
|
536
|
+
* @param name - 字段名,支持点分隔的路径格式,如 'a.b.c'
|
|
537
|
+
* @param config - 表单配置数组
|
|
538
|
+
* @returns 找到的 text 值,如果未找到则返回 undefined
|
|
539
|
+
*/
|
|
540
|
+
export declare const getTextByName: (name: string, config?: schema_d_exports.FormConfig) => string | undefined;
|
|
541
|
+
/**
|
|
542
|
+
* 将校验返回的 invalidFields 汇总为可读的错误文案(多条以 `<br>` 拼接)。
|
|
543
|
+
*
|
|
544
|
+
* `useFieldTextInError` 为 `true`(默认)时用字段的 text 文案作为错误前缀,找不到则回退为字段 name。
|
|
545
|
+
*
|
|
546
|
+
* 由渲染式校验(Form.vue 的 `submitForm` / `validate`)与无渲染校验(`validateValues`)共用,
|
|
547
|
+
* 保证两条校验链路产出的错误文案格式完全一致。
|
|
548
|
+
*
|
|
549
|
+
* @param invalidFields - async-validator 产出的字段错误表
|
|
550
|
+
* @param [options] - 文案选项
|
|
551
|
+
* @param [options.config] - 用于查找 text 的表单配置
|
|
552
|
+
* @param [options.useFieldTextInError=true] - 错误前缀是否使用字段 text
|
|
553
|
+
* @returns 拼接后的错误文案;无错误时为空串
|
|
554
|
+
*/
|
|
555
|
+
export declare const formatValidateError: (invalidFields: Record<string, any>, { config, useFieldTextInError }?: {
|
|
556
|
+
config?: schema_d_exports.FormConfig;
|
|
557
|
+
useFieldTextInError?: boolean;
|
|
558
|
+
}) => string;
|
|
559
|
+
//#endregion
|
|
560
|
+
//#region temp/packages/form/src/utils/submitHeadless.d.ts
|
|
561
|
+
/**
|
|
562
|
+
* submitForm 函数参数(与 Form.vue 组件 props 对齐)
|
|
563
|
+
*/
|
|
564
|
+
interface SubmitFormOptions {
|
|
565
|
+
/** 表单配置 */
|
|
566
|
+
config: schema_d_exports.FormConfig;
|
|
567
|
+
/** 表单初始值 */
|
|
568
|
+
initValues?: Record<string, any>;
|
|
569
|
+
/** 需对比的值(开启对比模式时传入) */
|
|
570
|
+
lastValues?: Record<string, any>;
|
|
571
|
+
/** 是否开启对比模式 */
|
|
572
|
+
isCompare?: boolean;
|
|
573
|
+
parentValues?: Record<string, any>;
|
|
574
|
+
labelWidth?: string;
|
|
575
|
+
disabled?: boolean;
|
|
576
|
+
height?: string;
|
|
577
|
+
stepActive?: string | number;
|
|
578
|
+
size?: 'small' | 'default' | 'large';
|
|
579
|
+
inline?: boolean;
|
|
580
|
+
labelPosition?: 'top' | 'left' | 'right';
|
|
581
|
+
keyProp?: string;
|
|
582
|
+
popperClass?: string;
|
|
583
|
+
preventSubmitDefault?: boolean;
|
|
584
|
+
/**
|
|
585
|
+
* 表单校验失败时,错误提示前缀是否使用字段的 text 文案(通过 `getTextByName` 从 config 中查找)。
|
|
586
|
+
* 默认 `true`,置为 `false` 时直接使用字段 name。
|
|
587
|
+
*/
|
|
588
|
+
useFieldTextInError?: boolean;
|
|
589
|
+
/** 宿主业务上下文,与 MForm 的同名 prop 语义一致 */
|
|
590
|
+
context?: schema_d_exports.FormContext;
|
|
591
|
+
/** 透传给 Form.submitForm 的参数:是否直接返回原始响应式 values */
|
|
592
|
+
native?: boolean;
|
|
593
|
+
/**
|
|
594
|
+
* 是否在 resolve 结果中携带 changeRecords(变更记录)。
|
|
595
|
+
* 开启后 resolve 的结果为 `{ values, changeRecords }`,否则仅 resolve values。
|
|
596
|
+
*/
|
|
597
|
+
returnChangeRecords?: boolean;
|
|
598
|
+
/**
|
|
599
|
+
* 父级应用上下文,用于继承全局组件、指令、provide 等。
|
|
600
|
+
* 仅 `dialog: true` 时生效。`@tmagic/form/headless` 不支持弹层。
|
|
601
|
+
*/
|
|
602
|
+
appContext?: AppContext | null;
|
|
603
|
+
/**
|
|
604
|
+
* 是否以弹层展示表单。默认 `false`。
|
|
605
|
+
*
|
|
606
|
+
* `@tmagic/form/headless` 不支持 `dialog: true`,请从 `@tmagic/form` 引入。
|
|
607
|
+
*/
|
|
608
|
+
dialog?: boolean;
|
|
609
|
+
/**
|
|
610
|
+
* 弹层标题,仅 `dialog: true` 时生效。
|
|
611
|
+
*/
|
|
612
|
+
title?: string;
|
|
613
|
+
typeMatchValid?: boolean;
|
|
614
|
+
/**
|
|
615
|
+
* 外部中断信号。abort 时会立即以 `signal.reason` reject。
|
|
616
|
+
*/
|
|
617
|
+
signal?: AbortSignal;
|
|
618
|
+
}
|
|
619
|
+
/**
|
|
620
|
+
* 开启 `returnChangeRecords` 时 submitForm 的返回结果
|
|
621
|
+
*/
|
|
622
|
+
interface SubmitFormResult {
|
|
623
|
+
/** 校验通过后的表单值 */
|
|
624
|
+
values: any;
|
|
625
|
+
/** 表单变更记录 */
|
|
626
|
+
changeRecords: ChangeRecord[];
|
|
627
|
+
}
|
|
628
|
+
/**
|
|
629
|
+
* validateForm 函数参数(与 Form.vue 组件 props 对齐,取校验所需子集)
|
|
630
|
+
*/
|
|
631
|
+
interface ValidateFormOptions {
|
|
632
|
+
/** 表单配置 */
|
|
633
|
+
config: schema_d_exports.FormConfig;
|
|
634
|
+
/** 待校验的表单值 */
|
|
635
|
+
initValues?: Record<string, any>;
|
|
636
|
+
parentValues?: Record<string, any>;
|
|
637
|
+
labelWidth?: string;
|
|
638
|
+
keyProp?: string;
|
|
639
|
+
/**
|
|
640
|
+
* 校验失败时,错误提示前缀是否使用字段的 text 文案(通过 `getTextByName` 从 config 中查找)。
|
|
641
|
+
* 默认 `true`,置为 `false` 时直接使用字段 name。
|
|
642
|
+
*/
|
|
643
|
+
useFieldTextInError?: boolean;
|
|
644
|
+
/** 宿主业务上下文,与 MForm 的同名 prop 语义一致 */
|
|
645
|
+
context?: schema_d_exports.FormContext;
|
|
646
|
+
/**
|
|
647
|
+
* 父级应用上下文。仅 `dialog: true` 时生效。`@tmagic/form/headless` 不支持弹层。
|
|
648
|
+
*/
|
|
649
|
+
appContext?: AppContext | null;
|
|
650
|
+
/**
|
|
651
|
+
* 是否以弹层展示表单。默认 `false`。
|
|
652
|
+
*
|
|
653
|
+
* `@tmagic/form/headless` 不支持 `dialog: true`,请从 `@tmagic/form` 引入。
|
|
654
|
+
*/
|
|
655
|
+
dialog?: boolean;
|
|
656
|
+
/**
|
|
657
|
+
* 弹层标题,仅 `dialog: true` 时生效。
|
|
658
|
+
*/
|
|
659
|
+
title?: string;
|
|
660
|
+
typeMatchValid?: boolean;
|
|
661
|
+
/**
|
|
662
|
+
* 外部中断信号。abort 时会立即以 `signal.reason` reject。
|
|
663
|
+
*/
|
|
664
|
+
signal?: AbortSignal;
|
|
665
|
+
}
|
|
666
|
+
/**
|
|
667
|
+
* 以命令式方式对一份「表单配置 + 值」做一次校验并取回表单值(无渲染)。
|
|
668
|
+
*
|
|
669
|
+
* `@tmagic/form/headless` 不支持 `dialog: true`。
|
|
670
|
+
*/
|
|
671
|
+
export declare const submitForm: (options: SubmitFormOptions) => Promise<any>;
|
|
672
|
+
/**
|
|
673
|
+
* 以命令式方式对一份「表单配置 + 值」做一次静默校验(无渲染)。
|
|
674
|
+
*
|
|
675
|
+
* `@tmagic/form/headless` 不支持 `dialog: true`。
|
|
676
|
+
*/
|
|
677
|
+
export declare const validateForm: (options: ValidateFormOptions) => Promise<string>;
|
|
678
|
+
declare namespace headless_d_exports {
|
|
679
|
+
export { ChangeRecord, CollectedField, ContainerChangeEventData, FORM_CONTEXT_KEY, FORM_DIFF_CONFIG_KEY, FORM_TYPE_MATCH_VALID_KEY, FieldInnerConfig, FieldInnerConfigContext, FieldInnerConfigError, FieldInnerConfigResult, FieldMountValueEffect, FieldMountValueEffectContext, FieldOptions, FormDiffConfig, FormLabelSlotProps, FormSlots, HeadlessFieldOptions, HeadlessFormStateOptions, MAX_SUGGESTION_OPTIONS, SubmitFormOptions, SubmitFormResult, TypeMatchValidateContext, TypeMatchValidator, ValidateError, ValidateFormOptions, ValidateValuesOptions, ValidateValuesResult, adaptFormValidator, appendProp, applyMountValueEffects, builtInFields, clearFields, clearTypeMatchRules, collectValidatableFields, createFormStateBase, createFormStateProxy, createHeadlessFormState, createObjectProp, createValues, datetimeFormatter, deleteTypeMatchRule, display, filterFunction, formatValidateError, getDataByPage, getField as getFormField, getItemProp, getNativeRules, getRules, getTextByName, getTypeMatchRule, initValue, isFieldInnerConfigError, isLeafFieldType, isValidName, mergeFieldOptions, mergeFormContexts, optionSuggestion, registerBuiltInFields, registerField, registerFields, resolveItemType, sortArray, sortChange, stringifyExampleValue, submitForm, unregisterField, validateForm, validateTypeMatch, validateValues };
|
|
680
|
+
}
|
|
681
|
+
//#endregion
|
|
682
|
+
export { type CollectedField, type FieldInnerConfig, type FieldInnerConfigContext, type FieldInnerConfigResult, type FieldMountValueEffect, type FieldMountValueEffectContext, type FieldOptions, type HeadlessFieldOptions, type HeadlessFormStateOptions, type SubmitFormOptions, type SubmitFormResult, type TypeMatchValidateContext, type TypeMatchValidator, type ValidateFormOptions, type ValidateValuesOptions, type ValidateValuesResult, getField as getFormField };
|