@paragrav/rhf-utils 0.0.19 → 0.0.20

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 (56) hide show
  1. package/dist/cjs/errors/nonfield/FormNonFieldErrorMarker.js +5 -2
  2. package/dist/cjs/errors/nonfield/FormNonFieldErrorMarker.utils.d.ts +2 -1
  3. package/dist/cjs/errors/nonfield/FormNonFieldErrorMarker.utils.js +5 -3
  4. package/dist/cjs/errors/nonfield/utils.d.ts +1 -1
  5. package/dist/cjs/errors/nonfield/utils.js +1 -1
  6. package/dist/cjs/errors/orphan/useFormErrorsHasOnlyOrphans.d.ts +2 -0
  7. package/dist/cjs/errors/orphan/useFormErrorsHasOnlyOrphans.js +19 -0
  8. package/dist/cjs/errors/{orphans/useFormOrphanErrors.d.ts → orphan/useOrphanFormErrors.d.ts} +2 -2
  9. package/dist/cjs/errors/{orphans/useFormOrphanErrors.js → orphan/useOrphanFormErrors.js} +6 -7
  10. package/dist/cjs/errors/orphan/useOrphanFormErrorsToConsoleError.d.ts +7 -0
  11. package/dist/cjs/errors/{orphans/useFormErrorOrphansToConsoleError.js → orphan/useOrphanFormErrorsToConsoleError.js} +6 -8
  12. package/dist/cjs/errors/orphan/utils.d.ts +3 -0
  13. package/dist/cjs/errors/{orphans → orphan}/utils.js +3 -3
  14. package/dist/cjs/errors/root/{useFormRootFieldErrors.d.ts → useRootFormFieldErrors.d.ts} +2 -2
  15. package/dist/cjs/errors/root/{useFormRootFieldErrors.js → useRootFormFieldErrors.js} +2 -2
  16. package/dist/cjs/errors/useFormErrorConsoleDebug.js +2 -2
  17. package/dist/cjs/errors/useFormErrorsIfAny.d.ts +6 -0
  18. package/dist/cjs/errors/{useFormContextErrorsIfAny.js → useFormErrorsIfAny.js} +2 -2
  19. package/dist/cjs/errors/useFormFlatFieldErrors.d.ts +5 -0
  20. package/dist/cjs/errors/useFormFlatFieldErrors.js +12 -0
  21. package/dist/cjs/main.d.ts +6 -4
  22. package/dist/cjs/main.js +12 -8
  23. package/dist/esm/errors/getFlatFieldErrors.mjs +8 -8
  24. package/dist/esm/errors/nonfield/FormNonFieldErrorMarker.mjs +1 -1
  25. package/dist/esm/errors/nonfield/FormNonFieldErrorMarker.utils.mjs +3 -3
  26. package/dist/esm/errors/orphan/useFormErrorsHasOnlyOrphans.mjs +10 -0
  27. package/dist/esm/errors/orphan/useOrphanFormErrors.mjs +14 -0
  28. package/dist/esm/errors/{orphans/useFormErrorOrphansToConsoleError.mjs → orphan/useOrphanFormErrorsToConsoleError.mjs} +2 -2
  29. package/dist/esm/errors/{orphans → orphan}/utils.mjs +1 -1
  30. package/dist/esm/errors/useFormErrorConsoleDebug.mjs +3 -3
  31. package/dist/esm/errors/useFormErrorsIfAny.mjs +9 -0
  32. package/dist/esm/errors/useFormFlatFieldErrors.mjs +6 -0
  33. package/dist/esm/main.mjs +20 -16
  34. package/dist/types/errors/nonfield/FormNonFieldErrorMarker.utils.d.ts +2 -1
  35. package/dist/types/errors/nonfield/utils.d.ts +1 -1
  36. package/dist/types/errors/orphan/useFormErrorsHasOnlyOrphans.d.ts +2 -0
  37. package/dist/types/errors/{orphans/useFormOrphanErrors.d.ts → orphan/useOrphanFormErrors.d.ts} +2 -2
  38. package/dist/types/errors/orphan/useOrphanFormErrorsToConsoleError.d.ts +8 -0
  39. package/dist/types/errors/orphan/utils.d.ts +4 -0
  40. package/dist/types/errors/root/{useFormRootFieldErrors.d.ts → useRootFormFieldErrors.d.ts} +2 -2
  41. package/dist/types/errors/useFormErrorsIfAny.d.ts +6 -0
  42. package/dist/types/errors/useFormFlatFieldErrors.d.ts +5 -0
  43. package/dist/types/main.d.ts +6 -4
  44. package/package.json +58 -13
  45. package/dist/cjs/errors/orphans/useFormErrorOrphansToConsoleError.d.ts +0 -9
  46. package/dist/cjs/errors/orphans/useFormErrorsHasOnlyOrphan.d.ts +0 -2
  47. package/dist/cjs/errors/orphans/useFormErrorsHasOnlyOrphan.js +0 -21
  48. package/dist/cjs/errors/orphans/utils.d.ts +0 -3
  49. package/dist/cjs/errors/useFormContextErrorsIfAny.d.ts +0 -6
  50. package/dist/esm/errors/orphans/useFormOrphanErrors.mjs +0 -14
  51. package/dist/esm/errors/useFormContextErrorsIfAny.mjs +0 -9
  52. package/dist/types/errors/orphans/useFormErrorOrphansToConsoleError.d.ts +0 -10
  53. package/dist/types/errors/orphans/useFormErrorsHasOnlyOrphan.d.ts +0 -2
  54. package/dist/types/errors/orphans/utils.d.ts +0 -4
  55. package/dist/types/errors/useFormContextErrorsIfAny.d.ts +0 -6
  56. /package/dist/esm/errors/root/{useFormRootFieldErrors.mjs → useRootFormFieldErrors.mjs} +0 -0
