UNPKG

23.4 kBJavaScriptView Raw
1"use strict";function e(e){return e&&"object"==typeof e&&"default"in e?e.default:e}Object.defineProperty(exports,"__esModule",{value:!0});var r=require("react"),t=e(require("react-fast-compare")),n=e(require("deepmerge")),i=e(require("lodash/isPlainObject")),a=e(require("lodash/clone")),o=e(require("lodash/toPath")),u=e(require("tiny-warning")),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=function(e){return Array.isArray(e)&&0===e.length},h=function(e){return"function"==typeof e},m=function(e){return null!==e&&"object"==typeof e},y=function(e){return String(Math.floor(Number(e)))===e},E=function(e){return"[object String]"===Object.prototype.toString.call(e)},S=function(e){return 0===r.Children.count(e)},T=function(e){return m(e)&&h(e.then)};function g(e,r,t,n){void 0===n&&(n=0);for(var i=o(r);e&&n<i.length;)e=e[i[n++]];return void 0===e?t:e}function b(e,r,t){for(var n=a(e),i=n,u=0,s=o(r);u<s.length-1;u++){var l=s[u],c=g(e,s.slice(0,u+1));if(c&&(m(c)||Array.isArray(c)))i=i[l]=a(c);else{var p=s[u+1];i=i[l]=y(p)&&Number(p)>=0?[]:{}}}return(0===u?e:i)[s[u]]===t?e:(void 0===t?delete i[s[u]]:i[s[u]]=t,0===u&&void 0===t&&delete n[s[u]],n)}function F(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];m(u)?t.get(u)||(t.set(u,!0),n[o]=Array.isArray(u)?[]:{},F(u,r,t,n[o])):n[o]=r}return n}var k=r.createContext(void 0);k.displayName="FormikContext";var O=k.Provider,_=k.Consumer;function R(){var e=r.useContext(k);return e||u(!1),e}function A(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 t(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:b(e.values,r.payload.field,r.payload.value)});case"SET_FIELD_TOUCHED":return c({},e,{touched:b(e.touched,r.payload.field,r.payload.value)});case"SET_FIELD_ERROR":return c({},e,{errors:b(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:F(e.values,!0),isSubmitting:!0,submitCount:e.submitCount+1});case"SUBMIT_FAILURE":case"SUBMIT_SUCCESS":return c({},e,{isSubmitting:!1});default:return e}}var C={},I={};function P(e){var i=e.validateOnChange,a=void 0===i||i,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,y=e.onSubmit,S=d(e,["validateOnChange","validateOnBlur","validateOnMount","isInitialValid","enableReinitialize","onSubmit"]),F=c({validateOnChange:a,validateOnBlur:u,validateOnMount:l,onSubmit:y},S),k=r.useRef(F.initialValues),O=r.useRef(F.initialErrors||C),_=r.useRef(F.initialTouched||I),R=r.useRef(F.initialStatus),P=r.useRef(!1),x=r.useRef({});r.useEffect((function(){return P.current=!0,function(){P.current=!1}}),[]);var D=r.useReducer(A,{values:F.initialValues,errors:F.initialErrors||C,touched:F.initialTouched||I,status:F.initialStatus,isSubmitting:!1,isValidating:!1,submitCount:0}),w=D[0],j=D[1],N=r.useCallback((function(e,r){return new Promise((function(t,n){var i=F.validate(e,r);null==i?t(C):T(i)?i.then((function(e){t(e||C)}),(function(e){n(e)})):t(i)}))}),[F.validate]),B=r.useCallback((function(e,r){var t=F.validationSchema,n=h(t)?t(r):t,i=r&&n.validateAt?n.validateAt(r,e):V(e,n);return new Promise((function(e,r){i.then((function(){e(C)}),(function(t){"ValidationError"===t.name?e(U(t)):r(t)}))}))}),[F.validationSchema]),q=r.useCallback((function(e,r){return new Promise((function(t){return t(x.current[e].validate(r))}))}),[]),G=r.useCallback((function(e){var r=Object.keys(x.current).filter((function(e){return h(x.current[e].validate)})),t=r.length>0?r.map((function(r){return q(r,g(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=b(e,r[n],t)),e)}),{})}))}),[q]),H=r.useCallback((function(e){return Promise.all([G(e),F.validationSchema?B(e):{},F.validate?N(e):{}]).then((function(e){return n.all([e[0],e[1],e[2]],{arrayMerge:M})}))}),[F.validate,F.validationSchema,G,N,B]),W=L((function(e){return void 0===e&&(e=w.values),j({type:"SET_ISVALIDATING",payload:!0}),H(e).then((function(e){return P.current&&(j({type:"SET_ISVALIDATING",payload:!1}),j({type:"SET_ERRORS",payload:e})),e}))}));r.useEffect((function(){l&&!0===P.current&&t(k.current,F.initialValues)&&W(k.current)}),[l,W]);var K=r.useCallback((function(e){var r=e&&e.values?e.values:k.current,t=e&&e.errors?e.errors:O.current?O.current:F.initialErrors||{},n=e&&e.touched?e.touched:_.current?_.current:F.initialTouched||{},i=e&&e.status?e.status:R.current?R.current:F.initialStatus;k.current=r,O.current=t,_.current=n,R.current=i;var a=function(){j({type:"RESET_FORM",payload:{isSubmitting:!!e&&!!e.isSubmitting,errors:t,touched:n,status:i,values:r,isValidating:!!e&&!!e.isValidating,submitCount:e&&e.submitCount&&"number"==typeof e.submitCount?e.submitCount:0}})};if(F.onReset){var o=F.onReset(w.values,pe);T(o)?o.then(a):a()}else a()}),[F.initialErrors,F.initialStatus,F.initialTouched]);r.useEffect((function(){!0!==P.current||t(k.current,F.initialValues)||(v&&(k.current=F.initialValues,K()),l&&W(k.current))}),[v,F.initialValues,K,l,W]),r.useEffect((function(){v&&!0===P.current&&!t(O.current,F.initialErrors)&&(O.current=F.initialErrors||C,j({type:"SET_ERRORS",payload:F.initialErrors||C}))}),[v,F.initialErrors]),r.useEffect((function(){v&&!0===P.current&&!t(_.current,F.initialTouched)&&(_.current=F.initialTouched||I,j({type:"SET_TOUCHED",payload:F.initialTouched||I}))}),[v,F.initialTouched]),r.useEffect((function(){v&&!0===P.current&&!t(R.current,F.initialStatus)&&(R.current=F.initialStatus,j({type:"SET_STATUS",payload:F.initialStatus}))}),[v,F.initialStatus,F.initialTouched]);var Y=L((function(e){if(x.current[e]&&h(x.current[e].validate)){var r=g(w.values,e),t=x.current[e].validate(r);return T(t)?(j({type:"SET_ISVALIDATING",payload:!0}),t.then((function(e){return e})).then((function(r){j({type:"SET_FIELD_ERROR",payload:{field:e,value:r}}),j({type:"SET_ISVALIDATING",payload:!1})}))):(j({type:"SET_FIELD_ERROR",payload:{field:e,value:t}}),Promise.resolve(t))}return F.validationSchema?(j({type:"SET_ISVALIDATING",payload:!0}),B(w.values,e).then((function(e){return e})).then((function(r){j({type:"SET_FIELD_ERROR",payload:{field:e,value:r[e]}}),j({type:"SET_ISVALIDATING",payload:!1})}))):Promise.resolve()})),z=r.useCallback((function(e,r){x.current[e]={validate:r.validate}}),[]),J=r.useCallback((function(e){delete x.current[e]}),[]),Q=L((function(e,r){return j({type:"SET_TOUCHED",payload:e}),(void 0===r?u:r)?W(w.values):Promise.resolve()})),X=r.useCallback((function(e){j({type:"SET_ERRORS",payload:e})}),[]),Z=L((function(e,r){var t=h(e)?e(w.values):e;return j({type:"SET_VALUES",payload:t}),(void 0===r?a:r)?W(t):Promise.resolve()})),$=r.useCallback((function(e,r){j({type:"SET_FIELD_ERROR",payload:{field:e,value:r}})}),[]),ee=L((function(e,r,t){return j({type:"SET_FIELD_VALUE",payload:{field:e,value:r}}),(void 0===t?a:t)?W(b(w.values,e,r)):Promise.resolve()})),re=r.useCallback((function(e,r){var t,n=r,i=e;if(!E(e)){e.persist&&e.persist();var a=e.target?e.target:e.currentTarget,o=a.type,u=a.value,s=a.checked,l=a.options,c=a.multiple;n=r||a.name||a.id,i=/number|range/.test(o)?(t=parseFloat(u),isNaN(t)?"":t):/checkbox/.test(o)?function(e,r,t){if("boolean"==typeof e)return Boolean(r);var n=[],i=!1,a=-1;if(Array.isArray(e))n=e,i=(a=e.indexOf(t))>=0;else if(!t||"true"==t||"false"==t)return Boolean(r);return r&&t&&!i?n.concat(t):i?n.slice(0,a).concat(n.slice(a+1)):n}(g(w.values,n),s,u):l&&c?function(e){return Array.from(e).filter((function(e){return e.selected})).map((function(e){return e.value}))}(l):u}n&&ee(n,i)}),[ee,w.values]),te=L((function(e){if(E(e))return function(r){return re(r,e)};re(e)})),ne=L((function(e,r,t){return void 0===r&&(r=!0),j({type:"SET_FIELD_TOUCHED",payload:{field:e,value:r}}),(void 0===t?u:t)?W(w.values):Promise.resolve()})),ie=r.useCallback((function(e,r){e.persist&&e.persist();var t=e.target;ne(r||t.name||t.id,!0)}),[ne]),ae=L((function(e){if(E(e))return function(r){return ie(r,e)};ie(e)})),oe=r.useCallback((function(e){h(e)?j({type:"SET_FORMIK_STATE",payload:e}):j({type:"SET_FORMIK_STATE",payload:function(){return e}})}),[]),ue=r.useCallback((function(e){j({type:"SET_STATUS",payload:e})}),[]),se=r.useCallback((function(e){j({type:"SET_ISSUBMITTING",payload:e})}),[]),le=L((function(){return j({type:"SUBMIT_ATTEMPT"}),W().then((function(e){var r=e instanceof Error;if(!r&&0===Object.keys(e).length){var t;try{if(void 0===(t=de()))return}catch(e){throw e}return Promise.resolve(t).then((function(e){return P.current&&j({type:"SUBMIT_SUCCESS"}),e})).catch((function(e){if(P.current)throw j({type:"SUBMIT_FAILURE"}),e}))}if(P.current&&(j({type:"SUBMIT_FAILURE"}),r))throw e}))})),ce=L((function(e){e&&e.preventDefault&&h(e.preventDefault)&&e.preventDefault(),e&&e.stopPropagation&&h(e.stopPropagation)&&e.stopPropagation(),le().catch((function(e){console.warn("Warning: An unhandled error was caught from submitForm()",e)}))})),pe={resetForm:K,validateForm:W,validateField:Y,setErrors:X,setFieldError:$,setFieldTouched:ne,setFieldValue:ee,setStatus:ue,setSubmitting:se,setTouched:Q,setValues:Z,setFormikState:oe,submitForm:le},de=L((function(){return y(w.values,pe)})),fe=L((function(e){e&&e.preventDefault&&h(e.preventDefault)&&e.preventDefault(),e&&e.stopPropagation&&h(e.stopPropagation)&&e.stopPropagation(),K()})),ve=r.useCallback((function(e){return{value:g(w.values,e),error:g(w.errors,e),touched:!!g(w.touched,e),initialValue:g(k.current,e),initialTouched:!!g(_.current,e),initialError:g(O.current,e)}}),[w.errors,w.touched,w.values]),he=r.useCallback((function(e){return{setValue:function(r,t){return ee(e,r,t)},setTouched:function(r,t){return ne(e,r,t)},setError:function(r){return $(e,r)}}}),[ee,ne,$]),me=r.useCallback((function(e){var r=m(e),t=r?e.name:e,n=g(w.values,t),i={name:t,value:n,onChange:te,onBlur:ae};if(r){var a=e.type,o=e.value,u=e.as,s=e.multiple;"checkbox"===a?void 0===o?i.checked=!!n:(i.checked=!(!Array.isArray(n)||!~n.indexOf(o)),i.value=o):"radio"===a?(i.checked=n===o,i.value=o):"select"===u&&s&&(i.value=i.value||[],i.multiple=!0)}return i}),[ae,te,w.values]),ye=r.useMemo((function(){return!t(k.current,w.values)}),[k.current,w.values]),Ee=r.useMemo((function(){return void 0!==p?ye?w.errors&&0===Object.keys(w.errors).length:!1!==p&&h(p)?p(F):p:w.errors&&0===Object.keys(w.errors).length}),[p,ye,w.errors,F]);return c({},w,{initialValues:k.current,initialErrors:O.current,initialTouched:_.current,initialStatus:R.current,handleBlur:ae,handleChange:te,handleReset:fe,handleSubmit:ce,resetForm:K,setErrors:X,setFormikState:oe,setFieldTouched:ne,setFieldValue:ee,setFieldError:$,setStatus:ue,setSubmitting:se,setTouched:Q,setValues:Z,submitForm:le,validateForm:W,validateField:Y,isValid:Ee,dirty:ye,unregisterField:J,registerField:z,getFieldProps:me,getFieldMeta:ve,getFieldHelpers:he,validateOnBlur:u,validateOnChange:a,validateOnMount:l})}function x(e){var t=P(e),n=e.component,i=e.children,a=e.render;return r.useImperativeHandle(e.innerRef,(function(){return t})),r.createElement(O,{value:t},n?r.createElement(n,t):a?a(t):i?h(i)?i(t):S(i)?null:r.Children.only(i):null)}function U(e){var r={};if(e.inner){if(0===e.inner.length)return b(r,e.path,e.message);var t=e.inner,n=Array.isArray(t),i=0;for(t=n?t:t[Symbol.iterator]();;){var a;if(n){if(i>=t.length)break;a=t[i++]}else{if((i=t.next()).done)break;a=i.value}var o=a;g(r,o.path)||(r=b(r,o.path,o.message))}}return r}function V(e,r,t,n){void 0===t&&(t=!1),void 0===n&&(n={});var i=D(e);return r[t?"validateSync":"validate"](i,{abortEarly:!1,context:n})}function D(e){var r=Array.isArray(e)?[]:{};for(var t in e)if(Object.prototype.hasOwnProperty.call(e,t)){var n=String(t);r[n]=!0===Array.isArray(e[n])?e[n].map((function(e){return!0===Array.isArray(e)||i(e)?D(e):""!==e?e:void 0})):i(e[n])?D(e[n]):""!==e[n]?e[n]:void 0}return r}function M(e,r,t){var i=e.slice();return r.forEach((function(r,a){if(void 0===i[a]){var o=!1!==t.clone&&t.isMergeableObject(r);i[a]=o?n(Array.isArray(r)?[]:{},r,t):r}else t.isMergeableObject(r)?i[a]=n(e[a],r,t):-1===e.indexOf(r)&&i.push(r)})),i}var w="undefined"!=typeof window&&void 0!==window.document&&void 0!==window.document.createElement?r.useLayoutEffect:r.useEffect;function L(e){var t=r.useRef(e);return w((function(){t.current=e})),r.useCallback((function(){for(var e=arguments.length,r=new Array(e),n=0;n<e;n++)r[n]=arguments[n];return t.current.apply(void 0,r)}),[])}var j=r.forwardRef((function(e,t){var n=e.action,i=d(e,["action"]),a=null!=n?n:"#",o=R();return r.createElement("form",Object.assign({onSubmit:o.handleSubmit,ref:t,onReset:o.handleReset,action:a},i))}));function N(e){var t=function(t){return r.createElement(_,null,(function(n){return n||u(!1),r.createElement(e,Object.assign({},t,{formik:n}))}))},n=e.displayName||e.name||e.constructor&&e.constructor.name||"Component";return t.WrappedComponent=e,t.displayName="FormikConnect("+n+")",s(t,e)}j.displayName="Form";var B=function(e,r,t){var n=W(e),i=n[r];return n.splice(r,1),n.splice(t,0,i),n},q=function(e,r,t){var n=W(e),i=n[r];return n[r]=n[t],n[t]=i,n},G=function(e,r,t){var n=W(e);return n.splice(r,0,t),n},H=function(e,r,t){var n=W(e);return n[r]=t,n},W=function(e){if(e){if(Array.isArray(e))return[].concat(e);var r=Object.keys(e).map((function(e){return parseInt(e)})).reduce((function(e,r){return r>e?r:e}),0);return Array.from(c({},e,{length:r+1}))}return[]},K=function(e){function n(r){var t;return(t=e.call(this,r)||this).updateArrayField=function(e,r,n){var i=t.props,a=i.name;(0,i.formik.setFormikState)((function(t){var i="function"==typeof n?n:e,o="function"==typeof r?r:e,u=b(t.values,a,e(g(t.values,a))),s=n?i(g(t.errors,a)):void 0,l=r?o(g(t.touched,a)):void 0;return v(s)&&(s=void 0),v(l)&&(l=void 0),c({},t,{values:u,errors:n?b(t.errors,a,s):t.errors,touched:r?b(t.touched,a,l):t.touched})}))},t.push=function(e){return t.updateArrayField((function(r){return[].concat(W(r),[l(e)])}),!1,!1)},t.handlePush=function(e){return function(){return t.push(e)}},t.swap=function(e,r){return t.updateArrayField((function(t){return q(t,e,r)}),!0,!0)},t.handleSwap=function(e,r){return function(){return t.swap(e,r)}},t.move=function(e,r){return t.updateArrayField((function(t){return B(t,e,r)}),!0,!0)},t.handleMove=function(e,r){return function(){return t.move(e,r)}},t.insert=function(e,r){return t.updateArrayField((function(t){return G(t,e,r)}),(function(r){return G(r,e,null)}),(function(r){return G(r,e,null)}))},t.handleInsert=function(e,r){return function(){return t.insert(e,r)}},t.replace=function(e,r){return t.updateArrayField((function(t){return H(t,e,r)}),!1,!1)},t.handleReplace=function(e,r){return function(){return t.replace(e,r)}},t.unshift=function(e){var r=-1;return t.updateArrayField((function(t){var n=t?[e].concat(t):[e];return r<0&&(r=n.length),n}),(function(e){var t=e?[null].concat(e):[null];return r<0&&(r=t.length),t}),(function(e){var t=e?[null].concat(e):[null];return r<0&&(r=t.length),t})),r},t.handleUnshift=function(e){return function(){return t.unshift(e)}},t.handleRemove=function(e){return function(){return t.remove(e)}},t.handlePop=function(){return function(){return t.pop()}},t.remove=t.remove.bind(f(t)),t.pop=t.pop.bind(f(t)),t}p(n,e);var i=n.prototype;return i.componentDidUpdate=function(e){this.props.validateOnChange&&this.props.formik.validateOnChange&&!t(g(e.formik.values,e.name),g(this.props.formik.values,this.props.name))&&this.props.formik.validateForm(this.props.formik.values)},i.remove=function(e){var r;return this.updateArrayField((function(t){var n=t?W(t):[];return r||(r=n[e]),h(n.splice)&&n.splice(e,1),n}),!0,!0),r},i.pop=function(){var e;return this.updateArrayField((function(r){var t=r;return e||(e=t&&t.pop&&t.pop()),t}),!0,!0),e},i.render=function(){var e=this.props,t=e.component,n=e.render,i=e.children,a=e.name,o=c({},{push:this.push,pop:this.pop,swap:this.swap,move:this.move,insert:this.insert,replace:this.replace,unshift:this.unshift,remove:this.remove,handlePush:this.handlePush,handlePop:this.handlePop,handleSwap:this.handleSwap,handleMove:this.handleMove,handleInsert:this.handleInsert,handleReplace:this.handleReplace,handleUnshift:this.handleUnshift,handleRemove:this.handleRemove},{form:d(e.formik,["validate","validationSchema"]),name:a});return t?r.createElement(t,o):n?n(o):i?"function"==typeof i?i(o):S(i)?null:r.Children.only(i):null},n}(r.Component);K.defaultProps={validateOnChange:!0};var Y=N(K),z=N(function(e){function t(){return e.apply(this,arguments)||this}p(t,e);var n=t.prototype;return n.shouldComponentUpdate=function(e){return g(this.props.formik.errors,this.props.name)!==g(e.formik.errors,this.props.name)||g(this.props.formik.touched,this.props.name)!==g(e.formik.touched,this.props.name)||Object.keys(this.props).length!==Object.keys(e).length},n.render=function(){var e=this.props,t=e.component,n=e.formik,i=e.render,a=e.children,o=e.name,u=d(e,["component","formik","render","children","name"]),s=g(n.touched,o),l=g(n.errors,o);return s&&l?i?h(i)?i(l):null:a?h(a)?a(l):null:t?r.createElement(t,u,l):l:null},t}(r.Component)),J=N(function(e){function t(r){var t;t=e.call(this,r)||this;var n=r.render,i=r.children,a=r.component,o=r.as;return n&&u(!1),a&&n&&u(!1),o&&i&&h(i)&&u(!1),a&&i&&h(i)&&u(!1),n&&i&&!S(i)&&u(!1),t}p(t,e);var n=t.prototype;return n.shouldComponentUpdate=function(e){return this.props.shouldUpdate?this.props.shouldUpdate(e,this.props):e.name!==this.props.name||g(e.formik.values,this.props.name)!==g(this.props.formik.values,this.props.name)||g(e.formik.errors,this.props.name)!==g(this.props.formik.errors,this.props.name)||g(e.formik.touched,this.props.name)!==g(this.props.formik.touched,this.props.name)||Object.keys(this.props).length!==Object.keys(e).length||e.formik.isSubmitting!==this.props.formik.isSubmitting},n.componentDidMount=function(){this.props.formik.registerField(this.props.name,{validate:this.props.validate})},n.componentDidUpdate=function(e){this.props.name!==e.name&&(this.props.formik.unregisterField(e.name),this.props.formik.registerField(this.props.name,{validate:this.props.validate})),this.props.validate!==e.validate&&this.props.formik.registerField(this.props.name,{validate:this.props.validate})},n.componentWillUnmount=function(){this.props.formik.unregisterField(this.props.name)},n.render=function(){var e=this.props,t=e.name,n=e.render,i=e.as,a=e.children,o=e.component,u=e.formik,s=d(e,["validate","name","render","as","children","component","shouldUpdate","formik"]),l=d(u,["validate","validationSchema"]),p=u.getFieldProps(c({name:t},s)),f={field:p,meta:{value:g(u.values,t),error:g(u.errors,t),touched:!!g(u.touched,t),initialValue:g(u.initialValues,t),initialTouched:!!g(u.initialTouched,t),initialError:g(u.initialErrors,t)},form:l};if(n)return n(f);if(h(a))return a(f);if(o){if("string"==typeof o){var v=s.innerRef,m=d(s,["innerRef"]);return r.createElement(o,c({ref:v},p,m),a)}return r.createElement(o,c({field:p,form:u},s),a)}var y=i||"input";if("string"==typeof y){var E=s.innerRef,S=d(s,["innerRef"]);return r.createElement(y,c({ref:E},p,S),a)}return r.createElement(y,c({},p,s),a)},t}(r.Component));exports.ErrorMessage=z,exports.FastField=J,exports.Field=function(e){var t=e.validate,n=e.name,i=e.render,a=e.children,o=e.as,u=e.component,s=d(e,["validate","name","render","children","as","component"]),l=d(R(),["validate","validationSchema"]),p=l.registerField,f=l.unregisterField;r.useEffect((function(){return p(n,{validate:t}),function(){f(n)}}),[p,f,n,t]);var v=l.getFieldProps(c({name:n},s)),m=l.getFieldMeta(n),y={field:v,form:l};if(i)return i(c({},y,{meta:m}));if(h(a))return a(c({},y,{meta:m}));if(u){if("string"==typeof u){var E=s.innerRef,S=d(s,["innerRef"]);return r.createElement(u,c({ref:E},v,S),a)}return r.createElement(u,c({field:v,form:l},s),a)}var T=o||"input";if("string"==typeof T){var g=s.innerRef,b=d(s,["innerRef"]);return r.createElement(T,c({ref:g},v,b),a)}return r.createElement(T,c({},v,s),a)},exports.FieldArray=Y,exports.Form=j,exports.Formik=x,exports.FormikConsumer=_,exports.FormikContext=k,exports.FormikProvider=O,exports.connect=N,exports.getActiveElement=function(e){if(void 0===(e=e||("undefined"!=typeof document?document:void 0)))return null;try{return e.activeElement||e.body}catch(r){return e.body}},exports.getIn=g,exports.insert=G,exports.isEmptyArray=v,exports.isEmptyChildren=S,exports.isFunction=h,exports.isInputEvent=function(e){return e&&m(e)&&m(e.target)},exports.isInteger=y,exports.isNaN=function(e){return e!=e},exports.isObject=m,exports.isPromise=T,exports.isString=E,exports.move=B,exports.prepareDataForValidation=D,exports.replace=H,exports.setIn=b,exports.setNestedObjectValues=F,exports.swap=q,exports.useField=function(e){var t=R(),n=t.getFieldProps,i=t.getFieldMeta,a=t.getFieldHelpers,o=t.registerField,s=t.unregisterField,l=m(e)?e:{name:e},c=l.name,p=l.validate;return r.useEffect((function(){return c&&o(c,{validate:p}),function(){c&&s(c)}}),[o,s,c,p]),c||u(!1),[n(l),i(c),a(c)]},exports.useFormik=P,exports.useFormikContext=R,exports.validateYupSchema=V,exports.withFormik=function(e){var t=e.mapPropsToValues,n=void 0===t?function(e){var r={};for(var t in e)e.hasOwnProperty(t)&&"function"!=typeof e[t]&&(r[t]=e[t]);return r}:t,i=d(e,["mapPropsToValues"]);return function(e){var t=e.displayName||e.name||e.constructor&&e.constructor.name||"Component",a=function(t){function a(){var n;return(n=t.apply(this,arguments)||this).validate=function(e){return i.validate(e,n.props)},n.validationSchema=function(){return h(i.validationSchema)?i.validationSchema(n.props):i.validationSchema},n.handleSubmit=function(e,r){return i.handleSubmit(e,c({},r,{props:n.props}))},n.renderFormComponent=function(t){return r.createElement(e,Object.assign({},n.props,t))},n}return p(a,t),a.prototype.render=function(){var e=d(this.props,["children"]);return r.createElement(x,Object.assign({},e,i,{validate:i.validate&&this.validate,validationSchema:i.validationSchema&&this.validationSchema,initialValues:n(this.props),initialStatus:i.mapPropsToStatus&&i.mapPropsToStatus(this.props),initialErrors:i.mapPropsToErrors&&i.mapPropsToErrors(this.props),initialTouched:i.mapPropsToTouched&&i.mapPropsToTouched(this.props),onSubmit:this.handleSubmit,children:this.renderFormComponent}))},a}(r.Component);return a.displayName="WithFormik("+t+")",s(a,e)}},exports.yupToFormErrors=U;
2//# sourceMappingURL=formik.cjs.production.min.js.map