node_modules ignore

This commit is contained in:
oier committed 2025-05-08 23:43:47 +02:00
1 parent e19d52f172
commit 4574544c9f
65041 files changed
+10593536

No files matched your search

+16
View File
@@ -0,0 +1,16 @@
/// <reference types="hoist-non-react-statics" />
import * as React from 'react';
import { FormikContextType } from './types';
export interface ErrorMessageProps {
id?: string;
name: string;
className?: string;
component?: string | React.ComponentType;
children?: (errorMessage: string) => React.ReactNode;
render?: (errorMessage: string) => React.ReactNode;
}
export declare const ErrorMessage: React.FC<ErrorMessageProps> & import("hoist-non-react-statics").NonReactStatics<React.ComponentClass<ErrorMessageProps & {
formik: FormikContextType<ErrorMessageProps & {
formik: FormikContextType<any>;
}>;
}, any>, {}>;
+15
View File
@@ -0,0 +1,15 @@
/// <reference types="hoist-non-react-statics" />
import * as React from 'react';
import { FormikProps, GenericFieldHTMLAttributes, FieldMetaProps, FieldInputProps } from './types';
import { FieldConfig } from './Field';
export interface FastFieldProps<V = any> {
field: FieldInputProps<V>;
meta: FieldMetaProps<V>;
form: FormikProps<V>;
}
export type FastFieldConfig<T> = FieldConfig & {
/** Override FastField's default shouldComponentUpdate */
shouldUpdate?: (nextProps: T & GenericFieldHTMLAttributes, props: {}) => boolean;
};
export type FastFieldAttributes<T> = GenericFieldHTMLAttributes & FastFieldConfig<T> & T;
export declare const FastField: React.FC<any> & import("hoist-non-react-statics").NonReactStatics<React.ComponentClass<any, any>, {}>;
+53
View File
@@ -0,0 +1,53 @@
import * as React from 'react';
import { FormikProps, GenericFieldHTMLAttributes, FieldMetaProps, FieldHelperProps, FieldInputProps, FieldValidator } from './types';
export interface FieldProps<V = any, FormValues = any> {
field: FieldInputProps<V>;
form: FormikProps<FormValues>;
meta: FieldMetaProps<V>;
}
export interface FieldConfig<V = any> {
/**
* Field component to render. Can either be a string like 'select' or a component.
*/
component?: string | React.ComponentType<FieldProps<V>> | React.ComponentType | React.ForwardRefExoticComponent<any>;
/**
* Component to render. Can either be a string e.g. 'select', 'input', or 'textarea', or a component.
*/
as?: React.ComponentType<FieldProps<V>['field']> | string | React.ComponentType | React.ForwardRefExoticComponent<any>;
/**
* Render prop (works like React router's <Route render={props =>} />)
* @deprecated
*/
render?: (props: FieldProps<V>) => React.ReactNode;
/**
* Children render function <Field name>{props => ...}</Field>)
*/
children?: ((props: FieldProps<V>) => React.ReactNode) | React.ReactNode;
/**
* Validate a single field value independently
*/
validate?: FieldValidator;
/**
* Used for 'select' and related input types.
*/
multiple?: boolean;
/**
* Field name
*/
name: string;
/** HTML input type */
type?: string;
/** Field value */
value?: any;
/** Inner ref */
innerRef?: (instance: any) => void;
}
export type FieldAttributes<T> = {
className?: string;
} & GenericFieldHTMLAttributes & FieldConfig<T> & T & {
name: string;
};
export type FieldHookConfig<T> = GenericFieldHTMLAttributes & FieldConfig<T>;
export declare function useField<Val = any>(propsOrFieldName: string | FieldHookConfig<Val>): [FieldInputProps<Val>, FieldMetaProps<Val>, FieldHelperProps<Val>];
export declare function Field({ validate, name, render, children, as: is, // `as` is reserved in typescript lol
component, className, ...props }: FieldAttributes<any>): any;
+62
View File
@@ -0,0 +1,62 @@
/// <reference types="hoist-non-react-statics" />
import * as React from 'react';
import { FormikContextType, FormikProps, SharedRenderProps } from './types';
export type FieldArrayRenderProps = ArrayHelpers & {
form: FormikProps<any>;
name: string;
};
export type FieldArrayConfig = {
/** Really the path to the array field to be updated */
name: string;
/** Should field array validate the form AFTER array updates/changes? */
validateOnChange?: boolean;
} & SharedRenderProps<FieldArrayRenderProps>;
export interface ArrayHelpers<T extends any[] = any[]> {
/** Imperatively add a value to the end of an array */
push<X = T[number]>(obj: X): void;
/** Curried fn to add a value to the end of an array */
handlePush<X = T[number]>(obj: X): () => void;
/** Imperatively swap two values in an array */
swap: (indexA: number, indexB: number) => void;
/** Curried fn to swap two values in an array */
handleSwap: (indexA: number, indexB: number) => () => void;
/** Imperatively move an element in an array to another index */
move: (from: number, to: number) => void;
/** Imperatively move an element in an array to another index */
handleMove: (from: number, to: number) => () => void;
/** Imperatively insert an element at a given index into the array */
insert<X = T[number]>(index: number, value: X): void;
/** Curried fn to insert an element at a given index into the array */
handleInsert<X = T[number]>(index: number, value: X): () => void;
/** Imperatively replace a value at an index of an array */
replace<X = T[number]>(index: number, value: X): void;
/** Curried fn to replace an element at a given index into the array */
handleReplace<X = T[number]>(index: number, value: X): () => void;
/** Imperatively add an element to the beginning of an array and return its length */
unshift<X = T[number]>(value: X): number;
/** Curried fn to add an element to the beginning of an array */
handleUnshift<X = T[number]>(value: X): () => void;
/** Curried fn to remove an element at an index of an array */
handleRemove: (index: number) => () => void;
/** Curried fn to remove a value from the end of the array */
handlePop: () => () => void;
/** Imperatively remove and element at an index of an array */
remove<X = T[number]>(index: number): X | undefined;
/** Imperatively remove and return value from the end of the array */
pop<X = T[number]>(): X | undefined;
}
/**
* Some array helpers!
*/
export declare const move: <T>(array: T[], from: number, to: number) => unknown[];
export declare const swap: <T>(arrayLike: ArrayLike<T>, indexA: number, indexB: number) => unknown[];
export declare const insert: <T>(arrayLike: ArrayLike<T>, index: number, value: T) => unknown[];
export declare const replace: <T>(arrayLike: ArrayLike<T>, index: number, value: T) => unknown[];
export declare const FieldArray: React.FC<FieldArrayConfig> & import("hoist-non-react-statics").NonReactStatics<React.ComponentClass<{
/** Really the path to the array field to be updated */
name: string;
/** Should field array validate the form AFTER array updates/changes? */
validateOnChange?: boolean | undefined;
} & SharedRenderProps<FieldArrayRenderProps> & {
formik: FormikContextType<any>;
}, any>, {}>;
+3
View File
@@ -0,0 +1,3 @@
import * as React from 'react';
export type FormikFormProps = Pick<React.FormHTMLAttributes<HTMLFormElement>, Exclude<keyof React.FormHTMLAttributes<HTMLFormElement>, 'onReset' | 'onSubmit'>>;
export declare const Form: React.ForwardRefExoticComponent<Omit<React.DetailedHTMLProps<React.FormHTMLAttributes<HTMLFormElement>, HTMLFormElement>, "ref"> & React.RefAttributes<HTMLFormElement>>;
+62
View File
@@ -0,0 +1,62 @@
import * as React from 'react';
import { FieldConfig } from './Field';
import { FieldHelperProps, FieldInputProps, FieldMetaProps, FormikConfig, FormikErrors, FormikState, FormikTouched, FormikValues } from './types';
export declare function useFormik<Values extends FormikValues = FormikValues>({ validateOnChange, validateOnBlur, validateOnMount, isInitialValid, enableReinitialize, onSubmit, ...rest }: FormikConfig<Values>): {
initialValues: Values;
initialErrors: FormikErrors<unknown>;
initialTouched: FormikTouched<unknown>;
initialStatus: any;
handleBlur: {
(e: React.FocusEvent<any, Element>): void;
<T = any>(fieldOrEvent: T): T extends string ? (e: any) => void : void;
};
handleChange: {
(e: React.ChangeEvent<any>): void;
<T_1 = string | React.ChangeEvent<any>>(field: T_1): T_1 extends React.ChangeEvent<any> ? void : (e: string | React.ChangeEvent<any>) => void;
};
handleReset: (e: any) => void;
handleSubmit: (e?: React.FormEvent<HTMLFormElement>) => void;
resetForm: (nextState?: Partial<FormikState<Values>>) => void;
setErrors: (errors: FormikErrors<Values>) => void;
setFormikState: (stateOrCb: FormikState<Values> | ((state: FormikState<Values>) => FormikState<Values>)) => void;
setFieldTouched: (field: string, touched?: boolean, shouldValidate?: boolean) => Promise<FormikErrors<Values>> | Promise<void>;
setFieldValue: (field: string, value: any, shouldValidate?: boolean) => Promise<FormikErrors<Values>> | Promise<void>;
setFieldError: (field: string, value: string | undefined) => void;
setStatus: (status: any) => void;
setSubmitting: (isSubmitting: boolean) => void;
setTouched: (touched: FormikTouched<Values>, shouldValidate?: boolean) => Promise<FormikErrors<Values>> | Promise<void>;
setValues: (values: React.SetStateAction<Values>, shouldValidate?: boolean) => Promise<FormikErrors<Values>> | Promise<void>;
submitForm: () => Promise<any>;
validateForm: (values?: Values) => Promise<FormikErrors<Values>>;
validateField: (name: string) => Promise<void> | Promise<string | undefined>;
isValid: boolean;
dirty: boolean;
unregisterField: (name: string) => void;
registerField: (name: string, { validate }: any) => void;
getFieldProps: (nameOrOptions: string | FieldConfig<any>) => FieldInputProps<any>;
getFieldMeta: (name: string) => FieldMetaProps<any>;
getFieldHelpers: (name: string) => FieldHelperProps<any>;
validateOnBlur: boolean;
validateOnChange: boolean;
validateOnMount: boolean;
values: Values;
errors: FormikErrors<Values>;
touched: FormikTouched<Values>;
isSubmitting: boolean;
isValidating: boolean;
status?: any;
submitCount: number;
};
export declare function Formik<Values extends FormikValues = FormikValues, ExtraProps = {}>(props: FormikConfig<Values> & ExtraProps): React.JSX.Element;
/**
* Transform Yup ValidationError to a more usable object
*/
export declare function yupToFormErrors<Values>(yupError: any): FormikErrors<Values>;
/**
* Validate a yup schema.
*/
export declare function validateYupSchema<T extends FormikValues>(values: T, schema: any, sync?: boolean, context?: any): Promise<Partial<T>>;
/**
* Recursively prepare values.
*/
export declare function prepareDataForValidation<T extends FormikValues>(values: T): FormikValues;
+6
View File
@@ -0,0 +1,6 @@
import * as React from 'react';
import { FormikContextType } from './types';
export declare const FormikContext: React.Context<FormikContextType<any>>;
export declare const FormikProvider: React.Provider<FormikContextType<any>>;
export declare const FormikConsumer: React.Consumer<FormikContextType<any>>;
export declare function useFormikContext<Values>(): FormikContextType<Values>;
+12
View File
@@ -0,0 +1,12 @@
import * as React from 'react';
import hoistNonReactStatics from 'hoist-non-react-statics';
import { FormikContextType } from './types';
/**
* Connect any component to Formik context, and inject as a prop called `formik`;
* @param Comp React Component
*/
export declare function connect<OuterProps, Values = {}>(Comp: React.ComponentType<OuterProps & {
formik: FormikContextType<Values>;
}>): React.FC<OuterProps> & hoistNonReactStatics.NonReactStatics<React.ComponentClass<OuterProps & {
formik: FormikContextType<Values>;
}, any>, {}>;
File diff suppressed because it is too large. Load diff
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"formik.cjs.development.js","sources":["../src/FormikContext.tsx","../src/utils.ts","../src/Formik.tsx","../src/Field.tsx","../src/Form.tsx","../src/withFormik.tsx","../src/connect.tsx","../src/FieldArray.tsx","../src/ErrorMessage.tsx","../src/FastField.tsx"],"sourcesContent":["import * as React from 'react';\nimport { FormikContextType } from './types';\nimport invariant from 'tiny-warning';\n\nexport const FormikContext = React.createContext<FormikContextType<any>>(\n undefined as any\n);\nFormikContext.displayName = 'FormikContext';\n\nexport const FormikProvider = FormikContext.Provider;\nexport const FormikConsumer = FormikContext.Consumer;\n\nexport function useFormikContext<Values>() {\n const formik = React.useContext<FormikContextType<Values>>(FormikContext);\n\n invariant(\n !!formik,\n `Formik context is undefined, please verify you are calling useFormikContext() as child of a <Formik> component.`\n );\n\n return formik;\n}\n","import clone from 'lodash/clone';\nimport toPath from 'lodash/toPath';\nimport * as React from 'react';\n\n// Assertions\n\n/** @private is the value an empty array? */\nexport const isEmptyArray = (value?: any) =>\n Array.isArray(value) && value.length === 0;\n\n/** @private is the given object a Function? */\nexport const isFunction = (obj: any): obj is Function =>\n typeof obj === 'function';\n\n/** @private is the given object an Object? */\nexport const isObject = (obj: any): obj is Object =>\n obj !== null && typeof obj === 'object';\n\n/** @private is the given object an integer? */\nexport const isInteger = (obj: any): boolean =>\n String(Math.floor(Number(obj))) === obj;\n\n/** @private is the given object a string? */\nexport const isString = (obj: any): obj is string =>\n Object.prototype.toString.call(obj) === '[object String]';\n\n/** @private is the given object a NaN? */\n// eslint-disable-next-line no-self-compare\nexport const isNaN = (obj: any): boolean => obj !== obj;\n\n/** @private Does a React component have exactly 0 children? */\nexport const isEmptyChildren = (children: any): boolean =>\n React.Children.count(children) === 0;\n\n/** @private is the given object/value a promise? */\nexport const isPromise = (value: any): value is PromiseLike<any> =>\n isObject(value) && isFunction(value.then);\n\n/** @private is the given object/value a type of synthetic event? */\nexport const isInputEvent = (value: any): value is React.SyntheticEvent<any> =>\n value && isObject(value) && isObject(value.target);\n\n/**\n * Same as document.activeElement but wraps in a try-catch block. In IE it is\n * not safe to call document.activeElement if there is nothing focused.\n *\n * The activeElement will be null only if the document or document body is not\n * yet defined.\n *\n * @param {?Document} doc Defaults to current document.\n * @return {Element | null}\n * @see https://github.com/facebook/fbjs/blob/master/packages/fbjs/src/core/dom/getActiveElement.js\n */\nexport function getActiveElement(doc?: Document): Element | null {\n doc = doc || (typeof document !== 'undefined' ? document : undefined);\n if (typeof doc === 'undefined') {\n return null;\n }\n try {\n return doc.activeElement || doc.body;\n } catch (e) {\n return doc.body;\n }\n}\n\n/**\n * Deeply get a value from an object via its path.\n */\nexport function getIn(\n obj: any,\n key: string | string[],\n def?: any,\n p: number = 0\n) {\n const path = toPath(key);\n while (obj && p < path.length) {\n obj = obj[path[p++]];\n }\n\n // check if path is not in the end\n if (p !== path.length && !obj) {\n return def;\n }\n\n return obj === undefined ? def : obj;\n}\n\n/**\n * Deeply set a value from in object via it's path. If the value at `path`\n * has changed, return a shallow copy of obj with `value` set at `path`.\n * If `value` has not changed, return the original `obj`.\n *\n * Existing objects / arrays along `path` are also shallow copied. Sibling\n * objects along path retain the same internal js reference. Since new\n * objects / arrays are only created along `path`, we can test if anything\n * changed in a nested structure by comparing the object's reference in\n * the old and new object, similar to how russian doll cache invalidation\n * works.\n *\n * In earlier versions of this function, which used cloneDeep, there were\n * issues whereby settings a nested value would mutate the parent\n * instead of creating a new object. `clone` avoids that bug making a\n * shallow copy of the objects along the update path\n * so no object is mutated in place.\n *\n * Before changing this function, please read through the following\n * discussions.\n *\n * @see https://github.com/developit/linkstate\n * @see https://github.com/jaredpalmer/formik/pull/123\n */\nexport function setIn(obj: any, path: string, value: any): any {\n let res: any = clone(obj); // this keeps inheritance when obj is a class\n let resVal: any = res;\n let i = 0;\n Line truncated
+2
View File
@@ -0,0 +1,2 @@
"use strict";function e(e){return e&&"object"==typeof e&&"default"in e?e.default:e}Object.defineProperty(exports,"__esModule",{value:!0});var r=e(require("deepmerge")),t=e(require("lodash/isPlainObject")),n=require("react"),i=e(require("react-fast-compare")),a=e(require("tiny-warning")),o=e(require("lodash/clone")),u=e(require("lodash/toPath")),s=e(require("hoist-non-react-statics")),l=e(require("lodash/cloneDeep"));function c(){return(c=Object.assign||function(e){for(var r=1;r<arguments.length;r++){var t=arguments[r];for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])}return e}).apply(this,arguments)}function p(e,r){e.prototype=Object.create(r.prototype),e.prototype.constructor=e,e.__proto__=r}function d(e,r){if(null==e)return{};var t,n,i={},a=Object.keys(e);for(n=0;n<a.length;n++)r.indexOf(t=a[n])>=0||(i[t]=e[t]);return i}function f(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}var v=n.createContext(void 0);v.displayName="FormikContext";var h=v.Provider,m=v.Consumer;function y(){var e=n.useContext(v);return e||a(!1),e}var E=function(e){return Array.isArray(e)&&0===e.length},S=function(e){return"function"==typeof e},T=function(e){return null!==e&&"object"==typeof e},g=function(e){return String(Math.floor(Number(e)))===e},b=function(e){return"[object String]"===Object.prototype.toString.call(e)},F=function(e){return 0===n.Children.count(e)},k=function(e){return T(e)&&S(e.then)};function A(e,r,t,n){void 0===n&&(n=0);for(var i=u(r);e&&n<i.length;)e=e[i[n++]];return n===i.length||e?void 0===e?t:e:t}function R(e,r,t){for(var n=o(e),i=n,a=0,s=u(r);a<s.length-1;a++){var l=s[a],c=A(e,s.slice(0,a+1));if(c&&(T(c)||Array.isArray(c)))i=i[l]=o(c);else{var p=s[a+1];i=i[l]=g(p)&&Number(p)>=0?[]:{}}}return(0===a?e:i)[s[a]]===t?e:(void 0===t?delete i[s[a]]:i[s[a]]=t,0===a&&void 0===t&&delete n[s[a]],n)}function _(e,r,t,n){void 0===t&&(t=new WeakMap),void 0===n&&(n={});for(var i=0,a=Object.keys(e);i<a.length;i++){var o=a[i],u=e[o];T(u)?t.get(u)||(t.set(u,!0),n[o]=Array.isArray(u)?[]:{},_(u,r,t,n[o])):n[o]=r}return n}var O={},C={};function I(e){var t=e.validateOnChange,a=void 0===t||t,o=e.validateOnBlur,u=void 0===o||o,s=e.validateOnMount,l=void 0!==s&&s,p=e.isInitialValid,f=e.enableReinitialize,v=void 0!==f&&f,h=e.onSubmit,m=d(e,["validateOnChange","validateOnBlur","validateOnMount","isInitialValid","enableReinitialize","onSubmit"]),y=c({validateOnChange:a,validateOnBlur:u,validateOnMount:l,onSubmit:h},m),E=n.useRef(y.initialValues),g=n.useRef(y.initialErrors||O),F=n.useRef(y.initialTouched||C),I=n.useRef(y.initialStatus),P=n.useRef(!1),V=n.useRef({});n.useEffect((function(){return P.current=!0,function(){P.current=!1}}),[]);var M=n.useState(0)[1],L=n.useRef({values:y.initialValues,errors:y.initialErrors||O,touched:y.initialTouched||C,status:y.initialStatus,isSubmitting:!1,isValidating:!1,submitCount:0}),N=L.current,j=n.useCallback((function(e){var r=L.current;L.current=function(e,r){switch(r.type){case"SET_VALUES":return c({},e,{values:r.payload});case"SET_TOUCHED":return c({},e,{touched:r.payload});case"SET_ERRORS":return i(e.errors,r.payload)?e:c({},e,{errors:r.payload});case"SET_STATUS":return c({},e,{status:r.payload});case"SET_ISSUBMITTING":return c({},e,{isSubmitting:r.payload});case"SET_ISVALIDATING":return c({},e,{isValidating:r.payload});case"SET_FIELD_VALUE":return c({},e,{values:R(e.values,r.payload.field,r.payload.value)});case"SET_FIELD_TOUCHED":return c({},e,{touched:R(e.touched,r.payload.field,r.payload.value)});case"SET_FIELD_ERROR":return c({},e,{errors:R(e.errors,r.payload.field,r.payload.value)});case"RESET_FORM":return c({},e,r.payload);case"SET_FORMIK_STATE":return r.payload(e);case"SUBMIT_ATTEMPT":return c({},e,{touched:_(e.values,!0),isSubmitting:!0,submitCount:e.submitCount+1});case"SUBMIT_FAILURE":case"SUBMIT_SUCCESS":return c({},e,{isSubmitting:!1});default:return e}}(r,e),r!==L.current&&M((function(e){return e+1}))}),[]),B=n.useCallback((function(e,r){return new Promise((function(t,n){var i=y.validate(e,r);null==i?t(O):k(i)?i.then((function(e){t(e||O)}),(function(e){n(e)})):t(i)}))}),[y.validate]),q=n.useCallback((function(e,r){var t=y.validationSchema,n=S(t)?t(r):t,i=r&&n.validateAt?n.validateAt(r,e):U(e,n);return new Promise((function(e,r){i.then((function(){e(O)}),(function(t){"ValidationError"===t.name?e(x(t)):r(t)}))}))}),[y.validationSchema]),G=n.useCallback((function(e,r){return new Promise((function(t){return t(V.current[e].validate(r))}))}),[]),H=n.useCallback((function(e){var r=Object.keys(V.current).filter((function(e){return S(V.current[e].validate)})),t=r.length>0?r.map((function(r){return G(r,A(e,r))})):[Promise.resolve("DO_NOT_DELETE_YOU_WILL_BE_FIRED")];return Promise.all(t).then((function(e){return e.reduce((function(e,t,n){return"DO_NOT_DELETE_YOU_WILL_BE_FIRED"===t?e:(t&&(e=R(e,r[n],t)),e)}),{})}))}),[G]),W=n.useCallback((function(e){return Promise.all([H(e),y.validationSchema?q(e):{},y.validatLine truncated
//# sourceMappingURL=formik.cjs.production.min.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"formik.cjs.production.min.js","sources":["../src/FormikContext.tsx","../src/utils.ts","../src/Formik.tsx","../src/Form.tsx","../src/connect.tsx","../src/FieldArray.tsx","../src/ErrorMessage.tsx","../src/FastField.tsx","../src/Field.tsx","../src/withFormik.tsx"],"sourcesContent":["import * as React from 'react';\nimport { FormikContextType } from './types';\nimport invariant from 'tiny-warning';\n\nexport const FormikContext = React.createContext<FormikContextType<any>>(\n undefined as any\n);\nFormikContext.displayName = 'FormikContext';\n\nexport const FormikProvider = FormikContext.Provider;\nexport const FormikConsumer = FormikContext.Consumer;\n\nexport function useFormikContext<Values>() {\n const formik = React.useContext<FormikContextType<Values>>(FormikContext);\n\n invariant(\n !!formik,\n `Formik context is undefined, please verify you are calling useFormikContext() as child of a <Formik> component.`\n );\n\n return formik;\n}\n","import clone from 'lodash/clone';\nimport toPath from 'lodash/toPath';\nimport * as React from 'react';\n\n// Assertions\n\n/** @private is the value an empty array? */\nexport const isEmptyArray = (value?: any) =>\n Array.isArray(value) && value.length === 0;\n\n/** @private is the given object a Function? */\nexport const isFunction = (obj: any): obj is Function =>\n typeof obj === 'function';\n\n/** @private is the given object an Object? */\nexport const isObject = (obj: any): obj is Object =>\n obj !== null && typeof obj === 'object';\n\n/** @private is the given object an integer? */\nexport const isInteger = (obj: any): boolean =>\n String(Math.floor(Number(obj))) === obj;\n\n/** @private is the given object a string? */\nexport const isString = (obj: any): obj is string =>\n Object.prototype.toString.call(obj) === '[object String]';\n\n/** @private is the given object a NaN? */\n// eslint-disable-next-line no-self-compare\nexport const isNaN = (obj: any): boolean => obj !== obj;\n\n/** @private Does a React component have exactly 0 children? */\nexport const isEmptyChildren = (children: any): boolean =>\n React.Children.count(children) === 0;\n\n/** @private is the given object/value a promise? */\nexport const isPromise = (value: any): value is PromiseLike<any> =>\n isObject(value) && isFunction(value.then);\n\n/** @private is the given object/value a type of synthetic event? */\nexport const isInputEvent = (value: any): value is React.SyntheticEvent<any> =>\n value && isObject(value) && isObject(value.target);\n\n/**\n * Same as document.activeElement but wraps in a try-catch block. In IE it is\n * not safe to call document.activeElement if there is nothing focused.\n *\n * The activeElement will be null only if the document or document body is not\n * yet defined.\n *\n * @param {?Document} doc Defaults to current document.\n * @return {Element | null}\n * @see https://github.com/facebook/fbjs/blob/master/packages/fbjs/src/core/dom/getActiveElement.js\n */\nexport function getActiveElement(doc?: Document): Element | null {\n doc = doc || (typeof document !== 'undefined' ? document : undefined);\n if (typeof doc === 'undefined') {\n return null;\n }\n try {\n return doc.activeElement || doc.body;\n } catch (e) {\n return doc.body;\n }\n}\n\n/**\n * Deeply get a value from an object via its path.\n */\nexport function getIn(\n obj: any,\n key: string | string[],\n def?: any,\n p: number = 0\n) {\n const path = toPath(key);\n while (obj && p < path.length) {\n obj = obj[path[p++]];\n }\n\n // check if path is not in the end\n if (p !== path.length && !obj) {\n return def;\n }\n\n return obj === undefined ? def : obj;\n}\n\n/**\n * Deeply set a value from in object via it's path. If the value at `path`\n * has changed, return a shallow copy of obj with `value` set at `path`.\n * If `value` has not changed, return the original `obj`.\n *\n * Existing objects / arrays along `path` are also shallow copied. Sibling\n * objects along path retain the same internal js reference. Since new\n * objects / arrays are only created along `path`, we can test if anything\n * changed in a nested structure by comparing the object's reference in\n * the old and new object, similar to how russian doll cache invalidation\n * works.\n *\n * In earlier versions of this function, which used cloneDeep, there were\n * issues whereby settings a nested value would mutate the parent\n * instead of creating a new object. `clone` avoids that bug making a\n * shallow copy of the objects along the update path\n * so no object is mutated in place.\n *\n * Before changing this function, please read through the following\n * discussions.\n *\n * @see https://github.com/developit/linkstate\n * @see https://github.com/jaredpalmer/formik/pull/123\n */\nexport function setIn(obj: any, path: string, value: any): any {\n let res: any = clone(obj); // this keeps inheritance when obj is a class\n let resVal: any = res;\n let i = 0;Line truncated
+2005
View File
File diff suppressed because it is too large. Load diff
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"formik.esm.js","sources":["../src/FormikContext.tsx","../src/utils.ts","../src/Formik.tsx","../src/Field.tsx","../src/Form.tsx","../src/withFormik.tsx","../src/connect.tsx","../src/FieldArray.tsx","../src/ErrorMessage.tsx","../src/FastField.tsx"],"sourcesContent":["import * as React from 'react';\nimport { FormikContextType } from './types';\nimport invariant from 'tiny-warning';\n\nexport const FormikContext = React.createContext<FormikContextType<any>>(\n undefined as any\n);\nFormikContext.displayName = 'FormikContext';\n\nexport const FormikProvider = FormikContext.Provider;\nexport const FormikConsumer = FormikContext.Consumer;\n\nexport function useFormikContext<Values>() {\n const formik = React.useContext<FormikContextType<Values>>(FormikContext);\n\n invariant(\n !!formik,\n `Formik context is undefined, please verify you are calling useFormikContext() as child of a <Formik> component.`\n );\n\n return formik;\n}\n","import clone from 'lodash/clone';\nimport toPath from 'lodash/toPath';\nimport * as React from 'react';\n\n// Assertions\n\n/** @private is the value an empty array? */\nexport const isEmptyArray = (value?: any) =>\n Array.isArray(value) && value.length === 0;\n\n/** @private is the given object a Function? */\nexport const isFunction = (obj: any): obj is Function =>\n typeof obj === 'function';\n\n/** @private is the given object an Object? */\nexport const isObject = (obj: any): obj is Object =>\n obj !== null && typeof obj === 'object';\n\n/** @private is the given object an integer? */\nexport const isInteger = (obj: any): boolean =>\n String(Math.floor(Number(obj))) === obj;\n\n/** @private is the given object a string? */\nexport const isString = (obj: any): obj is string =>\n Object.prototype.toString.call(obj) === '[object String]';\n\n/** @private is the given object a NaN? */\n// eslint-disable-next-line no-self-compare\nexport const isNaN = (obj: any): boolean => obj !== obj;\n\n/** @private Does a React component have exactly 0 children? */\nexport const isEmptyChildren = (children: any): boolean =>\n React.Children.count(children) === 0;\n\n/** @private is the given object/value a promise? */\nexport const isPromise = (value: any): value is PromiseLike<any> =>\n isObject(value) && isFunction(value.then);\n\n/** @private is the given object/value a type of synthetic event? */\nexport const isInputEvent = (value: any): value is React.SyntheticEvent<any> =>\n value && isObject(value) && isObject(value.target);\n\n/**\n * Same as document.activeElement but wraps in a try-catch block. In IE it is\n * not safe to call document.activeElement if there is nothing focused.\n *\n * The activeElement will be null only if the document or document body is not\n * yet defined.\n *\n * @param {?Document} doc Defaults to current document.\n * @return {Element | null}\n * @see https://github.com/facebook/fbjs/blob/master/packages/fbjs/src/core/dom/getActiveElement.js\n */\nexport function getActiveElement(doc?: Document): Element | null {\n doc = doc || (typeof document !== 'undefined' ? document : undefined);\n if (typeof doc === 'undefined') {\n return null;\n }\n try {\n return doc.activeElement || doc.body;\n } catch (e) {\n return doc.body;\n }\n}\n\n/**\n * Deeply get a value from an object via its path.\n */\nexport function getIn(\n obj: any,\n key: string | string[],\n def?: any,\n p: number = 0\n) {\n const path = toPath(key);\n while (obj && p < path.length) {\n obj = obj[path[p++]];\n }\n\n // check if path is not in the end\n if (p !== path.length && !obj) {\n return def;\n }\n\n return obj === undefined ? def : obj;\n}\n\n/**\n * Deeply set a value from in object via it's path. If the value at `path`\n * has changed, return a shallow copy of obj with `value` set at `path`.\n * If `value` has not changed, return the original `obj`.\n *\n * Existing objects / arrays along `path` are also shallow copied. Sibling\n * objects along path retain the same internal js reference. Since new\n * objects / arrays are only created along `path`, we can test if anything\n * changed in a nested structure by comparing the object's reference in\n * the old and new object, similar to how russian doll cache invalidation\n * works.\n *\n * In earlier versions of this function, which used cloneDeep, there were\n * issues whereby settings a nested value would mutate the parent\n * instead of creating a new object. `clone` avoids that bug making a\n * shallow copy of the objects along the update path\n * so no object is mutated in place.\n *\n * Before changing this function, please read through the following\n * discussions.\n *\n * @see https://github.com/developit/linkstate\n * @see https://github.com/jaredpalmer/formik/pull/123\n */\nexport function setIn(obj: any, path: string, value: any): any {\n let res: any = clone(obj); // this keeps inheritance when obj is a class\n let resVal: any = res;\n let i = 0;\n let pathArrLine truncated
+11
View File
@@ -0,0 +1,11 @@
export * from './Formik';
export * from './Field';
export * from './Form';
export * from './withFormik';
export * from './FieldArray';
export * from './utils';
export * from './types';
export * from './connect';
export * from './ErrorMessage';
export * from './FormikContext';
export * from './FastField';
+8
View File
@@ -0,0 +1,8 @@
'use strict'
if (process.env.NODE_ENV === 'production') {
module.exports = require('./formik.cjs.production.min.js')
} else {
module.exports = require('./formik.cjs.development.js')
}
+249
View File
@@ -0,0 +1,249 @@
import * as React from 'react';
import { FieldConfig } from './Field';
/**
* Values of fields in the form
*/
export interface FormikValues {
[field: string]: any;
}
/**
* An object containing error messages whose keys correspond to FormikValues.
* Should always be an object of strings, but any is allowed to support i18n libraries.
*/
export type FormikErrors<Values> = {
[K in keyof Values]?: Values[K] extends any[] ? Values[K][number] extends object ? FormikErrors<Values[K][number]>[] | string | string[] : string | string[] : Values[K] extends object ? FormikErrors<Values[K]> : string;
};
/**
* An object containing touched state of the form whose keys correspond to FormikValues.
*/
export type FormikTouched<Values> = {
[K in keyof Values]?: Values[K] extends any[] ? Values[K][number] extends object ? FormikTouched<Values[K][number]>[] : boolean : Values[K] extends object ? FormikTouched<Values[K]> : boolean;
};
/**
* Formik state tree
*/
export interface FormikState<Values> {
/** Form values */
values: Values;
/** map of field names to specific error for that field */
errors: FormikErrors<Values>;
/** map of field names to whether the field has been touched */
touched: FormikTouched<Values>;
/** whether the form is currently submitting */
isSubmitting: boolean;
/** whether the form is currently validating (prior to submission) */
isValidating: boolean;
/** Top level status state, in case you need it */
status?: any;
/** Number of times user tried to submit the form */
submitCount: number;
}
/**
* Formik computed properties. These are read-only.
*/
export interface FormikComputedProps<Values> {
/** True if any input has been touched. False otherwise. */
readonly dirty: boolean;
/** True if state.errors is empty */
readonly isValid: boolean;
/** The initial values of the form */
readonly initialValues: Values;
/** The initial errors of the form */
readonly initialErrors: FormikErrors<Values>;
/** The initial visited fields of the form */
readonly initialTouched: FormikTouched<Values>;
/** The initial status of the form */
readonly initialStatus?: any;
}
/**
* Formik state helpers
*/
export interface FormikHelpers<Values> {
/** Manually set top level status. */
setStatus: (status?: any) => void;
/** Manually set errors object */
setErrors: (errors: FormikErrors<Values>) => void;
/** Manually set isSubmitting */
setSubmitting: (isSubmitting: boolean) => void;
/** Manually set touched object */
setTouched: (touched: FormikTouched<Values>, shouldValidate?: boolean) => Promise<void | FormikErrors<Values>>;
/** Manually set values object */
setValues: (values: React.SetStateAction<Values>, shouldValidate?: boolean) => Promise<void | FormikErrors<Values>>;
/** Set value of form field directly */
setFieldValue: (field: string, value: any, shouldValidate?: boolean) => Promise<void | FormikErrors<Values>>;
/** Set error message of a form field directly */
setFieldError: (field: string, message: string | undefined) => void;
/** Set whether field has been touched directly */
setFieldTouched: (field: string, isTouched?: boolean, shouldValidate?: boolean) => Promise<void | FormikErrors<Values>>;
/** Validate form values */
validateForm: (values?: any) => Promise<FormikErrors<Values>>;
/** Validate field value */
validateField: (field: string) => Promise<void> | Promise<string | undefined>;
/** Reset form */
resetForm: (nextState?: Partial<FormikState<Values>>) => void;
/** Submit the form imperatively */
submitForm: () => Promise<void>;
/** Set Formik state, careful! */
setFormikState: (f: FormikState<Values> | ((prevState: FormikState<Values>) => FormikState<Values>), cb?: () => void) => void;
}
/**
* Formik form event handlers
*/
export interface FormikHandlers {
/** Form submit handler */
handleSubmit: (e?: React.FormEvent<HTMLFormElement>) => void;
/** Reset form event handler */
handleReset: (e?: React.SyntheticEvent<any>) => void;
handleBlur: {
/** Classic React blur handler, keyed by input name */
(e: React.FocusEvent<any>): void;
/** Preact-like linkState. Will return a handleBlur function. */
<T = string | any>(fieldOrEvent: T): T extends string ? (e: any) => void : void;
};
handleChange: {
/** Classic React change handler, keyed by input name */
(e: React.ChangeEvent<any>): void;
/** Preact-like linkState. Will return a handleChange function. */
<T = string | React.ChangeEvent<any>>(field: T): T extends React.ChangeEvent<any> ? void : (e: string | React.ChangeEvent<any>) => void;
};
getFieldProps: <Value = any>(props: string | FieldConfig<Value>) => FieldInputProps<Value>;
getFieldMeta: <Value>(name: string) => FieldMetaProps<Value>;
getFieldHelpers: <Value = any>(name: string) => FieldHelperProps<Value>;
}
/**
* Base formik configuration/props shared between the HoC and Component.
*/
export interface FormikSharedConfig<Props = {}> {
/** Tells Formik to validate the form on each input's onChange event */
validateOnChange?: boolean;
/** Tells Formik to validate the form on each input's onBlur event */
validateOnBlur?: boolean;
/** Tells Formik to validate upon mount */
validateOnMount?: boolean;
/** Tell Formik if initial form values are valid or not on first render */
isInitialValid?: boolean | ((props: Props) => boolean);
/** Should Formik reset the form when new initialValues change */
enableReinitialize?: boolean;
}
/**
* <Formik /> props
*/
export interface FormikConfig<Values> extends FormikSharedConfig {
/**
* Form component to render
*/
component?: React.ComponentType<FormikProps<Values>>;
/**
* Render prop (works like React router's <Route render={props =>} />)
* @deprecated
*/
render?: (props: FormikProps<Values>) => React.ReactNode;
/**
* React children or child render callback
*/
children?: ((props: FormikProps<Values>) => React.ReactNode) | React.ReactNode;
/**
* Initial values of the form
*/
initialValues: Values;
/**
* Initial status
*/
initialStatus?: any;
/** Initial object map of field names to specific error for that field */
initialErrors?: FormikErrors<Values>;
/** Initial object map of field names to whether the field has been touched */
initialTouched?: FormikTouched<Values>;
/**
* Reset handler
*/
onReset?: (values: Values, formikHelpers: FormikHelpers<Values>) => void;
/**
* Submission handler
*/
onSubmit: (values: Values, formikHelpers: FormikHelpers<Values>) => void | Promise<any>;
/**
* A Yup Schema or a function that returns a Yup schema
*/
validationSchema?: any | (() => any);
/**
* Validation function. Must return an error object or promise that
* throws an error object where that object keys map to corresponding value.
*/
validate?: (values: Values) => void | object | Promise<FormikErrors<Values>>;
/** Inner ref */
innerRef?: React.Ref<FormikProps<Values>>;
}
/**
* State, handlers, and helpers made available to form component or render prop
* of <Formik/>.
*/
export type FormikProps<Values> = FormikSharedConfig & FormikState<Values> & FormikHelpers<Values> & FormikHandlers & FormikComputedProps<Values> & FormikRegistration & {
submitForm: () => Promise<any>;
};
/** Internal Formik registration methods that get passed down as props */
export interface FormikRegistration {
registerField: (name: string, fns: {
validate?: FieldValidator;
}) => void;
unregisterField: (name: string) => void;
}
/**
* State, handlers, and helpers made available to Formik's primitive components through context.
*/
export type FormikContextType<Values> = FormikProps<Values> & Pick<FormikConfig<Values>, 'validate' | 'validationSchema'>;
export interface SharedRenderProps<T> {
/**
* Field component to render. Can either be a string like 'select' or a component.
*/
component?: keyof JSX.IntrinsicElements | React.ComponentType<T | void>;
/**
* Render prop (works like React router's <Route render={props =>} />)
*/
render?: (props: T) => React.ReactNode;
/**
* Children render function <Field name>{props => ...}</Field>)
*/
children?: (props: T) => React.ReactNode;
}
export type GenericFieldHTMLAttributes = JSX.IntrinsicElements['input'] | JSX.IntrinsicElements['select'] | JSX.IntrinsicElements['textarea'];
/** Field metadata */
export interface FieldMetaProps<Value> {
/** Value of the field */
value: Value;
/** Error message of the field */
error?: string;
/** Has the field been visited? */
touched: boolean;
/** Initial value of the field */
initialValue?: Value;
/** Initial touched state of the field */
initialTouched: boolean;
/** Initial error message of the field */
initialError?: string;
}
/** Imperative handles to change a field's value, error and touched */
export interface FieldHelperProps<Value> {
/** Set the field's value */
setValue: (value: Value, shouldValidate?: boolean) => Promise<void | FormikErrors<Value>>;
/** Set the field's touched value */
setTouched: (value: boolean, shouldValidate?: boolean) => Promise<void | FormikErrors<Value>>;
/** Set the field's error value */
setError: (value: string | undefined) => void;
}
/** Field input value, name, and event handlers */
export interface FieldInputProps<Value> {
/** Value of the field */
value: Value;
/** Name of the field */
name: string;
/** Multiple select? */
multiple?: boolean;
/** Is the field checked? */
checked?: boolean;
/** Change event handler */
onChange: FormikHandlers['handleChange'];
/** Blur event handler */
onBlur: FormikHandlers['handleBlur'];
}
export type FieldValidator = (value: any) => string | void | Promise<string | void>;
+68
View File
@@ -0,0 +1,68 @@
import * as React from 'react';
/** @private is the value an empty array? */
export declare const isEmptyArray: (value?: any) => boolean;
/** @private is the given object a Function? */
export declare const isFunction: (obj: any) => obj is Function;
/** @private is the given object an Object? */
export declare const isObject: (obj: any) => obj is Object;
/** @private is the given object an integer? */
export declare const isInteger: (obj: any) => boolean;
/** @private is the given object a string? */
export declare const isString: (obj: any) => obj is string;
/** @private is the given object a NaN? */
export declare const isNaN: (obj: any) => boolean;
/** @private Does a React component have exactly 0 children? */
export declare const isEmptyChildren: (children: any) => boolean;
/** @private is the given object/value a promise? */
export declare const isPromise: (value: any) => value is PromiseLike<any>;
/** @private is the given object/value a type of synthetic event? */
export declare const isInputEvent: (value: any) => value is React.SyntheticEvent<any, Event>;
/**
* Same as document.activeElement but wraps in a try-catch block. In IE it is
* not safe to call document.activeElement if there is nothing focused.
*
* The activeElement will be null only if the document or document body is not
* yet defined.
*
* @param {?Document} doc Defaults to current document.
* @return {Element | null}
* @see https://github.com/facebook/fbjs/blob/master/packages/fbjs/src/core/dom/getActiveElement.js
*/
export declare function getActiveElement(doc?: Document): Element | null;
/**
* Deeply get a value from an object via its path.
*/
export declare function getIn(obj: any, key: string | string[], def?: any, p?: number): any;
/**
* Deeply set a value from in object via it's path. If the value at `path`
* has changed, return a shallow copy of obj with `value` set at `path`.
* If `value` has not changed, return the original `obj`.
*
* Existing objects / arrays along `path` are also shallow copied. Sibling
* objects along path retain the same internal js reference. Since new
* objects / arrays are only created along `path`, we can test if anything
* changed in a nested structure by comparing the object's reference in
* the old and new object, similar to how russian doll cache invalidation
* works.
*
* In earlier versions of this function, which used cloneDeep, there were
* issues whereby settings a nested value would mutate the parent
* instead of creating a new object. `clone` avoids that bug making a
* shallow copy of the objects along the update path
* so no object is mutated in place.
*
* Before changing this function, please read through the following
* discussions.
*
* @see https://github.com/developit/linkstate
* @see https://github.com/jaredpalmer/formik/pull/123
*/
export declare function setIn(obj: any, path: string, value: any): any;
/**
* Recursively a set the same value for all keys and arrays nested object, cloning
* @param object
* @param value
* @param visited
* @param response
*/
export declare function setNestedObjectValues<T>(object: any, value: any, visited?: any, response?: any): T;
+68
View File
@@ -0,0 +1,68 @@
import * as React from 'react';
import { FormikHelpers, FormikProps, FormikSharedConfig, FormikValues, FormikTouched, FormikErrors } from './types';
/**
* State, handlers, and helpers injected as props into the wrapped form component.
* Used with withFormik()
*
* @deprecated Use `OuterProps & FormikProps<Values>` instead.
*/
export type InjectedFormikProps<Props, Values> = Props & FormikProps<Values>;
/**
* Formik helpers + { props }
*/
export type FormikBag<P, V> = {
props: P;
} & FormikHelpers<V>;
/**
* withFormik() configuration options. Backwards compatible.
*/
export interface WithFormikConfig<Props, Values extends FormikValues = FormikValues, DeprecatedPayload = Values> extends FormikSharedConfig<Props> {
/**
* Set the display name of the component. Useful for React DevTools.
*/
displayName?: string;
/**
* Submission handler
*/
handleSubmit: (values: Values, formikBag: FormikBag<Props, Values>) => void;
/**
* Map props to the form values
*/
mapPropsToValues?: (props: Props) => Values;
/**
* Map props to the form status
*/
mapPropsToStatus?: (props: Props) => any;
/**
* Map props to the form touched state
*/
mapPropsToTouched?: (props: Props) => FormikTouched<Values>;
/**
* Map props to the form errors state
*/
mapPropsToErrors?: (props: Props) => FormikErrors<Values>;
/**
* @deprecated in 0.9.0 (but needed to break TS types)
*/
mapValuesToPayload?: (values: Values) => DeprecatedPayload;
/**
* A Yup Schema or a function that returns a Yup schema
*/
validationSchema?: any | ((props: Props) => any);
/**
* Validation function. Must return an error object or promise that
* throws an error object where that object keys map to corresponding value.
*/
validate?: (values: Values, props: Props) => void | object | Promise<any>;
}
export type CompositeComponent<P> = React.ComponentClass<P> | React.FunctionComponent<P>;
export interface ComponentDecorator<TOwnProps, TMergedProps> {
(component: CompositeComponent<TMergedProps>): React.ComponentType<TOwnProps>;
}
export interface InferableComponentDecorator<TOwnProps> {
<T extends CompositeComponent<TOwnProps>>(component: T): T;
}
/**
* A public higher-order component to access the imperative API
*/
export declare function withFormik<OuterProps extends object, Values extends FormikValues, Payload = Values>({ mapPropsToValues, ...config }: WithFormikConfig<OuterProps, Values, Payload>): ComponentDecorator<OuterProps, OuterProps & FormikProps<Values>>;