@paragrav/rhf-utils 0.0.20 → 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.
Files changed (88) hide show
  1. package/dist/{types/errors → errors}/getFlatFieldErrors.d.ts +8 -0
  2. package/dist/errors/getFlatFieldErrors.mjs +22 -0
  3. package/dist/{types/errors → errors}/nonfield/FormNonFieldErrorMarker.d.ts +1 -1
  4. package/dist/{cjs/main.d.ts → main.d.ts} +3 -0
  5. package/dist/main.mjs +30 -0
  6. package/dist/submit/useFormOnSubmitSuccessful.d.ts +2 -0
  7. package/dist/submit/useFormOnSubmitSuccessful.mjs +11 -0
  8. package/dist/submit/useFormOnSubmitSuccessfulAndReset.d.ts +10 -0
  9. package/dist/submit/useFormOnSubmitSuccessfulAndReset.mjs +14 -0
  10. package/dist/submit/useResetFormOnSubmitSuccessful.d.ts +12 -0
  11. package/dist/submit/useResetFormOnSubmitSuccessful.mjs +11 -0
  12. package/package.json +39 -41
  13. package/dist/cjs/errors/flattenFieldErrors.d.ts +0 -14
  14. package/dist/cjs/errors/flattenFieldErrors.js +0 -16
  15. package/dist/cjs/errors/getFlatFieldErrors.d.ts +0 -16
  16. package/dist/cjs/errors/getFlatFieldErrors.js +0 -40
  17. package/dist/cjs/errors/nonfield/FormNonFieldErrorMarker.d.ts +0 -10
  18. package/dist/cjs/errors/nonfield/FormNonFieldErrorMarker.js +0 -18
  19. package/dist/cjs/errors/nonfield/FormNonFieldErrorMarker.spec.js +0 -15
  20. package/dist/cjs/errors/nonfield/FormNonFieldErrorMarker.utils.js +0 -13
  21. package/dist/cjs/errors/nonfield/utils.d.ts +0 -17
  22. package/dist/cjs/errors/nonfield/utils.js +0 -20
  23. package/dist/cjs/errors/orphan/useFormErrorsHasOnlyOrphans.js +0 -19
  24. package/dist/cjs/errors/orphan/useOrphanFormErrors.d.ts +0 -3
  25. package/dist/cjs/errors/orphan/useOrphanFormErrors.js +0 -18
  26. package/dist/cjs/errors/orphan/useOrphanFormErrorsToConsoleError.d.ts +0 -7
  27. package/dist/cjs/errors/orphan/useOrphanFormErrorsToConsoleError.js +0 -27
  28. package/dist/cjs/errors/orphan/utils.d.ts +0 -3
  29. package/dist/cjs/errors/orphan/utils.js +0 -21
  30. package/dist/cjs/errors/root/useRootFormFieldErrors.d.ts +0 -6
  31. package/dist/cjs/errors/root/useRootFormFieldErrors.js +0 -13
  32. package/dist/cjs/errors/root/utils.d.ts +0 -11
  33. package/dist/cjs/errors/root/utils.js +0 -24
  34. package/dist/cjs/errors/useFormErrorConsoleDebug.js +0 -22
  35. package/dist/cjs/errors/useFormErrorsEffect.d.ts +0 -3
  36. package/dist/cjs/errors/useFormErrorsEffect.js +0 -14
  37. package/dist/cjs/errors/useFormErrorsIfAny.d.ts +0 -6
  38. package/dist/cjs/errors/useFormErrorsIfAny.js +0 -13
  39. package/dist/cjs/errors/useFormErrorsOnChange.d.ts +0 -6
  40. package/dist/cjs/errors/useFormErrorsOnChange.js +0 -15
  41. package/dist/cjs/errors/useFormFlatFieldErrors.d.ts +0 -5
  42. package/dist/cjs/errors/useFormFlatFieldErrors.js +0 -12
  43. package/dist/cjs/errors/useFormRequestSubmit.js +0 -13
  44. package/dist/cjs/main.js +0 -28
  45. package/dist/cjs/utils.js +0 -5
  46. package/dist/esm/errors/getFlatFieldErrors.mjs +0 -21
  47. package/dist/esm/main.mjs +0 -24
  48. package/dist/types/errors/nonfield/FormNonFieldErrorMarker.spec.d.ts +0 -1
  49. package/dist/types/errors/nonfield/FormNonFieldErrorMarker.utils.d.ts +0 -7
  50. package/dist/types/errors/orphan/useFormErrorsHasOnlyOrphans.d.ts +0 -2
  51. package/dist/types/errors/useFormErrorConsoleDebug.d.ts +0 -8
  52. package/dist/types/errors/useFormRequestSubmit.d.ts +0 -6
  53. package/dist/types/main.d.ts +0 -11
  54. package/dist/types/utils.d.ts +0 -1
  55. /package/dist/{types/errors → errors}/flattenFieldErrors.d.ts +0 -0
  56. /package/dist/{esm/errors → errors}/flattenFieldErrors.mjs +0 -0
  57. /package/dist/{esm/errors → errors}/nonfield/FormNonFieldErrorMarker.mjs +0 -0
  58. /package/dist/{cjs/errors → errors}/nonfield/FormNonFieldErrorMarker.spec.d.ts +0 -0
  59. /package/dist/{cjs/errors → errors}/nonfield/FormNonFieldErrorMarker.utils.d.ts +0 -0
  60. /package/dist/{esm/errors → errors}/nonfield/FormNonFieldErrorMarker.utils.mjs +0 -0
  61. /package/dist/{types/errors → errors}/nonfield/utils.d.ts +0 -0
  62. /package/dist/{esm/errors → errors}/nonfield/utils.mjs +0 -0
  63. /package/dist/{cjs/errors → errors}/orphan/useFormErrorsHasOnlyOrphans.d.ts +0 -0
  64. /package/dist/{esm/errors → errors}/orphan/useFormErrorsHasOnlyOrphans.mjs +0 -0
  65. /package/dist/{types/errors → errors}/orphan/useOrphanFormErrors.d.ts +0 -0
  66. /package/dist/{esm/errors → errors}/orphan/useOrphanFormErrors.mjs +0 -0
  67. /package/dist/{types/errors → errors}/orphan/useOrphanFormErrorsToConsoleError.d.ts +0 -0
  68. /package/dist/{esm/errors → errors}/orphan/useOrphanFormErrorsToConsoleError.mjs +0 -0
  69. /package/dist/{types/errors → errors}/orphan/utils.d.ts +0 -0
  70. /package/dist/{esm/errors → errors}/orphan/utils.mjs +0 -0
  71. /package/dist/{types/errors → errors}/root/useRootFormFieldErrors.d.ts +0 -0
  72. /package/dist/{esm/errors → errors}/root/useRootFormFieldErrors.mjs +0 -0
  73. /package/dist/{types/errors → errors}/root/utils.d.ts +0 -0
  74. /package/dist/{esm/errors → errors}/root/utils.mjs +0 -0
  75. /package/dist/{cjs/errors → errors}/useFormErrorConsoleDebug.d.ts +0 -0
  76. /package/dist/{esm/errors → errors}/useFormErrorConsoleDebug.mjs +0 -0
  77. /package/dist/{types/errors → errors}/useFormErrorsEffect.d.ts +0 -0
  78. /package/dist/{esm/errors → errors}/useFormErrorsEffect.mjs +0 -0
  79. /package/dist/{types/errors → errors}/useFormErrorsIfAny.d.ts +0 -0
  80. /package/dist/{esm/errors → errors}/useFormErrorsIfAny.mjs +0 -0
  81. /package/dist/{types/errors → errors}/useFormErrorsOnChange.d.ts +0 -0
  82. /package/dist/{esm/errors → errors}/useFormErrorsOnChange.mjs +0 -0
  83. /package/dist/{types/errors → errors}/useFormFlatFieldErrors.d.ts +0 -0
  84. /package/dist/{esm/errors → errors}/useFormFlatFieldErrors.mjs +0 -0
  85. /package/dist/{cjs/errors → errors}/useFormRequestSubmit.d.ts +0 -0
  86. /package/dist/{esm/errors → errors}/useFormRequestSubmit.mjs +0 -0
  87. /package/dist/{cjs/utils.d.ts → utils.d.ts} +0 -0
  88. /package/dist/{esm/utils.mjs → utils.mjs} +0 -0