@@ -1,13 +1,16 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  const jsx_runtime_1 = require("react/jsx-runtime");
4
- const FormNonFieldErrorMarker_utils_1 = require("./FormNonFieldErrorMarker.utils");
7
+ const FormNonFieldErrorMarker_utils_1 = __importDefault(require("./FormNonFieldErrorMarker.utils"));
5
8
  /**
6
9
  * Empty, hidden marker to indicate a non-field error is presented to user.
7
10
  */
8
11
  const FormNonFieldErrorMarker = ({ path }) => {
9
12
  const dataAttribute = {
10
- [FormNonFieldErrorMarker_utils_1.FormNonFieldErrorMarkerHtmlAttribute]: path,
13
+ [FormNonFieldErrorMarker_utils_1.default]: path,
11
14
  };
12
15
  return ((0, jsx_runtime_1.jsx)("div", { role: "alert", "aria-hidden": "true" // hide from screen readers
13
16
  , style: { display: 'none' }, ...dataAttribute }));
@@ -1,6 +1,7 @@
1
1
  /**
2
2
  * HTML data attribute for {@link FormNonFieldErrorMarker}.
3
3
  */
4
- export declare const FormNonFieldErrorMarkerHtmlAttribute = "data-paragrav-rhf-utils-nonfield-error-marker-path";
4
+ declare const FormNonFieldErrorMarkerHtmlAttribute = "data-paragrav-rhf-utils-nonfield-error-marker-path";
5
+ export default FormNonFieldErrorMarkerHtmlAttribute;
5
6
  export declare const getFormNonFieldErrorMarkerQuerySelector: (path: string) => string;
6
7
  export declare const hasNonFieldErrorMarkerInDOM: (path: string, parentElement: Pick<HTMLElement, 'querySelector'>) => Element | null;
@@ -1,11 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.hasNonFieldErrorMarkerInDOM = exports.getFormNonFieldErrorMarkerQuerySelector = exports.FormNonFieldErrorMarkerHtmlAttribute = void 0;
3
+ exports.hasNonFieldErrorMarkerInDOM = exports.getFormNonFieldErrorMarkerQuerySelector = void 0;
4
4
  /**
5
5
  * HTML data attribute for {@link FormNonFieldErrorMarker}.
6
6
  */
7
- exports.FormNonFieldErrorMarkerHtmlAttribute = 'data-paragrav-rhf-utils-nonfield-error-marker-path';
8
- const getFormNonFieldErrorMarkerQuerySelector = (path) => `[role="alert"][${exports.FormNonFieldErrorMarkerHtmlAttribute}="${path}"]`;
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}"]`;
9
11
  exports.getFormNonFieldErrorMarkerQuerySelector = getFormNonFieldErrorMarkerQuerySelector;
10
12
  const hasNonFieldErrorMarkerInDOM = (path, parentElement) => parentElement.querySelector((0, exports.getFormNonFieldErrorMarkerQuerySelector)(path));
11
13
  exports.hasNonFieldErrorMarkerInDOM = hasNonFieldErrorMarkerInDOM;
@@ -12,6 +12,6 @@ import type { FieldError } from 'react-hook-form';
12
12
  * - Orphan (undisplayed), which are typically caused by one of the following cases:
13
13
  * - The input is missing.
14
14
  * - The schema is incorrect.
15
- * - The non-field error is not displayed to user with `FormErrorNonFieldMarker`.
15
+ * - The error is not displayed to user with `FormErrorNonFieldMarker`.
16
16
  */
17
17
  export declare const isNonFieldError: (error: FieldError) => boolean;
@@ -14,7 +14,7 @@ exports.isNonFieldError = void 0;
14
14
  * - Orphan (undisplayed), which are typically caused by one of the following cases:
15
15
  * - The input is missing.
16
16
  * - The schema is incorrect.
17
- * - The non-field error is not displayed to user with `FormErrorNonFieldMarker`.
17
+ * - The error is not displayed to user with `FormErrorNonFieldMarker`.
18
18
  */
19
19
  const isNonFieldError = (error) => !error.ref;
20
20
  exports.isNonFieldError = isNonFieldError;
@@ -0,0 +1,2 @@
1
+ declare const useFormErrorsHasOnlyOrphans: (formRef: React.RefObject<HTMLFormElement>) => boolean;
2
+ export default useFormErrorsHasOnlyOrphans;
@@ -0,0 +1,19 @@
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 +1,3 @@
1
1
  import React from 'react';
