@paragrav/rhf-utils 0.0.21 → 0.0.22
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/package.json +33 -50
- package/dist/cjs/errors/flattenFieldErrors.d.ts +0 -14
- package/dist/cjs/errors/flattenFieldErrors.js +0 -16
- package/dist/cjs/errors/getFlatFieldErrors.d.ts +0 -24
- package/dist/cjs/errors/getFlatFieldErrors.js +0 -49
- package/dist/cjs/errors/nonfield/FormNonFieldErrorMarker.js +0 -18
- package/dist/cjs/errors/nonfield/FormNonFieldErrorMarker.spec.js +0 -15
- package/dist/cjs/errors/nonfield/FormNonFieldErrorMarker.utils.js +0 -13
- package/dist/cjs/errors/nonfield/utils.d.ts +0 -17
- package/dist/cjs/errors/nonfield/utils.js +0 -20
- package/dist/cjs/errors/orphan/useFormErrorsHasOnlyOrphans.js +0 -19
- package/dist/cjs/errors/orphan/useOrphanFormErrors.d.ts +0 -3
- package/dist/cjs/errors/orphan/useOrphanFormErrors.js +0 -18
- package/dist/cjs/errors/orphan/useOrphanFormErrorsToConsoleError.d.ts +0 -7
- package/dist/cjs/errors/orphan/useOrphanFormErrorsToConsoleError.js +0 -27
- package/dist/cjs/errors/orphan/utils.d.ts +0 -3
- package/dist/cjs/errors/orphan/utils.js +0 -21
- package/dist/cjs/errors/root/useRootFormFieldErrors.d.ts +0 -6
- package/dist/cjs/errors/root/useRootFormFieldErrors.js +0 -13
- package/dist/cjs/errors/root/utils.d.ts +0 -11
- package/dist/cjs/errors/root/utils.js +0 -24
- package/dist/cjs/errors/useFormErrorConsoleDebug.js +0 -22
- package/dist/cjs/errors/useFormErrorsEffect.d.ts +0 -3
- package/dist/cjs/errors/useFormErrorsEffect.js +0 -14
- package/dist/cjs/errors/useFormErrorsIfAny.d.ts +0 -6
- package/dist/cjs/errors/useFormErrorsIfAny.js +0 -13
- package/dist/cjs/errors/useFormErrorsOnChange.d.ts +0 -6
- package/dist/cjs/errors/useFormErrorsOnChange.js +0 -15
- package/dist/cjs/errors/useFormFlatFieldErrors.d.ts +0 -5
- package/dist/cjs/errors/useFormFlatFieldErrors.js +0 -12
- package/dist/cjs/errors/useFormRequestSubmit.js +0 -13
- package/dist/cjs/main.js +0 -34
- package/dist/cjs/submit/useFormOnSubmitSuccessful.js +0 -17
- package/dist/cjs/submit/useFormOnSubmitSuccessfulAndReset.js +0 -39
- package/dist/cjs/submit/useResetFormOnSubmitSuccessful.d.ts +0 -11
- package/dist/cjs/submit/useResetFormOnSubmitSuccessful.js +0 -21
- package/dist/cjs/utils.js +0 -5
- package/dist/types/errors/nonfield/FormNonFieldErrorMarker.d.ts +0 -10
- package/dist/types/errors/nonfield/FormNonFieldErrorMarker.spec.d.ts +0 -1
- package/dist/types/errors/nonfield/FormNonFieldErrorMarker.utils.d.ts +0 -7
- package/dist/types/errors/orphan/useFormErrorsHasOnlyOrphans.d.ts +0 -2
- package/dist/types/errors/useFormErrorConsoleDebug.d.ts +0 -8
- package/dist/types/errors/useFormRequestSubmit.d.ts +0 -6
- package/dist/types/main.d.ts +0 -14
- package/dist/types/submit/useFormOnSubmitSuccessful.d.ts +0 -2
- package/dist/types/submit/useFormOnSubmitSuccessfulAndReset.d.ts +0 -10
- package/dist/types/utils.d.ts +0 -1
- /package/dist/{types/errors → errors}/flattenFieldErrors.d.ts +0 -0
- /package/dist/{esm/errors → errors}/flattenFieldErrors.mjs +0 -0
- /package/dist/{types/errors → errors}/getFlatFieldErrors.d.ts +0 -0
- /package/dist/{esm/errors → errors}/getFlatFieldErrors.mjs +0 -0
- /package/dist/{cjs/errors → errors}/nonfield/FormNonFieldErrorMarker.d.ts +0 -0
- /package/dist/{esm/errors → errors}/nonfield/FormNonFieldErrorMarker.mjs +0 -0
- /package/dist/{cjs/errors → errors}/nonfield/FormNonFieldErrorMarker.spec.d.ts +0 -0
- /package/dist/{cjs/errors → errors}/nonfield/FormNonFieldErrorMarker.utils.d.ts +0 -0
- /package/dist/{esm/errors → errors}/nonfield/FormNonFieldErrorMarker.utils.mjs +0 -0
- /package/dist/{types/errors → errors}/nonfield/utils.d.ts +0 -0
- /package/dist/{esm/errors → errors}/nonfield/utils.mjs +0 -0
- /package/dist/{cjs/errors → errors}/orphan/useFormErrorsHasOnlyOrphans.d.ts +0 -0
- /package/dist/{esm/errors → errors}/orphan/useFormErrorsHasOnlyOrphans.mjs +0 -0
- /package/dist/{types/errors → errors}/orphan/useOrphanFormErrors.d.ts +0 -0
- /package/dist/{esm/errors → errors}/orphan/useOrphanFormErrors.mjs +0 -0
- /package/dist/{types/errors → errors}/orphan/useOrphanFormErrorsToConsoleError.d.ts +0 -0
- /package/dist/{esm/errors → errors}/orphan/useOrphanFormErrorsToConsoleError.mjs +0 -0
- /package/dist/{types/errors → errors}/orphan/utils.d.ts +0 -0
- /package/dist/{esm/errors → errors}/orphan/utils.mjs +0 -0
- /package/dist/{types/errors → errors}/root/useRootFormFieldErrors.d.ts +0 -0
- /package/dist/{esm/errors → errors}/root/useRootFormFieldErrors.mjs +0 -0
- /package/dist/{types/errors → errors}/root/utils.d.ts +0 -0
- /package/dist/{esm/errors → errors}/root/utils.mjs +0 -0
- /package/dist/{cjs/errors → errors}/useFormErrorConsoleDebug.d.ts +0 -0
- /package/dist/{esm/errors → errors}/useFormErrorConsoleDebug.mjs +0 -0
- /package/dist/{types/errors → errors}/useFormErrorsEffect.d.ts +0 -0
- /package/dist/{esm/errors → errors}/useFormErrorsEffect.mjs +0 -0
- /package/dist/{types/errors → errors}/useFormErrorsIfAny.d.ts +0 -0
- /package/dist/{esm/errors → errors}/useFormErrorsIfAny.mjs +0 -0
- /package/dist/{types/errors → errors}/useFormErrorsOnChange.d.ts +0 -0
- /package/dist/{esm/errors → errors}/useFormErrorsOnChange.mjs +0 -0
- /package/dist/{types/errors → errors}/useFormFlatFieldErrors.d.ts +0 -0
- /package/dist/{esm/errors → errors}/useFormFlatFieldErrors.mjs +0 -0
- /package/dist/{cjs/errors → errors}/useFormRequestSubmit.d.ts +0 -0
- /package/dist/{esm/errors → errors}/useFormRequestSubmit.mjs +0 -0
- /package/dist/{cjs/main.d.ts → main.d.ts} +0 -0
- /package/dist/{esm/main.mjs → main.mjs} +0 -0
- /package/dist/{cjs/submit → submit}/useFormOnSubmitSuccessful.d.ts +0 -0
- /package/dist/{esm/submit → submit}/useFormOnSubmitSuccessful.mjs +0 -0
- /package/dist/{cjs/submit → submit}/useFormOnSubmitSuccessfulAndReset.d.ts +0 -0
- /package/dist/{esm/submit → submit}/useFormOnSubmitSuccessfulAndReset.mjs +0 -0
- /package/dist/{types/submit → submit}/useResetFormOnSubmitSuccessful.d.ts +0 -0
- /package/dist/{esm/submit → submit}/useResetFormOnSubmitSuccessful.mjs +0 -0
- /package/dist/{cjs/utils.d.ts → utils.d.ts} +0 -0
- /package/dist/{esm/utils.mjs → utils.mjs} +0 -0
package/package.json
CHANGED
|
@@ -2,95 +2,78 @@
|
|
|
2
2
|
"name": "@paragrav/rhf-utils",
|
|
3
3
|
"author": "paragrav.dev",
|
|
4
4
|
"license": "MIT",
|
|
5
|
-
"version": "0.0.
|
|
5
|
+
"version": "0.0.22",
|
|
6
6
|
"description": "Integration utilities for react-hook-form.",
|
|
7
7
|
"type": "module",
|
|
8
8
|
"sideEffects": false,
|
|
9
9
|
"files": [
|
|
10
10
|
"dist"
|
|
11
11
|
],
|
|
12
|
-
"
|
|
13
|
-
"module": "./dist/esm/main.mjs",
|
|
12
|
+
"module": "./dist/main.mjs",
|
|
14
13
|
"exports": {
|
|
15
14
|
".": {
|
|
16
|
-
"
|
|
17
|
-
"
|
|
18
|
-
"types": "./dist/types/main.d.ts"
|
|
15
|
+
"default": "./dist/main.mjs",
|
|
16
|
+
"types": "./dist/main.d.ts"
|
|
19
17
|
},
|
|
20
18
|
"./errors/useFormErrorConsoleDebug": {
|
|
21
|
-
"
|
|
22
|
-
"
|
|
23
|
-
"types": "./dist/types/errors/useFormErrorConsoleDebug.d.ts"
|
|
19
|
+
"default": "./dist/errors/useFormErrorConsoleDebug.mjs",
|
|
20
|
+
"types": "./dist/errors/useFormErrorConsoleDebug.d.ts"
|
|
24
21
|
},
|
|
25
22
|
"./errors/useFormErrorsEffect": {
|
|
26
|
-
"
|
|
27
|
-
"
|
|
28
|
-
"types": "./dist/types/errors/useFormErrorsEffect.d.ts"
|
|
23
|
+
"default": "./dist/errors/useFormErrorsEffect.mjs",
|
|
24
|
+
"types": "./dist/errors/useFormErrorsEffect.d.ts"
|
|
29
25
|
},
|
|
30
26
|
"./errors/useFormErrorsIfAny": {
|
|
31
|
-
"
|
|
32
|
-
"
|
|
33
|
-
"types": "./dist/types/errors/useFormErrorsIfAny.d.ts"
|
|
27
|
+
"default": "./dist/errors/useFormErrorsIfAny.mjs",
|
|
28
|
+
"types": "./dist/errors/useFormErrorsIfAny.d.ts"
|
|
34
29
|
},
|
|
35
30
|
"./errors/useFormErrorsOnChange": {
|
|
36
|
-
"
|
|
37
|
-
"
|
|
38
|
-
"types": "./dist/types/errors/useFormErrorsOnChange.d.ts"
|
|
31
|
+
"default": "./dist/errors/useFormErrorsOnChange.mjs",
|
|
32
|
+
"types": "./dist/errors/useFormErrorsOnChange.d.ts"
|
|
39
33
|
},
|
|
40
34
|
"./errors/useFormRequestSubmit": {
|
|
41
|
-
"
|
|
42
|
-
"
|
|
43
|
-
"types": "./dist/types/errors/useFormRequestSubmit.d.ts"
|
|
35
|
+
"default": "./dist/errors/useFormRequestSubmit.mjs",
|
|
36
|
+
"types": "./dist/errors/useFormRequestSubmit.d.ts"
|
|
44
37
|
},
|
|
45
38
|
"./errors/FormNonFieldErrorMarker": {
|
|
46
|
-
"
|
|
47
|
-
"
|
|
48
|
-
"types": "./dist/types/errors/nonfield/FormNonFieldErrorMarker.d.ts"
|
|
39
|
+
"default": "./dist/errors/nonfield/FormNonFieldErrorMarker.mjs",
|
|
40
|
+
"types": "./dist/errors/nonfield/FormNonFieldErrorMarker.d.ts"
|
|
49
41
|
},
|
|
50
42
|
"./errors/FormNonFieldErrorMarkerHtmlAttribute": {
|
|
51
|
-
"
|
|
52
|
-
"
|
|
53
|
-
"types": "./dist/types/errors/nonfield/FormNonFieldErrorMarker.utils.d.ts"
|
|
43
|
+
"default": "./dist/errors/nonfield/FormNonFieldErrorMarker.utils.mjs",
|
|
44
|
+
"types": "./dist/errors/nonfield/FormNonFieldErrorMarker.utils.d.ts"
|
|
54
45
|
},
|
|
55
46
|
"./errors/useOrphanFormErrorsToConsoleError": {
|
|
56
|
-
"
|
|
57
|
-
"
|
|
58
|
-
"types": "./dist/types/errors/orphan/useOrphanFormErrorsToConsoleError.d.ts"
|
|
47
|
+
"default": "./dist/errors/orphan/useOrphanFormErrorsToConsoleError.mjs",
|
|
48
|
+
"types": "./dist/errors/orphan/useOrphanFormErrorsToConsoleError.d.ts"
|
|
59
49
|
},
|
|
60
50
|
"./errors/useFormErrorsHasOnlyOrphans": {
|
|
61
|
-
"
|
|
62
|
-
"
|
|
63
|
-
"types": "./dist/types/errors/orphan/useFormErrorsHasOnlyOrphans.d.ts"
|
|
51
|
+
"default": "./dist/errors/orphan/useFormErrorsHasOnlyOrphans.mjs",
|
|
52
|
+
"types": "./dist/errors/orphan/useFormErrorsHasOnlyOrphans.d.ts"
|
|
64
53
|
},
|
|
65
54
|
"./errors/useOrphanFormErrors": {
|
|
66
|
-
"
|
|
67
|
-
"
|
|
68
|
-
"types": "./dist/types/errors/orphan/useOrphanFormErrors.d.ts"
|
|
55
|
+
"default": "./dist/errors/orphan/useOrphanFormErrors.mjs",
|
|
56
|
+
"types": "./dist/errors/orphan/useOrphanFormErrors.d.ts"
|
|
69
57
|
},
|
|
70
58
|
"./errors/useRootFormFieldErrors": {
|
|
71
|
-
"
|
|
72
|
-
"
|
|
73
|
-
"types": "./dist/types/errors/root/useRootFormFieldErrors.d.ts"
|
|
59
|
+
"default": "./dist/errors/root/useRootFormFieldErrors.mjs",
|
|
60
|
+
"types": "./dist/errors/root/useRootFormFieldErrors.d.ts"
|
|
74
61
|
},
|
|
75
62
|
"./submit/useFormOnSubmitSuccessful": {
|
|
76
|
-
"
|
|
77
|
-
"
|
|
78
|
-
"types": "./dist/types/submit/useFormOnSubmitSuccessful.d.ts"
|
|
63
|
+
"default": "./dist/submit/useFormOnSubmitSuccessful.mjs",
|
|
64
|
+
"types": "./dist/submit/useFormOnSubmitSuccessful.d.ts"
|
|
79
65
|
},
|
|
80
66
|
"./submit/useFormOnSubmitSuccessfulAndReset": {
|
|
81
|
-
"
|
|
82
|
-
"
|
|
83
|
-
"types": "./dist/types/submit/useFormOnSubmitSuccessfulAndReset.d.ts"
|
|
67
|
+
"default": "./dist/submit/useFormOnSubmitSuccessfulAndReset.mjs",
|
|
68
|
+
"types": "./dist/submit/useFormOnSubmitSuccessfulAndReset.d.ts"
|
|
84
69
|
},
|
|
85
70
|
"./submit/useResetFormAfterSubmitSuccessful": {
|
|
86
|
-
"
|
|
87
|
-
"
|
|
88
|
-
"types": "./dist/types/submit/useResetFormAfterSubmitSuccessful.d.ts"
|
|
71
|
+
"default": "./dist/submit/useResetFormAfterSubmitSuccessful.mjs",
|
|
72
|
+
"types": "./dist/submit/useResetFormAfterSubmitSuccessful.d.ts"
|
|
89
73
|
}
|
|
90
74
|
},
|
|
91
75
|
"scripts": {
|
|
92
|
-
"build": "npm run validate && npm run build:
|
|
93
|
-
"build:cjs": "tsc -p ./tsconfig.cjs.json",
|
|
76
|
+
"build": "npm run validate && npm run build:esm",
|
|
94
77
|
"build:esm": "vite build",
|
|
95
78
|
"lint": "eslint --ignore-path ./.gitignore --ext ts,tsx --report-unused-disable-directives --max-warnings 0 .",
|
|
96
79
|
"preinstall": "npx only-allow npm",
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import type { FieldErrors } from 'react-hook-form';
|
|
2
|
-
/**
|
|
3
|
-
* Only flattens a {@link FieldErrors} object.
|
|
4
|
-
* @returns e.g.,
|
|
5
|
-
* ```
|
|
6
|
-
* {
|
|
7
|
-
* "address.street.type": "too_short",
|
|
8
|
-
* "address.street.ref.value": "123",
|
|
9
|
-
* "address.street.message": "Required."
|
|
10
|
-
* }
|
|
11
|
-
* ```
|
|
12
|
-
*/
|
|
13
|
-
declare const flattenFieldErrors: (errors: FieldErrors) => Record<string, unknown>;
|
|
14
|
-
export default flattenFieldErrors;
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const flat_1 = require("flat");
|
|
4
|
-
/**
|
|
5
|
-
* Only flattens a {@link FieldErrors} object.
|
|
6
|
-
* @returns e.g.,
|
|
7
|
-
* ```
|
|
8
|
-
* {
|
|
9
|
-
* "address.street.type": "too_short",
|
|
10
|
-
* "address.street.ref.value": "123",
|
|
11
|
-
* "address.street.message": "Required."
|
|
12
|
-
* }
|
|
13
|
-
* ```
|
|
14
|
-
*/
|
|
15
|
-
const flattenFieldErrors = (errors) => (0, flat_1.flatten)(errors);
|
|
16
|
-
exports.default = flattenFieldErrors;
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import type { FieldError, FieldErrors } from 'react-hook-form';
|
|
2
|
-
export type FlatFieldErrors = Record<string, FieldError>;
|
|
3
|
-
/**
|
|
4
|
-
* Get {@link FlatFieldErrors} from {@link FieldErrors}.
|
|
5
|
-
* This makes it easy to work with potentially deeply-nested {@link FieldErrors}.
|
|
6
|
-
*
|
|
7
|
-
* @param errors {@link FieldErrors} object.
|
|
8
|
-
* @returns FlatFieldErrors object.
|
|
9
|
-
*
|
|
10
|
-
* e.g.,
|
|
11
|
-
* ```
|
|
12
|
-
* [ "address.street", { "address.street": { type: "too_short", ref: { value: "123" }, message: "Required." } } ]
|
|
13
|
-
* ```
|
|
14
|
-
*/
|
|
15
|
-
declare const getFlatFieldErrors: (errors: FieldErrors) => FlatFieldErrors;
|
|
16
|
-
export default getFlatFieldErrors;
|
|
17
|
-
/**
|
|
18
|
-
* Regular expression to maybe match the end of a leaf node path.
|
|
19
|
-
*
|
|
20
|
-
* i.e., `name.type`, `address.street.message`
|
|
21
|
-
*
|
|
22
|
-
* iow: dot [?: non-capturing]("type" | "message")[\b word boundary][$ end of string]
|
|
23
|
-
*/
|
|
24
|
-
export declare const regexMaybeFieldErrorLeafNode: RegExp;
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.regexMaybeFieldErrorLeafNode = void 0;
|
|
7
|
-
const react_hook_form_1 = require("react-hook-form");
|
|
8
|
-
const flattenFieldErrors_1 = __importDefault(require("./flattenFieldErrors"));
|
|
9
|
-
/**
|
|
10
|
-
* Get {@link FlatFieldErrors} from {@link FieldErrors}.
|
|
11
|
-
* This makes it easy to work with potentially deeply-nested {@link FieldErrors}.
|
|
12
|
-
*
|
|
13
|
-
* @param errors {@link FieldErrors} object.
|
|
14
|
-
* @returns FlatFieldErrors object.
|
|
15
|
-
*
|
|
16
|
-
* e.g.,
|
|
17
|
-
* ```
|
|
18
|
-
* [ "address.street", { "address.street": { type: "too_short", ref: { value: "123" }, message: "Required." } } ]
|
|
19
|
-
* ```
|
|
20
|
-
*/
|
|
21
|
-
const getFlatFieldErrors = (errors) => {
|
|
22
|
-
const flattened = (0, flattenFieldErrors_1.default)(errors);
|
|
23
|
-
const keys = Object.keys(flattened);
|
|
24
|
-
return Object.fromEntries(keys.reduce((entries, key) => {
|
|
25
|
-
// look for leaf node, which would have required `type` prop (e.g., `name.type`, `address.street.type`)
|
|
26
|
-
// remove `regexEndsWithType` suffix to get flat field path (e.g., `name`, `address.street`)
|
|
27
|
-
const path = key.replace(exports.regexMaybeFieldErrorLeafNode, '');
|
|
28
|
-
// if nothing replaced, then it's not a leaf node
|
|
29
|
-
if (path === key)
|
|
30
|
-
return entries;
|
|
31
|
-
// find field error in FieldErrors object
|
|
32
|
-
// has dual-purpose of confirming that each path is valid
|
|
33
|
-
const fieldError = (0, react_hook_form_1.get)(errors, path, undefined);
|
|
34
|
-
if (!fieldError)
|
|
35
|
-
return entries;
|
|
36
|
-
entries.push([path, fieldError]);
|
|
37
|
-
return entries;
|
|
38
|
-
}, []));
|
|
39
|
-
};
|
|
40
|
-
exports.default = getFlatFieldErrors;
|
|
41
|
-
//
|
|
42
|
-
/**
|
|
43
|
-
* Regular expression to maybe match the end of a leaf node path.
|
|
44
|
-
*
|
|
45
|
-
* i.e., `name.type`, `address.street.message`
|
|
46
|
-
*
|
|
47
|
-
* iow: dot [?: non-capturing]("type" | "message")[\b word boundary][$ end of string]
|
|
48
|
-
*/
|
|
49
|
-
exports.regexMaybeFieldErrorLeafNode = /\.(?:type|message)\b$/;
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
7
|
-
const FormNonFieldErrorMarker_utils_1 = __importDefault(require("./FormNonFieldErrorMarker.utils"));
|
|
8
|
-
/**
|
|
9
|
-
* Empty, hidden marker to indicate a non-field/non-root error is being displayed to user.
|
|
10
|
-
*/
|
|
11
|
-
const FormNonFieldErrorMarker = ({ path }) => {
|
|
12
|
-
const dataAttribute = {
|
|
13
|
-
[FormNonFieldErrorMarker_utils_1.default]: path,
|
|
14
|
-
};
|
|
15
|
-
return ((0, jsx_runtime_1.jsx)("div", { role: "alert", "aria-hidden": "true" // hide from screen readers
|
|
16
|
-
, style: { display: 'none' }, ...dataAttribute }));
|
|
17
|
-
};
|
|
18
|
-
exports.default = FormNonFieldErrorMarker;
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
7
|
-
const experimental_ct_react_1 = require("@playwright/experimental-ct-react");
|
|
8
|
-
const FormNonFieldErrorMarker_1 = __importDefault(require("./FormNonFieldErrorMarker"));
|
|
9
|
-
const FormNonFieldErrorMarker_utils_1 = require("./FormNonFieldErrorMarker.utils");
|
|
10
|
-
const path = 'test';
|
|
11
|
-
const querySelector = (0, FormNonFieldErrorMarker_utils_1.getFormNonFieldErrorMarkerQuerySelector)(path);
|
|
12
|
-
(0, experimental_ct_react_1.test)('FormNonFieldErrorMarker can be located via query', async ({ page, mount, }) => {
|
|
13
|
-
await mount((0, jsx_runtime_1.jsx)(FormNonFieldErrorMarker_1.default, { path: path }));
|
|
14
|
-
await (0, experimental_ct_react_1.expect)(page.locator(querySelector)).toBeAttached();
|
|
15
|
-
});
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.hasNonFieldErrorMarkerInDOM = exports.getFormNonFieldErrorMarkerQuerySelector = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* HTML data attribute for {@link FormNonFieldErrorMarker}.
|
|
6
|
-
*/
|
|
7
|
-
const FormNonFieldErrorMarkerHtmlAttribute = 'data-paragrav-rhf-utils-nonfield-error-marker-path';
|
|
8
|
-
exports.default = FormNonFieldErrorMarkerHtmlAttribute;
|
|
9
|
-
// utils
|
|
10
|
-
const getFormNonFieldErrorMarkerQuerySelector = (path) => `[role="alert"][${FormNonFieldErrorMarkerHtmlAttribute}="${path}"]`;
|
|
11
|
-
exports.getFormNonFieldErrorMarkerQuerySelector = getFormNonFieldErrorMarkerQuerySelector;
|
|
12
|
-
const hasNonFieldErrorMarkerInDOM = (path, parentElement) => parentElement.querySelector((0, exports.getFormNonFieldErrorMarkerQuerySelector)(path));
|
|
13
|
-
exports.hasNonFieldErrorMarkerInDOM = hasNonFieldErrorMarkerInDOM;
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import type { FieldError } from 'react-hook-form';
|
|
2
|
-
/**
|
|
3
|
-
* Determine if {@link FieldError} is a non-field error (i.e., has `ref`).
|
|
4
|
-
*
|
|
5
|
-
* A non-field error has no association to an input via {@link FieldError.ref}.
|
|
6
|
-
*
|
|
7
|
-
* These fall into one of two categories:
|
|
8
|
-
* - Root, which are typically displayed to user at bottom/top of form.
|
|
9
|
-
* - Non-root, which fall into two main sub-sets:
|
|
10
|
-
* - Non-orphan (displayed -- typically manually)
|
|
11
|
-
* - e.g., array min/max validation
|
|
12
|
-
* - Orphan (undisplayed), which are typically caused by one of the following cases:
|
|
13
|
-
* - The input is missing.
|
|
14
|
-
* - The schema is incorrect.
|
|
15
|
-
* - The error is not displayed to user with `FormErrorNonFieldMarker`.
|
|
16
|
-
*/
|
|
17
|
-
export declare const isNonFieldError: (error: FieldError) => boolean;
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isNonFieldError = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* Determine if {@link FieldError} is a non-field error (i.e., has `ref`).
|
|
6
|
-
*
|
|
7
|
-
* A non-field error has no association to an input via {@link FieldError.ref}.
|
|
8
|
-
*
|
|
9
|
-
* These fall into one of two categories:
|
|
10
|
-
* - Root, which are typically displayed to user at bottom/top of form.
|
|
11
|
-
* - Non-root, which fall into two main sub-sets:
|
|
12
|
-
* - Non-orphan (displayed -- typically manually)
|
|
13
|
-
* - e.g., array min/max validation
|
|
14
|
-
* - Orphan (undisplayed), which are typically caused by one of the following cases:
|
|
15
|
-
* - The input is missing.
|
|
16
|
-
* - The schema is incorrect.
|
|
17
|
-
* - The error is not displayed to user with `FormErrorNonFieldMarker`.
|
|
18
|
-
*/
|
|
19
|
-
const isNonFieldError = (error) => !error.ref;
|
|
20
|
-
exports.isNonFieldError = isNonFieldError;
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const utils_1 = require("@/utils");
|
|
7
|
-
const useFormFlatFieldErrors_1 = __importDefault(require("../useFormFlatFieldErrors"));
|
|
8
|
-
const useOrphanFormErrors_1 = __importDefault(require("./useOrphanFormErrors"));
|
|
9
|
-
const useFormErrorsHasOnlyOrphans = (formRef) => {
|
|
10
|
-
// get flat field errors of orphans and all errors
|
|
11
|
-
const orphans = (0, useOrphanFormErrors_1.default)(formRef);
|
|
12
|
-
const errors = (0, useFormFlatFieldErrors_1.default)();
|
|
13
|
-
// if either empty, early return
|
|
14
|
-
if ([orphans, errors].some(utils_1.isEmptyObject))
|
|
15
|
-
return false;
|
|
16
|
-
// equal length
|
|
17
|
-
return Object.keys(orphans).length === Object.keys(errors).length;
|
|
18
|
-
};
|
|
19
|
-
exports.default = useFormErrorsHasOnlyOrphans;
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const utils_1 = require("@/utils");
|
|
7
|
-
const useFormErrorsOnChange_1 = __importDefault(require("../useFormErrorsOnChange"));
|
|
8
|
-
const utils_2 = require("./utils");
|
|
9
|
-
const useOrphanFormErrors = (formRef) => (0, useFormErrorsOnChange_1.default)((errors) => {
|
|
10
|
-
// if no errors, return early
|
|
11
|
-
if ((0, utils_1.isEmptyObject)(errors))
|
|
12
|
-
return {};
|
|
13
|
-
// this should never happen
|
|
14
|
-
if (!formRef.current)
|
|
15
|
-
throw new Error();
|
|
16
|
-
return (0, utils_2.getOrphanFlatFieldErrors)(errors, formRef.current);
|
|
17
|
-
});
|
|
18
|
-
exports.default = useOrphanFormErrors;
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
/**
|
|
3
|
-
* Outputs orphan errors to `console.error` all errors with `ref: undefined` that do not begin with `root(.*)`.
|
|
4
|
-
* Sentry (or equivalent) should capture.
|
|
5
|
-
*/
|
|
6
|
-
declare const useOrphanFormErrorsToConsoleError: (formRef: React.RefObject<HTMLFormElement>) => void;
|
|
7
|
-
export default useOrphanFormErrorsToConsoleError;
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const react_1 = __importDefault(require("react"));
|
|
7
|
-
const react_hook_form_1 = require("react-hook-form");
|
|
8
|
-
const useOrphanFormErrors_1 = __importDefault(require("./useOrphanFormErrors"));
|
|
9
|
-
/**
|
|
10
|
-
* Outputs orphan errors to `console.error` all errors with `ref: undefined` that do not begin with `root(.*)`.
|
|
11
|
-
* Sentry (or equivalent) should capture.
|
|
12
|
-
*/
|
|
13
|
-
const useOrphanFormErrorsToConsoleError = (formRef) => {
|
|
14
|
-
const { getValues } = (0, react_hook_form_1.useFormContext)();
|
|
15
|
-
const { errors } = (0, react_hook_form_1.useFormState)();
|
|
16
|
-
const orphans = (0, useOrphanFormErrors_1.default)(formRef);
|
|
17
|
-
react_1.default.useEffect(() => {
|
|
18
|
-
if (!Object.keys(orphans).length)
|
|
19
|
-
return;
|
|
20
|
-
console.error('useOrphanFormErrorsToConsoleError', {
|
|
21
|
-
location: window.location,
|
|
22
|
-
values: getValues(),
|
|
23
|
-
orphans,
|
|
24
|
-
});
|
|
25
|
-
}, [errors, getValues, orphans]);
|
|
26
|
-
};
|
|
27
|
-
exports.default = useOrphanFormErrorsToConsoleError;
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.getOrphanFlatFieldErrors = void 0;
|
|
7
|
-
const getFlatFieldErrors_1 = __importDefault(require("../getFlatFieldErrors"));
|
|
8
|
-
const FormNonFieldErrorMarker_utils_1 = require("../nonfield/FormNonFieldErrorMarker.utils");
|
|
9
|
-
const utils_1 = require("../nonfield/utils");
|
|
10
|
-
const utils_2 = require("../root/utils");
|
|
11
|
-
const getOrphanFlatFieldErrors = (errors, parentElement) => {
|
|
12
|
-
const flatFieldErrors = (0, getFlatFieldErrors_1.default)(errors);
|
|
13
|
-
return Object.fromEntries(Object.entries(flatFieldErrors).filter(([path, error]) =>
|
|
14
|
-
// not root path
|
|
15
|
-
!(0, utils_2.isFormErrorPathRoot)(path) &&
|
|
16
|
-
// non-field
|
|
17
|
-
(0, utils_1.isNonFieldError)(error) &&
|
|
18
|
-
// does not have marker
|
|
19
|
-
!(0, FormNonFieldErrorMarker_utils_1.hasNonFieldErrorMarkerInDOM)(path, parentElement)));
|
|
20
|
-
};
|
|
21
|
-
exports.getOrphanFlatFieldErrors = getOrphanFlatFieldErrors;
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const useFormErrorsOnChange_1 = __importDefault(require("../useFormErrorsOnChange"));
|
|
7
|
-
const utils_1 = require("./utils");
|
|
8
|
-
/**
|
|
9
|
-
* Root field errors from form.
|
|
10
|
-
* These are typically displayed at the bottom of the form.
|
|
11
|
-
*/
|
|
12
|
-
const useRootFormFieldErrors = () => (0, useFormErrorsOnChange_1.default)(utils_1.getRootFlatFieldErrors);
|
|
13
|
-
exports.default = useRootFormFieldErrors;
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import type { FieldErrors } from 'react-hook-form';
|
|
2
|
-
import type { FlatFieldErrors } from '../getFlatFieldErrors';
|
|
3
|
-
/**
|
|
4
|
-
* Determine if an error path is root. (e.g., `root` or `root.nested`)
|
|
5
|
-
* @param path Flat path. (e.g., 'root.nested')
|
|
6
|
-
*/
|
|
7
|
-
export declare const isFormErrorPathRoot: (path: string) => boolean;
|
|
8
|
-
/**
|
|
9
|
-
*
|
|
10
|
-
*/
|
|
11
|
-
export declare const getRootFlatFieldErrors: (errors: FieldErrors) => FlatFieldErrors;
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.getRootFlatFieldErrors = exports.isFormErrorPathRoot = void 0;
|
|
7
|
-
const getFlatFieldErrors_1 = __importDefault(require("../getFlatFieldErrors"));
|
|
8
|
-
const ROOT = 'root';
|
|
9
|
-
/**
|
|
10
|
-
* Determine if an error path is root. (e.g., `root` or `root.nested`)
|
|
11
|
-
* @param path Flat path. (e.g., 'root.nested')
|
|
12
|
-
*/
|
|
13
|
-
const isFormErrorPathRoot = (path) => path === ROOT || path.startsWith(ROOT + '.');
|
|
14
|
-
exports.isFormErrorPathRoot = isFormErrorPathRoot;
|
|
15
|
-
/**
|
|
16
|
-
*
|
|
17
|
-
*/
|
|
18
|
-
const getRootFlatFieldErrors = (errors) => {
|
|
19
|
-
const flatFieldErrors = (0, getFlatFieldErrors_1.default)(errors);
|
|
20
|
-
return Object.fromEntries(Object.entries(flatFieldErrors)
|
|
21
|
-
// only include entries whose paths are "root"
|
|
22
|
-
.filter(([path]) => (0, exports.isFormErrorPathRoot)(path)));
|
|
23
|
-
};
|
|
24
|
-
exports.getRootFlatFieldErrors = getRootFlatFieldErrors;
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const useFormErrorsIfAny_1 = __importDefault(require("./useFormErrorsIfAny"));
|
|
7
|
-
/**
|
|
8
|
-
* Output form errors to console.debug() for easier debugging for certain condition.
|
|
9
|
-
* (e.g., in dev/staging environments or certain users)
|
|
10
|
-
*
|
|
11
|
-
* `console.debug()` is unlikely to trigger any automated console capture reporting.
|
|
12
|
-
*/
|
|
13
|
-
const useFormErrorConsoleDebug = (condition) => {
|
|
14
|
-
const errors = (0, useFormErrorsIfAny_1.default)();
|
|
15
|
-
if (!condition)
|
|
16
|
-
return;
|
|
17
|
-
if (!errors)
|
|
18
|
-
return;
|
|
19
|
-
// eslint-disable-next-line no-console
|
|
20
|
-
console.debug('useFormErrorConsoleDebug', errors);
|
|
21
|
-
};
|
|
22
|
-
exports.default = useFormErrorConsoleDebug;
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const react_1 = __importDefault(require("react"));
|
|
7
|
-
const react_hook_form_1 = require("react-hook-form");
|
|
8
|
-
const useFormErrorsEffect = (callback) => {
|
|
9
|
-
const { errors } = (0, react_hook_form_1.useFormState)();
|
|
10
|
-
react_1.default.useEffect(() => {
|
|
11
|
-
callback(errors);
|
|
12
|
-
}, [callback, errors]);
|
|
13
|
-
};
|
|
14
|
-
exports.default = useFormErrorsEffect;
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Returns errors only if there are errors.
|
|
3
|
-
* Allows simple typeguard without `isEmpty` dependency.
|
|
4
|
-
*/
|
|
5
|
-
declare const useFormErrorsIfAny: () => false | import("react-hook-form").FieldErrors<import("react-hook-form").FieldValues>;
|
|
6
|
-
export default useFormErrorsIfAny;
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const react_hook_form_1 = require("react-hook-form");
|
|
4
|
-
const utils_1 = require("@/utils");
|
|
5
|
-
/**
|
|
6
|
-
* Returns errors only if there are errors.
|
|
7
|
-
* Allows simple typeguard without `isEmpty` dependency.
|
|
8
|
-
*/
|
|
9
|
-
const useFormErrorsIfAny = () => {
|
|
10
|
-
const { errors } = (0, react_hook_form_1.useFormState)();
|
|
11
|
-
return (0, utils_1.isEmptyObject)(errors) ? false : errors;
|
|
12
|
-
};
|
|
13
|
-
exports.default = useFormErrorsIfAny;
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const react_1 = __importDefault(require("react"));
|
|
7
|
-
const react_hook_form_1 = require("react-hook-form");
|
|
8
|
-
/**
|
|
9
|
-
* Provide a callback to call when RHF errors change.
|
|
10
|
-
*/
|
|
11
|
-
const useFormErrorsOnChange = (callback) => {
|
|
12
|
-
const { errors } = (0, react_hook_form_1.useFormState)();
|
|
13
|
-
return react_1.default.useMemo(() => callback(errors), [callback, errors]);
|
|
14
|
-
};
|
|
15
|
-
exports.default = useFormErrorsOnChange;
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const getFlatFieldErrors_1 = __importDefault(require("./getFlatFieldErrors"));
|
|
7
|
-
const useFormErrorsOnChange_1 = __importDefault(require("./useFormErrorsOnChange"));
|
|
8
|
-
/**
|
|
9
|
-
* Use {@link FieldErrors} as {@link FlatFieldErrors}.
|
|
10
|
-
*/
|
|
11
|
-
const useFormFlatFieldErrors = () => (0, useFormErrorsOnChange_1.default)(getFlatFieldErrors_1.default);
|
|
12
|
-
exports.default = useFormFlatFieldErrors;
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
/**
|
|
4
|
-
* Get callback to trigger submit manually on form.
|
|
5
|
-
* @link https://developer.mozilla.org/docs/Web/API/HTMLFormElement/requestSubmit
|
|
6
|
-
*/
|
|
7
|
-
const useFormRequestSubmit = (ref) => (submitter) => {
|
|
8
|
-
// typeguard (should never happen at runtime when callback is called)
|
|
9
|
-
if (!ref.current)
|
|
10
|
-
throw new Error();
|
|
11
|
-
ref.current.requestSubmit(submitter);
|
|
12
|
-
};
|
|
13
|
-
exports.default = useFormRequestSubmit;
|
package/dist/cjs/main.js
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.useResetFormAfterSubmitSuccessful = exports.useFormOnSubmitSuccessfulAndReset = exports.useFormOnSubmitSuccessful = exports.useFormRequestSubmit = exports.useFormErrorsOnChange = exports.useFormErrorsIfAny = exports.useFormErrorsEffect = exports.useFormErrorConsoleDebug = exports.useRootFormFieldErrors = exports.useOrphanFormErrorsToConsoleError = exports.useOrphanFormErrors = exports.useFormErrorsHasOnlyOrphans = exports.FormNonFieldErrorMarkerHtmlAttribute = exports.FormNonFieldErrorMarker = void 0;
|
|
7
|
-
var FormNonFieldErrorMarker_1 = require("./errors/nonfield/FormNonFieldErrorMarker");
|
|
8
|
-
Object.defineProperty(exports, "FormNonFieldErrorMarker", { enumerable: true, get: function () { return __importDefault(FormNonFieldErrorMarker_1).default; } });
|
|
9
|
-
var FormNonFieldErrorMarker_utils_1 = require("./errors/nonfield/FormNonFieldErrorMarker.utils");
|
|
10
|
-
Object.defineProperty(exports, "FormNonFieldErrorMarkerHtmlAttribute", { enumerable: true, get: function () { return __importDefault(FormNonFieldErrorMarker_utils_1).default; } });
|
|
11
|
-
var useFormErrorsHasOnlyOrphans_1 = require("./errors/orphan/useFormErrorsHasOnlyOrphans");
|
|
12
|
-
Object.defineProperty(exports, "useFormErrorsHasOnlyOrphans", { enumerable: true, get: function () { return __importDefault(useFormErrorsHasOnlyOrphans_1).default; } });
|
|
13
|
-
var useOrphanFormErrors_1 = require("./errors/orphan/useOrphanFormErrors");
|
|
14
|
-
Object.defineProperty(exports, "useOrphanFormErrors", { enumerable: true, get: function () { return __importDefault(useOrphanFormErrors_1).default; } });
|
|
15
|
-
var useOrphanFormErrorsToConsoleError_1 = require("./errors/orphan/useOrphanFormErrorsToConsoleError");
|
|
16
|
-
Object.defineProperty(exports, "useOrphanFormErrorsToConsoleError", { enumerable: true, get: function () { return __importDefault(useOrphanFormErrorsToConsoleError_1).default; } });
|
|
17
|
-
var useRootFormFieldErrors_1 = require("./errors/root/useRootFormFieldErrors");
|
|
18
|
-
Object.defineProperty(exports, "useRootFormFieldErrors", { enumerable: true, get: function () { return __importDefault(useRootFormFieldErrors_1).default; } });
|
|
19
|
-
var useFormErrorConsoleDebug_1 = require("./errors/useFormErrorConsoleDebug");
|
|
20
|
-
Object.defineProperty(exports, "useFormErrorConsoleDebug", { enumerable: true, get: function () { return __importDefault(useFormErrorConsoleDebug_1).default; } });
|
|
21
|
-
var useFormErrorsEffect_1 = require("./errors/useFormErrorsEffect");
|
|
22
|
-
Object.defineProperty(exports, "useFormErrorsEffect", { enumerable: true, get: function () { return __importDefault(useFormErrorsEffect_1).default; } });
|
|
23
|
-
var useFormErrorsIfAny_1 = require("./errors/useFormErrorsIfAny");
|
|
24
|
-
Object.defineProperty(exports, "useFormErrorsIfAny", { enumerable: true, get: function () { return __importDefault(useFormErrorsIfAny_1).default; } });
|
|
25
|
-
var useFormErrorsOnChange_1 = require("./errors/useFormErrorsOnChange");
|
|
26
|
-
Object.defineProperty(exports, "useFormErrorsOnChange", { enumerable: true, get: function () { return __importDefault(useFormErrorsOnChange_1).default; } });
|
|
27
|
-
var useFormRequestSubmit_1 = require("./errors/useFormRequestSubmit");
|
|
28
|
-
Object.defineProperty(exports, "useFormRequestSubmit", { enumerable: true, get: function () { return __importDefault(useFormRequestSubmit_1).default; } });
|
|
29
|
-
var useFormOnSubmitSuccessful_1 = require("./submit/useFormOnSubmitSuccessful");
|
|
30
|
-
Object.defineProperty(exports, "useFormOnSubmitSuccessful", { enumerable: true, get: function () { return __importDefault(useFormOnSubmitSuccessful_1).default; } });
|
|
31
|
-
var useFormOnSubmitSuccessfulAndReset_1 = require("./submit/useFormOnSubmitSuccessfulAndReset");
|
|
32
|
-
Object.defineProperty(exports, "useFormOnSubmitSuccessfulAndReset", { enumerable: true, get: function () { return __importDefault(useFormOnSubmitSuccessfulAndReset_1).default; } });
|
|
33
|
-
var useResetFormOnSubmitSuccessful_1 = require("./submit/useResetFormOnSubmitSuccessful");
|
|
34
|
-
Object.defineProperty(exports, "useResetFormAfterSubmitSuccessful", { enumerable: true, get: function () { return __importDefault(useResetFormOnSubmitSuccessful_1).default; } });
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const react_1 = __importDefault(require("react"));
|
|
7
|
-
const react_hook_form_1 = require("react-hook-form");
|
|
8
|
-
const useFormOnSubmitSuccessful = (callback) => {
|
|
9
|
-
const { isSubmitSuccessful } = (0, react_hook_form_1.useFormState)();
|
|
10
|
-
react_1.default.useEffect(() => {
|
|
11
|
-
if (!callback)
|
|
12
|
-
return;
|
|
13
|
-
if (isSubmitSuccessful)
|
|
14
|
-
callback();
|
|
15
|
-
}, [callback, isSubmitSuccessful]);
|
|
16
|
-
};
|
|
17
|
-
exports.default = useFormOnSubmitSuccessful;
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const react_1 = __importDefault(require("react"));
|
|
7
|
-
const react_hook_form_1 = require("react-hook-form");
|
|
8
|
-
const useFormOnSubmitSuccessful_1 = __importDefault(require("./useFormOnSubmitSuccessful"));
|
|
9
|
-
/**
|
|
10
|
-
* Calls a callback after a successful submit and after a form reset.
|
|
11
|
-
*
|
|
12
|
-
* Using RHF and following its rules, we are not able to get the state `isSubmitSuccessful=true` and `isDirty=false`.
|
|
13
|
-
* So, this has to keep track of previous state.
|
|
14
|
-
*
|
|
15
|
-
* SubmitSuccessfulAndReset = was `isSubmitSuccessful` and now `!isSubmitSuccessful && !isDirty`
|
|
16
|
-
*/
|
|
17
|
-
const useFormOnSubmitSuccessfulAndReset = (callback) => {
|
|
18
|
-
const { isSubmitSuccessful, isDirty } = (0, react_hook_form_1.useFormState)();
|
|
19
|
-
/** Tracks whether form has been successfully submitted. (Ref as it should not trigger re-render.) */
|
|
20
|
-
const wasSubmittedSuccessfully = react_1.default.useRef(false);
|
|
21
|
-
// mark as submitted successfully
|
|
22
|
-
(0, useFormOnSubmitSuccessful_1.default)(() => {
|
|
23
|
-
wasSubmittedSuccessfully.current = true;
|
|
24
|
-
});
|
|
25
|
-
react_1.default.useEffect(() => {
|
|
26
|
-
if (!callback)
|
|
27
|
-
return;
|
|
28
|
-
// if hasn't been submitted successfully (to distinguish from initial load)
|
|
29
|
-
if (!wasSubmittedSuccessfully.current)
|
|
30
|
-
return;
|
|
31
|
-
// after resetting (and on initial load), both state vars are `false`
|
|
32
|
-
if (!isSubmitSuccessful && !isDirty) {
|
|
33
|
-
callback();
|
|
34
|
-
// reset ref
|
|
35
|
-
wasSubmittedSuccessfully.current = false;
|
|
36
|
-
}
|
|
37
|
-
}, [isSubmitSuccessful, isDirty]); // eslint-disable-line react-hooks/exhaustive-deps
|
|
38
|
-
};
|
|
39
|
-
exports.default = useFormOnSubmitSuccessfulAndReset;
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import type { KeepStateOptions } from 'react-hook-form';
|
|
2
|
-
type Options = {
|
|
3
|
-
enabled?: boolean;
|
|
4
|
-
} & KeepStateOptions;
|
|
5
|
-
/**
|
|
6
|
-
* Handle resetting after successful submit with no server validation errors.
|
|
7
|
-
* See `Rules` section: https://react-hook-form.com/api/useform/reset/
|
|
8
|
-
* Specifically: "- It's recommended to reset inside useEffect after submission."
|
|
9
|
-
*/
|
|
10
|
-
declare const useResetFormAfterSubmitSuccessful: (options?: Options) => void;
|
|
11
|
-
export default useResetFormAfterSubmitSuccessful;
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const react_hook_form_1 = require("react-hook-form");
|
|
7
|
-
const useFormOnSubmitSuccessful_1 = __importDefault(require("./useFormOnSubmitSuccessful"));
|
|
8
|
-
/**
|
|
9
|
-
* Handle resetting after successful submit with no server validation errors.
|
|
10
|
-
* See `Rules` section: https://react-hook-form.com/api/useform/reset/
|
|
11
|
-
* Specifically: "- It's recommended to reset inside useEffect after submission."
|
|
12
|
-
*/
|
|
13
|
-
const useResetFormAfterSubmitSuccessful = (options) => {
|
|
14
|
-
const { reset } = (0, react_hook_form_1.useFormContext)();
|
|
15
|
-
(0, useFormOnSubmitSuccessful_1.default)(() => {
|
|
16
|
-
if (!(options === null || options === void 0 ? void 0 : options.enabled))
|
|
17
|
-
return;
|
|
18
|
-
reset(undefined, options);
|
|
19
|
-
});
|
|
20
|
-
};
|
|
21
|
-
exports.default = useResetFormAfterSubmitSuccessful;
|
package/dist/cjs/utils.js
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
|
-
type Props = {
|
|
3
|
-
/** Flat field name. (e.g., `address.street`) */
|
|
4
|
-
path: string;
|
|
5
|
-
};
|
|
6
|
-
/**
|
|
7
|
-
* Empty, hidden marker to indicate a non-field/non-root error is being displayed to user.
|
|
8
|
-
*/
|
|
9
|
-
declare const FormNonFieldErrorMarker: React.FC<Props>;
|
|
10
|
-
export default FormNonFieldErrorMarker;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* HTML data attribute for {@link FormNonFieldErrorMarker}.
|
|
3
|
-
*/
|
|
4
|
-
declare const FormNonFieldErrorMarkerHtmlAttribute = "data-paragrav-rhf-utils-nonfield-error-marker-path";
|
|
5
|
-
export default FormNonFieldErrorMarkerHtmlAttribute;
|
|
6
|
-
export declare const getFormNonFieldErrorMarkerQuerySelector: (path: string) => string;
|
|
7
|
-
export declare const hasNonFieldErrorMarkerInDOM: (path: string, parentElement: Pick<HTMLElement, 'querySelector'>) => Element | null;
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Output form errors to console.debug() for easier debugging for certain condition.
|
|
3
|
-
* (e.g., in dev/staging environments or certain users)
|
|
4
|
-
*
|
|
5
|
-
* `console.debug()` is unlikely to trigger any automated console capture reporting.
|
|
6
|
-
*/
|
|
7
|
-
declare const useFormErrorConsoleDebug: (condition: boolean) => void;
|
|
8
|
-
export default useFormErrorConsoleDebug;
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Get callback to trigger submit manually on form.
|
|
3
|
-
* @link https://developer.mozilla.org/docs/Web/API/HTMLFormElement/requestSubmit
|
|
4
|
-
*/
|
|
5
|
-
declare const useFormRequestSubmit: (ref: React.RefObject<HTMLFormElement>) => HTMLFormElement['requestSubmit'];
|
|
6
|
-
export default useFormRequestSubmit;
|
package/dist/types/main.d.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
export { default as FormNonFieldErrorMarker } from './errors/nonfield/FormNonFieldErrorMarker';
|
|
2
|
-
export { default as FormNonFieldErrorMarkerHtmlAttribute } from './errors/nonfield/FormNonFieldErrorMarker.utils';
|
|
3
|
-
export { default as useFormErrorsHasOnlyOrphans } from './errors/orphan/useFormErrorsHasOnlyOrphans';
|
|
4
|
-
export { default as useOrphanFormErrors } from './errors/orphan/useOrphanFormErrors';
|
|
5
|
-
export { default as useOrphanFormErrorsToConsoleError } from './errors/orphan/useOrphanFormErrorsToConsoleError';
|
|
6
|
-
export { default as useRootFormFieldErrors } from './errors/root/useRootFormFieldErrors';
|
|
7
|
-
export { default as useFormErrorConsoleDebug } from './errors/useFormErrorConsoleDebug';
|
|
8
|
-
export { default as useFormErrorsEffect } from './errors/useFormErrorsEffect';
|
|
9
|
-
export { default as useFormErrorsIfAny } from './errors/useFormErrorsIfAny';
|
|
10
|
-
export { default as useFormErrorsOnChange } from './errors/useFormErrorsOnChange';
|
|
11
|
-
export { default as useFormRequestSubmit } from './errors/useFormRequestSubmit';
|
|
12
|
-
export { default as useFormOnSubmitSuccessful } from './submit/useFormOnSubmitSuccessful';
|
|
13
|
-
export { default as useFormOnSubmitSuccessfulAndReset } from './submit/useFormOnSubmitSuccessfulAndReset';
|
|
14
|
-
export { default as useResetFormAfterSubmitSuccessful } from './submit/useResetFormOnSubmitSuccessful';
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Calls a callback after a successful submit and after a form reset.
|
|
3
|
-
*
|
|
4
|
-
* Using RHF and following its rules, we are not able to get the state `isSubmitSuccessful=true` and `isDirty=false`.
|
|
5
|
-
* So, this has to keep track of previous state.
|
|
6
|
-
*
|
|
7
|
-
* SubmitSuccessfulAndReset = was `isSubmitSuccessful` and now `!isSubmitSuccessful && !isDirty`
|
|
8
|
-
*/
|
|
9
|
-
declare const useFormOnSubmitSuccessfulAndReset: (callback?: () => void) => void;
|
|
10
|
-
export default useFormOnSubmitSuccessfulAndReset;
|
package/dist/types/utils.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const isEmptyObject: (obj: Record<string, unknown>) => boolean;
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|