@@ -15,3 +15,11 @@ export type FlatFieldErrors = Record<string, FieldError>;
15
15
  */
16
16
  declare const getFlatFieldErrors: (errors: FieldErrors) => FlatFieldErrors;
17
17
  export default getFlatFieldErrors;
18
+ /**
19
+ * Regular expression to maybe match the end of a leaf node path.
20
+ *
21
+ * i.e., `name.type`, `address.street.message`
22
+ *
23
+ * iow: dot [?: non-capturing]("type" | "message")[\b word boundary][$ end of string]
24
+ */
25
+ export declare const regexMaybeFieldErrorLeafNode: RegExp;
@@ -0,0 +1,22 @@
1
+ import { get as l } from "react-hook-form";
2
+ import n from "./flattenFieldErrors.mjs";
3
+ const d = (t) => {
4
+ const a = n(t), c = Object.keys(a);
5
+ return Object.fromEntries(
6
+ c.reduce(
7
+ (r, o) => {
8
+ const e = o.replace(f, "");
9
+ if (e === o)
10
+ return r;
11
+ const s = l(t, e, void 0);
12
+ return s && r.push([e, s]), r;
13
+ },
14
+ []
15
+ // entries
16
+ )
17
+ );
18
+ }, u = d, f = /\.(?:type|message)\b$/;
19
+ export {
20
+ u as default,
21
+ f as regexMaybeFieldErrorLeafNode
22
+ };
@@ -4,7 +4,7 @@ type Props = {
4
4
  path: string;
5
5
  };
