Comparing version 3.0.0-next.4 to 3.0.0-next.5
# formik | ||
## 3.0.0-next.5 | ||
### Patch Changes | ||
- [`50433fa`](https://github.com/formium/formik/commit/50433fa3cec2cb1ae11176dc713d5f011fcc758d) [#2846](https://github.com/formium/formik/pull/2846) Thanks [@jaredpalmer](https://github.com/jaredpalmer)! - Implement useField field.onBlur to avoid rerendering entire form on blur events | ||
## 3.0.0-next.4 | ||
@@ -4,0 +10,0 @@ |
@@ -1,2 +0,2 @@ | ||
"use strict";function e(e){return e&&"object"==typeof e&&"default"in e?e.default:e}Object.defineProperty(exports,"__esModule",{value:!0});var t=require("react"),r=e(require("react-fast-compare")),n=e(require("deepmerge")),i=e(require("lodash/isPlainObject")),a=e(require("lodash/clone")),u=e(require("lodash/toPath")),o=require("use-context-selector"),l=e(require("tiny-warning")),s=require("scheduler"),c=e(require("hoist-non-react-statics")),d=e(require("lodash/cloneDeep"));function f(){return(f=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e}).apply(this,arguments)}function p(e,t){e.prototype=Object.create(t.prototype),e.prototype.constructor=e,e.__proto__=t}function v(e,t){if(null==e)return{};var r,n,i={},a=Object.keys(e);for(n=0;n<a.length;n++)t.indexOf(r=a[n])>=0||(i[r]=e[r]);return i}function h(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}var m=function(e){return Array.isArray(e)&&0===e.length},y=function(e){return"function"==typeof e},E=function(e){return null!==e&&"object"==typeof e},S=function(e){return String(Math.floor(Number(e)))===e},T=function(e){return"[object String]"===Object.prototype.toString.call(e)},b=function(e){return e!=e},g=function(e){return 0===t.Children.count(e)},F=function(e){return E(e)&&y(e.then)},x=function(e){return e&&E(e)&&E(e.target)},_="undefined"!=typeof window&&window.navigator&&window.navigator.product&&"ReactNative"===window.navigator.product;function O(e,t,r,n){void 0===n&&(n=0);for(var i=u(t);e&&n<i.length;)e=e[i[n++]];return void 0===e?r:e}function R(e,t,r){for(var n=a(e),i=n,o=0,l=u(t);o<l.length-1;o++){var s=l[o],c=O(e,l.slice(0,o+1));if(c&&(E(c)||Array.isArray(c)))i=i[s]=a(c);else{var d=l[o+1];i=i[s]=S(d)&&Number(d)>=0?[]:{}}}return(0===o?e:i)[l[o]]===r?e:(void 0===r?delete i[l[o]]:i[l[o]]=r,0===o&&void 0===r&&delete n[l[o]],n)}function I(e,t,r,n){void 0===r&&(r=new WeakMap),void 0===n&&(n={});for(var i=0,a=Object.keys(e);i<a.length;i++){var u=a[i],o=e[u];E(o)?r.get(o)||(r.set(o,!0),n[u]=Array.isArray(o)?[]:{},I(o,t,r,n[u])):n[u]=t}return n}function C(e){var t=[];if(e)for(var r=0;r<e.length;r++){var n=e[r];n.selected&&t.push(n.value)}return t}function k(e,t,r){if("boolean"==typeof e)return Boolean(t);var n=[],i=!1,a=-1;if(Array.isArray(e))n=e,i=(a=e.indexOf(r))>=0;else if(!r||"true"==r||"false"==r)return Boolean(t);return t&&r&&!i?n.concat(r):i?n.slice(0,a).concat(n.slice(a+1)):n}var A=function(e,t){return e},P=function(e,t){var r=parseFloat(e);return b(r)?"":r},V=function(e,t){return void 0===e?"":e},w=function(e,t){if(!_&&e.nativeEvent&&void 0!==e.nativeEvent.text)return e.nativeEvent.text;if(_&&e.nativeEvent)return e.nativeEvent.text;var r=e.target?e.target:e.currentTarget,n=r.value,i=r.checked,a=r.options,u=r.multiple;return/checkbox/.test(r.type)?k(t,i,n):u?C(a):n},D=o.createContext(void 0),L=D.Provider;function U(){return o.useContext(D)}function M(e){var r=e.children,n=U();return n||l(!1),t.createElement(t.Fragment,null,r(n))}function B(e){return o.useContextSelector(D,e)}function j(e,t){switch(t.type){case"SET_VALUES":return f({},e,{values:t.payload});case"SET_TOUCHED":return f({},e,{touched:t.payload});case"SET_ERRORS":return r(e.errors,t.payload)?e:f({},e,{errors:t.payload});case"SET_LOW_PRIORITY_ERRORS":return r(e.errors,t.payload.errors)||!r(e.values,t.payload.values)?e:f({},e,{errors:t.payload.errors});case"SET_STATUS":return f({},e,{status:t.payload});case"SET_ISSUBMITTING":return f({},e,{isSubmitting:t.payload});case"SET_ISVALIDATING":return f({},e,{isValidating:t.payload});case"SET_FIELD_VALUE":return f({},e,{values:R(e.values,t.payload.field,t.payload.value)});case"SET_FIELD_TOUCHED":return f({},e,{touched:R(e.touched,t.payload.field,t.payload.value)});case"SET_FIELD_ERROR":return f({},e,{errors:R(e.errors,t.payload.field,t.payload.value)});case"RESET_FORM":return f({},e,t.payload);case"SET_FORMIK_STATE":return t.payload(e);case"SUBMIT_ATTEMPT":return f({},e,{touched:I(e.values,!0),isSubmitting:!0,submitCount:e.submitCount+1});case"SUBMIT_FAILURE":case"SUBMIT_SUCCESS":return f({},e,{isSubmitting:!1});default:return e}}var N={},q={};function G(e){var i=e.validateOnChange,a=void 0===i||i,u=e.validateOnBlur,o=void 0===u||u,l=e.validateOnMount,c=void 0!==l&&l,d=e.isInitialValid,p=e.enableReinitialize,h=void 0!==p&&p,m=e.onSubmit,S=v(e,["validateOnChange","validateOnBlur","validateOnMount","isInitialValid","enableReinitialize","onSubmit"]),b=f({validateOnChange:a,validateOnBlur:o,validateOnMount:c,onSubmit:m},S),g=t.useRef(b.initialValues),I=t.useRef(b.initialErrors||N),w=t.useRef(b.initialTouched||q),D=t.useRef(b.initialStatus),L=t.useRef(!1),U=t.useRef({});t.useEffect((function(){return L.current=!0,function(){L.current=!1}}),[]);var M=t.useReducer(j,{values:b.initialValues,errors:b.initialErrors||N,touched:b.initialTouched||q,status:b.initialStatus,isSubmitting:!1,isValidating:!1,submitCount:0}),B=M[0],G=M[1],W=t.useCallback((function(e,t){return new Promise((function(r,n){var i=b.validate(e,t);null==i?r(N):F(i)?i.then((function(e){r(e||N)}),(function(e){n(e)})):r(i)}))}),[b.validate]),K=t.useCallback((function(e,t){var r=b.validationSchema,n=y(r)?r(t):r,i=t&&n.validateAt?n.validateAt(t,e):Y(e,n);return new Promise((function(e,t){i.then((function(){e(N)}),(function(r){"ValidationError"===r.name?e(H(r)):t(r)}))}))}),[b.validationSchema]),J=t.useCallback((function(e,t){return new Promise((function(r){return r(U.current[e].validate(t))}))}),[]),X=t.useCallback((function(e){var t=Object.keys(U.current).filter((function(e){return y(U.current[e].validate)})),r=t.length>0?t.map((function(t){return J(t,O(e,t))})):[Promise.resolve("DO_NOT_DELETE_YOU_WILL_BE_FIRED")];return Promise.all(r).then((function(e){return e.reduce((function(e,r,n){return"DO_NOT_DELETE_YOU_WILL_BE_FIRED"===r?e:(r&&(e=R(e,t[n],r)),e)}),{})}))}),[J]),Z=t.useCallback((function(e){return Promise.all([X(e),b.validationSchema?K(e):{},b.validate?W(e):{}]).then((function(e){return n.all([e[0],e[1],e[2]],{arrayMerge:z})}))}),[b.validate,b.validationSchema,X,W,K]),$=Q((function(e){return void 0===e&&(e=B.values),t=function(){return Z(e).then((function(t){return L.current&&G({type:"SET_LOW_PRIORITY_ERRORS",payload:{values:e,errors:t}}),t})).catch((function(e){}))},s.unstable_runWithPriority(s.unstable_LowPriority,(function(){return s.unstable_scheduleCallback(s.unstable_LowPriority,t)}));var t})),ee=Q((function(e){return void 0===e&&(e=B.values),G({type:"SET_ISVALIDATING",payload:!0}),Z(e).then((function(e){return L.current&&(G({type:"SET_ISVALIDATING",payload:!1}),r(B.errors,e)||G({type:"SET_ERRORS",payload:e})),e}))}));t.useEffect((function(){c&&!0===L.current&&r(g.current,b.initialValues)&&$(g.current)}),[c,$]);var te=t.useCallback((function(e){var t=e&&e.values?e.values:g.current,r=e&&e.errors?e.errors:I.current?I.current:b.initialErrors||{},n=e&&e.touched?e.touched:w.current?w.current:b.initialTouched||{},i=e&&e.status?e.status:D.current?D.current:b.initialStatus;g.current=t,I.current=r,w.current=n,D.current=i;var a=function(){G({type:"RESET_FORM",payload:{isSubmitting:!!e&&!!e.isSubmitting,errors:r,touched:n,status:i,values:t,isValidating:!!e&&!!e.isValidating,submitCount:e&&e.submitCount&&"number"==typeof e.submitCount?e.submitCount:0}})};if(b.onReset){var u=b.onReset(B.values,Te);F(u)?u.then(a):a()}else a()}),[b.initialErrors,b.initialStatus,b.initialTouched]);t.useEffect((function(){!0!==L.current||r(g.current,b.initialValues)||(h&&(g.current=b.initialValues,te()),c&&$(g.current))}),[h,b.initialValues,te,c,$]),t.useEffect((function(){h&&!0===L.current&&!r(I.current,b.initialErrors)&&(I.current=b.initialErrors||N,G({type:"SET_ERRORS",payload:b.initialErrors||N}))}),[h,b.initialErrors]),t.useEffect((function(){h&&!0===L.current&&!r(w.current,b.initialTouched)&&(w.current=b.initialTouched||q,G({type:"SET_TOUCHED",payload:b.initialTouched||q}))}),[h,b.initialTouched]),t.useEffect((function(){h&&!0===L.current&&!r(D.current,b.initialStatus)&&(D.current=b.initialStatus,G({type:"SET_STATUS",payload:b.initialStatus}))}),[h,b.initialStatus,b.initialTouched]);var re=Q((function(e){if(U.current[e]&&y(U.current[e].validate)){var t=O(B.values,e),r=U.current[e].validate(t);return F(r)?(G({type:"SET_ISVALIDATING",payload:!0}),r.then((function(e){return e})).then((function(t){G({type:"SET_FIELD_ERROR",payload:{field:e,value:t}}),G({type:"SET_ISVALIDATING",payload:!1})}))):(G({type:"SET_FIELD_ERROR",payload:{field:e,value:r}}),Promise.resolve(r))}return b.validationSchema?(G({type:"SET_ISVALIDATING",payload:!0}),K(B.values,e).then((function(e){return e})).then((function(t){G({type:"SET_FIELD_ERROR",payload:{field:e,value:t[e]}}),G({type:"SET_ISVALIDATING",payload:!1})}))):Promise.resolve()})),ne=t.useCallback((function(e,t){U.current[e]={validate:t.validate}}),[]),ie=t.useCallback((function(e){delete U.current[e]}),[]),ae=Q((function(e,t){return G({type:"SET_TOUCHED",payload:e}),(void 0===t?o:t)?$(B.values):Promise.resolve()})),ue=t.useCallback((function(e){G({type:"SET_ERRORS",payload:e})}),[]),oe=Q((function(e,t){var r=y(e)?e(B.values):e;return G({type:"SET_VALUES",payload:r}),(void 0===t?a:t)?$(r):Promise.resolve()})),le=t.useCallback((function(e,t){G({type:"SET_FIELD_ERROR",payload:{field:e,value:t}})}),[]),se=Q((function(e,t,r){return G({type:"SET_FIELD_VALUE",payload:{field:e,value:t}}),(void 0===r?a:r)?$(R(B.values,e,t)):Promise.resolve()})),ce=t.useCallback((function(e,t){var r,n=t,i=e;if(!T(e)){e.persist&&e.persist();var a=e.target?e.target:e.currentTarget,u=a.type,o=a.value,l=a.checked,s=a.options,c=a.multiple;n=t||a.name||a.id,i=/number|range/.test(u)?(r=parseFloat(o),isNaN(r)?"":r):/checkbox/.test(u)?k(O(B.values,n),l,o):c?C(s):o}n&&se(n,i)}),[se,B.values]),de=Q((function(e){if(T(e))return function(t){return ce(t,e)};ce(e)})),fe=Q((function(e,t,r){return void 0===t&&(t=!0),G({type:"SET_FIELD_TOUCHED",payload:{field:e,value:t}}),(void 0===r?o:r)?$(B.values):Promise.resolve()})),pe=t.useCallback((function(e,t){e.persist&&e.persist();var r=e.target;fe(t||r.name||r.id,!0)}),[fe]),ve=Q((function(e){if(T(e))return function(t){return pe(t,e)};pe(e)})),he=t.useCallback((function(e){y(e)?G({type:"SET_FORMIK_STATE",payload:e}):G({type:"SET_FORMIK_STATE",payload:function(){return e}})}),[]),me=t.useCallback((function(e){G({type:"SET_STATUS",payload:e})}),[]),ye=t.useCallback((function(e){G({type:"SET_ISSUBMITTING",payload:e})}),[]),Ee=Q((function(){return G({type:"SUBMIT_ATTEMPT"}),ee().then((function(e){var t=e instanceof Error;if(!t&&0===Object.keys(e).length){var r;try{if(void 0===(r=be()))return}catch(e){throw e}return Promise.resolve(r).then((function(e){return L.current&&G({type:"SUBMIT_SUCCESS"}),e})).catch((function(e){if(L.current)throw G({type:"SUBMIT_FAILURE"}),e}))}if(L.current&&(G({type:"SUBMIT_FAILURE"}),t))throw e}))})),Se=Q((function(e){e&&e.preventDefault&&y(e.preventDefault)&&e.preventDefault(),e&&e.stopPropagation&&y(e.stopPropagation)&&e.stopPropagation(),Ee().catch((function(e){console.warn("Warning: An unhandled error was caught from submitForm()",e)}))})),Te={resetForm:te,validateForm:ee,validateField:re,setErrors:ue,setFieldError:le,setFieldTouched:fe,setFieldValue:se,setStatus:me,setSubmitting:ye,setTouched:ae,setValues:oe,setFormikState:he,submitForm:Ee},be=Q((function(){return m(B.values,Te)})),ge=Q((function(e){e&&e.preventDefault&&y(e.preventDefault)&&e.preventDefault(),e&&e.stopPropagation&&y(e.stopPropagation)&&e.stopPropagation(),te()})),Fe=t.useCallback((function(e){return{value:O(B.values,e),error:O(B.errors,e),touched:!!O(B.touched,e),initialValue:O(g.current,e),initialTouched:!!O(w.current,e),initialError:O(I.current,e)}}),[B.errors,B.touched,B.values]),xe=Q((function(e){return{setValue:function(t,r){return se(e,t,r)},setTouched:function(t,r){return fe(e,t,r)},setError:function(t){return le(e,t)}}})),_e=Q((function(e,t){if(!_&&e.nativeEvent&&void 0!==e.nativeEvent.text)return e.nativeEvent.text;if(_&&e.nativeEvent)return e.nativeEvent.text;var r=e.target?e.target:e.currentTarget,n=r.value,i=r.checked,a=r.options,u=r.multiple;return/checkbox/.test(r.type)?k(O(B.values,t),i,n):u?C(a):n})),Oe=t.useCallback((function(e){var t=E(e),r=t?e.name?e.name:e.id:e,n=O(B.values,r),i=O(B.touched,r),a={name:r,value:n,onChange:de,onBlur:ve};if(t){var u=e.type,o=e.value,l=e.as,s=e.multiple,c=e.parse,d=void 0===c?/number|range/.test(u)?P:A:c,f=e.format,p=void 0===f?V:f,v=e.formatOnBlur,h=void 0!==v&&v;"checkbox"===u?void 0===o?a.checked=!!n:(a.checked=!(!Array.isArray(n)||!~n.indexOf(o)),a.value=o):"radio"===u?(a.checked=n===o,a.value=o):"select"===l&&s&&(a.value=a.value||[],a.multiple=!0),"radio"!==u&&"checkbox"!==u&&p&&(!0===h?!0===i&&(a.value=p(a.value)):a.value=p(a.value)),"radio"!==u&&"checkbox"!==u&&(a.onChange=function(e){x(e)?(e.persist&&e.persist(),se(r,d(_e(e,r)))):se(r,d(e))})}return a}),[_e,ve,de,se,B.touched,B.values]),Re=t.useMemo((function(){return!r(g.current,B.values)}),[g.current,B.values]),Ie=t.useMemo((function(){return void 0!==d?Re?B.errors&&0===Object.keys(B.errors).length:!1!==d&&y(d)?d(b):d:B.errors&&0===Object.keys(B.errors).length}),[d,Re,B.errors,b]);return f({},B,{initialValues:g.current,initialErrors:I.current,initialTouched:w.current,initialStatus:D.current,handleBlur:ve,handleChange:de,handleReset:ge,handleSubmit:Se,resetForm:te,setErrors:ue,setFormikState:he,setFieldTouched:fe,setFieldValue:se,setFieldError:le,setStatus:me,setSubmitting:ye,setTouched:ae,setValues:oe,submitForm:Ee,validateForm:ee,validateField:re,isValid:Ie,dirty:Re,unregisterField:ie,registerField:ne,getFieldProps:Oe,getFieldMeta:Fe,getFieldHelpers:xe,validateOnBlur:o,validateOnChange:a,validateOnMount:c})}function W(e){var r=G(e),n=e.component,i=e.children,a=e.render;return t.useImperativeHandle(e.innerRef,(function(){return r})),t.createElement(L,{value:r},n?t.createElement(n,r):a?a(r):i?y(i)?i(r):g(i)?null:t.Children.only(i):null)}function H(e){var t={};if(e.inner){if(0===e.inner.length)return R(t,e.path,e.message);var r=e.inner,n=Array.isArray(r),i=0;for(r=n?r:r[Symbol.iterator]();;){var a;if(n){if(i>=r.length)break;a=r[i++]}else{if((i=r.next()).done)break;a=i.value}var u=a;O(t,u.path)||(t=R(t,u.path,u.message))}}return t}function Y(e,t,r,n){void 0===r&&(r=!1),void 0===n&&(n={});var i=K(e);return t[r?"validateSync":"validate"](i,{abortEarly:!1,context:n})}function K(e){var t=Array.isArray(e)?[]:{};for(var r in e)if(Object.prototype.hasOwnProperty.call(e,r)){var n=String(r);t[n]=!0===Array.isArray(e[n])?e[n].map((function(e){return!0===Array.isArray(e)||i(e)?K(e):""!==e?e:void 0})):i(e[n])?K(e[n]):""!==e[n]?e[n]:void 0}return t}function z(e,t,r){var i=e.slice();return t.forEach((function(t,a){if(void 0===i[a]){var u=!1!==r.clone&&r.isMergeableObject(t);i[a]=u?n(Array.isArray(t)?[]:{},t,r):t}else r.isMergeableObject(t)?i[a]=n(e[a],t,r):-1===e.indexOf(t)&&i.push(t)})),i}var J="undefined"!=typeof window&&void 0!==window.document&&void 0!==window.document.createElement?t.useLayoutEffect:t.useEffect;function Q(e){var r=t.useRef(e);return J((function(){r.current=e})),t.useCallback((function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];return r.current.apply(void 0,t)}),[])}function X(e){var r=E(e)?e:{name:e},n=r.name,i=r.validate,a=B((function(e){return e.registerField})),u=B((function(e){return e.unregisterField}));t.useEffect((function(){return n||l(!1),a||l(!1),n&&a(n,{validate:i}),function(){n&&u(n)}}),[a,u,n,i]);var o,s={value:Z(o=n)[0],touched:ee(o)[0],error:$(o)[0],initialValue:te(o),initialTouched:re(o),initialError:ne(o)},c=s.value,d=s.touched,f=B((function(e){return e.setFieldValue})),p=B((function(e){return e.handleChange})),v=B((function(e){return e.handleBlur})),h=B((function(e){return e.getFieldHelpers})),m={name:n,value:c,onChange:p,onBlur:v},y=e.type,S=e.value,T=e.as,b=e.multiple,g=e.parse,F=void 0===g?/number|range/.test(null!=y?y:"")?P:A:g,_=e.format,O=void 0===_?V:_,R=e.formatOnBlur,I=void 0!==R&&R;return"checkbox"===y?void 0===S?m.checked=!!c:(m.checked=!(!Array.isArray(c)||!~c.indexOf(S)),m.value=S):"radio"===y?(m.checked=c===S,m.value=S):"select"===T&&b&&(m.value=m.value||[],m.multiple=!0),"radio"!==y&&"checkbox"!==y&&O&&(!0===I?!0===d&&(m.value=O(m.value,n)):m.value=O(m.value,n)),"radio"!==y&&"checkbox"!==y&&(m.onChange=function(e){x(e)?(e.persist&&e.persist(),f(n,F(w(e,c),n))):f(n,F(e,n))}),[m,s,h(n)]}function Z(e){var r=B((function(t){return O(t.values,e)})),n=B((function(e){return e.setFieldValue}));return[r,t.useCallback((function(t,r){n(e,t,r)}),[e])]}function $(e){var r=B((function(t){return O(t.errors,e)})),n=B((function(e){return e.setFieldError}));return[r,t.useCallback((function(t){n(e,t)}),[e])]}function ee(e){var r=B((function(t){return Boolean(O(t.errors,e))})),n=B((function(e){return e.setFieldTouched}));return[r,t.useCallback((function(t,r){n(e,t,r)}),[e])]}function te(e){return B((function(t){return O(t.initialValues,e)}))}function re(e){return B((function(t){return Boolean(O(t.initialTouched,e))}))}function ne(e){return B((function(t){return O(t.initialErrors,e)}))}var ie=t.forwardRef((function(e,r){var n=e.action,i=v(e,["action"]),a=n||"#",u=o.useContextSelector(D,(function(e){return e.handleReset})),l=o.useContextSelector(D,(function(e){return e.handleSubmit}));return t.createElement("form",Object.assign({onSubmit:l,ref:r,onReset:u,action:a},i))}));function ae(e){var r=function(r){return t.createElement(M,{children:function(n){return n||l(!1),t.createElement(e,Object.assign({},r,{formik:n}))}})},n=e.displayName||e.name||e.constructor&&e.constructor.name||"Component";return r.WrappedComponent=e,r.displayName="FormikConnect("+n+")",c(r,e)}ie.displayName="Form";var ue=function(e,t,r){var n=ce(e),i=n[t];return n.splice(t,1),n.splice(r,0,i),n},oe=function(e,t,r){var n=ce(e),i=n[t];return n[t]=n[r],n[r]=i,n},le=function(e,t,r){var n=ce(e);return n.splice(t,0,r),n},se=function(e,t,r){var n=ce(e);return n[t]=r,n},ce=function(e){if(e){if(Array.isArray(e))return[].concat(e);var t=Object.keys(e).map((function(e){return parseInt(e)})).reduce((function(e,t){return t>e?t:e}),0);return Array.from(f({},e,{length:t+1}))}return[]},de=function(e){function n(t){var r;return(r=e.call(this,t)||this).updateArrayField=function(e,t,n){var i=r.props,a=i.name;(0,i.formik.setFormikState)((function(r){var i="function"==typeof n?n:e,u="function"==typeof t?t:e,o=R(r.values,a,e(O(r.values,a))),l=n?i(O(r.errors,a)):void 0,s=t?u(O(r.touched,a)):void 0;return m(l)&&(l=void 0),m(s)&&(s=void 0),f({},r,{values:o,errors:n?R(r.errors,a,l):r.errors,touched:t?R(r.touched,a,s):r.touched})}))},r.push=function(e){return r.updateArrayField((function(t){return[].concat(ce(t),[d(e)])}),!1,!1)},r.handlePush=function(e){return function(){return r.push(e)}},r.swap=function(e,t){return r.updateArrayField((function(r){return oe(r,e,t)}),!0,!0)},r.handleSwap=function(e,t){return function(){return r.swap(e,t)}},r.move=function(e,t){return r.updateArrayField((function(r){return ue(r,e,t)}),!0,!0)},r.handleMove=function(e,t){return function(){return r.move(e,t)}},r.insert=function(e,t){return r.updateArrayField((function(r){return le(r,e,t)}),(function(t){return le(t,e,null)}),(function(t){return le(t,e,null)}))},r.handleInsert=function(e,t){return function(){return r.insert(e,t)}},r.replace=function(e,t){return r.updateArrayField((function(r){return se(r,e,t)}),!1,!1)},r.handleReplace=function(e,t){return function(){return r.replace(e,t)}},r.unshift=function(e){var t=-1;return r.updateArrayField((function(r){var n=r?[e].concat(r):[e];return t<0&&(t=n.length),n}),(function(e){var r=e?[null].concat(e):[null];return t<0&&(t=r.length),r}),(function(e){var r=e?[null].concat(e):[null];return t<0&&(t=r.length),r})),t},r.handleUnshift=function(e){return function(){return r.unshift(e)}},r.handleRemove=function(e){return function(){return r.remove(e)}},r.handlePop=function(){return function(){return r.pop()}},r.remove=r.remove.bind(h(r)),r.pop=r.pop.bind(h(r)),r}p(n,e);var i=n.prototype;return i.componentDidUpdate=function(e){this.props.validateOnChange&&this.props.formik.validateOnChange&&!r(O(e.formik.values,e.name),O(this.props.formik.values,this.props.name))&&this.props.formik.validateForm(this.props.formik.values)},i.remove=function(e){var t;return this.updateArrayField((function(r){var n=r?ce(r):[];return t||(t=n[e]),y(n.splice)&&n.splice(e,1),n}),!0,!0),t},i.pop=function(){var e;return this.updateArrayField((function(t){var r=t;return e||(e=r&&r.pop&&r.pop()),r}),!0,!0),e},i.render=function(){var e=this.props,r=e.component,n=e.render,i=e.children,a=e.name,u=f({},{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:v(e.formik,["validate","validationSchema"]),name:a});return r?t.createElement(r,u):n?n(u):i?"function"==typeof i?i(u):g(i)?null:t.Children.only(i):null},n}(t.Component);de.defaultProps={validateOnChange:!0};var fe=ae(de);exports.ErrorMessage=function(e){var r=e.component,n=e.render,i=e.children,a=e.name,u=v(e,["component","render","children","name"]),o=ee(a)[0],l=$(a)[0];return o&&l?n?y(n)?n(l):null:i?y(i)?i(l):null:r?t.createElement(r,u,l):l:null},exports.FastField=function(e){var r=e.render,n=e.children,i=e.as,a=e.component,u=e.shouldUpdate,o=v(e,["render","children","as","component","shouldUpdate"]);t.useEffect((function(){r&&l(!1),a&&r&&l(!1),i&&n&&y(n)&&l(!1),a&&n&&y(n)&&l(!1),r&&n&&!g(n)&&l(!1),u&&l(!1)}),[]);var s=X(o),c=s[0],d=s[1];if(r)return y(r)?r({field:c,meta:d}):null;if(y(n))return n({field:c,meta:d});var p=o.innerRef,h=v(o,["innerRef","parse","format","formatOnBlur","validate"]);if(a)return t.createElement(a,"string"==typeof a?f({ref:p},c,h):f({field:c,meta:d},h),n);var m=i||"input";return t.createElement(m,f("string"==typeof m?{ref:p}:{},c,h),n)},exports.Field=function(e){var r=e.render,n=e.children,i=e.as,a=e.component,u=v(e,["render","children","as","component"]);t.useEffect((function(){r&&l(!1),a&&r&&l(!1),i&&n&&y(n)&&l(!1),a&&n&&y(n)&&l(!1),r&&n&&!g(n)&&l(!1)}),[]);var o=X(u),s=o[0],c=o[1],d={field:s,form:v(U(),["validate","validationSchema"])};if(r)return y(r)?r(f({},d,{meta:c})):null;if(y(n))return n(f({},d,{meta:c}));var p=i||"input";if("string"==typeof p){var h=u.innerRef,m=v(u,["innerRef","parse","format","formatOnBlur"]);return t.createElement(p,f({ref:h},s,m),n)}var E=v(u,["parse","format","formatOnBlur"]);return t.createElement(p,f({},s,E),n)},exports.FieldArray=fe,exports.Form=ie,exports.Formik=W,exports.FormikConsumer=M,exports.FormikContext=D,exports.FormikProvider=L,exports.connect=ae,exports.defaultFormatFn=V,exports.defaultParseFn=A,exports.getActiveElement=function(e){if(void 0===(e=e||("undefined"!=typeof document?document:void 0)))return null;try{return e.activeElement||e.body}catch(t){return e.body}},exports.getIn=O,exports.getSelectedValues=C,exports.getValueForCheckbox=k,exports.getValueFromEvent=w,exports.insert=le,exports.isEmptyArray=m,exports.isEmptyChildren=g,exports.isFunction=y,exports.isInputEvent=x,exports.isInteger=S,exports.isNaN=b,exports.isObject=E,exports.isPromise=F,exports.isReactNative=_,exports.isString=T,exports.move=ue,exports.numberParseFn=P,exports.prepareDataForValidation=K,exports.replace=se,exports.setIn=R,exports.setNestedObjectValues=I,exports.swap=oe,exports.useErrors=function(){return[B((function(e){return e.errors})),B((function(e){return e.setErrors}))]},exports.useField=X,exports.useFieldError=$,exports.useFieldInitialError=ne,exports.useFieldInitialTouched=re,exports.useFieldInitialValue=te,exports.useFieldTouched=ee,exports.useFieldValue=Z,exports.useFormik=G,exports.useFormikContext=U,exports.useFormikContextSelector=B,exports.useInitialErrors=function(){return B((function(e){return e.initialErrors}))},exports.useInitialStatus=function(){return B((function(e){return e.initialStatus}))},exports.useInitialTouched=function(){return B((function(e){return e.initialTouched}))},exports.useInitialValues=function(){return B((function(e){return e.initialValues}))},exports.useStatus=function(){return[B((function(e){return e.status})),B((function(e){return e.setStatus}))]},exports.useTouched=function(){return[B((function(e){return e.touched})),B((function(e){return e.setTouched}))]},exports.useValues=function(){return[B((function(e){return e.values})),B((function(e){return e.setValues}))]},exports.validateYupSchema=Y,exports.withFormik=function(e){var r=e.mapPropsToValues,n=void 0===r?function(e){var t={};for(var r in e)e.hasOwnProperty(r)&&"function"!=typeof e[r]&&(t[r]=e[r]);return t}:r,i=v(e,["mapPropsToValues"]);return function(e){var r=e.displayName||e.name||e.constructor&&e.constructor.name||"Component",a=function(r){function a(){var n;return(n=r.apply(this,arguments)||this).validate=function(e){return i.validate(e,n.props)},n.validationSchema=function(){return y(i.validationSchema)?i.validationSchema(n.props):i.validationSchema},n.handleSubmit=function(e,t){return i.handleSubmit(e,f({},t,{props:n.props}))},n.renderFormComponent=function(r){return t.createElement(e,Object.assign({},n.props,r))},n}return p(a,r),a.prototype.render=function(){var e=v(this.props,["children"]);return t.createElement(W,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}(t.Component);return a.displayName="WithFormik("+r+")",c(a,e)}},exports.yupToFormErrors=H; | ||
"use strict";function e(e){return e&&"object"==typeof e&&"default"in e?e.default:e}Object.defineProperty(exports,"__esModule",{value:!0});var t=require("react"),r=e(require("react-fast-compare")),n=e(require("deepmerge")),i=e(require("lodash/isPlainObject")),a=e(require("lodash/clone")),u=e(require("lodash/toPath")),o=require("use-context-selector"),l=e(require("tiny-warning")),s=require("scheduler"),c=e(require("hoist-non-react-statics")),d=e(require("lodash/cloneDeep"));function f(){return(f=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e}).apply(this,arguments)}function p(e,t){e.prototype=Object.create(t.prototype),e.prototype.constructor=e,e.__proto__=t}function v(e,t){if(null==e)return{};var r,n,i={},a=Object.keys(e);for(n=0;n<a.length;n++)t.indexOf(r=a[n])>=0||(i[r]=e[r]);return i}function h(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}var m=function(e){return Array.isArray(e)&&0===e.length},y=function(e){return"function"==typeof e},E=function(e){return null!==e&&"object"==typeof e},S=function(e){return String(Math.floor(Number(e)))===e},T=function(e){return"[object String]"===Object.prototype.toString.call(e)},b=function(e){return e!=e},g=function(e){return 0===t.Children.count(e)},F=function(e){return E(e)&&y(e.then)},x=function(e){return e&&E(e)&&E(e.target)},_="undefined"!=typeof window&&window.navigator&&window.navigator.product&&"ReactNative"===window.navigator.product;function O(e,t,r,n){void 0===n&&(n=0);for(var i=u(t);e&&n<i.length;)e=e[i[n++]];return void 0===e?r:e}function R(e,t,r){for(var n=a(e),i=n,o=0,l=u(t);o<l.length-1;o++){var s=l[o],c=O(e,l.slice(0,o+1));if(c&&(E(c)||Array.isArray(c)))i=i[s]=a(c);else{var d=l[o+1];i=i[s]=S(d)&&Number(d)>=0?[]:{}}}return(0===o?e:i)[l[o]]===r?e:(void 0===r?delete i[l[o]]:i[l[o]]=r,0===o&&void 0===r&&delete n[l[o]],n)}function I(e,t,r,n){void 0===r&&(r=new WeakMap),void 0===n&&(n={});for(var i=0,a=Object.keys(e);i<a.length;i++){var u=a[i],o=e[u];E(o)?r.get(o)||(r.set(o,!0),n[u]=Array.isArray(o)?[]:{},I(o,t,r,n[u])):n[u]=t}return n}function k(e){var t=[];if(e)for(var r=0;r<e.length;r++){var n=e[r];n.selected&&t.push(n.value)}return t}function C(e,t,r){if("boolean"==typeof e)return Boolean(t);var n=[],i=!1,a=-1;if(Array.isArray(e))n=e,i=(a=e.indexOf(r))>=0;else if(!r||"true"==r||"false"==r)return Boolean(t);return t&&r&&!i?n.concat(r):i?n.slice(0,a).concat(n.slice(a+1)):n}var A=function(e,t){return e},P=function(e,t){var r=parseFloat(e);return b(r)?"":r},V=function(e,t){return void 0===e?"":e},w=function(e,t){if(!_&&e.nativeEvent&&void 0!==e.nativeEvent.text)return e.nativeEvent.text;if(_&&e.nativeEvent)return e.nativeEvent.text;var r=e.target?e.target:e.currentTarget,n=r.value,i=r.checked,a=r.options,u=r.multiple;return/checkbox/.test(r.type)?C(t,i,n):u?k(a):n},D=o.createContext(void 0),L=D.Provider;function U(){return o.useContext(D)}function M(e){var r=e.children,n=U();return n||l(!1),t.createElement(t.Fragment,null,r(n))}function B(e){return o.useContextSelector(D,e)}function j(e,t){switch(t.type){case"SET_VALUES":return f({},e,{values:t.payload});case"SET_TOUCHED":return f({},e,{touched:t.payload});case"SET_ERRORS":return r(e.errors,t.payload)?e:f({},e,{errors:t.payload});case"SET_LOW_PRIORITY_ERRORS":return r(e.errors,t.payload.errors)||!r(e.values,t.payload.values)?e:f({},e,{errors:t.payload.errors});case"SET_STATUS":return f({},e,{status:t.payload});case"SET_ISSUBMITTING":return f({},e,{isSubmitting:t.payload});case"SET_ISVALIDATING":return f({},e,{isValidating:t.payload});case"SET_FIELD_VALUE":return f({},e,{values:R(e.values,t.payload.field,t.payload.value)});case"SET_FIELD_TOUCHED":return f({},e,{touched:R(e.touched,t.payload.field,t.payload.value)});case"SET_FIELD_ERROR":return f({},e,{errors:R(e.errors,t.payload.field,t.payload.value)});case"RESET_FORM":return f({},e,t.payload);case"SET_FORMIK_STATE":return t.payload(e);case"SUBMIT_ATTEMPT":return f({},e,{touched:I(e.values,!0),isSubmitting:!0,submitCount:e.submitCount+1});case"SUBMIT_FAILURE":case"SUBMIT_SUCCESS":return f({},e,{isSubmitting:!1});default:return e}}var N={},q={};function G(e){var i=e.validateOnChange,a=void 0===i||i,u=e.validateOnBlur,o=void 0===u||u,l=e.validateOnMount,c=void 0!==l&&l,d=e.isInitialValid,p=e.enableReinitialize,h=void 0!==p&&p,m=e.onSubmit,S=v(e,["validateOnChange","validateOnBlur","validateOnMount","isInitialValid","enableReinitialize","onSubmit"]),b=f({validateOnChange:a,validateOnBlur:o,validateOnMount:c,onSubmit:m},S),g=t.useRef(b.initialValues),I=t.useRef(b.initialErrors||N),w=t.useRef(b.initialTouched||q),D=t.useRef(b.initialStatus),L=t.useRef(!1),U=t.useRef({});t.useEffect((function(){return L.current=!0,function(){L.current=!1}}),[]);var M=t.useReducer(j,{values:b.initialValues,errors:b.initialErrors||N,touched:b.initialTouched||q,status:b.initialStatus,isSubmitting:!1,isValidating:!1,submitCount:0}),B=M[0],G=M[1],W=t.useCallback((function(e,t){return new Promise((function(r,n){var i=b.validate(e,t);null==i?r(N):F(i)?i.then((function(e){r(e||N)}),(function(e){n(e)})):r(i)}))}),[b.validate]),K=t.useCallback((function(e,t){var r=b.validationSchema,n=y(r)?r(t):r,i=t&&n.validateAt?n.validateAt(t,e):Y(e,n);return new Promise((function(e,t){i.then((function(){e(N)}),(function(r){"ValidationError"===r.name?e(H(r)):t(r)}))}))}),[b.validationSchema]),J=t.useCallback((function(e,t){return new Promise((function(r){return r(U.current[e].validate(t))}))}),[]),X=t.useCallback((function(e){var t=Object.keys(U.current).filter((function(e){return y(U.current[e].validate)})),r=t.length>0?t.map((function(t){return J(t,O(e,t))})):[Promise.resolve("DO_NOT_DELETE_YOU_WILL_BE_FIRED")];return Promise.all(r).then((function(e){return e.reduce((function(e,r,n){return"DO_NOT_DELETE_YOU_WILL_BE_FIRED"===r?e:(r&&(e=R(e,t[n],r)),e)}),{})}))}),[J]),Z=t.useCallback((function(e){return Promise.all([X(e),b.validationSchema?K(e):{},b.validate?W(e):{}]).then((function(e){return n.all([e[0],e[1],e[2]],{arrayMerge:z})}))}),[b.validate,b.validationSchema,X,W,K]),$=Q((function(e){return void 0===e&&(e=B.values),t=function(){return Z(e).then((function(t){return L.current&&G({type:"SET_LOW_PRIORITY_ERRORS",payload:{values:e,errors:t}}),t})).catch((function(e){}))},s.unstable_runWithPriority(s.unstable_LowPriority,(function(){return s.unstable_scheduleCallback(s.unstable_LowPriority,t)}));var t})),ee=Q((function(e){return void 0===e&&(e=B.values),G({type:"SET_ISVALIDATING",payload:!0}),Z(e).then((function(e){return L.current&&(G({type:"SET_ISVALIDATING",payload:!1}),r(B.errors,e)||G({type:"SET_ERRORS",payload:e})),e}))}));t.useEffect((function(){c&&!0===L.current&&r(g.current,b.initialValues)&&$(g.current)}),[c,$]);var te=t.useCallback((function(e){var t=e&&e.values?e.values:g.current,r=e&&e.errors?e.errors:I.current?I.current:b.initialErrors||{},n=e&&e.touched?e.touched:w.current?w.current:b.initialTouched||{},i=e&&e.status?e.status:D.current?D.current:b.initialStatus;g.current=t,I.current=r,w.current=n,D.current=i;var a=function(){G({type:"RESET_FORM",payload:{isSubmitting:!!e&&!!e.isSubmitting,errors:r,touched:n,status:i,values:t,isValidating:!!e&&!!e.isValidating,submitCount:e&&e.submitCount&&"number"==typeof e.submitCount?e.submitCount:0}})};if(b.onReset){var u=b.onReset(B.values,Te);F(u)?u.then(a):a()}else a()}),[b.initialErrors,b.initialStatus,b.initialTouched]);t.useEffect((function(){!0!==L.current||r(g.current,b.initialValues)||(h&&(g.current=b.initialValues,te()),c&&$(g.current))}),[h,b.initialValues,te,c,$]),t.useEffect((function(){h&&!0===L.current&&!r(I.current,b.initialErrors)&&(I.current=b.initialErrors||N,G({type:"SET_ERRORS",payload:b.initialErrors||N}))}),[h,b.initialErrors]),t.useEffect((function(){h&&!0===L.current&&!r(w.current,b.initialTouched)&&(w.current=b.initialTouched||q,G({type:"SET_TOUCHED",payload:b.initialTouched||q}))}),[h,b.initialTouched]),t.useEffect((function(){h&&!0===L.current&&!r(D.current,b.initialStatus)&&(D.current=b.initialStatus,G({type:"SET_STATUS",payload:b.initialStatus}))}),[h,b.initialStatus,b.initialTouched]);var re=Q((function(e){if(U.current[e]&&y(U.current[e].validate)){var t=O(B.values,e),r=U.current[e].validate(t);return F(r)?(G({type:"SET_ISVALIDATING",payload:!0}),r.then((function(e){return e})).then((function(t){G({type:"SET_FIELD_ERROR",payload:{field:e,value:t}}),G({type:"SET_ISVALIDATING",payload:!1})}))):(G({type:"SET_FIELD_ERROR",payload:{field:e,value:r}}),Promise.resolve(r))}return b.validationSchema?(G({type:"SET_ISVALIDATING",payload:!0}),K(B.values,e).then((function(e){return e})).then((function(t){G({type:"SET_FIELD_ERROR",payload:{field:e,value:t[e]}}),G({type:"SET_ISVALIDATING",payload:!1})}))):Promise.resolve()})),ne=t.useCallback((function(e,t){U.current[e]={validate:t.validate}}),[]),ie=t.useCallback((function(e){delete U.current[e]}),[]),ae=Q((function(e,t){return G({type:"SET_TOUCHED",payload:e}),(void 0===t?o:t)?$(B.values):Promise.resolve()})),ue=t.useCallback((function(e){G({type:"SET_ERRORS",payload:e})}),[]),oe=Q((function(e,t){var r=y(e)?e(B.values):e;return G({type:"SET_VALUES",payload:r}),(void 0===t?a:t)?$(r):Promise.resolve()})),le=t.useCallback((function(e,t){G({type:"SET_FIELD_ERROR",payload:{field:e,value:t}})}),[]),se=Q((function(e,t,r){return G({type:"SET_FIELD_VALUE",payload:{field:e,value:t}}),(void 0===r?a:r)?$(R(B.values,e,t)):Promise.resolve()})),ce=t.useCallback((function(e,t){var r,n=t,i=e;if(!T(e)){e.persist&&e.persist();var a=e.target?e.target:e.currentTarget,u=a.type,o=a.value,l=a.checked,s=a.options,c=a.multiple;n=t||a.name||a.id,i=/number|range/.test(u)?(r=parseFloat(o),isNaN(r)?"":r):/checkbox/.test(u)?C(O(B.values,n),l,o):c?k(s):o}n&&se(n,i)}),[se,B.values]),de=Q((function(e){if(T(e))return function(t){return ce(t,e)};ce(e)})),fe=Q((function(e,t,r){return void 0===t&&(t=!0),G({type:"SET_FIELD_TOUCHED",payload:{field:e,value:t}}),(void 0===r?o:r)?$(B.values):Promise.resolve()})),pe=t.useCallback((function(e,t){e.persist&&e.persist();var r=e.target;fe(t||r.name||r.id,!0)}),[fe]),ve=Q((function(e){if(T(e))return function(t){return pe(t,e)};pe(e)})),he=t.useCallback((function(e){y(e)?G({type:"SET_FORMIK_STATE",payload:e}):G({type:"SET_FORMIK_STATE",payload:function(){return e}})}),[]),me=t.useCallback((function(e){G({type:"SET_STATUS",payload:e})}),[]),ye=t.useCallback((function(e){G({type:"SET_ISSUBMITTING",payload:e})}),[]),Ee=Q((function(){return G({type:"SUBMIT_ATTEMPT"}),ee().then((function(e){var t=e instanceof Error;if(!t&&0===Object.keys(e).length){var r;try{if(void 0===(r=be()))return}catch(e){throw e}return Promise.resolve(r).then((function(e){return L.current&&G({type:"SUBMIT_SUCCESS"}),e})).catch((function(e){if(L.current)throw G({type:"SUBMIT_FAILURE"}),e}))}if(L.current&&(G({type:"SUBMIT_FAILURE"}),t))throw e}))})),Se=Q((function(e){e&&e.preventDefault&&y(e.preventDefault)&&e.preventDefault(),e&&e.stopPropagation&&y(e.stopPropagation)&&e.stopPropagation(),Ee().catch((function(e){console.warn("Warning: An unhandled error was caught from submitForm()",e)}))})),Te={resetForm:te,validateForm:ee,validateField:re,setErrors:ue,setFieldError:le,setFieldTouched:fe,setFieldValue:se,setStatus:me,setSubmitting:ye,setTouched:ae,setValues:oe,setFormikState:he,submitForm:Ee},be=Q((function(){return m(B.values,Te)})),ge=Q((function(e){e&&e.preventDefault&&y(e.preventDefault)&&e.preventDefault(),e&&e.stopPropagation&&y(e.stopPropagation)&&e.stopPropagation(),te()})),Fe=t.useCallback((function(e){return{value:O(B.values,e),error:O(B.errors,e),touched:!!O(B.touched,e),initialValue:O(g.current,e),initialTouched:!!O(w.current,e),initialError:O(I.current,e)}}),[B.errors,B.touched,B.values]),xe=Q((function(e){return{setValue:function(t,r){return se(e,t,r)},setTouched:function(t,r){return fe(e,t,r)},setError:function(t){return le(e,t)}}})),_e=Q((function(e,t){if(!_&&e.nativeEvent&&void 0!==e.nativeEvent.text)return e.nativeEvent.text;if(_&&e.nativeEvent)return e.nativeEvent.text;var r=e.target?e.target:e.currentTarget,n=r.value,i=r.checked,a=r.options,u=r.multiple;return/checkbox/.test(r.type)?C(O(B.values,t),i,n):u?k(a):n})),Oe=t.useCallback((function(e){var t=E(e),r=t?e.name?e.name:e.id:e,n=O(B.values,r),i=O(B.touched,r),a={name:r,value:n,onChange:de,onBlur:ve};if(t){var u=e.type,o=e.value,l=e.as,s=e.multiple,c=e.parse,d=void 0===c?/number|range/.test(u)?P:A:c,f=e.format,p=void 0===f?V:f,v=e.formatOnBlur,h=void 0!==v&&v;"checkbox"===u?void 0===o?a.checked=!!n:(a.checked=!(!Array.isArray(n)||!~n.indexOf(o)),a.value=o):"radio"===u?(a.checked=n===o,a.value=o):"select"===l&&s&&(a.value=a.value||[],a.multiple=!0),"radio"!==u&&"checkbox"!==u&&p&&(!0===h?!0===i&&(a.value=p(a.value)):a.value=p(a.value)),"radio"!==u&&"checkbox"!==u&&(a.onChange=function(e){x(e)?(e.persist&&e.persist(),se(r,d(_e(e,r)))):se(r,d(e))})}return a}),[_e,ve,de,se,B.touched,B.values]),Re=t.useMemo((function(){return!r(g.current,B.values)}),[g.current,B.values]),Ie=t.useMemo((function(){return void 0!==d?Re?B.errors&&0===Object.keys(B.errors).length:!1!==d&&y(d)?d(b):d:B.errors&&0===Object.keys(B.errors).length}),[d,Re,B.errors,b]);return f({},B,{initialValues:g.current,initialErrors:I.current,initialTouched:w.current,initialStatus:D.current,handleBlur:ve,handleChange:de,handleReset:ge,handleSubmit:Se,resetForm:te,setErrors:ue,setFormikState:he,setFieldTouched:fe,setFieldValue:se,setFieldError:le,setStatus:me,setSubmitting:ye,setTouched:ae,setValues:oe,submitForm:Ee,validateForm:ee,validateField:re,isValid:Ie,dirty:Re,unregisterField:ie,registerField:ne,getFieldProps:Oe,getFieldMeta:Fe,getFieldHelpers:xe,validateOnBlur:o,validateOnChange:a,validateOnMount:c})}function W(e){var r=G(e),n=e.component,i=e.children,a=e.render;return t.useImperativeHandle(e.innerRef,(function(){return r})),t.createElement(L,{value:r},n?t.createElement(n,r):a?a(r):i?y(i)?i(r):g(i)?null:t.Children.only(i):null)}function H(e){var t={};if(e.inner){if(0===e.inner.length)return R(t,e.path,e.message);var r=e.inner,n=Array.isArray(r),i=0;for(r=n?r:r[Symbol.iterator]();;){var a;if(n){if(i>=r.length)break;a=r[i++]}else{if((i=r.next()).done)break;a=i.value}var u=a;O(t,u.path)||(t=R(t,u.path,u.message))}}return t}function Y(e,t,r,n){void 0===r&&(r=!1),void 0===n&&(n={});var i=K(e);return t[r?"validateSync":"validate"](i,{abortEarly:!1,context:n})}function K(e){var t=Array.isArray(e)?[]:{};for(var r in e)if(Object.prototype.hasOwnProperty.call(e,r)){var n=String(r);t[n]=!0===Array.isArray(e[n])?e[n].map((function(e){return!0===Array.isArray(e)||i(e)?K(e):""!==e?e:void 0})):i(e[n])?K(e[n]):""!==e[n]?e[n]:void 0}return t}function z(e,t,r){var i=e.slice();return t.forEach((function(t,a){if(void 0===i[a]){var u=!1!==r.clone&&r.isMergeableObject(t);i[a]=u?n(Array.isArray(t)?[]:{},t,r):t}else r.isMergeableObject(t)?i[a]=n(e[a],t,r):-1===e.indexOf(t)&&i.push(t)})),i}var J="undefined"!=typeof window&&void 0!==window.document&&void 0!==window.document.createElement?t.useLayoutEffect:t.useEffect;function Q(e){var r=t.useRef(e);return J((function(){r.current=e})),t.useCallback((function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];return r.current.apply(void 0,t)}),[])}function X(e){var r=E(e)?e:{name:e},n=r.name,i=r.validate,a=B((function(e){return e.registerField})),u=B((function(e){return e.unregisterField}));t.useEffect((function(){return n||l(!1),a||l(!1),n&&a(n,{validate:i}),function(){n&&u(n)}}),[a,u,n,i]);var o,s={value:Z(o=n)[0],touched:ee(o)[0],error:$(o)[0],initialValue:te(o),initialTouched:re(o),initialError:ne(o)},c=s.value,d=s.touched,f=B((function(e){return e.setFieldValue})),p=B((function(e){return e.setFieldTouched})),v=B((function(e){return e.getFieldHelpers})),h={name:n,value:c,onChange:function(e){x(e)?(e.persist&&e.persist(),f(n,g(w(e,c),n))):f(n,g(e,n))},onBlur:function(e){x(e)?(e.persist&&e.persist(),p(n,!0)):f(n,e)}},m=e.type,y=e.value,S=e.as,T=e.multiple,b=e.parse,g=void 0===b?/number|range/.test(null!=m?m:"")?P:A:b,F=e.format,_=void 0===F?V:F,O=e.formatOnBlur,R=void 0!==O&&O;return"checkbox"===m?void 0===y?h.checked=!!c:(h.checked=!(!Array.isArray(c)||!~c.indexOf(y)),h.value=y):"radio"===m?(h.checked=c===y,h.value=y):"select"===S&&T&&(h.value=h.value||[],h.multiple=!0),"radio"!==m&&"checkbox"!==m&&_&&(!0===R?!0===d&&(h.value=_(h.value,n)):h.value=_(h.value,n)),[h,s,v(n)]}function Z(e){var r=B((function(t){return O(t.values,e)})),n=B((function(e){return e.setFieldValue}));return[r,t.useCallback((function(t,r){n(e,t,r)}),[e])]}function $(e){var r=B((function(t){return O(t.errors,e)})),n=B((function(e){return e.setFieldError}));return[r,t.useCallback((function(t){n(e,t)}),[e])]}function ee(e){var r=B((function(t){return Boolean(O(t.errors,e))})),n=B((function(e){return e.setFieldTouched}));return[r,t.useCallback((function(t,r){n(e,t,r)}),[e])]}function te(e){return B((function(t){return O(t.initialValues,e)}))}function re(e){return B((function(t){return Boolean(O(t.initialTouched,e))}))}function ne(e){return B((function(t){return O(t.initialErrors,e)}))}var ie=t.forwardRef((function(e,r){var n=e.action,i=v(e,["action"]),a=n||"#",u=o.useContextSelector(D,(function(e){return e.handleReset})),l=o.useContextSelector(D,(function(e){return e.handleSubmit}));return t.createElement("form",Object.assign({onSubmit:l,ref:r,onReset:u,action:a},i))}));function ae(e){var r=function(r){return t.createElement(M,{children:function(n){return n||l(!1),t.createElement(e,Object.assign({},r,{formik:n}))}})},n=e.displayName||e.name||e.constructor&&e.constructor.name||"Component";return r.WrappedComponent=e,r.displayName="FormikConnect("+n+")",c(r,e)}ie.displayName="Form";var ue=function(e,t,r){var n=ce(e),i=n[t];return n.splice(t,1),n.splice(r,0,i),n},oe=function(e,t,r){var n=ce(e),i=n[t];return n[t]=n[r],n[r]=i,n},le=function(e,t,r){var n=ce(e);return n.splice(t,0,r),n},se=function(e,t,r){var n=ce(e);return n[t]=r,n},ce=function(e){if(e){if(Array.isArray(e))return[].concat(e);var t=Object.keys(e).map((function(e){return parseInt(e)})).reduce((function(e,t){return t>e?t:e}),0);return Array.from(f({},e,{length:t+1}))}return[]},de=function(e){function n(t){var r;return(r=e.call(this,t)||this).updateArrayField=function(e,t,n){var i=r.props,a=i.name;(0,i.formik.setFormikState)((function(r){var i="function"==typeof n?n:e,u="function"==typeof t?t:e,o=R(r.values,a,e(O(r.values,a))),l=n?i(O(r.errors,a)):void 0,s=t?u(O(r.touched,a)):void 0;return m(l)&&(l=void 0),m(s)&&(s=void 0),f({},r,{values:o,errors:n?R(r.errors,a,l):r.errors,touched:t?R(r.touched,a,s):r.touched})}))},r.push=function(e){return r.updateArrayField((function(t){return[].concat(ce(t),[d(e)])}),!1,!1)},r.handlePush=function(e){return function(){return r.push(e)}},r.swap=function(e,t){return r.updateArrayField((function(r){return oe(r,e,t)}),!0,!0)},r.handleSwap=function(e,t){return function(){return r.swap(e,t)}},r.move=function(e,t){return r.updateArrayField((function(r){return ue(r,e,t)}),!0,!0)},r.handleMove=function(e,t){return function(){return r.move(e,t)}},r.insert=function(e,t){return r.updateArrayField((function(r){return le(r,e,t)}),(function(t){return le(t,e,null)}),(function(t){return le(t,e,null)}))},r.handleInsert=function(e,t){return function(){return r.insert(e,t)}},r.replace=function(e,t){return r.updateArrayField((function(r){return se(r,e,t)}),!1,!1)},r.handleReplace=function(e,t){return function(){return r.replace(e,t)}},r.unshift=function(e){var t=-1;return r.updateArrayField((function(r){var n=r?[e].concat(r):[e];return t<0&&(t=n.length),n}),(function(e){var r=e?[null].concat(e):[null];return t<0&&(t=r.length),r}),(function(e){var r=e?[null].concat(e):[null];return t<0&&(t=r.length),r})),t},r.handleUnshift=function(e){return function(){return r.unshift(e)}},r.handleRemove=function(e){return function(){return r.remove(e)}},r.handlePop=function(){return function(){return r.pop()}},r.remove=r.remove.bind(h(r)),r.pop=r.pop.bind(h(r)),r}p(n,e);var i=n.prototype;return i.componentDidUpdate=function(e){this.props.validateOnChange&&this.props.formik.validateOnChange&&!r(O(e.formik.values,e.name),O(this.props.formik.values,this.props.name))&&this.props.formik.validateForm(this.props.formik.values)},i.remove=function(e){var t;return this.updateArrayField((function(r){var n=r?ce(r):[];return t||(t=n[e]),y(n.splice)&&n.splice(e,1),n}),!0,!0),t},i.pop=function(){var e;return this.updateArrayField((function(t){var r=t;return e||(e=r&&r.pop&&r.pop()),r}),!0,!0),e},i.render=function(){var e=this.props,r=e.component,n=e.render,i=e.children,a=e.name,u=f({},{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:v(e.formik,["validate","validationSchema"]),name:a});return r?t.createElement(r,u):n?n(u):i?"function"==typeof i?i(u):g(i)?null:t.Children.only(i):null},n}(t.Component);de.defaultProps={validateOnChange:!0};var fe=ae(de);exports.ErrorMessage=function(e){var r=e.component,n=e.render,i=e.children,a=e.name,u=v(e,["component","render","children","name"]),o=ee(a)[0],l=$(a)[0];return o&&l?n?y(n)?n(l):null:i?y(i)?i(l):null:r?t.createElement(r,u,l):l:null},exports.FastField=function(e){var r=e.render,n=e.children,i=e.as,a=e.component,u=e.shouldUpdate,o=v(e,["render","children","as","component","shouldUpdate"]);t.useEffect((function(){r&&l(!1),a&&r&&l(!1),i&&n&&y(n)&&l(!1),a&&n&&y(n)&&l(!1),r&&n&&!g(n)&&l(!1),u&&l(!1)}),[]);var s=X(o),c=s[0],d=s[1];if(r)return y(r)?r({field:c,meta:d}):null;if(y(n))return n({field:c,meta:d});var p=o.innerRef,h=v(o,["innerRef","parse","format","formatOnBlur","validate"]);if(a)return t.createElement(a,"string"==typeof a?f({ref:p},c,h):f({field:c,meta:d},h),n);var m=i||"input";return t.createElement(m,f("string"==typeof m?{ref:p}:{},c,h),n)},exports.Field=function(e){var r=e.render,n=e.children,i=e.as,a=e.component,u=v(e,["render","children","as","component"]);t.useEffect((function(){r&&l(!1),a&&r&&l(!1),i&&n&&y(n)&&l(!1),a&&n&&y(n)&&l(!1),r&&n&&!g(n)&&l(!1)}),[]);var o=X(u),s=o[0],c=o[1],d={field:s,form:v(U(),["validate","validationSchema"])};if(r)return y(r)?r(f({},d,{meta:c})):null;if(y(n))return n(f({},d,{meta:c}));var p=i||"input";if("string"==typeof p){var h=u.innerRef,m=v(u,["innerRef","parse","format","formatOnBlur"]);return t.createElement(p,f({ref:h},s,m),n)}var E=v(u,["parse","format","formatOnBlur"]);return t.createElement(p,f({},s,E),n)},exports.FieldArray=fe,exports.Form=ie,exports.Formik=W,exports.FormikConsumer=M,exports.FormikContext=D,exports.FormikProvider=L,exports.connect=ae,exports.defaultFormatFn=V,exports.defaultParseFn=A,exports.getActiveElement=function(e){if(void 0===(e=e||("undefined"!=typeof document?document:void 0)))return null;try{return e.activeElement||e.body}catch(t){return e.body}},exports.getIn=O,exports.getSelectedValues=k,exports.getValueForCheckbox=C,exports.getValueFromEvent=w,exports.insert=le,exports.isEmptyArray=m,exports.isEmptyChildren=g,exports.isFunction=y,exports.isInputEvent=x,exports.isInteger=S,exports.isNaN=b,exports.isObject=E,exports.isPromise=F,exports.isReactNative=_,exports.isString=T,exports.move=ue,exports.numberParseFn=P,exports.prepareDataForValidation=K,exports.replace=se,exports.setIn=R,exports.setNestedObjectValues=I,exports.swap=oe,exports.useErrors=function(){return[B((function(e){return e.errors})),B((function(e){return e.setErrors}))]},exports.useField=X,exports.useFieldError=$,exports.useFieldInitialError=ne,exports.useFieldInitialTouched=re,exports.useFieldInitialValue=te,exports.useFieldTouched=ee,exports.useFieldValue=Z,exports.useFormik=G,exports.useFormikContext=U,exports.useFormikContextSelector=B,exports.useInitialErrors=function(){return B((function(e){return e.initialErrors}))},exports.useInitialStatus=function(){return B((function(e){return e.initialStatus}))},exports.useInitialTouched=function(){return B((function(e){return e.initialTouched}))},exports.useInitialValues=function(){return B((function(e){return e.initialValues}))},exports.useStatus=function(){return[B((function(e){return e.status})),B((function(e){return e.setStatus}))]},exports.useTouched=function(){return[B((function(e){return e.touched})),B((function(e){return e.setTouched}))]},exports.useValues=function(){return[B((function(e){return e.values})),B((function(e){return e.setValues}))]},exports.validateYupSchema=Y,exports.withFormik=function(e){var r=e.mapPropsToValues,n=void 0===r?function(e){var t={};for(var r in e)e.hasOwnProperty(r)&&"function"!=typeof e[r]&&(t[r]=e[r]);return t}:r,i=v(e,["mapPropsToValues"]);return function(e){var r=e.displayName||e.name||e.constructor&&e.constructor.name||"Component",a=function(r){function a(){var n;return(n=r.apply(this,arguments)||this).validate=function(e){return i.validate(e,n.props)},n.validationSchema=function(){return y(i.validationSchema)?i.validationSchema(n.props):i.validationSchema},n.handleSubmit=function(e,t){return i.handleSubmit(e,f({},t,{props:n.props}))},n.renderFormComponent=function(r){return t.createElement(e,Object.assign({},n.props,r))},n}return p(a,r),a.prototype.render=function(){var e=v(this.props,["children"]);return t.createElement(W,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}(t.Component);return a.displayName="WithFormik("+r+")",c(a,e)}},exports.yupToFormErrors=H; | ||
//# sourceMappingURL=formik.cjs.production.min.js.map |
{ | ||
"name": "formik", | ||
"description": "Forms in React, without tears", | ||
"version": "3.0.0-next.4", | ||
"version": "3.0.0-next.5", | ||
"license": "Apache-2.0", | ||
@@ -6,0 +6,0 @@ "author": "Jared Palmer <jared@palmer.net>", |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
660127
4913