@1money/component-ui 0.0.74 → 0.0.76
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/es/components/Dialog/Dialog.js +7 -39
- package/es/components/Dialog/constants.d.ts +0 -3
- package/es/components/Dialog/constants.js +1 -4
- package/es/components/Dialog/style/Dialog.css +0 -21
- package/es/components/ProForm/ProForm.js +46 -33
- package/es/components/ProForm/ProFormDependency.js +6 -16
- package/es/components/ProForm/ProFormItem.js +5 -7
- package/es/components/ProForm/ProFormList.js +112 -40
- package/es/components/ProForm/core/constants.d.ts +2 -0
- package/es/components/ProForm/core/constants.js +7 -1
- package/es/components/ProForm/core/devWarning.d.ts +3 -0
- package/es/components/ProForm/core/devWarning.js +22 -0
- package/es/components/ProForm/core/formStore.d.ts +10 -2
- package/es/components/ProForm/core/formStore.js +21 -2
- package/es/components/ProForm/core/hooks/useForm.js +246 -103
- package/es/components/ProForm/core/hooks/useFormCore.js +134 -28
- package/es/components/ProForm/core/interface.d.ts +124 -49
- package/es/components/ProForm/core/runRules.d.ts +44 -12
- package/es/components/ProForm/core/runRules.js +584 -133
- package/es/components/ProForm/core/useFormItem.d.ts +6 -7
- package/es/components/ProForm/core/useFormItem.js +44 -22
- package/es/components/ProForm/core/validationError.d.ts +13 -0
- package/es/components/ProForm/core/validationError.js +29 -0
- package/es/components/ProForm/fields/ProFormCheckboxGroup.js +19 -5
- package/es/components/ProForm/fields/ProFormFieldSet.js +51 -12
- package/es/components/ProForm/fields/ProFormRadioGroup.js +8 -3
- package/es/components/ProForm/fields/ProFormSelect.js +13 -7
- package/es/components/ProForm/fields/createProFormField.js +18 -25
- package/es/components/ProForm/hooks/useFieldRequest.js +10 -8
- package/es/components/ProForm/index.d.ts +2 -1
- package/es/components/ProForm/index.js +4 -1
- package/es/components/ProForm/interface.d.ts +31 -40
- package/es/components/ProForm/layouts/QueryFilter.js +24 -16
- package/es/components/ProForm/style/ProForm.css +0 -1
- package/es/components/ProForm/utils.d.ts +8 -0
- package/es/components/ProForm/utils.js +51 -3
- package/es/components/Table/core/useTableSetup.js +2 -2
- package/es/components/Table/interface.d.ts +1 -1
- package/es/index.css +1 -1
- package/lib/components/Dialog/Dialog.js +6 -38
- package/lib/components/Dialog/constants.d.ts +0 -3
- package/lib/components/Dialog/constants.js +1 -4
- package/lib/components/Dialog/style/Dialog.css +0 -21
- package/lib/components/ProForm/ProForm.js +45 -32
- package/lib/components/ProForm/ProFormDependency.js +5 -15
- package/lib/components/ProForm/ProFormItem.js +5 -7
- package/lib/components/ProForm/ProFormList.js +110 -38
- package/lib/components/ProForm/core/constants.d.ts +2 -0
- package/lib/components/ProForm/core/constants.js +8 -2
- package/lib/components/ProForm/core/devWarning.d.ts +3 -0
- package/lib/components/ProForm/core/devWarning.js +29 -0
- package/lib/components/ProForm/core/formStore.d.ts +10 -2
- package/lib/components/ProForm/core/formStore.js +23 -2
- package/lib/components/ProForm/core/hooks/useForm.js +242 -99
- package/lib/components/ProForm/core/hooks/useFormCore.js +133 -27
- package/lib/components/ProForm/core/interface.d.ts +124 -49
- package/lib/components/ProForm/core/runRules.d.ts +44 -12
- package/lib/components/ProForm/core/runRules.js +587 -133
- package/lib/components/ProForm/core/useFormItem.d.ts +6 -7
- package/lib/components/ProForm/core/useFormItem.js +43 -21
- package/lib/components/ProForm/core/validationError.d.ts +13 -0
- package/lib/components/ProForm/core/validationError.js +36 -0
- package/lib/components/ProForm/fields/ProFormCheckboxGroup.js +18 -4
- package/lib/components/ProForm/fields/ProFormFieldSet.js +51 -12
- package/lib/components/ProForm/fields/ProFormRadioGroup.js +7 -2
- package/lib/components/ProForm/fields/ProFormSelect.js +13 -7
- package/lib/components/ProForm/fields/createProFormField.js +18 -25
- package/lib/components/ProForm/hooks/useFieldRequest.js +10 -8
- package/lib/components/ProForm/index.d.ts +2 -1
- package/lib/components/ProForm/index.js +10 -1
- package/lib/components/ProForm/interface.d.ts +31 -40
- package/lib/components/ProForm/layouts/QueryFilter.js +24 -16
- package/lib/components/ProForm/style/ProForm.css +0 -1
- package/lib/components/ProForm/utils.d.ts +8 -0
- package/lib/components/ProForm/utils.js +52 -3
- package/lib/components/Table/core/useTableSetup.js +2 -2
- package/lib/components/Table/interface.d.ts +1 -1
- package/lib/index.css +1 -1
- package/package.json +1 -1
- package/scripts/mcp-server/examples.generated.json +42 -36
- package/scripts/mcp-server/index.generated.json +23 -67
|
@@ -1,39 +1,101 @@
|
|
|
1
1
|
import type React from 'react';
|
|
2
2
|
import type { FC, ReactNode } from 'react';
|
|
3
3
|
import type { FormSize, FormLayout, LabelAlign, ValidateStatus, ValidateTrigger } from './constants';
|
|
4
|
+
import { RULE_CONTEXT_READ_MEMBERS, RULE_CONTEXT_MUTATOR_MEMBERS } from './constants';
|
|
4
5
|
export type { FormSize, FormLayout, LabelAlign, ValidateStatus, ValidateTrigger, };
|
|
6
|
+
/** Built-in `type` check names. */
|
|
7
|
+
export type RuleType = 'string' | 'number' | 'boolean' | 'method' | 'regexp' | 'integer' | 'float' | 'object' | 'array' | 'date' | 'url' | 'hex' | 'email' | 'enum';
|
|
5
8
|
export interface Rule {
|
|
6
9
|
/** Fails on undefined / null / '' / empty array */
|
|
7
10
|
required?: boolean;
|
|
8
|
-
|
|
11
|
+
/** Error content shown on failure — any ReactNode (falls back to a generated string) */
|
|
12
|
+
message?: ReactNode;
|
|
9
13
|
/** For strings: min length; arrays: min item count; numbers: min value */
|
|
10
14
|
min?: number;
|
|
11
15
|
/** For strings: max length; arrays: max item count; numbers: max value */
|
|
12
16
|
max?: number;
|
|
17
|
+
/** Exact string length / array item count / numeric value. Takes precedence over min/max */
|
|
18
|
+
len?: number;
|
|
13
19
|
pattern?: RegExp;
|
|
14
|
-
type?:
|
|
20
|
+
type?: RuleType;
|
|
15
21
|
enum?: unknown[];
|
|
22
|
+
/** Fails a non-empty string consisting only of whitespace */
|
|
23
|
+
whitespace?: boolean;
|
|
24
|
+
/** Transform the value before every check (builtin and validator) of THIS rule */
|
|
25
|
+
transform?: (value: unknown) => unknown;
|
|
26
|
+
/** Deep rule(s) applied to every member of an array/object value */
|
|
27
|
+
defaultField?: Rule | Rule[];
|
|
28
|
+
/** Deep rules applied per key of an object/array value */
|
|
29
|
+
fields?: Record<string, Rule | Rule[]>;
|
|
16
30
|
/** A failing rule produces a non-blocking warning instead of an error */
|
|
17
31
|
warningOnly?: boolean;
|
|
18
32
|
/**
|
|
19
|
-
* Run this rule only on the given interactive
|
|
20
|
-
*
|
|
33
|
+
* Run this rule only on the given interactive event(s). It
|
|
34
|
+
* must be a subset of the item's effective triggers to fire interactively.
|
|
35
|
+
* Rules without it run on every effective trigger. Submit always runs
|
|
36
|
+
* every rule.
|
|
21
37
|
*/
|
|
22
38
|
validateTrigger?: ValidateTrigger | ValidateTrigger[];
|
|
23
|
-
|
|
39
|
+
/**
|
|
40
|
+
* Custom validator: resolve (or return undefined) to pass,
|
|
41
|
+
* reject/throw to fail. The failure message is taken from the rejection
|
|
42
|
+
* (Error.message or a plain string), then `rule.message`, then a generic
|
|
43
|
+
* fallback. Return values are ignored — returning `false` or a string does
|
|
44
|
+
* NOT fail the rule.
|
|
45
|
+
*/
|
|
46
|
+
validator?: (rule: Rule, value: unknown) => Promise<void> | void;
|
|
24
47
|
}
|
|
48
|
+
/**
|
|
49
|
+
* Form/Item-level validateTrigger config: a single event, a
|
|
50
|
+
* list of events, or `false` to disable interactive validation entirely
|
|
51
|
+
* (submit / validateFields still run every rule). Item-level overrides
|
|
52
|
+
* form-level.
|
|
53
|
+
*/
|
|
54
|
+
export type ValidateTriggerProp = ValidateTrigger | ValidateTrigger[] | false;
|
|
55
|
+
/**
|
|
56
|
+
* The form context handed to function-form rules. The read helpers are
|
|
57
|
+
* always available (derived from the validation-time value snapshot). The
|
|
58
|
+
* remaining members are backed by the live form instance and are present
|
|
59
|
+
* whenever rules run inside a mounted form — they are only absent when the
|
|
60
|
+
* pure rule engine is invoked directly without an instance.
|
|
61
|
+
*/
|
|
62
|
+
export interface RuleContext {
|
|
63
|
+
getFieldValue: (name: string) => unknown;
|
|
64
|
+
getFieldsValue: () => Record<string, unknown>;
|
|
65
|
+
setFieldValue?: (name: string, value: unknown) => void;
|
|
66
|
+
setFieldsValue?: (values: Record<string, unknown>) => void;
|
|
67
|
+
resetFields?: () => void;
|
|
68
|
+
getFieldError?: (name: string) => ReactNode | undefined;
|
|
69
|
+
getFieldWarning?: (name: string) => ReactNode | undefined;
|
|
70
|
+
isFieldTouched?: (name: string) => boolean;
|
|
71
|
+
isFieldValidating?: (name: string) => boolean;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* A rule entry as consumers write it: a static Rule, or — for cross-field
|
|
75
|
+
* validation — a function of the form context returning a Rule (the
|
|
76
|
+
* `({ getFieldValue }) => ({ validator })` idiom).
|
|
77
|
+
*/
|
|
78
|
+
export type FormRule = Rule | ((ctx: RuleContext) => Rule);
|
|
79
|
+
export type RuleContextReadMember = (typeof RULE_CONTEXT_READ_MEMBERS)[number];
|
|
80
|
+
export type RuleContextMutatorMember = (typeof RULE_CONTEXT_MUTATOR_MEMBERS)[number];
|
|
81
|
+
type AssertRuleContextMembers<T extends keyof RuleContext> = T;
|
|
82
|
+
/**
|
|
83
|
+
* Compile-time guard: the member lists in constants.ts must stay subsets of
|
|
84
|
+
* RuleContext — renaming or removing a member there breaks this line.
|
|
85
|
+
*/
|
|
86
|
+
export type RuleContextInstanceMember = AssertRuleContextMembers<RuleContextReadMember | RuleContextMutatorMember>;
|
|
25
87
|
export interface FieldProps {
|
|
26
88
|
name: string;
|
|
27
89
|
value: unknown;
|
|
28
|
-
error?:
|
|
90
|
+
error?: ReactNode;
|
|
29
91
|
touched?: boolean;
|
|
30
92
|
validating?: boolean;
|
|
31
93
|
onChange: (value: unknown) => void;
|
|
32
94
|
onBlur: () => void;
|
|
33
95
|
}
|
|
34
96
|
export interface FieldOptions {
|
|
35
|
-
rules?:
|
|
36
|
-
validateTrigger?:
|
|
97
|
+
rules?: FormRule[];
|
|
98
|
+
validateTrigger?: ValidateTriggerProp;
|
|
37
99
|
}
|
|
38
100
|
export interface FieldComponentProps {
|
|
39
101
|
children: ReactNode | ((props: FieldProps) => ReactNode);
|
|
@@ -44,14 +106,14 @@ export interface FormCoreInstance {
|
|
|
44
106
|
submit: () => {
|
|
45
107
|
success: boolean;
|
|
46
108
|
values?: Record<string, unknown>;
|
|
47
|
-
errors?: Record<string,
|
|
109
|
+
errors?: Record<string, ReactNode>;
|
|
48
110
|
};
|
|
49
111
|
resetFields: () => void;
|
|
50
112
|
getFieldValue: (name: string) => unknown;
|
|
51
113
|
getFieldsValue: () => Record<string, unknown>;
|
|
52
114
|
setFieldsValue: (values: Record<string, unknown>) => void;
|
|
53
115
|
setFieldValue: (name: string, value: unknown) => void;
|
|
54
|
-
validateFields: (fieldsRules?: Record<string,
|
|
116
|
+
validateFields: (fieldsRules?: Record<string, FormRule[]>) => boolean;
|
|
55
117
|
}
|
|
56
118
|
/**
|
|
57
119
|
* Full form instance returned by useForm — extends FormCoreInstance with async
|
|
@@ -63,84 +125,84 @@ export interface FormInstance<Values = Record<string, unknown>> {
|
|
|
63
125
|
getFieldsValue: (nameList?: string[]) => Values;
|
|
64
126
|
setFieldValue: (name: string, value: unknown) => void;
|
|
65
127
|
setFieldsValue: (values: Partial<Values>) => void;
|
|
66
|
-
setFieldError: (name: string, error:
|
|
67
|
-
setFieldsError: (errors: Record<string,
|
|
128
|
+
setFieldError: (name: string, error: ReactNode | null) => void;
|
|
129
|
+
setFieldsError: (errors: Record<string, ReactNode>) => void;
|
|
68
130
|
resetFields: (fields?: string[]) => void;
|
|
69
131
|
validateFields: (nameList?: string[]) => Promise<Values>;
|
|
70
132
|
submit: (callback?: (values: Values) => void | Promise<void>) => Promise<Values | undefined>;
|
|
71
|
-
getFieldError: (name: string) =>
|
|
72
|
-
getFieldsError: (nameList?: string[]) => Record<string,
|
|
73
|
-
getFieldWarning: (name: string) =>
|
|
133
|
+
getFieldError: (name: string) => ReactNode | undefined;
|
|
134
|
+
getFieldsError: (nameList?: string[]) => Record<string, ReactNode>;
|
|
135
|
+
getFieldWarning: (name: string) => ReactNode | undefined;
|
|
74
136
|
isFieldTouched: (name: string) => boolean;
|
|
75
137
|
isFieldsTouched: (nameList?: string[], allTouched?: boolean) => boolean;
|
|
76
138
|
isFieldValidating: (name: string) => boolean;
|
|
77
139
|
setFieldTouched: (name: string, isTouched?: boolean) => void;
|
|
78
140
|
setFieldsTouched: (touched: Record<string, boolean>) => void;
|
|
79
141
|
defineField: (name: string, options?: FieldOptions) => FC<FieldComponentProps>;
|
|
80
|
-
registerField: (name: string, rules:
|
|
142
|
+
registerField: (name: string, rules: FormRule[]) => void;
|
|
81
143
|
unregisterField: (name: string) => void;
|
|
82
144
|
}
|
|
83
145
|
export interface UseFormOptions {
|
|
84
146
|
onValuesChange?: (changedValues: Record<string, unknown>, allValues: Record<string, unknown>) => void;
|
|
85
|
-
validateTrigger?:
|
|
86
|
-
rules?: Record<string,
|
|
147
|
+
validateTrigger?: ValidateTriggerProp;
|
|
148
|
+
rules?: Record<string, FormRule[]>;
|
|
87
149
|
}
|
|
88
150
|
export interface UseFormCoreConfig<Values = Record<string, unknown>> {
|
|
89
151
|
initialValues?: Partial<Values>;
|
|
90
152
|
onFinish?: (values: Values) => void;
|
|
91
153
|
onFinishFailed?: (errorInfo: {
|
|
92
154
|
values: Values;
|
|
93
|
-
errors: Record<string,
|
|
155
|
+
errors: Record<string, ReactNode>;
|
|
94
156
|
}) => void;
|
|
95
157
|
onValuesChange?: (changedValues: Partial<Values>, allValues: Values) => void;
|
|
96
158
|
onReset?: () => void;
|
|
97
159
|
size?: FormSize;
|
|
98
160
|
labelAlign?: LabelAlign;
|
|
99
161
|
disabled?: boolean;
|
|
100
|
-
|
|
101
|
-
requiredMark?: boolean;
|
|
102
|
-
validateTrigger?: ValidateTrigger;
|
|
162
|
+
validateTrigger?: ValidateTriggerProp;
|
|
103
163
|
}
|
|
104
164
|
/** Internal shape of data produced by useFormCore, consumed by ProForm to build ProFormContext */
|
|
105
165
|
export interface FormCoreContextShape {
|
|
106
166
|
values: Record<string, unknown>;
|
|
107
|
-
errors: Record<string,
|
|
108
|
-
warnings: Record<string,
|
|
167
|
+
errors: Record<string, ReactNode>;
|
|
168
|
+
warnings: Record<string, ReactNode>;
|
|
109
169
|
touched: Record<string, boolean>;
|
|
110
170
|
formInstance: FormCoreInstance;
|
|
111
171
|
setFieldValue: (name: string, value: unknown) => void;
|
|
112
|
-
setFieldError: (name: string, error:
|
|
113
|
-
setFieldWarning: (name: string, warning:
|
|
114
|
-
validateField: (name: string, rules:
|
|
115
|
-
registerField: (name: string, rules:
|
|
172
|
+
setFieldError: (name: string, error: ReactNode | null) => void;
|
|
173
|
+
setFieldWarning: (name: string, warning: ReactNode | null) => void;
|
|
174
|
+
validateField: (name: string, rules: FormRule[], providedValue?: unknown) => boolean;
|
|
175
|
+
registerField: (name: string, rules: FormRule[]) => void;
|
|
116
176
|
unregisterField: (name: string) => void;
|
|
117
177
|
size: FormSize;
|
|
118
178
|
labelAlign: LabelAlign;
|
|
119
179
|
disabled: boolean;
|
|
120
|
-
|
|
121
|
-
requiredMark: boolean;
|
|
122
|
-
validateTrigger: ValidateTrigger;
|
|
180
|
+
validateTrigger: ValidateTriggerProp;
|
|
123
181
|
}
|
|
124
182
|
/** Config for useForm — accepts all UseFormCoreConfig fields */
|
|
125
183
|
export type UseFormConfig<Values = Record<string, unknown>> = UseFormCoreConfig<Values>;
|
|
126
184
|
/** Internal state exposed by useForm for ProForm integration */
|
|
127
185
|
export interface UseFormInternals {
|
|
128
186
|
values: Record<string, unknown>;
|
|
129
|
-
errors: Record<string,
|
|
130
|
-
warnings: Record<string,
|
|
187
|
+
errors: Record<string, ReactNode>;
|
|
188
|
+
warnings: Record<string, ReactNode>;
|
|
131
189
|
touched: Record<string, boolean>;
|
|
132
190
|
validating: Record<string, boolean>;
|
|
133
|
-
fieldRules: Record<string,
|
|
191
|
+
fieldRules: Record<string, FormRule[]>;
|
|
134
192
|
setFieldValue: (name: string, value: unknown) => void;
|
|
135
|
-
setFieldError: (name: string, error:
|
|
136
|
-
setFieldWarning: (name: string, warning:
|
|
137
|
-
validateField: (name: string, rules:
|
|
138
|
-
validateFieldAsync: (name: string, value: unknown, rules:
|
|
193
|
+
setFieldError: (name: string, error: ReactNode | null) => void;
|
|
194
|
+
setFieldWarning: (name: string, warning: ReactNode | null) => void;
|
|
195
|
+
validateField: (name: string, rules: FormRule[], providedValue?: unknown) => boolean;
|
|
196
|
+
validateFieldAsync: (name: string, value: unknown, rules: FormRule[]) => Promise<{
|
|
139
197
|
isValid: boolean;
|
|
140
|
-
error:
|
|
198
|
+
error: ReactNode | null;
|
|
141
199
|
}>;
|
|
142
|
-
registerField: (name: string, rules:
|
|
200
|
+
registerField: (name: string, rules: FormRule[]) => void;
|
|
143
201
|
unregisterField: (name: string) => void;
|
|
202
|
+
/** Count a mounted instance for `name` — pair with `releaseField` on unmount. */
|
|
203
|
+
retainField: (name: string) => void;
|
|
204
|
+
/** Drop one instance count; the field's rules are removed only at zero. */
|
|
205
|
+
releaseField: (name: string) => void;
|
|
144
206
|
handleSubmit: (e?: React.FormEvent) => void;
|
|
145
207
|
handleReset: (e?: React.FormEvent) => void;
|
|
146
208
|
}
|
|
@@ -151,21 +213,34 @@ export interface UseFormReturn {
|
|
|
151
213
|
}
|
|
152
214
|
export interface UseFormCoreReturn {
|
|
153
215
|
values: Record<string, unknown>;
|
|
154
|
-
errors: Record<string,
|
|
155
|
-
warnings: Record<string,
|
|
216
|
+
errors: Record<string, ReactNode>;
|
|
217
|
+
warnings: Record<string, ReactNode>;
|
|
156
218
|
touched: Record<string, boolean>;
|
|
157
|
-
fieldRules: Record<string,
|
|
158
|
-
getFieldRules: (name: string) =>
|
|
219
|
+
fieldRules: Record<string, FormRule[]>;
|
|
220
|
+
getFieldRules: (name: string) => FormRule[] | undefined;
|
|
221
|
+
/** Instance handed to function-form rules; useForm upgrades it to the full form instance. */
|
|
222
|
+
getRuleContextInstance: () => Partial<RuleContext>;
|
|
223
|
+
setRuleContextInstance: (instance: Partial<RuleContext>) => void;
|
|
224
|
+
/** Bump and return the field's validation epoch — every run captures one. */
|
|
225
|
+
beginValidationRun: (name: string) => number;
|
|
226
|
+
/** True while no newer run has started for the field since `epoch` was issued. */
|
|
227
|
+
isValidationRunCurrent: (name: string, epoch: number) => boolean;
|
|
228
|
+
/** Invalidate in-flight runs (all fields, or the given ones) — e.g. on reset. */
|
|
229
|
+
invalidateValidationRuns: (names?: string[]) => void;
|
|
159
230
|
setFieldValue: (name: string, value: unknown) => void;
|
|
160
|
-
setFieldError: (name: string, error:
|
|
161
|
-
setFieldWarning: (name: string, warning:
|
|
231
|
+
setFieldError: (name: string, error: ReactNode | null) => void;
|
|
232
|
+
setFieldWarning: (name: string, warning: ReactNode | null) => void;
|
|
162
233
|
setFieldsValue: (values: Record<string, unknown>) => void;
|
|
163
234
|
getFieldValue: (name: string) => unknown;
|
|
164
235
|
getFieldsValue: () => Record<string, unknown>;
|
|
165
|
-
validateField: (name: string, rules:
|
|
166
|
-
validateFields: (fieldsRules?: Record<string,
|
|
167
|
-
registerField: (name: string, rules:
|
|
236
|
+
validateField: (name: string, rules: FormRule[], providedValue?: unknown) => boolean;
|
|
237
|
+
validateFields: (fieldsRules?: Record<string, FormRule[]>) => boolean;
|
|
238
|
+
registerField: (name: string, rules: FormRule[]) => void;
|
|
168
239
|
unregisterField: (name: string) => void;
|
|
240
|
+
/** Count a mounted instance for `name` — pair with `releaseField` on unmount. */
|
|
241
|
+
retainField: (name: string) => void;
|
|
242
|
+
/** Drop one instance count; the field's rules are removed only at zero. */
|
|
243
|
+
releaseField: (name: string) => void;
|
|
169
244
|
handleSubmit: (e?: React.FormEvent) => void;
|
|
170
245
|
handleReset: (e?: React.FormEvent) => void;
|
|
171
246
|
resetFields: () => void;
|
|
@@ -1,25 +1,57 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { ReactNode } from 'react';
|
|
2
|
+
import type { FormRule, Rule, RuleContext, ValidateTrigger, ValidateTriggerProp } from './interface';
|
|
2
3
|
export interface RuleRunResult {
|
|
3
|
-
error:
|
|
4
|
-
warning:
|
|
4
|
+
error: ReactNode | null;
|
|
5
|
+
warning: ReactNode | null;
|
|
5
6
|
}
|
|
6
7
|
/**
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
* Submit-time validation bypasses this filter and runs every rule.
|
|
8
|
+
* Coerce a thrown/rejected reason into displayable failure content:
|
|
9
|
+
* a non-empty Error.message or a non-empty plain string — otherwise null
|
|
10
|
+
* (caller picks its fallback). Shared with the form-level last-resort nets.
|
|
11
11
|
*/
|
|
12
|
-
export declare function
|
|
12
|
+
export declare function coerceFailureReason(reason: unknown): ReactNode | null;
|
|
13
|
+
/**
|
|
14
|
+
* Resolve function-form rules into static rules. The
|
|
15
|
+
* context exposes the value snapshot the run was invoked with; function rules
|
|
16
|
+
* must be cheap and side-effect free — they may be resolved more than once
|
|
17
|
+
* per validation pass.
|
|
18
|
+
*/
|
|
19
|
+
export declare function resolveRules(rules: FormRule[], values: Record<string, unknown>, instance?: Partial<RuleContext>): Rule[];
|
|
20
|
+
/**
|
|
21
|
+
* Normalize a form/item-level validateTrigger config into the effective
|
|
22
|
+
* interactive event list: item-level (when present) overrides form-level;
|
|
23
|
+
* `false` disables interactive validation entirely.
|
|
24
|
+
*/
|
|
25
|
+
export declare function normalizeTriggers(itemTrigger: ValidateTriggerProp | undefined, formTrigger: ValidateTriggerProp): ValidateTrigger[];
|
|
26
|
+
/**
|
|
27
|
+
* Filter rules applicable to an interactive event: the event
|
|
28
|
+
* validates only when it is in the item's effective trigger set. Within the
|
|
29
|
+
* set, a rule WITHOUT `validateTrigger` runs on every event; a rule WITH one
|
|
30
|
+
* runs only on matching events — so a rule trigger outside the item's set
|
|
31
|
+
* never fires interactively. Submit-time validation bypasses this filter and
|
|
32
|
+
* runs every rule.
|
|
33
|
+
*
|
|
34
|
+
* Dev guard: a rule whose (non-empty) trigger set is fully OUTSIDE the
|
|
35
|
+
* active set can never fire interactively — usually a leftover of the
|
|
36
|
+
* pre-0.0.76 override semantics, so it warns once. `validateTrigger: []`
|
|
37
|
+
* is the deliberate submit-only idiom and stays silent.
|
|
38
|
+
*/
|
|
39
|
+
export declare function filterRulesByTrigger(rules: Rule[], trigger: ValidateTrigger, activeTriggers: ValidateTrigger[], fieldName?: string): Rule[];
|
|
13
40
|
/**
|
|
14
41
|
* Synchronous rule run. A Promise-returning validator CANNOT be evaluated
|
|
15
42
|
* here — it is deferred (treated as passing for this run; its rejection is
|
|
16
43
|
* swallowed) and left to the async runs (blur/submit), which always await it.
|
|
17
44
|
* Failing it instead would mis-report "Validation failed" on every keystroke
|
|
18
45
|
* for perfectly valid input.
|
|
46
|
+
*
|
|
47
|
+
* The per-rule try/catch is the engine's totality choke point: NO input —
|
|
48
|
+
* including exotic values that break a builtin check — may escape as a throw;
|
|
49
|
+
* every failure surfaces through the error/warning channels.
|
|
19
50
|
*/
|
|
20
|
-
export declare function runRulesSync(name: string, value: unknown, values: Record<string, unknown>, rules:
|
|
51
|
+
export declare function runRulesSync(name: string, value: unknown, values: Record<string, unknown>, rules: FormRule[], instance?: Partial<RuleContext>): RuleRunResult;
|
|
21
52
|
/**
|
|
22
|
-
* Asynchronous rule run. Custom validators are awaited (sync or async)
|
|
23
|
-
*
|
|
53
|
+
* Asynchronous rule run. Custom validators are awaited (sync or async):
|
|
54
|
+
* resolving passes, rejecting/throwing fails. Return values are ignored.
|
|
55
|
+
* Shares the totality choke point with runRulesSync.
|
|
24
56
|
*/
|
|
25
|
-
export declare function runRulesAsync(name: string, value: unknown, values: Record<string, unknown>, rules:
|
|
57
|
+
export declare function runRulesAsync(name: string, value: unknown, values: Record<string, unknown>, rules: FormRule[], instance?: Partial<RuleContext>): Promise<RuleRunResult>;
|