@paragrav/rhf-utils 0.75.0 → 0.77.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/tsdown/{FormRelaySetter-CLkDwgfH.js → FormRelaySetter-BNson1Za.js} +31 -28
- package/dist/tsdown/{FormRelaySetter-CLkDwgfH.js.map → FormRelaySetter-BNson1Za.js.map} +1 -1
- package/dist/tsdown/index.d.ts +11 -11
- package/dist/tsdown/index.d.ts.map +1 -1
- package/dist/tsdown/index.js +24 -16
- package/dist/tsdown/index.js.map +1 -1
- package/dist/tsdown/relay.d.ts +7 -7
- package/dist/tsdown/relay.d.ts.map +1 -1
- package/dist/tsdown/relay.js +7 -3
- package/dist/tsdown/relay.js.map +1 -1
- package/dist/tsdown/trpc.d.ts +2 -3
- package/dist/tsdown/trpc.d.ts.map +1 -1
- package/package.json +18 -18
|
@@ -28,35 +28,38 @@ const { Provider: _FormRelayContextProvider, useRequired: useFormRelayContext }
|
|
|
28
28
|
//#region src/form/relay/context/FormRelayContextProvider.tsx
|
|
29
29
|
const FormRelayContextProvider = ({ children }) => {
|
|
30
30
|
const [state, setState] = React.useState({});
|
|
31
|
+
const add = React.useCallback((formState, utils, options) => {
|
|
32
|
+
if (state[utils.formId]) throw new Error("Form id already exists.");
|
|
33
|
+
setState((forms) => ({
|
|
34
|
+
...forms,
|
|
35
|
+
[utils.formId]: {
|
|
36
|
+
state: formState,
|
|
37
|
+
utils,
|
|
38
|
+
options
|
|
39
|
+
}
|
|
40
|
+
}));
|
|
41
|
+
}, [state]);
|
|
42
|
+
const update = React.useCallback((id, state) => {
|
|
43
|
+
setState((forms) => {
|
|
44
|
+
const current = forms[id];
|
|
45
|
+
if (!current) throw new Error("Form id doesn't exist");
|
|
46
|
+
return {
|
|
47
|
+
...forms,
|
|
48
|
+
[id]: {
|
|
49
|
+
...current,
|
|
50
|
+
state
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
});
|
|
54
|
+
}, []);
|
|
55
|
+
const remove = React.useCallback((id) => {
|
|
56
|
+
setState((forms) => Object.fromEntries(Object.entries(forms).filter(([entryId]) => entryId !== id)));
|
|
57
|
+
}, []);
|
|
31
58
|
return /* @__PURE__ */ jsx(_FormRelayContextProvider, {
|
|
32
59
|
value: {
|
|
33
|
-
add
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
...forms,
|
|
37
|
-
[utils.formId]: {
|
|
38
|
-
state: formState,
|
|
39
|
-
utils,
|
|
40
|
-
options
|
|
41
|
-
}
|
|
42
|
-
}));
|
|
43
|
-
}, [state]),
|
|
44
|
-
update: React.useCallback((id, state) => {
|
|
45
|
-
setState((forms) => {
|
|
46
|
-
const current = forms[id];
|
|
47
|
-
if (!current) throw new Error("Form id doesn't exist");
|
|
48
|
-
return {
|
|
49
|
-
...forms,
|
|
50
|
-
[id]: {
|
|
51
|
-
...current,
|
|
52
|
-
state
|
|
53
|
-
}
|
|
54
|
-
};
|
|
55
|
-
});
|
|
56
|
-
}, []),
|
|
57
|
-
remove: React.useCallback((id) => {
|
|
58
|
-
setState((forms) => Object.fromEntries(Object.entries(forms).filter(([entryId]) => entryId !== id)));
|
|
59
|
-
}, []),
|
|
60
|
+
add,
|
|
61
|
+
update,
|
|
62
|
+
remove,
|
|
60
63
|
state
|
|
61
64
|
},
|
|
62
65
|
children
|
|
@@ -196,4 +199,4 @@ const FormRelaySetter = ({ options }) => {
|
|
|
196
199
|
//#endregion
|
|
197
200
|
export { _RhfUtilsContextProvider as a, FormRelayContextProvider as c, isEmptyObject as i, useFormRelayContext as l, useFormRelaySet as n, useRhfUtilsContext as o, getFlatFieldErrors as r, useRhfUtilsMaybeContext as s, FormRelaySetter as t, createContext as u };
|
|
198
201
|
|
|
199
|
-
//# sourceMappingURL=FormRelaySetter-
|
|
202
|
+
//# sourceMappingURL=FormRelaySetter-BNson1Za.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FormRelaySetter-CLkDwgfH.js","names":[],"sources":["../../src/utils/createContext.ts","../../src/form/relay/context/useFormRelayContext.ts","../../src/form/relay/context/FormRelayContextProvider.tsx","../../src/form/context/utils/useRhfUtilsContext.tsx","../../src/utils/isEmptyObject.ts","../../src/errors/flat/flattenFieldErrors.ts","../../src/errors/flat/getFlatFieldErrors.ts","../../src/form/relay/set/useFormRelaySet.ts","../../src/form/relay/set/FormRelaySetter.tsx"],"sourcesContent":["import React from 'react';\n\n/**\n * Create a strictly-typed context that throws error if no provider is found.\n * @returns A tuple with a function to get the context and the context provider.\n */\nexport function createContext<T = unknown>() {\n const context = React.createContext<T | undefined>(undefined);\n\n const useMaybe = () => React.useContext(context);\n\n const useRequired = () => {\n const c = useMaybe();\n\n // type guard\n if (c === undefined) throw new Error();\n\n return c;\n };\n\n return {\n Provider: context.Provider,\n useMaybe,\n useRequired,\n } as const;\n}\n","import type { RhfUtilsContext } from '@/form/context/utils/RhfUtilsContextType';\n\nimport { createContext } from '@/utils/createContext';\n\nimport type { FormRelayOptions } from '../FormRelayOptions';\nimport type { FormRelay, FormRelayStateSelected } from '../types';\n\nexport type FormsRelayed = Record<\n string, // form id\n FormRelay\n>;\n\nexport type FormRelayContext = {\n // set\n\n add: (\n state: FormRelayStateSelected,\n utils: RhfUtilsContext,\n options: FormRelayOptions,\n ) => void;\n\n update: (id: string, state: FormRelayStateSelected) => void;\n\n remove: (id: string) => void;\n\n // state\n\n state: FormsRelayed;\n};\n\nexport const {\n Provider: _FormRelayContextProvider,\n useRequired: useFormRelayContext,\n} = createContext<FormRelayContext>();\n","import React from 'react';\n\nimport type { RhfUtilsContext } from '@/form/context/utils/RhfUtilsContextType';\n\nimport type { FormRelayOptions } from '../FormRelayOptions';\nimport type { FormRelayStateSelected } from '../types';\n\nimport type { FormsRelayed } from './useFormRelayContext';\nimport { _FormRelayContextProvider } from './useFormRelayContext';\n\ntype Props = React.PropsWithChildren;\n\nexport const FormRelayContextProvider: React.FC<Props> = ({ children }) => {\n // state\n\n const [state, setState] = React.useState<FormsRelayed>({});\n\n // set\n\n const add = React.useCallback(\n (\n formState: FormRelayStateSelected,\n utils: RhfUtilsContext,\n options: FormRelayOptions,\n ) => {\n if (state[utils.formId]) throw new Error('Form id already exists.');\n\n setState((forms) => ({\n ...forms,\n [utils.formId]: { state: formState, utils, options },\n }));\n },\n\n [state],\n );\n\n const update = React.useCallback(\n (id: string, state: FormRelayStateSelected) => {\n setState((forms) => {\n const current = forms[id];\n\n if (!current) throw new Error(\"Form id doesn't exist\");\n\n return {\n ...forms,\n [id]: { ...current, state },\n };\n });\n },\n [],\n );\n\n const remove = React.useCallback((id: string) => {\n setState((forms) =>\n Object.fromEntries(\n Object.entries(forms)\n // keep only other ids\n .filter(([entryId]) => entryId !== id),\n ),\n );\n }, []);\n\n //\n\n return (\n <_FormRelayContextProvider\n value={{\n // set\n\n add,\n update,\n remove,\n\n // get\n\n state,\n }}\n >\n {children}\n </_FormRelayContextProvider>\n );\n};\n","import { createContext } from '@/utils/createContext';\n\nimport type { RhfUtilsContext } from './RhfUtilsContextType';\n\nconst {\n Provider: _RhfUtilsContextProvider,\n useRequired: useRhfUtilsContext,\n useMaybe: useRhfUtilsMaybeContext,\n} = createContext<RhfUtilsContext>();\n\nexport {\n _RhfUtilsContextProvider,\n useRhfUtilsContext,\n useRhfUtilsMaybeContext,\n};\n","export const isEmptyObject = (obj: Record<string, unknown>) =>\n Object.keys(obj).length === 0;\n","import { flatten } from 'flat';\nimport type { FieldErrors } from 'react-hook-form';\n\n/**\n * Flatten a {@link FieldErrors} object.\n *\n * @returns e.g.,\n * ```ts\n * {\n * \"address.street.type\": \"too_short\",\n * \"address.street.ref.value\": \"123\",\n * \"address.street.message\": \"Required.\"\n * }\n * ```\n */\nexport const flattenFieldErrors = (errors: FieldErrors) =>\n flatten<FieldErrors, Record<string, unknown>>(errors);\n","import type { FieldError, FieldErrors } from 'react-hook-form';\nimport { get } from 'react-hook-form';\n\nimport type { SafeFieldValues } from '@/form/rhf/SafeFieldValuesType';\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 */\nexport const 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 (entriesAccumulator, flattenedKey) => {\n /**\n * Maybe path.\n *\n * Derived from flattened key by removing leaf node suffix (if present).\n *\n * @example\n * path: `address.street.message` -> `address.street`\n * @example\n * not path: `address.street.ref` -> `address.street.ref` (no suffix match to replace)\n */\n const maybePath = flattenedKey.replace(\n regexMaybeFieldErrorLeafNodeSuffix,\n '',\n );\n\n // if nothing replaced, then it's not a leaf node; return early\n if (maybePath === flattenedKey) return entriesAccumulator;\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, maybePath, undefined) as\n FieldError | undefined;\n\n // if no field error found, then derived path was wrong; return early\n if (!fieldError) return entriesAccumulator;\n\n /**\n * Add entry to accumulator.\n *\n * (If it's a duplicate (e.g., `.type` leaf node matched before `.message`),\n * it doesn't matter because `Object.fromEntries` will just overwrite\n * first entry with second matching key/value.)\n */\n entriesAccumulator.push([maybePath, fieldError]);\n\n return entriesAccumulator;\n },\n\n [], // entries\n ),\n );\n};\n\n//\n\n/**\n * Regular expression to maybe match the end of a leaf node path.\n *\n * @example\n * - `name.type`\n * - `address.street.message`\n *\n * @description\n *\n * dot [?: non-capturing](\"type\" | \"message\")[\\b word boundary][$ end of string]\n */\nexport const regexMaybeFieldErrorLeafNodeSuffix = /\\.(?:type|message)\\b$/;\n\n//\n\nexport type FieldErrorsSansRef<\n TFieldValues extends SafeFieldValues = SafeFieldValues,\n> = Record<\n keyof TFieldValues | 'root',\n Partial<Pick<FieldError, 'message' | 'type'>> & {\n hasRef: boolean;\n }\n>;\n\nexport const getFlatFieldErrorsSansRef = <TFieldValues extends SafeFieldValues>(\n errors: FieldErrors<TFieldValues>,\n) =>\n Object.fromEntries(\n Object.entries(getFlatFieldErrors(errors)).map(([name, error]) => [\n name,\n {\n type: error.type,\n message: error.message,\n hasRef: !!error.ref, // strip out actual ref, etc. (avoid circular JSON error)\n },\n ]),\n ) as FieldErrorsSansRef<TFieldValues>;\n","import React from 'react';\nimport { useFormState } from 'react-hook-form';\n\nimport { getFlatFieldErrorsSansRef } from '@/errors/flat/getFlatFieldErrors';\n\nimport { useRhfUtilsContext } from '@/form/context/utils/useRhfUtilsContext';\n\nimport { useFormRelayContext } from '../context/useFormRelayContext';\nimport type { FormRelayOptions } from '../FormRelayOptions';\nimport type { FormRelayStateSelected } from '../types';\n\nexport const useFormRelaySet = (options?: FormRelayOptions) => {\n if (!options) return;\n\n // eslint-disable-next-line react-hooks/rules-of-hooks\n const [memoOptions] = React.useState(options);\n\n // eslint-disable-next-line react-hooks/rules-of-hooks\n useFormRelayOnMount(memoOptions);\n // eslint-disable-next-line react-hooks/rules-of-hooks\n useFormRelayOnChange(memoOptions);\n};\n\n// HELPERS\n\n// mount\n\nconst useFormRelayOnMount = (options: FormRelayOptions) => {\n const utils = useRhfUtilsContext();\n const relay = useFormRelayContext();\n const formStateForRelay = useFormStateForRelay(options);\n\n React.useEffect(\n () => {\n relay.add(formStateForRelay, utils, options);\n\n // unmount\n return () => {\n relay.remove(utils.formId);\n };\n },\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [],\n );\n};\n\n// update\n\nconst useFormRelayOnChange = (options: FormRelayOptions) => {\n const utils = useRhfUtilsContext();\n const relay = useFormRelayContext();\n const formStateForRelay = useFormStateForRelay(options);\n\n React.useEffect(\n // when form state changes, publish to relay context\n () => {\n relay.update(utils.formId, formStateForRelay);\n },\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [formStateForRelay],\n );\n};\n\n// relayed form state\n\n/** Transform, memo-ize {@link useFormState}'s return to {@link FormRelayed} */\nconst useFormStateForRelay = (\n options: FormRelayOptions,\n): FormRelayStateSelected => {\n const formState = useFormState();\n\n const formStateSelected = options.select(formState);\n\n const formStateSelectedJson = JSON.stringify({\n ...formStateSelected,\n errors:\n formStateSelected.errors &&\n getFlatFieldErrorsSansRef(formStateSelected.errors),\n });\n\n const memoFormStateSelected = React.useMemo(\n // when watch JSON changes, update memo\n () => formStateSelected,\n\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [formStateSelectedJson],\n );\n\n return memoFormStateSelected;\n};\n","import type { FormRelayOptions } from '../FormRelayOptions';\n\nimport { useFormRelaySet } from './useFormRelaySet';\n\ntype Props = {\n options?: FormRelayOptions;\n};\n\nexport const FormRelaySetter: React.FC<Props> = ({ options }) => {\n useFormRelaySet(options);\n\n return null;\n};\n"],"mappings":";;;;;;;;;AAMA,SAAgB,gBAA6B;CAC3C,MAAM,UAAU,MAAM,cAA6B,KAAA,CAAS;CAE5D,MAAM,iBAAiB,MAAM,WAAW,OAAO;CAE/C,MAAM,oBAAoB;EACxB,MAAM,IAAI,SAAS;EAGnB,IAAI,MAAM,KAAA,GAAW,MAAM,IAAI,MAAM;EAErC,OAAO;CACT;CAEA,OAAO;EACL,UAAU,QAAQ;EAClB;EACA;CACF;AACF;;;ACKA,MAAa,EACX,UAAU,2BACV,aAAa,wBACX,cAAgC;;;ACrBpC,MAAa,4BAA6C,EAAE,eAAe;CAGzE,MAAM,CAAC,OAAO,YAAY,MAAM,SAAuB,CAAC,CAAC;CAiDzD,OACE,oBAAC,2BAAD;EACE,OAAO;GAGL,KAlDM,MAAM,aAE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":"FormRelaySetter-BNson1Za.js","names":[],"sources":["../../src/utils/createContext.ts","../../src/form/relay/context/useFormRelayContext.ts","../../src/form/relay/context/FormRelayContextProvider.tsx","../../src/form/context/utils/useRhfUtilsContext.tsx","../../src/utils/isEmptyObject.ts","../../src/errors/flat/flattenFieldErrors.ts","../../src/errors/flat/getFlatFieldErrors.ts","../../src/form/relay/set/useFormRelaySet.ts","../../src/form/relay/set/FormRelaySetter.tsx"],"sourcesContent":["import React from 'react';\n\n/**\n * Create a strictly-typed context that throws error if no provider is found.\n * @returns A tuple with a function to get the context and the context provider.\n */\nexport function createContext<T = unknown>() {\n const context = React.createContext<T | undefined>(undefined);\n\n const useMaybe = () => React.useContext(context);\n\n const useRequired = () => {\n const c = useMaybe();\n\n // type guard\n if (c === undefined) throw new Error();\n\n return c;\n };\n\n return {\n Provider: context.Provider,\n useMaybe,\n useRequired,\n } as const;\n}\n","import type { RhfUtilsContext } from '@/form/context/utils/RhfUtilsContextType';\n\nimport { createContext } from '@/utils/createContext';\n\nimport type { FormRelayOptions } from '../FormRelayOptions';\nimport type { FormRelay, FormRelayStateSelected } from '../types';\n\nexport type FormsRelayed = Record<\n string, // form id\n FormRelay\n>;\n\nexport type FormRelayContext = {\n // set\n\n add: (\n state: FormRelayStateSelected,\n utils: RhfUtilsContext,\n options: FormRelayOptions,\n ) => void;\n\n update: (id: string, state: FormRelayStateSelected) => void;\n\n remove: (id: string) => void;\n\n // state\n\n state: FormsRelayed;\n};\n\nexport const {\n Provider: _FormRelayContextProvider,\n useRequired: useFormRelayContext,\n} = createContext<FormRelayContext>();\n","import React from 'react';\n\nimport type { RhfUtilsContext } from '@/form/context/utils/RhfUtilsContextType';\n\nimport type { FormRelayOptions } from '../FormRelayOptions';\nimport type { FormRelayStateSelected } from '../types';\n\nimport type { FormsRelayed } from './useFormRelayContext';\nimport { _FormRelayContextProvider } from './useFormRelayContext';\n\ntype Props = React.PropsWithChildren;\n\nexport const FormRelayContextProvider: React.FC<Props> = ({ children }) => {\n // state\n\n const [state, setState] = React.useState<FormsRelayed>({});\n\n // set\n\n const add = React.useCallback(\n (\n formState: FormRelayStateSelected,\n utils: RhfUtilsContext,\n options: FormRelayOptions,\n ) => {\n if (state[utils.formId]) throw new Error('Form id already exists.');\n\n setState((forms) => ({\n ...forms,\n [utils.formId]: { state: formState, utils, options },\n }));\n },\n\n [state],\n );\n\n const update = React.useCallback(\n (id: string, state: FormRelayStateSelected) => {\n setState((forms) => {\n const current = forms[id];\n\n if (!current) throw new Error(\"Form id doesn't exist\");\n\n return {\n ...forms,\n [id]: { ...current, state },\n };\n });\n },\n [],\n );\n\n const remove = React.useCallback((id: string) => {\n setState((forms) =>\n Object.fromEntries(\n Object.entries(forms)\n // keep only other ids\n .filter(([entryId]) => entryId !== id),\n ),\n );\n }, []);\n\n //\n\n return (\n <_FormRelayContextProvider\n value={{\n // set\n\n add,\n update,\n remove,\n\n // get\n\n state,\n }}\n >\n {children}\n </_FormRelayContextProvider>\n );\n};\n","import { createContext } from '@/utils/createContext';\n\nimport type { RhfUtilsContext } from './RhfUtilsContextType';\n\nconst {\n Provider: _RhfUtilsContextProvider,\n useRequired: useRhfUtilsContext,\n useMaybe: useRhfUtilsMaybeContext,\n} = createContext<RhfUtilsContext>();\n\nexport {\n _RhfUtilsContextProvider,\n useRhfUtilsContext,\n useRhfUtilsMaybeContext,\n};\n","export const isEmptyObject = (obj: Record<string, unknown>) =>\n Object.keys(obj).length === 0;\n","import { flatten } from 'flat';\nimport type { FieldErrors } from 'react-hook-form';\n\n/**\n * Flatten a {@link FieldErrors} object.\n *\n * @returns e.g.,\n * ```ts\n * {\n * \"address.street.type\": \"too_short\",\n * \"address.street.ref.value\": \"123\",\n * \"address.street.message\": \"Required.\"\n * }\n * ```\n */\nexport const flattenFieldErrors = (errors: FieldErrors) =>\n flatten<FieldErrors, Record<string, unknown>>(errors);\n","import type { FieldError, FieldErrors } from 'react-hook-form';\nimport { get } from 'react-hook-form';\n\nimport type { SafeFieldValues } from '@/form/rhf/SafeFieldValuesType';\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 */\nexport const 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 (entriesAccumulator, flattenedKey) => {\n /**\n * Maybe path.\n *\n * Derived from flattened key by removing leaf node suffix (if present).\n *\n * @example\n * path: `address.street.message` -> `address.street`\n * @example\n * not path: `address.street.ref` -> `address.street.ref` (no suffix match to replace)\n */\n const maybePath = flattenedKey.replace(\n regexMaybeFieldErrorLeafNodeSuffix,\n '',\n );\n\n // if nothing replaced, then it's not a leaf node; return early\n if (maybePath === flattenedKey) return entriesAccumulator;\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, maybePath, undefined) as\n FieldError | undefined;\n\n // if no field error found, then derived path was wrong; return early\n if (!fieldError) return entriesAccumulator;\n\n /**\n * Add entry to accumulator.\n *\n * (If it's a duplicate (e.g., `.type` leaf node matched before `.message`),\n * it doesn't matter because `Object.fromEntries` will just overwrite\n * first entry with second matching key/value.)\n */\n entriesAccumulator.push([maybePath, fieldError]);\n\n return entriesAccumulator;\n },\n\n [], // entries\n ),\n );\n};\n\n//\n\n/**\n * Regular expression to maybe match the end of a leaf node path.\n *\n * @example\n * - `name.type`\n * - `address.street.message`\n *\n * @description\n *\n * dot [?: non-capturing](\"type\" | \"message\")[\\b word boundary][$ end of string]\n */\nexport const regexMaybeFieldErrorLeafNodeSuffix = /\\.(?:type|message)\\b$/;\n\n//\n\nexport type FieldErrorsSansRef<\n TFieldValues extends SafeFieldValues = SafeFieldValues,\n> = Record<\n keyof TFieldValues | 'root',\n Partial<Pick<FieldError, 'message' | 'type'>> & {\n hasRef: boolean;\n }\n>;\n\nexport const getFlatFieldErrorsSansRef = <TFieldValues extends SafeFieldValues>(\n errors: FieldErrors<TFieldValues>,\n) =>\n Object.fromEntries(\n Object.entries(getFlatFieldErrors(errors)).map(([name, error]) => [\n name,\n {\n type: error.type,\n message: error.message,\n hasRef: !!error.ref, // strip out actual ref, etc. (avoid circular JSON error)\n },\n ]),\n ) as FieldErrorsSansRef<TFieldValues>;\n","import React from 'react';\nimport { useFormState } from 'react-hook-form';\n\nimport { getFlatFieldErrorsSansRef } from '@/errors/flat/getFlatFieldErrors';\n\nimport { useRhfUtilsContext } from '@/form/context/utils/useRhfUtilsContext';\n\nimport { useFormRelayContext } from '../context/useFormRelayContext';\nimport type { FormRelayOptions } from '../FormRelayOptions';\nimport type { FormRelayStateSelected } from '../types';\n\nexport const useFormRelaySet = (options?: FormRelayOptions) => {\n if (!options) return;\n\n // eslint-disable-next-line react-hooks/rules-of-hooks\n const [memoOptions] = React.useState(options);\n\n // eslint-disable-next-line react-hooks/rules-of-hooks\n useFormRelayOnMount(memoOptions);\n // eslint-disable-next-line react-hooks/rules-of-hooks\n useFormRelayOnChange(memoOptions);\n};\n\n// HELPERS\n\n// mount\n\nconst useFormRelayOnMount = (options: FormRelayOptions) => {\n const utils = useRhfUtilsContext();\n const relay = useFormRelayContext();\n const formStateForRelay = useFormStateForRelay(options);\n\n React.useEffect(\n () => {\n relay.add(formStateForRelay, utils, options);\n\n // unmount\n return () => {\n relay.remove(utils.formId);\n };\n },\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [],\n );\n};\n\n// update\n\nconst useFormRelayOnChange = (options: FormRelayOptions) => {\n const utils = useRhfUtilsContext();\n const relay = useFormRelayContext();\n const formStateForRelay = useFormStateForRelay(options);\n\n React.useEffect(\n // when form state changes, publish to relay context\n () => {\n relay.update(utils.formId, formStateForRelay);\n },\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [formStateForRelay],\n );\n};\n\n// relayed form state\n\n/** Transform, memo-ize {@link useFormState}'s return to {@link FormRelayed} */\nconst useFormStateForRelay = (\n options: FormRelayOptions,\n): FormRelayStateSelected => {\n const formState = useFormState();\n\n const formStateSelected = options.select(formState);\n\n const formStateSelectedJson = JSON.stringify({\n ...formStateSelected,\n errors:\n formStateSelected.errors &&\n getFlatFieldErrorsSansRef(formStateSelected.errors),\n });\n\n const memoFormStateSelected = React.useMemo(\n // when watch JSON changes, update memo\n () => formStateSelected,\n\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [formStateSelectedJson],\n );\n\n return memoFormStateSelected;\n};\n","import type { FormRelayOptions } from '../FormRelayOptions';\n\nimport { useFormRelaySet } from './useFormRelaySet';\n\ntype Props = {\n options?: FormRelayOptions;\n};\n\nexport const FormRelaySetter: React.FC<Props> = ({ options }) => {\n useFormRelaySet(options);\n\n return null;\n};\n"],"mappings":";;;;;;;;;AAMA,SAAgB,gBAA6B;CAC3C,MAAM,UAAU,MAAM,cAA6B,KAAA,CAAS;CAE5D,MAAM,iBAAiB,MAAM,WAAW,OAAO;CAE/C,MAAM,oBAAoB;EACxB,MAAM,IAAI,SAAS;EAGnB,IAAI,MAAM,KAAA,GAAW,MAAM,IAAI,MAAM;EAErC,OAAO;CACT;CAEA,OAAO;EACL,UAAU,QAAQ;EAClB;EACA;CACF;AACF;;;ACKA,MAAa,EACX,UAAU,2BACV,aAAa,wBACX,cAAgC;;;ACrBpC,MAAa,4BAA6C,EAAE,eAAe;CAGzE,MAAM,CAAC,OAAO,YAAY,MAAM,SAAuB,CAAC,CAAC;CAIzD,MAAM,MAAM,MAAM,aAEd,WACA,O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,OAAO;CAEvB,OAAO;AACT"}
|
package/dist/tsdown/index.d.ts
CHANGED
|
@@ -8,7 +8,7 @@ import { z } from "zod";
|
|
|
8
8
|
type Props$4 = React$1.PropsWithChildren<{
|
|
9
9
|
config?: RhfUtilsClientConfig;
|
|
10
10
|
}>;
|
|
11
|
-
declare const RhfUtilsClientConfigProvider: React$1.FC<Props$4>;
|
|
11
|
+
export declare const RhfUtilsClientConfigProvider: React$1.FC<Props$4>;
|
|
12
12
|
//#endregion
|
|
13
13
|
//#region src/errors/flat/context/useFlatFieldErrorsContextHasOnlyOrphans.d.ts
|
|
14
14
|
/**
|
|
@@ -16,7 +16,7 @@ declare const RhfUtilsClientConfigProvider: React$1.FC<Props$4>;
|
|
|
16
16
|
*
|
|
17
17
|
* You may want to treat this case specifically.
|
|
18
18
|
*/
|
|
19
|
-
declare const useFlatFieldErrorsContextHasOnlyOrphans: () => boolean;
|
|
19
|
+
export declare const useFlatFieldErrorsContextHasOnlyOrphans: () => boolean;
|
|
20
20
|
//#endregion
|
|
21
21
|
//#region src/errors/nonfield/RhfUtilsNonFieldErrorMarker.d.ts
|
|
22
22
|
type Props$3 = {
|
|
@@ -30,7 +30,7 @@ type Props$3 = {
|
|
|
30
30
|
* Field array with minimum items.
|
|
31
31
|
* (When there are no items, the error is not associated with a field and is displayed separately.)
|
|
32
32
|
*/
|
|
33
|
-
declare const RhfUtilsNonFieldErrorMarker: React.FC<Props$3>;
|
|
33
|
+
export declare const RhfUtilsNonFieldErrorMarker: React.FC<Props$3>;
|
|
34
34
|
//#endregion
|
|
35
35
|
//#region src/form/context/utils/useRhfUtilsContext.d.ts
|
|
36
36
|
declare const _RhfUtilsContextProvider: import("react").Provider<RhfUtilsContextProviderProps | undefined>, useRhfUtilsContext: () => RhfUtilsContextProviderProps, useRhfUtilsMaybeContext: () => RhfUtilsContextProviderProps | undefined;
|
|
@@ -78,12 +78,12 @@ type UseRhfUtilsFormChildrenProps<TFieldValues extends SafeFieldValues, TTransfo
|
|
|
78
78
|
*
|
|
79
79
|
* @link https://developer.mozilla.org/docs/Web/API/HTMLFormElement/requestSubmit
|
|
80
80
|
*/
|
|
81
|
-
declare const useFormRequestSubmit: (ref: React$1.RefObject<HTMLFormElement | null>) => HTMLFormElement["requestSubmit"];
|
|
81
|
+
export declare const useFormRequestSubmit: (ref: React$1.RefObject<HTMLFormElement | null>) => HTMLFormElement["requestSubmit"];
|
|
82
82
|
//#endregion
|
|
83
83
|
//#region src/submit/last/context/useLastSubmitContext.d.ts
|
|
84
|
-
declare const useLastSubmit: () => LastSubmitContextRead;
|
|
85
|
-
declare const useLastSubmitStatus: () => import("react").RefObject<LastSubmitStatus>;
|
|
86
|
-
declare const useLastSubmitError: () => LastSubmitError | undefined;
|
|
84
|
+
export declare const useLastSubmit: () => LastSubmitContextRead;
|
|
85
|
+
export declare const useLastSubmitStatus: () => import("react").RefObject<LastSubmitStatus>;
|
|
86
|
+
export declare const useLastSubmitError: () => LastSubmitError | undefined;
|
|
87
87
|
//#endregion
|
|
88
88
|
//#region src/form/defaults/form/UseRhfUtilsFormInstanceFormProps.d.ts
|
|
89
89
|
type DataAttributes = Record<`data-${string}`, string>;
|
|
@@ -150,7 +150,7 @@ type ZodTypeSafeFieldValues = ZodTypeOfSafeFieldValues | z.ZodEffects<ZodTypeOfS
|
|
|
150
150
|
//#endregion
|
|
151
151
|
//#region src/resolvers/zod/form/RhfUtilsZodForm.d.ts
|
|
152
152
|
type Props$2<TSchema extends ZodTypeSafeFieldValues, TGetApiValues extends undefined | RhfUtilsFormPropsGetApiValues<TSchema[typeof zodTypeOutput], SafeFieldValues>, TOnSubmitReturnType, TApiValues extends undefined | SafeFieldValues = TGetApiValues extends RhfUtilsFormPropsGetApiValues<TSchema[typeof zodTypeOutput], infer U> ? U : undefined> = React.PropsWithChildren<RhfUtilsFormProps<TSchema[typeof zodTypeInput], TSchema[typeof zodTypeOutput], TGetApiValues, TOnSubmitReturnType, TApiValues>>;
|
|
153
|
-
declare const RhfUtilsZodForm: <TSchema extends ZodTypeSafeFieldValues, TGetApiValues extends undefined | RhfUtilsFormPropsGetApiValues<TSchema[typeof zodTypeOutput], SafeFieldValues>, TOnSubmitReturnType, TApiValues extends undefined | SafeFieldValues = TGetApiValues extends RhfUtilsFormPropsGetApiValues<TSchema[typeof zodTypeOutput], infer U> ? U : undefined>(props: Props$2<TSchema, TGetApiValues, TOnSubmitReturnType, TApiValues>) => import("react").JSX.Element;
|
|
153
|
+
export declare const RhfUtilsZodForm: <TSchema extends ZodTypeSafeFieldValues, TGetApiValues extends undefined | RhfUtilsFormPropsGetApiValues<TSchema[typeof zodTypeOutput], SafeFieldValues>, TOnSubmitReturnType, TApiValues extends undefined | SafeFieldValues = TGetApiValues extends RhfUtilsFormPropsGetApiValues<TSchema[typeof zodTypeOutput], infer U> ? U : undefined>(props: Props$2<TSchema, TGetApiValues, TOnSubmitReturnType, TApiValues>) => import("react").JSX.Element;
|
|
154
154
|
//#endregion
|
|
155
155
|
//#region src/form/providers/RhfUtilsFormProvidersPropsType.d.ts
|
|
156
156
|
/**
|
|
@@ -170,13 +170,13 @@ type RhfUtilsFormProvidersProps<TFieldValues extends SafeFieldValues, TTransform
|
|
|
170
170
|
type Props$1<TSchema extends ZodTypeSafeFieldValues> = React.PropsWithChildren<{
|
|
171
171
|
schema: TSchema;
|
|
172
172
|
} & RhfUtilsFormProvidersProps<TSchema[typeof zodTypeInput], TSchema[typeof zodTypeOutput]>>;
|
|
173
|
-
declare const RhfUtilsZodFormProviders: <TSchema extends ZodTypeSafeFieldValues>({ schema, children, ...props }: Props$1<TSchema>) => import("react").JSX.Element;
|
|
173
|
+
export declare const RhfUtilsZodFormProviders: <TSchema extends ZodTypeSafeFieldValues>({ schema, children, ...props }: Props$1<TSchema>) => import("react").JSX.Element;
|
|
174
174
|
//#endregion
|
|
175
175
|
//#region src/resolvers/zod/with-providers/RhfUtilsZodFormWithProviders.d.ts
|
|
176
176
|
type Props<TSchema extends ZodTypeSafeFieldValues, TGetApiValues extends undefined | RhfUtilsFormPropsGetApiValues<TTransformedValues, SafeFieldValues>, TOnSubmitReturnType, TFieldValues extends TSchema[typeof zodTypeInput] = TSchema[typeof zodTypeInput], TTransformedValues extends TSchema[typeof zodTypeOutput] = TSchema[typeof zodTypeOutput], TApiValues extends undefined | SafeFieldValues = TGetApiValues extends RhfUtilsFormPropsGetApiValues<TTransformedValues, infer U> ? U : undefined> = React.PropsWithChildren<{
|
|
177
177
|
schema: TSchema;
|
|
178
178
|
} & Omit<RhfUtilsFormProvidersProps<TFieldValues, TTransformedValues>, 'resolver'> & RhfUtilsFormProps<TFieldValues, TTransformedValues, TGetApiValues, TOnSubmitReturnType, TApiValues>>;
|
|
179
|
-
declare const RhfUtilsZodFormWithProviders: <TSchema extends ZodTypeSafeFieldValues, TGetApiValues extends undefined | RhfUtilsFormPropsGetApiValues<TTransformedValues, SafeFieldValues>, TOnSubmitReturnType, TFieldValues extends TSchema[typeof zodTypeInput] = TSchema[typeof zodTypeInput], TTransformedValues extends TSchema[typeof zodTypeOutput] = TSchema[typeof zodTypeOutput], TApiValues extends undefined | SafeFieldValues = TGetApiValues extends RhfUtilsFormPropsGetApiValues<TTransformedValues, infer U> ? U : undefined>({ schema, ...props }: Props<TSchema, TGetApiValues, TOnSubmitReturnType, TFieldValues, TTransformedValues, TApiValues>) => import("react").JSX.Element;
|
|
179
|
+
export declare const RhfUtilsZodFormWithProviders: <TSchema extends ZodTypeSafeFieldValues, TGetApiValues extends undefined | RhfUtilsFormPropsGetApiValues<TTransformedValues, SafeFieldValues>, TOnSubmitReturnType, TFieldValues extends TSchema[typeof zodTypeInput] = TSchema[typeof zodTypeInput], TTransformedValues extends TSchema[typeof zodTypeOutput] = TSchema[typeof zodTypeOutput], TApiValues extends undefined | SafeFieldValues = TGetApiValues extends RhfUtilsFormPropsGetApiValues<TTransformedValues, infer U> ? U : undefined>({ schema, ...props }: Props<TSchema, TGetApiValues, TOnSubmitReturnType, TFieldValues, TTransformedValues, TApiValues>) => import("react").JSX.Element;
|
|
180
180
|
//#endregion
|
|
181
181
|
//#region src/resolvers/zod/RhfUtilsUseZodFormChildrenPropsType.d.ts
|
|
182
182
|
type RhfUtilsUseZodFormChildrenProps<TSchema extends ZodTypeSafeFieldValues, TChildrenProps = undefined> = UseRhfUtilsFormChildrenProps<TSchema[typeof zodTypeInput], TSchema[typeof zodTypeOutput], TChildrenProps>;
|
|
@@ -187,5 +187,5 @@ type RhfUtilsUseZodFormChildrenProps<TSchema extends ZodTypeSafeFieldValues, TCh
|
|
|
187
187
|
*/
|
|
188
188
|
type RhfUtilsUseZodFormChildrenFC<TSchema extends ZodTypeSafeFieldValues, TChildrenProps = undefined> = React$1.FC<RhfUtilsUseZodFormChildrenProps<TSchema, TChildrenProps>>;
|
|
189
189
|
//#endregion
|
|
190
|
-
export { FormSubmitError, type FormSubmitFieldErrors, type Register, type RhfUtilsClientConfig, type RhfUtilsClientConfigFormOutletProps,
|
|
190
|
+
export { FormSubmitError, type FormSubmitFieldErrors, type Register, type RhfUtilsClientConfig, type RhfUtilsClientConfigFormOutletProps, type RhfUtilsFormOptions, type RhfUtilsUseZodFormChildrenFC, type RhfUtilsUseZodFormChildrenProps, type SafeFieldValues, type RHF_UseFormReturnWithoutProxies as UseFormReturnWithoutProxies, type UseRhfUtilsFormChildrenProps, type UseRhfUtilsFormOnSubmitContext, type UseRhfUtilsFormOnSubmitErrorContext, type ZodTypeSafeFieldValues, useFlatFieldErrorsContext, useRhfUtilsContext };
|
|
191
191
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../../src/client/config/context/RhfUtilsClientConfigProvider.tsx","../../src/errors/flat/context/useFlatFieldErrorsContextHasOnlyOrphans.ts","../../src/errors/nonfield/RhfUtilsNonFieldErrorMarker.tsx","../../src/form/context/utils/useRhfUtilsContext.tsx","../../src/form/RHF_UseFormReturnWithoutProxiesType.ts","../../src/form/UseRhfUtilsFormChildrenPropsType.ts","../../src/form/utils/useFormRequestSubmit.ts","../../src/submit/last/context/useLastSubmitContext.ts","../../src/form/defaults/form/UseRhfUtilsFormInstanceFormProps.ts","../../src/form/with-handlers-and-children/RhfUtilsFormPropsOnBeforeSubmitInvariants.ts","../../src/form/with-handlers-and-children/RhfUtilsFormProps.ts","../../src/resolvers/zod/consts.ts","../../src/resolvers/zod/ZodTypeSafeFieldValuesType.ts","../../src/resolvers/zod/form/RhfUtilsZodForm.tsx","../../src/form/providers/RhfUtilsFormProvidersPropsType.ts","../../src/resolvers/zod/providers/RhfUtilsZodFormProviders.tsx","../../src/resolvers/zod/with-providers/RhfUtilsZodFormWithProviders.tsx","../../src/resolvers/zod/RhfUtilsUseZodFormChildrenPropsType.ts","../../src/resolvers/zod/RhfUtilsUseZodFormChildrenFCType.ts"],"mappings":";;;;;;;KAQK,UAAQ,QAAM;EACjB,SAAS;;
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../../src/client/config/context/RhfUtilsClientConfigProvider.tsx","../../src/errors/flat/context/useFlatFieldErrorsContextHasOnlyOrphans.ts","../../src/errors/nonfield/RhfUtilsNonFieldErrorMarker.tsx","../../src/form/context/utils/useRhfUtilsContext.tsx","../../src/form/RHF_UseFormReturnWithoutProxiesType.ts","../../src/form/UseRhfUtilsFormChildrenPropsType.ts","../../src/form/utils/useFormRequestSubmit.ts","../../src/submit/last/context/useLastSubmitContext.ts","../../src/form/defaults/form/UseRhfUtilsFormInstanceFormProps.ts","../../src/form/with-handlers-and-children/RhfUtilsFormPropsOnBeforeSubmitInvariants.ts","../../src/form/with-handlers-and-children/RhfUtilsFormProps.ts","../../src/resolvers/zod/consts.ts","../../src/resolvers/zod/ZodTypeSafeFieldValuesType.ts","../../src/resolvers/zod/form/RhfUtilsZodForm.tsx","../../src/form/providers/RhfUtilsFormProvidersPropsType.ts","../../src/resolvers/zod/providers/RhfUtilsZodFormProviders.tsx","../../src/resolvers/zod/with-providers/RhfUtilsZodFormW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AgB,0BAChB,QAAA,aAAA,SAIC,QAAM,6BAAQ,IAAA;;;KCVZ,MACH,gBAAgB,wBAChB,kCAEI,8BAA8B,oBAAoB,kBACtD,qBACA,qBAAqB,eAAe,gBAClC,eAAe,eACjB,2BAA2B,eAAe,iBACxC,eAAe,gBACjB,+BAA+B,kBAC7B,sBAAsB,8BACpB,0BACM,KAEJ,iBAEJ,MAAM;EACN,QAAQ;IAER,KACE,2BAA2B,cAAc,mCAI3C,kBACE,cACA,oBACA,eACA,qBACA;qBAIO,+BACX,gBAAgB,wBAChB,kCAEI,8BAA8B,oBAAoB,kBACtD,qBACA,qBAAqB,eAAe,gBAClC,eAAe,eACjB,2BAA2B,eAAe,iBACxC,eAAe,gBACjB,+BAA+B,kBAC7B,sBAAsB,8BACpB,0BACM,KAEJ,iBAEN,WAAA,SAGC,MACD,SACA,eACA,qBACA,cACA,oBACA,gCACD,IAAA;;;KCpEW,gCACV,gBAAgB,wBAChB,8BACE,6BACF,eAAe,eACf,eAAe,gBACf;;;;;;KCHU,6BACV,gBAAgB,wBAChB,8BACE,QAAM,GAAG,gCAAgC,SAAS"}
|
package/dist/tsdown/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as _RhfUtilsContextProvider, c as FormRelayContextProvider, i as isEmptyObject, o as useRhfUtilsContext, r as getFlatFieldErrors, t as FormRelaySetter, u as createContext } from "./FormRelaySetter-
|
|
1
|
+
import { a as _RhfUtilsContextProvider, c as FormRelayContextProvider, i as isEmptyObject, o as useRhfUtilsContext, r as getFlatFieldErrors, t as FormRelaySetter, u as createContext } from "./FormRelaySetter-BNson1Za.js";
|
|
2
2
|
import React from "react";
|
|
3
3
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
4
4
|
import { Controller, FormProvider, useForm, useFormContext, useFormState, useWatch } from "react-hook-form";
|
|
@@ -107,7 +107,8 @@ const LazyDevTool = ({ config }) => {
|
|
|
107
107
|
//#endregion
|
|
108
108
|
//#region src/devtool/LazyDevToolViaProviders.tsx
|
|
109
109
|
const LazyDevToolViaProviders = () => {
|
|
110
|
-
|
|
110
|
+
const utils = useRhfUtilsContext();
|
|
111
|
+
return /* @__PURE__ */ jsx(LazyDevTool, { config: utils.options.devTool });
|
|
111
112
|
};
|
|
112
113
|
//#endregion
|
|
113
114
|
//#region src/form/_Controller.tsx
|
|
@@ -144,7 +145,8 @@ const useHandleCancelWithCheckIfCanBe = (onCancel, useCanFormBeCancelled, formOn
|
|
|
144
145
|
//#region src/form/utils/useHandleCancelWithCheckIfCanBeViaProviders.ts
|
|
145
146
|
const useHandleCancelWithCheckIfCanBeViaProviders = (onCancel) => {
|
|
146
147
|
const { useCanFormBeCancelled } = useRhfUtilsClientConfig();
|
|
147
|
-
|
|
148
|
+
const formSubmitContext = useRhfUtilsFormOnSubmitContext();
|
|
149
|
+
return useHandleCancelWithCheckIfCanBe(onCancel, useCanFormBeCancelled, formSubmitContext);
|
|
148
150
|
};
|
|
149
151
|
//#endregion
|
|
150
152
|
//#region src/form/with-handlers-and-children/_ChildrenViaProviders.tsx
|
|
@@ -188,9 +190,10 @@ const getRhfUtilsFormResolvedFormProps = (global, instance, surfaced) => ({
|
|
|
188
190
|
//#endregion
|
|
189
191
|
//#region src/form/defaults/form/useRhfUtilsFormResolvedFormProps.ts
|
|
190
192
|
const useRhfUtilsFormResolvedFormProps = (formProps, id, surfaced) => {
|
|
193
|
+
const config = useRhfUtilsClientConfig();
|
|
191
194
|
return {
|
|
192
195
|
id,
|
|
193
|
-
...getRhfUtilsFormResolvedFormProps(
|
|
196
|
+
...getRhfUtilsFormResolvedFormProps(config.defaults?.form, formProps, surfaced)
|
|
194
197
|
};
|
|
195
198
|
};
|
|
196
199
|
//#endregion
|
|
@@ -213,7 +216,8 @@ const useRhfUtilsFormHandleSubmit_Internal = ({ onValid, onInvalid, onError, onF
|
|
|
213
216
|
const rhfContext = useFormContext();
|
|
214
217
|
const { options } = useRhfUtilsContext();
|
|
215
218
|
const lastSubmitStatusRef = useLastSubmitStatus();
|
|
216
|
-
const
|
|
219
|
+
const handleSubmit = rhfContext.handleSubmit(onValid, onInvalid);
|
|
220
|
+
const handleSubmitWithLastSubmitError = useLastSubmitErrorContextWith(handleSubmit);
|
|
217
221
|
return (event) => {
|
|
218
222
|
lastSubmitStatusRef.current = "submitting";
|
|
219
223
|
if (options.stopSubmitPropagation) event.stopPropagation();
|
|
@@ -285,7 +289,8 @@ const RhfUtilsFormWithSubmitHandler_Internal = ({ getApiData, onSubmitInvalid, o
|
|
|
285
289
|
Controller: _Controller,
|
|
286
290
|
FormSubmitError
|
|
287
291
|
};
|
|
288
|
-
|
|
292
|
+
const FormComponent = config.FormComponent ?? "form";
|
|
293
|
+
return /* @__PURE__ */ jsx(FormComponent, {
|
|
289
294
|
...resolvedFormProps,
|
|
290
295
|
id: utils.formId,
|
|
291
296
|
ref: utils.formRef,
|
|
@@ -400,15 +405,16 @@ const FlatFieldErrorsContextProvider = ({ formRef, children }) => {
|
|
|
400
405
|
const { errors } = useFormState();
|
|
401
406
|
const all = getFlatFieldErrors(errors);
|
|
402
407
|
const orphans = formRef.current ? getOrphansFromFlatFieldErrors(all, formRef.current) : {};
|
|
408
|
+
const value = {
|
|
409
|
+
all,
|
|
410
|
+
fields: getRefdFromFlatFieldErrors(all),
|
|
411
|
+
roots: getRootsFromFlatFieldErrors(all),
|
|
412
|
+
orphans,
|
|
413
|
+
hasErrors: !isEmptyObject(errors),
|
|
414
|
+
hasOrphans: !isEmptyObject(orphans)
|
|
415
|
+
};
|
|
403
416
|
return /* @__PURE__ */ jsx(_FormErrorsFlatContextProvider, {
|
|
404
|
-
value
|
|
405
|
-
all,
|
|
406
|
-
fields: getRefdFromFlatFieldErrors(all),
|
|
407
|
-
roots: getRootsFromFlatFieldErrors(all),
|
|
408
|
-
orphans,
|
|
409
|
-
hasErrors: !isEmptyObject(errors),
|
|
410
|
-
hasOrphans: !isEmptyObject(orphans)
|
|
411
|
-
},
|
|
417
|
+
value,
|
|
412
418
|
children
|
|
413
419
|
});
|
|
414
420
|
};
|
|
@@ -416,9 +422,10 @@ const FlatFieldErrorsContextProvider = ({ formRef, children }) => {
|
|
|
416
422
|
//#region src/submit/last/context/LastSubmitContextProvider.tsx
|
|
417
423
|
const LastSubmitContextProvider = ({ children }) => {
|
|
418
424
|
const [error, setError] = React.useState();
|
|
425
|
+
const statusRef = React.useRef(null);
|
|
419
426
|
return /* @__PURE__ */ jsx(_LastSubmitContextProvider, {
|
|
420
427
|
value: {
|
|
421
|
-
status: { ref:
|
|
428
|
+
status: { ref: statusRef },
|
|
422
429
|
error: {
|
|
423
430
|
state: error,
|
|
424
431
|
reset: () => {
|
|
@@ -642,7 +649,8 @@ const useSubmitFormOnWatch = (formRef, options) => {
|
|
|
642
649
|
//#region src/form/context/utils/RhfUtilsContextProvider.tsx
|
|
643
650
|
const RhfUtilsContextProvider = ({ formId, formRef, options, children }) => {
|
|
644
651
|
const [memoOptions] = React.useState(options);
|
|
645
|
-
|
|
652
|
+
const config = useRhfUtilsClientConfig();
|
|
653
|
+
useFlatFieldErrorsContextOutput(config.fieldErrors?.output);
|
|
646
654
|
(memoOptions.submitOnWatch ? useSubmitFormOnWatch : void 0)?.(formRef, memoOptions.submitOnWatch);
|
|
647
655
|
useResetFormOnSubmitted(memoOptions.resetOnSubmitted);
|
|
648
656
|
return /* @__PURE__ */ jsx(_RhfUtilsContextProvider, {
|
package/dist/tsdown/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["RhfController","useRhfForm","RhfFormProvider"],"sources":["../../src/client/config/context/RhfUtilsClientConfigContext.tsx","../../src/client/config/context/RhfUtilsClientConfigProvider.tsx","../../src/errors/flat/context/useFlatFieldErrorsContext.ts","../../src/errors/flat/context/useFlatFieldErrorsContextHasOnlyOrphans.ts","../../src/errors/nonfield/RhfUtilsNonFieldErrorMarkerHtmlAttribute.ts","../../src/errors/nonfield/RhfUtilsNonFieldErrorMarker.tsx","../../src/form/utils/useFormRequestSubmit.ts","../../src/submit/error/FormSubmitError.ts","../../src/submit/last/context/useLastSubmitContext.ts","../../src/devtool/LazyDevTool.tsx","../../src/devtool/LazyDevToolViaProviders.tsx","../../src/form/_Controller.tsx","../../src/client/config/context/useRhfUtilsClientConfig.ts","../../src/submit/useRhfUtilsFormOnSubmitContext.ts","../../src/form/utils/useHandleCancelWithCheckIfCanBe.ts","../../src/form/utils/useHandleCancelWithCheckIfCanBeViaProviders.ts","../../src/form/with-handlers-and-children/_ChildrenViaProviders.tsx","../../src/submit/error/setCtxErrorsByFormSubmitFieldErrors.ts","../../src/form/defaults/form/getRhfUtilsFormResolvedFormProps.ts","../../src/form/defaults/form/useRhfUtilsFormResolvedFormProps.ts","../../src/submit/last/context/useLastSubmitErrorContextWith.ts","../../src/form/with-handlers-and-children/_useHandleSubmit.ts","../../src/form/with-handlers-and-children/_FormWithSubmitHandler.tsx","../../src/form/with-handlers-and-children/RhfUtilsForm.tsx","../../src/resolvers/zod/form/RhfUtilsZodForm.tsx","../../src/errors/flat/filterFlatFieldErrors.ts","../../src/errors/isFieldErrorRefd.ts","../../src/errors/isFlatFieldErrorEntryRefd.ts","../../src/errors/getRefdFromFlatFieldErrors.ts","../../src/errors/nonfield/RhfUtilsNonFieldErrorMarker.utils.ts","../../src/errors/nonfield/isNonFieldErrorMarkerInDOM.ts","../../src/errors/root/consts.ts","../../src/errors/root/isFormErrorPathRoot.ts","../../src/errors/orphan/isOrphanFormError.ts","../../src/errors/orphan/getIsOrphanFormErrorWithParentElement.ts","../../src/errors/orphan/getOrphansFromFlatFieldErrors.ts","../../src/errors/root/isFlatFieldErrorEntryPathRoot.ts","../../src/errors/root/getRootsFromFlatFieldErrors.ts","../../src/errors/flat/context/FlatFieldErrorsContextProvider.tsx","../../src/submit/last/context/LastSubmitContextProvider.tsx","../../src/errors/output/consoleErrors.ts","../../src/errors/flat/context/useFlatFieldErrorsContextOutput.ts","../../src/utils/useRefIfValueWasTrue.ts","../../src/submit/useFormOnSubmitted.ts","../../src/submit/useResetFormOnSubmitted.ts","../../src/utils/useIsFirstRender.ts","../../src/utils/useDebouncedOnChangeValue.ts","../../src/submit/useSubmitFormOnEvent.ts","../../src/submit/useSubmitFormOnWatch.ts","../../src/form/context/utils/RhfUtilsContextProvider.tsx","../../src/form/options/getRhfUtilsFormResolvedOptions.ts","../../src/form/options/useRhfUtilsFormResolvedOptions.ts","../../src/form/rhf/getRhfUtilsFormResolvedRhfProps.ts","../../src/form/rhf/useRhfFormWithResolvedProps.ts","../../src/form/providers/RhfUtilsFormProviders.tsx","../../src/resolvers/zod/getZodResolver.ts","../../src/resolvers/zod/providers/RhfUtilsZodFormProviders.tsx","../../src/form/with-providers/RhfUtilsFormWithProviders.tsx","../../src/resolvers/zod/with-providers/RhfUtilsZodFormWithProviders.tsx","../../src/_exports/index.ts"],"sourcesContent":["import React from 'react';\n\nimport type { RhfUtilsClientConfig } from '../RhfUtilsClientConfigType';\n\nexport const RhfUtilsClientConfigContext_Internal = React.createContext<\n RhfUtilsClientConfig | undefined\n>(undefined);\n","import React from 'react';\n\nimport { FormRelayContextProvider } from '@/form/relay/context/FormRelayContextProvider';\n\nimport type { RhfUtilsClientConfig } from '../RhfUtilsClientConfigType';\n\nimport { RhfUtilsClientConfigContext_Internal } from './RhfUtilsClientConfigContext';\n\ntype Props = React.PropsWithChildren<{\n config?: RhfUtilsClientConfig;\n}>;\n\nexport const RhfUtilsClientConfigProvider: React.FC<Props> = ({\n config,\n children,\n}) => {\n const [memoConfig] = React.useState(config ?? {});\n\n return (\n <RhfUtilsClientConfigContext_Internal.Provider value={memoConfig}>\n <FormRelayContextProvider>{children}</FormRelayContextProvider>\n </RhfUtilsClientConfigContext_Internal.Provider>\n );\n};\n","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 { _FormErrorsFlatContextProvider, useFlatFieldErrorsContext };\n","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 */\nexport const 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","/**\n * HTML data attribute for {@link RhfUtilsNonFieldErrorMarker}.\n */\nexport const RhfUtilsNonFieldErrorMarkerHtmlAttribute =\n 'data-rhfutils-nonfield-error-marker-path';\n","import { RhfUtilsNonFieldErrorMarkerHtmlAttribute } from './RhfUtilsNonFieldErrorMarkerHtmlAttribute';\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 */\nexport const RhfUtilsNonFieldErrorMarker: React.FC<Props> = ({ path }) => {\n const dataAttribute = {\n [RhfUtilsNonFieldErrorMarkerHtmlAttribute]: 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","import React from 'react';\n\n/**\n * Get callback to trigger submit manually on form.\n *\n * Note: `submitter` is optional, but is required to be a submit button.\n *\n * @link https://developer.mozilla.org/docs/Web/API/HTMLFormElement/requestSubmit\n */\nexport const useFormRequestSubmit = (\n ref: React.RefObject<HTMLFormElement | null>,\n): HTMLFormElement['requestSubmit'] =>\n React.useCallback(\n (submitter) => {\n // typeguard (should never happen at runtime when callback is called)\n if (!ref.current) throw new Error();\n\n requestSubmitByForm(ref.current, submitter);\n },\n [ref],\n );\n\n//\n\nconst requestSubmitByForm = (\n form: Pick<HTMLFormElement, 'requestSubmit'>, // narrow to avoid `{[string]: any}` type\n submitter?: HTMLElement | null, // submit button\n) => {\n form.requestSubmit(submitter);\n};\n","import type { SafeFieldValues } from '@/form/rhf/SafeFieldValuesType';\n\nimport type { FormSubmitFieldErrors } from './FormSubmitFieldErrors';\n\nexport class FormSubmitError<\n TFieldValues extends SafeFieldValues = SafeFieldValues,\n TApiValues extends undefined | SafeFieldValues = undefined,\n> extends Error {\n constructor(\n public errors: FormSubmitFieldErrors<TFieldValues, TApiValues>,\n message?: string, // error message\n // options?: ErrorOptions, // requires es2022\n ) {\n super(message);\n }\n}\n","import { createContext } from '@/utils/createContext';\n\nimport type {\n LastSubmitContext,\n LastSubmitContextRead,\n} from './LastSubmitContextType';\n\nconst {\n Provider: _LastSubmitContextProvider,\n useRequired: _useLastSubmitContext,\n} = createContext<LastSubmitContext>();\n\nexport { _LastSubmitContextProvider, _useLastSubmitContext };\n\n//\n\nexport const useLastSubmit = (): LastSubmitContextRead => {\n const lastSubmit = _useLastSubmitContext();\n\n return {\n statusRef: lastSubmit.status.ref,\n error: lastSubmit.error.state,\n };\n};\n\nexport const useLastSubmitStatus = () => useLastSubmit().statusRef;\n\nexport const useLastSubmitError = () => useLastSubmit().error;\n","import type { DevtoolUIProps } from '@hookform/devtools/dist/devToolUI';\nimport React from 'react';\n\nconst LazyRhfDevTool = React.lazy(() =>\n import('@hookform/devtools').then((res) => ({\n default: res.DevTool,\n })),\n);\n\ntype LazyDevToolProps = {\n config?: boolean | Pick<DevtoolUIProps, 'placement' | 'styles'>;\n};\n\n/**\n * Lazy-loaded RHF DevTool.\n */\nexport const LazyDevTool: React.FC<LazyDevToolProps> = ({ config }) => {\n const [memoConfig] = React.useState(config);\n\n // early escape for non-dev builds\n if (!memoConfig) return null;\n\n const props = typeof memoConfig === 'object' ? memoConfig : undefined;\n\n return (\n <React.Suspense>\n <LazyRhfDevTool {...props} />\n </React.Suspense>\n );\n};\n","import { useRhfUtilsContext } from '@/form/context/utils/useRhfUtilsContext';\n\nimport { LazyDevTool } from './LazyDevTool';\n\nexport const LazyDevToolViaProviders: React.FC = () => {\n const utils = useRhfUtilsContext();\n\n return <LazyDevTool config={utils.options.devTool} />;\n};\n","import type { ControllerProps, FieldPath } from 'react-hook-form';\nimport { Controller as RhfController } from 'react-hook-form';\n\nimport type { SafeFieldValues } from './rhf/SafeFieldValuesType';\n\nexport type _ControllerProps<\n TFieldValues extends SafeFieldValues,\n TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>,\n> = Omit<ControllerProps<TFieldValues, TName>, 'control'>;\n\nexport const _Controller = <\n TFieldValues extends SafeFieldValues,\n TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>,\n>(\n props: _ControllerProps<TFieldValues, TName>,\n) => <RhfController {...props} />;\n","import React from 'react';\n\nimport { RhfUtilsClientConfigContext_Internal } from './RhfUtilsClientConfigContext';\n\nexport const useRhfUtilsClientConfig = () => {\n const ctx = React.useContext(RhfUtilsClientConfigContext_Internal);\n\n if (ctx === undefined) throw new Error();\n\n return ctx;\n};\n","import { useFormContext } from 'react-hook-form';\n\nimport { useRhfUtilsContext } from '@/form/context/utils/useRhfUtilsContext';\nimport type { SafeFieldValues } from '@/form/rhf/SafeFieldValuesType';\n\nimport { FormSubmitError } from './error/FormSubmitError';\nimport { useLastSubmit } from './last/context/useLastSubmitContext';\nimport type { UseRhfUtilsFormOnSubmitContext } from './UseRhfUtilsFormOnSubmitContextType';\n\nexport const useRhfUtilsFormOnSubmitContext = <\n TFieldValues extends SafeFieldValues = SafeFieldValues,\n TTransformedValues extends SafeFieldValues = TFieldValues,\n>(): UseRhfUtilsFormOnSubmitContext<TFieldValues, TTransformedValues> => {\n const utilsCtx = useRhfUtilsContext();\n\n const lastSubmitCtx = useLastSubmit();\n\n const rhf = useFormContext<TFieldValues, unknown, TTransformedValues>();\n\n return {\n utils: utilsCtx,\n lastSubmit: lastSubmitCtx,\n rhf,\n FormSubmitError,\n };\n};\n","import type { RhfUtilsClientConfig } from '@/client/config/RhfUtilsClientConfigType';\n\nimport type { UseRhfUtilsFormOnSubmitContext } from '@/submit/UseRhfUtilsFormOnSubmitContextType';\n\nimport type { MaybePromise } from '@/utils/types';\n\nexport const useHandleCancelWithCheckIfCanBe = (\n onCancel: undefined | (() => MaybePromise<void>),\n useCanFormBeCancelled: RhfUtilsClientConfig['useCanFormBeCancelled'],\n formOnSubmitContext: UseRhfUtilsFormOnSubmitContext,\n) => {\n const canFormBeCancelled = useCanFormBeCancelled?.();\n\n const handleCancelWithCheck = async () => {\n if (!onCancel) return;\n\n // - resolve possible promise\n // - keep returned handled non-async to avoid downstream type issues\n const canBeCancelled = await Promise.resolve(\n canFormBeCancelled?.(formOnSubmitContext),\n );\n\n // if form explicitly can't be cancelled, early return\n if (canBeCancelled === false) return;\n\n return Promise.resolve(onCancel());\n };\n\n return handleCancelWithCheck;\n};\n","import { useRhfUtilsClientConfig } from '@/client/config/context/useRhfUtilsClientConfig';\n\nimport { useRhfUtilsFormOnSubmitContext } from '@/submit/useRhfUtilsFormOnSubmitContext';\n\nimport type { MaybePromise } from '@/utils/types';\n\nimport { useHandleCancelWithCheckIfCanBe } from './useHandleCancelWithCheckIfCanBe';\n\nexport const useHandleCancelWithCheckIfCanBeViaProviders = (\n onCancel: undefined | (() => MaybePromise<void>),\n) => {\n const { useCanFormBeCancelled } = useRhfUtilsClientConfig();\n const formSubmitContext = useRhfUtilsFormOnSubmitContext();\n\n return useHandleCancelWithCheckIfCanBe(\n onCancel,\n useCanFormBeCancelled,\n formSubmitContext,\n );\n};\n","import { useFormContext } from 'react-hook-form';\n\nimport { FormSubmitError } from '@/submit/error/FormSubmitError';\n\nimport { _Controller } from '../_Controller';\nimport { useRhfUtilsContext } from '../context/utils/useRhfUtilsContext';\nimport type { SafeFieldValues } from '../rhf/SafeFieldValuesType';\nimport { useHandleCancelWithCheckIfCanBeViaProviders } from '../utils/useHandleCancelWithCheckIfCanBeViaProviders';\n\nimport type { RhfUtilsFormProps } from './RhfUtilsFormProps';\n\nexport const RhfUtilsFormChildrenViaProviders_Internal = <\n TFieldValues extends SafeFieldValues,\n TTransformedValues extends SafeFieldValues,\n>({\n onCancel,\n Children,\n}: Pick<\n RhfUtilsFormProps<TFieldValues, TTransformedValues, undefined, undefined>,\n 'Children' | 'onCancel'\n>) => {\n const rhf = useFormContext<TFieldValues, unknown, TTransformedValues>();\n const utils = useRhfUtilsContext();\n const onCancelWithCheck =\n useHandleCancelWithCheckIfCanBeViaProviders(onCancel);\n\n return (\n <Children\n {...utils}\n rhf={rhf}\n onCancel={onCancelWithCheck}\n Controller={_Controller<TFieldValues>}\n FormSubmitError={FormSubmitError}\n />\n );\n};\n","import type { FieldPath } from 'react-hook-form';\n\nimport type { SafeFieldValues } from '@/form/rhf/SafeFieldValuesType';\nimport type { RHF_UseFormReturnWithoutProxies } from '@/form/RHF_UseFormReturnWithoutProxiesType';\n\nimport type { FormSubmitFieldErrors } from './FormSubmitFieldErrors';\n\n/**\n * Handle thrown {@link FormSubmitError}.\n * Add key/values as name/message to RHF context errors.\n */\nexport const setCtxErrorsByFormSubmitFieldErrors = <\n TFieldValues extends SafeFieldValues,\n TTransformedValues extends SafeFieldValues,\n>(\n ctx: RHF_UseFormReturnWithoutProxies<TFieldValues, TTransformedValues>,\n errors: FormSubmitFieldErrors,\n) => {\n // loop through error object and set errors in rhf context\n Object.entries(errors).forEach(([name, fieldError]) => {\n ctx.setError(name as FieldPath<TFieldValues>, {\n type: 'FormSubmitFieldError', // default\n ...fieldError,\n });\n });\n};\n","import type {\n RhfUtilsFormInstanceFormSurfacedProps,\n UseRhfUtilsFormInstanceFormProps,\n} from './UseRhfUtilsFormInstanceFormProps';\n\nexport const getRhfUtilsFormResolvedFormProps = (\n global: UseRhfUtilsFormInstanceFormProps | undefined,\n instance: UseRhfUtilsFormInstanceFormProps | undefined,\n surfaced?: RhfUtilsFormInstanceFormSurfacedProps,\n): UseRhfUtilsFormInstanceFormProps => ({\n ...global,\n ...instance,\n\n className:\n [global?.className, instance?.className, surfaced?.className]\n .filter(Boolean) // filter out falsy values\n .join(' ')\n .trim() || undefined, // replace empty string with undefined\n});\n","import { useRhfUtilsClientConfig } from '@/client/config/context/useRhfUtilsClientConfig';\n\nimport { getRhfUtilsFormResolvedFormProps } from './getRhfUtilsFormResolvedFormProps';\nimport type { UseRhfUtilsFormInstanceFormProps } from './UseRhfUtilsFormInstanceFormProps';\n\nexport const useRhfUtilsFormResolvedFormProps = (\n formProps: UseRhfUtilsFormInstanceFormProps | undefined,\n id: string,\n surfaced?: { className?: string },\n) => {\n const config = useRhfUtilsClientConfig();\n\n return {\n id,\n\n ...getRhfUtilsFormResolvedFormProps(\n config.defaults?.form,\n formProps,\n surfaced,\n ),\n };\n};\n","import type { MaybePromise } from '@/utils/types';\n\nimport { _useLastSubmitContext } from './useLastSubmitContext';\n\nexport const useLastSubmitErrorContextWith = (\n handleSubmit: (\n event: React.SubmitEvent<HTMLFormElement>,\n ) => MaybePromise<unknown>,\n) => {\n const ctx = _useLastSubmitContext();\n\n return async function (event: React.SubmitEvent<HTMLFormElement>) {\n try {\n ctx.error.reset(); // reset state before next submit event\n\n return await handleSubmit(event);\n } catch (error: unknown) {\n ctx.error.set(error, event);\n\n throw error;\n }\n };\n};\n","import type { SubmitErrorHandler, SubmitHandler } from 'react-hook-form';\nimport { useFormContext } from 'react-hook-form';\n\nimport { useLastSubmitStatus } from '@/submit/last/context/useLastSubmitContext';\nimport { useLastSubmitErrorContextWith } from '@/submit/last/context/useLastSubmitErrorContextWith';\n\nimport type { MaybePromise } from '@/utils/types';\n\nimport { useRhfUtilsContext } from '../context/utils/useRhfUtilsContext';\nimport type { SafeFieldValues } from '../rhf/SafeFieldValuesType';\n\ntype Props<\n TFieldValues extends SafeFieldValues,\n TTransformedValues extends SafeFieldValues,\n> = {\n onValid: SubmitHandler<TTransformedValues>;\n onInvalid?: SubmitErrorHandler<TFieldValues>;\n onError: (error: unknown, event: React.BaseSyntheticEvent) => void;\n onFinally?: () => MaybePromise<unknown>;\n};\n\nexport const useRhfUtilsFormHandleSubmit_Internal = <\n TFieldValues extends SafeFieldValues,\n TTransformedValues extends SafeFieldValues,\n>({\n onValid,\n onInvalid,\n onError,\n onFinally,\n}: Props<TFieldValues, TTransformedValues>): ((\n event: React.SubmitEvent<HTMLFormElement>,\n) => void) => {\n const rhfContext = useFormContext<\n TFieldValues,\n unknown,\n TTransformedValues\n >();\n\n const { options } = useRhfUtilsContext();\n const lastSubmitStatusRef = useLastSubmitStatus();\n\n const handleSubmit = rhfContext.handleSubmit(onValid, onInvalid);\n\n const handleSubmitWithLastSubmitError =\n useLastSubmitErrorContextWith(handleSubmit);\n\n return (event: React.SubmitEvent<HTMLFormElement>) => {\n lastSubmitStatusRef.current = 'submitting';\n\n // cannot stop propagation in handleSubmitValid, b/c it receives a different event object\n if (options.stopSubmitPropagation) event.stopPropagation();\n\n void Promise.resolve(handleSubmitWithLastSubmitError(event))\n .then(() => {\n lastSubmitStatusRef.current = 'success';\n })\n .catch((error: unknown) => {\n lastSubmitStatusRef.current = 'error';\n\n onError(error, event);\n })\n .finally(() => {\n onFinally?.();\n });\n };\n};\n","import React from 'react';\nimport type { UseFormHandleSubmit, UseFormReturn } from 'react-hook-form';\nimport { useFormContext } from 'react-hook-form';\n\nimport { useRhfUtilsClientConfig } from '@/client/config/context/useRhfUtilsClientConfig';\nimport type { RhfUtilsClientConfigFormOutletProps } from '@/client/config/RhfUtilsClientConfigFormOutletProps';\nimport type { RhfUtilsClientConfigUseFormHooksProps } from '@/client/config/RhfUtilsClientConfigUseFormHooksProps';\n\nimport { FormSubmitError } from '@/submit/error/FormSubmitError';\nimport type { FormSubmitFieldErrors } from '@/submit/error/FormSubmitFieldErrors';\nimport { setCtxErrorsByFormSubmitFieldErrors } from '@/submit/error/setCtxErrorsByFormSubmitFieldErrors';\nimport { useLastSubmit } from '@/submit/last/context/useLastSubmitContext';\n\nimport type {\n UseRhfUtilsFormOnSubmitContext,\n UseRhfUtilsFormOnSubmitErrorContext,\n} from '../../submit/UseRhfUtilsFormOnSubmitContextType';\n\nimport { _Controller } from '../_Controller';\nimport { useRhfUtilsContext } from '../context/utils/useRhfUtilsContext';\nimport { useRhfUtilsFormResolvedFormProps } from '../defaults/form/useRhfUtilsFormResolvedFormProps';\nimport type { SafeFieldValues } from '../rhf/SafeFieldValuesType';\n\nimport { useRhfUtilsFormHandleSubmit_Internal } from './_useHandleSubmit';\nimport type {\n RhfUtilsFormProps,\n RhfUtilsFormPropsGetApiValues,\n} from './RhfUtilsFormProps';\nimport type { RhfUtilsFormPropsOnBeforeSubmitInvariants } from './RhfUtilsFormPropsOnBeforeSubmitInvariants';\n\nexport const RhfUtilsFormWithSubmitHandler_Internal = <\n TFieldValues extends SafeFieldValues,\n TTransformedValues extends SafeFieldValues,\n TGetApiValues extends\n | undefined\n | RhfUtilsFormPropsGetApiValues<TTransformedValues, SafeFieldValues>,\n TOnSubmitReturnType,\n TApiValues extends undefined | SafeFieldValues =\n TGetApiValues extends RhfUtilsFormPropsGetApiValues<\n TTransformedValues,\n infer U\n >\n ? U\n : undefined,\n>({\n getApiData,\n // handlers\n onSubmitInvalid,\n onBeforeSubmitInvariants,\n onBeforeSubmit,\n onSubmit,\n onSubmitSuccess,\n onSubmitError,\n onSubmitFinally,\n // other\n form,\n className,\n //\n children,\n}: React.PropsWithChildren<\n Pick<\n RhfUtilsFormProps<\n TFieldValues,\n TTransformedValues,\n TGetApiValues,\n TOnSubmitReturnType,\n TApiValues\n >,\n | 'getApiData'\n | 'onSubmitInvalid'\n | 'onBeforeSubmitInvariants'\n | 'onBeforeSubmit'\n | 'onSubmit'\n | 'onSubmitSuccess'\n | 'onSubmitError'\n | 'onSubmitFinally'\n | 'form'\n | 'className'\n >\n>) => {\n const rhfContext = useFormContext<\n TFieldValues,\n unknown,\n TTransformedValues\n >();\n\n const utils = useRhfUtilsContext();\n const config = useRhfUtilsClientConfig();\n const lastSubmit = useLastSubmit();\n\n const resolvedFormProps = useRhfUtilsFormResolvedFormProps(\n form,\n\n // eslint-disable-next-line react-hooks/refs -- bug?\n utils.formId,\n {\n className,\n },\n );\n\n // SUBMIT\n\n const handleSubmitValid: Parameters<\n UseFormHandleSubmit<TFieldValues, TTransformedValues>\n >[0] = async (data: TTransformedValues, event?: React.BaseSyntheticEvent) => {\n const input = rhfContext.getValues();\n\n const api = getApiData?.(data) as TApiValues;\n\n const datas = { input, output: data, api };\n\n const onSubmitContext: UseRhfUtilsFormOnSubmitContext<\n TFieldValues,\n TTransformedValues,\n TApiValues\n > = {\n utils,\n lastSubmit,\n rhf: rhfContext,\n FormSubmitError,\n };\n const submitEvent = event as React.BaseSyntheticEvent<SubmitEvent>; // `as` required due to conditional generic\n\n if (onBeforeSubmitInvariants)\n await handleOnSubmitInvariants<\n TFieldValues,\n TTransformedValues,\n TApiValues\n >(onBeforeSubmitInvariants, datas, onSubmitContext, submitEvent);\n\n await Promise.resolve(\n onBeforeSubmit?.(datas, onSubmitContext, submitEvent),\n );\n\n const submitResponse = (await Promise.resolve(\n onSubmit?.(datas, onSubmitContext, submitEvent),\n )) as TOnSubmitReturnType;\n\n // eslint-disable-next-line react-hooks/immutability\n lastSubmit.statusRef.current = 'success';\n\n await Promise.resolve(\n onSubmitSuccess?.(submitResponse, datas, onSubmitContext, submitEvent),\n );\n };\n\n function handleSubmitError(error: unknown, event: React.BaseSyntheticEvent) {\n // get `FormSubmitFieldErrors`, 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 strip `<any>` generic\n : // if error is not FormSubmitError, consumer can provide global handler\n config.onSubmitErrorUnknown?.(error);\n\n if (formSubmitErrors)\n setCtxErrorsByFormSubmitFieldErrors(rhfContext, formSubmitErrors);\n\n onSubmitError?.(\n error,\n {\n utils,\n lastSubmit,\n errors: formSubmitErrors,\n rhf: rhfContext,\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 handleSubmit = useRhfUtilsFormHandleSubmit_Internal({\n onValid: handleSubmitValid,\n onInvalid: onSubmitInvalid,\n onError: handleSubmitError,\n onFinally: onSubmitFinally,\n });\n\n // FormComponent and props\n\n const Outlet = React.useCallback(\n () => children,\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [],\n );\n\n /** FormComponent props -- general, non-form-, non-schema-specific. */\n const formHooksProps: RhfUtilsClientConfigUseFormHooksProps = {\n // eslint-disable-next-line react-hooks/refs -- bug?\n ...utils,\n rhf: rhfContext as UseFormReturn<SafeFieldValues, unknown, SafeFieldValues>,\n lastSubmit,\n };\n\n // eslint-disable-next-line react-hooks/refs\n config.useFormHooks?.(formHooksProps);\n\n /** FormComponent props -- general, non-form-, non-schema-specific. */\n const formInjectorProps: RhfUtilsClientConfigFormOutletProps = {\n // eslint-disable-next-line react-hooks/refs\n ...formHooksProps,\n Outlet,\n Controller: _Controller,\n FormSubmitError: FormSubmitError,\n };\n\n // FormComponent or native form\n const FormComponent = config.FormComponent ?? 'form';\n\n return (\n <FormComponent\n {...resolvedFormProps}\n // eslint-disable-next-line react-hooks/refs -- bug?\n id={utils.formId}\n // eslint-disable-next-line react-hooks/refs -- bug?\n ref={utils.formRef}\n onSubmit={handleSubmit}\n >\n {/** eslint-disable-next-line react-hooks/static-components */}\n {config.FormOutlet ? (\n <config.FormOutlet\n // eslint-disable-next-line react-hooks/refs -- bug?\n {...formInjectorProps}\n />\n ) : (\n children\n )}\n </FormComponent>\n );\n};\n\n//\n\nconst handleOnSubmitInvariants = async <\n TFieldValues extends SafeFieldValues,\n TTransformedValues extends SafeFieldValues,\n TApiValues extends undefined | SafeFieldValues,\n>(\n onBeforeSubmitInvariants: RhfUtilsFormPropsOnBeforeSubmitInvariants<\n TFieldValues,\n TTransformedValues,\n TApiValues\n >,\n data: { input: TFieldValues; output: TTransformedValues; api: TApiValues },\n context: UseRhfUtilsFormOnSubmitContext<\n TFieldValues,\n TTransformedValues,\n TApiValues\n >,\n event: React.BaseSyntheticEvent<SubmitEvent>,\n) => {\n const invariants = await Promise.resolve(\n onBeforeSubmitInvariants(data, context, event),\n );\n\n const falseyFieldsAndMessages = invariants\n .filter(({ validate }) => !validate)\n .map(({ field, message }) => [field, { message }] as const);\n\n if (!falseyFieldsAndMessages.length) return;\n\n throw new context.FormSubmitError(\n Object.fromEntries(falseyFieldsAndMessages) as FormSubmitFieldErrors<\n TFieldValues,\n TApiValues\n >,\n );\n};\n","import { LazyDevToolViaProviders } from '@/devtool/LazyDevToolViaProviders';\n\nimport type { SafeFieldValues } from '../rhf/SafeFieldValuesType';\n\nimport { RhfUtilsFormChildrenViaProviders_Internal } from './_ChildrenViaProviders';\nimport { RhfUtilsFormWithSubmitHandler_Internal } from './_FormWithSubmitHandler';\nimport type {\n RhfUtilsFormProps,\n RhfUtilsFormPropsGetApiValues,\n} from './RhfUtilsFormProps';\n\nexport const RhfUtilsForm = <\n TFieldValues extends SafeFieldValues,\n TTransformedValues extends SafeFieldValues,\n TGetApiValues extends\n | undefined\n | RhfUtilsFormPropsGetApiValues<TTransformedValues, SafeFieldValues>,\n TOnSubmitReturnType,\n TApiValues extends undefined | SafeFieldValues =\n TGetApiValues extends RhfUtilsFormPropsGetApiValues<\n TTransformedValues,\n infer U\n >\n ? U\n : undefined,\n>({\n getApiData,\n // handlers\n onCancel,\n onSubmitInvalid,\n onBeforeSubmitInvariants,\n onBeforeSubmit,\n onSubmit,\n onSubmitSuccess,\n onSubmitError,\n onSubmitFinally,\n //\n Children,\n // attrs\n form,\n className,\n}: RhfUtilsFormProps<\n TFieldValues,\n TTransformedValues,\n TGetApiValues,\n TOnSubmitReturnType,\n TApiValues\n>) => (\n <RhfUtilsFormWithSubmitHandler_Internal\n getApiData={getApiData}\n onSubmitInvalid={onSubmitInvalid}\n onBeforeSubmitInvariants={onBeforeSubmitInvariants}\n onBeforeSubmit={onBeforeSubmit}\n onSubmit={onSubmit}\n onSubmitSuccess={onSubmitSuccess}\n onSubmitError={onSubmitError}\n onSubmitFinally={onSubmitFinally}\n form={form}\n className={className}\n >\n <LazyDevToolViaProviders />\n\n <RhfUtilsFormChildrenViaProviders_Internal\n onCancel={onCancel}\n Children={Children}\n />\n </RhfUtilsFormWithSubmitHandler_Internal>\n);\n","import type { SafeFieldValues } from '@/form/rhf/SafeFieldValuesType';\nimport { RhfUtilsForm } from '@/form/with-handlers-and-children/RhfUtilsForm';\nimport type {\n RhfUtilsFormProps,\n RhfUtilsFormPropsGetApiValues,\n} from '@/form/with-handlers-and-children/RhfUtilsFormProps';\n\nimport type { zodTypeInput, zodTypeOutput } from '../consts';\nimport type { ZodTypeSafeFieldValues } from '../ZodTypeSafeFieldValuesType';\n\ntype Props<\n TSchema extends ZodTypeSafeFieldValues,\n TGetApiValues extends\n | undefined\n | RhfUtilsFormPropsGetApiValues<\n TSchema[typeof zodTypeOutput],\n SafeFieldValues\n >,\n TOnSubmitReturnType,\n TApiValues extends undefined | SafeFieldValues =\n TGetApiValues extends RhfUtilsFormPropsGetApiValues<\n TSchema[typeof zodTypeOutput],\n infer U\n >\n ? U\n : undefined,\n> = React.PropsWithChildren<\n RhfUtilsFormProps<\n TSchema[typeof zodTypeInput],\n TSchema[typeof zodTypeOutput],\n TGetApiValues,\n TOnSubmitReturnType,\n TApiValues\n >\n>;\n\nexport const RhfUtilsZodForm = <\n TSchema extends ZodTypeSafeFieldValues,\n TGetApiValues extends\n | undefined\n | RhfUtilsFormPropsGetApiValues<\n TSchema[typeof zodTypeOutput],\n SafeFieldValues\n >,\n TOnSubmitReturnType,\n TApiValues extends undefined | SafeFieldValues =\n TGetApiValues extends RhfUtilsFormPropsGetApiValues<\n TSchema[typeof zodTypeOutput],\n infer U\n >\n ? U\n : undefined,\n>(\n props: Props<TSchema, TGetApiValues, TOnSubmitReturnType, TApiValues>,\n) => <RhfUtilsForm {...props} />;\n","import type { FlatFieldErrorEntry, FlatFieldErrors } from './types';\n\n/**\n * Filter {@link FlatFieldErrors} by a predicate.\n *\n * (Encapsulates to and from Object entries.)\n */\nexport const 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","import type { FieldError } from 'react-hook-form';\n\n/**\n * Determine if {@link FieldError} is a `ref`'d field error.\n */\nexport const isFieldErrorRefd = (error: FieldError): boolean => !!error.ref;\n","import type { FlatFieldErrorEntry } from './flat/types';\nimport { isFieldErrorRefd } from './isFieldErrorRefd';\n\n/**\n * Determine if {@link FieldError} is a `ref`'d field error.\n */\nexport const isFlatFieldErrorEntryRefd = ([\n ,\n error,\n]: FlatFieldErrorEntry): boolean => isFieldErrorRefd(error);\n","import { makeFlatFieldErrorsFilter } from './flat/filterFlatFieldErrors';\nimport { isFlatFieldErrorEntryRefd } from './isFlatFieldErrorEntryRefd';\n\nexport const getRefdFromFlatFieldErrors = makeFlatFieldErrorsFilter(\n isFlatFieldErrorEntryRefd,\n);\n","import { RhfUtilsNonFieldErrorMarkerHtmlAttribute } from './RhfUtilsNonFieldErrorMarkerHtmlAttribute';\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 getRhfUtilsNonFieldErrorMarkerQuerySelector = (\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 RhfUtilsNonFieldErrorMarkerHtmlAttribute + 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","import { getRhfUtilsNonFieldErrorMarkerQuerySelector } from './RhfUtilsNonFieldErrorMarker.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 */\nexport const isNonFieldErrorMarkerInDOM = (\n path: string,\n parentElement: Pick<HTMLElement, 'querySelector'>,\n): boolean =>\n !!parentElement.querySelector(\n getRhfUtilsNonFieldErrorMarkerQuerySelector(path),\n );\n","export const FormErrorPathRoot = 'root';\n","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 */\nexport const isFormErrorPathRoot = (path: string): boolean =>\n path === FormErrorPathRoot || path.startsWith(FormErrorPathRoot + '.');\n","import type { FieldError } from 'react-hook-form';\n\nimport { isFieldErrorRefd } from '../isFieldErrorRefd';\nimport { isNonFieldErrorMarkerInDOM } from '../nonfield/isNonFieldErrorMarkerInDOM';\nimport { isFormErrorPathRoot } from '../root/isFormErrorPathRoot';\n\nexport const isOrphanFormError = (\n path: string,\n error: FieldError,\n parentElement: Pick<HTMLElement, 'querySelector'>,\n) =>\n // non-field\n !isFieldErrorRefd(error) &&\n // non-root\n !isFormErrorPathRoot(path) &&\n // not marked in DOM\n !isNonFieldErrorMarkerInDOM(path, parentElement);\n","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 */\nexport const getIsFlatFieldErrorEntryOrphanByParentElement =\n (parentElement: Pick<HTMLElement, 'querySelector'>) =>\n ([path, error]: FlatFieldErrorEntry) =>\n isOrphanFormError(path, error, parentElement);\n","import { makeFlatFieldErrorsFilter } from '../flat/filterFlatFieldErrors';\nimport type { FlatFieldErrors } from '../flat/types';\n\nimport { getIsFlatFieldErrorEntryOrphanByParentElement } from './getIsOrphanFormErrorWithParentElement';\n\nexport const getOrphansFromFlatFieldErrors = (\n errors: FlatFieldErrors,\n parentElement: Pick<HTMLElement, 'querySelector'>,\n): FlatFieldErrors =>\n makeFlatFieldErrorsFilter(\n getIsFlatFieldErrorEntryOrphanByParentElement(parentElement),\n )(errors);\n","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 */\nexport const isFlatFieldErrorEntryPathRoot = ([path]: FlatFieldErrorEntry) =>\n isFormErrorPathRoot(path);\n","import { makeFlatFieldErrorsFilter } from '../flat/filterFlatFieldErrors';\n\nimport { isFlatFieldErrorEntryPathRoot } from './isFlatFieldErrorEntryPathRoot';\n\nexport const getRootsFromFlatFieldErrors = makeFlatFieldErrorsFilter(\n isFlatFieldErrorEntryPathRoot,\n);\n","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 | null>;\n}>;\n\n/**\n * Provides a flattened version of the form errors.\n * Allows flattening and filtering to happen once per errors change.\n */\nexport const FlatFieldErrorsContextProvider: React.FC<Props> = ({\n formRef,\n children,\n}) => {\n const { errors } = useFormState();\n\n const all = getFlatFieldErrors(errors);\n\n const orphans =\n // eslint-disable-next-line react-hooks/refs\n formRef.current\n ? getOrphansFromFlatFieldErrors(\n all,\n // eslint-disable-next-line react-hooks/refs\n formRef.current,\n )\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","import React from 'react';\n\nimport type { LastSubmitError } from '../error/LastSubmitErrorType';\nimport type { LastSubmitStatus } from '../status/LastSubmitStatusType';\n\nimport { _LastSubmitContextProvider } from './useLastSubmitContext';\n\ntype Props = React.PropsWithChildren;\n\nexport const LastSubmitContextProvider: React.FC<Props> = ({ children }) => {\n const [error, setError] = React.useState<LastSubmitError>();\n\n const statusRef = React.useRef<LastSubmitStatus>(null);\n\n return (\n <_LastSubmitContextProvider\n value={{\n status: { ref: statusRef },\n\n error: {\n state: error,\n\n reset: () => {\n setError(undefined);\n },\n\n set: (error, event) => {\n setError({ error, event });\n },\n },\n }}\n >\n {children}\n </_LastSubmitContextProvider>\n );\n};\n","import type { SafeFieldValues } from '@/form/rhf/SafeFieldValuesType';\n\n/**\n * Output form values and errors to console.\n */\nexport const 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","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 */\nexport const 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\n//\n\nconst defaultMessage = 'Form errors';\n","import React from 'react';\n\nexport const useRefIfValueWasTrue = (value: boolean) => {\n const hasBooleanChanged = React.useRef(false);\n\n // when value is true, set ref to true\n React.useEffect(() => {\n if (!value) return;\n\n hasBooleanChanged.current = true;\n }, [value]);\n\n const reset = () => {\n hasBooleanChanged.current = false;\n };\n\n return [hasBooleanChanged, reset] as const;\n};\n","import React from 'react';\nimport { useFormState } from 'react-hook-form';\n\nimport type { MaybePromise } from '@/utils/types';\nimport { useRefIfValueWasTrue } from '@/utils/useRefIfValueWasTrue';\n\nexport const useFormOnSubmitted = (\n callback?: (success: boolean) => MaybePromise<unknown>,\n options?: { successful?: boolean },\n) => {\n const { isSubmitSuccessful, isSubmitting } = useFormState();\n\n const [wasSubmitting, resetWasSubmitting] =\n useRefIfValueWasTrue(isSubmitting);\n\n // on successful submit, call callback\n React.useEffect(() => {\n if (!callback) return;\n\n // if currently submitting, ignore\n if (isSubmitting) return;\n\n // wait for submit to finish\n if (!wasSubmitting.current) return;\n\n // always reset to wait for next submit\n resetWasSubmitting();\n\n // check success against options passed\n if (\n options?.successful === undefined || // if option not specified, call on any submit\n isSubmitSuccessful === options.successful // otherwise, call only if matches\n ) {\n callback(isSubmitSuccessful);\n }\n\n // eslint-disable-next-line react-hooks/exhaustive-deps -- only track isSubmitting -- so success is checked each time\n }, [isSubmitting]);\n};\n","import { useFormContext } from 'react-hook-form';\n\nimport { useFormOnSubmitted } from './useFormOnSubmitted';\n\n/**\n * Configuration options for {@link useResetFormOnSubmitted}.\n */\nexport type UseResetFormOnSubmittedOptions =\n // disabled\n | undefined\n\n // enabled\n | {\n /**\n * Reset values on successful submit.\n * - `defaults`: reset current values to defaults\n * - `current`: reset defaults to current values\n */\n success?: { values: 'defaults' | 'current' };\n\n /**\n * Reset values to defaults on submit error.\n */\n error?: { values: 'defaults' };\n };\n\n/**\n * Control resetting of values and (some) state (e.g., `isDirty`) after form submitted.\n *\n * `isDirty` and other state is reset, but submit-related state is preserved, as well as errors.\n *\n * Use cases:\n * - on success:\n * - `defaults`: reset current values to defaults (e.g., clear form)\n * - `current`: reset defaults to current values (e.g., keep values)\n * - on error:\n * - reset current values to default values (e.g., submitOnChange reset)\n *\n * See `Rules` section: https://react-hook-form.com/api/useform/reset/\n * Specifically: \"- It's recommended to reset inside useEffect after submission.\"\n */\nexport const useResetFormOnSubmitted = (\n options: UseResetFormOnSubmittedOptions,\n) => {\n const { getValues, reset } = useFormContext();\n\n useFormOnSubmitted((success) => {\n if (!options) return;\n\n const whichValues = options[success ? 'success' : 'error']?.values;\n\n if (!whichValues) return;\n\n const keepValues = whichValues === 'current';\n\n const values = keepValues\n ? getValues() // current values\n : undefined; // default values\n\n reset(values, {\n // keep submit stuff for tracking relevant state (e.g., `useFormOnSubmitSuccessful`)\n keepIsSubmitSuccessful: true,\n keepIsSubmitted: true,\n keepSubmitCount: true,\n\n /**\n * This is necessary when setting default values to current values (lest form stop updating).\n *\n * Technically, we are keeping values and resetting default values to same values.\n *\n * Steps to repro:\n * - RhfUtilsClientConfig with resetOnSubmitted set to success values to current\n * - remove `keepValues` prop from reset\n * - create valid form, submit\n * - form values should be unchanged\n * - unexpectedly: can no longer type into input\n */\n keepValues,\n\n // keep errors in the case of unsuccessful submit\n keepErrors: true,\n });\n });\n};\n","import React from 'react';\n\n/**\n * Use to determine if first render has run.\n *\n * (Supports strict mode.)\n */\nexport const useIsFirstRender = () => {\n const isFirstRender = React.useRef(DEFAULT_STATE);\n\n // on mount, mark as not first render\n React.useEffect(() => {\n if (isFirstRender.current) {\n isFirstRender.current = !DEFAULT_STATE;\n }\n\n // on dismount (or before additional strictmode run), reset state\n return () => {\n isFirstRender.current = DEFAULT_STATE;\n };\n }, []);\n\n return isFirstRender;\n};\n\nconst DEFAULT_STATE = true;\n","import React from 'react';\n\n/**\n * React hook to debounce onChange event callback.\n *\n * Returns debounced state setter (uses ref internally).\n *\n * When debounce delay has elapsed after setting value,\n * onChange callback is called with latest value.\n *\n * @returns `[setValueDebounced]`\n */\nexport const useDebouncedOnChangeValue = <TValue>({\n onChange,\n delay,\n}: {\n onChange: (value: TValue) => void;\n delay: number;\n}) => {\n /**\n * State. (Via ref as it should not re-render.)\n */\n const state = React.useRef<{\n value: TValue;\n timer: NodeJS.Timeout;\n }>(null);\n\n // internal fns\n\n /** Callback for `setTimeout`. */\n const _onTimeout = () => {\n // typeguard (this should never happen)\n if (!state.current) return;\n\n // call consumer\n onChange(state.current.value);\n\n // reset state\n state.current = null;\n };\n\n const _clearTimeout = () => {\n if (state.current) clearTimeout(state.current.timer);\n };\n\n // cleanup\n\n React.useEffect(\n // return timeout clearer\n () => _clearTimeout,\n [],\n );\n\n // return\n\n const setValueDebounced = (value: TValue) => {\n // if there is active timeout, clear it\n _clearTimeout();\n\n // update state\n state.current = {\n // value being tracked\n value,\n // new timer\n timer: setTimeout(_onTimeout, delay),\n };\n };\n\n return [setValueDebounced] as const;\n};\n","import React from 'react';\n\nimport { useFormRequestSubmit } from '@/form/utils/useFormRequestSubmit';\n\nimport { useDebouncedOnChangeValue } from '@/utils/useDebouncedOnChangeValue';\n\nexport type UseSubmitFormOnEventDebouncedOptions = {\n /** Milliseconds to debounce form submission. (Default is none.) */\n debounce?: number;\n};\n\n/**\n * Internal, shared hook to setup debounced callback for OnChange hooks.\n */\nexport const useSubmitFormOnEventDebounced = (\n formRef: React.RefObject<HTMLFormElement | null>,\n options?: UseSubmitFormOnEventDebouncedOptions,\n) => {\n const requestSubmit = useFormRequestSubmit(formRef);\n\n const [setOnChangeDebounced] = useDebouncedOnChangeValue<unknown>({\n delay: options?.debounce ?? 0,\n\n // on change value after debounce\n onChange: () => {\n requestSubmit();\n },\n });\n\n return setOnChangeDebounced;\n};\n","import React from 'react';\nimport { useFormState, useWatch } from 'react-hook-form';\n\nimport { useIsFirstRender } from '@/utils/useIsFirstRender';\n\nimport { useSubmitFormOnEventDebounced } from './useSubmitFormOnEvent';\n\nexport type UseSubmitFormOnWatchOptions = {\n /** Milliseconds to debounce form submission. (Default is none.) */\n debounce: number;\n};\n\n/**\n * Watches for changes in form values.\n *\n * Caveats:\n * - uses RHF's useWatch\n * - triggers change immediately as user types, so use sensible debounce time\n * - does not cover uncontrolled inputs\n */\nexport const useSubmitFormOnWatch = (\n formRef: React.RefObject<HTMLFormElement | null>,\n options?: UseSubmitFormOnWatchOptions,\n) => {\n const setOnChangeDebounced = useSubmitFormOnEventDebounced(formRef, {\n debounce: options?.debounce,\n });\n\n const watch = useWatch();\n const { isValid, isDirty, isValidating, isSubmitting } = useFormState();\n\n /**\n * In some cases, {@link watch} reference object can change,\n * even when no input has been made by user.\n */\n const watchJson = React.useMemo(() => JSON.stringify(watch), [watch]);\n\n const isFirstRender = useIsFirstRender();\n\n React.useEffect(\n // on form values/state change, call callback\n () => {\n if (isFirstRender.current) return; // ignore initial render (i.e., don't immediately submit)\n // form state\n if (isValidating) return; // wait for validation\n if (isSubmitting) return; // do not re-submit\n if (!isValid) return;\n if (!isDirty) return;\n\n setOnChangeDebounced(watch);\n },\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [isValid, isDirty, watchJson, isValidating],\n // - isValidating bc we need to re-trigger after validation complete\n // - e.g., single keystroke making input in/valid; we have to wait\n // - isSubmitting not included bc would create infinite loop of submits after first submission\n // - expect form to block changes while submitting to avoid changes that get swallowed\n );\n};\n","import React from 'react';\n\nimport { useRhfUtilsClientConfig } from '@/client/config/context/useRhfUtilsClientConfig';\n\nimport { useFlatFieldErrorsContextOutput } from '@/errors/flat/context/useFlatFieldErrorsContextOutput';\n\nimport type { RhfUtilsFormOptions } from '@/form/options/RhfUtilsFormOptionsType';\n\nimport { useResetFormOnSubmitted } from '@/submit/useResetFormOnSubmitted';\nimport { useSubmitFormOnWatch } from '@/submit/useSubmitFormOnWatch';\n\nimport { _RhfUtilsContextProvider } from './useRhfUtilsContext';\n\nexport type RhfUtilsContextProviderProps = {\n formId: string;\n formRef: React.RefObject<HTMLFormElement | null>;\n\n /** Consumer-supplied options and values. */\n options: RhfUtilsFormOptions;\n};\n\nexport const RhfUtilsContextProvider: React.FC<\n React.PropsWithChildren<RhfUtilsContextProviderProps>\n> = ({\n formId,\n formRef,\n options,\n //\n children,\n}) => {\n const [memoOptions] = React.useState(options);\n\n const config = useRhfUtilsClientConfig();\n\n useFlatFieldErrorsContextOutput(config.fieldErrors?.output);\n\n (memoOptions.submitOnWatch ? useSubmitFormOnWatch : undefined)?.(\n formRef,\n memoOptions.submitOnWatch,\n );\n\n useResetFormOnSubmitted(memoOptions.resetOnSubmitted);\n\n return (\n <_RhfUtilsContextProvider\n value={{\n formId,\n formRef,\n options,\n }}\n >\n {children}\n </_RhfUtilsContextProvider>\n );\n};\n","import type { RhfUtilsFormOptions } from './RhfUtilsFormOptionsType';\n\nexport const getRhfUtilsFormResolvedOptions = (\n global: RhfUtilsFormOptions | undefined,\n instance: RhfUtilsFormOptions | undefined,\n): RhfUtilsFormOptions => ({\n ...global,\n ...instance,\n\n // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing -- false positive\n ...((global?.resetOnSubmitted || instance?.resetOnSubmitted) && {\n resetOnSubmitted: {\n ...global?.resetOnSubmitted,\n ...instance?.resetOnSubmitted,\n },\n }),\n});\n","import React from 'react';\n\nimport type { RhfUtilsClientConfig } from '@/client/config/RhfUtilsClientConfigType';\n\nimport { getRhfUtilsFormResolvedOptions } from './getRhfUtilsFormResolvedOptions';\nimport type { RhfUtilsFormOptions } from './RhfUtilsFormOptionsType';\n\nexport const useRhfUtilsFormResolvedOptions = (\n config: RhfUtilsClientConfig,\n options: RhfUtilsFormOptions | undefined,\n) =>\n React.useMemo(\n () => getRhfUtilsFormResolvedOptions(config.defaults?.options, options),\n\n // eslint-disable-next-line react-hooks/exhaustive-deps, react-hooks/use-memo\n [JSON.stringify(options)],\n );\n","import type { UseRhfUtilsFormResolvedDefaults } from '../defaults/UseRhfUtilsFormResolvedDefaultsType';\n\nimport type { SafeFieldValues } from './SafeFieldValuesType';\nimport type {\n RhfUseFormGlobalProps,\n RhfUseFormInstanceProps,\n} from './UseFormPropsType';\n\nexport const getRhfUtilsFormResolvedRhfProps = <\n TFieldValues extends SafeFieldValues,\n TTransformedValues extends SafeFieldValues,\n>(\n global: RhfUseFormGlobalProps | undefined,\n instance:\n RhfUseFormInstanceProps<TFieldValues, TTransformedValues> | undefined,\n): UseRhfUtilsFormResolvedDefaults<\n TFieldValues,\n TTransformedValues\n>['rhf'] => ({\n ...global,\n ...instance,\n});\n","import type { Resolver, UseFormProps } from 'react-hook-form';\nimport { useForm as useRhfForm } from 'react-hook-form';\n\nimport type { RhfUtilsClientConfig } from '@/client/config/RhfUtilsClientConfigType';\n\nimport type { SafeFieldValues } from '../rhf/SafeFieldValuesType';\nimport type { RhfUseFormInstanceProps } from '../rhf/UseFormPropsType';\n\nimport { getRhfUtilsFormResolvedRhfProps } from './getRhfUtilsFormResolvedRhfProps';\n\nexport const useRhfFormWithResolvedProps = <\n TFieldValues extends SafeFieldValues,\n TTransformedValues extends SafeFieldValues,\n>(\n props: RhfUseFormInstanceProps<TFieldValues, TTransformedValues> | undefined,\n config: RhfUtilsClientConfig,\n defaultValues: UseFormProps<\n TFieldValues,\n unknown,\n TTransformedValues\n >['defaultValues'],\n resolver?: Resolver<TFieldValues, unknown, TTransformedValues>,\n) =>\n useRhfForm<TFieldValues, unknown, TTransformedValues>({\n ...getRhfUtilsFormResolvedRhfProps(config.defaults?.rhf, props),\n resolver,\n defaultValues,\n });\n","import React from 'react';\nimport { FormProvider as RhfFormProvider } from 'react-hook-form';\n\nimport { useRhfUtilsClientConfig } from '@/client/config/context/useRhfUtilsClientConfig';\n\nimport { FlatFieldErrorsContextProvider } from '@/errors/flat/context/FlatFieldErrorsContextProvider';\n\nimport { LastSubmitContextProvider } from '@/submit/last/context/LastSubmitContextProvider';\n\nimport { RhfUtilsContextProvider } from '../context/utils/RhfUtilsContextProvider';\nimport { useRhfUtilsFormResolvedOptions } from '../options/useRhfUtilsFormResolvedOptions';\nimport { FormRelaySetter } from '../relay/set/FormRelaySetter';\nimport type { SafeFieldValues } from '../rhf/SafeFieldValuesType';\nimport { useRhfFormWithResolvedProps } from '../rhf/useRhfFormWithResolvedProps';\n\nimport type { RhfUtilsFormProvidersProps } from './RhfUtilsFormProvidersPropsType';\n\ntype Props<\n TFieldValues extends SafeFieldValues,\n TTransformedValues extends SafeFieldValues,\n> = React.PropsWithChildren<\n RhfUtilsFormProvidersProps<TFieldValues, TTransformedValues>\n>;\n\nexport function RhfUtilsFormProviders<\n TFieldValues extends SafeFieldValues,\n TTransformedValues extends SafeFieldValues,\n>({\n formId,\n rhf,\n resolver,\n defaultValues,\n options,\n relay,\n //\n children,\n}: Props<TFieldValues, TTransformedValues>) {\n // global config\n\n const config = useRhfUtilsClientConfig();\n\n // id\n\n const reactId = React.useId();\n // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing -- replace empty string\n const id = formId || reactId;\n\n // ref\n\n const formRef = React.useRef<HTMLFormElement>(null);\n\n // rhf\n\n const resolvedRhf = useRhfFormWithResolvedProps(\n rhf,\n config,\n defaultValues,\n resolver,\n );\n\n // options\n\n const resolvedOptions = useRhfUtilsFormResolvedOptions(config, options);\n\n //\n\n return (\n <RhfFormProvider {...resolvedRhf}>\n <FlatFieldErrorsContextProvider formRef={formRef}>\n <RhfUtilsContextProvider\n formId={id}\n formRef={formRef}\n options={resolvedOptions}\n >\n <FormRelaySetter options={relay} />\n\n <LastSubmitContextProvider>{children}</LastSubmitContextProvider>\n </RhfUtilsContextProvider>\n </FlatFieldErrorsContextProvider>\n </RhfFormProvider>\n );\n}\n","import { zodResolver } from '@hookform/resolvers/zod';\nimport type { Resolver } from 'react-hook-form';\n\nimport type { zodTypeInput, zodTypeOutput } from './consts';\nimport type { ZodTypeSafeFieldValues } from './ZodTypeSafeFieldValuesType';\n\nexport const getZodResolver = <\n TSchema extends ZodTypeSafeFieldValues,\n TFieldValues extends TSchema[typeof zodTypeInput],\n TTransformedValues extends TSchema[typeof zodTypeOutput],\n>(\n schema: TSchema,\n) => zodResolver(schema) as Resolver<TFieldValues, unknown, TTransformedValues>;\n","import { RhfUtilsFormProviders } from '@/form/providers/RhfUtilsFormProviders';\nimport type { RhfUtilsFormProvidersProps } from '@/form/providers/RhfUtilsFormProvidersPropsType';\n\nimport type { zodTypeInput, zodTypeOutput } from '../consts';\nimport { getZodResolver } from '../getZodResolver';\nimport type { ZodTypeSafeFieldValues } from '../ZodTypeSafeFieldValuesType';\n\ntype Props<TSchema extends ZodTypeSafeFieldValues> = React.PropsWithChildren<\n { schema: TSchema } &\n //\n RhfUtilsFormProvidersProps<\n TSchema[typeof zodTypeInput],\n TSchema[typeof zodTypeOutput]\n >\n>;\n\nexport const RhfUtilsZodFormProviders = <\n TSchema extends ZodTypeSafeFieldValues,\n>({\n schema,\n children,\n ...props\n}: Props<TSchema>) => (\n <RhfUtilsFormProviders {...props} resolver={getZodResolver(schema)}>\n {children}\n </RhfUtilsFormProviders>\n);\n","import { RhfUtilsFormProviders } from '../providers/RhfUtilsFormProviders';\nimport type { RhfUtilsFormProvidersProps } from '../providers/RhfUtilsFormProvidersPropsType';\nimport type { SafeFieldValues } from '../rhf/SafeFieldValuesType';\nimport { RhfUtilsForm } from '../with-handlers-and-children/RhfUtilsForm';\nimport type {\n RhfUtilsFormProps,\n RhfUtilsFormPropsGetApiValues,\n} from '../with-handlers-and-children/RhfUtilsFormProps';\n\nimport type { RhfUtilsFormWithProvidersProps } from './RhfUtilsFormWithProvidersProps';\n\n/**\n * Form providers (with utils) with immediate descendent {@link RhfUtilsForm}.\n * (Syntactic sugar for {@link useRhfUtilsForm}. Use this for most applications.)\n */\nexport function RhfUtilsFormWithProviders<\n TFieldValues extends SafeFieldValues,\n TTransformedValues extends SafeFieldValues,\n TGetApiValues extends\n | undefined\n | RhfUtilsFormPropsGetApiValues<TTransformedValues, SafeFieldValues>,\n TOnSubmitReturnType,\n TApiValues extends undefined | SafeFieldValues =\n TGetApiValues extends RhfUtilsFormPropsGetApiValues<\n TTransformedValues,\n infer U\n >\n ? U\n : undefined,\n>({\n getApiData,\n // provider\n resolver,\n rhf,\n defaultValues,\n options,\n relay,\n // form\n onCancel,\n onSubmitInvalid,\n onBeforeSubmitInvariants,\n onBeforeSubmit,\n onSubmit,\n onSubmitSuccess,\n onSubmitError,\n onSubmitFinally,\n Children,\n form,\n formId,\n className,\n}: RhfUtilsFormWithProvidersProps<\n TFieldValues,\n TTransformedValues,\n TGetApiValues,\n TOnSubmitReturnType,\n TApiValues\n>) {\n const providerProps: RhfUtilsFormProvidersProps<\n TFieldValues,\n TTransformedValues\n > = {\n formId,\n resolver,\n rhf,\n defaultValues,\n options,\n relay,\n };\n\n const formProps: RhfUtilsFormProps<\n TFieldValues,\n TTransformedValues,\n TGetApiValues,\n TOnSubmitReturnType,\n TApiValues\n > = {\n getApiData,\n onCancel,\n onSubmitInvalid,\n onBeforeSubmitInvariants,\n onBeforeSubmit,\n onSubmit,\n onSubmitSuccess,\n onSubmitError,\n onSubmitFinally,\n Children,\n form,\n className,\n };\n\n return (\n <RhfUtilsFormProviders {...providerProps}>\n <RhfUtilsForm {...formProps} />\n </RhfUtilsFormProviders>\n );\n}\n","import type { RhfUtilsFormProvidersProps } from '@/form/providers/RhfUtilsFormProvidersPropsType';\nimport type { SafeFieldValues } from '@/form/rhf/SafeFieldValuesType';\nimport type {\n RhfUtilsFormProps,\n RhfUtilsFormPropsGetApiValues,\n} from '@/form/with-handlers-and-children/RhfUtilsFormProps';\nimport { RhfUtilsFormWithProviders } from '@/form/with-providers/RhfUtilsFormWithProviders';\n\nimport type { zodTypeInput, zodTypeOutput } from '../consts';\nimport { getZodResolver } from '../getZodResolver';\nimport type { ZodTypeSafeFieldValues } from '../ZodTypeSafeFieldValuesType';\n\ntype Props<\n TSchema extends ZodTypeSafeFieldValues,\n TGetApiValues extends\n | undefined\n | RhfUtilsFormPropsGetApiValues<TTransformedValues, SafeFieldValues>,\n TOnSubmitReturnType,\n TFieldValues extends TSchema[typeof zodTypeInput] =\n TSchema[typeof zodTypeInput],\n TTransformedValues extends TSchema[typeof zodTypeOutput] =\n TSchema[typeof zodTypeOutput],\n TApiValues extends undefined | SafeFieldValues =\n TGetApiValues extends RhfUtilsFormPropsGetApiValues<\n TTransformedValues,\n infer U\n >\n ? U\n : undefined,\n> = React.PropsWithChildren<\n { schema: TSchema } &\n // provider\n Omit<\n RhfUtilsFormProvidersProps<TFieldValues, TTransformedValues>,\n 'resolver'\n > &\n // form\n RhfUtilsFormProps<\n TFieldValues,\n TTransformedValues,\n TGetApiValues,\n TOnSubmitReturnType,\n TApiValues\n >\n>;\n\nexport const RhfUtilsZodFormWithProviders = <\n TSchema extends ZodTypeSafeFieldValues,\n TGetApiValues extends\n | undefined\n | RhfUtilsFormPropsGetApiValues<TTransformedValues, SafeFieldValues>,\n TOnSubmitReturnType,\n TFieldValues extends TSchema[typeof zodTypeInput] =\n TSchema[typeof zodTypeInput],\n TTransformedValues extends TSchema[typeof zodTypeOutput] =\n TSchema[typeof zodTypeOutput],\n TApiValues extends undefined | SafeFieldValues =\n TGetApiValues extends RhfUtilsFormPropsGetApiValues<\n TTransformedValues,\n infer U\n >\n ? U\n : undefined,\n>({\n schema,\n ...props\n}: Props<\n TSchema,\n TGetApiValues,\n TOnSubmitReturnType,\n TFieldValues,\n TTransformedValues,\n TApiValues\n>) => (\n <RhfUtilsFormWithProviders {...props} resolver={getZodResolver(schema)} />\n);\n","/**\n * @license @paragrav/rhf-utils\n *\n * Copyright (c) 2024-present paragrav.dev\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\nexport type { Register } from '../Register';\nexport * from './config';\nexport * from './errors';\nexport * from './form';\nexport * from './submit';\nexport * from './zod';\n"],"mappings":";;;;;;AAIA,MAAa,uCAAuC,MAAM,cAExD,KAAA,CAAS;;;ACMX,MAAa,gCAAiD,EAC5D,QACA,eACI;CACJ,MAAM,CAAC,cAAc,MAAM,SAAS,UAAU,CAAC,CAAC;CAEhD,OACE,oBAAC,qCAAqC,UAAtC;EAA+C,OAAO;EACpD,UAAA,oBAAC,0BAAD,EAA2B,SAAmC,CAAA;CACjB,CAAA;AAEnD;;;ACTA,MAAM,EACJ,UAAU,gCACV,aAAa,8BACX,cAAsC;;;;;;;;ACR1C,MAAa,gDAAgD;CAC3D,MAAM,SAAS,0BAA0B;CAazC,OAXuB,MAAM,cAAc;EAEzC,IAAI,CAAC,OAAO,WAAW,OAAO;EAC9B,IAAI,CAAC,OAAO,YAAY,OAAO;EAG/B,OACE,OAAO,KAAK,OAAO,OAAO,CAAC,CAAC,WAAW,OAAO,KAAK,OAAO,GAAG,CAAC,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c,4BAClB,KACA,QACA,eACA,QACF;CAIA,MAAM,kBAAkB,+BAA+B,QAAQ,OAAO;CAItE,OACE,oBAACC,cAAD;EAAiB,GAAI;EACnB,UAAA,oBAAC,gCAAD;GAAyC;GACvC,UAAA,qBAAC,yBAAD;IACE,QAAQ;IACC;IACT,SAAS;IAHX,UAAA,CAKE,oBAAC,iBAAD,EAAiB,SAAS,MAAQ,CAAA,GAElC,oBAAC,2BAAD,EAA4B,SAAoC,CAAA,CACzC;;EACK,CAAA;CACjB,CAAA;AAErB;;;AC3EA,MAAa,kBAKX,WACG,YAAY,MAAM;;;ACIvB,MAAa,4BAEX,EACA,QACA,UACA,GAAG,YAEH,oBAAC,uBAAD;CAAuB,GAAI;CAAO,UAAU,eAAe,MAAM;CAC9D;AACoB,CAAA;;;;;;;ACVzB,SAAgB,0BAcd,EACA,YAEA,UACA,KACA,eACA,SACA,OAEA,UACA,iBACA,0BACA,gBACA,UACA,iBACA,eACA,iBACA,UACA,MACA,QACA,aAOC;CACD,MAAM,gBAGF;EACF;EACA;EACA;EACA;EACA;EACA;CACF;CAEA,MAAM,YAMF;EACF;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACF;CAEA,OACE,oBAAC,uBAAD;EAAuB,GAAI;EACzB,UAAA,oBAAC,cAAD,EAAc,GAAI,UAAY,CAAA;CACT,CAAA;AAE3B;;;ACjDA,MAAa,gCAiBX,EACA,QACA,GAAG,YASH,oBAAC,2BAAD;CAA2B,GAAI;CAAO,UAAU,eAAe,MAAM;AAAI,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.js","names":["RhfController","useRhfForm","RhfFormProvider"],"sources":["../../src/client/config/context/RhfUtilsClientConfigContext.tsx","../../src/client/config/context/RhfUtilsClientConfigProvider.tsx","../../src/errors/flat/context/useFlatFieldErrorsContext.ts","../../src/errors/flat/context/useFlatFieldErrorsContextHasOnlyOrphans.ts","../../src/errors/nonfield/RhfUtilsNonFieldErrorMarkerHtmlAttribute.ts","../../src/errors/nonfield/RhfUtilsNonFieldErrorMarker.tsx","../../src/form/utils/useFormRequestSubmit.ts","../../src/submit/error/FormSubmitError.ts","../../src/submit/last/context/useLastSubmitContext.ts","../../src/devtool/LazyDevTool.tsx","../../src/devtool/LazyDevToolViaProviders.tsx","../../src/form/_Controller.tsx","../../src/client/config/context/useRhfUtilsClientConfig.ts","../../src/submit/useRhfUtilsFormOnSubmitContext.ts","../../src/form/utils/useHandleCancelWithCheckIfCanBe.ts","../../src/form/utils/useHandleCancelWithCheckIfCanBeViaProviders.ts","../../src/form/with-handlers-and-children/_ChildrenViaProviders.tsx","../../src/submit/error/setCtxErrorsByFormSubmitFieldErrors.ts","../../src/form/defaults/form/getRhfUtilsFormResolvedFormProps.ts","../../src/form/defaults/form/useRhfUtilsFormResolvedFormProps.ts","../../src/submit/last/context/useLastSubmitErrorContextWith.ts","../../src/form/with-handlers-and-children/_useHandleSubmit.ts","../../src/form/with-handlers-and-children/_FormWithSubmitHandler.tsx","../../src/form/with-handlers-and-children/RhfUtilsForm.tsx","../../src/resolvers/zod/form/RhfUtilsZodForm.tsx","../../src/errors/flat/filterFlatFieldErrors.ts","../../src/errors/isFieldErrorRefd.ts","../../src/errors/isFlatFieldErrorEntryRefd.ts","../../src/errors/getRefdFromFlatFieldErrors.ts","../../src/errors/nonfield/RhfUtilsNonFieldErrorMarker.utils.ts","../../src/errors/nonfield/isNonFieldErrorMarkerInDOM.ts","../../src/errors/root/consts.ts","../../src/errors/root/isFormErrorPathRoot.ts","../../src/errors/orphan/isOrphanFormError.ts","../../src/errors/orphan/getIsOrphanFormErrorWithParentElement.ts","../../src/errors/orphan/getOrphansFromFlatFieldErrors.ts","../../src/errors/root/isFlatFieldErrorEntryPathRoot.ts","../../src/errors/root/getRootsFromFlatFieldErrors.ts","../../src/errors/flat/context/FlatFieldErrorsContextProvider.tsx","../../src/submit/last/context/LastSubmitContextProvider.tsx","../../src/errors/output/consoleErrors.ts","../../src/errors/flat/context/useFlatFieldErrorsContextOutput.ts","../../src/utils/useRefIfValueWasTrue.ts","../../src/submit/useFormOnSubmitted.ts","../../src/submit/useResetFormOnSubmitted.ts","../../src/utils/useIsFirstRender.ts","../../src/utils/useDebouncedOnChangeValue.ts","../../src/submit/useSubmitFormOnEvent.ts","../../src/submit/useSubmitFormOnWatch.ts","../../src/form/context/utils/RhfUtilsContextProvider.tsx","../../src/form/options/getRhfUtilsFormResolvedOptions.ts","../../src/form/options/useRhfUtilsFormResolvedOptions.ts","../../src/form/rhf/getRhfUtilsFormResolvedRhfProps.ts","../../src/form/rhf/useRhfFormWithResolvedProps.ts","../../src/form/providers/RhfUtilsFormProviders.tsx","../../src/resolvers/zod/getZodResolver.ts","../../src/resolvers/zod/providers/RhfUtilsZodFormProviders.tsx","../../src/form/with-providers/RhfUtilsFormWithProviders.tsx","../../src/resolvers/zod/with-providers/RhfUtilsZodFormWithProviders.tsx","../../src/_exports/index.ts"],"sourcesContent":["import React from 'react';\n\nimport type { RhfUtilsClientConfig } from '../RhfUtilsClientConfigType';\n\nexport const RhfUtilsClientConfigContext_Internal = React.createContext<\n RhfUtilsClientConfig | undefined\n>(undefined);\n","import React from 'react';\n\nimport { FormRelayContextProvider } from '@/form/relay/context/FormRelayContextProvider';\n\nimport type { RhfUtilsClientConfig } from '../RhfUtilsClientConfigType';\n\nimport { RhfUtilsClientConfigContext_Internal } from './RhfUtilsClientConfigContext';\n\ntype Props = React.PropsWithChildren<{\n config?: RhfUtilsClientConfig;\n}>;\n\nexport const RhfUtilsClientConfigProvider: React.FC<Props> = ({\n config,\n children,\n}) => {\n const [memoConfig] = React.useState(config ?? {});\n\n return (\n <RhfUtilsClientConfigContext_Internal.Provider value={memoConfig}>\n <FormRelayContextProvider>{children}</FormRelayContextProvider>\n </RhfUtilsClientConfigContext_Internal.Provider>\n );\n};\n","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 { _FormErrorsFlatContextProvider, useFlatFieldErrorsContext };\n","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 */\nexport const 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","/**\n * HTML data attribute for {@link RhfUtilsNonFieldErrorMarker}.\n */\nexport const RhfUtilsNonFieldErrorMarkerHtmlAttribute =\n 'data-rhfutils-nonfield-error-marker-path';\n","import { RhfUtilsNonFieldErrorMarkerHtmlAttribute } from './RhfUtilsNonFieldErrorMarkerHtmlAttribute';\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 */\nexport const RhfUtilsNonFieldErrorMarker: React.FC<Props> = ({ path }) => {\n const dataAttribute = {\n [RhfUtilsNonFieldErrorMarkerHtmlAttribute]: 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","import React from 'react';\n\n/**\n * Get callback to trigger submit manually on form.\n *\n * Note: `submitter` is optional, but is required to be a submit button.\n *\n * @link https://developer.mozilla.org/docs/Web/API/HTMLFormElement/requestSubmit\n */\nexport const useFormRequestSubmit = (\n ref: React.RefObject<HTMLFormElement | null>,\n): HTMLFormElement['requestSubmit'] =>\n React.useCallback(\n (submitter) => {\n // typeguard (should never happen at runtime when callback is called)\n if (!ref.current) throw new Error();\n\n requestSubmitByForm(ref.current, submitter);\n },\n [ref],\n );\n\n//\n\nconst requestSubmitByForm = (\n form: Pick<HTMLFormElement, 'requestSubmit'>, // narrow to avoid `{[string]: any}` type\n submitter?: HTMLElement | null, // submit button\n) => {\n form.requestSubmit(submitter);\n};\n","import type { SafeFieldValues } from '@/form/rhf/SafeFieldValuesType';\n\nimport type { FormSubmitFieldErrors } from './FormSubmitFieldErrors';\n\nexport class FormSubmitError<\n TFieldValues extends SafeFieldValues = SafeFieldValues,\n TApiValues extends undefined | SafeFieldValues = undefined,\n> extends Error {\n constructor(\n public errors: FormSubmitFieldErrors<TFieldValues, TApiValues>,\n message?: string, // error message\n // options?: ErrorOptions, // requires es2022\n ) {\n super(message);\n }\n}\n","import { createContext } from '@/utils/createContext';\n\nimport type {\n LastSubmitContext,\n LastSubmitContextRead,\n} from './LastSubmitContextType';\n\nconst {\n Provider: _LastSubmitContextProvider,\n useRequired: _useLastSubmitContext,\n} = createContext<LastSubmitContext>();\n\nexport { _LastSubmitContextProvider, _useLastSubmitContext };\n\n//\n\nexport const useLastSubmit = (): LastSubmitContextRead => {\n const lastSubmit = _useLastSubmitContext();\n\n return {\n statusRef: lastSubmit.status.ref,\n error: lastSubmit.error.state,\n };\n};\n\nexport const useLastSubmitStatus = () => useLastSubmit().statusRef;\n\nexport const useLastSubmitError = () => useLastSubmit().error;\n","import type { DevtoolUIProps } from '@hookform/devtools/dist/devToolUI';\nimport React from 'react';\n\nconst LazyRhfDevTool = React.lazy(() =>\n import('@hookform/devtools').then((res) => ({\n default: res.DevTool,\n })),\n);\n\ntype LazyDevToolProps = {\n config?: boolean | Pick<DevtoolUIProps, 'placement' | 'styles'>;\n};\n\n/**\n * Lazy-loaded RHF DevTool.\n */\nexport const LazyDevTool: React.FC<LazyDevToolProps> = ({ config }) => {\n const [memoConfig] = React.useState(config);\n\n // early escape for non-dev builds\n if (!memoConfig) return null;\n\n const props = typeof memoConfig === 'object' ? memoConfig : undefined;\n\n return (\n <React.Suspense>\n <LazyRhfDevTool {...props} />\n </React.Suspense>\n );\n};\n","import { useRhfUtilsContext } from '@/form/context/utils/useRhfUtilsContext';\n\nimport { LazyDevTool } from './LazyDevTool';\n\nexport const LazyDevToolViaProviders: React.FC = () => {\n const utils = useRhfUtilsContext();\n\n return <LazyDevTool config={utils.options.devTool} />;\n};\n","import type { ControllerProps, FieldPath } from 'react-hook-form';\nimport { Controller as RhfController } from 'react-hook-form';\n\nimport type { SafeFieldValues } from './rhf/SafeFieldValuesType';\n\nexport type _ControllerProps<\n TFieldValues extends SafeFieldValues,\n TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>,\n> = Omit<ControllerProps<TFieldValues, TName>, 'control'>;\n\nexport const _Controller = <\n TFieldValues extends SafeFieldValues,\n TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>,\n>(\n props: _ControllerProps<TFieldValues, TName>,\n) => <RhfController {...props} />;\n","import React from 'react';\n\nimport { RhfUtilsClientConfigContext_Internal } from './RhfUtilsClientConfigContext';\n\nexport const useRhfUtilsClientConfig = () => {\n const ctx = React.useContext(RhfUtilsClientConfigContext_Internal);\n\n if (ctx === undefined) throw new Error();\n\n return ctx;\n};\n","import { useFormContext } from 'react-hook-form';\n\nimport { useRhfUtilsContext } from '@/form/context/utils/useRhfUtilsContext';\nimport type { SafeFieldValues } from '@/form/rhf/SafeFieldValuesType';\n\nimport { FormSubmitError } from './error/FormSubmitError';\nimport { useLastSubmit } from './last/context/useLastSubmitContext';\nimport type { UseRhfUtilsFormOnSubmitContext } from './UseRhfUtilsFormOnSubmitContextType';\n\nexport const useRhfUtilsFormOnSubmitContext = <\n TFieldValues extends SafeFieldValues = SafeFieldValues,\n TTransformedValues extends SafeFieldValues = TFieldValues,\n>(): UseRhfUtilsFormOnSubmitContext<TFieldValues, TTransformedValues> => {\n const utilsCtx = useRhfUtilsContext();\n\n const lastSubmitCtx = useLastSubmit();\n\n const rhf = useFormContext<TFieldValues, unknown, TTransformedValues>();\n\n return {\n utils: utilsCtx,\n lastSubmit: lastSubmitCtx,\n rhf,\n FormSubmitError,\n };\n};\n","import type { RhfUtilsClientConfig } from '@/client/config/RhfUtilsClientConfigType';\n\nimport type { UseRhfUtilsFormOnSubmitContext } from '@/submit/UseRhfUtilsFormOnSubmitContextType';\n\nimport type { MaybePromise } from '@/utils/types';\n\nexport const useHandleCancelWithCheckIfCanBe = (\n onCancel: undefined | (() => MaybePromise<void>),\n useCanFormBeCancelled: RhfUtilsClientConfig['useCanFormBeCancelled'],\n formOnSubmitContext: UseRhfUtilsFormOnSubmitContext,\n) => {\n const canFormBeCancelled = useCanFormBeCancelled?.();\n\n const handleCancelWithCheck = async () => {\n if (!onCancel) return;\n\n // - resolve possible promise\n // - keep returned handled non-async to avoid downstream type issues\n const canBeCancelled = await Promise.resolve(\n canFormBeCancelled?.(formOnSubmitContext),\n );\n\n // if form explicitly can't be cancelled, early return\n if (canBeCancelled === false) return;\n\n return Promise.resolve(onCancel());\n };\n\n return handleCancelWithCheck;\n};\n","import { useRhfUtilsClientConfig } from '@/client/config/context/useRhfUtilsClientConfig';\n\nimport { useRhfUtilsFormOnSubmitContext } from '@/submit/useRhfUtilsFormOnSubmitContext';\n\nimport type { MaybePromise } from '@/utils/types';\n\nimport { useHandleCancelWithCheckIfCanBe } from './useHandleCancelWithCheckIfCanBe';\n\nexport const useHandleCancelWithCheckIfCanBeViaProviders = (\n onCancel: undefined | (() => MaybePromise<void>),\n) => {\n const { useCanFormBeCancelled } = useRhfUtilsClientConfig();\n const formSubmitContext = useRhfUtilsFormOnSubmitContext();\n\n return useHandleCancelWithCheckIfCanBe(\n onCancel,\n useCanFormBeCancelled,\n formSubmitContext,\n );\n};\n","import { useFormContext } from 'react-hook-form';\n\nimport { FormSubmitError } from '@/submit/error/FormSubmitError';\n\nimport { _Controller } from '../_Controller';\nimport { useRhfUtilsContext } from '../context/utils/useRhfUtilsContext';\nimport type { SafeFieldValues } from '../rhf/SafeFieldValuesType';\nimport { useHandleCancelWithCheckIfCanBeViaProviders } from '../utils/useHandleCancelWithCheckIfCanBeViaProviders';\n\nimport type { RhfUtilsFormProps } from './RhfUtilsFormProps';\n\nexport const RhfUtilsFormChildrenViaProviders_Internal = <\n TFieldValues extends SafeFieldValues,\n TTransformedValues extends SafeFieldValues,\n>({\n onCancel,\n Children,\n}: Pick<\n RhfUtilsFormProps<TFieldValues, TTransformedValues, undefined, undefined>,\n 'Children' | 'onCancel'\n>) => {\n const rhf = useFormContext<TFieldValues, unknown, TTransformedValues>();\n const utils = useRhfUtilsContext();\n const onCancelWithCheck =\n useHandleCancelWithCheckIfCanBeViaProviders(onCancel);\n\n return (\n <Children\n {...utils}\n rhf={rhf}\n onCancel={onCancelWithCheck}\n Controller={_Controller<TFieldValues>}\n FormSubmitError={FormSubmitError}\n />\n );\n};\n","import type { FieldPath } from 'react-hook-form';\n\nimport type { SafeFieldValues } from '@/form/rhf/SafeFieldValuesType';\nimport type { RHF_UseFormReturnWithoutProxies } from '@/form/RHF_UseFormReturnWithoutProxiesType';\n\nimport type { FormSubmitFieldErrors } from './FormSubmitFieldErrors';\n\n/**\n * Handle thrown {@link FormSubmitError}.\n * Add key/values as name/message to RHF context errors.\n */\nexport const setCtxErrorsByFormSubmitFieldErrors = <\n TFieldValues extends SafeFieldValues,\n TTransformedValues extends SafeFieldValues,\n>(\n ctx: RHF_UseFormReturnWithoutProxies<TFieldValues, TTransformedValues>,\n errors: FormSubmitFieldErrors,\n) => {\n // loop through error object and set errors in rhf context\n Object.entries(errors).forEach(([name, fieldError]) => {\n ctx.setError(name as FieldPath<TFieldValues>, {\n type: 'FormSubmitFieldError', // default\n ...fieldError,\n });\n });\n};\n","import type {\n RhfUtilsFormInstanceFormSurfacedProps,\n UseRhfUtilsFormInstanceFormProps,\n} from './UseRhfUtilsFormInstanceFormProps';\n\nexport const getRhfUtilsFormResolvedFormProps = (\n global: UseRhfUtilsFormInstanceFormProps | undefined,\n instance: UseRhfUtilsFormInstanceFormProps | undefined,\n surfaced?: RhfUtilsFormInstanceFormSurfacedProps,\n): UseRhfUtilsFormInstanceFormProps => ({\n ...global,\n ...instance,\n\n className:\n [global?.className, instance?.className, surfaced?.className]\n .filter(Boolean) // filter out falsy values\n .join(' ')\n .trim() || undefined, // replace empty string with undefined\n});\n","import { useRhfUtilsClientConfig } from '@/client/config/context/useRhfUtilsClientConfig';\n\nimport { getRhfUtilsFormResolvedFormProps } from './getRhfUtilsFormResolvedFormProps';\nimport type { UseRhfUtilsFormInstanceFormProps } from './UseRhfUtilsFormInstanceFormProps';\n\nexport const useRhfUtilsFormResolvedFormProps = (\n formProps: UseRhfUtilsFormInstanceFormProps | undefined,\n id: string,\n surfaced?: { className?: string },\n) => {\n const config = useRhfUtilsClientConfig();\n\n return {\n id,\n\n ...getRhfUtilsFormResolvedFormProps(\n config.defaults?.form,\n formProps,\n surfaced,\n ),\n };\n};\n","import type { MaybePromise } from '@/utils/types';\n\nimport { _useLastSubmitContext } from './useLastSubmitContext';\n\nexport const useLastSubmitErrorContextWith = (\n handleSubmit: (\n event: React.SubmitEvent<HTMLFormElement>,\n ) => MaybePromise<unknown>,\n) => {\n const ctx = _useLastSubmitContext();\n\n return async function (event: React.SubmitEvent<HTMLFormElement>) {\n try {\n ctx.error.reset(); // reset state before next submit event\n\n return await handleSubmit(event);\n } catch (error: unknown) {\n ctx.error.set(error, event);\n\n throw error;\n }\n };\n};\n","import type { SubmitErrorHandler, SubmitHandler } from 'react-hook-form';\nimport { useFormContext } from 'react-hook-form';\n\nimport { useLastSubmitStatus } from '@/submit/last/context/useLastSubmitContext';\nimport { useLastSubmitErrorContextWith } from '@/submit/last/context/useLastSubmitErrorContextWith';\n\nimport type { MaybePromise } from '@/utils/types';\n\nimport { useRhfUtilsContext } from '../context/utils/useRhfUtilsContext';\nimport type { SafeFieldValues } from '../rhf/SafeFieldValuesType';\n\ntype Props<\n TFieldValues extends SafeFieldValues,\n TTransformedValues extends SafeFieldValues,\n> = {\n onValid: SubmitHandler<TTransformedValues>;\n onInvalid?: SubmitErrorHandler<TFieldValues>;\n onError: (error: unknown, event: React.BaseSyntheticEvent) => void;\n onFinally?: () => MaybePromise<unknown>;\n};\n\nexport const useRhfUtilsFormHandleSubmit_Internal = <\n TFieldValues extends SafeFieldValues,\n TTransformedValues extends SafeFieldValues,\n>({\n onValid,\n onInvalid,\n onError,\n onFinally,\n}: Props<TFieldValues, TTransformedValues>): ((\n event: React.SubmitEvent<HTMLFormElement>,\n) => void) => {\n const rhfContext = useFormContext<\n TFieldValues,\n unknown,\n TTransformedValues\n >();\n\n const { options } = useRhfUtilsContext();\n const lastSubmitStatusRef = useLastSubmitStatus();\n\n const handleSubmit = rhfContext.handleSubmit(onValid, onInvalid);\n\n const handleSubmitWithLastSubmitError =\n useLastSubmitErrorContextWith(handleSubmit);\n\n return (event: React.SubmitEvent<HTMLFormElement>) => {\n lastSubmitStatusRef.current = 'submitting';\n\n // cannot stop propagation in handleSubmitValid, b/c it receives a different event object\n if (options.stopSubmitPropagation) event.stopPropagation();\n\n void Promise.resolve(handleSubmitWithLastSubmitError(event))\n .then(() => {\n lastSubmitStatusRef.current = 'success';\n })\n .catch((error: unknown) => {\n lastSubmitStatusRef.current = 'error';\n\n onError(error, event);\n })\n .finally(() => {\n onFinally?.();\n });\n };\n};\n","import React from 'react';\nimport type { UseFormHandleSubmit, UseFormReturn } from 'react-hook-form';\nimport { useFormContext } from 'react-hook-form';\n\nimport { useRhfUtilsClientConfig } from '@/client/config/context/useRhfUtilsClientConfig';\nimport type { RhfUtilsClientConfigFormOutletProps } from '@/client/config/RhfUtilsClientConfigFormOutletProps';\nimport type { RhfUtilsClientConfigUseFormHooksProps } from '@/client/config/RhfUtilsClientConfigUseFormHooksProps';\n\nimport { FormSubmitError } from '@/submit/error/FormSubmitError';\nimport type { FormSubmitFieldErrors } from '@/submit/error/FormSubmitFieldErrors';\nimport { setCtxErrorsByFormSubmitFieldErrors } from '@/submit/error/setCtxErrorsByFormSubmitFieldErrors';\nimport { useLastSubmit } from '@/submit/last/context/useLastSubmitContext';\n\nimport type {\n UseRhfUtilsFormOnSubmitContext,\n UseRhfUtilsFormOnSubmitErrorContext,\n} from '../../submit/UseRhfUtilsFormOnSubmitContextType';\n\nimport { _Controller } from '../_Controller';\nimport { useRhfUtilsContext } from '../context/utils/useRhfUtilsContext';\nimport { useRhfUtilsFormResolvedFormProps } from '../defaults/form/useRhfUtilsFormResolvedFormProps';\nimport type { SafeFieldValues } from '../rhf/SafeFieldValuesType';\n\nimport { useRhfUtilsFormHandleSubmit_Internal } from './_useHandleSubmit';\nimport type {\n RhfUtilsFormProps,\n RhfUtilsFormPropsGetApiValues,\n} from './RhfUtilsFormProps';\nimport type { RhfUtilsFormPropsOnBeforeSubmitInvariants } from './RhfUtilsFormPropsOnBeforeSubmitInvariants';\n\nexport const RhfUtilsFormWithSubmitHandler_Internal = <\n TFieldValues extends SafeFieldValues,\n TTransformedValues extends SafeFieldValues,\n TGetApiValues extends\n | undefined\n | RhfUtilsFormPropsGetApiValues<TTransformedValues, SafeFieldValues>,\n TOnSubmitReturnType,\n TApiValues extends undefined | SafeFieldValues =\n TGetApiValues extends RhfUtilsFormPropsGetApiValues<\n TTransformedValues,\n infer U\n >\n ? U\n : undefined,\n>({\n getApiData,\n // handlers\n onSubmitInvalid,\n onBeforeSubmitInvariants,\n onBeforeSubmit,\n onSubmit,\n onSubmitSuccess,\n onSubmitError,\n onSubmitFinally,\n // other\n form,\n className,\n //\n children,\n}: React.PropsWithChildren<\n Pick<\n RhfUtilsFormProps<\n TFieldValues,\n TTransformedValues,\n TGetApiValues,\n TOnSubmitReturnType,\n TApiValues\n >,\n | 'getApiData'\n | 'onSubmitInvalid'\n | 'onBeforeSubmitInvariants'\n | 'onBeforeSubmit'\n | 'onSubmit'\n | 'onSubmitSuccess'\n | 'onSubmitError'\n | 'onSubmitFinally'\n | 'form'\n | 'className'\n >\n>) => {\n const rhfContext = useFormContext<\n TFieldValues,\n unknown,\n TTransformedValues\n >();\n\n const utils = useRhfUtilsContext();\n const config = useRhfUtilsClientConfig();\n const lastSubmit = useLastSubmit();\n\n const resolvedFormProps = useRhfUtilsFormResolvedFormProps(\n form,\n\n // eslint-disable-next-line react-hooks/refs -- bug?\n utils.formId,\n {\n className,\n },\n );\n\n // SUBMIT\n\n const handleSubmitValid: Parameters<\n UseFormHandleSubmit<TFieldValues, TTransformedValues>\n >[0] = async (data: TTransformedValues, event?: React.BaseSyntheticEvent) => {\n const input = rhfContext.getValues();\n\n const api = getApiData?.(data) as TApiValues;\n\n const datas = { input, output: data, api };\n\n const onSubmitContext: UseRhfUtilsFormOnSubmitContext<\n TFieldValues,\n TTransformedValues,\n TApiValues\n > = {\n utils,\n lastSubmit,\n rhf: rhfContext,\n FormSubmitError,\n };\n const submitEvent = event as React.BaseSyntheticEvent<SubmitEvent>; // `as` required due to conditional generic\n\n if (onBeforeSubmitInvariants)\n await handleOnSubmitInvariants<\n TFieldValues,\n TTransformedValues,\n TApiValues\n >(onBeforeSubmitInvariants, datas, onSubmitContext, submitEvent);\n\n await Promise.resolve(\n onBeforeSubmit?.(datas, onSubmitContext, submitEvent),\n );\n\n const submitResponse = (await Promise.resolve(\n onSubmit?.(datas, onSubmitContext, submitEvent),\n )) as TOnSubmitReturnType;\n\n // eslint-disable-next-line react-hooks/immutability\n lastSubmit.statusRef.current = 'success';\n\n await Promise.resolve(\n onSubmitSuccess?.(submitResponse, datas, onSubmitContext, submitEvent),\n );\n };\n\n function handleSubmitError(error: unknown, event: React.BaseSyntheticEvent) {\n // get `FormSubmitFieldErrors`, 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 strip `<any>` generic\n : // if error is not FormSubmitError, consumer can provide global handler\n config.onSubmitErrorUnknown?.(error);\n\n if (formSubmitErrors)\n setCtxErrorsByFormSubmitFieldErrors(rhfContext, formSubmitErrors);\n\n onSubmitError?.(\n error,\n {\n utils,\n lastSubmit,\n errors: formSubmitErrors,\n rhf: rhfContext,\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 handleSubmit = useRhfUtilsFormHandleSubmit_Internal({\n onValid: handleSubmitValid,\n onInvalid: onSubmitInvalid,\n onError: handleSubmitError,\n onFinally: onSubmitFinally,\n });\n\n // FormComponent and props\n\n const Outlet = React.useCallback(\n () => children,\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [],\n );\n\n /** FormComponent props -- general, non-form-, non-schema-specific. */\n const formHooksProps: RhfUtilsClientConfigUseFormHooksProps = {\n // eslint-disable-next-line react-hooks/refs -- bug?\n ...utils,\n rhf: rhfContext as UseFormReturn<SafeFieldValues, unknown, SafeFieldValues>,\n lastSubmit,\n };\n\n // eslint-disable-next-line react-hooks/refs\n config.useFormHooks?.(formHooksProps);\n\n /** FormComponent props -- general, non-form-, non-schema-specific. */\n const formInjectorProps: RhfUtilsClientConfigFormOutletProps = {\n // eslint-disable-next-line react-hooks/refs\n ...formHooksProps,\n Outlet,\n Controller: _Controller,\n FormSubmitError: FormSubmitError,\n };\n\n // FormComponent or native form\n const FormComponent = config.FormComponent ?? 'form';\n\n return (\n <FormComponent\n {...resolvedFormProps}\n // eslint-disable-next-line react-hooks/refs -- bug?\n id={utils.formId}\n // eslint-disable-next-line react-hooks/refs -- bug?\n ref={utils.formRef}\n onSubmit={handleSubmit}\n >\n {/** eslint-disable-next-line react-hooks/static-components */}\n {config.FormOutlet ? (\n <config.FormOutlet\n // eslint-disable-next-line react-hooks/refs -- bug?\n {...formInjectorProps}\n />\n ) : (\n children\n )}\n </FormComponent>\n );\n};\n\n//\n\nconst handleOnSubmitInvariants = async <\n TFieldValues extends SafeFieldValues,\n TTransformedValues extends SafeFieldValues,\n TApiValues extends undefined | SafeFieldValues,\n>(\n onBeforeSubmitInvariants: RhfUtilsFormPropsOnBeforeSubmitInvariants<\n TFieldValues,\n TTransformedValues,\n TApiValues\n >,\n data: { input: TFieldValues; output: TTransformedValues; api: TApiValues },\n context: UseRhfUtilsFormOnSubmitContext<\n TFieldValues,\n TTransformedValues,\n TApiValues\n >,\n event: React.BaseSyntheticEvent<SubmitEvent>,\n) => {\n const invariants = await Promise.resolve(\n onBeforeSubmitInvariants(data, context, event),\n );\n\n const falseyFieldsAndMessages = invariants\n .filter(({ validate }) => !validate)\n .map(({ field, message }) => [field, { message }] as const);\n\n if (!falseyFieldsAndMessages.length) return;\n\n throw new context.FormSubmitError(\n Object.fromEntries(falseyFieldsAndMessages) as FormSubmitFieldErrors<\n TFieldValues,\n TApiValues\n >,\n );\n};\n","import { LazyDevToolViaProviders } from '@/devtool/LazyDevToolViaProviders';\n\nimport type { SafeFieldValues } from '../rhf/SafeFieldValuesType';\n\nimport { RhfUtilsFormChildrenViaProviders_Internal } from './_ChildrenViaProviders';\nimport { RhfUtilsFormWithSubmitHandler_Internal } from './_FormWithSubmitHandler';\nimport type {\n RhfUtilsFormProps,\n RhfUtilsFormPropsGetApiValues,\n} from './RhfUtilsFormProps';\n\nexport const RhfUtilsForm = <\n TFieldValues extends SafeFieldValues,\n TTransformedValues extends SafeFieldValues,\n TGetApiValues extends\n | undefined\n | RhfUtilsFormPropsGetApiValues<TTransformedValues, SafeFieldValues>,\n TOnSubmitReturnType,\n TApiValues extends undefined | SafeFieldValues =\n TGetApiValues extends RhfUtilsFormPropsGetApiValues<\n TTransformedValues,\n infer U\n >\n ? U\n : undefined,\n>({\n getApiData,\n // handlers\n onCancel,\n onSubmitInvalid,\n onBeforeSubmitInvariants,\n onBeforeSubmit,\n onSubmit,\n onSubmitSuccess,\n onSubmitError,\n onSubmitFinally,\n //\n Children,\n // attrs\n form,\n className,\n}: RhfUtilsFormProps<\n TFieldValues,\n TTransformedValues,\n TGetApiValues,\n TOnSubmitReturnType,\n TApiValues\n>) => (\n <RhfUtilsFormWithSubmitHandler_Internal\n getApiData={getApiData}\n onSubmitInvalid={onSubmitInvalid}\n onBeforeSubmitInvariants={onBeforeSubmitInvariants}\n onBeforeSubmit={onBeforeSubmit}\n onSubmit={onSubmit}\n onSubmitSuccess={onSubmitSuccess}\n onSubmitError={onSubmitError}\n onSubmitFinally={onSubmitFinally}\n form={form}\n className={className}\n >\n <LazyDevToolViaProviders />\n\n <RhfUtilsFormChildrenViaProviders_Internal\n onCancel={onCancel}\n Children={Children}\n />\n </RhfUtilsFormWithSubmitHandler_Internal>\n);\n","import type { SafeFieldValues } from '@/form/rhf/SafeFieldValuesType';\nimport { RhfUtilsForm } from '@/form/with-handlers-and-children/RhfUtilsForm';\nimport type {\n RhfUtilsFormProps,\n RhfUtilsFormPropsGetApiValues,\n} from '@/form/with-handlers-and-children/RhfUtilsFormProps';\n\nimport type { zodTypeInput, zodTypeOutput } from '../consts';\nimport type { ZodTypeSafeFieldValues } from '../ZodTypeSafeFieldValuesType';\n\ntype Props<\n TSchema extends ZodTypeSafeFieldValues,\n TGetApiValues extends\n | undefined\n | RhfUtilsFormPropsGetApiValues<\n TSchema[typeof zodTypeOutput],\n SafeFieldValues\n >,\n TOnSubmitReturnType,\n TApiValues extends undefined | SafeFieldValues =\n TGetApiValues extends RhfUtilsFormPropsGetApiValues<\n TSchema[typeof zodTypeOutput],\n infer U\n >\n ? U\n : undefined,\n> = React.PropsWithChildren<\n RhfUtilsFormProps<\n TSchema[typeof zodTypeInput],\n TSchema[typeof zodTypeOutput],\n TGetApiValues,\n TOnSubmitReturnType,\n TApiValues\n >\n>;\n\nexport const RhfUtilsZodForm = <\n TSchema extends ZodTypeSafeFieldValues,\n TGetApiValues extends\n | undefined\n | RhfUtilsFormPropsGetApiValues<\n TSchema[typeof zodTypeOutput],\n SafeFieldValues\n >,\n TOnSubmitReturnType,\n TApiValues extends undefined | SafeFieldValues =\n TGetApiValues extends RhfUtilsFormPropsGetApiValues<\n TSchema[typeof zodTypeOutput],\n infer U\n >\n ? U\n : undefined,\n>(\n props: Props<TSchema, TGetApiValues, TOnSubmitReturnType, TApiValues>,\n) => <RhfUtilsForm {...props} />;\n","import type { FlatFieldErrorEntry, FlatFieldErrors } from './types';\n\n/**\n * Filter {@link FlatFieldErrors} by a predicate.\n *\n * (Encapsulates to and from Object entries.)\n */\nexport const 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","import type { FieldError } from 'react-hook-form';\n\n/**\n * Determine if {@link FieldError} is a `ref`'d field error.\n */\nexport const isFieldErrorRefd = (error: FieldError): boolean => !!error.ref;\n","import type { FlatFieldErrorEntry } from './flat/types';\nimport { isFieldErrorRefd } from './isFieldErrorRefd';\n\n/**\n * Determine if {@link FieldError} is a `ref`'d field error.\n */\nexport const isFlatFieldErrorEntryRefd = ([\n ,\n error,\n]: FlatFieldErrorEntry): boolean => isFieldErrorRefd(error);\n","import { makeFlatFieldErrorsFilter } from './flat/filterFlatFieldErrors';\nimport { isFlatFieldErrorEntryRefd } from './isFlatFieldErrorEntryRefd';\n\nexport const getRefdFromFlatFieldErrors = makeFlatFieldErrorsFilter(\n isFlatFieldErrorEntryRefd,\n);\n","import { RhfUtilsNonFieldErrorMarkerHtmlAttribute } from './RhfUtilsNonFieldErrorMarkerHtmlAttribute';\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 getRhfUtilsNonFieldErrorMarkerQuerySelector = (\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 RhfUtilsNonFieldErrorMarkerHtmlAttribute + 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","import { getRhfUtilsNonFieldErrorMarkerQuerySelector } from './RhfUtilsNonFieldErrorMarker.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 */\nexport const isNonFieldErrorMarkerInDOM = (\n path: string,\n parentElement: Pick<HTMLElement, 'querySelector'>,\n): boolean =>\n !!parentElement.querySelector(\n getRhfUtilsNonFieldErrorMarkerQuerySelector(path),\n );\n","export const FormErrorPathRoot = 'root';\n","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 */\nexport const isFormErrorPathRoot = (path: string): boolean =>\n path === FormErrorPathRoot || path.startsWith(FormErrorPathRoot + '.');\n","import type { FieldError } from 'react-hook-form';\n\nimport { isFieldErrorRefd } from '../isFieldErrorRefd';\nimport { isNonFieldErrorMarkerInDOM } from '../nonfield/isNonFieldErrorMarkerInDOM';\nimport { isFormErrorPathRoot } from '../root/isFormErrorPathRoot';\n\nexport const isOrphanFormError = (\n path: string,\n error: FieldError,\n parentElement: Pick<HTMLElement, 'querySelector'>,\n) =>\n // non-field\n !isFieldErrorRefd(error) &&\n // non-root\n !isFormErrorPathRoot(path) &&\n // not marked in DOM\n !isNonFieldErrorMarkerInDOM(path, parentElement);\n","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 */\nexport const getIsFlatFieldErrorEntryOrphanByParentElement =\n (parentElement: Pick<HTMLElement, 'querySelector'>) =>\n ([path, error]: FlatFieldErrorEntry) =>\n isOrphanFormError(path, error, parentElement);\n","import { makeFlatFieldErrorsFilter } from '../flat/filterFlatFieldErrors';\nimport type { FlatFieldErrors } from '../flat/types';\n\nimport { getIsFlatFieldErrorEntryOrphanByParentElement } from './getIsOrphanFormErrorWithParentElement';\n\nexport const getOrphansFromFlatFieldErrors = (\n errors: FlatFieldErrors,\n parentElement: Pick<HTMLElement, 'querySelector'>,\n): FlatFieldErrors =>\n makeFlatFieldErrorsFilter(\n getIsFlatFieldErrorEntryOrphanByParentElement(parentElement),\n )(errors);\n","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 */\nexport const isFlatFieldErrorEntryPathRoot = ([path]: FlatFieldErrorEntry) =>\n isFormErrorPathRoot(path);\n","import { makeFlatFieldErrorsFilter } from '../flat/filterFlatFieldErrors';\n\nimport { isFlatFieldErrorEntryPathRoot } from './isFlatFieldErrorEntryPathRoot';\n\nexport const getRootsFromFlatFieldErrors = makeFlatFieldErrorsFilter(\n isFlatFieldErrorEntryPathRoot,\n);\n","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 | null>;\n}>;\n\n/**\n * Provides a flattened version of the form errors.\n * Allows flattening and filtering to happen once per errors change.\n */\nexport const FlatFieldErrorsContextProvider: React.FC<Props> = ({\n formRef,\n children,\n}) => {\n const { errors } = useFormState();\n\n const all = getFlatFieldErrors(errors);\n\n const orphans =\n // eslint-disable-next-line react-hooks/refs\n formRef.current\n ? getOrphansFromFlatFieldErrors(\n all,\n // eslint-disable-next-line react-hooks/refs\n formRef.current,\n )\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","import React from 'react';\n\nimport type { LastSubmitError } from '../error/LastSubmitErrorType';\nimport type { LastSubmitStatus } from '../status/LastSubmitStatusType';\n\nimport { _LastSubmitContextProvider } from './useLastSubmitContext';\n\ntype Props = React.PropsWithChildren;\n\nexport const LastSubmitContextProvider: React.FC<Props> = ({ children }) => {\n const [error, setError] = React.useState<LastSubmitError>();\n\n const statusRef = React.useRef<LastSubmitStatus>(null);\n\n return (\n <_LastSubmitContextProvider\n value={{\n status: { ref: statusRef },\n\n error: {\n state: error,\n\n reset: () => {\n setError(undefined);\n },\n\n set: (error, event) => {\n setError({ error, event });\n },\n },\n }}\n >\n {children}\n </_LastSubmitContextProvider>\n );\n};\n","import type { SafeFieldValues } from '@/form/rhf/SafeFieldValuesType';\n\n/**\n * Output form values and errors to console.\n */\nexport const 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","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 */\nexport const 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\n//\n\nconst defaultMessage = 'Form errors';\n","import React from 'react';\n\nexport const useRefIfValueWasTrue = (value: boolean) => {\n const hasBooleanChanged = React.useRef(false);\n\n // when value is true, set ref to true\n React.useEffect(() => {\n if (!value) return;\n\n hasBooleanChanged.current = true;\n }, [value]);\n\n const reset = () => {\n hasBooleanChanged.current = false;\n };\n\n return [hasBooleanChanged, reset] as const;\n};\n","import React from 'react';\nimport { useFormState } from 'react-hook-form';\n\nimport type { MaybePromise } from '@/utils/types';\nimport { useRefIfValueWasTrue } from '@/utils/useRefIfValueWasTrue';\n\nexport const useFormOnSubmitted = (\n callback?: (success: boolean) => MaybePromise<unknown>,\n options?: { successful?: boolean },\n) => {\n const { isSubmitSuccessful, isSubmitting } = useFormState();\n\n const [wasSubmitting, resetWasSubmitting] =\n useRefIfValueWasTrue(isSubmitting);\n\n // on successful submit, call callback\n React.useEffect(() => {\n if (!callback) return;\n\n // if currently submitting, ignore\n if (isSubmitting) return;\n\n // wait for submit to finish\n if (!wasSubmitting.current) return;\n\n // always reset to wait for next submit\n resetWasSubmitting();\n\n // check success against options passed\n if (\n options?.successful === undefined || // if option not specified, call on any submit\n isSubmitSuccessful === options.successful // otherwise, call only if matches\n ) {\n callback(isSubmitSuccessful);\n }\n\n // eslint-disable-next-line react-hooks/exhaustive-deps -- only track isSubmitting -- so success is checked each time\n }, [isSubmitting]);\n};\n","import { useFormContext } from 'react-hook-form';\n\nimport { useFormOnSubmitted } from './useFormOnSubmitted';\n\n/**\n * Configuration options for {@link useResetFormOnSubmitted}.\n */\nexport type UseResetFormOnSubmittedOptions =\n // disabled\n | undefined\n\n // enabled\n | {\n /**\n * Reset values on successful submit.\n * - `defaults`: reset current values to defaults\n * - `current`: reset defaults to current values\n */\n success?: { values: 'defaults' | 'current' };\n\n /**\n * Reset values to defaults on submit error.\n */\n error?: { values: 'defaults' };\n };\n\n/**\n * Control resetting of values and (some) state (e.g., `isDirty`) after form submitted.\n *\n * `isDirty` and other state is reset, but submit-related state is preserved, as well as errors.\n *\n * Use cases:\n * - on success:\n * - `defaults`: reset current values to defaults (e.g., clear form)\n * - `current`: reset defaults to current values (e.g., keep values)\n * - on error:\n * - reset current values to default values (e.g., submitOnChange reset)\n *\n * See `Rules` section: https://react-hook-form.com/api/useform/reset/\n * Specifically: \"- It's recommended to reset inside useEffect after submission.\"\n */\nexport const useResetFormOnSubmitted = (\n options: UseResetFormOnSubmittedOptions,\n) => {\n const { getValues, reset } = useFormContext();\n\n useFormOnSubmitted((success) => {\n if (!options) return;\n\n const whichValues = options[success ? 'success' : 'error']?.values;\n\n if (!whichValues) return;\n\n const keepValues = whichValues === 'current';\n\n const values = keepValues\n ? getValues() // current values\n : undefined; // default values\n\n reset(values, {\n // keep submit stuff for tracking relevant state (e.g., `useFormOnSubmitSuccessful`)\n keepIsSubmitSuccessful: true,\n keepIsSubmitted: true,\n keepSubmitCount: true,\n\n /**\n * This is necessary when setting default values to current values (lest form stop updating).\n *\n * Technically, we are keeping values and resetting default values to same values.\n *\n * Steps to repro:\n * - RhfUtilsClientConfig with resetOnSubmitted set to success values to current\n * - remove `keepValues` prop from reset\n * - create valid form, submit\n * - form values should be unchanged\n * - unexpectedly: can no longer type into input\n */\n keepValues,\n\n // keep errors in the case of unsuccessful submit\n keepErrors: true,\n });\n });\n};\n","import React from 'react';\n\n/**\n * Use to determine if first render has run.\n *\n * (Supports strict mode.)\n */\nexport const useIsFirstRender = () => {\n const isFirstRender = React.useRef(DEFAULT_STATE);\n\n // on mount, mark as not first render\n React.useEffect(() => {\n if (isFirstRender.current) {\n isFirstRender.current = !DEFAULT_STATE;\n }\n\n // on dismount (or before additional strictmode run), reset state\n return () => {\n isFirstRender.current = DEFAULT_STATE;\n };\n }, []);\n\n return isFirstRender;\n};\n\nconst DEFAULT_STATE = true;\n","import React from 'react';\n\n/**\n * React hook to debounce onChange event callback.\n *\n * Returns debounced state setter (uses ref internally).\n *\n * When debounce delay has elapsed after setting value,\n * onChange callback is called with latest value.\n *\n * @returns `[setValueDebounced]`\n */\nexport const useDebouncedOnChangeValue = <TValue>({\n onChange,\n delay,\n}: {\n onChange: (value: TValue) => void;\n delay: number;\n}) => {\n /**\n * State. (Via ref as it should not re-render.)\n */\n const state = React.useRef<{\n value: TValue;\n timer: NodeJS.Timeout;\n }>(null);\n\n // internal fns\n\n /** Callback for `setTimeout`. */\n const _onTimeout = () => {\n // typeguard (this should never happen)\n if (!state.current) return;\n\n // call consumer\n onChange(state.current.value);\n\n // reset state\n state.current = null;\n };\n\n const _clearTimeout = () => {\n if (state.current) clearTimeout(state.current.timer);\n };\n\n // cleanup\n\n React.useEffect(\n // return timeout clearer\n () => _clearTimeout,\n [],\n );\n\n // return\n\n const setValueDebounced = (value: TValue) => {\n // if there is active timeout, clear it\n _clearTimeout();\n\n // update state\n state.current = {\n // value being tracked\n value,\n // new timer\n timer: setTimeout(_onTimeout, delay),\n };\n };\n\n return [setValueDebounced] as const;\n};\n","import React from 'react';\n\nimport { useFormRequestSubmit } from '@/form/utils/useFormRequestSubmit';\n\nimport { useDebouncedOnChangeValue } from '@/utils/useDebouncedOnChangeValue';\n\nexport type UseSubmitFormOnEventDebouncedOptions = {\n /** Milliseconds to debounce form submission. (Default is none.) */\n debounce?: number;\n};\n\n/**\n * Internal, shared hook to setup debounced callback for OnChange hooks.\n */\nexport const useSubmitFormOnEventDebounced = (\n formRef: React.RefObject<HTMLFormElement | null>,\n options?: UseSubmitFormOnEventDebouncedOptions,\n) => {\n const requestSubmit = useFormRequestSubmit(formRef);\n\n const [setOnChangeDebounced] = useDebouncedOnChangeValue<unknown>({\n delay: options?.debounce ?? 0,\n\n // on change value after debounce\n onChange: () => {\n requestSubmit();\n },\n });\n\n return setOnChangeDebounced;\n};\n","import React from 'react';\nimport { useFormState, useWatch } from 'react-hook-form';\n\nimport { useIsFirstRender } from '@/utils/useIsFirstRender';\n\nimport { useSubmitFormOnEventDebounced } from './useSubmitFormOnEvent';\n\nexport type UseSubmitFormOnWatchOptions = {\n /** Milliseconds to debounce form submission. (Default is none.) */\n debounce: number;\n};\n\n/**\n * Watches for changes in form values.\n *\n * Caveats:\n * - uses RHF's useWatch\n * - triggers change immediately as user types, so use sensible debounce time\n * - does not cover uncontrolled inputs\n */\nexport const useSubmitFormOnWatch = (\n formRef: React.RefObject<HTMLFormElement | null>,\n options?: UseSubmitFormOnWatchOptions,\n) => {\n const setOnChangeDebounced = useSubmitFormOnEventDebounced(formRef, {\n debounce: options?.debounce,\n });\n\n const watch = useWatch();\n const { isValid, isDirty, isValidating, isSubmitting } = useFormState();\n\n /**\n * In some cases, {@link watch} reference object can change,\n * even when no input has been made by user.\n */\n const watchJson = React.useMemo(() => JSON.stringify(watch), [watch]);\n\n const isFirstRender = useIsFirstRender();\n\n React.useEffect(\n // on form values/state change, call callback\n () => {\n if (isFirstRender.current) return; // ignore initial render (i.e., don't immediately submit)\n // form state\n if (isValidating) return; // wait for validation\n if (isSubmitting) return; // do not re-submit\n if (!isValid) return;\n if (!isDirty) return;\n\n setOnChangeDebounced(watch);\n },\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [isValid, isDirty, watchJson, isValidating],\n // - isValidating bc we need to re-trigger after validation complete\n // - e.g., single keystroke making input in/valid; we have to wait\n // - isSubmitting not included bc would create infinite loop of submits after first submission\n // - expect form to block changes while submitting to avoid changes that get swallowed\n );\n};\n","import React from 'react';\n\nimport { useRhfUtilsClientConfig } from '@/client/config/context/useRhfUtilsClientConfig';\n\nimport { useFlatFieldErrorsContextOutput } from '@/errors/flat/context/useFlatFieldErrorsContextOutput';\n\nimport type { RhfUtilsFormOptions } from '@/form/options/RhfUtilsFormOptionsType';\n\nimport { useResetFormOnSubmitted } from '@/submit/useResetFormOnSubmitted';\nimport { useSubmitFormOnWatch } from '@/submit/useSubmitFormOnWatch';\n\nimport { _RhfUtilsContextProvider } from './useRhfUtilsContext';\n\nexport type RhfUtilsContextProviderProps = {\n formId: string;\n formRef: React.RefObject<HTMLFormElement | null>;\n\n /** Consumer-supplied options and values. */\n options: RhfUtilsFormOptions;\n};\n\nexport const RhfUtilsContextProvider: React.FC<\n React.PropsWithChildren<RhfUtilsContextProviderProps>\n> = ({\n formId,\n formRef,\n options,\n //\n children,\n}) => {\n const [memoOptions] = React.useState(options);\n\n const config = useRhfUtilsClientConfig();\n\n useFlatFieldErrorsContextOutput(config.fieldErrors?.output);\n\n (memoOptions.submitOnWatch ? useSubmitFormOnWatch : undefined)?.(\n formRef,\n memoOptions.submitOnWatch,\n );\n\n useResetFormOnSubmitted(memoOptions.resetOnSubmitted);\n\n return (\n <_RhfUtilsContextProvider\n value={{\n formId,\n formRef,\n options,\n }}\n >\n {children}\n </_RhfUtilsContextProvider>\n );\n};\n","import type { RhfUtilsFormOptions } from './RhfUtilsFormOptionsType';\n\nexport const getRhfUtilsFormResolvedOptions = (\n global: RhfUtilsFormOptions | undefined,\n instance: RhfUtilsFormOptions | undefined,\n): RhfUtilsFormOptions => ({\n ...global,\n ...instance,\n\n // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing -- false positive\n ...((global?.resetOnSubmitted || instance?.resetOnSubmitted) && {\n resetOnSubmitted: {\n ...global?.resetOnSubmitted,\n ...instance?.resetOnSubmitted,\n },\n }),\n});\n","import React from 'react';\n\nimport type { RhfUtilsClientConfig } from '@/client/config/RhfUtilsClientConfigType';\n\nimport { getRhfUtilsFormResolvedOptions } from './getRhfUtilsFormResolvedOptions';\nimport type { RhfUtilsFormOptions } from './RhfUtilsFormOptionsType';\n\nexport const useRhfUtilsFormResolvedOptions = (\n config: RhfUtilsClientConfig,\n options: RhfUtilsFormOptions | undefined,\n) =>\n React.useMemo(\n () => getRhfUtilsFormResolvedOptions(config.defaults?.options, options),\n\n // eslint-disable-next-line react-hooks/exhaustive-deps, react-hooks/use-memo\n [JSON.stringify(options)],\n );\n","import type { UseRhfUtilsFormResolvedDefaults } from '../defaults/UseRhfUtilsFormResolvedDefaultsType';\n\nimport type { SafeFieldValues } from './SafeFieldValuesType';\nimport type {\n RhfUseFormGlobalProps,\n RhfUseFormInstanceProps,\n} from './UseFormPropsType';\n\nexport const getRhfUtilsFormResolvedRhfProps = <\n TFieldValues extends SafeFieldValues,\n TTransformedValues extends SafeFieldValues,\n>(\n global: RhfUseFormGlobalProps | undefined,\n instance:\n RhfUseFormInstanceProps<TFieldValues, TTransformedValues> | undefined,\n): UseRhfUtilsFormResolvedDefaults<\n TFieldValues,\n TTransformedValues\n>['rhf'] => ({\n ...global,\n ...instance,\n});\n","import type { Resolver, UseFormProps } from 'react-hook-form';\nimport { useForm as useRhfForm } from 'react-hook-form';\n\nimport type { RhfUtilsClientConfig } from '@/client/config/RhfUtilsClientConfigType';\n\nimport type { SafeFieldValues } from '../rhf/SafeFieldValuesType';\nimport type { RhfUseFormInstanceProps } from '../rhf/UseFormPropsType';\n\nimport { getRhfUtilsFormResolvedRhfProps } from './getRhfUtilsFormResolvedRhfProps';\n\nexport const useRhfFormWithResolvedProps = <\n TFieldValues extends SafeFieldValues,\n TTransformedValues extends SafeFieldValues,\n>(\n props: RhfUseFormInstanceProps<TFieldValues, TTransformedValues> | undefined,\n config: RhfUtilsClientConfig,\n defaultValues: UseFormProps<\n TFieldValues,\n unknown,\n TTransformedValues\n >['defaultValues'],\n resolver?: Resolver<TFieldValues, unknown, TTransformedValues>,\n) =>\n useRhfForm<TFieldValues, unknown, TTransformedValues>({\n ...getRhfUtilsFormResolvedRhfProps(config.defaults?.rhf, props),\n resolver,\n defaultValues,\n });\n","import React from 'react';\nimport { FormProvider as RhfFormProvider } from 'react-hook-form';\n\nimport { useRhfUtilsClientConfig } from '@/client/config/context/useRhfUtilsClientConfig';\n\nimport { FlatFieldErrorsContextProvider } from '@/errors/flat/context/FlatFieldErrorsContextProvider';\n\nimport { LastSubmitContextProvider } from '@/submit/last/context/LastSubmitContextProvider';\n\nimport { RhfUtilsContextProvider } from '../context/utils/RhfUtilsContextProvider';\nimport { useRhfUtilsFormResolvedOptions } from '../options/useRhfUtilsFormResolvedOptions';\nimport { FormRelaySetter } from '../relay/set/FormRelaySetter';\nimport type { SafeFieldValues } from '../rhf/SafeFieldValuesType';\nimport { useRhfFormWithResolvedProps } from '../rhf/useRhfFormWithResolvedProps';\n\nimport type { RhfUtilsFormProvidersProps } from './RhfUtilsFormProvidersPropsType';\n\ntype Props<\n TFieldValues extends SafeFieldValues,\n TTransformedValues extends SafeFieldValues,\n> = React.PropsWithChildren<\n RhfUtilsFormProvidersProps<TFieldValues, TTransformedValues>\n>;\n\nexport function RhfUtilsFormProviders<\n TFieldValues extends SafeFieldValues,\n TTransformedValues extends SafeFieldValues,\n>({\n formId,\n rhf,\n resolver,\n defaultValues,\n options,\n relay,\n //\n children,\n}: Props<TFieldValues, TTransformedValues>) {\n // global config\n\n const config = useRhfUtilsClientConfig();\n\n // id\n\n const reactId = React.useId();\n // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing -- replace empty string\n const id = formId || reactId;\n\n // ref\n\n const formRef = React.useRef<HTMLFormElement>(null);\n\n // rhf\n\n const resolvedRhf = useRhfFormWithResolvedProps(\n rhf,\n config,\n defaultValues,\n resolver,\n );\n\n // options\n\n const resolvedOptions = useRhfUtilsFormResolvedOptions(config, options);\n\n //\n\n return (\n <RhfFormProvider {...resolvedRhf}>\n <FlatFieldErrorsContextProvider formRef={formRef}>\n <RhfUtilsContextProvider\n formId={id}\n formRef={formRef}\n options={resolvedOptions}\n >\n <FormRelaySetter options={relay} />\n\n <LastSubmitContextProvider>{children}</LastSubmitContextProvider>\n </RhfUtilsContextProvider>\n </FlatFieldErrorsContextProvider>\n </RhfFormProvider>\n );\n}\n","import { zodResolver } from '@hookform/resolvers/zod';\nimport type { Resolver } from 'react-hook-form';\n\nimport type { zodTypeInput, zodTypeOutput } from './consts';\nimport type { ZodTypeSafeFieldValues } from './ZodTypeSafeFieldValuesType';\n\nexport const getZodResolver = <\n TSchema extends ZodTypeSafeFieldValues,\n TFieldValues extends TSchema[typeof zodTypeInput],\n TTransformedValues extends TSchema[typeof zodTypeOutput],\n>(\n schema: TSchema,\n) => zodResolver(schema) as Resolver<TFieldValues, unknown, TTransformedValues>;\n","import { RhfUtilsFormProviders } from '@/form/providers/RhfUtilsFormProviders';\nimport type { RhfUtilsFormProvidersProps } from '@/form/providers/RhfUtilsFormProvidersPropsType';\n\nimport type { zodTypeInput, zodTypeOutput } from '../consts';\nimport { getZodResolver } from '../getZodResolver';\nimport type { ZodTypeSafeFieldValues } from '../ZodTypeSafeFieldValuesType';\n\ntype Props<TSchema extends ZodTypeSafeFieldValues> = React.PropsWithChildren<\n { schema: TSchema } &\n //\n RhfUtilsFormProvidersProps<\n TSchema[typeof zodTypeInput],\n TSchema[typeof zodTypeOutput]\n >\n>;\n\nexport const RhfUtilsZodFormProviders = <\n TSchema extends ZodTypeSafeFieldValues,\n>({\n schema,\n children,\n ...props\n}: Props<TSchema>) => (\n <RhfUtilsFormProviders {...props} resolver={getZodResolver(schema)}>\n {children}\n </RhfUtilsFormProviders>\n);\n","import { RhfUtilsFormProviders } from '../providers/RhfUtilsFormProviders';\nimport type { RhfUtilsFormProvidersProps } from '../providers/RhfUtilsFormProvidersPropsType';\nimport type { SafeFieldValues } from '../rhf/SafeFieldValuesType';\nimport { RhfUtilsForm } from '../with-handlers-and-children/RhfUtilsForm';\nimport type {\n RhfUtilsFormProps,\n RhfUtilsFormPropsGetApiValues,\n} from '../with-handlers-and-children/RhfUtilsFormProps';\n\nimport type { RhfUtilsFormWithProvidersProps } from './RhfUtilsFormWithProvidersProps';\n\n/**\n * Form providers (with utils) with immediate descendent {@link RhfUtilsForm}.\n * (Syntactic sugar for {@link useRhfUtilsForm}. Use this for most applications.)\n */\nexport function RhfUtilsFormWithProviders<\n TFieldValues extends SafeFieldValues,\n TTransformedValues extends SafeFieldValues,\n TGetApiValues extends\n | undefined\n | RhfUtilsFormPropsGetApiValues<TTransformedValues, SafeFieldValues>,\n TOnSubmitReturnType,\n TApiValues extends undefined | SafeFieldValues =\n TGetApiValues extends RhfUtilsFormPropsGetApiValues<\n TTransformedValues,\n infer U\n >\n ? U\n : undefined,\n>({\n getApiData,\n // provider\n resolver,\n rhf,\n defaultValues,\n options,\n relay,\n // form\n onCancel,\n onSubmitInvalid,\n onBeforeSubmitInvariants,\n onBeforeSubmit,\n onSubmit,\n onSubmitSuccess,\n onSubmitError,\n onSubmitFinally,\n Children,\n form,\n formId,\n className,\n}: RhfUtilsFormWithProvidersProps<\n TFieldValues,\n TTransformedValues,\n TGetApiValues,\n TOnSubmitReturnType,\n TApiValues\n>) {\n const providerProps: RhfUtilsFormProvidersProps<\n TFieldValues,\n TTransformedValues\n > = {\n formId,\n resolver,\n rhf,\n defaultValues,\n options,\n relay,\n };\n\n const formProps: RhfUtilsFormProps<\n TFieldValues,\n TTransformedValues,\n TGetApiValues,\n TOnSubmitReturnType,\n TApiValues\n > = {\n getApiData,\n onCancel,\n onSubmitInvalid,\n onBeforeSubmitInvariants,\n onBeforeSubmit,\n onSubmit,\n onSubmitSuccess,\n onSubmitError,\n onSubmitFinally,\n Children,\n form,\n className,\n };\n\n return (\n <RhfUtilsFormProviders {...providerProps}>\n <RhfUtilsForm {...formProps} />\n </RhfUtilsFormProviders>\n );\n}\n","import type { RhfUtilsFormProvidersProps } from '@/form/providers/RhfUtilsFormProvidersPropsType';\nimport type { SafeFieldValues } from '@/form/rhf/SafeFieldValuesType';\nimport type {\n RhfUtilsFormProps,\n RhfUtilsFormPropsGetApiValues,\n} from '@/form/with-handlers-and-children/RhfUtilsFormProps';\nimport { RhfUtilsFormWithProviders } from '@/form/with-providers/RhfUtilsFormWithProviders';\n\nimport type { zodTypeInput, zodTypeOutput } from '../consts';\nimport { getZodResolver } from '../getZodResolver';\nimport type { ZodTypeSafeFieldValues } from '../ZodTypeSafeFieldValuesType';\n\ntype Props<\n TSchema extends ZodTypeSafeFieldValues,\n TGetApiValues extends\n | undefined\n | RhfUtilsFormPropsGetApiValues<TTransformedValues, SafeFieldValues>,\n TOnSubmitReturnType,\n TFieldValues extends TSchema[typeof zodTypeInput] =\n TSchema[typeof zodTypeInput],\n TTransformedValues extends TSchema[typeof zodTypeOutput] =\n TSchema[typeof zodTypeOutput],\n TApiValues extends undefined | SafeFieldValues =\n TGetApiValues extends RhfUtilsFormPropsGetApiValues<\n TTransformedValues,\n infer U\n >\n ? U\n : undefined,\n> = React.PropsWithChildren<\n { schema: TSchema } &\n // provider\n Omit<\n RhfUtilsFormProvidersProps<TFieldValues, TTransformedValues>,\n 'resolver'\n > &\n // form\n RhfUtilsFormProps<\n TFieldValues,\n TTransformedValues,\n TGetApiValues,\n TOnSubmitReturnType,\n TApiValues\n >\n>;\n\nexport const RhfUtilsZodFormWithProviders = <\n TSchema extends ZodTypeSafeFieldValues,\n TGetApiValues extends\n | undefined\n | RhfUtilsFormPropsGetApiValues<TTransformedValues, SafeFieldValues>,\n TOnSubmitReturnType,\n TFieldValues extends TSchema[typeof zodTypeInput] =\n TSchema[typeof zodTypeInput],\n TTransformedValues extends TSchema[typeof zodTypeOutput] =\n TSchema[typeof zodTypeOutput],\n TApiValues extends undefined | SafeFieldValues =\n TGetApiValues extends RhfUtilsFormPropsGetApiValues<\n TTransformedValues,\n infer U\n >\n ? U\n : undefined,\n>({\n schema,\n ...props\n}: Props<\n TSchema,\n TGetApiValues,\n TOnSubmitReturnType,\n TFieldValues,\n TTransformedValues,\n TApiValues\n>) => (\n <RhfUtilsFormWithProviders {...props} resolver={getZodResolver(schema)} />\n);\n","/**\n * @license @paragrav/rhf-utils\n *\n * Copyright (c) 2024-present paragrav.dev\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\nexport type { Register } from '../Register';\nexport * from './config';\nexport * from './errors';\nexport * from './form';\nexport * from './submit';\nexport * from './zod';\n"],"mappings":";;;;;;AAIA,MAAa,uCAAuC,MAAM,cAExD,KAAA,CAAS;;;ACMX,MAAa,gCAAiD,EAC5D,QACA,eACI;CACJ,MAAM,CAAC,cAAc,MAAM,SAAS,UAAU,CAAC,CAAC;CAEhD,OACE,oBAAC,qCAAqC,UAAtC;EAA+C,OAAO;EACpD,UAAA,oBAAC,0BAAD,EAA2B,SAAmC,CAAA;CACjB,CAAA;AAEnD;;;ACTA,MAAM,EACJ,UAAU,gCACV,aAAa,8BACX,cAAsC;;;;;;;;ACR1C,MAAa,gDAAgD;CAC3D,MAAM,SAAS,0BAA0B;CAazC,OAXuB,MAAM,cAAc;EAEzC,IAAI,CAAC,OAAO,WAAW,OAAO;EAC9B,IAAI,CAAC,OAAO,YAAY,OAAO;EAG/B,OACE,OAAO,KAAK,OA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sBAGd,EACA,QACA,KACA,UACA,eACA,SACA,OAEA,YAC0C;CAG1C,MAAM,SAAS,wBAAwB;CAIvC,MAAM,UAAU,MAAM,MAAM;CAE5B,MAAM,KAAK,UAAU;CAIrB,MAAM,UAAU,MAAM,OAAwB,IAAI;CAIlD,MAAM,cAAc,4BAClB,KACA,QACA,eACA,QACF;CAIA,MAAM,kBAAkB,+BAA+B,QAAQ,OAAO;CAItE,OACE,oBAACC,cAAD;EAAiB,GAAI;EACnB,UAAA,oBAAC,gCAAD;GAAyC;GACvC,UAAA,qBAAC,yBAAD;IACE,QAAQ;IACC;IACT,SAAS;IAHX,UAAA,CAKE,oBAAC,iBAAD,EAAiB,SAAS,MAAQ,CAAA,GAElC,oBAAC,2BAAD,EAA4B,SAAoC,CAAA,CACzC;;EACK,CAAA;CACjB,CAAA;AAErB;;;AC3EA,MAAa,kBAKX,WACG,YAAY,MAAM;;;ACIvB,MAAa,4BAEX,EACA,QACA,UACA,GAAG,YAEH,oBAAC,uBAAD;CAAuB,GAAI;CAAO,UAAU,eAAe,MAAM;CAC9D;AACoB,CAAA;;;;;;;ACVzB,SAAgB,0BAcd,EACA,YAEA,UACA,KACA,eACA,SACA,OAEA,UACA,iBACA,0BACA,gBACA,UACA,iBACA,eACA,iBACA,UACA,MACA,QACA,aAOC;CACD,MAAM,gBAGF;EACF;EACA;EACA;EACA;EACA;EACA;CACF;CAEA,MAAM,YAMF;EACF;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACF;CAEA,OACE,oBAAC,uBAAD;EAAuB,GAAI;EACzB,UAAA,oBAAC,cAAD,EAAc,GAAI,UAAY,CAAA;CACT,CAAA;AAE3B;;;ACjDA,MAAa,gCAiBX,EACA,QACA,GAAG,YASH,oBAAC,2BAAD;CAA2B,GAAI;CAAO,UAAU,eAAe,MAAM;AAAI,CAAA"}
|
package/dist/tsdown/relay.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ import React$1 from "react";
|
|
|
4
4
|
import { FormState } from "react-hook-form";
|
|
5
5
|
//#region src/form/relay/context/FormRelayContextProvider.d.ts
|
|
6
6
|
type Props$1 = React$1.PropsWithChildren;
|
|
7
|
-
declare const FormRelayContextProvider: React$1.FC<Props$1>;
|
|
7
|
+
export declare const FormRelayContextProvider: React$1.FC<Props$1>;
|
|
8
8
|
//#endregion
|
|
9
9
|
//#region src/form/relay/get/FormRelayGroupType.d.ts
|
|
10
10
|
type FormRelayGroup = Partial<Omit<FormState<SafeFieldValues>, 'defaultValues' | 'dirtyFields' | 'touchedFields' | 'validatingFields' | 'errors' | 'submitErrors'> & {
|
|
@@ -30,10 +30,10 @@ type FormRelayGroup = Partial<Omit<FormState<SafeFieldValues>, 'defaultValues' |
|
|
|
30
30
|
*
|
|
31
31
|
* Allows you to build naive components that are not tied to one specific context.
|
|
32
32
|
*/
|
|
33
|
-
declare const useFirstFormStateGroup: () => FormRelayGroup;
|
|
33
|
+
export declare const useFirstFormStateGroup: () => FormRelayGroup;
|
|
34
34
|
//#endregion
|
|
35
35
|
//#region src/form/relay/get/useFormRelay.d.ts
|
|
36
|
-
declare const useFormRelayId: (formId: string) => FormRelay | undefined;
|
|
36
|
+
export declare const useFormRelayId: (formId: string) => FormRelay | undefined;
|
|
37
37
|
type FormRelayGroupCriteria = {
|
|
38
38
|
groups: string[];
|
|
39
39
|
} | {
|
|
@@ -42,16 +42,16 @@ type FormRelayGroupCriteria = {
|
|
|
42
42
|
options: RhfUtilsFormOptions;
|
|
43
43
|
}) => boolean;
|
|
44
44
|
};
|
|
45
|
-
declare const useFormRelayGroup: (criteria?: FormRelayGroupCriteria) => FormRelayGroup;
|
|
45
|
+
export declare const useFormRelayGroup: (criteria?: FormRelayGroupCriteria) => FormRelayGroup;
|
|
46
46
|
//#endregion
|
|
47
47
|
//#region src/form/relay/set/FormRelaySetter.d.ts
|
|
48
48
|
type Props = {
|
|
49
49
|
options?: FormRelayOptions;
|
|
50
50
|
};
|
|
51
|
-
declare const FormRelaySetter: React.FC<Props>;
|
|
51
|
+
export declare const FormRelaySetter: React.FC<Props>;
|
|
52
52
|
//#endregion
|
|
53
53
|
//#region src/form/relay/set/useFormRelaySet.d.ts
|
|
54
|
-
declare const useFormRelaySet: (options?: FormRelayOptions) => void;
|
|
54
|
+
export declare const useFormRelaySet: (options?: FormRelayOptions) => void;
|
|
55
55
|
//#endregion
|
|
56
|
-
export {
|
|
56
|
+
export type { FormRelay, FormRelayGroup, FormRelayStateSelected };
|
|
57
57
|
//# sourceMappingURL=relay.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"relay.d.ts","names":[],"sources":["../../src/form/relay/context/FormRelayContextProvider.tsx","../../src/form/relay/get/FormRelayGroupType.ts","../../src/form/relay/get/grouper/useFirstFormStateGroup.ts","../../src/form/relay/get/useFormRelay.ts","../../src/form/relay/set/FormRelaySetter.tsx","../../src/form/relay/set/useFormRelaySet.ts"],"mappings":";;;;;KAUK,UAAQ,QAAM;
|
|
1
|
+
{"version":3,"file":"relay.d.ts","names":[],"sources":["../../src/form/relay/context/FormRelayContextProvider.tsx","../../src/form/relay/get/FormRelayGroupType.ts","../../src/form/relay/get/grouper/useFirstFormStateGroup.ts","../../src/form/relay/get/useFormRelay.ts","../../src/form/relay/set/FormRelaySetter.tsx","../../src/form/relay/set/useFormRelaySet.ts"],"mappings":";;;;;KAUK,UAAQ,QAAM;qBAEN,0BAA0B,QAAM,GAAG;;;KCRpC,iBAAiB,QAC3B,KACE,UAAU;EAQV;EAEA;EAEA;EAEA;;EAGA;;;;;;EAOA;;;;;;;;;;;qBCVS,8BAA6B;;;qBCT7B,iBAAkB,mBAAlB;KAKD;EACN;;EAEA,YAAY;IACV,QAAQ;IACR,SAAS;;;qBAIJ,oBACX,WAAW,2BACV;;;KCvBE;EACH,UAAU;;qBAGC,iBAAiB,MAAM,GAAG;;;qBCG1B,kBAAmB,UAAU"}
|
package/dist/tsdown/relay.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { c as FormRelayContextProvider, i as isEmptyObject, l as useFormRelayContext, n as useFormRelaySet, s as useRhfUtilsMaybeContext, t as FormRelaySetter, u as createContext } from "./FormRelaySetter-
|
|
1
|
+
import { c as FormRelayContextProvider, i as isEmptyObject, l as useFormRelayContext, n as useFormRelaySet, s as useRhfUtilsMaybeContext, t as FormRelaySetter, u as createContext } from "./FormRelaySetter-BNson1Za.js";
|
|
2
2
|
import React from "react";
|
|
3
3
|
import { useFormState } from "react-hook-form";
|
|
4
4
|
//#region src/form/relay/context/utils.ts
|
|
@@ -41,7 +41,8 @@ const getFormRelayedAggregatedByRelayedItem = (formStates) => formStates.reduce(
|
|
|
41
41
|
const useFormRelayId = (formId) => useFormRelayContext().state[formId];
|
|
42
42
|
const useFormRelayGroup = (criteria) => {
|
|
43
43
|
const relayState = useFormRelayContext().state;
|
|
44
|
-
const
|
|
44
|
+
const relayStateFiltered = getFormRelaysByCriteria(relayState, criteria);
|
|
45
|
+
const state = getFormRelayedAggregatedByRelayedItem(relayStateFiltered.map(({ state }) => state));
|
|
45
46
|
const jsonState = JSON.stringify(state);
|
|
46
47
|
return React.useMemo(() => state, [jsonState]);
|
|
47
48
|
};
|
|
@@ -62,7 +63,10 @@ const { Provider: _FormRelayGrouperContextProvider, useRequired: _useFormRelayGr
|
|
|
62
63
|
* Allows you to build naive components that are not tied to one specific context.
|
|
63
64
|
*/
|
|
64
65
|
const useFirstFormStateGroup = () => {
|
|
65
|
-
if (useRhfUtilsMaybeContext())
|
|
66
|
+
if (useRhfUtilsMaybeContext()) {
|
|
67
|
+
const state = useFormState();
|
|
68
|
+
return getFormRelayedAggregatedByRelayedItem([state]);
|
|
69
|
+
}
|
|
66
70
|
const maybeRelayCtx = _useFormRelayGrouperMaybeContext();
|
|
67
71
|
if (maybeRelayCtx) return maybeRelayCtx.state;
|
|
68
72
|
return useFormRelayGroup();
|
package/dist/tsdown/relay.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"relay.js","names":[],"sources":["../../src/form/relay/context/utils.ts","../../src/form/relay/get/useFormRelay.ts","../../src/form/relay/get/grouper/context/index.ts","../../src/form/relay/get/grouper/useFirstFormStateGroup.ts"],"sourcesContent":["import { isEmptyObject } from '@/utils/isEmptyObject';\n\nimport type { FormRelayGroup } from '../get/FormRelayGroupType';\nimport type { FormRelayStateSelected } from '../types';\n\n// see: https://github.com/react-hook-form/react-hook-form/blob/7ce7cc6da38e9787bcf05e94fbd14dd712d27a85/src/logic/getProxyFormState.ts\n\n/** Condense list of form states to singular booleans. */\nexport const getFormRelayedAggregatedByRelayedItem = (\n formStates: FormRelayStateSelected[],\n): FormRelayGroup =>\n formStates.reduce<FormRelayGroup>(\n (acc, curr) =>\n ({\n // booleans\n isDirty: acc.isDirty || curr.isDirty,\n isSubmitting: acc.isSubmitting || curr.isSubmitting,\n isLoading: acc.isLoading || curr.isLoading,\n isSubmitted: acc.isSubmitted || curr.isSubmitted,\n isSubmitSuccessful: acc.isSubmitSuccessful || curr.isSubmitSuccessful,\n isValidating: acc.isValidating || curr.isValidating,\n isValid: acc.isValid || curr.isValid,\n isReady: acc.isReady || curr.isReady,\n disabled: acc.disabled || curr.disabled,\n // objects\n hasErrors:\n acc.hasErrors || (curr.errors && !isEmptyObject(curr.errors)),\n hasDirtyFields:\n acc.hasDirtyFields ||\n (curr.dirtyFields && !isEmptyObject(curr.dirtyFields)),\n hasTouchedFields:\n acc.hasTouchedFields ||\n (curr.touchedFields && !isEmptyObject(curr.touchedFields)),\n hasValidatingFields:\n acc.hasValidatingFields ||\n (curr.validatingFields && !isEmptyObject(curr.validatingFields)),\n // counts\n submitCount: (acc.submitCount ?? 0) + (curr.submitCount ?? 0),\n // supplemental\n isMounted: acc.isMounted || curr.isMounted,\n }) satisfies FormRelayGroup,\n\n // initial values\n {\n isDirty: undefined,\n isSubmitting: undefined,\n isLoading: undefined,\n isSubmitted: undefined,\n isSubmitSuccessful: undefined,\n isValidating: undefined,\n isReady: undefined,\n isValid: undefined,\n disabled: undefined,\n // objects\n hasErrors: undefined,\n hasDirtyFields: undefined,\n hasTouchedFields: undefined,\n hasValidatingFields: undefined,\n // counts\n submitCount: undefined,\n // supplemental\n isMounted: undefined,\n },\n );\n","import React from 'react';\n\nimport type { RhfUtilsFormOptions } from '@/form/options/RhfUtilsFormOptionsType';\n\nimport type { FormsRelayed } from '../context/useFormRelayContext';\nimport { useFormRelayContext } from '../context/useFormRelayContext';\nimport { getFormRelayedAggregatedByRelayedItem } from '../context/utils';\nimport type { FormRelayOptions } from '../FormRelayOptions';\n\nimport type { FormRelayGroup } from './FormRelayGroupType';\n\nexport const useFormRelayId = (formId: string) =>\n useFormRelayContext().state[formId];\n\n//\n\nexport type FormRelayGroupCriteria =\n | { groups: string[] }\n | {\n predicate: (context: {\n groups: FormRelayOptions['groups'];\n options: RhfUtilsFormOptions;\n }) => boolean;\n };\n\nexport const useFormRelayGroup = (\n criteria?: FormRelayGroupCriteria,\n): FormRelayGroup => {\n const relayState = useFormRelayContext().state;\n\n const relayStateFiltered = getFormRelaysByCriteria(relayState, criteria);\n\n const state = getFormRelayedAggregatedByRelayedItem(\n relayStateFiltered.map(({ state }) => state),\n );\n\n const jsonState = JSON.stringify(state);\n\n const memoState = React.useMemo(\n () => state,\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [jsonState],\n );\n\n return memoState;\n};\n\n// WRITE TESTS\n\nconst getFormRelaysByCriteria = (\n relayState: FormsRelayed,\n criteria?: FormRelayGroupCriteria,\n) =>\n Object.values(relayState).filter(\n ({ options, utils }) =>\n // no criteria specified\n !criteria ||\n // groups specified\n ('groups' in criteria &&\n criteria.groups.filter((group) => options.groups?.includes(group))\n .length) ||\n // predicate specified\n ('predicate' in criteria &&\n criteria.predicate({\n groups: options.groups,\n options: utils.options,\n })),\n );\n","import { createContext } from '@/utils/createContext';\n\nimport type { FormRelayGroup } from '../../FormRelayGroupType';\n\nexport type FormRelayGrouperContext = {\n state: FormRelayGroup;\n};\n\n// context\n\nexport const {\n Provider: _FormRelayGrouperContextProvider,\n useRequired: _useFormRelayGrouperContext,\n useMaybe: _useFormRelayGrouperMaybeContext,\n} = createContext<FormRelayGrouperContext>();\n","import { useFormState } from 'react-hook-form';\n\nimport { useRhfUtilsMaybeContext } from '@/form/context/utils/useRhfUtilsContext';\n\nimport { getFormRelayedAggregatedByRelayedItem } from '../../context/utils';\n\nimport type { FormRelayGroup } from '../FormRelayGroupType';\nimport { useFormRelayGroup } from '../useFormRelay';\n\nimport { _useFormRelayGrouperMaybeContext } from './context';\n\n/* eslint-disable react-hooks/rules-of-hooks -- ⚠️ condition will (i.e., should) not change between renders! */\n\n/**\n * Use this when you don't (want to) know whether component is wrapped\n * with RHF context, `FormRelayGrouperContext`, or `FormRelayContext`.\n * Will return `FormRelayGroup`, regardless.\n *\n * Allows you to build naive components that are not tied to one specific context.\n */\nexport const useFirstFormStateGroup = (): FormRelayGroup => {\n const maybeUtils = useRhfUtilsMaybeContext();\n\n // if utils present, then relay unnecessary (bc we are in the context of a single form)\n\n if (maybeUtils) {\n const state = useFormState();\n\n return getFormRelayedAggregatedByRelayedItem([state]);\n }\n\n // if relay grouper present...\n\n const maybeRelayCtx = _useFormRelayGrouperMaybeContext();\n\n if (maybeRelayCtx) return maybeRelayCtx.state;\n\n // otherwise: use top-level relay\n\n return useFormRelayGroup();\n};\n"],"mappings":";;;;;AAQA,MAAa,yCACX,eAEA,WAAW,QACR,KAAK,UACH;CAEC,SAAS,IAAI,WAAW,KAAK;CAC7B,cAAc,IAAI,gBAAgB,KAAK;CACvC,WAAW,IAAI,aAAa,KAAK;CACjC,aAAa,IAAI,eAAe,KAAK;CACrC,oBAAoB,IAAI,sBAAsB,KAAK;CACnD,cAAc,IAAI,gBAAgB,KAAK;CACvC,SAAS,IAAI,WAAW,KAAK;CAC7B,SAAS,IAAI,WAAW,KAAK;CAC7B,UAAU,IAAI,YAAY,KAAK;CAE/B,WACE,IAAI,aAAc,KAAK,UAAU,CAAC,cAAc,KAAK,MAAM;CAC7D,gBACE,IAAI,kBACH,KAAK,eAAe,CAAC,cAAc,KAAK,WAAW;CACtD,kBACE,IAAI,oBACH,KAAK,iBAAiB,CAAC,cAAc,KAAK,aAAa;CAC1D,qBACE,IAAI,uBACH,KAAK,oBAAoB,CAAC,cAAc,KAAK,gBAAgB;CAEhE,cAAc,IAAI,eAAe,MAAM,KAAK,eAAe;CAE3D,WAAW,IAAI,aAAa,KAAK;AACnC,IAGF;CACE,SAAS,KAAA;CACT,cAAc,KAAA;CACd,WAAW,KAAA;CACX,aAAa,KAAA;CACb,oBAAoB,KAAA;CACpB,cAAc,KAAA;CACd,SAAS,KAAA;CACT,SAAS,KAAA;CACT,UAAU,KAAA;CAEV,WAAW,KAAA;CACX,gBAAgB,KAAA;CAChB,kBAAkB,KAAA;CAClB,qBAAqB,KAAA;CAErB,aAAa,KAAA;CAEb,WAAW,KAAA;AACb,CACF;;;ACpDF,MAAa,kBAAkB,WAC7B,oBAAoB,CAAC,CAAC,MAAM;AAa9B,MAAa,qBACX,aACmB;CACnB,MAAM,aAAa,oBAAoB,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"relay.js","names":[],"sources":["../../src/form/relay/context/utils.ts","../../src/form/relay/get/useFormRelay.ts","../../src/form/relay/get/grouper/context/index.ts","../../src/form/relay/get/grouper/useFirstFormStateGroup.ts"],"sourcesContent":["import { isEmptyObject } from '@/utils/isEmptyObject';\n\nimport type { FormRelayGroup } from '../get/FormRelayGroupType';\nimport type { FormRelayStateSelected } from '../types';\n\n// see: https://github.com/react-hook-form/react-hook-form/blob/7ce7cc6da38e9787bcf05e94fbd14dd712d27a85/src/logic/getProxyFormState.ts\n\n/** Condense list of form states to singular booleans. */\nexport const getFormRelayedAggregatedByRelayedItem = (\n formStates: FormRelayStateSelected[],\n): FormRelayGroup =>\n formStates.reduce<FormRelayGroup>(\n (acc, curr) =>\n ({\n // booleans\n isDirty: acc.isDirty || curr.isDirty,\n isSubmitting: acc.isSubmitting || curr.isSubmitting,\n isLoading: acc.isLoading || curr.isLoading,\n isSubmitted: acc.isSubmitted || curr.isSubmitted,\n isSubmitSuccessful: acc.isSubmitSuccessful || curr.isSubmitSuccessful,\n isValidating: acc.isValidating || curr.isValidating,\n isValid: acc.isValid || curr.isValid,\n isReady: acc.isReady || curr.isReady,\n disabled: acc.disabled || curr.disabled,\n // objects\n hasErrors:\n acc.hasErrors || (curr.errors && !isEmptyObject(curr.errors)),\n hasDirtyFields:\n acc.hasDirtyFields ||\n (curr.dirtyFields && !isEmptyObject(curr.dirtyFields)),\n hasTouchedFields:\n acc.hasTouchedFields ||\n (curr.touchedFields && !isEmptyObject(curr.touchedFields)),\n hasValidatingFields:\n acc.hasValidatingFields ||\n (curr.validatingFields && !isEmptyObject(curr.validatingFields)),\n // counts\n submitCount: (acc.submitCount ?? 0) + (curr.submitCount ?? 0),\n // supplemental\n isMounted: acc.isMounted || curr.isMounted,\n }) satisfies FormRelayGroup,\n\n // initial values\n {\n isDirty: undefined,\n isSubmitting: undefined,\n isLoading: undefined,\n isSubmitted: undefined,\n isSubmitSuccessful: undefined,\n isValidating: undefined,\n isReady: undefined,\n isValid: undefined,\n disabled: undefined,\n // objects\n hasErrors: undefined,\n hasDirtyFields: undefined,\n hasTouchedFields: undefined,\n hasValidatingFields: undefined,\n // counts\n submitCount: undefined,\n // supplemental\n isMounted: undefined,\n },\n );\n","import React from 'react';\n\nimport type { RhfUtilsFormOptions } from '@/form/options/RhfUtilsFormOptionsType';\n\nimport type { FormsRelayed } from '../context/useFormRelayContext';\nimport { useFormRelayContext } from '../context/useFormRelayContext';\nimport { getFormRelayedAggregatedByRelayedItem } from '../context/utils';\nimport type { FormRelayOptions } from '../FormRelayOptions';\n\nimport type { FormRelayGroup } from './FormRelayGroupType';\n\nexport const useFormRelayId = (formId: string) =>\n useFormRelayContext().state[formId];\n\n//\n\nexport type FormRelayGroupCriteria =\n | { groups: string[] }\n | {\n predicate: (context: {\n groups: FormRelayOptions['groups'];\n options: RhfUtilsFormOptions;\n }) => boolean;\n };\n\nexport const useFormRelayGroup = (\n criteria?: FormRelayGroupCriteria,\n): FormRelayGroup => {\n const relayState = useFormRelayContext().state;\n\n const relayStateFiltered = getFormRelaysByCriteria(relayState, criteria);\n\n const state = getFormRelayedAggregatedByRelayedItem(\n relayStateFiltered.map(({ state }) => state),\n );\n\n const jsonState = JSON.stringify(state);\n\n const memoState = React.useMemo(\n () => state,\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [jsonState],\n );\n\n return memoState;\n};\n\n// WRITE TESTS\n\nconst getFormRelaysByCriteria = (\n relayState: FormsRelayed,\n criteria?: FormRelayGroupCriteria,\n) =>\n Object.values(relayState).filter(\n ({ options, utils }) =>\n // no criteria specified\n !criteria ||\n // groups specified\n ('groups' in criteria &&\n criteria.groups.filter((group) => options.groups?.includes(group))\n .length) ||\n // predicate specified\n ('predicate' in criteria &&\n criteria.predicate({\n groups: options.groups,\n options: utils.options,\n })),\n );\n","import { createContext } from '@/utils/createContext';\n\nimport type { FormRelayGroup } from '../../FormRelayGroupType';\n\nexport type FormRelayGrouperContext = {\n state: FormRelayGroup;\n};\n\n// context\n\nexport const {\n Provider: _FormRelayGrouperContextProvider,\n useRequired: _useFormRelayGrouperContext,\n useMaybe: _useFormRelayGrouperMaybeContext,\n} = createContext<FormRelayGrouperContext>();\n","import { useFormState } from 'react-hook-form';\n\nimport { useRhfUtilsMaybeContext } from '@/form/context/utils/useRhfUtilsContext';\n\nimport { getFormRelayedAggregatedByRelayedItem } from '../../context/utils';\n\nimport type { FormRelayGroup } from '../FormRelayGroupType';\nimport { useFormRelayGroup } from '../useFormRelay';\n\nimport { _useFormRelayGrouperMaybeContext } from './context';\n\n/* eslint-disable react-hooks/rules-of-hooks -- ⚠️ condition will (i.e., should) not change between renders! */\n\n/**\n * Use this when you don't (want to) know whether component is wrapped\n * with RHF context, `FormRelayGrouperContext`, or `FormRelayContext`.\n * Will return `FormRelayGroup`, regardless.\n *\n * Allows you to build naive components that are not tied to one specific context.\n */\nexport const useFirstFormStateGroup = (): FormRelayGroup => {\n const maybeUtils = useRhfUtilsMaybeContext();\n\n // if utils present, then relay unnecessary (bc we are in the context of a single form)\n\n if (maybeUtils) {\n const state = useFormState();\n\n return getFormRelayedAggregatedByRelayedItem([state]);\n }\n\n // if relay grouper present...\n\n const maybeRelayCtx = _useFormRelayGrouperMaybeContext();\n\n if (maybeRelayCtx) return maybeRelayCtx.state;\n\n // otherwise: use top-level relay\n\n return useFormRelayGroup();\n};\n"],"mappings":";;;;;AAQA,MAAa,yCACX,eAEA,WAAW,QACR,KAAK,UACH;CAEC,SAAS,IAAI,WAAW,KAAK;CAC7B,cAAc,IAAI,gBAAgB,KAAK;CACvC,WAAW,IAAI,aAAa,KAAK;CACjC,aAAa,IAAI,eAAe,KAAK;CACrC,oBAAoB,IAAI,sBAAsB,KAAK;CACnD,cAAc,IAAI,gBAAgB,KAAK;CACvC,SAAS,IAAI,WAAW,KAAK;CAC7B,SAAS,IAAI,WAAW,KAAK;CAC7B,UAAU,IAAI,YAAY,KAAK;CAE/B,WACE,IAAI,aAAc,KAAK,UAAU,CAAC,cAAc,KAAK,MAAM;CAC7D,gBACE,IAAI,kBACH,KAAK,eAAe,CAAC,cAAc,KAAK,WAAW;CACtD,kBACE,IAAI,oBACH,KAAK,iBAAiB,CAAC,cAAc,KAAK,aAAa;CAC1D,qBACE,IAAI,uBACH,KAAK,oBAAoB,CAAC,cAAc,KAAK,gBAAgB;CAEhE,cAAc,IAAI,eAAe,MAAM,KAAK,eAAe;CAE3D,WAAW,IAAI,aAAa,KAAK;AACnC,IAGF;CACE,SAAS,KAAA;CACT,cAAc,KAAA;CACd,WAAW,KAAA;CACX,aAAa,KAAA;CACb,oBAAoB,KAAA;CACpB,cAAc,KAAA;CACd,SAAS,KAAA;CACT,SAAS,KAAA;CACT,UAAU,KAAA;CAEV,WAAW,KAAA;CACX,gBAAgB,KAAA;CAChB,kBAAkB,KAAA;CAClB,qBAAqB,KAAA;CAErB,aAAa,KAAA;CAEb,WAAW,KAAA;AACb,CACF;;;ACpDF,MAAa,kBAAkB,WAC7B,oBAAoB,CAAC,CAAC,MAAM;AAa9B,MAAa,qBACX,aACmB;CACnB,MAAM,aAAa,oBAAoB,CAAC,CAAC;CAEzC,MAAM,qBAAqB,wBAAwB,YAAY,QAAQ;CAEvE,MAAM,QAAQ,sCACZ,mBAAmB,KAAK,EAAE,YAAY,KAAK,CAC7C;CAEA,MAAM,YAAY,KAAK,UAAU,KAAK;CAQtC,OANkB,MAAM,cAChB,OAEN,CAAC,SAAS,CAGG;AACjB;AAIA,MAAM,2BACJ,YACA,aAEA,OAAO,OAAO,UAAU,CAAC,CAAC,QACvB,EAAE,SAAS,YAEV,CAAC,YAEA,YAAY,YACX,SAAS,OAAO,QAAQ,UAAU,QAAQ,QAAQ,SAAS,KAAK,CAAC,CAAC,CAC/D,UAEJ,eAAe,YACd,SAAS,UAAU;CACjB,QAAQ,QAAQ;CAChB,SAAS,MAAM;AACjB,CAAC,CACP;;;ACzDF,MAAa,EACX,UAAU,kCACV,aAAa,6BACb,UAAU,qCACR,cAAuC;;;;;;;;;;ACM3C,MAAa,+BAA+C;CAK1D,IAJmB,wBAIN,GAAG;EACd,MAAM,QAAQ,aAAa;EAE3B,OAAO,sCAAsC,CAAC,KAAK,CAAC;CACtD;CAIA,MAAM,gBAAgB,iCAAiC;CAEvD,IAAI,eAAe,OAAO,cAAc;CAIxC,OAAO,kBAAkB;AAC3B"}
|
package/dist/tsdown/trpc.d.ts
CHANGED
|
@@ -9,13 +9,13 @@ import { AnyTRPCRouter } from "@trpc/server";
|
|
|
9
9
|
* @param onError Fallback for handling non-TRPC errors.
|
|
10
10
|
* @returns FormSubmitError
|
|
11
11
|
*/
|
|
12
|
-
declare const makeOnSubmitTrpcClientErrorHandler: (onNotTrpcClientError: NonNullable<RhfUtilsClientConfig["onSubmitErrorUnknown"]>) => (error: unknown) => FormSubmitFieldErrors | undefined;
|
|
12
|
+
export declare const makeOnSubmitTrpcClientErrorHandler: (onNotTrpcClientError: NonNullable<RhfUtilsClientConfig["onSubmitErrorUnknown"]>) => (error: unknown) => FormSubmitFieldErrors | undefined;
|
|
13
13
|
//#endregion
|
|
14
14
|
//#region src/errors/trpc/trpcClientErrorToFormSubmitFieldErrorsSchemaTransformer.d.ts
|
|
15
15
|
/**
|
|
16
16
|
* Schema that transforms {@link TRPCClientError} to RHF {@link FormSubmitFieldErrors}.
|
|
17
17
|
*/
|
|
18
|
-
declare const trpcClientErrorToFormSubmitFieldErrorsSchemaTransformer: z.ZodEffects<z.ZodEffects<z.ZodPipeline<z.ZodEffects<z.ZodEffects<z.ZodType<TRPCClientErrorLike<AnyTRPCRouter>, z.ZodTypeDef, TRPCClientErrorLike<AnyTRPCRouter>>, string, TRPCClientErrorLike<AnyTRPCRouter>>, unknown, TRPCClientErrorLike<AnyTRPCRouter>>, z.ZodArray<z.ZodObject<{
|
|
18
|
+
export declare const trpcClientErrorToFormSubmitFieldErrorsSchemaTransformer: z.ZodEffects<z.ZodEffects<z.ZodPipeline<z.ZodEffects<z.ZodEffects<z.ZodType<TRPCClientErrorLike<AnyTRPCRouter>, z.ZodTypeDef, TRPCClientErrorLike<AnyTRPCRouter>>, string, TRPCClientErrorLike<AnyTRPCRouter>>, unknown, TRPCClientErrorLike<AnyTRPCRouter>>, z.ZodArray<z.ZodObject<{
|
|
19
19
|
code: z.ZodString;
|
|
20
20
|
message: z.ZodString;
|
|
21
21
|
path: z.ZodArray<z.ZodString, "many">;
|
|
@@ -32,5 +32,4 @@ declare const trpcClientErrorToFormSubmitFieldErrorsSchemaTransformer: z.ZodEffe
|
|
|
32
32
|
message: string;
|
|
33
33
|
}])[], TRPCClientErrorLike<AnyTRPCRouter>>, FormSubmitFieldErrors, TRPCClientErrorLike<AnyTRPCRouter>>;
|
|
34
34
|
//#endregion
|
|
35
|
-
export { makeOnSubmitTrpcClientErrorHandler, trpcClientErrorToFormSubmitFieldErrorsSchemaTransformer };
|
|
36
35
|
//# sourceMappingURL=trpc.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"trpc.d.ts","names":[],"sources":["../../src/errors/trpc/makeOnSubmitTrpcClientErrorHandler.ts","../../src/errors/trpc/trpcClientErrorToFormSubmitFieldErrorsSchemaTransformer.ts"],"mappings":";;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"trpc.d.ts","names":[],"sources":["../../src/errors/trpc/makeOnSubmitTrpcClientErrorHandler.ts","../../src/errors/trpc/trpcClientErrorToFormSubmitFieldErrorsSchemaTransformer.ts"],"mappings":";;;;;;;;;;;qBAca,qCAET,sBAAsB,YACpB,mDAGH,mBAAiB;;;;;;qBCPP,yDAAuD,EAAA,WAAA,EAAA,WAAA,EAAA,YAAA,EAAA,WAAA,EAAA,WAAA,EAAA,QAAA,oBAAA,gBAAA,EAAA,YAAA,oBAAA,yBAAA,oBAAA,0BAAA,oBAAA,iBAAA,EAAA,SAAA,EAAA;;;;;;;;;;;;;;;OA6CS,oBAAA,iBAAA,uBAAA,oBAAA"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@paragrav/rhf-utils",
|
|
3
3
|
"author": "paragrav.dev",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.77.0",
|
|
5
5
|
"description": "Integration utilities for react-hook-form.",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"sideEffects": false,
|
|
@@ -43,18 +43,18 @@
|
|
|
43
43
|
}
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
|
-
"@eslint/compat": "
|
|
46
|
+
"@eslint/compat": "2.1.0",
|
|
47
47
|
"@eslint/config-helpers": "^0.7.0",
|
|
48
|
-
"@eslint/eslintrc": "^3.3.
|
|
48
|
+
"@eslint/eslintrc": "^3.3.7",
|
|
49
49
|
"@eslint/js": "^9.39.5",
|
|
50
|
-
"@playwright/experimental-ct-react": "^1.
|
|
51
|
-
"@playwright/test": "^1.
|
|
50
|
+
"@playwright/experimental-ct-react": "^1.62.1",
|
|
51
|
+
"@playwright/test": "^1.62.1",
|
|
52
52
|
"@rollup/plugin-typescript": "^12.3.0",
|
|
53
53
|
"@types/node": "^24.13.3",
|
|
54
|
-
"@typescript-eslint/eslint-plugin": "^8.
|
|
55
|
-
"@typescript-eslint/parser": "^8.
|
|
54
|
+
"@typescript-eslint/eslint-plugin": "^8.70.0",
|
|
55
|
+
"@typescript-eslint/parser": "^8.70.0",
|
|
56
56
|
"@typescript/native": "npm:typescript@^7.0.2",
|
|
57
|
-
"@vitejs/plugin-react": "^6.
|
|
57
|
+
"@vitejs/plugin-react": "^6.1.1",
|
|
58
58
|
"clean-publish": "^7.1.0",
|
|
59
59
|
"cross-env": "^10.1.0",
|
|
60
60
|
"eslint": "^9.39.5",
|
|
@@ -66,21 +66,21 @@
|
|
|
66
66
|
"eslint-plugin-prettier": "^5.5.6",
|
|
67
67
|
"eslint-plugin-react": "^7.37.5",
|
|
68
68
|
"eslint-plugin-react-hooks": "^7.1.1",
|
|
69
|
-
"eslint-plugin-react-refresh": "^0.5.
|
|
69
|
+
"eslint-plugin-react-refresh": "^0.5.6",
|
|
70
70
|
"eslint-plugin-simple-import-sort": "^14.0.0",
|
|
71
|
-
"globals": "^17.
|
|
72
|
-
"happy-dom": "^20.
|
|
71
|
+
"globals": "^17.12.0",
|
|
72
|
+
"happy-dom": "^20.14.0",
|
|
73
73
|
"husky": "^9.1.7",
|
|
74
|
-
"lint-staged": "^17.
|
|
74
|
+
"lint-staged": "^17.5.0",
|
|
75
75
|
"prettier": "^3.9.6",
|
|
76
|
-
"rollup": "^4.
|
|
76
|
+
"rollup": "^4.63.1",
|
|
77
77
|
"safe-stable-stringify": "^2.5.0",
|
|
78
|
-
"terser": "^5.
|
|
79
|
-
"tsdown": "^0.
|
|
78
|
+
"terser": "^5.51.2",
|
|
79
|
+
"tsdown": "^0.23.0",
|
|
80
80
|
"typescript": "^6.0.3",
|
|
81
|
-
"typescript-eslint": "^8.
|
|
82
|
-
"vite": "^8.
|
|
83
|
-
"vitest": "^
|
|
81
|
+
"typescript-eslint": "^8.70.0",
|
|
82
|
+
"vite": "^8.2.2",
|
|
83
|
+
"vitest": "^5.0.0"
|
|
84
84
|
},
|
|
85
85
|
"repository": {
|
|
86
86
|
"type": "git",
|