@paragrav/rhf-utils 0.0.135 → 0.0.137
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/README.md +90 -65
- package/dist/esm/client/config/useRhfUtilsClientConfigContext.mjs +0 -1
- package/dist/esm/client/index.mjs +0 -1
- package/dist/esm/client/utils.mjs +0 -1
- package/dist/esm/client/zod/context/RhfUtilsClientForZodContextProvider.mjs +3 -2
- package/dist/esm/client/zod/context/RhfUtilsZodForm.mjs +0 -1
- package/dist/esm/client/zod/context/useRhfUtilsClientForZodContext.mjs +0 -1
- package/dist/esm/client/zod/context/useRhfUtilsZodForm.mjs +0 -1
- package/dist/esm/client/zod/createRhfUtilsClientForZod.mjs +0 -1
- package/dist/esm/devtool/LazyDevTool.mjs +0 -1
- package/dist/esm/errors/flat/FlatFieldErrorsList.mjs +0 -1
- package/dist/esm/errors/flat/context/FlatFieldErrorsContextProvider.mjs +0 -1
- package/dist/esm/errors/flat/context/useFlatFieldErrorsContext.mjs +0 -1
- package/dist/esm/errors/flat/context/useFlatFieldErrorsContextHasOnlyOrphans.mjs +0 -1
- package/dist/esm/errors/flat/context/useFlatFieldErrorsContextOutput.mjs +0 -1
- package/dist/esm/errors/flat/filterFlatFieldErrors.mjs +0 -1
- package/dist/esm/errors/flat/flattenFieldErrors.mjs +0 -1
- package/dist/esm/errors/flat/getFlatFieldErrors.mjs +10 -11
- package/dist/esm/errors/getRefdFromFlatFieldErrors.mjs +0 -1
- package/dist/esm/errors/isFieldErrorRefd.mjs +0 -1
- package/dist/esm/errors/isFlatFieldErrorEntryRefd.mjs +0 -1
- package/dist/esm/errors/message/FormErrorMessage.mjs +0 -1
- package/dist/esm/errors/message/RhfUtilsFieldErrorMessage.mjs +14 -0
- package/dist/esm/errors/nonfield/FormNonFieldErrorMarker.mjs +0 -1
- package/dist/esm/errors/nonfield/FormNonFieldErrorMarker.utils.mjs +0 -1
- package/dist/esm/errors/nonfield/FormNonFieldErrorMarkerHtmlAttribute.mjs +0 -1
- package/dist/esm/errors/nonfield/isNonFieldErrorMarkerInDOM.mjs +0 -1
- package/dist/esm/errors/orphan/getIsOrphanFormErrorWithParentElement.mjs +0 -1
- package/dist/esm/errors/orphan/getOrphansFromFlatFieldErrors.mjs +0 -1
- package/dist/esm/errors/orphan/isOrphanFormError.mjs +3 -4
- package/dist/esm/errors/output/consoleErrors.mjs +0 -1
- package/dist/esm/errors/root/RootErrorsListFromFlatFieldErrorsContext.mjs +0 -1
- package/dist/esm/errors/root/consts.mjs +0 -1
- package/dist/esm/errors/root/getRootsFromFlatFieldErrors.mjs +0 -1
- package/dist/esm/errors/root/isFlatFieldErrorEntryPathRoot.mjs +0 -1
- package/dist/esm/errors/root/isFormErrorPathRoot.mjs +0 -1
- package/dist/esm/exports.mjs +32 -37
- package/dist/esm/form/Form.mjs +14 -15
- package/dist/esm/form/FormWithProviders.mjs +0 -1
- package/dist/esm/form/RhfUtilsFormProviders.mjs +0 -1
- package/dist/esm/form/_Controller.mjs +0 -1
- package/dist/esm/form/context/group/FormGroupContextProvider.mjs +0 -1
- package/dist/esm/form/context/group/index.mjs +0 -1
- package/dist/esm/form/context/group/useFormGroupChildIsMountedTracker.mjs +0 -1
- package/dist/esm/form/context/group/useFormGroupChildIsSubmittingTracker.mjs +0 -1
- package/dist/esm/form/context/group/useFormGroupChildTracker.mjs +0 -1
- package/dist/esm/form/context/group/useFormGroupIsAnyBusy.mjs +0 -1
- package/dist/esm/form/context/group/useFormGroupIsChildBusy.mjs +0 -1
- package/dist/esm/form/context/group/useFormGroupIsParentBusy.mjs +0 -1
- package/dist/esm/form/context/group/useFormGroupParentTracker.mjs +0 -1
- package/dist/esm/form/context/group/useFormOrParentIsBusy.mjs +0 -1
- package/dist/esm/form/context/utils/RhfUtilsContextProvider.mjs +15 -14
- package/dist/esm/form/context/utils/useRhfUtilsContext.mjs +0 -1
- package/dist/esm/form/context/utils/useRhfUtilsContextRequestSubmit.mjs +0 -1
- package/dist/esm/form/useFormIsBusy.mjs +0 -1
- package/dist/esm/form/useRhfUtilsForm.mjs +0 -1
- package/dist/esm/form/utils/getSubmitterButtonData.mjs +0 -1
- package/dist/esm/form/utils/useFormRequestSubmit.mjs +9 -6
- package/dist/esm/submit/error/FormSubmitError.mjs +0 -1
- package/dist/esm/submit/error/setCtxErrorsByFormSubmitFieldErrors.mjs +12 -0
- package/dist/esm/submit/useFormOnSubmitted.mjs +0 -1
- package/dist/esm/submit/useResetFormOnSubmitted.mjs +0 -1
- package/dist/esm/submit/useSubmitFormOnChange.mjs +18 -12
- package/dist/esm/utils/PassthroughChildren.mjs +0 -1
- package/dist/esm/utils/createContext.mjs +0 -1
- package/dist/esm/utils/isEmptyObject.mjs +0 -1
- package/dist/esm/utils/useDebouncedOnChangeValue.mjs +26 -0
- package/dist/esm/utils/useRefIfValueWasTrue.mjs +0 -1
- package/dist/types/client/config/RhfUtilsClientConfig.d.ts +5 -5
- package/dist/types/client/zod/context/RhfUtilsClientForZodContextProvider.d.ts +1 -1
- package/dist/types/errors/flat/flattenFieldErrors.d.ts +3 -2
- package/dist/types/errors/message/{FormErrorMessageByPath.d.ts → RhfUtilsFieldErrorMessage.d.ts} +2 -2
- package/dist/types/errors/trpc/getOnSubmitTrpcClientErrorHandler.d.ts +2 -2
- package/dist/types/errors/trpc/trpcClientErrorToFormSubmitFieldErrorsSchemaTransformer.d.ts +28 -0
- package/dist/types/exports.d.ts +1 -3
- package/dist/types/form/RhfUtilsFormOptions.d.ts +7 -3
- package/dist/types/form/UseRhfUtilsFormProps.d.ts +1 -1
- package/dist/types/form/utils/useFormRequestSubmit.d.ts +5 -0
- package/dist/types/submit/error/FormSubmitError.d.ts +3 -3
- package/dist/types/submit/error/{FormSubmitErrors.d.ts → FormSubmitFieldErrors.d.ts} +1 -1
- package/dist/types/submit/error/setCtxErrorsByFormSubmitFieldErrors.d.ts +10 -0
- package/dist/types/submit/useFormOnSubmitSuccessfulAndReset.d.ts +1 -1
- package/dist/types/submit/useFormOnSubmitted.d.ts +1 -1
- package/dist/types/submit/useSubmitFormOnChange.d.ts +3 -1
- package/dist/types/utils/timeoutAsync.d.ts +6 -0
- package/dist/types/utils/useDebouncedOnChangeValue.d.ts +14 -0
- package/package.json +1 -1
- package/dist/esm/client/config/useRhfUtilsClientConfigContext.mjs.map +0 -1
- package/dist/esm/client/index.mjs.map +0 -1
- package/dist/esm/client/utils.mjs.map +0 -1
- package/dist/esm/client/zod/context/RhfUtilsClientForZodContextProvider.mjs.map +0 -1
- package/dist/esm/client/zod/context/RhfUtilsZodForm.mjs.map +0 -1
- package/dist/esm/client/zod/context/useRhfUtilsClientForZodContext.mjs.map +0 -1
- package/dist/esm/client/zod/context/useRhfUtilsZodForm.mjs.map +0 -1
- package/dist/esm/client/zod/createRhfUtilsClientForZod.mjs.map +0 -1
- package/dist/esm/devtool/LazyDevTool.mjs.map +0 -1
- package/dist/esm/errors/flat/FlatFieldErrorsList.mjs.map +0 -1
- package/dist/esm/errors/flat/context/FlatFieldErrorsContextProvider.mjs.map +0 -1
- package/dist/esm/errors/flat/context/useFlatFieldErrorsContext.mjs.map +0 -1
- package/dist/esm/errors/flat/context/useFlatFieldErrorsContextHasOnlyOrphans.mjs.map +0 -1
- package/dist/esm/errors/flat/context/useFlatFieldErrorsContextOutput.mjs.map +0 -1
- package/dist/esm/errors/flat/filterFlatFieldErrors.mjs.map +0 -1
- package/dist/esm/errors/flat/flattenFieldErrors.mjs.map +0 -1
- package/dist/esm/errors/flat/getFlatFieldErrors.mjs.map +0 -1
- package/dist/esm/errors/getRefdFromFlatFieldErrors.mjs.map +0 -1
- package/dist/esm/errors/isFieldErrorRefd.mjs.map +0 -1
- package/dist/esm/errors/isFlatFieldErrorEntryRefd.mjs.map +0 -1
- package/dist/esm/errors/message/FormErrorMessage.mjs.map +0 -1
- package/dist/esm/errors/message/FormErrorMessageByPath.mjs +0 -15
- package/dist/esm/errors/message/FormErrorMessageByPath.mjs.map +0 -1
- package/dist/esm/errors/nonfield/FormNonFieldErrorMarker.mjs.map +0 -1
- package/dist/esm/errors/nonfield/FormNonFieldErrorMarker.utils.mjs.map +0 -1
- package/dist/esm/errors/nonfield/FormNonFieldErrorMarkerHtmlAttribute.mjs.map +0 -1
- package/dist/esm/errors/nonfield/isNonFieldErrorMarkerInDOM.mjs.map +0 -1
- package/dist/esm/errors/orphan/getIsOrphanFormErrorWithParentElement.mjs.map +0 -1
- package/dist/esm/errors/orphan/getOrphansFromFlatFieldErrors.mjs.map +0 -1
- package/dist/esm/errors/orphan/isOrphanFormError.mjs.map +0 -1
- package/dist/esm/errors/output/consoleErrors.mjs.map +0 -1
- package/dist/esm/errors/root/RootErrorsListFromFlatFieldErrorsContext.mjs.map +0 -1
- package/dist/esm/errors/root/consts.mjs.map +0 -1
- package/dist/esm/errors/root/getRootsFromFlatFieldErrors.mjs.map +0 -1
- package/dist/esm/errors/root/isFlatFieldErrorEntryPathRoot.mjs.map +0 -1
- package/dist/esm/errors/root/isFormErrorPathRoot.mjs.map +0 -1
- package/dist/esm/errors/trpc/getOnSubmitTrpcClientErrorHandler.mjs +0 -7
- package/dist/esm/errors/trpc/getOnSubmitTrpcClientErrorHandler.mjs.map +0 -1
- package/dist/esm/errors/trpc/trpcClientErrorMessageSchema.mjs +0 -11
- package/dist/esm/errors/trpc/trpcClientErrorMessageSchema.mjs.map +0 -1
- package/dist/esm/errors/trpc/trpcClientErrorToFormSubmitErrorsSchemaTransformer.mjs +0 -35
- package/dist/esm/errors/trpc/trpcClientErrorToFormSubmitErrorsSchemaTransformer.mjs.map +0 -1
- package/dist/esm/exports.mjs.map +0 -1
- package/dist/esm/form/Form.mjs.map +0 -1
- package/dist/esm/form/FormWithProviders.mjs.map +0 -1
- package/dist/esm/form/RhfUtilsFormProviders.mjs.map +0 -1
- package/dist/esm/form/_Controller.mjs.map +0 -1
- package/dist/esm/form/context/group/FormGroupContextProvider.mjs.map +0 -1
- package/dist/esm/form/context/group/index.mjs.map +0 -1
- package/dist/esm/form/context/group/useFormGroupChildIsMountedTracker.mjs.map +0 -1
- package/dist/esm/form/context/group/useFormGroupChildIsSubmittingTracker.mjs.map +0 -1
- package/dist/esm/form/context/group/useFormGroupChildTracker.mjs.map +0 -1
- package/dist/esm/form/context/group/useFormGroupIsAnyBusy.mjs.map +0 -1
- package/dist/esm/form/context/group/useFormGroupIsChildBusy.mjs.map +0 -1
- package/dist/esm/form/context/group/useFormGroupIsParentBusy.mjs.map +0 -1
- package/dist/esm/form/context/group/useFormGroupParentTracker.mjs.map +0 -1
- package/dist/esm/form/context/group/useFormOrParentIsBusy.mjs.map +0 -1
- package/dist/esm/form/context/utils/RhfUtilsContextProvider.mjs.map +0 -1
- package/dist/esm/form/context/utils/useRhfUtilsContext.mjs.map +0 -1
- package/dist/esm/form/context/utils/useRhfUtilsContextRequestSubmit.mjs.map +0 -1
- package/dist/esm/form/useFormIsBusy.mjs.map +0 -1
- package/dist/esm/form/useRhfUtilsForm.mjs.map +0 -1
- package/dist/esm/form/utils/getSubmitterButtonData.mjs.map +0 -1
- package/dist/esm/form/utils/useFormRequestSubmit.mjs.map +0 -1
- package/dist/esm/submit/error/FormSubmitError.mjs.map +0 -1
- package/dist/esm/submit/error/setCtxErrorsByFormSubmitErrors.mjs +0 -13
- package/dist/esm/submit/error/setCtxErrorsByFormSubmitErrors.mjs.map +0 -1
- package/dist/esm/submit/useFormOnSubmitted.mjs.map +0 -1
- package/dist/esm/submit/useResetFormOnSubmitted.mjs.map +0 -1
- package/dist/esm/submit/useSubmitFormOnChange.mjs.map +0 -1
- package/dist/esm/utils/PassthroughChildren.mjs.map +0 -1
- package/dist/esm/utils/createContext.mjs.map +0 -1
- package/dist/esm/utils/isEmptyObject.mjs.map +0 -1
- package/dist/esm/utils/useRefIfValueWasTrue.mjs.map +0 -1
- package/dist/types/errors/trpc/trpcClientErrorToFormSubmitErrorsSchemaTransformer.d.ts +0 -28
- package/dist/types/submit/error/setCtxErrorsByFormSubmitErrors.d.ts +0 -10
|
@@ -1,5 +1,10 @@
|
|
|
1
|
+
import { default as React } from 'react';
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* Get callback to trigger submit manually on form.
|
|
5
|
+
*
|
|
6
|
+
* Note: `submitter` is optional, but is required to be a submit button.
|
|
7
|
+
*
|
|
3
8
|
* @link https://developer.mozilla.org/docs/Web/API/HTMLFormElement/requestSubmit
|
|
4
9
|
*/
|
|
5
10
|
declare const useFormRequestSubmit: (ref: React.RefObject<HTMLFormElement>) => HTMLFormElement["requestSubmit"];
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { SafeFieldValues } from '../../form/SafeFieldValues';
|
|
2
|
-
import {
|
|
2
|
+
import { FormSubmitFieldErrors } from './FormSubmitFieldErrors';
|
|
3
3
|
|
|
4
4
|
export declare class FormSubmitError<TFieldValues extends SafeFieldValues = SafeFieldValues> extends Error {
|
|
5
|
-
errors:
|
|
6
|
-
constructor(errors:
|
|
5
|
+
errors: FormSubmitFieldErrors<TFieldValues>;
|
|
6
|
+
constructor(errors: FormSubmitFieldErrors<TFieldValues>, message?: string);
|
|
7
7
|
}
|
|
@@ -9,7 +9,7 @@ import { SafeFieldValues } from '../../form/SafeFieldValues';
|
|
|
9
9
|
* - `root` is reserved for special use cases.
|
|
10
10
|
* - simplified `ErrorOption` value.
|
|
11
11
|
*/
|
|
12
|
-
export type
|
|
12
|
+
export type FormSubmitFieldErrors<TFieldValues extends SafeFieldValues = SafeFieldValues> = Record<FieldPath<TFieldValues> | `root.${string}`, {
|
|
13
13
|
type?: string;
|
|
14
14
|
message: string;
|
|
15
15
|
}>;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { UseFormReturn } from 'react-hook-form';
|
|
2
|
+
import { SafeFieldValues } from '../../form/SafeFieldValues';
|
|
3
|
+
import { FormSubmitFieldErrors } from './FormSubmitFieldErrors';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Handle thrown {@link FormSubmitError}.
|
|
7
|
+
* Add key/values as name/message to RHF context errors.
|
|
8
|
+
*/
|
|
9
|
+
declare const setCtxErrorsByFormSubmitFieldErrors: <TFieldValues extends SafeFieldValues, TTransformedValues extends SafeFieldValues>(ctx: UseFormReturn<TFieldValues, unknown, TTransformedValues>, errors: FormSubmitFieldErrors) => void;
|
|
10
|
+
export default setCtxErrorsByFormSubmitFieldErrors;
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { default as React } from 'react';
|
|
2
2
|
|
|
3
3
|
declare const useSubmitFormOnChange: (formRef: React.RefObject<HTMLFormElement>, options?: {
|
|
4
|
-
/** Disable
|
|
4
|
+
/** Disable behavior. (Default behavior is enabled for sake of simplicity of general usage.) */
|
|
5
5
|
disabled?: boolean;
|
|
6
|
+
/** Milliseconds to debounce form submission. (Default is none.) */
|
|
7
|
+
debounce?: number;
|
|
6
8
|
}) => void;
|
|
7
9
|
export default useSubmitFormOnChange;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* React hook to debounce onChange event callback.
|
|
3
|
+
*
|
|
4
|
+
* Returns debounced state setter (uses ref internally).
|
|
5
|
+
*
|
|
6
|
+
* When debounce delay has elapsed after setting value,
|
|
7
|
+
* onChange callback is called with latest value.
|
|
8
|
+
*
|
|
9
|
+
* @returns `[setValueDebounced]`
|
|
10
|
+
*/
|
|
11
|
+
export declare const useDebouncedOnChangeValue: <TValue>({ onChange, delay, }: {
|
|
12
|
+
onChange: (value: TValue) => void;
|
|
13
|
+
delay: number;
|
|
14
|
+
}) => readonly [(value: TValue) => void];
|
package/package.json
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useRhfUtilsClientConfigContext.mjs","sources":["../../../../src/client/config/useRhfUtilsClientConfigContext.tsx"],"sourcesContent":["import createContext from '@/utils/createContext';\n\nimport type { RhfUtilsClientConfig } from './RhfUtilsClientConfig';\n\nconst {\n Provider: _RhfUtilsClientConfigContextProvider,\n useMaybe: useRhfUtilsClientConfigMaybeContext,\n} = createContext<RhfUtilsClientConfig>();\n\n//\n\nexport default useRhfUtilsClientConfigMaybeContext;\n\n//\n\nexport { _RhfUtilsClientConfigContextProvider };\n"],"names":["_RhfUtilsClientConfigContextProvider","useRhfUtilsClientConfigMaybeContext","createContext"],"mappings":";AAIM,MAAA;AAAA,EACJ,UAAUA;AAAA,EACV,UAAUC;AACZ,IAAIC,EAAoC;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sources":["../../../src/client/index.tsx"],"sourcesContent":["import React from 'react';\nimport type { Resolver } from 'react-hook-form';\n\nimport type { RhfUtilsClientConfig } from '@/client/config/RhfUtilsClientConfig';\n\nimport type { FormWithProvidersProps } from '@/form/FormWithProviders';\nimport FormWithProviders from '@/form/FormWithProviders';\nimport type { SafeFieldValues } from '@/form/SafeFieldValues';\nimport useRhfUtilsForm from '@/form/useRhfUtilsForm';\nimport type { UseRhfUtilsFormProps } from '@/form/UseRhfUtilsFormProps';\nimport type { UseRhfUtilsFormReturn } from '@/form/UseRhfUtilsFormReturn';\n\nimport { mergeRhfUtilsClientConfigDefaultsWithUseRhfUtilsFormProps } from './utils';\n\n/**\n * Generic object schema type.\n */\nexport type ObjectSchema<\n TInputKey extends string,\n TOutputKey extends string,\n> = {\n [key in TInputKey]: SafeFieldValues; // should have key that returns FieldValues for input\n} & {\n [key in TOutputKey]: SafeFieldValues; // should have key that returns FieldValues for output\n};\n\n//\n\nexport type CreateRhfUtilsClient<\n TObjectSchema extends ObjectSchema<\n TObjectSchemaInputKey,\n TObjectSchemaOutputKey\n >,\n TObjectSchemaInputKey extends string,\n TObjectSchemaOutputKey extends string,\n> = {\n useForm: <\n TSchema extends TObjectSchema,\n TSchemaInput extends SafeFieldValues = TSchema[TObjectSchemaInputKey],\n TSchemaOutput extends SafeFieldValues = TSchema[TObjectSchemaOutputKey],\n UseRhfUtilsFormPropsForm extends UseRhfUtilsFormProps<\n TSchemaInput,\n TSchemaOutput\n > = UseRhfUtilsFormProps<TSchemaInput, TSchemaOutput>,\n >(\n schema: TSchema,\n form: UseRhfUtilsFormPropsForm,\n ) => UseRhfUtilsFormReturn<TSchemaInput, TSchemaOutput> & {\n FormWithProviders: React.FC<React.PropsWithChildren>;\n };\n\n FormWithProviders: <\n TSchema extends TObjectSchema,\n TSchemaInput extends SafeFieldValues = TSchema[TObjectSchemaInputKey],\n TSchemaOutput extends SafeFieldValues = TSchema[TObjectSchemaOutputKey],\n >(\n props: { schema: TSchema } & FormWithProvidersProps<\n TSchemaInput,\n TSchemaOutput\n >,\n ) => JSX.Element;\n};\n\n/**\n * ...\n *\n * (We need to use generics to generate types for schema resolver.)\n */\nexport const createRhfUtilsClient =\n <\n TObjectSchema extends ObjectSchema<\n TObjectSchemaInputKey,\n TObjectSchemaOutputKey\n >,\n TObjectSchemaInputKey extends string,\n TObjectSchemaOutputKey extends string,\n >(\n resolver: (schema: TObjectSchema) => Resolver<SafeFieldValues, unknown>,\n ) =>\n (\n config: RhfUtilsClientConfig,\n ): CreateRhfUtilsClient<\n TObjectSchema,\n TObjectSchemaInputKey,\n TObjectSchemaOutputKey\n > => {\n const _getUseRhfUtilsFormPropsWithResolverAndConfig =\n _getUseRhfUtilsFormProps(resolver, config);\n\n return {\n useForm: <\n TSchema extends TObjectSchema,\n TSchemaInput extends SafeFieldValues = TSchema[TObjectSchemaInputKey],\n TSchemaOutput extends SafeFieldValues = TSchema[TObjectSchemaOutputKey],\n UseRhfUtilsFormPropsForm extends UseRhfUtilsFormProps<\n TSchemaInput,\n TSchemaOutput\n > = UseRhfUtilsFormProps<TSchemaInput, TSchemaOutput>,\n >(\n schema: TSchema,\n form: UseRhfUtilsFormPropsForm,\n ) => {\n const useFormProps = _getUseRhfUtilsFormPropsWithResolverAndConfig<\n TSchema,\n TSchemaInput,\n TSchemaOutput\n >(schema, form);\n\n return {\n ...useRhfUtilsForm(useFormProps),\n FormWithProviders: (): React.ReactNode => {\n return <FormWithProviders {...useFormProps} />;\n },\n };\n },\n FormWithProviders: _getFormWithProviders(resolver, config),\n };\n };\n\nconst _getUseRhfUtilsFormProps = <\n TObjectSchema extends ObjectSchema<\n TObjectSchemaInputKey,\n TObjectSchemaOutputKey\n >,\n TObjectSchemaInputKey extends string,\n TObjectSchemaOutputKey extends string,\n>(\n resolver: (schema: TObjectSchema) => Resolver<SafeFieldValues, unknown>,\n config: RhfUtilsClientConfig,\n) =>\n function _getUseRhfUtilsFormPropsWithResolverAndConfigBySchemaAndFormProps<\n TSchema extends TObjectSchema,\n TSchemaInput extends SafeFieldValues = TSchema[TObjectSchemaInputKey],\n TSchemaOutput extends SafeFieldValues = TSchema[TObjectSchemaOutputKey],\n >(\n schema: TSchema,\n props: UseRhfUtilsFormProps<TSchemaInput, TSchemaOutput>,\n ): UseRhfUtilsFormProps<TSchemaInput, TSchemaOutput> {\n return {\n ...props,\n\n ...mergeRhfUtilsClientConfigDefaultsWithUseRhfUtilsFormProps(\n config.defaults,\n props,\n {\n rhf: {\n resolver: resolver(schema) as Resolver<TSchemaInput, unknown>,\n },\n },\n ),\n };\n };\n\nconst _getFormWithProviders = <\n TObjectSchema extends ObjectSchema<\n TObjectSchemaInputKey,\n TObjectSchemaOutputKey\n >,\n TObjectSchemaInputKey extends string,\n TObjectSchemaOutputKey extends string,\n>(\n resolver: (schema: TObjectSchema) => Resolver<SafeFieldValues, unknown>,\n config: RhfUtilsClientConfig,\n) => {\n const _getUseRhfUtilsFormPropsWithResolverAndConfig =\n _getUseRhfUtilsFormProps<\n TObjectSchema,\n TObjectSchemaInputKey,\n TObjectSchemaOutputKey\n >(resolver, config);\n\n return function _FormWithProviders<\n TSchema extends TObjectSchema,\n TSchemaInput extends SafeFieldValues = TSchema[TObjectSchemaInputKey],\n TSchemaOutput extends SafeFieldValues = TSchema[TObjectSchemaOutputKey],\n >({\n schema,\n children,\n ...props\n }: { schema: TSchema } & FormWithProvidersProps<\n TSchemaInput,\n TSchemaOutput\n >) {\n return (\n <FormWithProviders\n {..._getUseRhfUtilsFormPropsWithResolverAndConfig(schema, props)}\n >\n {children}\n </FormWithProviders>\n );\n };\n};\n"],"names":["createRhfUtilsClient","resolver","config","_getUseRhfUtilsFormPropsWithResolverAndConfig","_getUseRhfUtilsFormProps","schema","form","useFormProps","useRhfUtilsForm","jsx","FormWithProviders","_getFormWithProviders","props","mergeRhfUtilsClientConfigDefaultsWithUseRhfUtilsFormProps","children"],"mappings":";;;;;AAoEO,MAAMA,IACX,CAQEC,MAEF,CACEC,MAKG;AACG,QAAAC,IACJC,EAAyBH,GAAUC,CAAM;AAEpC,SAAA;AAAA,IACL,SAAS,CASPG,GACAC,MACG;AACG,YAAAC,IAAeJ,EAInBE,GAAQC,CAAI;AAEP,aAAA;AAAA,QACL,GAAGE,EAAgBD,CAAY;AAAA,QAC/B,mBAAmB,MACV,gBAAAE,EAACC,GAAmB,EAAA,GAAGH,EAAc,CAAA;AAAA,MAC9C;AAAA,IAEJ;AAAA,IACA,mBAAmBI,EAAsBV,GAAUC,CAAM;AAAA,EAAA;AAE7D,GAEIE,IAA2B,CAQ/BH,GACAC,MAEA,SAKEG,GACAO,GACmD;AAC5C,SAAA;AAAA,IACL,GAAGA;AAAA,IAEH,GAAGC;AAAA,MACDX,EAAO;AAAA,MACPU;AAAA,MACA;AAAA,QACE,KAAK;AAAA,UACH,UAAUX,EAASI,CAAM;AAAA,QAC3B;AAAA,MACF;AAAA,IACF;AAAA,EAAA;AAEJ,GAEIM,IAAwB,CAQ5BV,GACAC,MACG;AACG,QAAAC,IACJC,EAIEH,GAAUC,CAAM;AAEpB,SAAO,SAIL;AAAA,IACA,QAAAG;AAAA,IACA,UAAAS;AAAA,IACA,GAAGF;AAAA,EAAA,GAIF;AAEC,WAAA,gBAAAH;AAAA,MAACC;AAAA,MAAA;AAAA,QACE,GAAGP,EAA8CE,GAAQO,CAAK;AAAA,QAE9D,UAAAE;AAAA,MAAA;AAAA,IAAA;AAAA,EACH;AAGN;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"utils.mjs","sources":["../../../src/client/utils.ts"],"sourcesContent":["import type { RhfUtilsFormOptions } from '@/form/RhfUtilsFormOptions';\nimport type { SafeFieldValues } from '@/form/SafeFieldValues';\nimport type { UseRhfUtilsFormProps } from '@/form/UseRhfUtilsFormProps';\n\nimport type { RhfUtilsClientConfig } from './config/RhfUtilsClientConfig';\n\n/**\n * Merge {@link RhfUtilsClientConfig.defaults} with array of {@link UseRhfUtilsFormProps}'s overrides.\n */\nexport const mergeRhfUtilsClientConfigDefaultsWithUseRhfUtilsFormProps = <\n TFieldValues extends SafeFieldValues,\n TTransformedValues extends SafeFieldValues,\n>(\n defaults: RhfUtilsClientConfig['defaults'],\n ...props: Pick<\n UseRhfUtilsFormProps<TFieldValues, TTransformedValues>,\n 'rhf' | 'utils' | 'form'\n >[]\n) =>\n // sequentially merge each set of props into defaults\n props.reduce(\n (acc, curr) => ({\n rhf: {\n ...acc?.rhf,\n ...curr.rhf,\n },\n\n utils: {\n ...acc?.utils,\n ...curr.utils,\n\n // manual merges\n\n // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing -- false positive\n ...((acc?.utils?.resetOnSubmitted || curr.utils?.resetOnSubmitted) && {\n resetOnSubmitted: {\n ...acc?.utils?.resetOnSubmitted,\n ...curr.utils?.resetOnSubmitted,\n },\n }),\n } satisfies RhfUtilsFormOptions,\n\n form: {\n ...acc?.form,\n ...curr.form,\n\n // manual merges\n\n className:\n [acc?.form?.className, curr.form?.className]\n .filter(Boolean) // filter out falsy values\n .join(' ') || undefined, // stringify (replace empty string with undefined)\n },\n }),\n\n // start with defaults\n defaults,\n );\n"],"names":["mergeRhfUtilsClientConfigDefaultsWithUseRhfUtilsFormProps","defaults","props","acc","curr","_a","_b","_c","_d","_e","_f"],"mappings":"AASa,MAAAA,IAA4D,CAIvEC,MACGC;AAAA;AAAA,EAMHA,EAAM;AAAA,IACJ,CAACC,GAAKC,MAAU;AAZP,UAAAC,GAAAC,GAAAC,GAAAC,GAAAC,GAAAC;AAYO;AAAA,QACd,KAAK;AAAA,UACH,GAAGP,KAAA,gBAAAA,EAAK;AAAA,UACR,GAAGC,EAAK;AAAA,QACV;AAAA,QAEA,OAAO;AAAA,UACL,GAAGD,KAAA,gBAAAA,EAAK;AAAA,UACR,GAAGC,EAAK;AAAA;AAAA;AAAA,UAKR,MAAKC,IAAAF,KAAA,gBAAAA,EAAK,UAAL,gBAAAE,EAAY,uBAAoBC,IAAAF,EAAK,UAAL,gBAAAE,EAAY,sBAAqB;AAAA,YACpE,kBAAkB;AAAA,cAChB,IAAGC,IAAAJ,KAAA,gBAAAA,EAAK,UAAL,gBAAAI,EAAY;AAAA,cACf,IAAGC,IAAAJ,EAAK,UAAL,gBAAAI,EAAY;AAAA,YACjB;AAAA,UACF;AAAA,QACF;AAAA,QAEA,MAAM;AAAA,UACJ,GAAGL,KAAA,gBAAAA,EAAK;AAAA,UACR,GAAGC,EAAK;AAAA;AAAA,UAIR,WACE,EAACK,IAAAN,KAAA,gBAAAA,EAAK,SAAL,gBAAAM,EAAW,YAAWC,IAAAN,EAAK,SAAL,gBAAAM,EAAW,SAAS,EACxC,OAAO,OAAO,EACd,KAAK,GAAG,KAAK;AAAA;AAAA,QACpB;AAAA,MAAA;AAAA;AAAA;AAAA,IAIFT;AAAA,EACF;AAAA;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"RhfUtilsClientForZodContextProvider.mjs","sources":["../../../../../src/client/zod/context/RhfUtilsClientForZodContextProvider.tsx"],"sourcesContent":["import React from 'react';\n\nimport type { RhfUtilsClientConfig } from '@/client/config/RhfUtilsClientConfig';\nimport { _RhfUtilsClientConfigContextProvider } from '@/client/config/useRhfUtilsClientConfigContext';\n\nimport createRhfUtilsClientForZod from '../createRhfUtilsClientForZod';\n\nimport { _RhfUtilsClientForZodContextProvider } from './useRhfUtilsClientForZodContext';\n\ntype Props = React.PropsWithChildren<{\n config: RhfUtilsClientConfig;\n}>;\n\nconst RhfUtilsClientForZodContextProvider: React.FC<Props> = ({\n config,\n children,\n}) => {\n const [_config] = React.useState(config); // memo-ize initial value\n const [_client] = React.useState(() => createRhfUtilsClientForZod(_config));\n\n return (\n <_RhfUtilsClientConfigContextProvider value={_config}>\n <_RhfUtilsClientForZodContextProvider value={_client}>\n {children}\n </_RhfUtilsClientForZodContextProvider>\n </_RhfUtilsClientConfigContextProvider>\n );\n};\n\nexport default RhfUtilsClientForZodContextProvider;\n"],"names":["RhfUtilsClientForZodContextProvider","config","children","_config","React","_client","createRhfUtilsClientForZod","jsx","_RhfUtilsClientConfigContextProvider","_RhfUtilsClientForZodContextProvider","RhfUtilsClientForZodContextProvider$1"],"mappings":";;;;;AAaA,MAAMA,IAAuD,CAAC;AAAA,EAC5D,QAAAC;AAAA,EACA,UAAAC;AACF,MAAM;AACJ,QAAM,CAACC,CAAO,IAAIC,EAAM,SAASH,CAAM,GACjC,CAACI,CAAO,IAAID,EAAM,SAAS,MAAME,EAA2BH,CAAO,CAAC;AAGxE,SAAA,gBAAAI,EAACC,KAAqC,OAAOL,GAC3C,4BAACM,GAAqC,EAAA,OAAOJ,GAC1C,UAAAH,EACH,CAAA,EACF,CAAA;AAEJ,GAEAQ,IAAeV;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"RhfUtilsZodForm.mjs","sources":["../../../../../src/client/zod/context/RhfUtilsZodForm.tsx"],"sourcesContent":["import type { UseRhfUtilsFormProps } from '@/form/UseRhfUtilsFormProps';\n\nimport type { zodTypeInput, zodTypeOutput } from '../consts';\nimport type { ZodTypeFieldValues } from '../ZodTypeFieldValues';\n\nimport useRhfUtilsClientForZodContext from './useRhfUtilsClientForZodContext';\n\ntype Props<TSchema extends ZodTypeFieldValues> = {\n schema: TSchema;\n} & UseRhfUtilsFormProps<\n TSchema[typeof zodTypeInput],\n TSchema[typeof zodTypeOutput]\n>;\n\nfunction RhfUtilsZodForm<TSchema extends ZodTypeFieldValues>({\n schema,\n ...props\n}: Props<TSchema>) {\n const { FormWithProviders } = useRhfUtilsClientForZodContext();\n\n return <FormWithProviders schema={schema} {...props} />;\n}\n\nexport default RhfUtilsZodForm;\n"],"names":["RhfUtilsZodForm","schema","props","FormWithProviders","useRhfUtilsClientForZodContext","jsx"],"mappings":";;AAcA,SAASA,EAAoD;AAAA,EAC3D,QAAAC;AAAA,EACA,GAAGC;AACL,GAAmB;AACX,QAAA,EAAE,mBAAAC,MAAsBC;AAE9B,SAAQ,gBAAAC,EAAAF,GAAA,EAAkB,QAAAF,GAAiB,GAAGC,EAAO,CAAA;AACvD;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useRhfUtilsClientForZodContext.mjs","sources":["../../../../../src/client/zod/context/useRhfUtilsClientForZodContext.tsx"],"sourcesContent":["import createContext from '@/utils/createContext';\n\nimport type createRhfUtilsClientForZod from '../createRhfUtilsClientForZod';\n\nexport type RhfUtilsClientForZodContext = ReturnType<\n typeof createRhfUtilsClientForZod\n>;\n\nconst {\n Provider: _RhfUtilsClientForZodContextProvider,\n useRequired: useRhfUtilsClientForZodContext,\n} = createContext<RhfUtilsClientForZodContext>();\n\n//\n\nexport default useRhfUtilsClientForZodContext;\n\n//\n\nexport { _RhfUtilsClientForZodContextProvider };\n"],"names":["_RhfUtilsClientForZodContextProvider","useRhfUtilsClientForZodContext","createContext"],"mappings":";AAQM,MAAA;AAAA,EACJ,UAAUA;AAAA,EACV,aAAaC;AACf,IAAIC,EAA2C;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useRhfUtilsZodForm.mjs","sources":["../../../../../src/client/zod/context/useRhfUtilsZodForm.ts"],"sourcesContent":["import type { UseRhfUtilsFormProps } from '@/form/UseRhfUtilsFormProps';\n\nimport type { zodTypeInput, zodTypeOutput } from '../consts';\nimport type { ZodTypeFieldValues } from '../ZodTypeFieldValues';\n\nimport useRhfUtilsClientForZodContext from './useRhfUtilsClientForZodContext';\n\nconst useRhfUtilsZodForm = <TSchema extends ZodTypeFieldValues>(\n schema: TSchema,\n form: UseRhfUtilsFormProps<\n TSchema[typeof zodTypeInput],\n TSchema[typeof zodTypeOutput]\n >,\n) => useRhfUtilsClientForZodContext().useForm(schema, form);\n\nexport default useRhfUtilsZodForm;\n"],"names":["useRhfUtilsZodForm","schema","form","useRhfUtilsClientForZodContext","useRhfUtilsZodForm$1"],"mappings":";AAOA,MAAMA,IAAqB,CACzBC,GACAC,MAIGC,EAAiC,EAAA,QAAQF,GAAQC,CAAI,GAE1DE,IAAeJ;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"createRhfUtilsClientForZod.mjs","sources":["../../../../src/client/zod/createRhfUtilsClientForZod.tsx"],"sourcesContent":["import { zodResolver } from '@hookform/resolvers/zod';\n\nimport { createRhfUtilsClient } from '..';\n\nimport { zodTypeInput, zodTypeOutput } from './consts';\nimport type { ZodTypeFieldValues } from './ZodTypeFieldValues';\n\nconst createRhfUtilsClientForZod = createRhfUtilsClient<\n ZodTypeFieldValues,\n typeof zodTypeInput,\n typeof zodTypeOutput\n>(zodResolver);\n\nexport default createRhfUtilsClientForZod;\n"],"names":["createRhfUtilsClientForZod","createRhfUtilsClient","zodResolver"],"mappings":";;AAOM,MAAAA,IAA6BC,EAIjCC,CAAW;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"LazyDevTool.mjs","sources":["../../../src/devtool/LazyDevTool.tsx"],"sourcesContent":["import type { DevtoolUIProps } from '@hookform/devtools/dist/devToolUI';\nimport React from 'react';\nimport { useFormContext } from 'react-hook-form';\n\nconst LazyRhfDevTool = React.lazy(() =>\n import('@hookform/devtools').then((res) => ({\n default: res.DevTool,\n })),\n);\n\ntype LazyDevToolProps = {\n isDevelopment?: boolean;\n props?: Omit<DevtoolUIProps, 'control'>;\n};\n\n/**\n * Lazy-loaded RHF DevTool.\n */\nconst LazyDevTool: React.FC<LazyDevToolProps> = ({ isDevelopment, props }) => {\n // early escape for non-dev builds\n if (!isDevelopment) return null;\n\n // eslint-disable-next-line react-hooks/rules-of-hooks\n const { control } = useFormContext();\n\n return (\n <React.Suspense fallback={null}>\n <LazyRhfDevTool control={control} {...props} />\n </React.Suspense>\n );\n};\n\nexport default LazyDevTool;\n"],"names":["LazyRhfDevTool","React","res","LazyDevTool","isDevelopment","props","control","useFormContext","jsx"],"mappings":";;;AAIA,MAAMA,IAAiBC,EAAM;AAAA,EAAK,MAChC,OAAO,oBAAoB,EAAE,KAAK,CAACC,OAAS;AAAA,IAC1C,SAASA,EAAI;AAAA,EAAA,EACb;AACJ,GAUMC,IAA0C,CAAC,EAAE,eAAAC,GAAe,OAAAC,QAAY;AAExE,MAAA,CAACD,EAAsB,QAAA;AAGrB,QAAA,EAAE,SAAAE,MAAYC;AAGlB,SAAA,gBAAAC,EAACP,EAAM,UAAN,EAAe,UAAU,MACxB,UAAA,gBAAAO,EAACR,GAAe,EAAA,SAAAM,GAAmB,GAAGD,EAAO,CAAA,EAC/C,CAAA;AAEJ;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"FlatFieldErrorsList.mjs","sources":["../../../../src/errors/flat/FlatFieldErrorsList.tsx"],"sourcesContent":["import isEmptyObject from '@/utils/isEmptyObject';\n\nimport type { FlatFieldErrors } from './types';\n\nexport type Props = {\n errors: FlatFieldErrors | null | undefined;\n};\n\nconst FlatFieldErrorsList: React.FC<Props> = ({ errors }) => {\n if (!errors) return;\n if (isEmptyObject(errors)) return;\n\n return (\n <ul>\n {Object.values(errors).map((value, index) => (\n <li\n key={index}\n role=\"alert\"\n aria-live=\"polite\" // https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attributes/aria-live\n >\n {value.message}\n </li>\n ))}\n </ul>\n );\n};\n\nexport default FlatFieldErrorsList;\n"],"names":["FlatFieldErrorsList","errors","isEmptyObject","jsx","value","index"],"mappings":";;AAQA,MAAMA,IAAuC,CAAC,EAAE,QAAAC,QAAa;AAC3D,MAAKA,KACD,CAAAC,EAAcD,CAAM;AAGtB,WAAA,gBAAAE,EAAC,QACE,UAAO,OAAA,OAAOF,CAAM,EAAE,IAAI,CAACG,GAAOC,MACjC,gBAAAF;AAAA,MAAC;AAAA,MAAA;AAAA,QAEC,MAAK;AAAA,QACL,aAAU;AAAA,QAET,UAAMC,EAAA;AAAA,MAAA;AAAA,MAJFC;AAAA,IAMR,CAAA,EACH,CAAA;AAEJ;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"FlatFieldErrorsContextProvider.mjs","sources":["../../../../../src/errors/flat/context/FlatFieldErrorsContextProvider.tsx"],"sourcesContent":["import React from 'react';\nimport { useFormState } from 'react-hook-form';\n\nimport getRefdFromFlatFieldErrors from '@/errors/getRefdFromFlatFieldErrors';\n\nimport isEmptyObject from '@/utils/isEmptyObject';\n\nimport getOrphansFromFlatFieldErrors from '../../orphan/getOrphansFromFlatFieldErrors';\nimport getRootsFromFlatFieldErrors from '../../root/getRootsFromFlatFieldErrors';\n\nimport getFlatFieldErrors from '../getFlatFieldErrors';\n\nimport { _FormErrorsFlatContextProvider } from './useFlatFieldErrorsContext';\n\ntype Props = React.PropsWithChildren<{\n formRef: React.RefObject<HTMLFormElement>;\n}>;\n\n/**\n * Provides a flattened version of the form errors.\n * Allows flattening and filtering to happen once per errors change.\n */\nconst FlatFieldErrorsContextProvider: React.FC<Props> = ({\n formRef,\n children,\n}) => {\n const { errors } = useFormState();\n\n const all = getFlatFieldErrors(errors);\n\n const orphans = formRef.current\n ? getOrphansFromFlatFieldErrors(all, formRef.current)\n : {};\n\n const value = {\n all,\n fields: getRefdFromFlatFieldErrors(all),\n roots: getRootsFromFlatFieldErrors(all),\n orphans,\n // computed\n hasErrors: !isEmptyObject(errors),\n hasOrphans: !isEmptyObject(orphans),\n };\n\n return (\n <_FormErrorsFlatContextProvider value={value}>\n {children}\n </_FormErrorsFlatContextProvider>\n );\n};\n\nexport default FlatFieldErrorsContextProvider;\n"],"names":["FlatFieldErrorsContextProvider","formRef","children","errors","useFormState","all","getFlatFieldErrors","orphans","getOrphansFromFlatFieldErrors","value","getRefdFromFlatFieldErrors","getRootsFromFlatFieldErrors","isEmptyObject","jsx","_FormErrorsFlatContextProvider"],"mappings":";;;;;;;;;AAsBA,MAAMA,IAAkD,CAAC;AAAA,EACvD,SAAAC;AAAA,EACA,UAAAC;AACF,MAAM;AACE,QAAA,EAAE,QAAAC,MAAWC,KAEbC,IAAMC,EAAmBH,CAAM,GAE/BI,IAAUN,EAAQ,UACpBO,EAA8BH,GAAKJ,EAAQ,OAAO,IAClD,IAEEQ,IAAQ;AAAA,IACZ,KAAAJ;AAAA,IACA,QAAQK,EAA2BL,CAAG;AAAA,IACtC,OAAOM,EAA4BN,CAAG;AAAA,IACtC,SAAAE;AAAA;AAAA,IAEA,WAAW,CAACK,EAAcT,CAAM;AAAA,IAChC,YAAY,CAACS,EAAcL,CAAO;AAAA,EAAA;AAIlC,SAAA,gBAAAM,EAACC,GAA+B,EAAA,OAAAL,GAC7B,UAAAP,EACH,CAAA;AAEJ;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useFlatFieldErrorsContext.mjs","sources":["../../../../../src/errors/flat/context/useFlatFieldErrorsContext.ts"],"sourcesContent":["import createContext from '@/utils/createContext';\n\nimport type { FlatFieldErrors } from '../types';\n\nexport type FlatFieldErrorsContext = {\n all: FlatFieldErrors;\n fields: FlatFieldErrors;\n roots: FlatFieldErrors;\n orphans: FlatFieldErrors;\n // computed\n hasErrors: boolean;\n hasOrphans: boolean;\n};\n\nconst {\n Provider: _FormErrorsFlatContextProvider,\n useRequired: useFlatFieldErrorsContext,\n} = createContext<FlatFieldErrorsContext>();\n\n//\n\nexport default useFlatFieldErrorsContext;\n\n//\n\nexport { _FormErrorsFlatContextProvider };\n"],"names":["_FormErrorsFlatContextProvider","useFlatFieldErrorsContext","createContext","useFlatFieldErrorsContext$1"],"mappings":";AAcM,MAAA;AAAA,EACJ,UAAUA;AAAA,EACV,aAAaC;AACf,IAAIC,EAAsC,GAI1CC,IAAeF;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useFlatFieldErrorsContextHasOnlyOrphans.mjs","sources":["../../../../../src/errors/flat/context/useFlatFieldErrorsContextHasOnlyOrphans.ts"],"sourcesContent":["import React from 'react';\n\nimport useFlatFieldErrorsContext from './useFlatFieldErrorsContext';\n\n/**\n * Returns `true` if all errors are orphans.\n *\n * You may want to treat this case specifically.\n */\nconst useFlatFieldErrorsContextHasOnlyOrphans = () => {\n const errors = useFlatFieldErrorsContext();\n\n const hasOnlyOrphans = React.useMemo(() => {\n // if empty or no orphans, early return\n if (!errors.hasErrors) return false;\n if (!errors.hasOrphans) return false;\n\n // if same count, then all errors are orphans\n return (\n Object.keys(errors.orphans).length === Object.keys(errors.all).length\n );\n }, [errors]);\n\n return hasOnlyOrphans;\n};\n\nexport default useFlatFieldErrorsContextHasOnlyOrphans;\n"],"names":["useFlatFieldErrorsContextHasOnlyOrphans","errors","useFlatFieldErrorsContext","React","useFlatFieldErrorsContextHasOnlyOrphans$1"],"mappings":";;AASA,MAAMA,IAA0C,MAAM;AACpD,QAAMC,IAASC;AAaR,SAXgBC,EAAM,QAAQ,MAE/B,CAACF,EAAO,aACR,CAACA,EAAO,aAAmB,KAI7B,OAAO,KAAKA,EAAO,OAAO,EAAE,WAAW,OAAO,KAAKA,EAAO,GAAG,EAAE,QAEhE,CAACA,CAAM,CAAC;AAGb,GAEAG,IAAeJ;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useFlatFieldErrorsContextOutput.mjs","sources":["../../../../../src/errors/flat/context/useFlatFieldErrorsContextOutput.ts"],"sourcesContent":["import React from 'react';\nimport { useFormContext } from 'react-hook-form';\n\nimport consoleErrors from '../../output/consoleErrors';\n\nimport type { FlatFieldErrorsOutputConfig } from './FlatFieldErrorsOutputConfig';\nimport useFlatFieldErrorsContext from './useFlatFieldErrorsContext';\n\n/**\n * Outputs (e.g., console, throw) errors based on config.\n */\nconst useFlatFieldErrorsContextOutput = (\n config?: FlatFieldErrorsOutputConfig,\n) => {\n const form = useFormContext();\n\n const errors = useFlatFieldErrorsContext();\n\n // when errors change (memo-ized by provider)\n // output as configured\n React.useEffect(() => {\n // if no errors, don't do anything further\n if (!errors.hasErrors) return;\n\n // CONSOLE\n\n const console = config?.console?.(errors);\n\n if (console) {\n consoleErrors(\n console.message ?? defaultMessage,\n form.getValues(),\n errors,\n console.type,\n );\n }\n\n // THROW\n\n const _throw = config?.throw?.(errors);\n\n if (_throw)\n throw new Error(typeof _throw === 'string' ? _throw : defaultMessage);\n }, [errors]); // eslint-disable-line react-hooks/exhaustive-deps\n};\n\nexport default useFlatFieldErrorsContextOutput;\n\nconst defaultMessage = 'Form errors';\n"],"names":["useFlatFieldErrorsContextOutput","config","form","useFormContext","errors","useFlatFieldErrorsContext","React","console","_a","consoleErrors","defaultMessage","_throw","_b"],"mappings":";;;;AAWM,MAAAA,IAAkC,CACtCC,MACG;AACH,QAAMC,IAAOC,KAEPC,IAASC;AAIf,EAAAC,EAAM,UAAU,MAAM;;AAEhB,QAAA,CAACF,EAAO,UAAW;AAIjB,UAAAG,KAAUC,IAAAP,KAAA,gBAAAA,EAAQ,YAAR,gBAAAO,EAAA,KAAAP,GAAkBG;AAElC,IAAIG,KACFE;AAAA,MACEF,EAAQ,WAAWG;AAAA,MACnBR,EAAK,UAAU;AAAA,MACfE;AAAA,MACAG,EAAQ;AAAA,IAAA;AAMN,UAAAI,KAASC,IAAAX,KAAA,gBAAAA,EAAQ,UAAR,gBAAAW,EAAA,KAAAX,GAAgBG;AAE3B,QAAAO;AACF,YAAM,IAAI,MAAM,OAAOA,KAAW,WAAWA,IAASD,CAAc;AAAA,EAAA,GACrE,CAACN,CAAM,CAAC;AACb,GAIMM,IAAiB;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"filterFlatFieldErrors.mjs","sources":["../../../../src/errors/flat/filterFlatFieldErrors.ts"],"sourcesContent":["import type { FlatFieldErrorEntry, FlatFieldErrors } from './types';\n\n/**\n * Filter {@link FlatFieldErrors} by a predicate.\n *\n * (Encapsulates to and from Object entries.)\n */\nconst makeFlatFieldErrorsFilter =\n (predicate: (entry: FlatFieldErrorEntry, index: number) => boolean) =>\n (errors: FlatFieldErrors): FlatFieldErrors =>\n // re-create object from entries\n Object.fromEntries(\n // break down to entries\n Object.entries(errors)\n // filter by predicate\n .filter(predicate),\n );\n\nexport default makeFlatFieldErrorsFilter;\n"],"names":["makeFlatFieldErrorsFilter","predicate","errors"],"mappings":"AAOM,MAAAA,IACJ,CAACC,MACD,CAACC;AAAA;AAAA,EAEC,OAAO;AAAA;AAAA,IAEL,OAAO,QAAQA,CAAM,EAElB,OAAOD,CAAS;AAAA,EACrB;AAAA;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"flattenFieldErrors.mjs","sources":["../../../../src/errors/flat/flattenFieldErrors.ts"],"sourcesContent":["import { flatten } from 'flat';\nimport type { FieldErrors } from 'react-hook-form';\n\n/**\n * Only flattens a {@link FieldErrors} object.\n * @returns e.g.,\n * ```\n * {\n * \"address.street.type\": \"too_short\",\n * \"address.street.ref.value\": \"123\",\n * \"address.street.message\": \"Required.\"\n * }\n * ```\n */\nconst flattenFieldErrors = (errors: FieldErrors) =>\n flatten<FieldErrors, Record<string, unknown>>(errors);\n\nexport default flattenFieldErrors;\n"],"names":["flattenFieldErrors","errors","flatten"],"mappings":";AAcA,MAAMA,IAAqB,CAACC,MAC1BC,EAA8CD,CAAM;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"getFlatFieldErrors.mjs","sources":["../../../../src/errors/flat/getFlatFieldErrors.ts"],"sourcesContent":["import type { FieldError, FieldErrors } from 'react-hook-form';\nimport { get } from 'react-hook-form';\n\nimport flattenFieldErrors from './flattenFieldErrors';\nimport type { FlatFieldErrors } from './types';\n\n/**\n * Get {@link FlatFieldErrors} from {@link FieldErrors}.\n * This makes it easy to work with potentially deeply-nested {@link FieldErrors}.\n *\n * @param errors {@link FieldErrors} object.\n *\n * @returns `FlatFieldErrors` object.\n *\n * @example\n * ```\n * {\n * \"address.street\": {\n * type: \"too_short\",\n * ref: { value: \"123\" },\n * message: \"Required.\" }\n * }\n * }\n * ```\n */\nconst getFlatFieldErrors = (errors: FieldErrors): FlatFieldErrors => {\n // flatten object for simpler processing\n const flattened = flattenFieldErrors(errors);\n\n // get flattened keys (e.g., `name.message`), which we must transform back to actual paths (e.g., `name`)\n const flattenedKeys = Object.keys(flattened);\n\n // rebuild FlatFieldErrors\n return Object.fromEntries(\n flattenedKeys.reduce<[PropertyKey, FieldError][]>(\n (entries, flattenedKey) => {\n // remove possible leaf node suffix from flattened key\n const path = flattenedKey.replace(\n regexMaybeFieldErrorLeafNodeSuffix,\n '',\n );\n\n // if nothing replaced, then it's not a leaf node; return early\n if (path === flattenedKey) return entries;\n\n // find field error in original FieldErrors object\n // has dual-purpose of confirming that each path is valid\n const fieldError = get(errors, path, undefined) as\n | FieldError\n | undefined;\n\n // if no field error found, then key was wrong; return early\n if (!fieldError) return entries;\n\n // add entry\n entries.push([path, fieldError]);\n\n // if dupe, doesn't matter -- i.e., `.type` leaf node matched before `.message`\n // Object.entries will overwrite dupe with same key/value\n\n return entries;\n },\n\n [], // entries\n ),\n );\n};\n\nexport default getFlatFieldErrors;\n\n//\n\n/**\n * Regular expression to maybe match the end of a leaf node path.\n *\n * i.e., `name.type`, `address.street.message`\n *\n * iow: dot [?: non-capturing](\"type\" | \"message\")[\\b word boundary][$ end of string]\n */\nexport const regexMaybeFieldErrorLeafNodeSuffix = /\\.(?:type|message)\\b$/;\n"],"names":["getFlatFieldErrors","errors","flattened","flattenFieldErrors","flattenedKeys","entries","flattenedKey","path","regexMaybeFieldErrorLeafNodeSuffix","fieldError","get"],"mappings":";;AAyBM,MAAAA,IAAqB,CAACC,MAAyC;AAE7D,QAAAC,IAAYC,EAAmBF,CAAM,GAGrCG,IAAgB,OAAO,KAAKF,CAAS;AAG3C,SAAO,OAAO;AAAA,IACZE,EAAc;AAAA,MACZ,CAACC,GAASC,MAAiB;AAEzB,cAAMC,IAAOD,EAAa;AAAA,UACxBE;AAAA,UACA;AAAA,QAAA;AAIE,YAAAD,MAASD,EAAqB,QAAAD;AAIlC,cAAMI,IAAaC,EAAIT,GAAQM,GAAM,MAAS;AAK1C,eAACE,KAGLJ,EAAQ,KAAK,CAACE,GAAME,CAAU,CAAC,GAKxBJ;AAAA,MACT;AAAA,MAEA,CAAC;AAAA;AAAA,IACH;AAAA,EAAA;AAEJ,GAaaG,IAAqC;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"getRefdFromFlatFieldErrors.mjs","sources":["../../../src/errors/getRefdFromFlatFieldErrors.ts"],"sourcesContent":["import makeFlatFieldErrorsFilter from './flat/filterFlatFieldErrors';\nimport isFlatFieldErrorEntryRefd from './isFlatFieldErrorEntryRefd';\n\nconst getRefdFromFlatFieldErrors = makeFlatFieldErrorsFilter(\n isFlatFieldErrorEntryRefd,\n);\n\nexport default getRefdFromFlatFieldErrors;\n"],"names":["getRefdFromFlatFieldErrors","makeFlatFieldErrorsFilter","isFlatFieldErrorEntryRefd"],"mappings":";;AAGA,MAAMA,IAA6BC;AAAA,EACjCC;AACF;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"isFieldErrorRefd.mjs","sources":["../../../src/errors/isFieldErrorRefd.ts"],"sourcesContent":["import type { FieldError } from 'react-hook-form';\n\n/**\n * Determine if {@link FieldError} is a `ref`'d field error.\n */\nconst isFieldErrorRefd = (error: FieldError): boolean => !!error.ref;\n\nexport default isFieldErrorRefd;\n"],"names":["isFieldErrorRefd","error"],"mappings":"AAKA,MAAMA,IAAmB,CAACC,MAA+B,CAAC,CAACA,EAAM;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"isFlatFieldErrorEntryRefd.mjs","sources":["../../../src/errors/isFlatFieldErrorEntryRefd.ts"],"sourcesContent":["import type { FlatFieldErrorEntry } from './flat/types';\nimport isFieldErrorRefd from './isFieldErrorRefd';\n\n/**\n * Determine if {@link FieldError} is a `ref`'d field error.\n */\nconst isFlatFieldErrorEntryRefd = ([, error]: FlatFieldErrorEntry): boolean =>\n isFieldErrorRefd(error);\n\nexport default isFlatFieldErrorEntryRefd;\n"],"names":["isFlatFieldErrorEntryRefd","error","isFieldErrorRefd"],"mappings":";AAMA,MAAMA,IAA4B,CAAC,CAAA,EAAGC,CAAK,MACzCC,EAAiBD,CAAK;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"FormErrorMessage.mjs","sources":["../../../../src/errors/message/FormErrorMessage.tsx"],"sourcesContent":["import React from 'react';\n\ntype Props = { message: string; className?: string };\n\nconst FormErrorMessage: React.FC<Props> = ({ message, className }) => (\n <p\n role=\"alert\"\n aria-live=\"polite\" // https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attributes/aria-live\n className={className}\n >\n {message}\n </p>\n);\n\nexport default FormErrorMessage;\n"],"names":["FormErrorMessage","message","className","jsx"],"mappings":";;AAIA,MAAMA,IAAoC,CAAC,EAAE,SAAAC,GAAS,WAAAC,EACpD,MAAA,gBAAAC;AAAA,EAAC;AAAA,EAAA;AAAA,IACC,MAAK;AAAA,IACL,aAAU;AAAA,IACV,WAAAD;AAAA,IAEC,UAAAD;AAAA,EAAA;AACH;"}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { jsxs as n, Fragment as a, jsx as e } from "react/jsx-runtime";
|
|
2
|
-
import { useFormState as g, get as i } from "react-hook-form";
|
|
3
|
-
import F from "../nonfield/FormNonFieldErrorMarker.mjs";
|
|
4
|
-
import c from "./FormErrorMessage.mjs";
|
|
5
|
-
const f = ({ path: o, Component: s }) => {
|
|
6
|
-
const { errors: t } = g(), r = i(t, o, void 0), m = s ?? c;
|
|
7
|
-
return r != null && r.message ? /* @__PURE__ */ n(a, { children: [
|
|
8
|
-
/* @__PURE__ */ e(m, { message: r.message }),
|
|
9
|
-
/* @__PURE__ */ e(F, { path: o })
|
|
10
|
-
] }) : null;
|
|
11
|
-
}, E = f;
|
|
12
|
-
export {
|
|
13
|
-
E as default
|
|
14
|
-
};
|
|
15
|
-
//# sourceMappingURL=FormErrorMessageByPath.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"FormErrorMessageByPath.mjs","sources":["../../../../src/errors/message/FormErrorMessageByPath.tsx"],"sourcesContent":["import type { FieldError } from 'react-hook-form';\nimport { get, useFormState } from 'react-hook-form';\n\nimport FormNonFieldErrorMarker from '../nonfield/FormNonFieldErrorMarker';\n\nimport FormErrorMessage from './FormErrorMessage';\n\ntype Props = {\n /** Field name as flat path. (e.g., \"address.street\") */\n path: string;\n /** Optional component to use to display message. (Defaults to {@link FormErrorMessage}) */\n Component?: React.FC<{ message: string }>;\n};\n\nconst FormErrorMessageByPath: React.FC<Props> = ({ path, Component }) => {\n const { errors } = useFormState();\n\n const error = get(errors, path, undefined) as FieldError | undefined;\n\n const _Component = Component ?? FormErrorMessage;\n\n if (!error?.message) return null;\n\n return (\n <>\n {/* error message */}\n <_Component message={error.message} />\n\n {/* marker (only required for non-root non-field errors) */}\n <FormNonFieldErrorMarker path={path} />\n </>\n );\n};\n\nexport default FormErrorMessageByPath;\n"],"names":["FormErrorMessageByPath","path","Component","errors","useFormState","error","get","_Component","FormErrorMessage","jsxs","Fragment","jsx","FormNonFieldErrorMarker","FormErrorMessageByPath$1"],"mappings":";;;;AAcA,MAAMA,IAA0C,CAAC,EAAE,MAAAC,GAAM,WAAAC,QAAgB;AACjE,QAAA,EAAE,QAAAC,MAAWC,KAEbC,IAAQC,EAAIH,GAAQF,GAAM,MAAS,GAEnCM,IAAaL,KAAaM;AAE5B,SAACH,KAAA,QAAAA,EAAO,UAKR,gBAAAI,EAAAC,GAAA,EAAA,UAAA;AAAA,IAAC,gBAAAC,EAAAJ,GAAA,EAAW,SAASF,EAAM,QAAS,CAAA;AAAA,IAGpC,gBAAAM,EAACC,KAAwB,MAAAX,GAAY;AAAA,EACvC,EAAA,CAAA,IAT0B;AAW9B,GAEAY,IAAeb;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"FormNonFieldErrorMarker.mjs","sources":["../../../../src/errors/nonfield/FormNonFieldErrorMarker.tsx"],"sourcesContent":["import FormNonFieldErrorMarkerHtmlAttribute from './FormNonFieldErrorMarkerHtmlAttribute';\n\ntype Props = {\n /** Flat field name. (e.g., `address.street`) */\n path: string;\n};\n\n/**\n * Empty, hidden marker to indicate a non-field/non-root error is being displayed to user.\n *\n * Example use case:\n * Field array with minimum items.\n * (When there are no items, the error is not associated with a field and is displayed separately.)\n */\nconst FormNonFieldErrorMarker: React.FC<Props> = ({ path }) => {\n const dataAttribute = {\n [FormNonFieldErrorMarkerHtmlAttribute]: path,\n };\n\n return (\n <div\n role=\"alert\"\n aria-hidden=\"true\" // hide from screen readers\n style={{ display: 'none' }} // hide from view/flow\n {...dataAttribute}\n />\n );\n};\n\nexport default FormNonFieldErrorMarker;\n"],"names":["FormNonFieldErrorMarker","path","dataAttribute","FormNonFieldErrorMarkerHtmlAttribute","jsx","FormNonFieldErrorMarker$1"],"mappings":";;AAcA,MAAMA,IAA2C,CAAC,EAAE,MAAAC,QAAW;AAC7D,QAAMC,IAAgB;AAAA,IACpB,CAACC,CAAoC,GAAGF;AAAA,EAAA;AAIxC,SAAA,gBAAAG;AAAA,IAAC;AAAA,IAAA;AAAA,MACC,MAAK;AAAA,MACL,eAAY;AAAA,MACZ,OAAO,EAAE,SAAS,OAAO;AAAA,MACxB,GAAGF;AAAA,IAAA;AAAA,EAAA;AAGV,GAEAG,IAAeL;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"FormNonFieldErrorMarker.utils.mjs","sources":["../../../../src/errors/nonfield/FormNonFieldErrorMarker.utils.ts"],"sourcesContent":["import FormNonFieldErrorMarkerHtmlAttribute from './FormNonFieldErrorMarkerHtmlAttribute';\n\n/**\n * Returns query selector for matching non-field error marker.\n * By default includes nested field matching. (See `options.excludeNested`.)\n *\n * @returns One or more selectors in a comma-separated list.\n */\nexport const getFormNonFieldErrorMarkerQuerySelector = (\n path: string,\n options?: {\n /**\n * Do not look for match as nested field.\n *\n * By default this is enabled to facilitate looking for fields that may be nested inside objects.\n * This is only a problem when a front-end field is nested more deeply than back-end.\n * For example, field arrays require objects as items, so actual field may be `field.value`.\n * This should be safe, as fields are by definition leaf nodes, so will not have nested fields.\n * (If this check should need to be more precise in the future, it may be ideal to distinguish between client/server errors or paths.)\n */\n excludeNested?: boolean;\n },\n) => {\n return (\n // list of selector variants\n (\n [\n // equals\n // e.g., attr=\"path\"\n ['', ''],\n\n // starts with\n // e.g., attr^=\"path.\"\n ...(options?.excludeNested\n ? []\n : [\n [\n // @see https://developer.mozilla.org/en-US/docs/Web/CSS/Attribute_selectors#attrvalue_4\n '^',\n // only match nested (avoid match 'field' with 'field1`)\n '.',\n ],\n ]),\n ] as const\n )\n .map(([attrSuffix, pathSuffix]) =>\n _getQuerySelector(\n FormNonFieldErrorMarkerHtmlAttribute + attrSuffix,\n path + pathSuffix,\n ),\n )\n\n // construct list selector for O(n)\n .join(', ')\n );\n};\n\n// util\n\nconst _getQuerySelector = (attr: string, value: string) =>\n `[role=\"alert\"][${attr}=\"${value}\"]`;\n"],"names":["getFormNonFieldErrorMarkerQuerySelector","path","options","attrSuffix","pathSuffix","_getQuerySelector","FormNonFieldErrorMarkerHtmlAttribute","attr","value"],"mappings":";AAQa,MAAAA,IAA0C,CACrDC,GACAC;AAAA;AAAA,EAgBI;AAAA;AAAA;AAAA,IAGE,CAAC,IAAI,EAAE;AAAA,IAOD;AAAA;AAAA,MAEE;AAAA;AAAA,MAEA;AAAA,IACF;AAAA,EACF,EAGL;AAAA,IAAI,CAAC,CAACC,GAAYC,CAAU,MAC3BC;AAAA,MACEC,IAAuCH;AAAA,MACvCF,IAAOG;AAAA,IACT;AAAA,EAAA,EAID,KAAK,IAAI;AAAA,GAMVC,IAAoB,CAACE,GAAcC,MACvC,kBAAkBD,CAAI,KAAKC,CAAK;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"FormNonFieldErrorMarkerHtmlAttribute.mjs","sources":["../../../../src/errors/nonfield/FormNonFieldErrorMarkerHtmlAttribute.ts"],"sourcesContent":["/**\n * HTML data attribute for {@link FormNonFieldErrorMarker}.\n */\nconst FormNonFieldErrorMarkerHtmlAttribute =\n 'data-paragrav-rhf-utils-nonfield-error-marker-path';\n\nexport default FormNonFieldErrorMarkerHtmlAttribute;\n"],"names":["FormNonFieldErrorMarkerHtmlAttribute"],"mappings":"AAGA,MAAMA,IACJ;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"isNonFieldErrorMarkerInDOM.mjs","sources":["../../../../src/errors/nonfield/isNonFieldErrorMarkerInDOM.ts"],"sourcesContent":["import { getFormNonFieldErrorMarkerQuerySelector } from './FormNonFieldErrorMarker.utils';\n\n/**\n * Determine if a non-field error marker is in the DOM.\n * Note: this will also look for nested markers to accommodate field arrays\n */\nconst isNonFieldErrorMarkerInDOM = (\n path: string,\n parentElement: Pick<HTMLElement, 'querySelector'>,\n): boolean =>\n !!parentElement.querySelector(getFormNonFieldErrorMarkerQuerySelector(path));\n\nexport default isNonFieldErrorMarkerInDOM;\n"],"names":["isNonFieldErrorMarkerInDOM","path","parentElement","getFormNonFieldErrorMarkerQuerySelector"],"mappings":";AAMM,MAAAA,IAA6B,CACjCC,GACAC,MAEA,CAAC,CAACA,EAAc,cAAcC,EAAwCF,CAAI,CAAC;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"getIsOrphanFormErrorWithParentElement.mjs","sources":["../../../../src/errors/orphan/getIsOrphanFormErrorWithParentElement.ts"],"sourcesContent":["import type { FlatFieldErrorEntry } from '../flat/types';\n\nimport isOrphanFormError from './isOrphanFormError';\n\n/**\n * Util wrapper for {@link isOrphanFormError} for usage with {@link FlatFieldErrorEntry}.\n */\nconst getIsFlatFieldErrorEntryOrphanByParentElement =\n (parentElement: Pick<HTMLElement, 'querySelector'>) =>\n ([path, error]: FlatFieldErrorEntry) =>\n isOrphanFormError(path, error, parentElement);\n\nexport default getIsFlatFieldErrorEntryOrphanByParentElement;\n"],"names":["getIsFlatFieldErrorEntryOrphanByParentElement","parentElement","path","error","isOrphanFormError"],"mappings":";AAOM,MAAAA,IACJ,CAACC,MACD,CAAC,CAACC,GAAMC,CAAK,MACXC,EAAkBF,GAAMC,GAAOF,CAAa;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"getOrphansFromFlatFieldErrors.mjs","sources":["../../../../src/errors/orphan/getOrphansFromFlatFieldErrors.ts"],"sourcesContent":["import makeFlatFieldErrorsFilter from '../flat/filterFlatFieldErrors';\nimport type { FlatFieldErrors } from '../flat/types';\n\nimport getIsFlatFieldErrorEntryOrphanByParentElement from './getIsOrphanFormErrorWithParentElement';\n\nconst getOrphansFromFlatFieldErrors = (\n errors: FlatFieldErrors,\n parentElement: Pick<HTMLElement, 'querySelector'>,\n): FlatFieldErrors =>\n makeFlatFieldErrorsFilter(\n getIsFlatFieldErrorEntryOrphanByParentElement(parentElement),\n )(errors);\n\nexport default getOrphansFromFlatFieldErrors;\n"],"names":["getOrphansFromFlatFieldErrors","errors","parentElement","makeFlatFieldErrorsFilter","getIsFlatFieldErrorEntryOrphanByParentElement"],"mappings":";;AAKM,MAAAA,IAAgC,CACpCC,GACAC,MAEAC;AAAA,EACEC,EAA8CF,CAAa;AAC7D,EAAED,CAAM;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"isOrphanFormError.mjs","sources":["../../../../src/errors/orphan/isOrphanFormError.ts"],"sourcesContent":["import type { FieldError } from 'react-hook-form';\n\nimport isFieldErrorRefd from '../isFieldErrorRefd';\nimport isNonFieldErrorMarkerInDOM from '../nonfield/isNonFieldErrorMarkerInDOM';\nimport isFormErrorPathRoot from '../root/isFormErrorPathRoot';\n\nconst isOrphanFormError = (\n path: string,\n error: FieldError,\n parentElement: Pick<HTMLElement, 'querySelector'>,\n) =>\n // not root path\n !isFormErrorPathRoot(path) &&\n // non-field\n !isFieldErrorRefd(error) &&\n // not marked in DOM\n !isNonFieldErrorMarkerInDOM(path, parentElement);\n\nexport default isOrphanFormError;\n"],"names":["isOrphanFormError","path","error","parentElement","isFormErrorPathRoot","isFieldErrorRefd","isNonFieldErrorMarkerInDOM"],"mappings":";;;AAMM,MAAAA,IAAoB,CACxBC,GACAC,GACAC;AAAA;AAAA,EAGA,CAACC,EAAoBH,CAAI;AAAA,EAEzB,CAACI,EAAiBH,CAAK;AAAA,EAEvB,CAACI,EAA2BL,GAAME,CAAa;AAAA;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"consoleErrors.mjs","sources":["../../../../src/errors/output/consoleErrors.ts"],"sourcesContent":["import type { SafeFieldValues } from '@/form/SafeFieldValues';\n\n/**\n * Output form values and errors to console.\n */\nconst consoleErrors = (\n message: string,\n values: SafeFieldValues,\n // accept any record -- e.g., FieldErrors or FlatFieldErrors\n errors: Record<string, unknown>,\n type: 'debug' | 'error' = 'debug',\n) => {\n // eslint-disable-next-line no-console -- deliberate logging\n console[type](message, { values, errors });\n};\n\nexport default consoleErrors;\n"],"names":["consoleErrors","message","values","errors","type"],"mappings":"AAKA,MAAMA,IAAgB,CACpBC,GACAC,GAEAC,GACAC,IAA0B,YACvB;AAEH,UAAQA,CAAI,EAAEH,GAAS,EAAE,QAAAC,GAAQ,QAAAC,GAAQ;AAC3C;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"RootErrorsListFromFlatFieldErrorsContext.mjs","sources":["../../../../src/errors/root/RootErrorsListFromFlatFieldErrorsContext.tsx"],"sourcesContent":["import useFlatFieldErrorsContext from '../flat/context/useFlatFieldErrorsContext';\nimport FlatFieldErrorsList from '../flat/FlatFieldErrorsList';\n\nconst RootErrorsListFromFlatFieldErrorsContext: React.FC = () => {\n const rootErrors = useFlatFieldErrorsContext().roots;\n\n return <FlatFieldErrorsList errors={rootErrors} />;\n};\n\nexport default RootErrorsListFromFlatFieldErrorsContext;\n"],"names":["RootErrorsListFromFlatFieldErrorsContext","rootErrors","useFlatFieldErrorsContext","jsx","FlatFieldErrorsList","RootErrorsListFromFlatFieldErrorsContext$1"],"mappings":";;;AAGA,MAAMA,IAAqD,MAAM;AACzD,QAAAC,IAAaC,EAA4B,EAAA;AAExC,SAAA,gBAAAC,EAACC,GAAoB,EAAA,QAAQH,EAAY,CAAA;AAClD,GAEAI,IAAeL;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"consts.mjs","sources":["../../../../src/errors/root/consts.ts"],"sourcesContent":["export const FormErrorPathRoot = 'root';\n"],"names":["FormErrorPathRoot"],"mappings":"AAAO,MAAMA,IAAoB;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"getRootsFromFlatFieldErrors.mjs","sources":["../../../../src/errors/root/getRootsFromFlatFieldErrors.ts"],"sourcesContent":["import makeFlatFieldErrorsFilter from '../flat/filterFlatFieldErrors';\n\nimport isFlatFieldErrorEntryPathRoot from './isFlatFieldErrorEntryPathRoot';\n\nconst getRootsFromFlatFieldErrors = makeFlatFieldErrorsFilter(\n isFlatFieldErrorEntryPathRoot,\n);\n\nexport default getRootsFromFlatFieldErrors;\n"],"names":["getRootsFromFlatFieldErrors","makeFlatFieldErrorsFilter","isFlatFieldErrorEntryPathRoot"],"mappings":";;AAIA,MAAMA,IAA8BC;AAAA,EAClCC;AACF;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"isFlatFieldErrorEntryPathRoot.mjs","sources":["../../../../src/errors/root/isFlatFieldErrorEntryPathRoot.ts"],"sourcesContent":["import type { FlatFieldErrorEntry } from '../flat/types';\n\nimport isFormErrorPathRoot from './isFormErrorPathRoot';\n\n/**\n * Util wrapper for {@link isFormErrorPathRoot} for usage with {@link FlatFieldErrorEntry}.\n */\nconst isFlatFieldErrorEntryPathRoot = ([path]: FlatFieldErrorEntry) =>\n isFormErrorPathRoot(path);\n\nexport default isFlatFieldErrorEntryPathRoot;\n"],"names":["isFlatFieldErrorEntryPathRoot","path","isFormErrorPathRoot"],"mappings":";AAOA,MAAMA,IAAgC,CAAC,CAACC,CAAI,MAC1CC,EAAoBD,CAAI;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"isFormErrorPathRoot.mjs","sources":["../../../../src/errors/root/isFormErrorPathRoot.ts"],"sourcesContent":["import { FormErrorPathRoot } from './consts';\n\n/**\n * Determine if an error path is root. (e.g., `root` or `root.nested`)\n *\n * @param path Flat path. (e.g., 'root.nested')\n */\nconst isFormErrorPathRoot = (path: string): boolean =>\n path === FormErrorPathRoot || path.startsWith(FormErrorPathRoot + '.');\n\nexport default isFormErrorPathRoot;\n"],"names":["isFormErrorPathRoot","path","FormErrorPathRoot"],"mappings":";AAOM,MAAAA,IAAsB,CAACC,MAC3BA,MAASC,KAAqBD,EAAK,WAAWC,IAAoB,GAAG;"}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { TRPCClientError as n } from "@trpc/client";
|
|
2
|
-
import e from "./trpcClientErrorToFormSubmitErrorsSchemaTransformer.mjs";
|
|
3
|
-
const o = (t) => (r) => r instanceof n ? e.parse(r) : t(r), a = o;
|
|
4
|
-
export {
|
|
5
|
-
a as default
|
|
6
|
-
};
|
|
7
|
-
//# sourceMappingURL=getOnSubmitTrpcClientErrorHandler.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"getOnSubmitTrpcClientErrorHandler.mjs","sources":["../../../../src/errors/trpc/getOnSubmitTrpcClientErrorHandler.ts"],"sourcesContent":["import { TRPCClientError } from '@trpc/client';\n\nimport type { RhfUtilsClientConfig } from '@/client/config/RhfUtilsClientConfig';\n\nimport type { FormSubmitErrors } from '@/submit/error/FormSubmitErrors';\n\nimport trpcClientErrorToFormSubmitErrorsSchemaTransformer from './trpcClientErrorToFormSubmitErrorsSchemaTransformer';\n\n/**\n * HOF that returns submit error handler for {@link RhfUtilsClientConfig.onSubmitErrorUnknown}.\n *\n * @param onError Fallback for handling non-TRPC errors.\n * @returns FormSubmitError\n */\nconst getOnSubmitTrpcClientErrorHandler =\n (\n onNotTrpcClientError: NonNullable<\n RhfUtilsClientConfig['onSubmitErrorUnknown']\n >,\n ) =>\n (error: unknown): FormSubmitErrors | undefined => {\n // transform\n if (error instanceof TRPCClientError)\n return trpcClientErrorToFormSubmitErrorsSchemaTransformer.parse(error);\n\n // if unknown error, use callback\n return onNotTrpcClientError(error);\n };\n\nexport default getOnSubmitTrpcClientErrorHandler;\n"],"names":["getOnSubmitTrpcClientErrorHandler","onNotTrpcClientError","error","TRPCClientError","trpcClientErrorToFormSubmitErrorsSchemaTransformer","getOnSubmitTrpcClientErrorHandler$1"],"mappings":";;AAcA,MAAMA,IACJ,CACEC,MAIF,CAACC,MAEKA,aAAiBC,IACZC,EAAmD,MAAMF,CAAK,IAGhED,EAAqBC,CAAK,GAGrCG,IAAeL;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"trpcClientErrorMessageSchema.mjs","sources":["../../../../src/errors/trpc/trpcClientErrorMessageSchema.ts"],"sourcesContent":["import { z } from 'zod';\n\n/**\n * Schema for {@link TRPCClientError} message.\n *\n * (Sent from backend as JSON string.)\n */\nconst trpcClientErrorMessageSchema = z.object({\n validation: z.string(),\n code: z.string(),\n message: z.string(),\n path: z.array(z.string()),\n});\n\nexport default trpcClientErrorMessageSchema;\n"],"names":["trpcClientErrorMessageSchema","z"],"mappings":";AAOM,MAAAA,IAA+BC,EAAE,OAAO;AAAA,EAC5C,YAAYA,EAAE,OAAO;AAAA,EACrB,MAAMA,EAAE,OAAO;AAAA,EACf,SAASA,EAAE,OAAO;AAAA,EAClB,MAAMA,EAAE,MAAMA,EAAE,QAAQ;AAC1B,CAAC;"}
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { TRPCClientError as o } from "@trpc/client";
|
|
2
|
-
import { z as e } from "zod";
|
|
3
|
-
import a from "./trpcClientErrorMessageSchema.mjs";
|
|
4
|
-
const i = e.custom(
|
|
5
|
-
(r) => r instanceof o
|
|
6
|
-
// check instance type
|
|
7
|
-
).transform((r) => r.message).transform((r) => {
|
|
8
|
-
try {
|
|
9
|
-
return JSON.parse(r);
|
|
10
|
-
} catch {
|
|
11
|
-
return [
|
|
12
|
-
{
|
|
13
|
-
validation: "root",
|
|
14
|
-
code: "server",
|
|
15
|
-
message: r,
|
|
16
|
-
path: ["root"]
|
|
17
|
-
}
|
|
18
|
-
];
|
|
19
|
-
}
|
|
20
|
-
}).pipe(e.array(a)).transform(
|
|
21
|
-
(r) => r.map(
|
|
22
|
-
(t) => [
|
|
23
|
-
t.path.join("."),
|
|
24
|
-
// flatten path (e.g., "street.name")
|
|
25
|
-
{
|
|
26
|
-
type: t.code,
|
|
27
|
-
message: t.message
|
|
28
|
-
}
|
|
29
|
-
]
|
|
30
|
-
)
|
|
31
|
-
).transform((r) => Object.fromEntries(r));
|
|
32
|
-
export {
|
|
33
|
-
i as default
|
|
34
|
-
};
|
|
35
|
-
//# sourceMappingURL=trpcClientErrorToFormSubmitErrorsSchemaTransformer.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"trpcClientErrorToFormSubmitErrorsSchemaTransformer.mjs","sources":["../../../../src/errors/trpc/trpcClientErrorToFormSubmitErrorsSchemaTransformer.ts"],"sourcesContent":["import type { TRPCClientErrorLike } from '@trpc/client';\nimport { TRPCClientError } from '@trpc/client';\nimport type { AnyRouter } from '@trpc/server';\nimport type { ErrorOption } from 'react-hook-form';\nimport { z } from 'zod';\n\nimport type { FormSubmitErrors } from '@/submit/error/FormSubmitErrors';\n\nimport trpcClientErrorMessageSchema from './trpcClientErrorMessageSchema';\n\n/**\n * Schema that transforms {@link TRPCClientError} to RHF {@link FormSubmitErrors}.\n */\nconst trpcClientErrorToFormSubmitErrorsSchemaTransformer = z\n .custom<TRPCClientErrorLike<AnyRouter>>(\n (error: unknown) => error instanceof TRPCClientError, // check instance type\n )\n\n // return: message (stringified json)\n .transform((error) => error.message)\n\n // return: parsed json as unknown\n .transform((json) => {\n try {\n return JSON.parse(json) as unknown;\n } catch (error) {\n // if not json, message is just string\n // build single item array for root\n // (must be in array for next step in transform)\n return [\n {\n validation: 'root',\n code: 'server',\n message: json,\n path: ['root'],\n },\n ] satisfies z.infer<typeof trpcClientErrorMessageSchema>[];\n }\n })\n\n // return: (trpc client error)[]\n .pipe(z.array(trpcClientErrorMessageSchema))\n\n // return: [path, ErrorOption][] (array of entries)\n .transform((errors) =>\n errors.map(\n (error) =>\n [\n error.path.join('.'), // flatten path (e.g., \"street.name\")\n {\n type: error.code,\n message: error.message,\n } satisfies ErrorOption,\n ] as const,\n ),\n )\n\n // return: FormSubmitErrors\n .transform((errors) => Object.fromEntries(errors) as FormSubmitErrors);\n\nexport default trpcClientErrorToFormSubmitErrorsSchemaTransformer;\n"],"names":["trpcClientErrorToFormSubmitErrorsSchemaTransformer","z","error","TRPCClientError","json","trpcClientErrorMessageSchema","errors"],"mappings":";;;AAaA,MAAMA,IAAqDC,EACxD;AAAA,EACC,CAACC,MAAmBA,aAAiBC;AAAA;AACvC,EAGC,UAAU,CAACD,MAAUA,EAAM,OAAO,EAGlC,UAAU,CAACE,MAAS;AACf,MAAA;AACK,WAAA,KAAK,MAAMA,CAAI;AAAA,UACR;AAIP,WAAA;AAAA,MACL;AAAA,QACE,YAAY;AAAA,QACZ,MAAM;AAAA,QACN,SAASA;AAAA,QACT,MAAM,CAAC,MAAM;AAAA,MACf;AAAA,IAAA;AAAA,EAEJ;AACF,CAAC,EAGA,KAAKH,EAAE,MAAMI,CAA4B,CAAC,EAG1C;AAAA,EAAU,CAACC,MACVA,EAAO;AAAA,IACL,CAACJ,MACC;AAAA,MACEA,EAAM,KAAK,KAAK,GAAG;AAAA;AAAA,MACnB;AAAA,QACE,MAAMA,EAAM;AAAA,QACZ,SAASA,EAAM;AAAA,MACjB;AAAA,IACF;AAAA,EACJ;AACF,EAGC,UAAU,CAACI,MAAW,OAAO,YAAYA,CAAM,CAAqB;"}
|
package/dist/esm/exports.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"exports.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Form.mjs","sources":["../../../src/form/Form.tsx"],"sourcesContent":["import React from 'react';\nimport type { UseFormHandleSubmit } from 'react-hook-form';\nimport { useFormContext } from 'react-hook-form';\n\nimport type { RhfUtilsFormChildrenWrapperProps } from '@/client/config/RhfUtilsClientConfig';\nimport useRhfUtilsClientConfigMaybeContext from '@/client/config/useRhfUtilsClientConfigContext';\n\nimport LazyDevTool from '@/devtool/LazyDevTool';\n\nimport { FormSubmitError } from '@/submit/error/FormSubmitError';\nimport setCtxErrorsByFormSubmitErrors from '@/submit/error/setCtxErrorsByFormSubmitErrors';\n\nimport PassthroughChildren from '@/utils/PassthroughChildren';\n\nimport _Controller from './_Controller';\nimport type { SafeFieldValues } from './SafeFieldValues';\nimport type { UseRhfUtilsFormChildrenProps } from './UseRhfUtilsFormChildrenProps';\nimport type {\n UseRhfUtilsFormOnSubmitContext,\n UseRhfUtilsFormOnSubmitErrorContext,\n} from './UseRhfUtilsFormOnSubmitContext';\nimport type { UseRhfUtilsFormProps } from './UseRhfUtilsFormProps';\n\nexport type FormChildrenSlots = 'top' | 'bottom';\n\nexport type FormProps<\n TFieldValues extends SafeFieldValues,\n TTransformedValues extends SafeFieldValues,\n> = {\n formId: string;\n formRef: React.RefObject<HTMLFormElement>;\n} & Pick<\n UseRhfUtilsFormProps<TFieldValues, TTransformedValues>,\n | 'onSubmit'\n | 'onSubmitError'\n | 'onSubmitInvalid'\n //\n | 'Children'\n //\n | 'form'\n | 'utils'\n>;\n\nfunction _Form<\n TFieldValues extends SafeFieldValues,\n TTransformedValues extends SafeFieldValues,\n>({\n formId,\n formRef,\n //\n onSubmit,\n onSubmitError,\n onSubmitInvalid,\n Children,\n //\n form,\n utils,\n}: FormProps<TFieldValues, TTransformedValues>) {\n const rhfContext = useFormContext<\n TFieldValues,\n unknown,\n TTransformedValues\n >();\n\n const config = useRhfUtilsClientConfigMaybeContext();\n\n // handlers\n\n const handleSubmit = async (event: React.FormEvent<HTMLFormElement>) => {\n // cannot stop propagation in handleSubmitValid, b/c it receives a different event object\n if (utils?.stopSubmitPropagation) event.stopPropagation();\n\n try {\n await rhfContext.handleSubmit(handleSubmitValid, onSubmitInvalid)(event);\n } catch (error) {\n handleSubmitError(error, event);\n }\n };\n\n const handleSubmitValid = ((\n data: TTransformedValues,\n event?: React.BaseSyntheticEvent,\n ) => {\n return onSubmit?.(\n data,\n {\n formId,\n formRef,\n context: rhfContext,\n utils,\n FormSubmitError: FormSubmitError<TFieldValues>,\n } satisfies UseRhfUtilsFormOnSubmitContext<\n TFieldValues,\n TTransformedValues\n >,\n event as React.BaseSyntheticEvent<SubmitEvent>, // `as` required due to conditional generic\n );\n }) as Parameters<UseFormHandleSubmit<TFieldValues, TTransformedValues>>[0];\n\n const handleSubmitError = (\n error: unknown,\n event: React.BaseSyntheticEvent,\n ) => {\n // get `FormSubmitErrors`, if possible\n const formSubmitErrors =\n error instanceof FormSubmitError\n ? // consumer can manually throw FormSubmitError (e.g., manual validation)\n (error as FormSubmitError).errors // `as` to avoid `<any>`\n : // if error is not FormSubmitError, consumer can provide global handler\n config?.onSubmitErrorUnknown?.(error);\n\n if (formSubmitErrors)\n setCtxErrorsByFormSubmitErrors(rhfContext, formSubmitErrors);\n\n onSubmitError?.(\n error,\n {\n formId,\n formRef,\n context: rhfContext,\n utils,\n } satisfies UseRhfUtilsFormOnSubmitErrorContext<\n TFieldValues,\n TTransformedValues\n >,\n event as React.BaseSyntheticEvent<SubmitEvent>, // `as` required due to conditional generic\n );\n };\n\n const childrenProps: UseRhfUtilsFormChildrenProps<\n TFieldValues,\n TTransformedValues\n > = {\n formId,\n formRef,\n context: rhfContext,\n utils,\n Controller: _Controller<TFieldValues>,\n FormSubmitError: FormSubmitError<TFieldValues>,\n };\n\n // children wrapper is not specific to schema (not possible)\n const childrenWrapperProps =\n childrenProps as RhfUtilsFormChildrenWrapperProps;\n\n const FormComponent = config?.FormComponent ?? 'form';\n\n const FormChildrenWrapper =\n config?.FormChildrenWrapper ?? PassthroughChildren;\n\n return (\n <FormComponent\n {...form}\n ref={formRef}\n onSubmit={(e) => void handleSubmit(e)}\n >\n <FormChildrenWrapper {...childrenWrapperProps}>\n {utils?.devTool && (\n <LazyDevTool\n props={\n typeof utils.devTool === 'object' ? utils.devTool : undefined\n }\n />\n )}\n\n <Children {...childrenProps} />\n </FormChildrenWrapper>\n </FormComponent>\n );\n}\n\nexport default _Form;\n"],"names":["_Form","formId","formRef","onSubmit","onSubmitError","onSubmitInvalid","Children","form","utils","rhfContext","useFormContext","config","useRhfUtilsClientConfigMaybeContext","handleSubmit","event","handleSubmitValid","error","handleSubmitError","data","FormSubmitError","formSubmitErrors","_a","setCtxErrorsByFormSubmitErrors","childrenProps","_Controller","childrenWrapperProps","FormComponent","FormChildrenWrapper","PassthroughChildren","jsx","e","jsxs","LazyDevTool"],"mappings":";;;;;;;;;AA2CA,SAASA,EAGP;AAAA,EACA,QAAAC;AAAA,EACA,SAAAC;AAAA;AAAA,EAEA,UAAAC;AAAA,EACA,eAAAC;AAAA,EACA,iBAAAC;AAAA,EACA,UAAAC;AAAA;AAAA,EAEA,MAAAC;AAAA,EACA,OAAAC;AACF,GAAgD;AAC9C,QAAMC,IAAaC,KAMbC,IAASC,KAITC,IAAe,OAAOC,MAA4C;AAElE,IAAAN,KAAA,QAAAA,EAAO,yBAAuBM,EAAM,gBAAgB;AAEpD,QAAA;AACF,YAAML,EAAW,aAAaM,GAAmBV,CAAe,EAAES,CAAK;AAAA,aAChEE,GAAO;AACd,MAAAC,EAAkBD,GAAOF,CAAK;AAAA,IAChC;AAAA,EAAA,GAGIC,IAAqB,CACzBG,GACAJ,MAEOX,KAAA,gBAAAA;AAAA,IACLe;AAAA,IACA;AAAA,MACE,QAAAjB;AAAA,MACA,SAAAC;AAAA,MACA,SAASO;AAAA,MACT,OAAAD;AAAA,MACA,iBAAAW;AAAA,IACF;AAAA,IAIAL;AAAA,KAIEG,IAAoB,CACxBD,GACAF,MACG;;AAEH,UAAMM,IACJJ,aAAiBG;AAAA;AAAA,MAEZH,EAA0B;AAAA;AAAA;AAAA,OAE3BK,IAAAV,KAAA,gBAAAA,EAAQ,yBAAR,gBAAAU,EAAA,KAAAV,GAA+BK;AAAA;AAEjC,IAAAI,KACFE,EAA+Bb,GAAYW,CAAgB,GAE7DhB,KAAA,QAAAA;AAAA,MACEY;AAAA,MACA;AAAA,QACE,QAAAf;AAAA,QACA,SAAAC;AAAA,QACA,SAASO;AAAA,QACT,OAAAD;AAAA,MACF;AAAA,MAIAM;AAAA;AAAA,EACF,GAGIS,IAGF;AAAA,IACF,QAAAtB;AAAA,IACA,SAAAC;AAAA,IACA,SAASO;AAAA,IACT,OAAAD;AAAA,IACA,YAAYgB;AAAA,IACZ,iBAAAL;AAAA,EAAA,GAIIM,IACJF,GAEIG,KAAgBf,KAAA,gBAAAA,EAAQ,kBAAiB,QAEzCgB,KACJhB,KAAA,gBAAAA,EAAQ,wBAAuBiB;AAG/B,SAAA,gBAAAC;AAAA,IAACH;AAAA,IAAA;AAAA,MACE,GAAGnB;AAAA,MACJ,KAAKL;AAAA,MACL,UAAU,CAAC4B,MAAM,KAAKjB,EAAaiB,CAAC;AAAA,MAEpC,UAAA,gBAAAC,EAACJ,GAAqB,EAAA,GAAGF,GACtB,UAAA;AAAA,SAAAjB,KAAA,gBAAAA,EAAO,YACN,gBAAAqB;AAAA,UAACG;AAAA,UAAA;AAAA,YACC,OACE,OAAOxB,EAAM,WAAY,WAAWA,EAAM,UAAU;AAAA,UAAA;AAAA,QAExD;AAAA,QAGF,gBAAAqB,EAACvB,GAAU,EAAA,GAAGiB,GAAe;AAAA,MAAA,GAC/B;AAAA,IAAA;AAAA,EAAA;AAGN;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"FormWithProviders.mjs","sources":["../../../src/form/FormWithProviders.tsx"],"sourcesContent":["import Form from './Form';\nimport RhfUtilsFormProviders from './RhfUtilsFormProviders';\nimport type { SafeFieldValues } from './SafeFieldValues';\nimport useRhfUtilsForm from './useRhfUtilsForm';\nimport type { UseRhfUtilsFormProps } from './UseRhfUtilsFormProps';\n\nexport type FormWithProvidersProps<\n TFieldValues extends SafeFieldValues,\n TTransformedValues extends SafeFieldValues,\n> = React.PropsWithChildren<\n UseRhfUtilsFormProps<TFieldValues, TTransformedValues>\n>;\n\n/**\n * Form providers (with utils) with immediate descendent {@link Form}.\n * (Syntactic sugar for {@link useRhfUtilsForm}. Use this for most applications.)\n *\n * Use {@link useRhfUtilsForm} if you need to specific nesting hierarchy.\n * (e.g., wrapping `<tr>` with provider and nesting `<form>` within `<td>` to appease HTML rules.)\n */\nfunction FormWithProviders<\n TFieldValues extends SafeFieldValues,\n TTransformedValues extends SafeFieldValues,\n>(props: FormWithProvidersProps<TFieldValues, TTransformedValues>) {\n const form = useRhfUtilsForm(props);\n\n return (\n <RhfUtilsFormProviders {...form.providerProps}>\n <Form {...form.formProps} />\n </RhfUtilsFormProviders>\n );\n}\n\nexport default FormWithProviders;\n"],"names":["FormWithProviders","props","form","useRhfUtilsForm","jsx","RhfUtilsFormProviders","Form"],"mappings":";;;;AAoBA,SAASA,EAGPC,GAAiE;AAC3D,QAAAC,IAAOC,EAAgBF,CAAK;AAGhC,SAAA,gBAAAG,EAACC,GAAuB,EAAA,GAAGH,EAAK,eAC9B,4BAACI,GAAM,EAAA,GAAGJ,EAAK,UAAW,CAAA,EAC5B,CAAA;AAEJ;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"RhfUtilsFormProviders.mjs","sources":["../../../src/form/RhfUtilsFormProviders.tsx"],"sourcesContent":["import type { UseFormReturn } from 'react-hook-form';\nimport { FormProvider } from 'react-hook-form';\n\nimport FlatFieldErrorsContextProvider from '@/errors/flat/context/FlatFieldErrorsContextProvider';\n\nimport RhfUtilsContextProvider from './context/utils/RhfUtilsContextProvider';\nimport type { RhfUtilsFormOptions } from './RhfUtilsFormOptions';\nimport type { SafeFieldValues } from './SafeFieldValues';\n\nexport type RhfUtilsFormProvidersProps<\n TFieldValues extends SafeFieldValues,\n TTransformedValues extends SafeFieldValues,\n> = React.PropsWithChildren<{\n formId: string;\n formRef: React.RefObject<HTMLFormElement>;\n rhfForm: UseFormReturn<TFieldValues, unknown, TTransformedValues>;\n utils?: RhfUtilsFormOptions;\n}>;\n\nfunction RhfUtilsFormProviders<\n TFieldValues extends SafeFieldValues,\n TTransformedValues extends SafeFieldValues,\n>({\n formId,\n formRef,\n rhfForm,\n utils,\n children,\n}: RhfUtilsFormProvidersProps<TFieldValues, TTransformedValues>) {\n return (\n <FormProvider {...rhfForm}>\n <FlatFieldErrorsContextProvider formRef={formRef}>\n <RhfUtilsContextProvider\n formId={formId}\n formRef={formRef}\n options={utils}\n >\n {children}\n </RhfUtilsContextProvider>\n </FlatFieldErrorsContextProvider>\n </FormProvider>\n );\n}\n\nexport default RhfUtilsFormProviders;\n"],"names":["RhfUtilsFormProviders","formId","formRef","rhfForm","utils","children","FormProvider","jsx","FlatFieldErrorsContextProvider","RhfUtilsContextProvider"],"mappings":";;;;AAmBA,SAASA,EAGP;AAAA,EACA,QAAAC;AAAA,EACA,SAAAC;AAAA,EACA,SAAAC;AAAA,EACA,OAAAC;AAAA,EACA,UAAAC;AACF,GAAiE;AAC/D,2BACGC,GAAc,EAAA,GAAGH,GAChB,UAAA,gBAAAI,EAACC,KAA+B,SAAAN,GAC9B,UAAA,gBAAAK;AAAA,IAACE;AAAA,IAAA;AAAA,MACC,QAAAR;AAAA,MACA,SAAAC;AAAA,MACA,SAASE;AAAA,MAER,UAAAC;AAAA,IAAA;AAAA,EAAA,EAEL,CAAA,EACF,CAAA;AAEJ;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"_Controller.mjs","sources":["../../../src/form/_Controller.tsx"],"sourcesContent":["import type { ControllerProps, FieldPath } from 'react-hook-form';\nimport { Controller as RhfController } from 'react-hook-form';\n\nimport type { SafeFieldValues } from './SafeFieldValues';\n\nexport type _ControllerProps<\n TFieldValues extends SafeFieldValues,\n TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>,\n> = Omit<ControllerProps<TFieldValues, TName>, 'control'>;\n\nfunction _Controller<\n TFieldValues extends SafeFieldValues,\n TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>,\n>(props: _ControllerProps<TFieldValues, TName>) {\n return <RhfController {...props} />;\n}\n\nexport default _Controller;\n"],"names":["_Controller","props","jsx","RhfController"],"mappings":";;AAUA,SAASA,EAGPC,GAA8C;AACvC,SAAA,gBAAAC,EAACC,GAAe,EAAA,GAAGF,EAAO,CAAA;AACnC;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"FormGroupContextProvider.mjs","sources":["../../../../../src/form/context/group/FormGroupContextProvider.tsx"],"sourcesContent":["import React from 'react';\n\nimport { _FormGroupContextProvider } from '.';\n\ntype Props = React.PropsWithChildren;\n\nconst FormGroupContextProvider: React.FC<Props> = ({ children }) => {\n // children\n\n const [childrenBusyIds, setChildrenBusyIds] = React.useState<string[]>([]);\n\n const childrenBusyCount = childrenBusyIds.length;\n\n const setChildrenBusyId = React.useCallback((id: string, isBusy: boolean) => {\n setChildrenBusyIds((prev) =>\n isBusy\n ? // add to array\n [...prev, id]\n : // remove from array\n prev.filter((formId) => formId !== id),\n );\n }, []);\n\n // parent\n\n const [isParentBusy, setIsParentBusy] = React.useState(false);\n\n // value\n\n const value = {\n children: {\n busyCount: childrenBusyCount,\n busyIds: childrenBusyIds,\n setBusyId: setChildrenBusyId,\n },\n parent: {\n isBusy: isParentBusy,\n setIsBusy: setIsParentBusy,\n },\n };\n\n return (\n <_FormGroupContextProvider value={value}>\n {children}\n </_FormGroupContextProvider>\n );\n};\n\nexport default FormGroupContextProvider;\n"],"names":["FormGroupContextProvider","children","childrenBusyIds","setChildrenBusyIds","React","childrenBusyCount","setChildrenBusyId","id","isBusy","prev","formId","isParentBusy","setIsParentBusy","jsx","_FormGroupContextProvider","FormGroupContextProvider$1"],"mappings":";;;AAMA,MAAMA,IAA4C,CAAC,EAAE,UAAAC,QAAe;AAGlE,QAAM,CAACC,GAAiBC,CAAkB,IAAIC,EAAM,SAAmB,CAAA,CAAE,GAEnEC,IAAoBH,EAAgB,QAEpCI,IAAoBF,EAAM,YAAY,CAACG,GAAYC,MAAoB;AAC3E,IAAAL;AAAA,MAAmB,CAACM,MAClBD;AAAA;AAAA,QAEI,CAAC,GAAGC,GAAMF,CAAE;AAAA;AAAA;AAAA,QAEZE,EAAK,OAAO,CAACC,MAAWA,MAAWH,CAAE;AAAA;AAAA,IAAA;AAAA,EAE7C,GAAG,CAAE,CAAA,GAIC,CAACI,GAAcC,CAAe,IAAIR,EAAM,SAAS,EAAK;AAiB1D,SAAA,gBAAAS,EAACC,GAA0B,EAAA,OAbf;AAAA,IACZ,UAAU;AAAA,MACR,WAAWT;AAAA,MACX,SAASH;AAAA,MACT,WAAWI;AAAA,IACb;AAAA,IACA,QAAQ;AAAA,MACN,QAAQK;AAAA,MACR,WAAWC;AAAA,IACb;AAAA,EAAA,GAKG,UAAAX,EACH,CAAA;AAEJ,GAEAc,IAAef;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sources":["../../../../../src/form/context/group/index.ts"],"sourcesContent":["import createContext from '@/utils/createContext';\n\nexport type FormGroupContext = {\n /** Dependent forms. */\n children: {\n busyIds: string[];\n busyCount: number;\n setBusyId: (id: string, isBusy: boolean) => void;\n };\n /** Main form. */\n parent: {\n isBusy: boolean;\n setIsBusy: (isBusy: boolean) => void;\n };\n};\n\nexport const {\n Provider: _FormGroupContextProvider,\n useRequired: _useFormGroupContext,\n useMaybe: _useFormGroupContextMaybe,\n} = createContext<FormGroupContext>();\n"],"names":["_FormGroupContextProvider","_useFormGroupContext","_useFormGroupContextMaybe","createContext"],"mappings":";AAgBa,MAAA;AAAA,EACX,UAAUA;AAAA,EACV,aAAaC;AAAA,EACb,UAAUC;AACZ,IAAIC,EAAgC;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useFormGroupChildIsMountedTracker.mjs","sources":["../../../../../src/form/context/group/useFormGroupChildIsMountedTracker.ts"],"sourcesContent":["import useFormGroupChildTracker from './useFormGroupChildTracker';\nimport useFormGroupIsParentBusy from './useFormGroupIsParentBusy';\n\n/**\n * Mark \"child\" form as \"busy\" when mounted.\n */\nconst useFormGroupChildIsMountedTracker = () => {\n useFormGroupChildTracker(true);\n\n // return parent status\n return useFormGroupIsParentBusy();\n};\n\nexport default useFormGroupChildIsMountedTracker;\n"],"names":["useFormGroupChildIsMountedTracker","useFormGroupChildTracker","useFormGroupIsParentBusy","useFormGroupChildIsMountedTracker$1"],"mappings":";;AAMA,MAAMA,IAAoC,OACxCC,EAAyB,EAAI,GAGtBC,EAAyB,IAGlCC,IAAeH;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useFormGroupChildIsSubmittingTracker.mjs","sources":["../../../../../src/form/context/group/useFormGroupChildIsSubmittingTracker.ts"],"sourcesContent":["import { useFormState } from 'react-hook-form';\n\nimport useFormGroupChildTracker from './useFormGroupChildTracker';\nimport useFormGroupIsParentBusy from './useFormGroupIsParentBusy';\n\n/**\n * Mark \"child\" form as \"busy\" when submitting.\n */\nconst useFormGroupChildIsSubmittingTracker = () => {\n const { isSubmitting } = useFormState();\n\n useFormGroupChildTracker(isSubmitting);\n\n // return parent status\n return useFormGroupIsParentBusy();\n};\n\nexport default useFormGroupChildIsSubmittingTracker;\n"],"names":["useFormGroupChildIsSubmittingTracker","isSubmitting","useFormState","useFormGroupChildTracker","useFormGroupIsParentBusy","useFormGroupChildIsSubmittingTracker$1"],"mappings":";;;AAQA,MAAMA,IAAuC,MAAM;AAC3C,QAAA,EAAE,cAAAC,MAAiBC;AAEzB,SAAAC,EAAyBF,CAAY,GAG9BG,EAAyB;AAClC,GAEAC,IAAeL;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useFormGroupChildTracker.mjs","sources":["../../../../../src/form/context/group/useFormGroupChildTracker.ts"],"sourcesContent":["import React from 'react';\n\nimport { _useFormGroupContext } from '.';\n\n/**\n * Mark \"child\" form as \"busy\" via arbitrary boolean.\n * Automatically marks as \"not busy\" on dismount.\n */\nconst useFormGroupChildTracker = (track: boolean) => {\n const { setBusyId } = _useFormGroupContext().children;\n\n // generate unique id to track this form instance\n const id = React.useId();\n\n // update context state based on isSubmitting\n React.useEffect(() => {\n setBusyId(id, track);\n }, [track, id, setBusyId]);\n\n // on dismount, set form as not busy\n // (e.g., form hides after successful submission; useEffect above will not re-run before unmount)\n React.useEffect(() => {\n return () => {\n setBusyId(id, false);\n };\n }, []); // eslint-disable-line react-hooks/exhaustive-deps\n};\n\nexport default useFormGroupChildTracker;\n"],"names":["useFormGroupChildTracker","track","setBusyId","_useFormGroupContext","id","React","useFormGroupChildTracker$1"],"mappings":";;AAQA,MAAMA,IAA2B,CAACC,MAAmB;AACnD,QAAM,EAAE,WAAAC,EAAA,IAAcC,EAAA,EAAuB,UAGvCC,IAAKC,EAAM;AAGjB,EAAAA,EAAM,UAAU,MAAM;AACpB,IAAAH,EAAUE,GAAIH,CAAK;AAAA,EAClB,GAAA,CAACA,GAAOG,GAAIF,CAAS,CAAC,GAIzBG,EAAM,UAAU,MACP,MAAM;AACX,IAAAH,EAAUE,GAAI,EAAK;AAAA,EAAA,GAEpB,CAAE,CAAA;AACP,GAEAE,IAAeN;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useFormGroupIsAnyBusy.mjs","sources":["../../../../../src/form/context/group/useFormGroupIsAnyBusy.ts"],"sourcesContent":["import { _useFormGroupContextMaybe } from '.';\n\nconst useFormGroupIsAnyBusy = (): boolean => {\n const ctx = _useFormGroupContextMaybe();\n\n return !!ctx?.children.busyCount || !!ctx?.parent.isBusy;\n};\n\nexport default useFormGroupIsAnyBusy;\n"],"names":["useFormGroupIsAnyBusy","ctx","_useFormGroupContextMaybe","useFormGroupIsAnyBusy$1"],"mappings":";AAEA,MAAMA,IAAwB,MAAe;AAC3C,QAAMC,IAAMC;AAEL,SAAA,CAAC,EAACD,KAAA,QAAAA,EAAK,SAAS,cAAa,CAAC,EAACA,KAAA,QAAAA,EAAK,OAAO;AACpD,GAEAE,IAAeH;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useFormGroupIsChildBusy.mjs","sources":["../../../../../src/form/context/group/useFormGroupIsChildBusy.ts"],"sourcesContent":["import { _useFormGroupContextMaybe } from '.';\n\nconst useFormGroupIsChildBusy = (): boolean => {\n const ctx = _useFormGroupContextMaybe();\n\n return !!ctx?.children.busyCount;\n};\n\nexport default useFormGroupIsChildBusy;\n"],"names":["useFormGroupIsChildBusy","ctx","_useFormGroupContextMaybe","useFormGroupIsChildBusy$1"],"mappings":";AAEA,MAAMA,IAA0B,MAAe;AAC7C,QAAMC,IAAMC;AAEL,SAAA,CAAC,EAACD,KAAA,QAAAA,EAAK,SAAS;AACzB,GAEAE,IAAeH;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useFormGroupIsParentBusy.mjs","sources":["../../../../../src/form/context/group/useFormGroupIsParentBusy.ts"],"sourcesContent":["import { _useFormGroupContextMaybe } from '.';\n\nconst useFormGroupIsParentBusy = (): boolean => {\n const ctx = _useFormGroupContextMaybe();\n\n return !!ctx?.parent.isBusy;\n};\n\nexport default useFormGroupIsParentBusy;\n"],"names":["useFormGroupIsParentBusy","ctx","_useFormGroupContextMaybe"],"mappings":";AAEA,MAAMA,IAA2B,MAAe;AAC9C,QAAMC,IAAMC;AAEL,SAAA,CAAC,EAACD,KAAA,QAAAA,EAAK,OAAO;AACvB;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useFormGroupParentTracker.mjs","sources":["../../../../../src/form/context/group/useFormGroupParentTracker.ts"],"sourcesContent":["import React from 'react';\n\nimport useFormIsBusy from '@/form/useFormIsBusy';\n\nimport { _useFormGroupContext } from '.';\nimport useFormGroupIsChildBusy from './useFormGroupIsChildBusy';\n\n/**\n * Connect specific form state as parent context.\n *\n * Requires usage of provider.\n */\nconst useFormGroupParentTracker = () => {\n const isBusy = useFormIsBusy();\n\n const { setIsBusy } = _useFormGroupContext().parent;\n\n // when this form state changes, update context state\n React.useEffect(() => {\n setIsBusy(isBusy);\n }, [setIsBusy, isBusy]);\n\n // return children status\n return useFormGroupIsChildBusy();\n};\n\nexport default useFormGroupParentTracker;\n"],"names":["useFormGroupParentTracker","isBusy","useFormIsBusy","setIsBusy","_useFormGroupContext","React","useFormGroupIsChildBusy","useFormGroupParentTracker$1"],"mappings":";;;;AAYA,MAAMA,IAA4B,MAAM;AACtC,QAAMC,IAASC,KAET,EAAE,WAAAC,EAAA,IAAcC,EAAA,EAAuB;AAG7C,SAAAC,EAAM,UAAU,MAAM;AACpB,IAAAF,EAAUF,CAAM;AAAA,EAAA,GACf,CAACE,GAAWF,CAAM,CAAC,GAGfK,EAAwB;AACjC,GAEAC,IAAeP;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useFormOrParentIsBusy.mjs","sources":["../../../../../src/form/context/group/useFormOrParentIsBusy.ts"],"sourcesContent":["import useFormIsBusy from '../../useFormIsBusy';\n\nimport { _useFormGroupContextMaybe } from '.';\n\nconst useFormOrParentIsBusy = (): boolean => {\n const isFormBusy = useFormIsBusy();\n const isParentBusy = _useFormGroupContextMaybe()?.parent.isBusy;\n\n return Boolean(isFormBusy || isParentBusy);\n};\n\nexport default useFormOrParentIsBusy;\n"],"names":["useFormOrParentIsBusy","isFormBusy","useFormIsBusy","isParentBusy","_a","_useFormGroupContextMaybe","useFormOrParentIsBusy$1"],"mappings":";;AAIA,MAAMA,IAAwB,MAAe;;AAC3C,QAAMC,IAAaC,KACbC,KAAeC,IAAAC,QAAA,gBAAAD,EAA6B,OAAO;AAElD,SAAA,GAAQH,KAAcE;AAC/B,GAEAG,IAAeN;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"RhfUtilsContextProvider.mjs","sources":["../../../../../src/form/context/utils/RhfUtilsContextProvider.tsx"],"sourcesContent":["import useRhfUtilsClientConfigMaybeContext from '@/client/config/useRhfUtilsClientConfigContext';\n\nimport useFlatFieldErrorsContextOutput from '@/errors/flat/context/useFlatFieldErrorsContextOutput';\n\nimport type { RhfUtilsFormOptions } from '@/form/RhfUtilsFormOptions';\n\nimport useResetFormOnSubmitted from '@/submit/useResetFormOnSubmitted';\nimport useSubmitFormOnChange from '@/submit/useSubmitFormOnChange';\n\nimport { _RhfUtilsContextProvider } from './useRhfUtilsContext';\n\ntype Props = React.PropsWithChildren<{\n formId: string;\n formRef: React.RefObject<HTMLFormElement>;\n options?: RhfUtilsFormOptions;\n}>;\n\nconst RhfUtilsContextProvider: React.FC<Props> = ({\n formId,\n formRef,\n options,\n children,\n}) => {\n const config = useRhfUtilsClientConfigMaybeContext();\n\n useFlatFieldErrorsContextOutput(config?.FieldErrors?.output);\n\n useSubmitFormOnChange(formRef, {\n disabled: !options?.submitOnChange,\n });\n\n useResetFormOnSubmitted(options?.resetOnSubmitted);\n\n return (\n <_RhfUtilsContextProvider value={{ formId, formRef, options }}>\n {children}\n </_RhfUtilsContextProvider>\n );\n};\n\nexport default RhfUtilsContextProvider;\n"],"names":["RhfUtilsContextProvider","formId","formRef","options","children","config","useRhfUtilsClientConfigMaybeContext","useFlatFieldErrorsContextOutput","_a","useSubmitFormOnChange","useResetFormOnSubmitted","jsx","_RhfUtilsContextProvider"],"mappings":";;;;;;AAiBA,MAAMA,IAA2C,CAAC;AAAA,EAChD,QAAAC;AAAA,EACA,SAAAC;AAAA,EACA,SAAAC;AAAA,EACA,UAAAC;AACF,MAAM;;AACJ,QAAMC,IAASC;AAEiB,SAAAC,GAAAC,IAAAH,KAAA,gBAAAA,EAAQ,gBAAR,gBAAAG,EAAqB,MAAM,GAE3DC,EAAsBP,GAAS;AAAA,IAC7B,UAAU,EAACC,KAAA,QAAAA,EAAS;AAAA,EAAA,CACrB,GAEDO,EAAwBP,KAAA,gBAAAA,EAAS,gBAAgB,GAG/C,gBAAAQ,EAACC,KAAyB,OAAO,EAAE,QAAAX,GAAQ,SAAAC,GAAS,SAAAC,EAAA,GACjD,UAAAC,EACH,CAAA;AAEJ;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useRhfUtilsContext.mjs","sources":["../../../../../src/form/context/utils/useRhfUtilsContext.tsx"],"sourcesContent":["import type { RhfUtilsFormOptions } from '@/form/RhfUtilsFormOptions';\n\nimport createContext from '@/utils/createContext';\n\nexport type RhfUtilsContext = {\n formId: string;\n formRef: React.RefObject<HTMLFormElement>;\n options: RhfUtilsFormOptions | undefined;\n};\n\nconst { Provider: _RhfUtilsContextProvider, useRequired: _useRhfUtilsContext } =\n createContext<RhfUtilsContext>();\n\n/**\n * Use utils from the current form context.\n */\nconst useRhfUtilsContext = _useRhfUtilsContext;\n\nexport default useRhfUtilsContext;\n\nexport { _RhfUtilsContextProvider };\n"],"names":["_RhfUtilsContextProvider","_useRhfUtilsContext","createContext","useRhfUtilsContext","useRhfUtilsContext$1"],"mappings":";AAUA,MAAM,EAAE,UAAUA,GAA0B,aAAaC,EAAA,IACvDC,EAA+B,GAK3BC,IAAqBF,GAE3BG,IAAeD;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useRhfUtilsContextRequestSubmit.mjs","sources":["../../../../../src/form/context/utils/useRhfUtilsContextRequestSubmit.ts"],"sourcesContent":["import useFormRequestSubmit from '@/form/utils/useFormRequestSubmit';\n\nimport useRhfUtilsContext from './useRhfUtilsContext';\n\n/**\n * Get `requestSubmit` function from the form ref'd in current context.\n */\nconst useRhfUtilsContextRequestSubmit = () => {\n const utils = useRhfUtilsContext();\n\n return useFormRequestSubmit(utils.formRef);\n};\n\nexport default useRhfUtilsContextRequestSubmit;\n"],"names":["useRhfUtilsContextRequestSubmit","utils","useRhfUtilsContext","useFormRequestSubmit","useRhfUtilsContextRequestSubmit$1"],"mappings":";;AAOA,MAAMA,IAAkC,MAAM;AAC5C,QAAMC,IAAQC;AAEP,SAAAC,EAAqBF,EAAM,OAAO;AAC3C,GAEAG,IAAeJ;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useFormIsBusy.mjs","sources":["../../../src/form/useFormIsBusy.ts"],"sourcesContent":["import { useFormState } from 'react-hook-form';\n\nconst useFormIsBusy = (): boolean => {\n const { isSubmitting, isLoading } = useFormState();\n\n return isSubmitting || isLoading;\n};\n\nexport default useFormIsBusy;\n"],"names":["useFormIsBusy","isSubmitting","isLoading","useFormState"],"mappings":";AAEA,MAAMA,IAAgB,MAAe;AACnC,QAAM,EAAE,cAAAC,GAAc,WAAAC,EAAU,IAAIC,EAAa;AAEjD,SAAOF,KAAgBC;AACzB;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useRhfUtilsForm.mjs","sources":["../../../src/form/useRhfUtilsForm.tsx"],"sourcesContent":["import React from 'react';\nimport { useForm as useRhfForm } from 'react-hook-form';\n\nimport { FormSubmitError } from '@/submit/error/FormSubmitError';\n\nimport type { FormProps } from './Form';\nimport type { RhfUtilsFormProvidersProps } from './RhfUtilsFormProviders';\nimport type { SafeFieldValues } from './SafeFieldValues';\nimport type { UseRhfUtilsFormProps } from './UseRhfUtilsFormProps';\nimport type { UseRhfUtilsFormReturn } from './UseRhfUtilsFormReturn';\n\n/**\n * Core Rhf Form hook. Use `Form` in `index.ts` for most cases.\n * Use this if you need to separate form components.\n * e.g., a form for table row due to `form` being considered invalid HTML around `tr` tags.\n * With this hook, you can wrap the `tr` tag with `form.Provider` and use `form.Form` inside\n * one of the cells. Other components can be outside form while referring to form by its id via `form` attribute.\n * see https://caniuse.com/?search=form%20attribute\n * @returns Form provider and form.\n */\nconst useRhfUtilsForm = <\n TFieldValues extends SafeFieldValues,\n TTransformedValues extends SafeFieldValues,\n>({\n defaultValues,\n onSubmit,\n onSubmitError,\n onSubmitInvalid,\n Children,\n rhf,\n form,\n utils,\n}: UseRhfUtilsFormProps<\n TFieldValues,\n TTransformedValues\n>): UseRhfUtilsFormReturn<TFieldValues, TTransformedValues> => {\n const formId = React.useId();\n\n const rhfForm = useRhfForm<TFieldValues, unknown, TTransformedValues>({\n ...rhf,\n defaultValues,\n });\n\n const formRef = React.useRef<HTMLFormElement>(null);\n\n const providerProps: RhfUtilsFormProvidersProps<\n TFieldValues,\n TTransformedValues\n > = {\n formId,\n formRef,\n rhfForm,\n utils,\n };\n\n const formProps: FormProps<TFieldValues, TTransformedValues> = {\n Children,\n onSubmit,\n onSubmitError,\n onSubmitInvalid,\n formId,\n formRef,\n form,\n utils,\n };\n\n return {\n id: formId,\n ref: formRef,\n context: rhfForm,\n providerProps,\n formProps,\n FormSubmitError: FormSubmitError<TFieldValues>,\n } as const;\n};\n\nexport default useRhfUtilsForm;\n\nexport type UseRhfUtilsForm<\n TFieldValues extends SafeFieldValues,\n TTransformedValues extends SafeFieldValues,\n> = typeof useRhfUtilsForm<TFieldValues, TTransformedValues>;\n"],"names":["useRhfUtilsForm","defaultValues","onSubmit","onSubmitError","onSubmitInvalid","Children","rhf","form","utils","formId","React","rhfForm","useRhfForm","formRef","FormSubmitError"],"mappings":";;;AAoBA,MAAMA,IAAkB,CAGtB;AAAA,EACA,eAAAC;AAAA,EACA,UAAAC;AAAA,EACA,eAAAC;AAAA,EACA,iBAAAC;AAAA,EACA,UAAAC;AAAA,EACA,KAAAC;AAAA,EACA,MAAAC;AAAA,EACA,OAAAC;AACF,MAG+D;AACvD,QAAAC,IAASC,EAAM,SAEfC,IAAUC,EAAsD;AAAA,IACpE,GAAGN;AAAA,IACH,eAAAL;AAAA,EAAA,CACD,GAEKY,IAAUH,EAAM,OAAwB,IAAI;AAuB3C,SAAA;AAAA,IACL,IAAID;AAAA,IACJ,KAAKI;AAAA,IACL,SAASF;AAAA,IACT,eAtBE;AAAA,MACF,QAAAF;AAAA,MACA,SAAAI;AAAA,MACA,SAAAF;AAAA,MACA,OAAAH;AAAA,IAAA;AAAA,IAmBA,WAhB6D;AAAA,MAC7D,UAAAH;AAAA,MACA,UAAAH;AAAA,MACA,eAAAC;AAAA,MACA,iBAAAC;AAAA,MACA,QAAAK;AAAA,MACA,SAAAI;AAAA,MACA,MAAAN;AAAA,MACA,OAAAC;AAAA,IAAA;AAAA,IASA,iBAAAM;AAAA,EAAA;AAEJ;"}
|