@ahrowe/ui 0.1.4 → 0.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +59 -40
- package/dist/index.mjs.map +1 -1
- package/dist/types/package/services/formValidation/FormValidatorGroupWithForm.d.ts +3 -0
- package/dist/types/package/services/formValidation/formValidatorGroup.d.ts +8 -2
- package/dist/types/package/services/formValidation/useFormValidatorGroup.d.ts +5 -2
- package/package.json +2 -2
- /package/dist/{mcp → mcp.js} +0 -0
|
@@ -6,6 +6,9 @@ import { default as React } from 'react';
|
|
|
6
6
|
*
|
|
7
7
|
* This is the class you should use everywhere — it is a drop-in replacement
|
|
8
8
|
* for FormValidatorGroup with one extra property: `this.Form`.
|
|
9
|
+
*
|
|
10
|
+
* Also injects the default toast-based onSubmitError so both hook and class-component
|
|
11
|
+
* consumers surface errors out of the box; pass options.onSubmitError to override.
|
|
9
12
|
*/
|
|
10
13
|
export default class FormValidatorGroupWithForm<TGroup extends FormGroup = FormGroup, TInitial = InferGroupValues<TGroup>> extends FormValidatorGroup<TGroup, TInitial> {
|
|
11
14
|
Form: React.FC<React.FormHTMLAttributes<HTMLFormElement>>;
|
|
@@ -16,6 +16,7 @@ export interface FormValidatorGroupOptions<TGroup extends FormGroup = FormGroup,
|
|
|
16
16
|
onSubmit?: (values: MergedValues<TInitial, TGroup>, group: FormValidatorGroup<TGroup, TInitial>) => Promise<void> | void;
|
|
17
17
|
onValidate?: (group: FormValidatorGroup<TGroup, TInitial>) => ValidationError | null | void;
|
|
18
18
|
errorParser?: ErrorParser;
|
|
19
|
+
onSubmitError?: (errors: ValidationError[]) => void;
|
|
19
20
|
}
|
|
20
21
|
interface ComponentLike {
|
|
21
22
|
forceUpdate: () => void;
|
|
@@ -27,6 +28,7 @@ export default class FormValidatorGroup<TGroup extends FormGroup = FormGroup, TI
|
|
|
27
28
|
onSubmitCallback: (values: MergedValues<TInitial, TGroup>, group: FormValidatorGroup<TGroup, TInitial>) => Promise<void> | void;
|
|
28
29
|
onValidateCallback: (group: FormValidatorGroup<TGroup, TInitial>) => ValidationError | null | void;
|
|
29
30
|
errorParser: ErrorParser;
|
|
31
|
+
onSubmitError: (errors: ValidationError[]) => void;
|
|
30
32
|
submitCount: number;
|
|
31
33
|
onDebounce: (values: MergedValues<TInitial, TGroup>) => void;
|
|
32
34
|
onReset: (group: FormValidatorGroup<TGroup, TInitial>, valuesAfterCreation: FormValues, initialValues: TInitial) => void;
|
|
@@ -35,7 +37,7 @@ export default class FormValidatorGroup<TGroup extends FormGroup = FormGroup, TI
|
|
|
35
37
|
* @param component - Class component instance for forceUpdate (pass null when using hooks)
|
|
36
38
|
* @param options - initialValues, onSubmit, onValidate, errorParser
|
|
37
39
|
*/
|
|
38
|
-
constructor(formValidatorGroup: TGroup, component?: ComponentLike | null, { initialValues, onSubmit, onValidate, errorParser, }?: FormValidatorGroupOptions<TGroup, TInitial>);
|
|
40
|
+
constructor(formValidatorGroup: TGroup, component?: ComponentLike | null, { initialValues, onSubmit, onValidate, errorParser, onSubmitError, }?: FormValidatorGroupOptions<TGroup, TInitial>);
|
|
39
41
|
get isSubmitting(): boolean;
|
|
40
42
|
get wasTouched(): boolean;
|
|
41
43
|
get isDirty(): boolean;
|
|
@@ -45,7 +47,11 @@ export default class FormValidatorGroup<TGroup extends FormGroup = FormGroup, TI
|
|
|
45
47
|
set: (validatorName: keyof TGroup & string, value: unknown) => this;
|
|
46
48
|
reset: (toOverride?: FormValues) => void;
|
|
47
49
|
resetDirtyAndTouched: () => void;
|
|
48
|
-
/**
|
|
50
|
+
/**
|
|
51
|
+
* Parses an API error and pushes field-level errors into the matching validators.
|
|
52
|
+
* When field errors are found and isInternal is set, surfaces the first field message.
|
|
53
|
+
* When the error shape isn't recognised (no field errors), always surfaces a generic message.
|
|
54
|
+
*/
|
|
49
55
|
parseError: (err: unknown, isInternal?: boolean) => void;
|
|
50
56
|
registerOnUpdateListener: (callback: UpdateListener) => void;
|
|
51
57
|
removeOnUpdateListener: (callback: UpdateListener) => void;
|
|
@@ -8,8 +8,11 @@ import { FormGroup, FormValidatorGroupOptions, InferGroupValues } from './formVa
|
|
|
8
8
|
* onSubmit / onValidate are kept fresh via refs — they always reflect the latest
|
|
9
9
|
* closure without needing to be listed in effect dependencies.
|
|
10
10
|
*
|
|
11
|
+
* onSubmitError defaults to showing the message as an error toast (provided by FormValidatorGroupWithForm);
|
|
12
|
+
* pass options.onSubmitError to override.
|
|
13
|
+
*
|
|
11
14
|
* @param groupDef - Map of field name → FormValidator instance
|
|
12
|
-
* @param options - initialValues, onSubmit, onValidate, errorParser
|
|
15
|
+
* @param options - initialValues, onSubmit, onValidate, errorParser, onSubmitError
|
|
13
16
|
*
|
|
14
17
|
* @example
|
|
15
18
|
* const form = useFormValidatorGroup(
|
|
@@ -20,4 +23,4 @@ import { FormGroup, FormValidatorGroupOptions, InferGroupValues } from './formVa
|
|
|
20
23
|
* },
|
|
21
24
|
* );
|
|
22
25
|
*/
|
|
23
|
-
export declare function useFormValidatorGroup<TGroup extends FormGroup = FormGroup, TInitial = InferGroupValues<TGroup>>(groupDef: TGroup, { initialValues, onSubmit, onValidate, errorParser }?: FormValidatorGroupOptions<TGroup, TInitial>): FormValidatorGroup<TGroup, TInitial>;
|
|
26
|
+
export declare function useFormValidatorGroup<TGroup extends FormGroup = FormGroup, TInitial = InferGroupValues<TGroup>>(groupDef: TGroup, { initialValues, onSubmit, onValidate, errorParser, onSubmitError }?: FormValidatorGroupOptions<TGroup, TInitial>): FormValidatorGroup<TGroup, TInitial>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ahrowe/ui",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.5",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
},
|
|
38
38
|
"style": "./dist/style.css",
|
|
39
39
|
"bin": {
|
|
40
|
-
"ahrowe-ui-mcp": "./dist/mcp"
|
|
40
|
+
"ahrowe-ui-mcp": "./dist/mcp.js"
|
|
41
41
|
},
|
|
42
42
|
"files": [
|
|
43
43
|
"dist",
|
/package/dist/{mcp → mcp.js}
RENAMED
|
File without changes
|