remix-validated-form 4.4.2 → 4.4.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,95 @@
1
+ $ tsc --module ESNext --outDir ./browser --watch
2
+ c10:51:22 PM - Starting compilation in watch mode...
3
+
4
+
5
+ 10:51:23 PM - Found 0 errors. Watching for file changes.
6
+ c10:58:01 PM - File change detected. Starting incremental compilation...
7
+
8
+ src/internal/hooks.ts(149,23): error TS2304: Cannot find name 'formId'.
9
+ src/internal/hooks.ts(151,41): error TS2304: Cannot find name 'defaultDefaultValues'.
10
+ src/unreleased/formStateHooks.ts(18,3): error TS2724: '"../internal/hooks"' has no exported member named 'useSyncedDefaultValues'. Did you mean 'useFieldDefaultValue'?
11
+
12
+ 10:58:02 PM - Found 3 errors. Watching for file changes.
13
+ c10:58:40 PM - File change detected. Starting incremental compilation...
14
+
15
+ src/internal/hooks.ts(156,23): error TS2304: Cannot find name 'formId'.
16
+
17
+ 10:58:40 PM - Found 1 error. Watching for file changes.
18
+ c10:59:28 PM - File change detected. Starting incremental compilation...
19
+
20
+
21
+ 10:59:28 PM - Found 0 errors. Watching for file changes.
22
+ c11:00:16 PM - File change detected. Starting incremental compilation...
23
+
24
+ src/internal/hooks.ts(160,4): error TS1005: ',' expected.
25
+ src/internal/hooks.ts(161,1): error TS1128: Declaration or statement expected.
26
+
27
+ 11:00:16 PM - Found 2 errors. Watching for file changes.
28
+ c11:01:07 PM - File change detected. Starting incremental compilation...
29
+
30
+
31
+ 11:01:07 PM - Found 0 errors. Watching for file changes.
32
+ c11:01:30 PM - File change detected. Starting incremental compilation...
33
+
34
+
35
+ 11:01:30 PM - Found 0 errors. Watching for file changes.
36
+ c11:01:50 PM - File change detected. Starting incremental compilation...
37
+
38
+
39
+ 11:01:50 PM - Found 0 errors. Watching for file changes.
40
+ c11:02:06 PM - File change detected. Starting incremental compilation...
41
+
42
+
43
+ 11:02:06 PM - Found 0 errors. Watching for file changes.
44
+ c11:04:31 PM - File change detected. Starting incremental compilation...
45
+
46
+
47
+ 11:04:31 PM - Found 0 errors. Watching for file changes.
48
+ c11:05:28 PM - File change detected. Starting incremental compilation...
49
+
50
+
51
+ 11:05:28 PM - Found 0 errors. Watching for file changes.
52
+ c11:05:52 PM - File change detected. Starting incremental compilation...
53
+
54
+
55
+ 11:05:52 PM - Found 0 errors. Watching for file changes.
56
+ c11:06:11 PM - File change detected. Starting incremental compilation...
57
+
58
+
59
+ 11:06:11 PM - Found 0 errors. Watching for file changes.
60
+ c11:06:33 PM - File change detected. Starting incremental compilation...
61
+
62
+
63
+ 11:06:33 PM - Found 0 errors. Watching for file changes.
64
+ c11:06:48 PM - File change detected. Starting incremental compilation...
65
+
66
+
67
+ 11:06:48 PM - Found 0 errors. Watching for file changes.
68
+ c11:08:57 PM - File change detected. Starting incremental compilation...
69
+
70
+ src/internal/hooks.ts(114,25): error TS2304: Cannot find name 'useCorrectDefaultValues'.
71
+ src/unreleased/formStateHooks.ts(19,3): error TS2305: Module '"../internal/hooks"' has no exported member 'useCorrectDefaultValues'.
72
+
73
+ 11:08:57 PM - Found 2 errors. Watching for file changes.
74
+ c11:09:06 PM - File change detected. Starting incremental compilation...
75
+
76
+ src/unreleased/formStateHooks.ts(19,3): error TS2305: Module '"../internal/hooks"' has no exported member 'useCorrectDefaultValues'.
77
+
78
+ 11:09:06 PM - Found 1 error. Watching for file changes.
79
+ c11:09:19 PM - File change detected. Starting incremental compilation...
80
+
81
+ src/unreleased/formStateHooks.ts(48,49): error TS2345: Argument of type 'string | symbol' is not assignable to parameter of type 'InternalFormContextValue'.
82
+ Type 'string' is not assignable to type 'InternalFormContextValue'.
83
+
84
+ 11:09:19 PM - Found 1 error. Watching for file changes.
85
+ c11:09:34 PM - File change detected. Starting incremental compilation...
86
+
87
+ src/unreleased/formStateHooks.ts(48,49): error TS2345: Argument of type 'string | symbol' is not assignable to parameter of type 'InternalFormContextValue'.
88
+ Type 'string' is not assignable to type 'InternalFormContextValue'.
89
+
90
+ 11:09:34 PM - Found 1 error. Watching for file changes.
91
+ c11:09:38 PM - File change detected. Starting incremental compilation...
92
+
93
+
94
+ 11:09:38 PM - Found 0 errors. Watching for file changes.
95
+ c11:11:35 PM - File change detected. Starting incremental compilat
@@ -20,9 +20,7 @@ export declare const useInternalHasBeenSubmitted: (formId: InternalFormId) => bo
20
20
  export declare const useValidateField: (formId: InternalFormId) => (fieldName: string) => Promise<string | null>;
21
21
  export declare const useValidate: (formId: InternalFormId) => () => Promise<void>;
22
22
  export declare const useRegisterReceiveFocus: (formId: InternalFormId) => (fieldName: string, handler: () => void) => () => void;
23
- export declare const useSyncedDefaultValues: (formId: InternalFormId) => {
24
- [fieldName: string]: any;
25
- };
23
+ export declare const useSyncedDefaultValues: (formId: InternalFormId) => {};
26
24
  export declare const useSetTouched: ({ formId }: InternalFormContextValue) => (field: string, touched: boolean) => void;
27
25
  export declare const useTouchedFields: (formId: InternalFormId) => import("..").TouchedFields;
28
26
  export declare const useFieldErrors: (formId: InternalFormId) => FieldErrors;
@@ -1,4 +1,4 @@
1
- import { useCallback } from "react";
1
+ import { useCallback, useMemo } from "react";
2
2
  import { useInternalFormContext, useRegisterReceiveFocus, } from "./internal/hooks";
3
3
  import { useFormHelpers, useFormState } from "./unreleased/formStateHooks";