2
- declare const useFormOrphanErrors: (formRef: React.RefObject<HTMLFormElement>) => import("@/errors/getFlatFieldErrors").FlatFieldErrors;
3
- export default useFormOrphanErrors;
2
+ declare const useOrphanFormErrors: (formRef: React.RefObject<HTMLFormElement>) => import("@/errors/getFlatFieldErrors").FlatFieldErrors;
3
+ export default useOrphanFormErrors;
@@ -6,14 +6,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const utils_1 = require("@/utils");
7
7
  const useFormErrorsOnChange_1 = __importDefault(require("../useFormErrorsOnChange"));
8
8
  const utils_2 = require("./utils");
9
- const useFormOrphanErrors = (formRef) => (0, useFormErrorsOnChange_1.default)((errors) => {
9
+ const useOrphanFormErrors = (formRef) => (0, useFormErrorsOnChange_1.default)((errors) => {
10
10
  // if no errors, return early
11
11
  if ((0, utils_1.isEmptyObject)(errors))
12
12
  return {};
13
- if (!formRef.current) {
14
- console.error(errors);
15
- throw new Error('This should not happen.');
16
- }
17
- return (0, utils_2.getRootFlatFieldErrors)(errors, formRef.current);
13
+ // this should never happen
14
+ if (!formRef.current)
15
+ throw new Error();
16
+ return (0, utils_2.getOrphanFlatFieldErrors)(errors, formRef.current);
18
17
  });
19
- exports.default = useFormOrphanErrors;
18
+ exports.default = useOrphanFormErrors;
@@ -0,0 +1,7 @@
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;
@@ -5,25 +5,23 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const react_1 = __importDefault(require("react"));
7
7
  const react_hook_form_1 = require("react-hook-form");
8
- const useFormOrphanErrors_1 = __importDefault(require("./useFormOrphanErrors"));
8
+ const useOrphanFormErrors_1 = __importDefault(require("./useOrphanFormErrors"));
9
9
  /**
10
- * Orphans are field errors that do not have a ref.
11
- * (Most commonly `root(.*)`, but these are filtered out. They are handled by `useFormRootFieldErrors`.)
12
- * Outputs to `console.error` all errors with `ref: undefined` that do not begin with `root(.*)`.
10
+ * Outputs orphan errors to `console.error` all errors with `ref: undefined` that do not begin with `root(.*)`.
13
11
  * Sentry (or equivalent) should capture.
14
12
  */
15
- const useFormErrorOrphansToConsoleError = (formRef) => {
13
+ const useOrphanFormErrorsToConsoleError = (formRef) => {
16
14
  const { getValues } = (0, react_hook_form_1.useFormContext)();
17
15
  const { errors } = (0, react_hook_form_1.useFormState)();
18
- const orphans = (0, useFormOrphanErrors_1.default)(formRef);
16
+ const orphans = (0, useOrphanFormErrors_1.default)(formRef);
19
17
  react_1.default.useEffect(() => {
20
18
  if (!Object.keys(orphans).length)
21
19
  return;
22
- console.error('useFormErrorOrphansToConsoleError', {
20
+ console.error('useOrphanFormErrorsToConsoleError', {
23
21
  location: window.location,
24
22
  values: getValues(),
25
23
  orphans,
26
24
  });
27
25
  }, [errors, getValues, orphans]);
28
26
  };
29
- exports.default = useFormErrorOrphansToConsoleError;
27
+ exports.default = useOrphanFormErrorsToConsoleError;
@@ -0,0 +1,3 @@
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;
@@ -3,12 +3,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.getRootFlatFieldErrors = void 0;
6
+ exports.getOrphanFlatFieldErrors = void 0;
7
7
  const getFlatFieldErrors_1 = __importDefault(require("../getFlatFieldErrors"));
8
8
  const FormNonFieldErrorMarker_utils_1 = require("../nonfield/FormNonFieldErrorMarker.utils");
9
9
  const utils_1 = require("../nonfield/utils");
10
10
  const utils_2 = require("../root/utils");
11
- const getRootFlatFieldErrors = (errors, parentElement) => {
11
+ const getOrphanFlatFieldErrors = (errors, parentElement) => {
12
12
  const flatFieldErrors = (0, getFlatFieldErrors_1.default)(errors);
13
13
  return Object.fromEntries(Object.entries(flatFieldErrors).filter(([path, error]) =>
14
14
  // not root path
@@ -18,4 +18,4 @@ const getRootFlatFieldErrors = (errors, parentElement) => {
18
18
  // does not have marker
19
19
  !(0, FormNonFieldErrorMarker_utils_1.hasNonFieldErrorMarkerInDOM)(path, parentElement)));
20
20
  };
21
- exports.getRootFlatFieldErrors = getRootFlatFieldErrors;
21
+ exports.getOrphanFlatFieldErrors = getOrphanFlatFieldErrors;
@@ -2,5 +2,5 @@
2
2
  * Root field errors from form.
3
3
  * These are typically displayed at the bottom of the form.
4
4
  */
5
- declare const useFormRootFieldErrors: () => import("@/errors/getFlatFieldErrors").FlatFieldErrors;
6
- export default useFormRootFieldErrors;
5
+ declare const useRootFormFieldErrors: () => import("@/errors/getFlatFieldErrors").FlatFieldErrors;
6
+ export default useRootFormFieldErrors;
@@ -9,5 +9,5 @@ const utils_1 = require("./utils");
9
9
  * Root field errors from form.
10
10
  * These are typically displayed at the bottom of the form.
11
11
  */
12
- const useFormRootFieldErrors = () => (0, useFormErrorsOnChange_1.default)(utils_1.getRootFlatFieldErrors);
13
- exports.default = useFormRootFieldErrors;
12
+ const useRootFormFieldErrors = () => (0, useFormErrorsOnChange_1.default)(utils_1.getRootFlatFieldErrors);
13
+ exports.default = useRootFormFieldErrors;
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- const useFormContextErrorsIfAny_1 = __importDefault(require("./useFormContextErrorsIfAny"));
6
+ const useFormErrorsIfAny_1 = __importDefault(require("./useFormErrorsIfAny"));
7
7
  /**
8
8
  * Output form errors to console.debug() for easier debugging for certain condition.
9
9
  * (e.g., in dev/staging environments or certain users)
@@ -11,7 +11,7 @@ const useFormContextErrorsIfAny_1 = __importDefault(require("./useFormContextErr
11
11
  * `console.debug()` is unlikely to trigger any automated console capture reporting.
12
12
  */
13
13
  const useFormErrorConsoleDebug = (condition) => {
14
- const errors = (0, useFormContextErrorsIfAny_1.default)();
14
+ const errors = (0, useFormErrorsIfAny_1.default)();
15
15
  if (!condition)
16
16
  return;
17
17
  if (!errors)
@@ -0,0 +1,6 @@
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;
@@ -6,8 +6,8 @@ const utils_1 = require("@/utils");
6
6
  * Returns errors only if there are errors.
7
7
  * Allows simple typeguard without `isEmpty` dependency.
8
8
  */
9
- const useFormContextErrorsIfAny = () => {
9
+ const useFormErrorsIfAny = () => {
10
10
  const { errors } = (0, react_hook_form_1.useFormState)();
11
11
  return (0, utils_1.isEmptyObject)(errors) ? false : errors;
12
12
  };
13
- exports.default = useFormContextErrorsIfAny;
13
+ exports.default = useFormErrorsIfAny;
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Use {@link FieldErrors} as {@link FlatFieldErrors}.
3
+ */
4
+ declare const useFormFlatFieldErrors: () => import("./getFlatFieldErrors").FlatFieldErrors;
5
+ export default useFormFlatFieldErrors;
@@ -0,0 +1,12 @@
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,9 +1,11 @@
1
1
  export { default as FormNonFieldErrorMarker } from './errors/nonfield/FormNonFieldErrorMarker';
2
- export { FormNonFieldErrorMarkerHtmlAttribute } from './errors/nonfield/FormNonFieldErrorMarker.utils';
3
- export { default as useFormErrorOrphansToConsoleError } from './errors/orphans/useFormErrorOrphansToConsoleError';
4
- export { default as useFormOrphanErrors } from './errors/orphans/useFormOrphanErrors';
5
- export { default as useFormRootFieldErrors } from './errors/root/useFormRootFieldErrors';
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';
6
7
  export { default as useFormErrorConsoleDebug } from './errors/useFormErrorConsoleDebug';
7
8
  export { default as useFormErrorsEffect } from './errors/useFormErrorsEffect';
9
+ export { default as useFormErrorsIfAny } from './errors/useFormErrorsIfAny';
8
10
  export { default as useFormErrorsOnChange } from './errors/useFormErrorsOnChange';
9
11
  export { default as useFormRequestSubmit } from './errors/useFormRequestSubmit';
package/dist/cjs/main.js CHANGED
@@ -3,21 +3,25 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.useFormRequestSubmit = exports.useFormErrorsOnChange = exports.useFormErrorsEffect = exports.useFormErrorConsoleDebug = exports.useFormRootFieldErrors = exports.useFormOrphanErrors = exports.useFormErrorOrphansToConsoleError = exports.FormNonFieldErrorMarkerHtmlAttribute = exports.FormNonFieldErrorMarker = void 0;
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
7
  var FormNonFieldErrorMarker_1 = require("./errors/nonfield/FormNonFieldErrorMarker");
8
8
  Object.defineProperty(exports, "FormNonFieldErrorMarker", { enumerable: true, get: function () { return __importDefault(FormNonFieldErrorMarker_1).default; } });
9
9
  var FormNonFieldErrorMarker_utils_1 = require("./errors/nonfield/FormNonFieldErrorMarker.utils");
10
- Object.defineProperty(exports, "FormNonFieldErrorMarkerHtmlAttribute", { enumerable: true, get: function () { return FormNonFieldErrorMarker_utils_1.FormNonFieldErrorMarkerHtmlAttribute; } });
11
- var useFormErrorOrphansToConsoleError_1 = require("./errors/orphans/useFormErrorOrphansToConsoleError");
12
- Object.defineProperty(exports, "useFormErrorOrphansToConsoleError", { enumerable: true, get: function () { return __importDefault(useFormErrorOrphansToConsoleError_1).default; } });
13
- var useFormOrphanErrors_1 = require("./errors/orphans/useFormOrphanErrors");
14
- Object.defineProperty(exports, "useFormOrphanErrors", { enumerable: true, get: function () { return __importDefault(useFormOrphanErrors_1).default; } });
15
- var useFormRootFieldErrors_1 = require("./errors/root/useFormRootFieldErrors");
16
- Object.defineProperty(exports, "useFormRootFieldErrors", { enumerable: true, get: function () { return __importDefault(useFormRootFieldErrors_1).default; } });
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; } });
17
19
  var useFormErrorConsoleDebug_1 = require("./errors/useFormErrorConsoleDebug");
18
20
  Object.defineProperty(exports, "useFormErrorConsoleDebug", { enumerable: true, get: function () { return __importDefault(useFormErrorConsoleDebug_1).default; } });
19
21
  var useFormErrorsEffect_1 = require("./errors/useFormErrorsEffect");
20
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; } });
21
25
  var useFormErrorsOnChange_1 = require("./errors/useFormErrorsOnChange");
22
26
  Object.defineProperty(exports, "useFormErrorsOnChange", { enumerable: true, get: function () { return __importDefault(useFormErrorsOnChange_1).default; } });
23
27
  var useFormRequestSubmit_1 = require("./errors/useFormRequestSubmit");
@@ -1,21 +1,21 @@
1
- import { get as f } from "react-hook-form";
1
+ import { get as l } from "react-hook-form";
2
2
  import d from "./flattenFieldErrors.mjs";
3
- const i = (e) => {
4
- const c = d(e), s = Object.keys(c);
3
+ const f = (e) => {
4
+ const s = d(e), c = Object.keys(s);
5
5
  return Object.fromEntries(
6
- s.reduce(
6
+ c.reduce(
7
7
  (t, o) => {
8
- const r = o.replace(l, "");
8
+ const r = o.replace(a, "");
9
9
  if (r === o)
10
10
  return t;
11
- const n = f(e, r, void 0);
11
+ const n = l(e, r, void 0);
12
12
  return n && t.push([r, n]), t;
13
13
  },
14
14
  []
15
15
  // entries
16
16
  )
17
17
  );
18
- }, l = /\.type$/;
18
+ }, u = f, a = /\.type$/;
19
19
  export {
20
- i as default
20
+ u as default
21
21
  };
@@ -1,5 +1,5 @@
1
1
  import { jsx as t } from "react/jsx-runtime";
2
- import { FormNonFieldErrorMarkerHtmlAttribute as e } from "./FormNonFieldErrorMarker.utils.mjs";
2
+ import e from "./FormNonFieldErrorMarker.utils.mjs";
3
3
  const a = ({ path: r }) => {
4
4
  const o = {
5
5
  [e]: r
@@ -1,6 +1,6 @@
1
- const o = "data-paragrav-rhf-utils-nonfield-error-marker-path", t = (r) => `[role="alert"][${o}="${r}"]`, a = (r, e) => e.querySelector(t(r));
1
+ const e = "data-paragrav-rhf-utils-nonfield-error-marker-path", a = e, t = (r) => `[role="alert"][${e}="${r}"]`, l = (r, o) => o.querySelector(t(r));
2
2
  export {
3
- o as FormNonFieldErrorMarkerHtmlAttribute,
3
+ a as default,
4
4
  t as getFormNonFieldErrorMarkerQuerySelector,
5
- a as hasNonFieldErrorMarkerInDOM
5
+ l as hasNonFieldErrorMarkerInDOM
6
6
  };
@@ -0,0 +1,10 @@
1
+ import { isEmptyObject as e } from "../../utils.mjs";
2
+ import t from "../useFormFlatFieldErrors.mjs";
3
+ import n from "./useOrphanFormErrors.mjs";
4
+ const m = (o) => {
5
+ const r = n(o), s = t();
6
+ return [r, s].some(e) ? !1 : Object.keys(r).length === Object.keys(s).length;
7
+ }, O = m;
8
+ export {
9
+ O as default
10
+ };
@@ -0,0 +1,14 @@
1
+ import "react";
2
+ import { isEmptyObject as t } from "../../utils.mjs";
3
+ import e from "../useFormErrorsOnChange.mjs";
4
+ import { getOrphanFlatFieldErrors as n } from "./utils.mjs";
5
+ const m = (r) => e((o) => {
6
+ if (t(o))
7
+ return {};
8
+ if (!r.current)
9
+ throw new Error();
10
+ return n(o, r.current);
11
+ }), a = m;
12
+ export {
13
+ a as default
14
+ };
@@ -1,10 +1,10 @@
1
1
  import t from "react";
2
2
  import { useFormContext as n, useFormState as a } from "react-hook-form";
3
- import m from "./useFormOrphanErrors.mjs";
3
+ import m from "./useOrphanFormErrors.mjs";
4
4
  const c = (e) => {
5
5
  const { getValues: o } = n(), { errors: s } = a(), r = m(e);
6
6
  t.useEffect(() => {
7
- Object.keys(r).length && console.error("useFormErrorOrphansToConsoleError", {
7
+ Object.keys(r).length && console.error("useOrphanFormErrorsToConsoleError", {
8
8
  location: window.location,
9
9
  values: o(),
10
10
  orphans: r
@@ -16,5 +16,5 @@ const d = (o, t) => {
16
16
  );
17
17
  };
18
18
  export {
19
- d as getRootFlatFieldErrors
19
+ d as getOrphanFlatFieldErrors
20
20
  };
@@ -1,8 +1,8 @@
1
- import e from "./useFormContextErrorsIfAny.mjs";
1
+ import e from "./useFormErrorsIfAny.mjs";
2
2
  const s = (o) => {
3
3
  const r = e();
4
4
  o && r && console.debug("useFormErrorConsoleDebug", r);
5
- }, u = s;
5
+ }, n = s;
6
6
  export {
7
- u as default
7
+ n as default
8
8
  };
@@ -0,0 +1,9 @@
1
+ import { useFormState as o } from "react-hook-form";
2
+ import { isEmptyObject as s } from "../utils.mjs";
3
+ const t = () => {
4
+ const { errors: r } = o();
5
+ return s(r) ? !1 : r;
6
+ }, f = t;
7
+ export {
8
+ f as default
9
+ };
@@ -0,0 +1,6 @@
1
+ import r from "./getFlatFieldErrors.mjs";
2
+ import o from "./useFormErrorsOnChange.mjs";
3
+ const s = () => o(r);
4
+ export {
5
+ s as default
6
+ };
package/dist/esm/main.mjs CHANGED
@@ -1,20 +1,24 @@
1
1
  import { default as e } from "./errors/nonfield/FormNonFieldErrorMarker.mjs";
2
- import { FormNonFieldErrorMarkerHtmlAttribute as s } from "./errors/nonfield/FormNonFieldErrorMarker.utils.mjs";
3
- import { default as m } from "./errors/orphans/useFormErrorOrphansToConsoleError.mjs";
4
- import { default as u } from "./errors/orphans/useFormOrphanErrors.mjs";
5
- import { default as F } from "./errors/root/useFormRootFieldErrors.mjs";
6
- import { default as p } from "./errors/useFormErrorConsoleDebug.mjs";
7
- import { default as x } from "./errors/useFormErrorsEffect.mjs";
8
- import { default as i } from "./errors/useFormErrorsOnChange.mjs";
9
- import { default as h } from "./errors/useFormRequestSubmit.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";
10
12
  export {
11
13
  e as FormNonFieldErrorMarker,
12
- s as FormNonFieldErrorMarkerHtmlAttribute,
13
- p as useFormErrorConsoleDebug,
14
- m as useFormErrorOrphansToConsoleError,
15
- x as useFormErrorsEffect,
16
- i as useFormErrorsOnChange,
17
- u as useFormOrphanErrors,
18
- h as useFormRequestSubmit,
19
- F as useFormRootFieldErrors
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
20
24
  };
@@ -1,6 +1,7 @@
1
1
  /**
2
2
  * HTML data attribute for {@link FormNonFieldErrorMarker}.
3
3
  */
4
- export declare const FormNonFieldErrorMarkerHtmlAttribute = "data-paragrav-rhf-utils-nonfield-error-marker-path";
4
+ declare const FormNonFieldErrorMarkerHtmlAttribute = "data-paragrav-rhf-utils-nonfield-error-marker-path";
5
+ export default FormNonFieldErrorMarkerHtmlAttribute;
5
6
  export declare const getFormNonFieldErrorMarkerQuerySelector: (path: string) => string;
6
7
  export declare const hasNonFieldErrorMarkerInDOM: (path: string, parentElement: Pick<HTMLElement, 'querySelector'>) => Element | null;
@@ -13,6 +13,6 @@ import { FieldError } from 'react-hook-form';
13
13
  * - Orphan (undisplayed), which are typically caused by one of the following cases:
14
14
  * - The input is missing.
15
15
  * - The schema is incorrect.
16
- * - The non-field error is not displayed to user with `FormErrorNonFieldMarker`.
16
+ * - The error is not displayed to user with `FormErrorNonFieldMarker`.
17
17
  */
18
18
  export declare const isNonFieldError: (error: FieldError) => boolean;
@@ -0,0 +1,2 @@
1
+ declare const useFormErrorsHasOnlyOrphans: (formRef: React.RefObject<HTMLFormElement>) => boolean;
2
+ export default useFormErrorsHasOnlyOrphans;
@@ -1,4 +1,4 @@
1
1
  import { default as React } from 'react';
2
2
 
3
- declare const useFormOrphanErrors: (formRef: React.RefObject<HTMLFormElement>) => import('../getFlatFieldErrors').FlatFieldErrors;
4
- export default useFormOrphanErrors;
3
+ declare const useOrphanFormErrors: (formRef: React.RefObject<HTMLFormElement>) => import('../getFlatFieldErrors').FlatFieldErrors;
4
+ export default useOrphanFormErrors;
@@ -0,0 +1,8 @@
1
+ import { default as React } from 'react';
2
+
3
+ /**
4
+ * Outputs orphan errors to `console.error` all errors with `ref: undefined` that do not begin with `root(.*)`.
5
+ * Sentry (or equivalent) should capture.
6
+ */
7
+ declare const useOrphanFormErrorsToConsoleError: (formRef: React.RefObject<HTMLFormElement>) => void;
8
+ export default useOrphanFormErrorsToConsoleError;
@@ -0,0 +1,4 @@
1
+ import { FlatFieldErrors } from '../getFlatFieldErrors';
2
+ import { FieldErrors } from 'react-hook-form';
3
+
4
+ export declare const getOrphanFlatFieldErrors: (errors: FieldErrors, parentElement: Pick<HTMLElement, 'querySelector'>) => FlatFieldErrors;
@@ -2,5 +2,5 @@
2
2
  * Root field errors from form.
3
3
  * These are typically displayed at the bottom of the form.
4
4
  */
5
- declare const useFormRootFieldErrors: () => import('../getFlatFieldErrors').FlatFieldErrors;
6
- export default useFormRootFieldErrors;
5
+ declare const useRootFormFieldErrors: () => import('../getFlatFieldErrors').FlatFieldErrors;
6
+ export default useRootFormFieldErrors;
@@ -0,0 +1,6 @@
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;
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Use {@link FieldErrors} as {@link FlatFieldErrors}.
3
+ */
4
+ declare const useFormFlatFieldErrors: () => import('./getFlatFieldErrors').FlatFieldErrors;
5
+ export default useFormFlatFieldErrors;
@@ -1,9 +1,11 @@
1
1
  export { default as FormNonFieldErrorMarker } from './errors/nonfield/FormNonFieldErrorMarker';
2
- export { FormNonFieldErrorMarkerHtmlAttribute } from './errors/nonfield/FormNonFieldErrorMarker.utils';
3
- export { default as useFormErrorOrphansToConsoleError } from './errors/orphans/useFormErrorOrphansToConsoleError';
4
- export { default as useFormOrphanErrors } from './errors/orphans/useFormOrphanErrors';
5
- export { default as useFormRootFieldErrors } from './errors/root/useFormRootFieldErrors';
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';
6
7
  export { default as useFormErrorConsoleDebug } from './errors/useFormErrorConsoleDebug';
7
8
  export { default as useFormErrorsEffect } from './errors/useFormErrorsEffect';
9
+ export { default as useFormErrorsIfAny } from './errors/useFormErrorsIfAny';
8
10
  export { default as useFormErrorsOnChange } from './errors/useFormErrorsOnChange';
9
11
  export { default as useFormRequestSubmit } from './errors/useFormRequestSubmit';
package/package.json CHANGED
@@ -2,9 +2,10 @@
2
2
  "name": "@paragrav/rhf-utils",
3
3
  "author": "paragrav.dev",
4
4
  "license": "MIT",
5
- "version": "0.0.19",
5
+ "version": "0.0.20",
6
6
  "description": "Integration utilities for react-hook-form.",
7
7
  "type": "module",
8
+ "sideEffects": false,
8
9
  "files": [
9
10
  "dist"
10
11
  ],
@@ -12,22 +13,66 @@
12
13
  "module": "./dist/esm/main.mjs",
13
14
  "exports": {
14
15
  ".": {
15
- "require": {
16
- "types": "./dist/types/main.d.ts",
17
- "default": "./dist/cjs/main.js"
18
- },
19
- "import": {
20
- "types": "./dist/types/main.d.ts",
21
- "default": "./dist/esm/main.mjs"
22
- }
16
+ "import": "./dist/esm/main.mjs",
17
+ "require": "./dist/cjs/main.js",
18
+ "types": "./dist/types/main.d.ts"
23
19
  },
24
- "./useFormErrorConsoleDebug": {
25
- "types": "./dist/types/errors/useFormErrorConsoleDebug.d.ts",
20
+ "./errors/useFormErrorConsoleDebug": {
21
+ "import": "./dist/esm/errors/useFormErrorConsoleDebug.mjs",
26
22
  "require": "./dist/cjs/errors/useFormErrorConsoleDebug.cjs",
27
- "import": "./dist/esm/errors/useFormErrorConsoleDebug.mjs"
23
+ "types": "./dist/types/errors/useFormErrorConsoleDebug.d.ts"
24
+ },
25
+ "./errors/useFormErrorsEffect": {
26
+ "import": "./dist/esm/errors/useFormErrorsEffect.mjs",
27
+ "require": "./dist/cjs/errors/useFormErrorsEffect.cjs",
28
+ "types": "./dist/types/errors/useFormErrorsEffect.d.ts"
29
+ },
30
+ "./errors/useFormErrorsIfAny": {
31
+ "import": "./dist/esm/errors/useFormErrorsIfAny.mjs",
32
+ "require": "./dist/cjs/errors/useFormErrorsIfAny.cjs",
33
+ "types": "./dist/types/errors/useFormErrorsIfAny.d.ts"
34
+ },
35
+ "./errors/useFormErrorsOnChange": {
36
+ "import": "./dist/esm/errors/useFormErrorsOnChange.mjs",
37
+ "require": "./dist/cjs/errors/useFormErrorsOnChange.cjs",
38
+ "types": "./dist/types/errors/useFormErrorsOnChange.d.ts"
39
+ },
40
+ "./errors/useFormRequestSubmit": {
41
+ "import": "./dist/esm/errors/useFormRequestSubmit.mjs",
42
+ "require": "./dist/cjs/errors/useFormRequestSubmit.cjs",
43
+ "types": "./dist/types/errors/useFormRequestSubmit.d.ts"
44
+ },
45
+ "./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"
49
+ },
50
+ "./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"
54
+ },
55
+ "./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"
59
+ },
60
+ "./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"
64
+ },
65
+ "./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"
69
+ },
70
+ "./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"
28
74
  }
29
75
  },
30
- "sideEffects": false,
31
76
  "scripts": {
32
77
  "build": "npm run validate && npm run build:cjs && npm run build:esm",
33
78
  "build:cjs": "tsc -p ./tsconfig.cjs.json",
@@ -1,9 +0,0 @@
1
- import React from 'react';
2
- /**
3
- * Orphans are field errors that do not have a ref.
4
- * (Most commonly `root(.*)`, but these are filtered out. They are handled by `useFormRootFieldErrors`.)
5
- * Outputs to `console.error` all errors with `ref: undefined` that do not begin with `root(.*)`.
6
- * Sentry (or equivalent) should capture.
7
- */
8
- declare const useFormErrorOrphansToConsoleError: (formRef: React.RefObject<HTMLFormElement>) => void;
9
- export default useFormErrorOrphansToConsoleError;
@@ -1,2 +0,0 @@
1
- declare const useFormErrorsHasOnlyOrphan: (formRef: React.RefObject<HTMLFormElement>) => boolean;
2
- export default useFormErrorsHasOnlyOrphan;
@@ -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 utils_1 = require("@/utils");
7
- const useFormContextErrorsIfAny_1 = __importDefault(require("../useFormContextErrorsIfAny"));
8
- const useFormOrphanErrors_1 = __importDefault(require("./useFormOrphanErrors"));
9
- const useFormErrorsHasOnlyOrphan = (formRef) => {
10
- const orphans = (0, useFormOrphanErrors_1.default)(formRef);
11
- const errors = (0, useFormContextErrorsIfAny_1.default)();
12
- // no errors
13
- if (!errors)
14
- return false;
15
- // no orphans
16
- if ((0, utils_1.isEmptyObject)(orphans))
17
- return false;
18
- // equal length
19
- return Object.keys(orphans).length === Object.keys(errors).length;
20
- };
21
- exports.default = useFormErrorsHasOnlyOrphan;
@@ -1,3 +0,0 @@
1
- import type { FieldErrors } from 'react-hook-form';
2
- import type { FlatFieldErrors } from '../getFlatFieldErrors';
3
- export declare const getRootFlatFieldErrors: (errors: FieldErrors, parentElement: Pick<HTMLElement, 'querySelector'>) => FlatFieldErrors;
@@ -1,6 +0,0 @@
1
- /**
2
- * Returns errors only if there are errors.
3
- * Allows simple typeguard without `isEmpty` dependency.
4
- */
5
- declare const useFormContextErrorsIfAny: () => false | import("react-hook-form").FieldErrors<import("react-hook-form").FieldValues>;
6
- export default useFormContextErrorsIfAny;
@@ -1,14 +0,0 @@
1
- import "react";
2
- import { isEmptyObject as t } from "../../utils.mjs";
3
- import e from "../useFormErrorsOnChange.mjs";
4
- import { getRootFlatFieldErrors as n } from "./utils.mjs";
5
- const s = (o) => e((r) => {
6
- if (t(r))
7
- return {};
8
- if (!o.current)
9
- throw console.error(r), new Error("This should not happen.");
10
- return n(r, o.current);
11
- }), a = s;
12
- export {
13
- a as default
14
- };
@@ -1,9 +0,0 @@
1
- import { useFormState as t } from "react-hook-form";
2
- import { isEmptyObject as o } from "../utils.mjs";
3
- const m = () => {
4
- const { errors: r } = t();
5
- return o(r) ? !1 : r;
6
- };
7
- export {
8
- m as default
9
- };
@@ -1,10 +0,0 @@
1
- import { default as React } from 'react';
2
-
3
- /**
4
- * Orphans are field errors that do not have a ref.
5
- * (Most commonly `root(.*)`, but these are filtered out. They are handled by `useFormRootFieldErrors`.)
6
- * Outputs to `console.error` all errors with `ref: undefined` that do not begin with `root(.*)`.
7
- * Sentry (or equivalent) should capture.
8
- */
9
- declare const useFormErrorOrphansToConsoleError: (formRef: React.RefObject<HTMLFormElement>) => void;
10
- export default useFormErrorOrphansToConsoleError;
@@ -1,2 +0,0 @@
1
- declare const useFormErrorsHasOnlyOrphan: (formRef: React.RefObject<HTMLFormElement>) => boolean;
2
- export default useFormErrorsHasOnlyOrphan;
@@ -1,4 +0,0 @@
1
- import { FlatFieldErrors } from '../getFlatFieldErrors';
2
- import { FieldErrors } from 'react-hook-form';
3
-
4
- export declare const getRootFlatFieldErrors: (errors: FieldErrors, parentElement: Pick<HTMLElement, 'querySelector'>) => FlatFieldErrors;
@@ -1,6 +0,0 @@
1
- /**
2
- * Returns errors only if there are errors.
3
- * Allows simple typeguard without `isEmpty` dependency.
4
- */
5
- declare const useFormContextErrorsIfAny: () => false | import('react-hook-form').FieldErrors<import("react-hook-form").FieldValues>;
6
- export default useFormContextErrorsIfAny;