6
6
  /**
7
- * Empty, hidden marker to indicate a non-field error is presented to user.
7
+ * Empty, hidden marker to indicate a non-field/non-root error is being displayed to user.
8
8
  */
9
9
  declare const FormNonFieldErrorMarker: React.FC<Props>;
10
10
  export default FormNonFieldErrorMarker;
@@ -9,3 +9,6 @@ export { default as useFormErrorsEffect } from './errors/useFormErrorsEffect';
9
9
  export { default as useFormErrorsIfAny } from './errors/useFormErrorsIfAny';
10
10
  export { default as useFormErrorsOnChange } from './errors/useFormErrorsOnChange';
11
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';
package/dist/main.mjs ADDED
@@ -0,0 +1,30 @@
1
+ import { default as e } from "./errors/nonfield/FormNonFieldErrorMarker.mjs";
2
+ import { default as t } from "./errors/nonfield/FormNonFieldErrorMarker.utils.mjs";
3
+ import { default as a } from "./errors/orphan/useFormErrorsHasOnlyOrphans.mjs";
4
+ import { default as m } from "./errors/orphan/useOrphanFormErrors.mjs";
5
+ import { default as d } from "./errors/orphan/useOrphanFormErrorsToConsoleError.mjs";
6
+ import { default as F } from "./errors/root/useRootFormFieldErrors.mjs";
7
+ import { default as x } from "./errors/useFormErrorConsoleDebug.mjs";
8
+ import { default as i } from "./errors/useFormErrorsEffect.mjs";
9
+ import { default as O } from "./errors/useFormErrorsIfAny.mjs";
10
+ import { default as b } from "./errors/useFormErrorsOnChange.mjs";
11
+ import { default as A } from "./errors/useFormRequestSubmit.mjs";
12
+ import { default as C } from "./submit/useFormOnSubmitSuccessful.mjs";
13
+ import { default as k } from "./submit/useFormOnSubmitSuccessfulAndReset.mjs";
14
+ import { default as H } from "./submit/useResetFormOnSubmitSuccessful.mjs";
15
+ export {
16
+ e as FormNonFieldErrorMarker,
17
+ t as FormNonFieldErrorMarkerHtmlAttribute,
18
+ x as useFormErrorConsoleDebug,
19
+ i as useFormErrorsEffect,
20
+ a as useFormErrorsHasOnlyOrphans,
21
+ O as useFormErrorsIfAny,
22
+ b as useFormErrorsOnChange,
23
+ C as useFormOnSubmitSuccessful,
24
+ k as useFormOnSubmitSuccessfulAndReset,
25
+ A as useFormRequestSubmit,
26
+ m as useOrphanFormErrors,
27
+ d as useOrphanFormErrorsToConsoleError,
28
+ H as useResetFormAfterSubmitSuccessful,
29
+ F as useRootFormFieldErrors
30
+ };
@@ -0,0 +1,2 @@
1
+ declare const useFormOnSubmitSuccessful: (callback?: () => void) => void;
2
+ export default useFormOnSubmitSuccessful;
@@ -0,0 +1,11 @@
1
+ import u from "react";
2
+ import { useFormState as e } from "react-hook-form";
3
+ const o = (s) => {
4
+ const { isSubmitSuccessful: t } = e();
5
+ u.useEffect(() => {
6
+ s && t && s();
7
+ }, [s, t]);
8
+ }, r = o;
9
+ export {
10
+ r as default
11
+ };
@@ -0,0 +1,10 @@
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;
@@ -0,0 +1,14 @@
1
+ import r from "react";
2
+ import { useFormState as c } from "react-hook-form";
3
+ import f from "./useFormOnSubmitSuccessful.mjs";
4
+ const m = (s) => {
5
+ const { isSubmitSuccessful: t, isDirty: u } = c(), e = r.useRef(!1);
6
+ f(() => {
7
+ e.current = !0;
8
+ }), r.useEffect(() => {
9
+ s && e.current && !t && !u && (s(), e.current = !1);
10
+ }, [t, u]);
11
+ }, S = m;
12
+ export {
13
+ S as default
14
+ };
@@ -0,0 +1,12 @@
1
+ import { KeepStateOptions } from 'react-hook-form';
2
+
3
+ type Options = {
4
+ enabled?: boolean;
5
+ } & KeepStateOptions;
6
+ /**
7
+ * Handle resetting after successful submit with no server validation errors.
8
+ * See `Rules` section: https://react-hook-form.com/api/useform/reset/
9
+ * Specifically: "- It's recommended to reset inside useEffect after submission."
10
+ */
11
+ declare const useResetFormAfterSubmitSuccessful: (options?: Options) => void;
12
+ export default useResetFormAfterSubmitSuccessful;
@@ -0,0 +1,11 @@
1
+ import { useFormContext as r } from "react-hook-form";
2
+ import t from "./useFormOnSubmitSuccessful.mjs";
3
+ const s = (e) => {
4
+ const { reset: u } = r();
5
+ t(() => {
6
+ e != null && e.enabled && u(void 0, e);
7
+ });
8
+ }, f = s;
9
+ export {
10
+ f as default
11
+ };
package/package.json CHANGED
@@ -2,80 +2,78 @@
2
2
  "name": "@paragrav/rhf-utils",
