UNPKG

react-swift-form

Version:
29 lines (25 loc) 33.2 kB
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const m=require("react");var He={exports:{}},we={};/** * @license React * react-jsx-runtime.production.min.js * * Copyright (c) Facebook, Inc. and its affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */var Cr;function lt(){if(Cr)return we;Cr=1;var r=m,t=Symbol.for("react.element"),a=Symbol.for("react.fragment"),s=Object.prototype.hasOwnProperty,n=r.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,i={key:!0,ref:!0,__self:!0,__source:!0};function l(u,f,h){var v,y={},w=null,p=null;h!==void 0&&(w=""+h),f.key!==void 0&&(w=""+f.key),f.ref!==void 0&&(p=f.ref);for(v in f)s.call(f,v)&&!i.hasOwnProperty(v)&&(y[v]=f[v]);if(u&&u.defaultProps)for(v in f=u.defaultProps,f)y[v]===void 0&&(y[v]=f[v]);return{$$typeof:t,type:u,key:w,ref:p,props:y,_owner:n.current}}return we.Fragment=a,we.jsx=l,we.jsxs=l,we}var Te={};/** * @license React * react-jsx-runtime.development.js * * Copyright (c) Facebook, Inc. and its affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */var Or;function ct(){return Or||(Or=1,process.env.NODE_ENV!=="production"&&function(){var r=m,t=Symbol.for("react.element"),a=Symbol.for("react.portal"),s=Symbol.for("react.fragment"),n=Symbol.for("react.strict_mode"),i=Symbol.for("react.profiler"),l=Symbol.for("react.provider"),u=Symbol.for("react.context"),f=Symbol.for("react.forward_ref"),h=Symbol.for("react.suspense"),v=Symbol.for("react.suspense_list"),y=Symbol.for("react.memo"),w=Symbol.for("react.lazy"),p=Symbol.for("react.offscreen"),k=Symbol.iterator,N="@@iterator";function I(e){if(e===null||typeof e!="object")return null;var o=k&&e[k]||e[N];return typeof o=="function"?o:null}var R=r.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;function S(e){{for(var o=arguments.length,c=new Array(o>1?o-1:0),b=1;b<o;b++)c[b-1]=arguments[b];W("error",e,c)}}function W(e,o,c){{var b=R.ReactDebugCurrentFrame,_=b.getStackAddendum();_!==""&&(o+="%s",c=c.concat([_]));var T=c.map(function(F){return String(F)});T.unshift("Warning: "+o),Function.prototype.apply.call(console[e],console,T)}}var re=!1,L=!1,G=!1,te=!1,P=!1,V;V=Symbol.for("react.module.reference");function j(e){return!!(typeof e=="string"||typeof e=="function"||e===s||e===i||P||e===n||e===h||e===v||te||e===p||re||L||G||typeof e=="object"&&e!==null&&(e.$$typeof===w||e.$$typeof===y||e.$$typeof===l||e.$$typeof===u||e.$$typeof===f||e.$$typeof===V||e.getModuleId!==void 0))}function A(e,o,c){var b=e.displayName;if(b)return b;var _=o.displayName||o.name||"";return _!==""?c+"("+_+")":c}function q(e){return e.displayName||"Context"}function x(e){if(e==null)return null;if(typeof e.tag=="number"&&S("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),typeof e=="function")return e.displayName||e.name||null;if(typeof e=="string")return e;switch(e){case s:return"Fragment";case a:return"Portal";case i:return"Profiler";case n:return"StrictMode";case h:return"Suspense";case v:return"SuspenseList"}if(typeof e=="object")switch(e.$$typeof){case u:var o=e;return q(o)+".Consumer";case l:var c=e;return q(c._context)+".Provider";case f:return A(e,e.render,"ForwardRef");case y:var b=e.displayName||null;return b!==null?b:x(e.type)||"Memo";case w:{var _=e,T=_._payload,F=_._init;try{return x(F(T))}catch{return null}}}return null}var H=Object.assign,le=0,X,Ee,Oe,fe,K,pe,U;function ne(){}ne.__reactDisabledLog=!0;function ke(){{if(le===0){X=console.log,Ee=console.info,Oe=console.warn,fe=console.error,K=console.group,pe=console.groupCollapsed,U=console.groupEnd;var e={configurable:!0,enumerable:!0,value:ne,writable:!0};Object.defineProperties(console,{info:e,log:e,warn:e,error:e,group:e,groupCollapsed:e,groupEnd:e})}le++}}function Ae(){{if(le--,le===0){var e={configurable:!0,enumerable:!0,writable:!0};Object.defineProperties(console,{log:H({},e,{value:X}),info:H({},e,{value:Ee}),warn:H({},e,{value:Oe}),error:H({},e,{value:fe}),group:H({},e,{value:K}),groupCollapsed:H({},e,{value:pe}),groupEnd:H({},e,{value:U})})}le<0&&S("disabledDepth fell below zero. This is a bug in React. Please file an issue.")}}var ce=R.ReactCurrentDispatcher,ae;function se(e,o,c){{if(ae===void 0)try{throw Error()}catch(_){var b=_.stack.trim().match(/\n( *(at )?)/);ae=b&&b[1]||""}return` `+ae+e}}var de=!1,oe;{var Me=typeof WeakMap=="function"?WeakMap:Map;oe=new Me}function Fe(e,o){if(!e||de)return"";{var c=oe.get(e);if(c!==void 0)return c}var b;de=!0;var _=Error.prepareStackTrace;Error.prepareStackTrace=void 0;var T;T=ce.current,ce.current=null,ke();try{if(o){var F=function(){throw Error()};if(Object.defineProperty(F.prototype,"props",{set:function(){throw Error()}}),typeof Reflect=="object"&&Reflect.construct){try{Reflect.construct(F,[])}catch(ie){b=ie}Reflect.construct(e,[],F)}else{try{F.call()}catch(ie){b=ie}e.call(F.prototype)}}else{try{throw Error()}catch(ie){b=ie}e()}}catch(ie){if(ie&&b&&typeof ie.stack=="string"){for(var C=ie.stack.split(` `),B=b.stack.split(` `),M=C.length-1,D=B.length-1;M>=1&&D>=0&&C[M]!==B[D];)D--;for(;M>=1&&D>=0;M--,D--)if(C[M]!==B[D]){if(M!==1||D!==1)do if(M--,D--,D<0||C[M]!==B[D]){var J=` `+C[M].replace(" at new "," at ");return e.displayName&&J.includes("<anonymous>")&&(J=J.replace("<anonymous>",e.displayName)),typeof e=="function"&&oe.set(e,J),J}while(M>=1&&D>=0);break}}}finally{de=!1,ce.current=T,Ae(),Error.prepareStackTrace=_}var Re=e?e.displayName||e.name:"",Sr=Re?se(Re):"";return typeof e=="function"&&oe.set(e,Sr),Sr}function Ne(e,o,c){return Fe(e,!1)}function he(e){var o=e.prototype;return!!(o&&o.isReactComponent)}function me(e,o,c){if(e==null)return"";if(typeof e=="function")return Fe(e,he(e));if(typeof e=="string")return se(e);switch(e){case h:return se("Suspense");case v:return se("SuspenseList")}if(typeof e=="object")switch(e.$$typeof){case f:return Ne(e.render);case y:return me(e.type,o,c);case w:{var b=e,_=b._payload,T=b._init;try{return me(T(_),o,c)}catch{}}}return""}var ve=Object.prototype.hasOwnProperty,_e={},je=R.ReactDebugCurrentFrame;function ge(e){if(e){var o=e._owner,c=me(e.type,e._source,o?o.type:null);je.setExtraStackFrame(c)}else je.setExtraStackFrame(null)}function d(e,o,c,b,_){{var T=Function.call.bind(ve);for(var F in e)if(T(e,F)){var C=void 0;try{if(typeof e[F]!="function"){var B=Error((b||"React class")+": "+c+" type `"+F+"` is invalid; it must be a function, usually from the `prop-types` package, but received `"+typeof e[F]+"`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");throw B.name="Invariant Violation",B}C=e[F](o,F,b,c,null,"SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED")}catch(M){C=M}C&&!(C instanceof Error)&&(ge(_),S("%s: type specification of %s `%s` is invalid; the type checker function must return `null` or an `Error` but returned a %s. You may have forgotten to pass an argument to the type checker creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and shape all require an argument).",b||"React class",c,F,typeof C),ge(null)),C instanceof Error&&!(C.message in _e)&&(_e[C.message]=!0,ge(_),S("Failed %s type: %s",c,C.message),ge(null))}}}var E=Array.isArray;function g(e){return E(e)}function O(e){{var o=typeof Symbol=="function"&&Symbol.toStringTag,c=o&&e[Symbol.toStringTag]||e.constructor.name||"Object";return c}}function $(e){try{return Y(e),!1}catch{return!0}}function Y(e){return""+e}function be(e){if($(e))return S("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.",O(e)),Y(e)}var Z=R.ReactCurrentOwner,Kr={key:!0,ref:!0,__self:!0,__source:!0},vr,gr,Ye;Ye={};function Jr(e){if(ve.call(e,"ref")){var o=Object.getOwnPropertyDescriptor(e,"ref").get;if(o&&o.isReactWarning)return!1}return e.ref!==void 0}function zr(e){if(ve.call(e,"key")){var o=Object.getOwnPropertyDescriptor(e,"key").get;if(o&&o.isReactWarning)return!1}return e.key!==void 0}function Gr(e,o){if(typeof e.ref=="string"&&Z.current&&o&&Z.current.stateNode!==o){var c=x(Z.current.type);Ye[c]||(S('Component "%s" contains the string ref "%s". Support for string refs will be removed in a future major release. This case cannot be automatically converted to an arrow function. We ask you to manually fix this case by using useRef() or createRef() instead. Learn more about using refs safely here: https://reactjs.org/link/strict-mode-string-ref',x(Z.current.type),e.ref),Ye[c]=!0)}}function Xr(e,o){{var c=function(){vr||(vr=!0,S("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",o))};c.isReactWarning=!0,Object.defineProperty(e,"key",{get:c,configurable:!0})}}function Zr(e,o){{var c=function(){gr||(gr=!0,S("%s: `ref` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",o))};c.isReactWarning=!0,Object.defineProperty(e,"ref",{get:c,configurable:!0})}}var Qr=function(e,o,c,b,_,T,F){var C={$$typeof:t,type:e,key:o,ref:c,props:F,_owner:T};return C._store={},Object.defineProperty(C._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:!1}),Object.defineProperty(C,"_self",{configurable:!1,enumerable:!1,writable:!1,value:b}),Object.defineProperty(C,"_source",{configurable:!1,enumerable:!1,writable:!1,value:_}),Object.freeze&&(Object.freeze(C.props),Object.freeze(C)),C};function et(e,o,c,b,_){{var T,F={},C=null,B=null;c!==void 0&&(be(c),C=""+c),zr(o)&&(be(o.key),C=""+o.key),Jr(o)&&(B=o.ref,Gr(o,_));for(T in o)ve.call(o,T)&&!Kr.hasOwnProperty(T)&&(F[T]=o[T]);if(e&&e.defaultProps){var M=e.defaultProps;for(T in M)F[T]===void 0&&(F[T]=M[T])}if(C||B){var D=typeof e=="function"?e.displayName||e.name||"Unknown":e;C&&Xr(F,D),B&&Zr(F,D)}return Qr(e,C,B,_,b,Z.current,F)}}var Be=R.ReactCurrentOwner,br=R.ReactDebugCurrentFrame;function ye(e){if(e){var o=e._owner,c=me(e.type,e._source,o?o.type:null);br.setExtraStackFrame(c)}else br.setExtraStackFrame(null)}var Ue;Ue=!1;function qe(e){return typeof e=="object"&&e!==null&&e.$$typeof===t}function Er(){{if(Be.current){var e=x(Be.current.type);if(e)return` Check the render method of \``+e+"`."}return""}}function rt(e){{if(e!==void 0){var o=e.fileName.replace(/^.*[\\\/]/,""),c=e.lineNumber;return` Check your code at `+o+":"+c+"."}return""}}var pr={};function tt(e){{var o=Er();if(!o){var c=typeof e=="string"?e:e.displayName||e.name;c&&(o=` Check the top-level render call using <`+c+">.")}return o}}function hr(e,o){{if(!e._store||e._store.validated||e.key!=null)return;e._store.validated=!0;var c=tt(o);if(pr[c])return;pr[c]=!0;var b="";e&&e._owner&&e._owner!==Be.current&&(b=" It was passed a child from "+x(e._owner.type)+"."),ye(e),S('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.',c,b),ye(null)}}function yr(e,o){{if(typeof e!="object")return;if(g(e))for(var c=0;c<e.length;c++){var b=e[c];qe(b)&&hr(b,o)}else if(qe(e))e._store&&(e._store.validated=!0);else if(e){var _=I(e);if(typeof _=="function"&&_!==e.entries)for(var T=_.call(e),F;!(F=T.next()).done;)qe(F.value)&&hr(F.value,o)}}}function nt(e){{var o=e.type;if(o==null||typeof o=="string")return;var c;if(typeof o=="function")c=o.propTypes;else if(typeof o=="object"&&(o.$$typeof===f||o.$$typeof===y))c=o.propTypes;else return;if(c){var b=x(o);d(c,e.props,"prop",b,e)}else if(o.PropTypes!==void 0&&!Ue){Ue=!0;var _=x(o);S("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?",_||"Unknown")}typeof o.getDefaultProps=="function"&&!o.getDefaultProps.isReactClassApproved&&S("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.")}}function at(e){{for(var o=Object.keys(e.props),c=0;c<o.length;c++){var b=o[c];if(b!=="children"&&b!=="key"){ye(e),S("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.",b),ye(null);break}}e.ref!==null&&(ye(e),S("Invalid attribute `ref` supplied to `React.Fragment`."),ye(null))}}function Rr(e,o,c,b,_,T){{var F=j(e);if(!F){var C="";(e===void 0||typeof e=="object"&&e!==null&&Object.keys(e).length===0)&&(C+=" You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.");var B=rt(_);B?C+=B:C+=Er();var M;e===null?M="null":g(e)?M="array":e!==void 0&&e.$$typeof===t?(M="<"+(x(e.type)||"Unknown")+" />",C=" Did you accidentally export a JSX literal instead of a component?"):M=typeof e,S("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s",M,C)}var D=et(e,o,c,_,T);if(D==null)return D;if(F){var J=o.children;if(J!==void 0)if(b)if(g(J)){for(var Re=0;Re<J.length;Re++)yr(J[Re],e);Object.freeze&&Object.freeze(J)}else S("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");else yr(J,e)}return e===s?at(D):nt(D),D}}function st(e,o,c){return Rr(e,o,c,!0)}function ot(e,o,c){return Rr(e,o,c,!1)}var it=ot,ut=st;Te.Fragment=s,Te.jsx=it,Te.jsxs=ut}()),Te}process.env.NODE_ENV==="production"?He.exports=lt():He.exports=ct();var Se=He.exports;const Q={all:{},global:{},manual:{},native:{},validator:{}},Ke={changedFields:new Set,isSubmitting:!1,isValid:!0,isValidating:!1,submitCount:0,touchedFields:new Set},nr=Symbol.for("rsf-default"),ee=m.createContext({errors:Q,form:{current:null},mode:"submit",onChange:()=>()=>null,onError:()=>()=>null,onReset:()=>()=>null,onSubmit:()=>()=>null,register(){},reset:()=>null,revalidateMode:"submit",states:{...Ke,changedFields:[],dirtyFields:[],isChanged:!1,isDirty:!1,isPristine:!0,isReady:!1,isSubmitted:!1,isTouched:!1,isValid:!0,touchedFields:[]},subscribe(){return()=>{}},unregister(){},useNativeValidation:!0,validate(){return Promise.resolve([!0,Q])},watch:()=>()=>null});function Le(r,t){return r.filter(a=>t.includes(a))}function ar(r){return r instanceof Object&&"id"in r}function Je(r){return r instanceof Object&&!ar(r)&&"error"in r}function Fr(r,t){const a=t.split("."),{length:s}=a;let n=0,i=r;for(;typeof i=="object"&&i!=null&&n<s;)i=i[a[n++]];return n&&n===s?i:void 0}function Pe(r,t,a=!1){return!Array.from(new Set(Object.keys(r).concat(Object.keys(t)))).some(n=>typeof r[n]!=typeof t[n]?!0:!a||r[n]===null||typeof r[n]!="object"?r[n]!==t[n]:!Pe(r[n],t[n],a))}function ue(r,t){return Object.fromEntries(Object.entries(r).filter(t))}function Ie(r){return typeof r=="function"}function _r(r){return!!(r&&"names"in r&&r.names instanceof Array&&"validator"in r&&typeof r.validator=="function")}function $e(r){return"setErrors"in r}function jr(r){if(!r)return null;for(const t in r)if(t!=="customError"&&t!=="valid"&&r[t])return t;return null}function We(r){const{form:t,names:a,transformers:s={},values:n={}}=r,i=new FormData(t),l=new Map(Ce(t).map(h=>(h=z(h),[h.name,h])));return Array.from(new Set(Object.keys(n).concat(Array.from(i.keys())))).filter(h=>!a||a.includes(h)).reduce((h,v)=>{if(n[v]!==void 0)h[v]=n[v];else{const y=l.get(v);h[v]=y?dr(y):i.get(v)}return s[v]&&(h[v]=s[v](h[v])),h},{})}function wr(r,t={}){const a=Object.fromEntries(r.reduce((s,n)=>{if(n.messages)for(const i of n.names)s.push([i,n.messages]);return s},[]));return a[nr]=t,a}function De(r,t){return t?ue(r,([a])=>t.includes(a)):r}function xe(r){const t=Object.entries(r.native).find(([,a])=>a);if(t)r.main={error:t[1],global:!1,id:t[0],names:[t[0]]};else{const a=Object.entries(r.manual).find(([,s])=>s);if(a)r.main={error:a[1]??"",global:!1,id:a[0],names:[a[0]]};else{const s=Object.entries(r.validator).find(([,{error:n}])=>n);if(s)r.main={error:s[1].error,global:s[1].global,id:s[0],names:s[1].names};else{const n=Object.entries(r.global).find(([,{error:i}])=>i);n&&(r.main={error:n[1].error,global:n[1].global,id:n[0],names:n[1].names})}}}return r.main}function Tr(r,t){const a=new Set;for(const s of r){const{id:n,names:i}=s;(!t||Le(t,i).length>0)&&a.add(n)}return[...a]}function sr(r,t,a={}){const s=Object.values(t).reduce((n,{error:i,names:l})=>{for(const u of l)n[u]||(n[u]=i);return n},{});for(const[n,i]of Object.entries(a))(i||!s[n])&&(s[n]=i??"");for(const[n,i]of Object.entries(r))(i||!s[n])&&(s[n]=i);return s}function or(r){const{global:t=!0,ids:a,manualErrors:s={},names:n,nativeErrors:i,validatorErrors:l}=r,u=De(i,n),f=De(l,a),h=De(s,n),v={all:sr(u,f,h),global:t?ue(f,([,{global:y}])=>y):{},manual:h,native:u,validator:f};return xe(v),v}function ze(r,t){const{global:a,validator:s}=t,n={...r.native,...t.native},i={...r.manual,...t.manual},u={all:sr(n,s,i),global:a,manual:i,native:n,validator:s};return xe(u),u}function Ge(r){return!!r.main}function ir(r,t={},a={}){return r?t[r]?t[r]:a[r]??r:""}function Vr(r){const{defaultMessages:t={},input:a,messages:s={}}=r,n=z(a);n.setCustomValidity("");const{validity:i}=n,l=jr(i);if(l){const u=s[l]??t[l];return u&&n.setCustomValidity(u),u??n.validationMessage}return""}function Pr(r){const{fieldMessages:t,form:a}=r;return Ce(a).reduce((n,i)=>{const l=z(i).name??"";return n[l]=Vr({defaultMessages:t[nr],input:i,messages:t[l]}),n},{})}function xr(r){const{errors:t={},fieldMessages:a={},form:s}=r,n=Object.fromEntries(Object.entries(t).map(([i,l])=>[i,ir(l,a[i]??a[nr])]));for(const[i,l]of Object.entries(n)){const u=z(s.elements[i]);u&&l&&!u.validationMessage&&u.setCustomValidity(l)}return n}function kr(r){const{form:t,transformers:a={},validators:s=[],values:n={}}=r,i=s.map(l=>{const{names:u,validator:f}=l;return f?f(We({form:t,names:u,transformers:a,values:n}),u):""});return Promise.all(Object.values(i))}function Ar(r){const{defaultMessages:t={},form:a,validatorResults:s,validators:n}=r,i={};return s.forEach((l,u)=>{const{id:f,messages:h,names:v}=n[u];if(l){const y=ir(l,h,t);for(const w of v){const p=z(a.elements[w]);p&&y&&!p.validationMessage&&p.setCustomValidity(y)}i[f]={error:y,global:!$e(n[u]),names:v}}}),i}function Xe(r,t){if(t){const a=r.find(s=>t.names.includes(z(s).name));if(a)return z(a).focus(),!0}return!1}function Mr(r){const{display:t,errors:a,filterLocalErrors:s,focusOnError:n,form:i,localFields:l={},names:u,revalidate:f,setErrors:h,useNativeValidation:v,validators:y}=r;if(!t&&!f)return;const{all:w,global:p,manual:k,native:N,validator:I}=a,R=Ce(i);let S=!1;function W(){return S}function re(P){S=P}if(v){if(!u)t&&i.reportValidity();else if(a.main&&(t||f)){const P=a.main.names[0];z(i.elements[P]).reportValidity()}return}const L=new Set;for(const P of Object.keys(l))L.add(P);const G=Array.from(L),te=new Map;for(const P of y)if(!(u&&Le(u,P.names).length===0))if($e(P)){const{id:V,names:j,setErrors:A,validator:q}=P;if(!q)te.set(A,or({global:!1,ids:[V],manualErrors:k,names:j,nativeErrors:N,validatorErrors:I}));else if(I[V]){const x=te.get(A);x&&(x.validator={...x==null?void 0:x.validator,[V]:I[V]})}}else{const{id:V,names:j}=P;for(const A of j){const q=l[A];if(q){const x=te.get(q);x&&I[V]&&(x.validator={...x==null?void 0:x.validator,[V]:I[V]})}}}for(const[P,V]of te)xe(V),P(j=>{if(t||f&&Ge(j)){n&&!W()&&re(Xe(R,V.main));const A=ze(j,V);return A.main?Pe(A,j,!0)?j:A:Q}return j});h(P=>{if(t||f&&Ge(P)){let V=a;s&&(V={all:ue(w,([A])=>!G.includes(A)),global:p,manual:ue(k,([A])=>!G.includes(A)),native:ue(N,([A])=>!G.includes(A)),validator:ue(I,([,{names:A}])=>Le(G,A).length!==A.length)},xe(V)),n&&!W()&&re(Xe(R,V.main));const j=ze(P,V);return j.main?Pe(j,P,!0)?P:j:Q}return P})}async function Nr(r){const{display:t,errors:a={},filterLocalErrors:s,focusOnError:n,form:i,localFields:l,messages:u,names:f,revalidate:h,setErrors:v,transformers:y={},useNativeValidation:w,validators:p,values:k={}}=r,N=wr(p,u),I=await kr({form:i,transformers:y,validators:p,values:k}),R=Pr({fieldMessages:N,form:i}),S=xr({errors:a,fieldMessages:N,form:i}),W=Ar({defaultMessages:u,form:i,validatorResults:I,validators:p}),re=Tr(p,f),L=or({ids:re,manualErrors:S,names:f,nativeErrors:R,validatorErrors:W});return Mr({display:t,errors:L,filterLocalErrors:s,focusOnError:n,form:i,localFields:l,names:f,revalidate:h,setErrors:v,useNativeValidation:w,validators:p}),L}function ur(r){return r instanceof HTMLInputElement||r instanceof HTMLSelectElement||r instanceof HTMLTextAreaElement||r instanceof RadioNodeList}function z(r){return r instanceof RadioNodeList?r[0]:r}const ft=["submit","reset"];function Ce(r){return[...r.elements].filter(t=>ur(t)&&t.name&&!ft.includes(t.type))}function Ir(r){const t={};for(const a of r.values()){const{setErrors:s}=a;for(const n of a.names)t[n]=s}return t}function Ze(r,t,a){const s=[];for(const n of r.values()){const{defaultValues:i,onBlurOptOut:l,onChangeOptOut:u,setErrors:f,transformers:h,validators:v,...y}=n;if(s.push({...y,setErrors:f}),Ie(v))s.push({...y,setErrors:f,validator:v});else if(_r(v)){const{names:w,validator:p}=v;s.push({...y,names:w,setErrors:f,validator:p})}else if(typeof v=="object")for(const[w,p]of Object.entries(v))if(Ie(p))s.push({...y,id:w,names:[w],setErrors:f,validator:p});else{const{names:k,validator:N}=p;s.push({...y,id:w,names:k,setErrors:f,validator:N})}}if(t)for(const[n,i]of Object.entries(t))if(Ie(i))s.push({id:n,messages:a,names:[n],validator:i});else{const{names:l,validator:u}=i;s.push({id:n,messages:a,names:l,validator:u})}return s}function lr(r){return typeof r=="object"&&r!==null&&"target"in r}function cr(r){return"type"in r&&r.type==="checkbox"}function Qe(r){return r.type==="file"}function Dr(r){return r.tagName==="SELECT"}const dt=["INPUT","SELECT","TEXTAREA"];function fr(r){return!!("tagName"in r&&dt.includes(r.tagName))}function er(r){return lr(r)&&r.target&&fr(r.target)?r.target.name:null}function dr(r){if("multiple"in r&&r.multiple){if(r.type==="email")return String(r.value).split(",").map(t=>t.trim());if(Qe(r)&&r.files)return[...r.files];if(Dr(r))return[...r.options].filter(t=>t.selected).map(t=>t.value)}else if(Qe(r)&&r.files)return r.files[0];return r.value}function Lr(r,t){let a=r;return lr(r)&&r.target&&(cr(r.target)?a=r.target.checked:fr(r.target)&&(a=dr(r.target))),t?t(a):a}function Wr(r,t,a){return!t||a==="all"||a===t||a instanceof Array&&a.includes(t)?!1:![...r].some(({onChangeOptOut:s})=>s===t||s instanceof Array&&s.includes(t))}function $r(r,t,a){return!t||a==="all"||a===t||a instanceof Array&&a.includes(t)?!1:![...r].some(({onBlurOptOut:s})=>s===t||s instanceof Array&&s.includes(t))}function Ve(r,t){return[...r].reduce((a,{transformers:s})=>({...a,...s}),t)}function Yr(r,t,a,s){return{...[...r].reduce((i,{defaultValues:l})=>({...i,...l}),t),...a,...s}}function rr(r,t,a,s){let n={};s&&(n=Object.fromEntries(Ce(s).map(f=>[z(f).name,z(f).getAttribute("value")])));const i=Array.from(r.changedFields),l=i.filter(f=>a[f]!==void 0?t[f]!==a[f]:n[f]!=null?t[f]!==n[f]:t[f]!==""),u=Array.from(r.touchedFields);return{...r,changedFields:i,dirtyFields:l,isChanged:i.length>0,isDirty:l.length>0,isPristine:l.length===0,isSubmitted:r.submitCount>0,isTouched:u.length>0,touchedFields:u}}function tr(r,t){const a=t instanceof Array?t:[t],s=r.changedFields.filter(l=>a.includes(l)),n=r.dirtyFields.filter(l=>a.includes(l)),i=r.touchedFields.filter(l=>a.includes(l));return{...r,changedFields:s,dirtyFields:n,isChanged:s.length>0,isDirty:n.length>0,isPristine:n.length===0,isSubmitted:r.submitCount>0,isTouched:i.length>0,touchedFields:i}}function mt(r){const{Component:t="div",errorPath:a="main",global:s,...n}=r,{errors:i}=m.useContext(ee),l=Fr(i,a);if(!l)return null;let u;if(typeof l=="string"&&!s)u=l;else if((ar(l)||Je(l))&&(!s||l.global))u=l.error;else{const f=Object.values(l)[0];typeof f=="string"&&!s?u=f:Je(f)&&(!s||f.global)&&(u=f.error)}return u?Se.jsx(t,{"data-testid":"rsf-error",...n,children:u}):null}function Br(r={}){const{defaultValues:t,errorCallback:a=console.error,filterLocalErrors:s=!0,focusOnError:n=!0,form:i=null,messages:l,mode:u="submit",onBlurOptOut:f,onChangeOptOut:h,onReset:v,onSubmit:y,onSubmitError:w,revalidateMode:p="submit",transformers:k,useNativeValidation:N=!0,validators:I}=r,R=m.useRef(i),S=m.useRef(new Set),W=m.useRef(t??{}),re=m.useRef({}),L=m.useRef({}),G=m.useRef(null),te=m.useRef({}),P=m.useRef({}),V=m.useRef({}),j=m.useRef({...Ke,changedFields:new Set,isReady:!1,touchedFields:new Set}),A=m.useRef(Q),[q,x]=m.useState(Q),H=m.useRef(new Set),le=m.useCallback(d=>(H.current.has(d)||H.current.add(d),()=>H.current.delete(d)),[]),X=m.useCallback(()=>{for(const d of H.current.values())d(rr(j.current,L.current,W.current,R.current))},[]),Ee=m.useRef(new Map),Oe=m.useCallback((d,E)=>{const g=E===void 0||E instanceof Array?E:[E];return Ee.current.set(d,g),()=>Ee.current.delete(d)},[]),fe=m.useCallback(()=>{if(R.current){const d=We({form:R.current,transformers:Ve(S.current,k),values:L.current});for(const[E,g]of Ee.current.entries()){const O=ue(d,([Y])=>!g||g.includes(Y)),$=ue(re.current,([Y])=>!g||g.includes(Y));E({names:g,prevValues:$,values:O})}re.current={...d}}},[k]),K=m.useCallback(async(d=!1,E=!1,g=!1,O)=>{var Y;if(!R.current)return[!1,Q];j.current.isValidating=!0,X();let $;try{const be=Ir(S.current),Z=Ze(S.current,I,l);$=await Nr({display:d,errors:te.current,filterLocalErrors:s,focusOnError:g,form:R.current,localFields:be,messages:l,names:O instanceof Array?O:O?[O]:void 0,revalidate:E,setErrors:x,transformers:Ve(S.current,k),useNativeValidation:N,validators:Z,values:L.current})}finally{j.current.isValidating=!1,j.current.isValid=!!((Y=R.current)!=null&&Y.checkValidity()),X()}return[j.current.isValid,$]},[s,l,X,N,k,I]),pe=m.useRef(),U=m.useCallback((d,E,g,O)=>{clearTimeout(pe.current),pe.current=setTimeout(()=>void K(d,E,g,O),0)},[K]);m.useEffect(()=>()=>clearTimeout(pe.current),[]);const ne=m.useCallback(d=>{if(R.current){for(const E of Ce(R.current)){const g=z(E),{name:O}=g;O&&d[O]!==void 0&&d[O]!==null&&(cr(g)?g.checked=!!d[O]:g.value=String(d[O]))}fe()}},[fe]),ke=m.useCallback(d=>{S.current.add(d),d.defaultValues&&(W.current={...W.current,...d.defaultValues},ne(d.defaultValues)),U()},[U,ne]),Ae=m.useCallback(d=>{S.current.delete(d),U()},[U]),ce=m.useCallback(d=>{x(Q);const E=Ze(S.current,I,l);for(const g of E)$e(g)&&g.setErrors(Q);j.current={...Ke,changedFields:new Set,isReady:j.current.isReady,touchedFields:new Set},L.current={},W.current=Yr(S.current,t,d,G.current),G.current=null;for(const g of Object.values(V.current))g();setTimeout(()=>{ne(W.current),U()})},[U,t,l,ne,I]),ae=m.useCallback(d=>{var E;G.current=d,(E=R.current)==null||E.reset()},[]),se=m.useCallback((d,E)=>{const g=er(d)??E;if(!g)throw new Error("react-swift-form was unable to retrieve the field name");j.current.changedFields.add(g);const O=Ve(S.current,k),$=Lr(d,O==null?void 0:O[g]);return L.current[g]=$,fe(),U(u==="all"||u==="change",p==="change",!1,g),[g,$]},[U,u,p,k,fe]);let de=!1;const oe=m.useCallback(async(d,E,g)=>{if(!de){d.preventDefault();try{j.current.isSubmitting=!0;const[O,$]=await K(!0,!1,n);O&&R.current?(R.current.getAttribute("action")!==null&&(de=!0,setTimeout(()=>{var Y;(Y=R.current)==null||Y.requestSubmit(),de=!1})),E&&await E(d,We({form:R.current,transformers:Ve(S.current,k),values:L.current}),ae)):g&&await g(d,$,ae)}catch(O){a(O)}finally{j.current.isSubmitting=!1,j.current.submitCount++,X()}}},[n,ae,k,K]),Me=m.useCallback(d=>{const E=er(d);E&&P.current[E]?P.current[E]=!1:Wr(S.current,E,h)&&se(d)},[se,h]),Fe=m.useCallback(d=>{const E=v==null?void 0:v(d,L.current);ce(E)},[v,ce]),Ne=m.useCallback(d=>oe(d,y,w),[y,w,oe]);m.useEffect(()=>{W.current={...W.current,...t};for(const d of Object.values(V.current))d();ne(W.current)},[t,ne]),m.useEffect(()=>{if(A.current!==q){A.current=q;return}K().then(()=>{R.current&&(j.current.isReady=!0,X(),R.current.dataset.rsf="init")})}),m.useEffect(()=>{if(R.current){const d=R.current,E=g=>{g.target&&ur(g.target)&&(j.current.touchedFields.add(g.target.name),(u==="all"||u==="blur"||p==="blur")&&$r(S.current,g.target.name,f)?K(u==="all"||u==="blur",p==="blur",!1,g.target.name):X())};return d.addEventListener("focusout",E),()=>d.removeEventListener("focusout",E)}},[u,f,p,X,K]);const he=m.useCallback(d=>E=>{te.current[d]=E,U(u==="all"||u==="change",p==="change",!1,d)},[U,u,p]),me=m.useCallback((d,E={})=>{const{getError:g,name:O}=E;if(O){const $=()=>{L.current[O]===void 0&&W.current[O]!==void 0&&(L.current[O]=W.current[O])};V.current[O]=$,$()}return($,...Y)=>{const[be,Z]=se($,O);P.current[be]=!0,g&&he(be)(g(Z,...Y)),d(Z,...Y)}},[se,he]),ve=m.useCallback(d=>E=>{const g=d==null?void 0:d(E,L.current);ce(g)},[ce]),_e=m.useCallback((d,E)=>async g=>oe(g,d,E),[oe]),je=m.useCallback((d,E)=>Oe(({prevValues:g,values:O})=>{Pe(O,g)||d(O)},E),[Oe]),ge=m.useMemo(()=>({noValidate:!N,onChange:Me,onReset:Fe,onSubmit:Ne,ref:R}),[Me,Fe,Ne,N]);return m.useMemo(()=>({errors:q,form:R,formProps:ge,messages:l,mode:u,onChange:me,onError:he,onReset:ve,onSubmit:_e,register:ke,reset:ae,revalidateMode:p,states:rr(j.current,L.current,W.current,R.current),subscribe:le,unregister:Ae,useNativeValidation:N,validate:K,watch:je}),[q,ge,l,u,me,he,ve,_e,ke,ae,p,le,Ae,N,K,je])}function vt(){return m.useContext(ee)}function gt(){const{errors:r}=m.useContext(ee);return r}function mr(r){const{subscribe:t}=m.useContext(ee);m.useEffect(()=>t(r),[t])}function bt(r){const{states:t}=m.useContext(ee),[a,s]=m.useState(r?tr(t,r):t);return mr(n=>s(r?tr(n,r):n)),a}function Ur(){const{states:r}=m.useContext(ee),[t,a]=m.useState(r.isValid);return mr(({isValid:s})=>a(s)),t}function qr(r){const{defaultValues:t,id:a,messages:s,names:n,onBlurOptOut:i,onChangeOptOut:l,transformers:u,validators:f}=r,{onChange:h,onError:v,onReset:y,onSubmit:w,register:p,unregister:k,watch:N}=m.useContext(ee),[I,R]=m.useState(Q);return m.useEffect(()=>{const S={defaultValues:t,id:a??String(n),messages:s,names:n,onBlurOptOut:i,onChangeOptOut:l,setErrors:R,transformers:u,validators:f};return p(S),()=>k(S)},[t,a,s,n,i,l,p,u,k,f]),{error:I.main,errors:I,onChange:h,onError:v,onReset:y,onSubmit:w,watch:N}}function Et(r){const{defaultValue:t,id:a,messages:s,name:n,onBlurOptOut:i,onChangeOptOut:l,transformer:u,validator:f}=r,h=m.useMemo(()=>[n],[n]),v=m.useMemo(()=>t!==void 0?{[n]:t}:void 0,[t,n]),y=m.useMemo(()=>u!==void 0?{[n]:u}:void 0,[n,u]),{errors:w,...p}=qr({defaultValues:v,id:a??n,messages:s,names:h,onBlurOptOut:i?n:void 0,onChangeOptOut:l?n:void 0,transformers:y,validators:f});return{...p,error:w.main,errors:w}}function pt(r){const[t,a]=m.useState({}),{watch:s}=m.useContext(ee);return m.useEffect(()=>s(a,r),[r,s]),t}function Hr(r){const{children:t,...a}=r;return Se.jsx(ee.Provider,{value:a,children:t})}function ht(r){const{children:t,defaultValues:a,filterLocalErrors:s,messages:n,mode:i,onBlurOptOut:l,onChangeOptOut:u,onReset:f,onSubmit:h,onSubmitError:v,revalidateMode:y,transformers:w,useNativeValidation:p=!0,validators:k,...N}=r,{formProps:I,...R}=Br({defaultValues:a,filterLocalErrors:s,messages:n,mode:i,onBlurOptOut:l,onChangeOptOut:u,onReset:f,onSubmit:h,onSubmitError:v,revalidateMode:y,transformers:w,useNativeValidation:p,validators:k});return Se.jsx(Hr,{...R,children:Se.jsx("form",{"data-testid":"rsf-form",...N,...I,children:typeof t=="function"?t(R):t})})}function yt(r){const{...t}=r;return Se.jsx("input",{"data-testid":"rsf-reset",type:"reset",...t})}function Rt(r){const{disableOnError:t,...a}=r,s=Ur();return Se.jsx("input",{"data-testid":"rsf-submit",disabled:t?!s:!1,type:"submit",...a})}exports.Error=mt;exports.Form=ht;exports.FormProvider=Hr;exports.Reset=yt;exports.Submit=Rt;exports.areObjectEquals=Pe;exports.displayErrors=Mr;exports.filterObject=ue;exports.focusError=Xe;exports.formContext=ee;exports.getAllError=sr;exports.getCustomMessage=ir;exports.getData=We;exports.getDefaultValues=Yr;exports.getErrorObject=or;exports.getFieldMessages=wr;exports.getFieldStates=tr;exports.getFilteredErrors=De;exports.getFormInput=z;exports.getFormInputs=Ce;exports.getFormStates=rr;exports.getInputValue=dr;exports.getLocalFields=Ir;exports.getManualError=xr;exports.getName=er;exports.getNativeError=Vr;exports.getNativeErrorKey=jr;exports.getNativeErrors=Pr;exports.getProperty=Fr;exports.getTransformers=Ve;exports.getValidatorError=kr;exports.getValidatorIds=Tr;exports.getValidators=Ze;exports.getValue=Lr;exports.hasError=Ge;exports.intersection=Le;exports.isCheckbox=cr;exports.isEvent=lr;exports.isField=fr;exports.isFileInput=Qe;exports.isFormElement=ur;exports.isLocalValidator=$e;exports.isMainError=ar;exports.isSelect=Dr;exports.isValidator=Ie;exports.isValidatorError=Je;exports.isValidatorObject=_r;exports.mergeErrors=ze;exports.setMainError=xe;exports.setValidatorError=Ar;exports.shouldBlur=$r;exports.shouldChange=Wr;exports.useForm=Br;exports.useFormContext=vt;exports.useFormErrors=gt;exports.useFormStates=bt;exports.useFormValid=Ur;exports.useInput=Et;exports.useInputs=qr;exports.useSubscribe=mr;exports.useWatch=pt;exports.validateForm=Nr; //# sourceMappingURL=index.cjs.map