You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1 line
265 KiB

2 years ago
{"ast":null,"code":"import React from 'react';\n\nvar isCheckBoxInput = element => element.type === 'checkbox';\n\nvar isDateObject = value => value instanceof Date;\n\nvar isNullOrUndefined = value => value == null;\n\nconst isObjectType = value => typeof value === 'object';\n\nvar isObject = value => !isNullOrUndefined(value) && !Array.isArray(value) && isObjectType(value) && !isDateObject(value);\n\nvar getEventValue = event => isObject(event) && event.target ? isCheckBoxInput(event.target) ? event.target.checked : event.target.value : event;\n\nvar getNodeParentName = name => name.substring(0, name.search(/\\.\\d+(\\.|$)/)) || name;\n\nvar isNameInFieldArray = (names, name) => names.has(getNodeParentName(name));\n\nvar compact = value => Array.isArray(value) ? value.filter(Boolean) : [];\n\nvar isUndefined = val => val === undefined;\n\nvar get = (obj, path, defaultValue) => {\n if (!path || !isObject(obj)) {\n return defaultValue;\n }\n\n const result = compact(path.split(/[,[\\].]+?/)).reduce((result, key) => isNullOrUndefined(result) ? result : result[key], obj);\n return isUndefined(result) || result === obj ? isUndefined(obj[path]) ? defaultValue : obj[path] : result;\n};\n\nconst EVENTS = {\n BLUR: 'blur',\n FOCUS_OUT: 'focusout',\n CHANGE: 'change'\n};\nconst VALIDATION_MODE = {\n onBlur: 'onBlur',\n onChange: 'onChange',\n onSubmit: 'onSubmit',\n onTouched: 'onTouched',\n all: 'all'\n};\nconst INPUT_VALIDATION_RULES = {\n max: 'max',\n min: 'min',\n maxLength: 'maxLength',\n minLength: 'minLength',\n pattern: 'pattern',\n required: 'required',\n validate: 'validate'\n};\nconst HookFormContext = React.createContext(null);\n/**\r\n * This custom hook allows you to access the form context. useFormContext is intended to be used in deeply nested structures, where it would become inconvenient to pass the context as a prop. To be used with {@link FormProvider}.\r\n *\r\n * @remarks\r\n * [API](https://react-hook-form.com/api/useformcontext) • [Demo](https://codesandbox.io/s/react-hook-form-v7-form-context-ytudi)\r\n *\r\n * @returns return all useForm methods\r\n *\r\n * @example\r\n * ```tsx\r\n * function App() {\r\n * const methods = useForm();\r\n * const onSubmit = data => console.log(data);\r\n *\r\n * return (\r\n * <FormProvider {...methods} >\r\n * <form onSubmit={methods.handleSubmit(onSubmit)}>\r\n * <NestedInput />\r\n * <input type=\"submit\" />\r\n * </form>\r\n * </FormProvider>\r\n * );\r\n * }\r\n *\r\n * function NestedInput() {\r\n * const { register } = useFormContext(); // retrieve all hook methods\r\n * return <input {...register(\"test\")} />;\r\n * }\r\n * ```\r\n */\n\nconst useFormContext = () => React.useContext(HookFormContext);\n/**\r\n * A provider component that propagates the `useForm` methods to all children components via [React Context](https://reactjs.org/docs/context.html) API. To be used with {@link useFormContext}.\r\n *\r\n * @remarks\r\n * [API](https://react-hook-form.com/api/useformcontext) • [Demo](https://codesandbox.io/s/react-hook-form-v7-form-context-ytudi)\r\n *\r\n * @param props - all useFrom methods\r\n *\r\n * @example\r\n * ```tsx\r\n * function App() {\r\n * const methods = useForm();\r\n * const onSubmit = data => console.log(data);\r\n *\r\n * return (\r\n * <FormProvider {...methods} >\r\n * <form onSubmit={methods.handleSubmit(onSubmit)}>\r\n * <NestedInput />\r\n * <input type=\"submit\" />\r\n * </form>\r\n * </FormProvider>\r\n * );\r\n * }\r\n *\r\n * function NestedInput() {\r\n * const { register } = useFormContext(); // retrieve all hook methods\r\n * return <input {...register(\"test\")} />;\r\n * }\r\n * ```\r\n */\n\n\nconst FormProvider = props => {\n const {\n children,\n ...data\n } = props;\n return React.createElement(HookFormContext.Provider, {\n value: data\n }, children);\n};\n\nvar getProxyFormState = function (formState, _proxyFormState, localProxyFormState) {\n let isRoot = arguments.length > 3 && arg