3
3
  "author": "paragrav.dev",
4
4
  "license": "MIT",
5
- "version": "0.0.20",
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
- "main": "./dist/cjs/main.js",
13
- "module": "./dist/esm/main.mjs",
12
+ "module": "./dist/main.mjs",
14
13
  "exports": {
15
14
  ".": {
16
- "import": "./dist/esm/main.mjs",
17
- "require": "./dist/cjs/main.js",
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
- "import": "./dist/esm/errors/useFormErrorConsoleDebug.mjs",
22
- "require": "./dist/cjs/errors/useFormErrorConsoleDebug.cjs",
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
- "import": "./dist/esm/errors/useFormErrorsEffect.mjs",
27
- "require": "./dist/cjs/errors/useFormErrorsEffect.cjs",
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
- "import": "./dist/esm/errors/useFormErrorsIfAny.mjs",
32
- "require": "./dist/cjs/errors/useFormErrorsIfAny.cjs",
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
- "import": "./dist/esm/errors/useFormErrorsOnChange.mjs",
37
- "require": "./dist/cjs/errors/useFormErrorsOnChange.cjs",
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
- "import": "./dist/esm/errors/useFormRequestSubmit.mjs",
42
- "require": "./dist/cjs/errors/useFormRequestSubmit.cjs",
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
- "import": "./dist/esm/errors/nonfield/FormNonFieldErrorMarker.mjs",
47
- "require": "./dist/cjs/errors/nonfield/FormNonFieldErrorMarker.cjs",
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
- "import": "./dist/esm/errors/nonfield/FormNonFieldErrorMarker.utils.mjs",
52
- "require": "./dist/cjs/errors/nonfield/FormNonFieldErrorMarker.utils.cjs",
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
- "import": "./dist/esm/errors/orphan/useOrphanFormErrorsToConsoleError.mjs",
57
- "require": "./dist/cjs/errors/orphan/useOrphanFormErrorsToConsoleError.cjs",
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
- "import": "./dist/esm/errors/orphan/useFormErrorsHasOnlyOrphans.mjs",
62
- "require": "./dist/cjs/errors/orphan/useFormErrorsHasOnlyOrphans.cjs",
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
- "import": "./dist/esm/errors/orphan/useOrphanFormErrors.mjs",
67
- "require": "./dist/cjs/errors/orphan/useOrphanFormErrors.cjs",
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
- "import": "./dist/esm/errors/root/useRootFormFieldErrors.mjs",
72
- "require": "./dist/cjs/errors/root/useRootFormFieldErrors.cjs",
73
- "types": "./dist/types/errors/root/useRootFormFieldErrors.d.ts"
59
+ "default": "./dist/errors/root/useRootFormFieldErrors.mjs",
60
+ "types": "./dist/errors/root/useRootFormFieldErrors.d.ts"
61
+ },
62
+ "./submit/useFormOnSubmitSuccessful": {
63
+ "default": "./dist/submit/useFormOnSubmitSuccessful.mjs",
64
+ "types": "./dist/submit/useFormOnSubmitSuccessful.d.ts"
65
+ },
66
+ "./submit/useFormOnSubmitSuccessfulAndReset": {
67
+ "default": "./dist/submit/useFormOnSubmitSuccessfulAndReset.mjs",
68
+ "types": "./dist/submit/useFormOnSubmitSuccessfulAndReset.d.ts"
69
+ },
70
+ "./submit/useResetFormAfterSubmitSuccessful": {
71
+ "default": "./dist/submit/useResetFormAfterSubmitSuccessful.mjs",
72
+ "types": "./dist/submit/useResetFormAfterSubmitSuccessful.d.ts"
74
73
  }
75
74
  },