4
4
  /**
@@ -15,7 +15,7 @@ export const useFormContext = (formId) => {
15
15
  internalClearError(name);
16
16
  });
17
17
  }, [internalClearError]);
18
- return {
18
+ return useMemo(() => ({
19
19
  ...state,
20
20
  setFieldTouched: setTouched,
21
21
  validateField,
@@ -24,5 +24,14 @@ export const useFormContext = (formId) => {
24
24
  clearAllErrors,
25
25
  validate,
26
26
  reset,
27
- };
27
+ }), [
28
+ clearAllErrors,
29
+ clearError,
30
+ registerReceiveFocus,
31
+ reset,
32
+ setTouched,
33
+ state,
34
+ validate,
35
+ validateField,
36
+ ]);
28
37
  };
@@ -14,5 +14,5 @@
14
14
  *
15
15
  * This source code is licensed under the MIT license found in the
16
16
  * LICENSE file in the root directory of this source tree.
17
- */var Ae=D.default,lv=Yr.exports;function dv(e,t){return e===t&&(e!==0||1/e===1/t)||e!==e&&t!==t}var vv=typeof Object.is=="function"?Object.is:dv,hv=lv.useSyncExternalStore,yv=Ae.useRef,pv=Ae.useEffect,gv=Ae.useMemo,mv=Ae.useDebugValue;Xr.useSyncExternalStoreWithSelector=function(e,t,r,n,a){var s=yv(null);if(s.current===null){var o={hasValue:!1,value:null};s.current=o}else o=s.current;s=gv(function(){function c(v){if(!u){if(u=!0,f=v,v=n(v),a!==void 0&&o.hasValue){var p=o.value;if(a(p,v))return l=p}return l=v}if(p=l,vv(f,v))return p;var m=n(v);return a!==void 0&&a(p,m)?p:(f=v,l=m)}var u=!1,f,l,d=r===void 0?null:r;return[function(){return c(t())},d===null?void 0:function(){return c(d())}]},[t,r,n,a]);var i=hv(e,s[0],s[1]);return pv(function(){o.hasValue=!0,o.value=i},[i]),mv(i),i};kr.exports=Xr;function bv(e,t=e.getState,r){const n=kr.exports.useSyncExternalStoreWithSelector(e.subscribe,e.getState,e.getServerState||e.getState,t,r);return y.useDebugValue(n),n}const sr=e=>{const t=typeof e=="function"?tv(e):e,r=(n,a)=>bv(t,n,a);return Object.assign(r,t),r},_v=e=>e?sr(e):sr;var Jr=_v;function O(e){for(var t=arguments.length,r=Array(t>1?t-1:0),n=1;n<t;n++)r[n-1]=arguments[n];throw Error("[Immer] minified error nr: "+e+(r.length?" "+r.map(function(a){return"'"+a+"'"}).join(","):"")+". Find the full error at: https://bit.ly/3cXEKWf")}function B(e){return!!e&&!!e[E]}function H(e){return!!e&&(function(t){if(!t||typeof t!="object")return!1;var r=Object.getPrototypeOf(t);if(r===null)return!0;var n=Object.hasOwnProperty.call(r,"constructor")&&r.constructor;return n===Object||typeof n=="function"&&Function.toString.call(n)===Tv}(e)||Array.isArray(e)||!!e[vr]||!!e.constructor[vr]||ct(e)||ft(e))}function ne(e,t,r){r===void 0&&(r=!1),X(e)===0?(r?Object.keys:yt)(e).forEach(function(n){r&&typeof n=="symbol"||t(n,e[n],e)}):e.forEach(function(n,a){return t(a,n,e)})}function X(e){var t=e[E];return t?t.i>3?t.i-4:t.i:Array.isArray(e)?1:ct(e)?2:ft(e)?3:0}function qe(e,t){return X(e)===2?e.has(t):Object.prototype.hasOwnProperty.call(e,t)}function $v(e,t){return X(e)===2?e.get(t):e[t]}function Qr(e,t,r){var n=X(e);n===2?e.set(t,r):n===3?(e.delete(t),e.add(r)):e[t]=r}function Sv(e,t){return e===t?e!==0||1/e==1/t:e!=e&&t!=t}function ct(e){return Av&&e instanceof Map}function ft(e){return Ov&&e instanceof Set}function G(e){return e.o||e.t}function lt(e){if(Array.isArray(e))return Array.prototype.slice.call(e);var t=Fv(e);delete t[E];for(var r=yt(t),n=0;n<r.length;n++){var a=r[n],s=t[a];s.writable===!1&&(s.writable=!0,s.configurable=!0),(s.get||s.set)&&(t[a]={configurable:!0,writable:!0,enumerable:s.enumerable,value:e[a]})}return Object.create(Object.getPrototypeOf(e),t)}function dt(e,t){return t===void 0&&(t=!1),vt(e)||B(e)||!H(e)||(X(e)>1&&(e.set=e.add=e.clear=e.delete=Pv),Object.freeze(e),t&&ne(e,function(r,n){return dt(n,!0)},!0)),e}function Pv(){O(2)}function vt(e){return e==null||typeof e!="object"||Object.isFrozen(e)}function w(e){var t=wv[e];return t||O(18,e),t}function or(){return ae}function De(e,t){t&&(w("Patches"),e.u=[],e.s=[],e.v=t)}function ge(e){ze(e),e.p.forEach(Ev),e.p=null}function ze(e){e===ae&&(ae=e.l)}function ir(e){return ae={p:[],l:ae,h:e,m:!0,_:0}}function Ev(e){var t=e[E];t.i===0||t.i===1?t.j():t.O=!0}function Me(e,t){t._=t.p.length;var r=t.p[0],n=e!==void 0&&e!==r;return t.h.g||w("ES5").S(t,e,n),n?(r[E].P&&(ge(t),O(4)),H(e)&&(e=me(t,e),t.l||be(t,e)),t.u&&w("Patches").M(r[E].t,e,t.u,t.s)):e=me(t,r,[]),ge(t),t.u&&t.v(t.u,t.s),e!==en?e:void 0}function me(e,t,r){if(vt(t))return t;var n=t[E];if(!n)return ne(t,function(s,o){return ur(e,n,t,s,o,r)},!0),t;if(n.A!==e)return t;if(!n.P)return be(e,n.t,!0),n.t;if(!n.I){n.I=!0,n.A._--;var a=n.i===4||n.i===5?n.o=lt(n.k):n.o;ne(n.i===3?new Set(a):a,function(s,o){return ur(e,n,a,s,o,r)}),be(e,a,!1),r&&e.u&&w("Patches").R(n,r,e.u,e.s)}return n.o}function ur(e,t,r,n,a,s){if(B(a)){var o=me(e,a,s&&t&&t.i!==3&&!qe(t.D,n)?s.concat(n):void 0);if(Qr(r,n,o),!B(o))return;e.m=!1}if(H(a)&&!vt(a)){if(!e.h.F&&e._<1)return;me(e,a),t&&t.A.l||be(e,a)}}function be(e,t,r){r===void 0&&(r=!1),e.h.F&&e.m&&dt(t,r)}function je(e,t){var r=e[E];return(r?G(r):e)[t]}function cr(e,t){if(t in e)for(var r=Object.getPrototypeOf(e);r;){var n=Object.getOwnPropertyDescriptor(r,t);if(n)return n;r=Object.getPrototypeOf(r)}}function We(e){e.P||(e.P=!0,e.l&&We(e.l))}function Re(e){e.o||(e.o=lt(e.t))}function ke(e,t,r){var n=ct(t)?w("MapSet").N(t,r):ft(t)?w("MapSet").T(t,r):e.g?function(a,s){var o=Array.isArray(a),i={i:o?1:0,A:s?s.A:or(),P:!1,I:!1,D:{},l:s,t:a,k:null,o:null,j:null,C:!1},c=i,u=Xe;o&&(c=[i],u=te);var f=Proxy.revocable(c,u),l=f.revoke,d=f.proxy;return i.k=d,i.j=l,d}(t,r):w("ES5").J(t,r);return(r?r.A:or()).p.push(n),n}function Iv(e){return B(e)||O(22,e),function t(r){if(!H(r))return r;var n,a=r[E],s=X(r);if(a){if(!a.P&&(a.i<4||!w("ES5").K(a)))return a.t;a.I=!0,n=fr(r,s),a.I=!1}else n=fr(r,s);return ne(n,function(o,i){a&&$v(a.t,o)===i||Qr(n,o,t(i))}),s===3?new Set(n):n}(e)}function fr(e,t){switch(t){case 2:return new Map(e);case 3:return Array.from(e)}return lt(e)}var lr,ae,ht=typeof Symbol!="undefined"&&typeof Symbol("x")=="symbol",Av=typeof Map!="undefined",Ov=typeof Set!="undefined",dr=typeof Proxy!="undefined"&&Proxy.revocable!==void 0&&typeof Reflect!="undefined",en=ht?Symbol.for("immer-nothing"):((lr={})["immer-nothing"]=!0,lr),vr=ht?Symbol.for("immer-draftable"):"__$immer_draftable",E=ht?Symbol.for("immer-state"):"__$immer_state",Tv=""+Object.prototype.constructor,yt=typeof Reflect!="undefined"&&Reflect.ownKeys?Reflect.ownKeys:Object.getOwnPropertySymbols!==void 0?function(e){return Object.getOwnPropertyNames(e).concat(Object.getOwnPropertySymbols(e))}:Object.getOwnPropertyNames,Fv=Object.getOwnPropertyDescriptors||function(e){var t={};return yt(e).forEach(function(r){t[r]=Object.getOwnPropertyDescriptor(e,r)}),t},wv={},Xe={get:function(e,t){if(t===E)return e;var r=G(e);if(!qe(r,t))return function(a,s,o){var i,c=cr(s,o);return c?"value"in c?c.value:(i=c.get)===null||i===void 0?void 0:i.call(a.k):void 0}(e,r,t);var n=r[t];return e.I||!H(n)?n:n===je(e.t,t)?(Re(e),e.o[t]=ke(e.A.h,n,e)):n},has:function(e,t){return t in G(e)},ownKeys:function(e){return Reflect.ownKeys(G(e))},set:function(e,t,r){var n=cr(G(e),t);if(n!=null&&n.set)return n.set.call(e.k,r),!0;if(!e.P){var a=je(G(e),t),s=a==null?void 0:a[E];if(s&&s.t===r)return e.o[t]=r,e.D[t]=!1,!0;if(Sv(r,a)&&(r!==void 0||qe(e.t,t)))return!0;Re(e),We(e)}return e.o[t]===r&&typeof r!="number"&&(r!==void 0||t in e.o)||(e.o[t]=r,e.D[t]=!0,!0)},deleteProperty:function(e,t){return je(e.t,t)!==void 0||t in e.t?(e.D[t]=!1,Re(e),We(e)):delete e.D[t],e.o&&delete e.o[t],!0},getOwnPropertyDescriptor:function(e,t){var r=G(e),n=Reflect.getOwnPropertyDescriptor(r,t);return n&&{writable:!0,configurable:e.i!==1||t!=="length",enumerable:n.enumerable,value:r[t]}},defineProperty:function(){O(11)},getPrototypeOf:function(e){return Object.getPrototypeOf(e.t)},setPrototypeOf:function(){O(12)}},te={};ne(Xe,function(e,t){te[e]=function(){return arguments[0]=arguments[0][0],t.apply(this,arguments)}}),te.deleteProperty=function(e,t){return te.set.call(this,e,t,void 0)},te.set=function(e,t,r){return Xe.set.call(this,e[0],t,r,e[0])};var Cv=function(){function e(r){var n=this;this.g=dr,this.F=!0,this.produce=function(a,s,o){if(typeof a=="function"&&typeof s!="function"){var i=s;s=a;var c=n;return function(m){var S=this;m===void 0&&(m=i);for(var b=arguments.length,$=Array(b>1?b-1:0),A=1;A<b;A++)$[A-1]=arguments[A];return c.produce(m,function(P){var T;return(T=s).call.apply(T,[S,P].concat($))})}}var u;if(typeof s!="function"&&O(6),o!==void 0&&typeof o!="function"&&O(7),H(a)){var f=ir(n),l=ke(n,a,void 0),d=!0;try{u=s(l),d=!1}finally{d?ge(f):ze(f)}return typeof Promise!="undefined"&&u instanceof Promise?u.then(function(m){return De(f,o),Me(m,f)},function(m){throw ge(f),m}):(De(f,o),Me(u,f))}if(!a||typeof a!="object"){if((u=s(a))===void 0&&(u=a),u===en&&(u=void 0),n.F&&dt(u,!0),o){var v=[],p=[];w("Patches").M(a,u,v,p),o(v,p)}return u}O(21,a)},this.produceWithPatches=function(a,s){if(typeof a=="function")return function(u){for(var f=arguments.length,l=Array(f>1?f-1:0),d=1;d<f;d++)l[d-1]=arguments[d];return n.produceWithPatches(u,function(v){return a.apply(void 0,[v].concat(l))})};var o,i,c=n.produce(a,s,function(u,f){o=u,i=f});return typeof Promise!="undefined"&&c instanceof Promise?c.then(function(u){return[u,o,i]}):[c,o,i]},typeof(r==null?void 0:r.useProxies)=="boolean"&&this.setUseProxies(r.useProxies),typeof(r==null?void 0:r.autoFreeze)=="boolean"&&this.setAutoFreeze(r.autoFreeze)}var t=e.prototype;return t.createDraft=function(r){H(r)||O(8),B(r)&&(r=Iv(r));var n=ir(this),a=ke(this,r,void 0);return a[E].C=!0,ze(n),a},t.finishDraft=function(r,n){var a=r&&r[E],s=a.A;return De(s,n),Me(void 0,s)},t.setAutoFreeze=function(r){this.F=r},t.setUseProxies=function(r){r&&!dr&&O(20),this.g=r},t.applyPatches=function(r,n){var a;for(a=n.length-1;a>=0;a--){var s=n[a];if(s.path.length===0&&s.op==="replace"){r=s.value;break}}a>-1&&(n=n.slice(a+1));var o=w("Patches").$;return B(r)?o(r,n):this.produce(r,function(i){return o(i,n)})},e}(),I=new Cv,xv=I.produce;I.produceWithPatches.bind(I);I.setAutoFreeze.bind(I);I.setUseProxies.bind(I);I.applyPatches.bind(I);I.createDraft.bind(I);I.finishDraft.bind(I);const Dv=e=>(t,r,n)=>(n.setState=(a,s,...o)=>{const i=typeof a=="function"?xv(a):a;return t(i,s,...o)},e(n.setState,r,n)),tn=Dv,rn=e=>{const t=new Map,r=n=>{if(t.has(n))return t.get(n);const a=e(n);return t.set(n,a),a};return r.remove=n=>{t.delete(n)},r},Y=rn(()=>Jr()(tn((e,t,r)=>({fields:{},register:n=>e(a=>{a.fields[n]?a.fields[n].refCount++:a.fields[n]={refCount:1,value:void 0,hydrated:!1,valueUpdatePromise:void 0,resolveValueUpdate:void 0}}),unregister:n=>e(a=>{const s=a.fields[n];!s||(s.refCount--,s.refCount===0&&delete a.fields[n])}),setValue:(n,a)=>e(s=>{const o=s.fields[n];if(!o)return;o.value=a;const i=new Promise(c=>{o.resolveValueUpdate=c});o.valueUpdatePromise=i}),hydrateWithDefault:(n,a)=>e(s=>{const o=s.fields[n];!o||(o.value=a,o.defaultValue=a,o.hydrated=!0)}),awaitValueUpdate:async n=>{var a;await((a=t().fields[n])==null?void 0:a.valueUpdatePromise)},reset:()=>e(n=>{Object.values(n.fields).forEach(a=>{!a||(a.value=a.defaultValue)})})})))),pt=rn(e=>Jr()(tn((t,r,n)=>({isHydrated:!1,isSubmitting:!1,hasBeenSubmitted:!1,touchedFields:{},fieldErrors:{},formElement:null,isValid:()=>Object.keys(r().fieldErrors).length===0,startSubmit:()=>t(a=>{a.isSubmitting=!0,a.hasBeenSubmitted=!0}),endSubmit:()=>t(a=>{a.isSubmitting=!1}),setTouched:(a,s)=>t(o=>{o.touchedFields[a]=s}),setFieldError:(a,s)=>t(o=>{o.fieldErrors[a]=s}),setFieldErrors:a=>t(s=>{s.fieldErrors=a}),clearFieldError:a=>t(s=>{delete s.fieldErrors[a]}),reset:()=>t(a=>{a.fieldErrors={},a.touchedFields={},a.hasBeenSubmitted=!1}),syncFormProps:a=>t(s=>{s.formProps=a}),setHydrated:()=>t(a=>{a.isHydrated=!0}),setFormElement:a=>{r().formElement!==a&&t(s=>{s.formElement=a})},validateField:async a=>{var c,u,f;const s=r().formElement;Q(s);const o=(c=r().formProps)==null?void 0:c.validator;Q(o),await((f=(u=Y(e).getState()).awaitValueUpdate)==null?void 0:f.call(u,a));const{error:i}=await o.validateField(new FormData(s),a);return i?(r().setFieldError(a,i),i):(r().clearFieldError(a),null)},validate:async()=>{var i;const a=r().formElement;Q(a);const s=(i=r().formProps)==null?void 0:i.validator;Q(s);const{error:o}=await s.validate(new FormData(a));o&&r().setFieldErrors(o.fieldErrors)},resetFormElement:()=>{var a;return(a=r().formElement)==null?void 0:a.reset()}})))),g=(e,t)=>pt(e)(t),Mv=(e,t)=>Y(e)(t),j=(e,t)=>{const r=y.useContext(Wr);if(e)return{formId:e};if(r)return r;throw new Error(`Unable to determine form for ${t}. Please use it inside a ValidatedForm or pass a 'formId'.`)};function gt({fetcher:e,subaction:t,formId:r}){var a;const n=re.useActionData();return e?(a=e.data)!=null&&a.fieldErrors?e.data:null:n!=null&&n.fieldErrors?typeof r=="string"&&n.formId?n.formId===r?n:null:!t&&!n.subaction||n.subaction===t?n:null:null}const nn=e=>{const t=gt(e),r=g(e.formId,n=>n.isHydrated);return ee.from(t==null?void 0:t.fieldErrors,r)},an=({formId:e})=>{const t=re.useMatches();if(typeof e=="string"){const r=zr(e),n=t.reverse().find(a=>a.data&&r in a.data);return n==null?void 0:n.data[r]}return null},sn=e=>{const{formId:t,defaultValuesProp:r}=e,n=g(t,o=>o.isHydrated),a=gt(e),s=an(e);return n?ee.hydratedData():a!=null&&a.repopulateFields?(Q(typeof a.repopulateFields=="object"),ee.serverData(a.repopulateFields)):r?ee.serverData(r):ee.serverData(s)},jv=({fetcher:e})=>{const t=re.useTransition();return e?e.state==="submitting":!!t.submission},Rv=(e,{formId:t})=>{const r=g(t,s=>s.touchedFields[e]),n=g(t,s=>s.setTouched),a=y.useCallback(s=>n(e,s),[e,n]);return[r,a]},Lv=(e,t)=>{const r=nn(t),n=g(t.formId,a=>a.fieldErrors[e]);return r.map(a=>a==null?void 0:a[e]).hydrateTo(n)},on=e=>{const{formId:t}=e;return g(t,r=>r.clearFieldError)},un=(e,t)=>{const r=sn(t),n=hn(t.formId);return r.map(a=>Ue(a,e)).hydrateTo(Ue(n,e))},cn=e=>g(e,t=>t.isSubmitting),fn=e=>g(e,t=>t.isValid()),ln=e=>g(e,t=>t.hasBeenSubmitted),dn=e=>g(e,t=>t.validateField),Gv=e=>g(e,t=>t.validate),Hv=()=>()=>{},vn=e=>g(e,t=>{var r,n;return(n=(r=t.formProps)==null?void 0:r.registerReceiveFocus)!=null?n:Hv}),Vv={},hn=e=>g(e,t=>{var r,n;return(n=(r=t.formProps)==null?void 0:r.defaultValues)!=null?n:Vv}),Kv=({formId:e})=>g(e,t=>t.setTouched),Nv=e=>g(e,t=>t.touchedFields),Bv=e=>g(e,t=>t.fieldErrors),yn=e=>g(e,t=>t.setFieldErrors),Uv=e=>g(e,t=>t.resetFormElement),qv=e=>g(e,t=>{var r;return(r=t.formProps)==null?void 0:r.action}),zv=e=>g(e,t=>{var r;return(r=t.formProps)==null?void 0:r.subaction}),Wv=(e,t)=>{const r=Y(e.formId),n=r(u=>{var f;return(f=u.fields[t])==null?void 0:f.value}),s=pt(e.formId)(u=>u.isHydrated),o=un(t,e),i=r(u=>{var f,l;return(l=(f=u.fields[t])==null?void 0:f.hydrated)!=null?l:!1}),c=r(u=>u.hydrateWithDefault);return y.useEffect(()=>{s&&!i&&c(t,o)},[o,t,c,i,s]),i?n:o},kv=(e,t)=>{const r=Y(e.formId),n=r(u=>{var f;return(f=u.fields[t])==null?void 0:f.resolveValueUpdate});y.useEffect(()=>{n==null||n()},[n]);const a=r(u=>u.register),s=r(u=>u.unregister);y.useEffect(()=>(a(t),()=>s(t)),[e.formId,t,a,s]);const o=r(u=>u.setValue),i=y.useCallback(u=>o(t,u),[t,o]);return[Wv(e,t),i]},Xv=e=>Y(e)(r=>r.setValue),pn=e=>{const t=j(e,"useIsSubmitting");return cn(t.formId)},gn=e=>{const t=j(e,"useIsValid");return fn(t.formId)},Yv=(e,t)=>{const{formId:r,handleReceiveFocus:n}=t!=null?t:{},a=j(r,"useField"),s=un(e,a),[o,i]=Rv(e,a),c=Lv(e,a),u=on(a),f=ln(a.formId),l=dn(a.formId),d=vn(a.formId);return y.useEffect(()=>{if(n)return d(e,n)},[n,e,d]),y.useMemo(()=>{const p={error:c,clearError:()=>u(e),validate:()=>{l(e)},defaultValue:s,touched:o,setTouched:i},m=Zd(K(C({},p),{name:e,hasBeenSubmitted:f,validationBehavior:t==null?void 0:t.validationBehavior}));return K(C({},p),{getInputProps:m})},[c,u,s,o,i,e,f,t==null?void 0:t.validationBehavior,l])},Zv=(e,t)=>{const r=j(t,"useControlField"),[n,a]=kv(r,e);return[n,a]},Jv=e=>{const t=j(e,"useControlField");return Xv(t.formId)};function Qv(e,t,r){return xn.json({fieldErrors:e.fieldErrors,subaction:e.subaction,repopulateFields:t,formId:e.formId},C({status:422},r))}const eh=(e,t)=>({[zr(e)]:t});function th(e,t,r,n){for(var a=e.length,s=r+(n?1:-1);n?s--:++s<a;)if(t(e[s],s,e))return s;return-1}var rh=th;function nh(e){return e!==e}var ah=nh;function sh(e,t,r){for(var n=r-1,a=e.length;++n<a;)if(e[n]===t)return n;return-1}var oh=sh,ih=rh,uh=ah,ch=oh;function fh(e,t,r){return t===t?ch(e,t,r):ih(e,uh,r)}var lh=fh,dh=lh;function vh(e,t){var r=e==null?0:e.length;return!!r&&dh(e,t,0)>-1}var hh=vh;function yh(e,t,r){for(var n=-1,a=e==null?0:e.length;++n<a;)if(r(t,e[n]))return!0;return!1}var ph=yh;function gh(){}var mh=gh,Le=Rr,bh=mh,_h=Qe,$h=1/0,Sh=Le&&1/_h(new Le([,-0]))[1]==$h?function(e){return new Le(e)}:bh,Ph=Sh,Eh=$r,Ih=hh,Ah=ph,Oh=Sr,Th=Ph,Fh=Qe,wh=200;function Ch(e,t,r){var n=-1,a=Ih,s=e.length,o=!0,i=[],c=i;if(r)o=!1,a=Ah;else if(s>=wh){var u=t?null:Th(e);if(u)return Fh(u);o=!1,a=Oh,c=new Eh}else c=t?[]:i;e:for(;++n<s;){var f=e[n],l=t?t(f):f;if(f=r||f!==0?f:0,o&&l===l){for(var d=c.length;d--;)if(c[d]===l)continue e;t&&c.push(l),i.push(f)}else a(c,l,r)||(c!==i&&c.push(l),i.push(f))}return i}var xh=Ch,Dh=xh;function Mh(e){return e&&e.length?Dh(e):[]}var jh=Mh;class mn{constructor(){this.dict=new Map,this.add=(t,r)=>{this.dict.has(t)?this.dict.get(t).push(r):this.dict.set(t,[r])},this.delete=t=>{this.dict.delete(t)},this.remove=(t,r)=>{if(!this.dict.has(t))return;const n=this.dict.get(t),a=n.indexOf(r);a!==-1&&n.splice(a,1),n.length===0&&this.dict.delete(t)},this.getAll=t=>{var r;return(r=this.dict.get(t))!=null?r:[]},this.entries=()=>this.dict.entries(),this.values=()=>this.dict.values(),this.has=t=>this.dict.has(t)}}const Rh=()=>{const e=y.useRef(null);return y.useCallback(()=>(e.current||(e.current=new mn),e.current),[])},Lh=e=>{pt.remove(e),Y.remove(e)};function bn(e,t){const r=y.useRef(!1);y.useEffect(()=>{e&&(r.current=!0),!e&&r.current&&(r.current=!1,t())})}var Gh=rt;function Hh(e,t){return Gh(e,t)}var Vh=Hh;const Kh=e=>t=>{e.filter(Boolean).forEach(r=>{typeof r=="function"?r(t):r!=null&&(r.current=t)})},Nh=typeof window!="undefined"?y.useLayoutEffect:y.useEffect,Bh=e=>{const t=y.useRef(e),r=t.current===e||Vh(t.current,e);return y.useEffect(()=>{r||(t.current=e)}),r?t.current:e},Uh=e=>new FormData(e);function qh(e){return e!==null}const zh=(e,t,r)=>{var s;const n=[...r.elements].map(o=>{const i=o instanceof RadioNodeList?o[0]:o;return i instanceof HTMLInputElement?i.name:null}).filter(qh).filter(o=>o in e),a=jh(n);for(const o of a){if(t.has(o)){t.getAll(o).forEach(c=>{c()});break}const i=r.elements.namedItem(o);if(!!i){if(i instanceof RadioNodeList){const c=(s=[...i].filter(u=>u instanceof HTMLInputElement).find(u=>u.value===i.value))!=null?s:i[0];if(c&&c instanceof HTMLInputElement){c.focus();break}}if(i instanceof HTMLInputElement){if(i.type==="hidden")continue;i.focus();break}}}},Wh=e=>{const[t]=y.useState(()=>Symbol("remix-validated-form-id"));return e!=null?e:t},kh=({resetAfterSubmit:e,formRef:t})=>{const r=pn(),n=gn();return bn(r,()=>{var a;n&&e&&((a=t.current)==null||a.reset())}),null};function Xh(e){let t=!1;return new Proxy(e,{get:(r,n)=>n==="preventDefault"?()=>{t=!0}:n==="defaultPrevented"?t:r[n]})}function Yh(m){var S=m,{validator:e,onSubmit:t,children:r,fetcher:n,action:a,defaultValues:s,formRef:o,onReset:i,subaction:c,resetAfterSubmit:u=!1,disableFocusOnError:f,method:l,replace:d,id:v}=S,p=At(S,["validator","onSubmit","children","fetcher","action","defaultValues","formRef","onReset","subaction","resetAfterSubmit","disableFocusOnError","method","replace","id"]);var St;const b=Wh(v),$=Bh(s),A=y.useMemo(()=>({formId:b,action:a,subaction:c,defaultValuesProp:$,fetcher:n}),[a,n,b,$,c]),P=gt(A),T=an(A),_n=jv(A),ce=y.useRef(null),$n=(St=n==null?void 0:n.Form)!=null?St:re.Form,Sn=re.useSubmit(),Oe=yn(b),Pn=g(b,h=>h.setFieldError),En=g(b,h=>h.reset),In=Mv(b,h=>h.reset),An=g(b,h=>h.startSubmit),Te=g(b,h=>h.endSubmit),mt=g(b,h=>h.syncFormProps),bt=g(b,h=>h.setHydrated),On=g(b,h=>h.setFormElement);y.useEffect(()=>(bt(),()=>Lh(b)),[b,bt]);const fe=Rh(),_t=y.useCallback((h,F)=>(fe().add(h,F),()=>{fe().remove(h,F)}),[fe]);Nh(()=>{var h;mt({action:a,defaultValues:(h=$!=null?$:T)!=null?h:{},subaction:c,registerReceiveFocus:_t,validator:e})},[a,$,_t,c,mt,T,e]),y.useEffect(()=>{var h;Oe((h=P==null?void 0:P.fieldErrors)!=null?h:{})},[P==null?void 0:P.fieldErrors,Oe,Pn]),bn(_n,()=>{Te()});let $t=D.default.useRef();y.useEffect(()=>{let h=ce.current;if(!h)return;function F(Z){if(!(Z.target instanceof HTMLElement))return;let R=Z.target.closest("button,input[type=submit]");R&&R.form===h&&R.type==="submit"&&($t.current=R)}return window.addEventListener("click",F,{capture:!0}),()=>{window.removeEventListener("click",F,{capture:!0})}},[]);const Tn=async h=>{An();const F=await e.validate(Uh(h.currentTarget));if(F.error)Te(),Oe(F.error.fieldErrors),f||zh(F.error.fieldErrors,fe(),ce.current);else{const Z=Xh(h);if(await(t==null?void 0:t(F.data,Z)),Z.defaultPrevented){Te();return}const R=h.nativeEvent.submitter;n?n.submit(R||h.currentTarget):Sn(R||h.currentTarget,{method:l,replace:d}),$t.current=null}};return D.default.createElement($n,K(C({ref:Kh([ce,o,On])},p),{id:v,action:a,method:l,replace:d,onSubmit:h=>{h.preventDefault(),Tn(h)},onReset:h=>{i==null||i(h),!h.defaultPrevented&&(En(),In())}}),D.default.createElement(Wr.Provider,{value:A},D.default.createElement(kh,{formRef:ce,resetAfterSubmit:u}),c&&D.default.createElement("input",{type:"hidden",value:c,name:"subaction"}),v&&D.default.createElement("input",{type:"hidden",value:v,name:he}),r))}var Zh=qr;function Jh(e,t,r){return e==null?e:Zh(e,t,r)}var Qh=Jh;const hr=e=>{const t=new mn;return e.forEach(([r,n])=>t.add(r,n)),[...t.entries()].reduce((r,[n,a])=>Qh(r,n,a.length===1?a[0]:a),{})},yr=e=>"entries"in e&&typeof e.entries=="function"?hr([...e.entries()]):hr(Object.entries(e));function ey(e){return{validate:async t=>{const r=yr(t),n=await e.validate(r);return n.error?{data:void 0,error:{fieldErrors:n.error,subaction:r.subaction,formId:r[he]},submittedData:r,formId:r[he]}:{data:n.data,error:void 0,submittedData:r,formId:r[he]}},validateField:(t,r)=>e.validateField(yr(t),r)}}const ty=e=>{const t=j(e,"useFormState"),r=cn(t.formId),n=ln(t.formId),a=Nv(t.formId),s=fn(t.formId),o=qv(t.formId),i=zv(t.formId),c=hn(t.formId),f=sn(t).hydrateTo(c),l=Bv(t.formId),v=nn(t).hydrateTo(l);return y.useMemo(()=>({action:o,subaction:i,defaultValues:f,fieldErrors:v!=null?v:{},hasBeenSubmitted:n,isSubmitting:r,touchedFields:a,isValid:s}),[o,n,f,v,r,s,i,a])},ry=e=>{const t=j(e,"useFormHelpers"),r=Kv(t),n=dn(t.formId),a=Gv(t.formId),s=on(t),o=yn(t.formId),i=Uv(t.formId);return y.useMemo(()=>({setTouched:r,validateField:n,clearError:s,validate:a,clearAllErrors:()=>o({}),reset:i}),[s,i,o,r,a,n])},ny=e=>{const t=j(e,"useFormContext"),r=ty(e),{clearError:n,setTouched:a,validateField:s,clearAllErrors:o,validate:i,reset:c}=ry(e),u=vn(t.formId),f=y.useCallback((...l)=>{l.forEach(d=>{n(d)})},[n]);return K(C({},r),{setFieldTouched:a,validateField:s,clearError:f,registerReceiveFocus:u,clearAllErrors:o,validate:i,reset:c})};exports.ValidatedForm=Yh;exports.createValidator=ey;exports.setFormDefaults=eh;exports.useControlField=Zv;exports.useField=Yv;exports.useFormContext=ny;exports.useIsSubmitting=pn;exports.useIsValid=gn;exports.useUpdateControlledField=Jv;exports.validationError=Qv;
17
+ */var Ae=D.default,lv=Yr.exports;function dv(e,t){return e===t&&(e!==0||1/e===1/t)||e!==e&&t!==t}var vv=typeof Object.is=="function"?Object.is:dv,hv=lv.useSyncExternalStore,yv=Ae.useRef,pv=Ae.useEffect,gv=Ae.useMemo,mv=Ae.useDebugValue;Xr.useSyncExternalStoreWithSelector=function(e,t,r,n,a){var s=yv(null);if(s.current===null){var o={hasValue:!1,value:null};s.current=o}else o=s.current;s=gv(function(){function c(v){if(!u){if(u=!0,f=v,v=n(v),a!==void 0&&o.hasValue){var p=o.value;if(a(p,v))return l=p}return l=v}if(p=l,vv(f,v))return p;var m=n(v);return a!==void 0&&a(p,m)?p:(f=v,l=m)}var u=!1,f,l,d=r===void 0?null:r;return[function(){return c(t())},d===null?void 0:function(){return c(d())}]},[t,r,n,a]);var i=hv(e,s[0],s[1]);return pv(function(){o.hasValue=!0,o.value=i},[i]),mv(i),i};kr.exports=Xr;function bv(e,t=e.getState,r){const n=kr.exports.useSyncExternalStoreWithSelector(e.subscribe,e.getState,e.getServerState||e.getState,t,r);return y.useDebugValue(n),n}const sr=e=>{const t=typeof e=="function"?tv(e):e,r=(n,a)=>bv(t,n,a);return Object.assign(r,t),r},_v=e=>e?sr(e):sr;var Jr=_v;function O(e){for(var t=arguments.length,r=Array(t>1?t-1:0),n=1;n<t;n++)r[n-1]=arguments[n];throw Error("[Immer] minified error nr: "+e+(r.length?" "+r.map(function(a){return"'"+a+"'"}).join(","):"")+". Find the full error at: https://bit.ly/3cXEKWf")}function B(e){return!!e&&!!e[E]}function H(e){return!!e&&(function(t){if(!t||typeof t!="object")return!1;var r=Object.getPrototypeOf(t);if(r===null)return!0;var n=Object.hasOwnProperty.call(r,"constructor")&&r.constructor;return n===Object||typeof n=="function"&&Function.toString.call(n)===Tv}(e)||Array.isArray(e)||!!e[vr]||!!e.constructor[vr]||ct(e)||ft(e))}function ne(e,t,r){r===void 0&&(r=!1),X(e)===0?(r?Object.keys:yt)(e).forEach(function(n){r&&typeof n=="symbol"||t(n,e[n],e)}):e.forEach(function(n,a){return t(a,n,e)})}function X(e){var t=e[E];return t?t.i>3?t.i-4:t.i:Array.isArray(e)?1:ct(e)?2:ft(e)?3:0}function qe(e,t){return X(e)===2?e.has(t):Object.prototype.hasOwnProperty.call(e,t)}function $v(e,t){return X(e)===2?e.get(t):e[t]}function Qr(e,t,r){var n=X(e);n===2?e.set(t,r):n===3?(e.delete(t),e.add(r)):e[t]=r}function Sv(e,t){return e===t?e!==0||1/e==1/t:e!=e&&t!=t}function ct(e){return Av&&e instanceof Map}function ft(e){return Ov&&e instanceof Set}function G(e){return e.o||e.t}function lt(e){if(Array.isArray(e))return Array.prototype.slice.call(e);var t=Fv(e);delete t[E];for(var r=yt(t),n=0;n<r.length;n++){var a=r[n],s=t[a];s.writable===!1&&(s.writable=!0,s.configurable=!0),(s.get||s.set)&&(t[a]={configurable:!0,writable:!0,enumerable:s.enumerable,value:e[a]})}return Object.create(Object.getPrototypeOf(e),t)}function dt(e,t){return t===void 0&&(t=!1),vt(e)||B(e)||!H(e)||(X(e)>1&&(e.set=e.add=e.clear=e.delete=Pv),Object.freeze(e),t&&ne(e,function(r,n){return dt(n,!0)},!0)),e}function Pv(){O(2)}function vt(e){return e==null||typeof e!="object"||Object.isFrozen(e)}function w(e){var t=wv[e];return t||O(18,e),t}function or(){return ae}function De(e,t){t&&(w("Patches"),e.u=[],e.s=[],e.v=t)}function ge(e){ze(e),e.p.forEach(Ev),e.p=null}function ze(e){e===ae&&(ae=e.l)}function ir(e){return ae={p:[],l:ae,h:e,m:!0,_:0}}function Ev(e){var t=e[E];t.i===0||t.i===1?t.j():t.O=!0}function Me(e,t){t._=t.p.length;var r=t.p[0],n=e!==void 0&&e!==r;return t.h.g||w("ES5").S(t,e,n),n?(r[E].P&&(ge(t),O(4)),H(e)&&(e=me(t,e),t.l||be(t,e)),t.u&&w("Patches").M(r[E].t,e,t.u,t.s)):e=me(t,r,[]),ge(t),t.u&&t.v(t.u,t.s),e!==en?e:void 0}function me(e,t,r){if(vt(t))return t;var n=t[E];if(!n)return ne(t,function(s,o){return ur(e,n,t,s,o,r)},!0),t;if(n.A!==e)return t;if(!n.P)return be(e,n.t,!0),n.t;if(!n.I){n.I=!0,n.A._--;var a=n.i===4||n.i===5?n.o=lt(n.k):n.o;ne(n.i===3?new Set(a):a,function(s,o){return ur(e,n,a,s,o,r)}),be(e,a,!1),r&&e.u&&w("Patches").R(n,r,e.u,e.s)}return n.o}function ur(e,t,r,n,a,s){if(B(a)){var o=me(e,a,s&&t&&t.i!==3&&!qe(t.D,n)?s.concat(n):void 0);if(Qr(r,n,o),!B(o))return;e.m=!1}if(H(a)&&!vt(a)){if(!e.h.F&&e._<1)return;me(e,a),t&&t.A.l||be(e,a)}}function be(e,t,r){r===void 0&&(r=!1),e.h.F&&e.m&&dt(t,r)}function je(e,t){var r=e[E];return(r?G(r):e)[t]}function cr(e,t){if(t in e)for(var r=Object.getPrototypeOf(e);r;){var n=Object.getOwnPropertyDescriptor(r,t);if(n)return n;r=Object.getPrototypeOf(r)}}function We(e){e.P||(e.P=!0,e.l&&We(e.l))}function Re(e){e.o||(e.o=lt(e.t))}function ke(e,t,r){var n=ct(t)?w("MapSet").N(t,r):ft(t)?w("MapSet").T(t,r):e.g?function(a,s){var o=Array.isArray(a),i={i:o?1:0,A:s?s.A:or(),P:!1,I:!1,D:{},l:s,t:a,k:null,o:null,j:null,C:!1},c=i,u=Xe;o&&(c=[i],u=te);var f=Proxy.revocable(c,u),l=f.revoke,d=f.proxy;return i.k=d,i.j=l,d}(t,r):w("ES5").J(t,r);return(r?r.A:or()).p.push(n),n}function Iv(e){return B(e)||O(22,e),function t(r){if(!H(r))return r;var n,a=r[E],s=X(r);if(a){if(!a.P&&(a.i<4||!w("ES5").K(a)))return a.t;a.I=!0,n=fr(r,s),a.I=!1}else n=fr(r,s);return ne(n,function(o,i){a&&$v(a.t,o)===i||Qr(n,o,t(i))}),s===3?new Set(n):n}(e)}function fr(e,t){switch(t){case 2:return new Map(e);case 3:return Array.from(e)}return lt(e)}var lr,ae,ht=typeof Symbol!="undefined"&&typeof Symbol("x")=="symbol",Av=typeof Map!="undefined",Ov=typeof Set!="undefined",dr=typeof Proxy!="undefined"&&Proxy.revocable!==void 0&&typeof Reflect!="undefined",en=ht?Symbol.for("immer-nothing"):((lr={})["immer-nothing"]=!0,lr),vr=ht?Symbol.for("immer-draftable"):"__$immer_draftable",E=ht?Symbol.for("immer-state"):"__$immer_state",Tv=""+Object.prototype.constructor,yt=typeof Reflect!="undefined"&&Reflect.ownKeys?Reflect.ownKeys:Object.getOwnPropertySymbols!==void 0?function(e){return Object.getOwnPropertyNames(e).concat(Object.getOwnPropertySymbols(e))}:Object.getOwnPropertyNames,Fv=Object.getOwnPropertyDescriptors||function(e){var t={};return yt(e).forEach(function(r){t[r]=Object.getOwnPropertyDescriptor(e,r)}),t},wv={},Xe={get:function(e,t){if(t===E)return e;var r=G(e);if(!qe(r,t))return function(a,s,o){var i,c=cr(s,o);return c?"value"in c?c.value:(i=c.get)===null||i===void 0?void 0:i.call(a.k):void 0}(e,r,t);var n=r[t];return e.I||!H(n)?n:n===je(e.t,t)?(Re(e),e.o[t]=ke(e.A.h,n,e)):n},has:function(e,t){return t in G(e)},ownKeys:function(e){return Reflect.ownKeys(G(e))},set:function(e,t,r){var n=cr(G(e),t);if(n!=null&&n.set)return n.set.call(e.k,r),!0;if(!e.P){var a=je(G(e),t),s=a==null?void 0:a[E];if(s&&s.t===r)return e.o[t]=r,e.D[t]=!1,!0;if(Sv(r,a)&&(r!==void 0||qe(e.t,t)))return!0;Re(e),We(e)}return e.o[t]===r&&typeof r!="number"&&(r!==void 0||t in e.o)||(e.o[t]=r,e.D[t]=!0,!0)},deleteProperty:function(e,t){return je(e.t,t)!==void 0||t in e.t?(e.D[t]=!1,Re(e),We(e)):delete e.D[t],e.o&&delete e.o[t],!0},getOwnPropertyDescriptor:function(e,t){var r=G(e),n=Reflect.getOwnPropertyDescriptor(r,t);return n&&{writable:!0,configurable:e.i!==1||t!=="length",enumerable:n.enumerable,value:r[t]}},defineProperty:function(){O(11)},getPrototypeOf:function(e){return Object.getPrototypeOf(e.t)},setPrototypeOf:function(){O(12)}},te={};ne(Xe,function(e,t){te[e]=function(){return arguments[0]=arguments[0][0],t.apply(this,arguments)}}),te.deleteProperty=function(e,t){return te.set.call(this,e,t,void 0)},te.set=function(e,t,r){return Xe.set.call(this,e[0],t,r,e[0])};var Cv=function(){function e(r){var n=this;this.g=dr,this.F=!0,this.produce=function(a,s,o){if(typeof a=="function"&&typeof s!="function"){var i=s;s=a;var c=n;return function(m){var S=this;m===void 0&&(m=i);for(var b=arguments.length,$=Array(b>1?b-1:0),A=1;A<b;A++)$[A-1]=arguments[A];return c.produce(m,function(P){var T;return(T=s).call.apply(T,[S,P].concat($))})}}var u;if(typeof s!="function"&&O(6),o!==void 0&&typeof o!="function"&&O(7),H(a)){var f=ir(n),l=ke(n,a,void 0),d=!0;try{u=s(l),d=!1}finally{d?ge(f):ze(f)}return typeof Promise!="undefined"&&u instanceof Promise?u.then(function(m){return De(f,o),Me(m,f)},function(m){throw ge(f),m}):(De(f,o),Me(u,f))}if(!a||typeof a!="object"){if((u=s(a))===void 0&&(u=a),u===en&&(u=void 0),n.F&&dt(u,!0),o){var v=[],p=[];w("Patches").M(a,u,v,p),o(v,p)}return u}O(21,a)},this.produceWithPatches=function(a,s){if(typeof a=="function")return function(u){for(var f=arguments.length,l=Array(f>1?f-1:0),d=1;d<f;d++)l[d-1]=arguments[d];return n.produceWithPatches(u,function(v){return a.apply(void 0,[v].concat(l))})};var o,i,c=n.produce(a,s,function(u,f){o=u,i=f});return typeof Promise!="undefined"&&c instanceof Promise?c.then(function(u){return[u,o,i]}):[c,o,i]},typeof(r==null?void 0:r.useProxies)=="boolean"&&this.setUseProxies(r.useProxies),typeof(r==null?void 0:r.autoFreeze)=="boolean"&&this.setAutoFreeze(r.autoFreeze)}var t=e.prototype;return t.createDraft=function(r){H(r)||O(8),B(r)&&(r=Iv(r));var n=ir(this),a=ke(this,r,void 0);return a[E].C=!0,ze(n),a},t.finishDraft=function(r,n){var a=r&&r[E],s=a.A;return De(s,n),Me(void 0,s)},t.setAutoFreeze=function(r){this.F=r},t.setUseProxies=function(r){r&&!dr&&O(20),this.g=r},t.applyPatches=function(r,n){var a;for(a=n.length-1;a>=0;a--){var s=n[a];if(s.path.length===0&&s.op==="replace"){r=s.value;break}}a>-1&&(n=n.slice(a+1));var o=w("Patches").$;return B(r)?o(r,n):this.produce(r,function(i){return o(i,n)})},e}(),I=new Cv,xv=I.produce;I.produceWithPatches.bind(I);I.setAutoFreeze.bind(I);I.setUseProxies.bind(I);I.applyPatches.bind(I);I.createDraft.bind(I);I.finishDraft.bind(I);const Dv=e=>(t,r,n)=>(n.setState=(a,s,...o)=>{const i=typeof a=="function"?xv(a):a;return t(i,s,...o)},e(n.setState,r,n)),tn=Dv,rn=e=>{const t=new Map,r=n=>{if(t.has(n))return t.get(n);const a=e(n);return t.set(n,a),a};return r.remove=n=>{t.delete(n)},r},Y=rn(()=>Jr()(tn((e,t,r)=>({fields:{},register:n=>e(a=>{a.fields[n]?a.fields[n].refCount++:a.fields[n]={refCount:1,value:void 0,hydrated:!1,valueUpdatePromise:void 0,resolveValueUpdate:void 0}}),unregister:n=>e(a=>{const s=a.fields[n];!s||(s.refCount--,s.refCount===0&&delete a.fields[n])}),setValue:(n,a)=>e(s=>{const o=s.fields[n];if(!o)return;o.value=a;const i=new Promise(c=>{o.resolveValueUpdate=c});o.valueUpdatePromise=i}),hydrateWithDefault:(n,a)=>e(s=>{const o=s.fields[n];!o||(o.value=a,o.defaultValue=a,o.hydrated=!0)}),awaitValueUpdate:async n=>{var a;await((a=t().fields[n])==null?void 0:a.valueUpdatePromise)},reset:()=>e(n=>{Object.values(n.fields).forEach(a=>{!a||(a.value=a.defaultValue)})})})))),pt=rn(e=>Jr()(tn((t,r,n)=>({isHydrated:!1,isSubmitting:!1,hasBeenSubmitted:!1,touchedFields:{},fieldErrors:{},formElement:null,isValid:()=>Object.keys(r().fieldErrors).length===0,startSubmit:()=>t(a=>{a.isSubmitting=!0,a.hasBeenSubmitted=!0}),endSubmit:()=>t(a=>{a.isSubmitting=!1}),setTouched:(a,s)=>t(o=>{o.touchedFields[a]=s}),setFieldError:(a,s)=>t(o=>{o.fieldErrors[a]=s}),setFieldErrors:a=>t(s=>{s.fieldErrors=a}),clearFieldError:a=>t(s=>{delete s.fieldErrors[a]}),reset:()=>t(a=>{a.fieldErrors={},a.touchedFields={},a.hasBeenSubmitted=!1}),syncFormProps:a=>t(s=>{s.formProps=a}),setHydrated:()=>t(a=>{a.isHydrated=!0}),setFormElement:a=>{r().formElement!==a&&t(s=>{s.formElement=a})},validateField:async a=>{var c,u,f;const s=r().formElement;Q(s);const o=(c=r().formProps)==null?void 0:c.validator;Q(o),await((f=(u=Y(e).getState()).awaitValueUpdate)==null?void 0:f.call(u,a));const{error:i}=await o.validateField(new FormData(s),a);return i?(r().setFieldError(a,i),i):(r().clearFieldError(a),null)},validate:async()=>{var i;const a=r().formElement;Q(a);const s=(i=r().formProps)==null?void 0:i.validator;Q(s);const{error:o}=await s.validate(new FormData(a));o&&r().setFieldErrors(o.fieldErrors)},resetFormElement:()=>{var a;return(a=r().formElement)==null?void 0:a.reset()}})))),g=(e,t)=>pt(e)(t),Mv=(e,t)=>Y(e)(t),j=(e,t)=>{const r=y.useContext(Wr);if(e)return{formId:e};if(r)return r;throw new Error(`Unable to determine form for ${t}. Please use it inside a ValidatedForm or pass a 'formId'.`)};function gt({fetcher:e,subaction:t,formId:r}){var a;const n=re.useActionData();return e?(a=e.data)!=null&&a.fieldErrors?e.data:null:n!=null&&n.fieldErrors?typeof r=="string"&&n.formId?n.formId===r?n:null:!t&&!n.subaction||n.subaction===t?n:null:null}const nn=e=>{const t=gt(e),r=g(e.formId,n=>n.isHydrated);return ee.from(t==null?void 0:t.fieldErrors,r)},an=({formId:e})=>{const t=re.useMatches();if(typeof e=="string"){const r=zr(e),n=t.reverse().find(a=>a.data&&r in a.data);return n==null?void 0:n.data[r]}return null},sn=e=>{const{formId:t,defaultValuesProp:r}=e,n=g(t,o=>o.isHydrated),a=gt(e),s=an(e);return n?ee.hydratedData():a!=null&&a.repopulateFields?(Q(typeof a.repopulateFields=="object"),ee.serverData(a.repopulateFields)):r?ee.serverData(r):ee.serverData(s)},jv=({fetcher:e})=>{const t=re.useTransition();return e?e.state==="submitting":!!t.submission},Rv=(e,{formId:t})=>{const r=g(t,s=>s.touchedFields[e]),n=g(t,s=>s.setTouched),a=y.useCallback(s=>n(e,s),[e,n]);return[r,a]},Lv=(e,t)=>{const r=nn(t),n=g(t.formId,a=>a.fieldErrors[e]);return r.map(a=>a==null?void 0:a[e]).hydrateTo(n)},on=e=>{const{formId:t}=e;return g(t,r=>r.clearFieldError)},un=(e,t)=>{const r=sn(t),n=hn(t.formId);return r.map(a=>Ue(a,e)).hydrateTo(Ue(n,e))},cn=e=>g(e,t=>t.isSubmitting),fn=e=>g(e,t=>t.isValid()),ln=e=>g(e,t=>t.hasBeenSubmitted),dn=e=>g(e,t=>t.validateField),Gv=e=>g(e,t=>t.validate),Hv=()=>()=>{},vn=e=>g(e,t=>{var r,n;return(n=(r=t.formProps)==null?void 0:r.registerReceiveFocus)!=null?n:Hv}),Vv={},hn=e=>g(e,t=>{var r,n;return(n=(r=t.formProps)==null?void 0:r.defaultValues)!=null?n:Vv}),Kv=({formId:e})=>g(e,t=>t.setTouched),Nv=e=>g(e,t=>t.touchedFields),Bv=e=>g(e,t=>t.fieldErrors),yn=e=>g(e,t=>t.setFieldErrors),Uv=e=>g(e,t=>t.resetFormElement),qv=e=>g(e,t=>{var r;return(r=t.formProps)==null?void 0:r.action}),zv=e=>g(e,t=>{var r;return(r=t.formProps)==null?void 0:r.subaction}),Wv=(e,t)=>{const r=Y(e.formId),n=r(u=>{var f;return(f=u.fields[t])==null?void 0:f.value}),s=pt(e.formId)(u=>u.isHydrated),o=un(t,e),i=r(u=>{var f,l;return(l=(f=u.fields[t])==null?void 0:f.hydrated)!=null?l:!1}),c=r(u=>u.hydrateWithDefault);return y.useEffect(()=>{s&&!i&&c(t,o)},[o,t,c,i,s]),i?n:o},kv=(e,t)=>{const r=Y(e.formId),n=r(u=>{var f;return(f=u.fields[t])==null?void 0:f.resolveValueUpdate});y.useEffect(()=>{n==null||n()},[n]);const a=r(u=>u.register),s=r(u=>u.unregister);y.useEffect(()=>(a(t),()=>s(t)),[e.formId,t,a,s]);const o=r(u=>u.setValue),i=y.useCallback(u=>o(t,u),[t,o]);return[Wv(e,t),i]},Xv=e=>Y(e)(r=>r.setValue),pn=e=>{const t=j(e,"useIsSubmitting");return cn(t.formId)},gn=e=>{const t=j(e,"useIsValid");return fn(t.formId)},Yv=(e,t)=>{const{formId:r,handleReceiveFocus:n}=t!=null?t:{},a=j(r,"useField"),s=un(e,a),[o,i]=Rv(e,a),c=Lv(e,a),u=on(a),f=ln(a.formId),l=dn(a.formId),d=vn(a.formId);return y.useEffect(()=>{if(n)return d(e,n)},[n,e,d]),y.useMemo(()=>{const p={error:c,clearError:()=>u(e),validate:()=>{l(e)},defaultValue:s,touched:o,setTouched:i},m=Zd(K(C({},p),{name:e,hasBeenSubmitted:f,validationBehavior:t==null?void 0:t.validationBehavior}));return K(C({},p),{getInputProps:m})},[c,u,s,o,i,e,f,t==null?void 0:t.validationBehavior,l])},Zv=(e,t)=>{const r=j(t,"useControlField"),[n,a]=kv(r,e);return[n,a]},Jv=e=>{const t=j(e,"useControlField");return Xv(t.formId)};function Qv(e,t,r){return xn.json({fieldErrors:e.fieldErrors,subaction:e.subaction,repopulateFields:t,formId:e.formId},C({status:422},r))}const eh=(e,t)=>({[zr(e)]:t});function th(e,t,r,n){for(var a=e.length,s=r+(n?1:-1);n?s--:++s<a;)if(t(e[s],s,e))return s;return-1}var rh=th;function nh(e){return e!==e}var ah=nh;function sh(e,t,r){for(var n=r-1,a=e.length;++n<a;)if(e[n]===t)return n;return-1}var oh=sh,ih=rh,uh=ah,ch=oh;function fh(e,t,r){return t===t?ch(e,t,r):ih(e,uh,r)}var lh=fh,dh=lh;function vh(e,t){var r=e==null?0:e.length;return!!r&&dh(e,t,0)>-1}var hh=vh;function yh(e,t,r){for(var n=-1,a=e==null?0:e.length;++n<a;)if(r(t,e[n]))return!0;return!1}var ph=yh;function gh(){}var mh=gh,Le=Rr,bh=mh,_h=Qe,$h=1/0,Sh=Le&&1/_h(new Le([,-0]))[1]==$h?function(e){return new Le(e)}:bh,Ph=Sh,Eh=$r,Ih=hh,Ah=ph,Oh=Sr,Th=Ph,Fh=Qe,wh=200;function Ch(e,t,r){var n=-1,a=Ih,s=e.length,o=!0,i=[],c=i;if(r)o=!1,a=Ah;else if(s>=wh){var u=t?null:Th(e);if(u)return Fh(u);o=!1,a=Oh,c=new Eh}else c=t?[]:i;e:for(;++n<s;){var f=e[n],l=t?t(f):f;if(f=r||f!==0?f:0,o&&l===l){for(var d=c.length;d--;)if(c[d]===l)continue e;t&&c.push(l),i.push(f)}else a(c,l,r)||(c!==i&&c.push(l),i.push(f))}return i}var xh=Ch,Dh=xh;function Mh(e){return e&&e.length?Dh(e):[]}var jh=Mh;class mn{constructor(){this.dict=new Map,this.add=(t,r)=>{this.dict.has(t)?this.dict.get(t).push(r):this.dict.set(t,[r])},this.delete=t=>{this.dict.delete(t)},this.remove=(t,r)=>{if(!this.dict.has(t))return;const n=this.dict.get(t),a=n.indexOf(r);a!==-1&&n.splice(a,1),n.length===0&&this.dict.delete(t)},this.getAll=t=>{var r;return(r=this.dict.get(t))!=null?r:[]},this.entries=()=>this.dict.entries(),this.values=()=>this.dict.values(),this.has=t=>this.dict.has(t)}}const Rh=()=>{const e=y.useRef(null);return y.useCallback(()=>(e.current||(e.current=new mn),e.current),[])},Lh=e=>{pt.remove(e),Y.remove(e)};function bn(e,t){const r=y.useRef(!1);y.useEffect(()=>{e&&(r.current=!0),!e&&r.current&&(r.current=!1,t())})}var Gh=rt;function Hh(e,t){return Gh(e,t)}var Vh=Hh;const Kh=e=>t=>{e.filter(Boolean).forEach(r=>{typeof r=="function"?r(t):r!=null&&(r.current=t)})},Nh=typeof window!="undefined"?y.useLayoutEffect:y.useEffect,Bh=e=>{const t=y.useRef(e),r=t.current===e||Vh(t.current,e);return y.useEffect(()=>{r||(t.current=e)}),r?t.current:e},Uh=e=>new FormData(e);function qh(e){return e!==null}const zh=(e,t,r)=>{var s;const n=[...r.elements].map(o=>{const i=o instanceof RadioNodeList?o[0]:o;return i instanceof HTMLInputElement?i.name:null}).filter(qh).filter(o=>o in e),a=jh(n);for(const o of a){if(t.has(o)){t.getAll(o).forEach(c=>{c()});break}const i=r.elements.namedItem(o);if(!!i){if(i instanceof RadioNodeList){const c=(s=[...i].filter(u=>u instanceof HTMLInputElement).find(u=>u.value===i.value))!=null?s:i[0];if(c&&c instanceof HTMLInputElement){c.focus();break}}if(i instanceof HTMLInputElement){if(i.type==="hidden")continue;i.focus();break}}}},Wh=e=>{const[t]=y.useState(()=>Symbol("remix-validated-form-id"));return e!=null?e:t},kh=({resetAfterSubmit:e,formRef:t})=>{const r=pn(),n=gn();return bn(r,()=>{var a;n&&e&&((a=t.current)==null||a.reset())}),null};function Xh(e){let t=!1;return new Proxy(e,{get:(r,n)=>n==="preventDefault"?()=>{t=!0}:n==="defaultPrevented"?t:r[n]})}function Yh(m){var S=m,{validator:e,onSubmit:t,children:r,fetcher:n,action:a,defaultValues:s,formRef:o,onReset:i,subaction:c,resetAfterSubmit:u=!1,disableFocusOnError:f,method:l,replace:d,id:v}=S,p=At(S,["validator","onSubmit","children","fetcher","action","defaultValues","formRef","onReset","subaction","resetAfterSubmit","disableFocusOnError","method","replace","id"]);var St;const b=Wh(v),$=Bh(s),A=y.useMemo(()=>({formId:b,action:a,subaction:c,defaultValuesProp:$,fetcher:n}),[a,n,b,$,c]),P=gt(A),T=an(A),_n=jv(A),ce=y.useRef(null),$n=(St=n==null?void 0:n.Form)!=null?St:re.Form,Sn=re.useSubmit(),Oe=yn(b),Pn=g(b,h=>h.setFieldError),En=g(b,h=>h.reset),In=Mv(b,h=>h.reset),An=g(b,h=>h.startSubmit),Te=g(b,h=>h.endSubmit),mt=g(b,h=>h.syncFormProps),bt=g(b,h=>h.setHydrated),On=g(b,h=>h.setFormElement);y.useEffect(()=>(bt(),()=>Lh(b)),[b,bt]);const fe=Rh(),_t=y.useCallback((h,F)=>(fe().add(h,F),()=>{fe().remove(h,F)}),[fe]);Nh(()=>{var h;mt({action:a,defaultValues:(h=$!=null?$:T)!=null?h:{},subaction:c,registerReceiveFocus:_t,validator:e})},[a,$,_t,c,mt,T,e]),y.useEffect(()=>{var h;Oe((h=P==null?void 0:P.fieldErrors)!=null?h:{})},[P==null?void 0:P.fieldErrors,Oe,Pn]),bn(_n,()=>{Te()});let $t=D.default.useRef();y.useEffect(()=>{let h=ce.current;if(!h)return;function F(Z){if(!(Z.target instanceof HTMLElement))return;let R=Z.target.closest("button,input[type=submit]");R&&R.form===h&&R.type==="submit"&&($t.current=R)}return window.addEventListener("click",F,{capture:!0}),()=>{window.removeEventListener("click",F,{capture:!0})}},[]);const Tn=async h=>{An();const F=await e.validate(Uh(h.currentTarget));if(F.error)Te(),Oe(F.error.fieldErrors),f||zh(F.error.fieldErrors,fe(),ce.current);else{const Z=Xh(h);if(await(t==null?void 0:t(F.data,Z)),Z.defaultPrevented){Te();return}const R=h.nativeEvent.submitter;n?n.submit(R||h.currentTarget):Sn(R||h.currentTarget,{method:l,replace:d}),$t.current=null}};return D.default.createElement($n,K(C({ref:Kh([ce,o,On])},p),{id:v,action:a,method:l,replace:d,onSubmit:h=>{h.preventDefault(),Tn(h)},onReset:h=>{i==null||i(h),!h.defaultPrevented&&(En(),In())}}),D.default.createElement(Wr.Provider,{value:A},D.default.createElement(kh,{formRef:ce,resetAfterSubmit:u}),c&&D.default.createElement("input",{type:"hidden",value:c,name:"subaction"}),v&&D.default.createElement("input",{type:"hidden",value:v,name:he}),r))}var Zh=qr;function Jh(e,t,r){return e==null?e:Zh(e,t,r)}var Qh=Jh;const hr=e=>{const t=new mn;return e.forEach(([r,n])=>t.add(r,n)),[...t.entries()].reduce((r,[n,a])=>Qh(r,n,a.length===1?a[0]:a),{})},yr=e=>"entries"in e&&typeof e.entries=="function"?hr([...e.entries()]):hr(Object.entries(e));function ey(e){return{validate:async t=>{const r=yr(t),n=await e.validate(r);return n.error?{data:void 0,error:{fieldErrors:n.error,subaction:r.subaction,formId:r[he]},submittedData:r,formId:r[he]}:{data:n.data,error:void 0,submittedData:r,formId:r[he]}},validateField:(t,r)=>e.validateField(yr(t),r)}}const ty=e=>{const t=j(e,"useFormState"),r=cn(t.formId),n=ln(t.formId),a=Nv(t.formId),s=fn(t.formId),o=qv(t.formId),i=zv(t.formId),c=hn(t.formId),f=sn(t).hydrateTo(c),l=Bv(t.formId),v=nn(t).hydrateTo(l);return y.useMemo(()=>({action:o,subaction:i,defaultValues:f,fieldErrors:v!=null?v:{},hasBeenSubmitted:n,isSubmitting:r,touchedFields:a,isValid:s}),[o,n,f,v,r,s,i,a])},ry=e=>{const t=j(e,"useFormHelpers"),r=Kv(t),n=dn(t.formId),a=Gv(t.formId),s=on(t),o=yn(t.formId),i=Uv(t.formId);return y.useMemo(()=>({setTouched:r,validateField:n,clearError:s,validate:a,clearAllErrors:()=>o({}),reset:i}),[s,i,o,r,a,n])},ny=e=>{const t=j(e,"useFormContext"),r=ty(e),{clearError:n,setTouched:a,validateField:s,clearAllErrors:o,validate:i,reset:c}=ry(e),u=vn(t.formId),f=y.useCallback((...l)=>{l.forEach(d=>{n(d)})},[n]);return y.useMemo(()=>K(C({},r),{setFieldTouched:a,validateField:s,clearError:f,registerReceiveFocus:u,clearAllErrors:o,validate:i,reset:c}),[o,f,u,c,a,r,i,s])};exports.ValidatedForm=Yh;exports.createValidator=ey;exports.setFormDefaults=eh;exports.useControlField=Zv;exports.useField=Yv;exports.useFormContext=ny;exports.useIsSubmitting=pn;exports.useIsValid=gn;exports.useUpdateControlledField=Jv;exports.validationError=Qv;
18
18
  //# sourceMappingURL=remix-validated-form.cjs.js.map