76
75
  "scripts": {
77
- "build": "npm run validate && npm run build:cjs && npm run build:esm",
78
- "build:cjs": "tsc -p ./tsconfig.cjs.json",
76
+ "build": "npm run validate && npm run build:esm",
79
77
  "build:esm": "vite build",
80
78
  "lint": "eslint --ignore-path ./.gitignore --ext ts,tsx --report-unused-disable-directives --max-warnings 0 .",
81
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,16 +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;
@@ -1,40 +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 flattenFieldErrors_1 = __importDefault(require("./flattenFieldErrors"));
8
- /**
9
- * Get {@link FlatFieldErrors} from {@link FieldErrors}.
10
- * This makes it easy to work with potentially deeply-nested {@link FieldErrors}.
11
- *
12
- * @param errors {@link FieldErrors} object.
13
- * @returns FlatFieldErrors object.
14
- *
15
- * e.g.,
16
- * ```
17
- * [ "address.street", { "address.street": { type: "too_short", ref: { value: "123" }, message: "Required." } } ]
18
- * ```
19
- */
20
- const getFlatFieldErrors = (errors) => {
21
- const flattened = (0, flattenFieldErrors_1.default)(errors);
22
- const keys = Object.keys(flattened);
23
- return Object.fromEntries(keys.reduce((entries, key) => {
24
- // look for leaf node, which would have required `type` prop (e.g., `name.type`, `address.street.type`)
25
- // remove `regexEndsWithType` suffix to get flat field path (e.g., `name`, `address.street`)
26
- const path = key.replace(regexEndsWithType, '');
27
- // if nothing replaced, then it's not a leaf node
28
- if (path === key)
29
- return entries;
30
- // find field error in FieldErrors object
31
- // has dual-purpose of confirming that each path is valid
32
- const fieldError = (0, react_hook_form_1.get)(errors, path, undefined);
33
- if (!fieldError)
34
- return entries;
35
- entries.push([path, fieldError]);
36
- return entries;
37
- }, []));
38
- };
39
- exports.default = getFlatFieldErrors;
40
- const regexEndsWithType = /\.type$/;
@@ -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 error is presented to user.
8
- */
9
- declare const FormNonFieldErrorMarker: React.FC<Props>;
10
- export default FormNonFieldErrorMarker;
@@ -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 error is presented 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 no orphans, or no errors
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,3 +0,0 @@
1
- import React from 'react';
2
- declare const useOrphanFormErrors: (formRef: React.RefObject<HTMLFormElement>) => import("@/errors/getFlatFieldErrors").FlatFieldErrors;
3
- export default useOrphanFormErrors;
@@ -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,3 +0,0 @@
1
- import type { FieldErrors } from 'react-hook-form';
2
- import type { FlatFieldErrors } from '../getFlatFieldErrors';
3
- export declare const getOrphanFlatFieldErrors: (errors: FieldErrors, parentElement: Pick<HTMLElement, 'querySelector'>) => FlatFieldErrors;
@@ -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,6 +0,0 @@
1
- /**
2
- * Root field errors from form.
3
- * These are typically displayed at the bottom of the form.
4
- */
5
- declare const useRootFormFieldErrors: () => import("@/errors/getFlatFieldErrors").FlatFieldErrors;
6
- export default useRootFormFieldErrors;
@@ -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,3 +0,0 @@
1
- import type { FieldErrors } from 'react-hook-form';
2
- declare const useFormErrorsEffect: <TReturn>(callback: (errors: FieldErrors) => TReturn) => void;
3
- export default useFormErrorsEffect;
@@ -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,6 +0,0 @@
1
- import type { FieldErrors } from 'react-hook-form';
2
- /**
3
- * Provide a callback to call when RHF errors change.
4
- */
5
- declare const useFormErrorsOnChange: <TReturn>(callback: (errors: FieldErrors) => TReturn) => TReturn;
6
- export default useFormErrorsOnChange;
@@ -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,5 +0,0 @@
1
- /**
2
- * Use {@link FieldErrors} as {@link FlatFieldErrors}.
3
- */
4
- declare const useFormFlatFieldErrors: () => import("./getFlatFieldErrors").FlatFieldErrors;
5
- export default useFormFlatFieldErrors;
@@ -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,28 +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.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; } });
package/dist/cjs/utils.js DELETED
@@ -1,5 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isEmptyObject = void 0;
4
- const isEmptyObject = (obj) => JSON.stringify(obj) === '{}';
5
- exports.isEmptyObject = isEmptyObject;
@@ -1,21 +0,0 @@
1
- import { get as l } from "react-hook-form";
2
- import d from "./flattenFieldErrors.mjs";
3
- const f = (e) => {
4
- const s = d(e), c = Object.keys(s);
5
- return Object.fromEntries(
6
- c.reduce(
7
- (t, o) => {
8
- const r = o.replace(a, "");
9
- if (r === o)
10
- return t;
11
- const n = l(e, r, void 0);
12
- return n && t.push([r, n]), t;
13
- },
14
- []
15
- // entries
16
- )
17
- );
18
- }, u = f, a = /\.type$/;
19
- export {
20
- u as default
21
- };
package/dist/esm/main.mjs DELETED
@@ -1,24 +0,0 @@
1
- import { default as e } from "./errors/nonfield/FormNonFieldErrorMarker.mjs";
2
- import { default as t } from "./errors/nonfield/FormNonFieldErrorMarker.utils.mjs";
3
- import { default as f } from "./errors/orphan/useFormErrorsHasOnlyOrphans.mjs";
4
- import { default as u } from "./errors/orphan/useOrphanFormErrors.mjs";
5
- import { default as d } from "./errors/orphan/useOrphanFormErrorsToConsoleError.mjs";
6
- import { default as F } from "./errors/root/useRootFormFieldErrors.mjs";
7
- import { default as n } from "./errors/useFormErrorConsoleDebug.mjs";
8
- import { default as i } from "./errors/useFormErrorsEffect.mjs";
9
- import { default as h } from "./errors/useFormErrorsIfAny.mjs";
10
- import { default as C } from "./errors/useFormErrorsOnChange.mjs";
11
- import { default as k } from "./errors/useFormRequestSubmit.mjs";
12
- export {
13
- e as FormNonFieldErrorMarker,
14
- t as FormNonFieldErrorMarkerHtmlAttribute,
15
- n as useFormErrorConsoleDebug,
16
- i as useFormErrorsEffect,
17
- f as useFormErrorsHasOnlyOrphans,
18
- h as useFormErrorsIfAny,
19
- C as useFormErrorsOnChange,
20
- k as useFormRequestSubmit,
21
- u as useOrphanFormErrors,
22
- d as useOrphanFormErrorsToConsoleError,
23
- F as useRootFormFieldErrors
24
- };
@@ -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,2 +0,0 @@
1
- declare const useFormErrorsHasOnlyOrphans: (formRef: React.RefObject<HTMLFormElement>) => boolean;
2
- export default useFormErrorsHasOnlyOrphans;
@@ -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;
@@ -1,11 +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';
@@ -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