react-f0rm 0.9.0 → 0.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +120 -3
- package/dist/devtools/index.cjs.js +1 -1
- package/dist/devtools/index.cjs.js.map +1 -1
- package/dist/devtools/index.mjs +1 -1
- package/dist/devtools/index.mjs.map +1 -1
- package/dist/form-BQsb2CuG.mjs +2 -0
- package/dist/form-BQsb2CuG.mjs.map +1 -0
- package/dist/{form-7sbcY2uT.d.ts → form-DSwruZIg.d.ts} +56 -2
- package/dist/form-DZK8HgZ7.cjs.js +2 -0
- package/dist/form-DZK8HgZ7.cjs.js.map +1 -0
- package/dist/index.cjs.js +1 -1
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +65 -6
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/dist/index.umd.js +139 -6
- package/dist/index.umd.js.map +1 -1
- package/dist/index.umd.min.js +2 -2
- package/dist/index.umd.min.js.map +1 -1
- package/dist/resolvers/standard-schema.cjs.js +1 -1
- package/dist/resolvers/standard-schema.mjs +1 -1
- package/dist/resolvers/yup.cjs.js +1 -1
- package/dist/resolvers/yup.d.ts +1 -1
- package/dist/resolvers/yup.mjs +1 -1
- package/dist/resolvers/zod.cjs.js +1 -1
- package/dist/resolvers/zod.d.ts +1 -1
- package/dist/resolvers/zod.mjs +1 -1
- package/dist/{validate-DXGZBon4.d.ts → validate-CqRu0f-o.d.ts} +1 -1
- package/package.json +1 -1
- package/dist/form-DbDDJ8bt.cjs.js +0 -2
- package/dist/form-DbDDJ8bt.cjs.js.map +0 -1
- package/dist/form-DsydpBhT.mjs +0 -2
- package/dist/form-DsydpBhT.mjs.map +0 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { a as FieldPath, N as Name, F as Form$1, V as ValidationMode, P as PathValueOf, b as FieldError, c as Path, O as Options } from './form-
|
|
2
|
-
export { d as FieldErrorEntry, e as FieldState, f as FormValidateFn, g as FormValidateMeta, H as HandleSubmitOptions, h as PathValue, R as ReValidateMode, i as ResetFieldOptions, j as ResetOptions, S as SetFieldOptions, k as SetFocusOptions, l as SetServerErrorsOptions, m as VALIDATION_OUTCOME, n as ValidateResult, o as ValidationOutcome, p as changeValue, q as changeValueByPath, r as clearErrors, s as createForm, t as ensureValidate, u as getDirtyFields, v as getError, w as getErrorByPath, x as getErrors, y as getFieldErrors, z as getFieldErrorsByPath, A as getFieldState, B as getFirstError, C as getTouchedFields, D as getValue, E as getValueByPath, G as getValues, I as handleSubmit, J as hasErrors, K as hasTouched, L as hasTouchedByPath, M as incrementSubmitCount, Q as isDirty, T as isTouched, U as removeField, W as removeFieldByPath, X as reset, Y as resetField, Z as
|
|
3
|
-
import { V as Validator } from './validate-
|
|
1
|
+
import { a as FieldPath, N as Name, F as Form$1, V as ValidationMode, P as PathValueOf, b as FieldError, c as Path, O as Options } from './form-DSwruZIg.js';
|
|
2
|
+
export { d as FieldErrorEntry, e as FieldState, f as FormValidateFn, g as FormValidateMeta, H as HandleSubmitOptions, h as PathValue, R as ReValidateMode, i as ResetFieldOptions, j as ResetOptions, S as SetFieldOptions, k as SetFocusOptions, l as SetServerErrorsOptions, m as VALIDATION_OUTCOME, n as ValidateResult, o as ValidationOutcome, p as changeValue, q as changeValueByPath, r as clearErrors, s as createForm, t as ensureValidate, u as getDirtyFields, v as getError, w as getErrorByPath, x as getErrors, y as getFieldErrors, z as getFieldErrorsByPath, A as getFieldState, B as getFirstError, C as getTouchedFields, D as getValue, E as getValueByPath, G as getValues, I as handleSubmit, J as hasErrors, K as hasTouched, L as hasTouchedByPath, M as incrementSubmitCount, Q as isDirty, T as isTouched, U as removeField, W as removeFieldByPath, X as reset, Y as resetField, Z as revalidateFormOnChange, _ as setDisabled, $ as setError, a0 as setErrorByPath, a1 as setFocus, a2 as setInitialValues, a3 as setIsSubmitting, a4 as setServerErrors, a5 as setSubmitSuccessful, a6 as setTouched, a7 as setTouchedByPath, a8 as setValidatingByPath, a9 as setValue, aa as setValueByPath, ab as trigger, ac as unsetValidatingByPath, ad as validate } from './form-DSwruZIg.js';
|
|
3
|
+
import { V as Validator } from './validate-CqRu0f-o.js';
|
|
4
4
|
import * as React from 'react';
|
|
5
5
|
import { ReactNode } from 'react';
|
|
6
6
|
import { EventEmitter } from '@for-fun/event-emitter';
|
|
@@ -137,6 +137,61 @@ declare function useFieldArray(options: {
|
|
|
137
137
|
name: Name;
|
|
138
138
|
form?: Form$1;
|
|
139
139
|
}): UseFieldArrayResult;
|
|
140
|
+
/**
|
|
141
|
+
* The result of {@link useFieldArrayItem}. Mirrors the {@link useField}
|
|
142
|
+
* return shape (`value`/`errors`/`error`) plus the row's `index` and
|
|
143
|
+
* `name` (path key) so nested fields can build on it —
|
|
144
|
+
* `useField({name: ['tags', item.index, 'label']})`.
|
|
145
|
+
*/
|
|
146
|
+
interface UseFieldArrayItemResult<TValue = any> {
|
|
147
|
+
value: TValue;
|
|
148
|
+
/** Overwrite this row's value in place (same array-layer write as
|
|
149
|
+
* `update(index, value)`: the row's id and position are kept). */
|
|
150
|
+
setValue: (value: TValue) => void;
|
|
151
|
+
/** Every error registered for the row's path, insertion order; the
|
|
152
|
+
* shared empty constant while clean, so consumers can memo on it. */
|
|
153
|
+
errors: FieldError[];
|
|
154
|
+
/** First error's message — the display text — or undefined. */
|
|
155
|
+
error: string | undefined;
|
|
156
|
+
/** The row's current path key (JSON-stringified segments, e.g.
|
|
157
|
+
* `["tags",0]`); moves with the row across reorder/remove. */
|
|
158
|
+
name: string;
|
|
159
|
+
/** The row's current position in the array. `-1` while the row is being
|
|
160
|
+
* removed (or when no useFieldArray is mounted at `name`): reads return
|
|
161
|
+
* undefined and nothing writes the dangling path. */
|
|
162
|
+
index: number;
|
|
163
|
+
form: Form$1;
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Subscribe to a single row of a {@link useFieldArray} field — the
|
|
167
|
+
* per-item counterpart `useFieldArray` alone cannot offer. `useFieldArray`
|
|
168
|
+
* subscribes to the whole branch, so any row's edit re-renders the
|
|
169
|
+
* component holding the array (and, without memoization, every row);
|
|
170
|
+
* `useFieldArrayItem` scopes what re-renders to one row identified by its
|
|
171
|
+
* stable id: editing row K re-renders only row K's component, and a
|
|
172
|
+
* whole-array rewrite re-renders only rows whose value reference actually
|
|
173
|
+
* changed. Pair it with a `React.memo` row component that takes stable
|
|
174
|
+
* props (`form`, `id`) so the array component's own re-render cannot drag
|
|
175
|
+
* the rows along.
|
|
176
|
+
*
|
|
177
|
+
* Rows whose index migrates — remove/move/swap/insert reshuffles —
|
|
178
|
+
* re-render by design: the row's path contains the index, exactly like
|
|
179
|
+
* TanStack Form's per-field api. The win is single-row edits staying
|
|
180
|
+
* single-row.
|
|
181
|
+
*
|
|
182
|
+
* Value reads and writes live on the array layer — the same layer every
|
|
183
|
+
* `useFieldArray` operation touches — so `value`, `setValue` and
|
|
184
|
+
* `update`/`append`/… always agree with each other.
|
|
185
|
+
*
|
|
186
|
+
* @param options `name` of the array (a useFieldArray must be mounted at
|
|
187
|
+
* the same path — it publishes the id table), the row's `id` from
|
|
188
|
+
* `fields[i].id`, and optionally an explicit `form`
|
|
189
|
+
*/
|
|
190
|
+
declare function useFieldArrayItem<TValue = any>(options: {
|
|
191
|
+
name: Name;
|
|
192
|
+
id: string;
|
|
193
|
+
form?: Form$1;
|
|
194
|
+
}): UseFieldArrayItemResult<TValue>;
|
|
140
195
|
|
|
141
196
|
declare const FormContext: React.Context<any>;
|
|
142
197
|
declare const FormProvider: React.Provider<any>;
|
|
@@ -152,8 +207,8 @@ declare const FormProvider: React.Provider<any>;
|
|
|
152
207
|
declare function useFormContext<T extends Record<string, any> = any>(): Form$1<T>;
|
|
153
208
|
/**
|
|
154
209
|
* Create an isolated bundle of form-context bindings: its own React context
|
|
155
|
-
* plus `useField` / `useFieldArray` / `
|
|
156
|
-
* their form from it.
|
|
210
|
+
* plus `useField` / `useFieldArray` / `useFieldArrayItem` /
|
|
211
|
+
* `useFormContext` hooks that resolve their form from it.
|
|
157
212
|
*
|
|
158
213
|
* Why: the module-level {@link FormContext} works fine for a single form per
|
|
159
214
|
* subtree, but nesting two forms (or reusing a component inside a different
|
|
@@ -178,6 +233,10 @@ declare function createFormContext<TValues extends Record<string, any> = any>():
|
|
|
178
233
|
useFieldArray: (options: {
|
|
179
234
|
name: FieldPath<TValues> | Name;
|
|
180
235
|
}) => UseFieldArrayResult;
|
|
236
|
+
useFieldArrayItem: <TValue = any>(options: {
|
|
237
|
+
name: FieldPath<TValues> | Name;
|
|
238
|
+
id: string;
|
|
239
|
+
}) => UseFieldArrayItemResult<TValue>;
|
|
181
240
|
};
|
|
182
241
|
declare const CheckboxGroupContext: React.Context<any>;
|
|
183
242
|
declare const CheckboxGroupProvider: React.Provider<any>;
|
|
@@ -514,5 +573,5 @@ interface SelectComponent {
|
|
|
514
573
|
}
|
|
515
574
|
declare const Select: SelectComponent;
|
|
516
575
|
|
|
517
|
-
export { Checkbox, CheckboxGroupContext, CheckboxGroupProvider, Field, FieldError, FieldPath, Form, FormContext, Form$1 as FormInstance, FormProvider, Name, Options, Path, PathValueOf, Select, ValidationMode, Validator, createFormContext, fieldErrorId, subscribe, useCanSubmit, useCheckboxGroupContext, useDirtyFields, useError, useErrorByPath, useField, useFieldArray, useFieldErrors, useFieldErrorsByPath, useForm, useFormContext, useHasErrors, useIsDirty, useIsSubmitting, useSubmitCount, useTouched, useTouchedByPath, useTouchedFields, useValue, useValueByPath, useWatch };
|
|
576
|
+
export { Checkbox, CheckboxGroupContext, CheckboxGroupProvider, Field, FieldError, FieldPath, Form, FormContext, Form$1 as FormInstance, FormProvider, Name, Options, Path, PathValueOf, Select, ValidationMode, Validator, createFormContext, fieldErrorId, subscribe, useCanSubmit, useCheckboxGroupContext, useDirtyFields, useError, useErrorByPath, useField, useFieldArray, useFieldArrayItem, useFieldErrors, useFieldErrorsByPath, useForm, useFormContext, useHasErrors, useIsDirty, useIsSubmitting, useSubmitCount, useTouched, useTouchedByPath, useTouchedFields, useValue, useValueByPath, useWatch };
|
|
518
577
|
export type { FieldRules, SubscribeEvent, SubscribeOptions, WatchScope };
|
package/dist/index.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import*as e from"react";import t,{useCallback as n,useRef as r,useState as o,useEffect as i,useMemo as u,useContext as s,useReducer as a,createContext as c,createElement as l}from"react";function f(e,t){for(var n=arguments.length,r=new Array(n>2?n-2:0),o=2;o<n;o++)r[o-2]=arguments[o];(e.get(t)||[]).forEach(function(e){return e.apply(void 0,r)})}function d(e,t,n){var r=function(e,t){var n=e.get(t);if(n)return n;var r=new Set;return e.set(t,r),r}(e,t);return r.add(n),function(){return r.delete(n)}}const m=new Map;function h(e){if(Array.isArray(e))return e;const t=m.get(e);if(t)return t;const n=function(e){const t=[];let n="";const r=()=>{t.push(n),n=""};for(let o=0;o<e.length;o++){const i=e[o];if("."===i)""!==n&&r();else if("["===i){""!==n&&r();const i=e[o+1];if('"'===i||"'"===i){const n=e.indexOf(i,o+2);if(-1===n)throw new TypeError(`Unterminated quote in path: ${e}`);if("]"!==e[n+1])throw new TypeError(`Expected "]" after quoted segment in path: ${e}`);t.push(e.slice(o+2,n)),o=n+1}else{const n=e.indexOf("]",o+1);if(-1===n)throw new TypeError(`Unterminated bracket in path: ${e}`);const r=e.slice(o+1,n);t.push(/^-?\d+$/.test(r)?Number(r):r),o=n}}else n+=i}""===n&&0!==t.length||r();return t}(e);return m.set(e,n),n}function y(e,t){return t.reduce((e,t)=>{if(null!=e)return e[t]},e)}function v(e,t){if(!t.length||null==e)return e;const[n,...r]=t;if(r.length){const t=v(e[n],r);return t===e[n]?e:p(e,[n],t)}if(Array.isArray(e)){if(!(n in e))return e;const t=e.slice();return delete t[n],t}if("object"!=typeof e||!(n in e))return e;const o={...e};return delete o[n],o}function p(e,t,n){if(!t.length)return n;const[r,...o]=t;if("number"==typeof r){const t=Array.isArray(e)?e.slice():[];return t[r]=p(t[r],o,n),t}return{...e,[r]:p(e&&e[r],o,n)}}function g(e,t,n,r){if(!t.length)return n;let o=e,i=null,u="";for(let s=0;s<t.length;s++){const a=t[s];if(!r.has(o)){let t;t="number"==typeof a?Array.isArray(o)?o.slice():[]:{...o},r.add(t),0===s?e=t:i[u]=t,o=t}s===t.length-1?o[a]=n:(i=o,u=a,o=o[a])}return e}function b(e){return e&&"function"==typeof e.then}function k(e,t){if(Object.is(e,t))return!0;if(e instanceof Date&&t instanceof Date)return e.getTime()===t.getTime();if(!e||!t||"object"!=typeof e||"object"!=typeof t)return!1;const n=Array.isArray(e);if(n!==Array.isArray(t))return!1;if(n){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(!k(e[n],t[n]))return!1;return!0}const r=Object.getPrototypeOf(e);if(r!==Object.prototype&&null!==r)return!1;if(Object.getPrototypeOf(t)!==r)return!1;const o=Object.keys(e),i=Object.keys(t);if(o.length!==i.length)return!1;for(const n of o)if(!k(e[n],t[n]))return!1;return!0}function S(e,t,n,r){return new Promise((o,i)=>{if(r())return void i();if(n())return void o();const u=d(e,t,()=>{if(r())return u(),void i();n()&&(u(),o())})})}function E(e){const t=h(e);return{value:t,key:JSON.stringify(t)}}const w=Symbol("validation-outcome");function V(e){return{emitter:new Map,...e,mode:e?.mode??"onSubmit",reValidateMode:e?.reValidateMode??"onChange",disabled:e?.disabled??!1,initialValues:e?.initialValues??{},values:new Map,deleted:new Set,errors:new Map,touched:new Set,validators:new Map,changeHandlers:new Map,validating:new Set,parsedValues:void 0,isSubmitting:!1,submitCount:0,isSubmitSuccessful:void 0}}function O(e){const{initialValues:t,parsedValues:n,values:r,deleted:o}=e,i=new Set;let u=n??t;for(const[e,t]of r)u=g(u,JSON.parse(e),t,i);for(const e of o)u=v(u,JSON.parse(e));return u}function _(e,t){return A(e,E(t))}function A({initialValues:e,parsedValues:t,values:n,deleted:r},o){return n.has(o.key)?n.get(o.key):r.has(o.key)?void 0:y(t??e,o.value)}function x(e,t,n,r){T(e,E(t),n,r)}function T(e,t,n,r){const{emitter:o,values:i,deleted:u}=e;i.set(t.key,n),le(u,t),function(e,{key:t}){const n=X.get(e);if(!n?.size)return;const r=`${t.slice(0,-1)},`;for(const e of n.keys())e.startsWith(r)&&n.delete(e)}(e,t),!1===r?.shouldDirty&&ee(e,t,n),re(e),r?.shouldTouch&&G(e,t),r?.shouldValidate&&e.validators.get(t.key)?.(),f(o,"change",t)}function C(e,t,n,r){L(e,E(t),n,r)}function L(e,t,n,r){!1===r?.shouldDirty&&ee(e,t,n);const o=e.changeHandlers.get(t.key);o?o(n):T(e,t,n,r)}function j(e,t){return D(e,E(t))}function D({errors:e},t){return e.get(t.key)?.[0]}const M=[];function N(e,t){return B(e,E(t))}function B({errors:e},t){return e.get(t.key)??M}function P({errors:e}){const t=[];for(const[n,r]of e){const e=JSON.parse(n).join(".");for(const{type:n,message:o}of r)t.push({path:e,type:n,message:o})}return t}function $({errors:e}){return e.values().next().value?.[0]?.message}function q(e,t){const n=E(t),{values:r,touched:o,validating:i}=e,u=r.get(n.key);return{value:A(e,n),error:D(e,n),errors:B(e,n),isDirty:r.has(n.key)&&Z(e,n.key,n.value)!==u,isTouched:o.has(n.key),isValidating:i.has(n.key)}}function H({emitter:e,validating:t},n){t.delete(n.key),f(e,"validating",n)}function I({emitter:e,validating:t},n){t.add(n.key),f(e,"validating",n)}function R(e,t,n){U(e,E(t),n)}function U({emitter:e,errors:t},n,r){const o=function(e){if("string"==typeof e)return e?[{type:"custom",message:e}]:void 0;if(pe(e))return[e];if(!e)return;const t=[];return e.forEach(e=>{"string"==typeof e&&e?t.push({type:"custom",message:e}):pe(e)&&t.push(e)}),t.length?t:void 0}(r);o?t.set(n.key,o):t.delete(n.key),f(e,"errors",n)}function F(e,t){const{emitter:n,errors:r}=e;if(void 0===t)return r.clear(),void f(n,"errors");const o="string"==typeof t||ve(t)?[E(t)]:t.map(e=>E(e));for(const{key:e}of o)r.delete(e);for(const e of o)f(n,"errors",e)}function J(e,t,n){n?.keepExisting||F(e);for(const[n,r]of Object.entries(t))R(e,n,(Array.isArray(r)?r:[r]).map(e=>({type:"server",message:e})))}function W(e,t){G(e,E(t))}function G({emitter:e,touched:t},n){t.has(n.key)||(t.add(n.key),f(e,"touched",n))}function K(e,t){return z(e,E(t))}function z({touched:e},t){return e.has(t.key)}function Y(e){let t=!1;return Q(e,()=>{t=!0}),t}function Q(e,t){for(const[n,r]of e.values){const o=JSON.parse(n);Z(e,n,o)!==r&&t(o.join("."))}}const X=new WeakMap;function Z(e,t,n){const r=X.get(e);return r?.has(t)?r.get(t):y(e.initialValues,n)}function ee(e,{key:t},n){let r=X.get(e);r||(r=new Map,X.set(e,r)),r.set(t,n)}function te(e,t){const n=X.get(e);n&&(void 0===t?n.clear():n.delete(t))}const ne=new WeakMap;function re(e){const t=ne.get(e);t&&t.version++}function oe(e){const t={};return Q(e,e=>{t[e]=!0}),t}function ie(e){let t=ne.get(e);if(t){if(t.version>0){const n=oe(e);(function(e,t){const n=Object.keys(e);return n.length===Object.keys(t).length&&n.every(e=>!0===t[e])})(t.result,n)||(t.result=n),t.version=0}}else t={version:0,result:oe(e)},ne.set(e,t);return t.result}function ue({touched:e}){return Array.from(e,e=>JSON.parse(e).join("."))}function se({touched:e}){return e.size>0}function ae(e,t){ce(e,E(t))}function ce(e,{key:t,value:n}){const{emitter:r,values:o,touched:i,errors:u,validating:s,deleted:a}=e;o.delete(t),i.delete(t),u.delete(t),s.delete(t),te(e,t),function(e,t){for(let n=1;n<t.length;n++)if(e.has(JSON.stringify(t.slice(0,n))))return!0;const n=`${JSON.stringify(t).slice(0,-1)},`;for(const t of e.keys())if(t.startsWith(n))return!0;return!1}(o,n)||a.add(t),re(e),f(r,"change"),f(r,"touched"),f(r,"errors"),f(r,"validating")}function le(e,{key:t}){if(e.size)for(const n of e)(n===t||n.startsWith(`${t.slice(0,-1)},`)||t.startsWith(`${n.slice(0,-1)},`))&&e.delete(n)}function fe(e,t){e.initialValues===t||k(e.initialValues,t)||(e.initialValues=t,e.parsedValues=void 0,e.values.clear(),e.deleted.clear(),te(e),re(e),f(e.emitter,"change"))}function de(e,t,n){const r=n?.keepDirtyValues?Object.keys(ie(e)).map(t=>({key:t,value:_(e,t)})):[];e.initialValues=t,e.parsedValues=void 0,n?.keepErrors||F(e);const{emitter:o,touched:i,values:u,deleted:s,validating:a}=e;u.clear(),s.clear(),te(e),n?.keepTouched||i.clear(),a.clear(),n?.keepIsSubmitting||(e.isSubmitting=!1),n?.keepSubmitCount||(e.submitCount=0),n?.keepIsSubmitted||(e.isSubmitSuccessful=void 0),re(e);for(const{key:t,value:n}of r)T(e,E(t),n);f(o,"change"),f(o,"touched"),f(o,"validating"),f(o,"submitting"),f(o,"submitCount"),f(o,"submitSuccessful"),f(o,"reset")}function me(e,t,n){const r=E(t),{emitter:o,values:i,touched:u,errors:s,deleted:a}=e;if(i.delete(r.key),te(e,r.key),void 0!==e.parsedValues){e.parsedValues=v(e.parsedValues,r.value);const t=y(e.initialValues,r.value);void 0!==t&&i.set(r.key,t)}n&&"value"in n&&i.set(r.key,n.value),le(a,r),f(o,"change"),!n?.keepTouched&&u.delete(r.key)&&f(o,"touched",r),!n?.keepErrors&&s.delete(r.key)&&f(o,"errors",r),re(e)}function he({errors:e}){return e.size>0}async function ye(e,t){const n=()=>S(e.emitter,"validating",()=>Se(e),()=>!1);if(void 0===t)return e.validators.forEach(e=>e()),await n(),e.validate&&await Ve(e),!he(e);const r="string"==typeof t||ve(t)?[E(t).key]:t.map(e=>E(e).key);return r.forEach(t=>e.validators.get(t)?.()),await n(),r.every(t=>!e.errors.has(t))}function ve(e){return e.some(e=>"number"==typeof e)}function pe(e){return!!e&&"object"==typeof e&&"string"==typeof e.type&&"string"==typeof e.message}function ge(e,t,n=[]){Object.entries(t).forEach(([t,r])=>{const o=[...n,...h(t)];"string"==typeof r?r&&R(e,o,r):Array.isArray(r)||pe(r)?R(e,o,r):r&&"object"==typeof r&&ge(e,r,o)})}function be(e,t){if(t){if("object"==typeof t&&w in t){const n=t;return n.errors&&ge(e,n.errors),void function(e,t){void 0!==t&&t!==e.parsedValues&&(e.parsedValues=t,f(e.emitter,"change"))}(e,n.values)}ge(e,t)}}const ke="__form_validate__";function Se(e){for(const t of e.validating)if(t!==ke)return!1;return!0}const Ee=Symbol("form-validate-settled"),we=new WeakMap;function Ve(e){const t=e.validate;if(!t)return Promise.resolve();const n=e.validateDebounce??0;if(n<=0){const n=new AbortController;return Promise.resolve(t(O(e),{form:e,signal:n.signal})).then(t=>{be(e,t)})}const r=function(e){let t=we.get(e);return t||(t={timer:null,controller:null,round:null,marked:!1,waiters:[]},we.set(e,t)),t}(e);return null!==r.timer?clearTimeout(r.timer):(r.marked=!0,e.validating.add(ke),f(e.emitter,"validating")),r.timer=setTimeout(()=>{r.timer=null;const t=r.round={};(function(e,t,n){const r=e.validate;if(!r)return Promise.resolve();t.controller?.abort();const o=t.controller=new AbortController;let i;try{i=Promise.resolve(r(O(e),{form:e,signal:o.signal}))}catch(e){i=Promise.reject(e)}return i.then(r=>{t.round===n&&be(e,r)},e=>{if(t.round===n)throw e})})(e,r,t).then(()=>Oe(e,r,t,Ee),n=>Oe(e,r,t,n))},n),new Promise((e,t)=>{r.waiters.push({resolve:e,reject:t})})}function Oe(e,t,n,r){if(t.round!==n)return;if(t.round=null,null!==t.timer)return;t.marked&&(t.marked=!1,e.validating.delete(ke),f(e.emitter,"validating"));const o=t.waiters;t.waiters=[];for(const e of o)r===Ee?e.resolve():e.reject(r)}async function _e(e){if(e.validators.forEach(e=>e()),await S(e.emitter,"validating",()=>Se(e),()=>he(e)).catch(()=>{throw new Error($(e))}),e.validate&&(await Ve(e),he(e)))throw new Error($(e))}async function Ae(e){return _e(e).catch(e=>e.message)}function xe(e,t){e.isSubmitting=t,f(e.emitter,"submitting")}function Te(e){e.submitCount++,f(e.emitter,"submitCount")}function Ce(e,t){e.isSubmitSuccessful=t,f(e.emitter,"submitSuccessful")}function Le(e,t){e.disabled=t,f(e.emitter,"disabled")}function je(e){if(e.startsWith("["))try{const t=JSON.parse(e);if(Array.isArray(t))return t.join(".")}catch{}return e}function De(e,t){const{onSubmit:n,onValidSubmit:r,onInvalidSubmit:o,shouldFocusError:i=!0}=t??{};return async t=>{t&&"function"==typeof t.preventDefault&&t.preventDefault();const u=t?.currentTarget;xe(e,!0),Te(e);const s=O(e);if(u&&"function"==typeof u.checkValidity&&!1===u.checkValidity()){if(u.reportValidity(),i&&"function"==typeof u.querySelector){const e=u.querySelector(":invalid");e&&"function"==typeof e.focus&&e.focus()}return xe(e,!1),Ce(e,!1),void(o&&o(function(e){const t=[],{elements:n}=e;for(let e=0;e<n.length;e++){const r=n[e];r.name&&"function"==typeof r.checkValidity&&!r.checkValidity()&&t.push({path:je(r.name),type:"native",message:r.validationMessage})}return t}(u),s))}if(await Ae(e)){if(xe(e,!1),Ce(e,!1),i){const t=e.errors.keys().next().value;void 0!==t&&f(e.emitter,"focusError",t)}o&&o(P(e),s)}else try{const o=O(e);n&&await n(o,t),r&&await r(o,t),Ce(e,!0)}catch{Ce(e,!1)}finally{xe(e,!1)}}}function Me(e,t,n){const{key:r}=E(t);n?f(e.emitter,"focusError",r,n):f(e.emitter,"focusError",r)}function Ne(e,t){switch(e){case"required":return"This field is required";case"min":return`Must be at least ${t}`;case"max":return`Must be at most ${t}`;case"minLength":return`Must be at least ${t} characters`;case"maxLength":return`Must be at most ${t} characters`;case"pattern":return"Invalid format";default:return"Invalid value"}}var Be,Pe={exports:{}},$e={};var qe,He,Ie={};var Re=(He||(He=1,"production"===process.env.NODE_ENV?Pe.exports=function(){if(Be)return $e;Be=1;var e=t,n="function"==typeof Object.is?Object.is:function(e,t){return e===t&&(0!==e||1/e==1/t)||e!=e&&t!=t},r=e.useState,o=e.useEffect,i=e.useLayoutEffect,u=e.useDebugValue;function s(e){var t=e.getSnapshot;e=e.value;try{var r=t();return!n(e,r)}catch(e){return!0}}var a="undefined"==typeof window||void 0===window.document||void 0===window.document.createElement?function(e,t){return t()}:function(e,t){var n=t(),a=r({inst:{value:n,getSnapshot:t}}),c=a[0].inst,l=a[1];return i(function(){c.value=n,c.getSnapshot=t,s(c)&&l({inst:c})},[e,n,t]),o(function(){return s(c)&&l({inst:c}),e(function(){s(c)&&l({inst:c})})},[e]),u(n),n};return $e.useSyncExternalStore=void 0!==e.useSyncExternalStore?e.useSyncExternalStore:a,$e}():Pe.exports=(qe||(qe=1,"production"!==process.env.NODE_ENV&&function(){function e(e){var t=e.getSnapshot;e=e.value;try{var n=t();return!r(e,n)}catch(e){return!0}}"undefined"!=typeof __REACT_DEVTOOLS_GLOBAL_HOOK__&&"function"==typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart&&__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(Error());var n=t,r="function"==typeof Object.is?Object.is:function(e,t){return e===t&&(0!==e||1/e==1/t)||e!=e&&t!=t},o=n.useState,i=n.useEffect,u=n.useLayoutEffect,s=n.useDebugValue,a=!1,c=!1,l="undefined"==typeof window||void 0===window.document||void 0===window.document.createElement?function(e,t){return t()}:function(t,l){a||void 0===n.startTransition||(a=!0,console.error("You are using an outdated, pre-release alpha of React 18 that does not support useSyncExternalStore. The use-sync-external-store shim will not work correctly. Upgrade to a newer pre-release."));var f=l();if(!c){var d=l();r(f,d)||(console.error("The result of getSnapshot should be cached to avoid an infinite loop"),c=!0)}var m=(d=o({inst:{value:f,getSnapshot:l}}))[0].inst,h=d[1];return u(function(){m.value=f,m.getSnapshot=l,e(m)&&h({inst:m})},[t,f,l]),i(function(){return e(m)&&h({inst:m}),t(function(){e(m)&&h({inst:m})})},[t]),s(f),f};Ie.useSyncExternalStore=void 0!==n.useSyncExternalStore?n.useSyncExternalStore:l,"undefined"!=typeof __REACT_DEVTOOLS_GLOBAL_HOOK__&&"function"==typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop&&__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(Error())}()),Ie)),Pe.exports);function Ue(e,t){return e.startsWith(`${t.slice(0,-1)},`)}function Fe(e,t,n,r,o){const{key:i}=n;return d(e,t,e=>{(void 0===e||e.key===i||Ue(i,e.key)||"branch"===r&&Ue(e.key,i))&&o()})}function Je(e,t,n,r){return d(e,t,e=>{void 0!==e&&e.key!==n||r()})}function We(e,t){const{name:n,event:r="change",scope:o="branch",callback:i}=t;if(void 0===n)return d(e.emitter,r,i);const u=function(e){return Array.isArray(e)&&e.every(e=>"number"!=typeof e)}(n)?n:[n],s=u.map(t=>{const n=E(t);return"errors"===r||"touched"===r?Je(e.emitter,r,n.key,i):Fe(e.emitter,r,n,o,i)});return 1===s.length?s[0]:()=>s.forEach(e=>e())}function Ge(e){const[t]=o(()=>{const t=V(e);return e&&void 0!==e.values&&fe(t,e.values),t}),n=e&&e.initialValues,u=e&&e.values,s=r(null);null===s.current&&(s.current={done:!1,source:void 0}),i(()=>{const e=s.current;e.done&&(e.source===n||k(e.source,n))||(e.done=!0,e.source=n,fe(t,n))},[t,n]);const a=r(null);return null===a.current&&(a.current={done:!1,source:void 0}),i(()=>{if(void 0===u)return;const e=a.current;e.done&&(e.source===u||k(e.source,u))||(e.done=!0,e.source=u,fe(t,u))},[t,u]),t}function Ke(e,t){const o=r(null);null===o.current&&(o.current={hasValue:!1});const i=o.current,u=r(t);u.current=t;const s=n(()=>(i.hasValue||(i.value=u.current(),i.hasValue=!0),i.value),[i]),a=n(t=>{i.hasValue=!1;return e(()=>{i.hasValue=!1,t()})},[e,i]);return Re.useSyncExternalStore(a,s,s)}function ze(e,t,r){return Ke(n(n=>d(e,t,n),[e,t]),r)}function Ye(e,t){return Qe(e,E(t))}function Qe(e,t){const{emitter:r}=e,{key:o}=t;return Ke(n(e=>Fe(r,"change",t,"leaf",e),[r,o]),A.bind(null,e,t))}function Xe(e,t){return Ze(e,E(t))}function Ze(e,t){const{emitter:r}=e,{key:o}=t;return Ke(n(e=>Je(r,"touched",o,e),[r,o]),z.bind(null,e,t))}function et(e,t){return tt(e,E(t))?.message}function tt(e,t){const{emitter:r}=e,{key:o}=t;return Ke(n(e=>Je(r,"errors",o,e),[r,o]),D.bind(null,e,t))}function nt(e,t){return rt(e,E(t))}function rt(e,t){const{emitter:r}=e,{key:o}=t;return Ke(n(e=>Je(r,"errors",o,e),[r,o]),B.bind(null,e,t))}function ot(e){return ze(e.emitter,"change",Y.bind(null,e))}function it(e){return ze(e.emitter,"change",ie.bind(null,e))}function ut(e){return ze(e.emitter,"touched",ue.bind(null,e))}function st(e){return ze(e.emitter,"errors",he.bind(null,e))}function at(e){return ze(e.emitter,"submitting",()=>e.isSubmitting)}function ct(e){const{emitter:t}=e;return Ke(n(e=>{const n=d(t,"errors",e),r=d(t,"submitting",e);return()=>{n(),r()}},[t]),()=>!e.isSubmitting&&!he(e))}function lt(e){return ze(e.emitter,"submitCount",()=>e.submitCount)}function ft(e){const t=u(()=>E(h(e)),[e]);return u(()=>t,[t.key])}function dt(e){const t=function(e){const t=r(e);return t.current=e,t}(e);return n((...e)=>t.current(...e),[t])}function mt(e,t){if(!e)return t;const n=function(e){return t=>{if(e.required&&(""===t||null==t))return[{type:"required",message:"string"==typeof e.required?e.required:Ne("required")}];const n=[],r=(t,n)=>e.messages?.[t]??Ne(t,n);if(void 0!==e.min){const o=Number(t);!Number.isNaN(o)&&o<e.min&&n.push({type:"min",message:r("min",e.min)})}if(void 0!==e.max){const o=Number(t);!Number.isNaN(o)&&o>e.max&&n.push({type:"max",message:r("max",e.max)})}return void 0!==e.minLength&&"string"==typeof t&&t.length<e.minLength&&n.push({type:"minLength",message:r("minLength",e.minLength)}),void 0!==e.maxLength&&"string"==typeof t&&t.length>e.maxLength&&n.push({type:"maxLength",message:r("maxLength",e.maxLength)}),e.pattern&&!e.pattern.value.test(t)&&n.push({type:"pattern",message:e.messages?.pattern??e.pattern.message??Ne("pattern")}),n.length?n:void 0}}(e);return t?(e,r)=>{const o=n(e,r),i=e=>{const t=[...o??[]];return Array.isArray(e)?t.push(...e):e&&t.push(e),t.length?t:void 0},u=t(e,r);return b(u)?u.then(i):i(u)}:n}function ht({form:e,name:t,initialValue:n,shouldUnregister:u,validate:a,rules:c,validateDebounce:l,delayError:f,disabled:d,mode:m},h){const y=s(h),v=e||y;if(!v)throw new Error("no form provided");const p=ft(t),g=function(e,t,n,o){const u=s(kt),a=n||u;if(!a)throw new Error("no form provided");const c=r(null),l=r(e);l.current=e;const f=r(o?.debounce??0);return f.current=o?.debounce??0,i(()=>{let e=null,n=null,r=!1;const o=()=>{r||(r=!0,I(a,t))},i=()=>{r&&(r=!1,H(a,t))},u=()=>{e=null;const r=l.current;if(!r)return void i();n?.abort(),n=new AbortController;const u=c.current={};let s;try{s=r(A(a,t),{form:a,path:t,signal:n.signal})}catch(e){throw i(),e}if(!b(s))return U(a,t,s),void i();o(),s.then(e=>{u===c.current&&U(a,t,e)}).catch(()=>{}).finally(()=>{u===c.current&&(i(),c.current=null)})};return a.validators.set(t.key,()=>{const t=f.current;if(t>0)return null!==e?clearTimeout(e):o(),void(e=setTimeout(u,t));u()}),()=>{a.validators.delete(t.key),null!==e&&(clearTimeout(e),e=null),i(),n?.abort()}},[a,t.key]),dt(()=>a.validators.get(t.key)?.())}(mt(c,a),p,v,{debounce:l}),k=rt(v,p),S=function(e,t){const[n,r]=o(e);return i(()=>{if(void 0===t)return;if(0===e.length)return void r(e);if(n.length>0)return void r(e);const o=setTimeout(()=>r(e),t);return()=>clearTimeout(o)},[e,t,n]),void 0===t?e:n}(k,f),E=S[0],w=E?.message,V=Qe(v,p),O=ze(v.emitter,"disabled",()=>v.disabled),_=m??v.mode;i(()=>{void 0!==n&&void 0===A(v,p)&&T(v,p,n)},[v,p,n]);const x=dt(e=>{T(v,p,e),("onChange"===_||"all"===_||"onTouched"===_&&z(v,p)||k.length>0&&"onChange"===v.reValidateMode)&&g()});i(()=>(v.changeHandlers.set(p.key,x),()=>{v.changeHandlers.get(p.key)===x&&v.changeHandlers.delete(p.key)}),[v,p.key,x]);const C=dt(()=>{G(v,p),("onBlur"===_||"onTouched"===_||"all"===_||k.length>0&&"onBlur"===v.reValidateMode)&&g()});return i(()=>()=>{!1!==u&&ce(v,p)},[p,v,u]),{form:v,value:V,error:w,errorObject:E,errors:S,onChange:x,onBlur:C,name:p.key,disabled:O||!!d}}function yt(e){return ht(e,kt)}let vt=0;function pt(){return"_"+ ++vt}function gt(e,t){const o=s(t),u=e.form||o;if(!u)throw new Error("no form provided");const c=ft(e.name),l=r([]),f=n(()=>A(u,c)||[],[u,c]),d=n(e=>{T(u,c,e)},[u,c]),m=n(()=>{const e=f();for(;l.current.length<e.length;)l.current.push(pt());for(;l.current.length>e.length;)l.current.pop();return l.current.map((e,t)=>({id:e,index:t}))},[f]),[h,y]=a(m,void 0,m);i(()=>Fe(u.emitter,"change",c,"branch",y),[u.emitter,c]);return{fields:h,append:dt(e=>{const t=f();l.current.push(pt()),d([...t,e])}),prepend:dt(e=>{const t=f();l.current.unshift(pt()),d([e,...t])}),insert:dt((e,t)=>{const n=f();l.current.splice(e,0,pt());const r=[...n.slice(0,e),t,...n.slice(e)];d(r)}),remove:dt(e=>{const t=f();l.current.splice(e,1);const n=t.filter((t,n)=>n!==e);d(n)}),swap:dt((e,t)=>{const n=f();[l.current[e],l.current[t]]=[l.current[t],l.current[e]];const r=[...n];[r[e],r[t]]=[r[t],r[e]],d(r)}),move:dt((e,t)=>{const n=f(),[r]=l.current.splice(e,1);l.current.splice(t,0,r);const o=[...n],[i]=o.splice(e,1);o.splice(t,0,i),d(o)}),replace:dt(e=>{l.current=e.map(()=>pt()),d([...e])}),update:dt((e,t)=>{const n=f();if(e<0||e>=n.length)return;const r=[...n];r[e]=t,d(r)})}}function bt(e){return gt(e,kt)}const kt=c(null),St=kt.Provider;function Et(){const e=s(kt);if(!e)throw new Error("no form provided");return e}function wt(){const e=c(null);return{context:e,FormProvider:function({form:t,children:n}){return l(e.Provider,{value:t},n)},useFormContext:function(){const t=s(e);if(!t)throw new Error("no form provided");return t},useField:function(t){return ht(t,e)},useFieldArray:function(t){return gt(t,e)}}}const Vt=c(null),Ot=Vt.Provider;function _t(){const e=s(Vt);if(!e)throw new Error("no group provided");return e}function At({form:t,context:n,initialValues:r,values:o,onSubmit:i,onValidSubmit:u,onInvalidSubmit:s,shouldFocusError:a,...c}){const l=Ge({initialValues:r,values:o}),f=t||l,d=De(f,{onSubmit:i,onValidSubmit:u,onInvalidSubmit:s,shouldFocusError:a}),{Provider:m}=n??kt;return e.createElement(m,{value:f},e.createElement("form",{...c,noValidate:!0,onSubmit:d}))}function xt(e){return e.replace(/["'[\],\s]+/g,"-").replace(/^-+|-+$/g,"")||"field"}function Tt(e,t,n){return{"aria-invalid":!!e||n["aria-invalid"],"aria-describedby":e?[n["aria-describedby"],xt(t)].filter(Boolean).join(" "):n["aria-describedby"]}}function Ct(e){return xt(E(e).key)}const Lt=e.forwardRef(({validate:t,eventToValue:n,initialValue:r,name:o,asProps:i,renderError:u,as:s,valueToProps:a,form:c,shouldUnregister:l,rules:f,validateDebounce:m,disabled:h,delayError:y,mode:v,...p},g)=>{const b=e.useRef(null),[k,S]=e.useState(0),E=e.useCallback(e=>{b.current=e,function(e,t){"function"==typeof e?e(t):e&&(e.current=t)}(g,e)},[g]),{value:w,onChange:V,onBlur:O,error:_,form:A,name:x,disabled:T}=yt({name:o,form:c,initialValue:r,shouldUnregister:l,rules:f,validateDebounce:m,delayError:y,disabled:h,mode:v,validate:(...e)=>{const n=b.current;if(!n||"function"!=typeof n.checkValidity||(n.setCustomValidity(""),!1!==n.checkValidity()))return t?t(...e):void 0;S(e=>e+1)}}),C=s||"input";e.useEffect(()=>{const e=b.current;e&&"function"==typeof e.setCustomValidity&&("string"==typeof _?(e.setCustomValidity(_),e.reportValidity()):e.setCustomValidity(""))},[_]),e.useEffect(()=>{k>0&&b.current?.reportValidity()},[k]),e.useEffect(()=>d(A.emitter,"focusError",(e,t)=>{if(e!==x)return;const n=b.current;n&&"function"==typeof n.focus&&(n.focus(),t?.shouldSelect&&"function"==typeof n.select&&n.select())}),[A,x]);const L=n??(e=>e.target.value),j=xt(x);return e.createElement(e.Fragment,null,e.createElement(C,{...p,name:x,onBlur:O,...i,...a?a(w):{value:w},...Tt(_,x,p),disabled:T,onChange:e=>V(L(e)),ref:E}),_&&u?e.createElement("span",{id:j,role:"alert"},u(_,j)):null)}),jt=e.forwardRef(({name:t,form:n,initialValue:r,shouldUnregister:o,validate:i,rules:u,validateDebounce:s,disabled:a,delayError:c,mode:l,...f},d)=>{const{value:m,onChange:h,onBlur:y,error:v,name:p,disabled:g}=yt({name:t,form:n,initialValue:r,shouldUnregister:o,validate:i,rules:u,validateDebounce:s,delayError:c,disabled:a,mode:l});return e.createElement("input",{...f,name:p,onBlur:y,type:"checkbox",checked:!!m,...Tt(v,p,f),disabled:g,onChange:e=>h(e.target.checked),ref:d})});function Dt(e,t){return e?Array.isArray(t)?t:[]:t??""}const Mt=e.forwardRef(({name:t,multiple:n,children:r,form:o,initialValue:i,shouldUnregister:u,validate:s,rules:a,validateDebounce:c,disabled:l,delayError:f,mode:d,...m},h)=>{const{value:y,onChange:v,onBlur:p,error:g,name:b,disabled:k}=yt({name:t,form:o,initialValue:i,shouldUnregister:u,validate:s,rules:a,validateDebounce:c,delayError:f,disabled:l,mode:d});return e.createElement("select",{...m,name:b,onBlur:p,multiple:n,value:Dt(n,y),...Tt(g,b,m),disabled:k,onChange:e=>v(n?Array.from(e.target.selectedOptions,e=>e.value):e.target.value),ref:h},r)});export{jt as Checkbox,Vt as CheckboxGroupContext,Ot as CheckboxGroupProvider,Lt as Field,At as Form,kt as FormContext,St as FormProvider,Mt as Select,w as VALIDATION_OUTCOME,C as changeValue,L as changeValueByPath,F as clearErrors,V as createForm,wt as createFormContext,_e as ensureValidate,Ct as fieldErrorId,ie as getDirtyFields,j as getError,D as getErrorByPath,P as getErrors,N as getFieldErrors,B as getFieldErrorsByPath,q as getFieldState,$ as getFirstError,ue as getTouchedFields,_ as getValue,A as getValueByPath,O as getValues,De as handleSubmit,he as hasErrors,K as hasTouched,z as hasTouchedByPath,Te as incrementSubmitCount,Y as isDirty,se as isTouched,ae as removeField,ce as removeFieldByPath,de as reset,me as resetField,Le as setDisabled,R as setError,U as setErrorByPath,Me as setFocus,fe as setInitialValues,xe as setIsSubmitting,J as setServerErrors,Ce as setSubmitSuccessful,W as setTouched,G as setTouchedByPath,I as setValidatingByPath,x as setValue,T as setValueByPath,We as subscribe,ye as trigger,H as unsetValidatingByPath,ct as useCanSubmit,_t as useCheckboxGroupContext,it as useDirtyFields,et as useError,tt as useErrorByPath,yt as useField,bt as useFieldArray,nt as useFieldErrors,rt as useFieldErrorsByPath,Ge as useForm,Et as useFormContext,st as useHasErrors,ot as useIsDirty,at as useIsSubmitting,lt as useSubmitCount,Xe as useTouched,Ze as useTouchedByPath,ut as useTouchedFields,Ye as useValue,Qe as useValueByPath,ze as useWatch,Ae as validate};
|
|
1
|
+
import*as e from"react";import t,{useCallback as n,useRef as r,useState as o,useEffect as i,useMemo as u,useContext as s,useReducer as a,createContext as c,createElement as l}from"react";function f(e,t){for(var n=arguments.length,r=new Array(n>2?n-2:0),o=2;o<n;o++)r[o-2]=arguments[o];(e.get(t)||[]).forEach(function(e){return e.apply(void 0,r)})}function d(e,t,n){var r=function(e,t){var n=e.get(t);if(n)return n;var r=new Set;return e.set(t,r),r}(e,t);return r.add(n),function(){return r.delete(n)}}const m=new Map;function y(e){if(Array.isArray(e))return e;const t=m.get(e);if(t)return t;const n=function(e){const t=[];let n="";const r=()=>{t.push(n),n=""};for(let o=0;o<e.length;o++){const i=e[o];if("."===i)""!==n&&r();else if("["===i){""!==n&&r();const i=e[o+1];if('"'===i||"'"===i){const n=e.indexOf(i,o+2);if(-1===n)throw new TypeError(`Unterminated quote in path: ${e}`);if("]"!==e[n+1])throw new TypeError(`Expected "]" after quoted segment in path: ${e}`);t.push(e.slice(o+2,n)),o=n+1}else{const n=e.indexOf("]",o+1);if(-1===n)throw new TypeError(`Unterminated bracket in path: ${e}`);const r=e.slice(o+1,n);t.push(/^-?\d+$/.test(r)?Number(r):r),o=n}}else n+=i}""===n&&0!==t.length||r();return t}(e);return m.set(e,n),n}function h(e,t){return t.reduce((e,t)=>{if(null!=e)return e[t]},e)}function v(e,t){if(!t.length||null==e)return e;const[n,...r]=t;if(r.length){const t=v(e[n],r);return t===e[n]?e:p(e,[n],t)}if(Array.isArray(e)){if(!(n in e))return e;const t=e.slice();return delete t[n],t}if("object"!=typeof e||!(n in e))return e;const o={...e};return delete o[n],o}function p(e,t,n){if(!t.length)return n;const[r,...o]=t;if("number"==typeof r){const t=Array.isArray(e)?e.slice():[];return t[r]=p(t[r],o,n),t}return{...e,[r]:p(e&&e[r],o,n)}}function g(e,t,n,r){if(!t.length)return n;let o=e,i=null,u="";for(let s=0;s<t.length;s++){const a=t[s];if(!r.has(o)){let t;t="number"==typeof a?Array.isArray(o)?o.slice():[]:{...o},r.add(t),0===s?e=t:i[u]=t,o=t}s===t.length-1?o[a]=n:(i=o,u=a,o=o[a])}return e}function b(e){return e&&"function"==typeof e.then}function k(e,t){if(Object.is(e,t))return!0;if(e instanceof Date&&t instanceof Date)return e.getTime()===t.getTime();if(!e||!t||"object"!=typeof e||"object"!=typeof t)return!1;const n=Array.isArray(e);if(n!==Array.isArray(t))return!1;if(n){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(!k(e[n],t[n]))return!1;return!0}const r=Object.getPrototypeOf(e);if(r!==Object.prototype&&null!==r)return!1;if(Object.getPrototypeOf(t)!==r)return!1;const o=Object.keys(e),i=Object.keys(t);if(o.length!==i.length)return!1;for(const n of o)if(!k(e[n],t[n]))return!1;return!0}function w(e,t,n,r){return new Promise((o,i)=>{if(r())return void i();if(n())return void o();const u=d(e,t,()=>{if(r())return u(),void i();n()&&(u(),o())})})}function S(e){const t=y(e);return{value:t,key:JSON.stringify(t)}}const E=Symbol("validation-outcome");function V(e){return{emitter:new Map,...e,mode:e?.mode??"onSubmit",reValidateMode:e?.reValidateMode??"onChange",disabled:e?.disabled??!1,validateDeps:e?.validateDeps?new Set(e.validateDeps.map(e=>S(e).key)):void 0,initialValues:e?.initialValues??{},values:new Map,deleted:new Set,errors:new Map,touched:new Set,validators:new Map,changeHandlers:new Map,validating:new Set,parsedValues:void 0,isSubmitting:!1,submitCount:0,isSubmitSuccessful:void 0}}function O(e){const{initialValues:t,parsedValues:n,values:r,deleted:o}=e,i=new Set;let u=n??t;for(const[e,t]of r)u=g(u,JSON.parse(e),t,i);for(const e of o)u=v(u,JSON.parse(e));return u}function _(e,t){return A(e,S(t))}function A({initialValues:e,parsedValues:t,values:n,deleted:r},o){return n.has(o.key)?n.get(o.key):r.has(o.key)?void 0:h(t??e,o.value)}function x(e,t,n,r){T(e,S(t),n,r)}function T(e,t,n,r){const{emitter:o,values:i,deleted:u}=e;i.set(t.key,n),le(u,t),function(e,{key:t}){const n=X.get(e);if(!n?.size)return;const r=`${t.slice(0,-1)},`;for(const e of n.keys())e.startsWith(r)&&n.delete(e)}(e,t),!1===r?.shouldDirty&&ee(e,t,n),re(e),r?.shouldTouch&&G(e,t),r?.shouldValidate&&e.validators.get(t.key)?.(),f(o,"change",t)}function C(e,t,n,r){L(e,S(t),n,r)}function L(e,t,n,r){!1===r?.shouldDirty&&ee(e,t,n);const o=e.changeHandlers.get(t.key);o?o(n):T(e,t,n,r)}function j(e,t){return D(e,S(t))}function D({errors:e},t){return e.get(t.key)?.[0]}const M=[];function N(e,t){return B(e,S(t))}function B({errors:e},t){return e.get(t.key)??M}function P({errors:e}){const t=[];for(const[n,r]of e){const e=JSON.parse(n).join(".");for(const{type:n,message:o}of r)t.push({path:e,type:n,message:o})}return t}function I({errors:e}){return e.values().next().value?.[0]?.message}function $(e,t){const n=S(t),{values:r,touched:o,validating:i}=e,u=r.get(n.key);return{value:A(e,n),error:D(e,n),errors:B(e,n),isDirty:r.has(n.key)&&Z(e,n.key,n.value)!==u,isTouched:o.has(n.key),isValidating:i.has(n.key)}}function q({emitter:e,validating:t},n){t.delete(n.key),f(e,"validating",n)}function H({emitter:e,validating:t},n){t.add(n.key),f(e,"validating",n)}function R(e,t,n){W(e,S(t),n)}function W({emitter:e,errors:t},n,r){const o=function(e){if("string"==typeof e)return e?[{type:"custom",message:e}]:void 0;if(pe(e))return[e];if(!e)return;const t=[];return e.forEach(e=>{"string"==typeof e&&e?t.push({type:"custom",message:e}):pe(e)&&t.push(e)}),t.length?t:void 0}(r);o?t.set(n.key,o):t.delete(n.key),f(e,"errors",n)}function F(e,t){const{emitter:n,errors:r}=e;if(void 0===t)return r.clear(),void f(n,"errors");const o="string"==typeof t||ve(t)?[S(t)]:t.map(e=>S(e));for(const{key:e}of o)r.delete(e);for(const e of o)f(n,"errors",e)}function J(e,t,n){n?.keepExisting||F(e);for(const[n,r]of Object.entries(t))R(e,n,(Array.isArray(r)?r:[r]).map(e=>({type:"server",message:e})))}function U(e,t){G(e,S(t))}function G({emitter:e,touched:t},n){t.has(n.key)||(t.add(n.key),f(e,"touched",n))}function K(e,t){return z(e,S(t))}function z({touched:e},t){return e.has(t.key)}function Y(e){let t=!1;return Q(e,()=>{t=!0}),t}function Q(e,t){for(const[n,r]of e.values){const o=JSON.parse(n);Z(e,n,o)!==r&&t(o.join("."))}}const X=new WeakMap;function Z(e,t,n){const r=X.get(e);return r?.has(t)?r.get(t):h(e.initialValues,n)}function ee(e,{key:t},n){let r=X.get(e);r||(r=new Map,X.set(e,r)),r.set(t,n)}function te(e,t){const n=X.get(e);n&&(void 0===t?n.clear():n.delete(t))}const ne=new WeakMap;function re(e){const t=ne.get(e);t&&t.version++}function oe(e){const t={};return Q(e,e=>{t[e]=!0}),t}function ie(e){let t=ne.get(e);if(t){if(t.version>0){const n=oe(e);(function(e,t){const n=Object.keys(e);return n.length===Object.keys(t).length&&n.every(e=>!0===t[e])})(t.result,n)||(t.result=n),t.version=0}}else t={version:0,result:oe(e)},ne.set(e,t);return t.result}function ue({touched:e}){return Array.from(e,e=>JSON.parse(e).join("."))}function se({touched:e}){return e.size>0}function ae(e,t){ce(e,S(t))}function ce(e,{key:t,value:n}){const{emitter:r,values:o,touched:i,errors:u,validating:s,deleted:a}=e;o.delete(t),i.delete(t),u.delete(t),s.delete(t),te(e,t),function(e,t){for(let n=1;n<t.length;n++)if(e.has(JSON.stringify(t.slice(0,n))))return!0;const n=`${JSON.stringify(t).slice(0,-1)},`;for(const t of e.keys())if(t.startsWith(n))return!0;return!1}(o,n)||a.add(t),re(e),f(r,"change"),f(r,"touched"),f(r,"errors"),f(r,"validating")}function le(e,{key:t}){if(e.size)for(const n of e)(n===t||n.startsWith(`${t.slice(0,-1)},`)||t.startsWith(`${n.slice(0,-1)},`))&&e.delete(n)}function fe(e,t){e.initialValues===t||k(e.initialValues,t)||(e.initialValues=t,e.parsedValues=void 0,e.values.clear(),e.deleted.clear(),te(e),re(e),f(e.emitter,"change"))}function de(e,t,n){const r=n?.keepDirtyValues?Object.keys(ie(e)).map(t=>({key:t,value:_(e,t)})):[];e.initialValues=t,e.parsedValues=void 0,n?.keepErrors||F(e);const{emitter:o,touched:i,values:u,deleted:s,validating:a}=e;u.clear(),s.clear(),te(e),n?.keepTouched||i.clear(),a.clear(),n?.keepIsSubmitting||(e.isSubmitting=!1),n?.keepSubmitCount||(e.submitCount=0),n?.keepIsSubmitted||(e.isSubmitSuccessful=void 0),re(e);for(const{key:t,value:n}of r)T(e,S(t),n);f(o,"change"),f(o,"touched"),f(o,"validating"),f(o,"submitting"),f(o,"submitCount"),f(o,"submitSuccessful"),f(o,"reset")}function me(e,t,n){const r=S(t),{emitter:o,values:i,touched:u,errors:s,deleted:a}=e;if(i.delete(r.key),te(e,r.key),void 0!==e.parsedValues){e.parsedValues=v(e.parsedValues,r.value);const t=h(e.initialValues,r.value);void 0!==t&&i.set(r.key,t)}n&&"value"in n&&i.set(r.key,n.value),le(a,r),f(o,"change"),!n?.keepTouched&&u.delete(r.key)&&f(o,"touched",r),!n?.keepErrors&&s.delete(r.key)&&f(o,"errors",r),re(e)}function ye({errors:e}){return e.size>0}async function he(e,t){const n=()=>w(e.emitter,"validating",()=>Ee(e),()=>!1);if(void 0===t)return e.validators.forEach(e=>e()),await n(),e.validate&&await _e(e),!ye(e);const r="string"==typeof t||ve(t)?[S(t).key]:t.map(e=>S(e).key);return r.forEach(t=>e.validators.get(t)?.()),await n(),r.every(t=>!e.errors.has(t))}function ve(e){return e.some(e=>"number"==typeof e)}function pe(e){return!!e&&"object"==typeof e&&"string"==typeof e.type&&"string"==typeof e.message}function ge(e,t,n=[],r){Object.entries(t).forEach(([t,o])=>{const i=[...n,...y(t)];"string"==typeof o?o&&(R(e,i,o),be(e,i,r)):Array.isArray(o)||pe(o)?(R(e,i,o),be(e,i,r)):o&&"object"==typeof o&&ge(e,o,i,r)})}function be(e,t,n){if(!n)return;const r=S(t),o=e.errors.get(r.key);o&&n.set(r.key,o)}function ke(e,t){const n=e.validateDeps?function(e){let t=we.get(e);t||(t=new Map,we.set(e,t));return t}(e):void 0;if(n&&(!function(e,t){for(const[n,r]of t){e.errors.get(n)===r&&(e.errors.delete(n),f(e.emitter,"errors",S(JSON.parse(n))))}}(e,n),n.clear()),t){if("object"==typeof t&&E in t){const r=t;return r.errors&&ge(e,r.errors,[],n),void function(e,t){void 0!==t&&t!==e.parsedValues&&(e.parsedValues=t,f(e.emitter,"change"))}(e,r.values)}ge(e,t,[],n)}}const we=new WeakMap;const Se="__form_validate__";function Ee(e){for(const t of e.validating)if(t!==Se)return!1;return!0}const Ve=Symbol("form-validate-settled"),Oe=new WeakMap;function _e(e){const t=e.validate;if(!t)return Promise.resolve();const n=e.validateDebounce??0;if(n<=0){const n=new AbortController;return Promise.resolve(t(O(e),{form:e,signal:n.signal})).then(t=>{ke(e,t)})}const r=function(e){let t=Oe.get(e);return t||(t={timer:null,controller:null,round:null,marked:!1,waiters:[]},Oe.set(e,t)),t}(e);return null!==r.timer?clearTimeout(r.timer):(r.marked=!0,e.validating.add(Se),f(e.emitter,"validating")),r.timer=setTimeout(()=>{r.timer=null;const t=r.round={};(function(e,t,n){const r=e.validate;if(!r)return Promise.resolve();t.controller?.abort();const o=t.controller=new AbortController;let i;try{i=Promise.resolve(r(O(e),{form:e,signal:o.signal}))}catch(e){i=Promise.reject(e)}return i.then(r=>{t.round===n&&ke(e,r)},e=>{if(t.round===n)throw e})})(e,r,t).then(()=>Ae(e,r,t,Ve),n=>Ae(e,r,t,n))},n),new Promise((e,t)=>{r.waiters.push({resolve:e,reject:t})})}function Ae(e,t,n,r){if(t.round!==n)return;if(t.round=null,null!==t.timer)return;t.marked&&(t.marked=!1,e.validating.delete(Se),f(e.emitter,"validating"));const o=t.waiters;t.waiters=[];for(const e of o)r===Ve?e.resolve():e.reject(r)}function xe(e,t,n){e.validateDeps?.has(t.key)&&e.validate&&("onChange"===n||"all"===n||"onTouched"===n&&z(e,t)||"onChange"===e.reValidateMode&&function(e){const t=we.get(e);if(!t)return!1;for(const[n,r]of t)if(e.errors.get(n)===r)return!0;return!1}(e))&&_e(e).catch(()=>{})}async function Te(e){if(e.validators.forEach(e=>e()),await w(e.emitter,"validating",()=>Ee(e),()=>ye(e)).catch(()=>{throw new Error(I(e))}),e.validate&&(await _e(e),ye(e)))throw new Error(I(e))}async function Ce(e){return Te(e).catch(e=>e.message)}function Le(e,t){e.isSubmitting=t,f(e.emitter,"submitting")}function je(e){e.submitCount++,f(e.emitter,"submitCount")}function De(e,t){e.isSubmitSuccessful=t,f(e.emitter,"submitSuccessful")}function Me(e,t){e.disabled=t,f(e.emitter,"disabled")}function Ne(e){if(e.startsWith("["))try{const t=JSON.parse(e);if(Array.isArray(t))return t.join(".")}catch{}return e}function Be(e,t){const{onSubmit:n,onValidSubmit:r,onInvalidSubmit:o,shouldFocusError:i=!0}=t??{};return async t=>{t&&"function"==typeof t.preventDefault&&t.preventDefault();const u=t?.currentTarget;Le(e,!0),je(e);const s=O(e);if(u&&"function"==typeof u.checkValidity&&!1===u.checkValidity()){if(u.reportValidity(),i&&"function"==typeof u.querySelector){const e=u.querySelector(":invalid");e&&"function"==typeof e.focus&&e.focus()}return Le(e,!1),De(e,!1),void(o&&o(function(e){const t=[],{elements:n}=e;for(let e=0;e<n.length;e++){const r=n[e];r.name&&"function"==typeof r.checkValidity&&!r.checkValidity()&&t.push({path:Ne(r.name),type:"native",message:r.validationMessage})}return t}(u),s))}if(await Ce(e)){if(Le(e,!1),De(e,!1),i){const t=e.errors.keys().next().value;void 0!==t&&f(e.emitter,"focusError",t)}o&&o(P(e),s)}else try{const o=O(e);n&&await n(o,t),r&&await r(o,t),De(e,!0)}catch{De(e,!1)}finally{Le(e,!1)}}}function Pe(e,t,n){const{key:r}=S(t);n?f(e.emitter,"focusError",r,n):f(e.emitter,"focusError",r)}function Ie(e,t){switch(e){case"required":return"This field is required";case"min":return`Must be at least ${t}`;case"max":return`Must be at most ${t}`;case"minLength":return`Must be at least ${t} characters`;case"maxLength":return`Must be at most ${t} characters`;case"pattern":return"Invalid format";default:return"Invalid value"}}var $e,qe={exports:{}},He={};var Re,We,Fe={};var Je=(We||(We=1,"production"===process.env.NODE_ENV?qe.exports=function(){if($e)return He;$e=1;var e=t,n="function"==typeof Object.is?Object.is:function(e,t){return e===t&&(0!==e||1/e==1/t)||e!=e&&t!=t},r=e.useState,o=e.useEffect,i=e.useLayoutEffect,u=e.useDebugValue;function s(e){var t=e.getSnapshot;e=e.value;try{var r=t();return!n(e,r)}catch(e){return!0}}var a="undefined"==typeof window||void 0===window.document||void 0===window.document.createElement?function(e,t){return t()}:function(e,t){var n=t(),a=r({inst:{value:n,getSnapshot:t}}),c=a[0].inst,l=a[1];return i(function(){c.value=n,c.getSnapshot=t,s(c)&&l({inst:c})},[e,n,t]),o(function(){return s(c)&&l({inst:c}),e(function(){s(c)&&l({inst:c})})},[e]),u(n),n};return He.useSyncExternalStore=void 0!==e.useSyncExternalStore?e.useSyncExternalStore:a,He}():qe.exports=(Re||(Re=1,"production"!==process.env.NODE_ENV&&function(){function e(e){var t=e.getSnapshot;e=e.value;try{var n=t();return!r(e,n)}catch(e){return!0}}"undefined"!=typeof __REACT_DEVTOOLS_GLOBAL_HOOK__&&"function"==typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart&&__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(Error());var n=t,r="function"==typeof Object.is?Object.is:function(e,t){return e===t&&(0!==e||1/e==1/t)||e!=e&&t!=t},o=n.useState,i=n.useEffect,u=n.useLayoutEffect,s=n.useDebugValue,a=!1,c=!1,l="undefined"==typeof window||void 0===window.document||void 0===window.document.createElement?function(e,t){return t()}:function(t,l){a||void 0===n.startTransition||(a=!0,console.error("You are using an outdated, pre-release alpha of React 18 that does not support useSyncExternalStore. The use-sync-external-store shim will not work correctly. Upgrade to a newer pre-release."));var f=l();if(!c){var d=l();r(f,d)||(console.error("The result of getSnapshot should be cached to avoid an infinite loop"),c=!0)}var m=(d=o({inst:{value:f,getSnapshot:l}}))[0].inst,y=d[1];return u(function(){m.value=f,m.getSnapshot=l,e(m)&&y({inst:m})},[t,f,l]),i(function(){return e(m)&&y({inst:m}),t(function(){e(m)&&y({inst:m})})},[t]),s(f),f};Fe.useSyncExternalStore=void 0!==n.useSyncExternalStore?n.useSyncExternalStore:l,"undefined"!=typeof __REACT_DEVTOOLS_GLOBAL_HOOK__&&"function"==typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop&&__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(Error())}()),Fe)),qe.exports);function Ue(e,t){return e.startsWith(`${t.slice(0,-1)},`)}function Ge(e,t,n,r,o){const{key:i}=n;return d(e,t,e=>{(void 0===e||e.key===i||Ue(i,e.key)||"branch"===r&&Ue(e.key,i))&&o()})}function Ke(e,t,n,r){return d(e,t,e=>{void 0!==e&&e.key!==n||r()})}function ze(e,t){const{name:n,event:r="change",scope:o="branch",callback:i}=t;if(void 0===n)return d(e.emitter,r,i);const u=function(e){return Array.isArray(e)&&e.every(e=>"number"!=typeof e)}(n)?n:[n],s=u.map(t=>{const n=S(t);return"errors"===r||"touched"===r?Ke(e.emitter,r,n.key,i):Ge(e.emitter,r,n,o,i)});return 1===s.length?s[0]:()=>s.forEach(e=>e())}function Ye(e){const[t]=o(()=>{const t=V(e);return e&&void 0!==e.values&&fe(t,e.values),t}),n=e&&e.initialValues,u=e&&e.values,s=r(null);null===s.current&&(s.current={done:!1,source:void 0}),i(()=>{const e=s.current;e.done&&(e.source===n||k(e.source,n))||(e.done=!0,e.source=n,fe(t,n))},[t,n]);const a=r(null);return null===a.current&&(a.current={done:!1,source:void 0}),i(()=>{if(void 0===u)return;const e=a.current;e.done&&(e.source===u||k(e.source,u))||(e.done=!0,e.source=u,fe(t,u))},[t,u]),t}function Qe(e,t){const o=r(null);null===o.current&&(o.current={hasValue:!1});const i=o.current,u=r(t);u.current=t;const s=n(()=>(i.hasValue||(i.value=u.current(),i.hasValue=!0),i.value),[i]),a=n(t=>{i.hasValue=!1;return e(()=>{i.hasValue=!1,t()})},[e,i]);return Je.useSyncExternalStore(a,s,s)}function Xe(e,t,r){return Qe(n(n=>d(e,t,n),[e,t]),r)}function Ze(e,t){return et(e,S(t))}function et(e,t){const{emitter:r}=e,{key:o}=t;return Qe(n(e=>Ge(r,"change",t,"leaf",e),[r,o]),A.bind(null,e,t))}function tt(e,t){return nt(e,S(t))}function nt(e,t){const{emitter:r}=e,{key:o}=t;return Qe(n(e=>Ke(r,"touched",o,e),[r,o]),z.bind(null,e,t))}function rt(e,t){return ot(e,S(t))?.message}function ot(e,t){const{emitter:r}=e,{key:o}=t;return Qe(n(e=>Ke(r,"errors",o,e),[r,o]),D.bind(null,e,t))}function it(e,t){return ut(e,S(t))}function ut(e,t){const{emitter:r}=e,{key:o}=t;return Qe(n(e=>Ke(r,"errors",o,e),[r,o]),B.bind(null,e,t))}function st(e){return Xe(e.emitter,"change",Y.bind(null,e))}function at(e){return Xe(e.emitter,"change",ie.bind(null,e))}function ct(e){return Xe(e.emitter,"touched",ue.bind(null,e))}function lt(e){return Xe(e.emitter,"errors",ye.bind(null,e))}function ft(e){return Xe(e.emitter,"submitting",()=>e.isSubmitting)}function dt(e){const{emitter:t}=e;return Qe(n(e=>{const n=d(t,"errors",e),r=d(t,"submitting",e);return()=>{n(),r()}},[t]),()=>!e.isSubmitting&&!ye(e))}function mt(e){return Xe(e.emitter,"submitCount",()=>e.submitCount)}function yt(e){const t=u(()=>S(y(e)),[e]);return u(()=>t,[t.key])}function ht(e){const t=r(e);return t.current=e,t}function vt(e){const t=ht(e);return n((...e)=>t.current(...e),[t])}function pt(e,t){if(!e)return t;const n=function(e){return t=>{if(e.required&&(""===t||null==t))return[{type:"required",message:"string"==typeof e.required?e.required:Ie("required")}];const n=[],r=(t,n)=>e.messages?.[t]??Ie(t,n);if(void 0!==e.min){const o=Number(t);!Number.isNaN(o)&&o<e.min&&n.push({type:"min",message:r("min",e.min)})}if(void 0!==e.max){const o=Number(t);!Number.isNaN(o)&&o>e.max&&n.push({type:"max",message:r("max",e.max)})}return void 0!==e.minLength&&"string"==typeof t&&t.length<e.minLength&&n.push({type:"minLength",message:r("minLength",e.minLength)}),void 0!==e.maxLength&&"string"==typeof t&&t.length>e.maxLength&&n.push({type:"maxLength",message:r("maxLength",e.maxLength)}),e.pattern&&!e.pattern.value.test(t)&&n.push({type:"pattern",message:e.messages?.pattern??e.pattern.message??Ie("pattern")}),n.length?n:void 0}}(e);return t?(e,r)=>{const o=n(e,r),i=e=>{const t=[...o??[]];return Array.isArray(e)?t.push(...e):e&&t.push(e),t.length?t:void 0},u=t(e,r);return b(u)?u.then(i):i(u)}:n}function gt({form:e,name:t,initialValue:n,shouldUnregister:u,validate:a,rules:c,validateDebounce:l,delayError:f,disabled:d,mode:m},y){const h=s(y),v=e||h;if(!v)throw new Error("no form provided");const p=yt(t),g=function(e,t,n,o){const u=s(Tt),a=n||u;if(!a)throw new Error("no form provided");const c=r(null),l=r(e);l.current=e;const f=r(o?.debounce??0);return f.current=o?.debounce??0,i(()=>{let e=null,n=null,r=!1;const o=()=>{r||(r=!0,H(a,t))},i=()=>{r&&(r=!1,q(a,t))},u=()=>{e=null;const r=l.current;if(!r)return void i();n?.abort(),n=new AbortController;const u=c.current={};let s;try{s=r(A(a,t),{form:a,path:t,signal:n.signal})}catch(e){throw i(),e}if(!b(s))return W(a,t,s),void i();o(),s.then(e=>{u===c.current&&W(a,t,e)}).catch(()=>{}).finally(()=>{u===c.current&&(i(),c.current=null)})};return a.validators.set(t.key,()=>{const t=f.current;if(t>0)return null!==e?clearTimeout(e):o(),void(e=setTimeout(u,t));u()}),()=>{a.validators.delete(t.key),null!==e&&(clearTimeout(e),e=null),i(),n?.abort()}},[a,t.key]),vt(()=>a.validators.get(t.key)?.())}(pt(c,a),p,v,{debounce:l}),k=ut(v,p),w=function(e,t){const[n,r]=o(e);return i(()=>{if(void 0===t)return;if(0===e.length)return void r(e);if(n.length>0)return void r(e);const o=setTimeout(()=>r(e),t);return()=>clearTimeout(o)},[e,t,n]),void 0===t?e:n}(k,f),S=w[0],E=S?.message,V=et(v,p),O=Xe(v.emitter,"disabled",()=>v.disabled),_=m??v.mode;i(()=>{void 0!==n&&void 0===A(v,p)&&T(v,p,n)},[v,p,n]);const x=vt(e=>{T(v,p,e),("onChange"===_||"all"===_||"onTouched"===_&&z(v,p)||k.length>0&&"onChange"===v.reValidateMode)&&g(),xe(v,p,_)});i(()=>(v.changeHandlers.set(p.key,x),()=>{v.changeHandlers.get(p.key)===x&&v.changeHandlers.delete(p.key)}),[v,p.key,x]);const C=vt(()=>{G(v,p),("onBlur"===_||"onTouched"===_||"all"===_||k.length>0&&"onBlur"===v.reValidateMode)&&g()});return i(()=>()=>{!1!==u&&ce(v,p)},[p,v,u]),{form:v,value:V,error:E,errorObject:S,errors:w,onChange:x,onBlur:C,name:p.key,disabled:O||!!d}}function bt(e){return gt(e,Tt)}let kt=0;function wt(){return"_"+ ++kt}const St=new WeakMap;function Et(e,t,n){let r=St.get(e);r||(r=new Map,St.set(e,r)),r.set(t,n)}function Vt(e){return e+1}function Ot(e,t){const o=s(t),u=e.form||o;if(!u)throw new Error("no form provided");const c=yt(e.name),l=r([]),f=n(()=>A(u,c)||[],[u,c]),d=n(e=>{T(u,c,e)},[u,c]),m=n(()=>{const e=f();for(;l.current.length<e.length;)l.current.push(wt());for(;l.current.length>e.length;)l.current.pop();return l.current.map((e,t)=>({id:e,index:t}))},[f]),[y,h]=a(m,void 0,m);i(()=>Ge(u.emitter,"change",c,"branch",h),[u.emitter,c]),Et(u,c.key,l.current),i(()=>(Et(u,c.key,l.current),()=>{const e=St.get(u);e?.get(c.key)===l.current&&e.delete(c.key)}),[u,c.key]);return{fields:y,append:vt(e=>{const t=f();l.current.push(wt()),d([...t,e])}),prepend:vt(e=>{const t=f();l.current.unshift(wt()),d([e,...t])}),insert:vt((e,t)=>{const n=f();l.current.splice(e,0,wt());const r=[...n.slice(0,e),t,...n.slice(e)];d(r)}),remove:vt(e=>{const t=f();l.current.splice(e,1);const n=t.filter((t,n)=>n!==e);d(n)}),swap:vt((e,t)=>{const n=f();[l.current[e],l.current[t]]=[l.current[t],l.current[e]];const r=[...n];[r[e],r[t]]=[r[t],r[e]],d(r)}),move:vt((e,t)=>{const n=f(),[r]=l.current.splice(e,1);l.current.splice(t,0,r);const o=[...n],[i]=o.splice(e,1);o.splice(t,0,i),d(o)}),replace:vt(e=>{l.current=e.map(()=>wt()),d([...e])}),update:vt((e,t)=>{const n=f();if(e<0||e>=n.length)return;const r=[...n];r[e]=t,d(r)})}}function _t(e){return Ot(e,Tt)}function At(e,t){const o=s(t),u=e.form||o;if(!u)throw new Error("no form provided");const{id:c}=e,l=yt(e.name),f=n(()=>function(e,t){return St.get(e)?.get(t)}(u,l.key)?.indexOf(c)??-1,[u,l.key,c]),d=n(e=>{const t=A(u,l);return Array.isArray(t)?t[e]:void 0},[u,l]),m=f(),y=d(m),h=r({index:m,value:y});h.current={index:m,value:y};const v=ht({computeIndex:f,computeValue:d}),[,p]=a(Vt,0);i(()=>Ge(u.emitter,"change",l,"leaf",()=>{const{computeIndex:e,computeValue:t}=v.current,n=e();n===h.current.index&&Object.is(t(n),h.current.value)||p()}),[u.emitter,l,v]);const g=yt([...l.value,m]),b=ut(u,g);return{value:y,setValue:vt(e=>{if(m<0)return;const t=[...A(u,l)??[]];m>=t.length||(t[m]=e,T(u,l,t))}),errors:b,error:b[0]?.message,name:g.key,index:m,form:u}}function xt(e){return At(e,Tt)}const Tt=c(null),Ct=Tt.Provider;function Lt(){const e=s(Tt);if(!e)throw new Error("no form provided");return e}function jt(){const e=c(null);return{context:e,FormProvider:function({form:t,children:n}){return l(e.Provider,{value:t},n)},useFormContext:function(){const t=s(e);if(!t)throw new Error("no form provided");return t},useField:function(t){return gt(t,e)},useFieldArray:function(t){return Ot(t,e)},useFieldArrayItem:function(t){return At(t,e)}}}const Dt=c(null),Mt=Dt.Provider;function Nt(){const e=s(Dt);if(!e)throw new Error("no group provided");return e}function Bt({form:t,context:n,initialValues:r,values:o,onSubmit:i,onValidSubmit:u,onInvalidSubmit:s,shouldFocusError:a,...c}){const l=Ye({initialValues:r,values:o}),f=t||l,d=Be(f,{onSubmit:i,onValidSubmit:u,onInvalidSubmit:s,shouldFocusError:a}),{Provider:m}=n??Tt;return e.createElement(m,{value:f},e.createElement("form",{...c,noValidate:!0,onSubmit:d}))}function Pt(e){return e.replace(/["'[\],\s]+/g,"-").replace(/^-+|-+$/g,"")||"field"}function It(e,t,n){return{"aria-invalid":!!e||n["aria-invalid"],"aria-describedby":e?[n["aria-describedby"],Pt(t)].filter(Boolean).join(" "):n["aria-describedby"]}}function $t(e){return Pt(S(e).key)}const qt=e.forwardRef(({validate:t,eventToValue:n,initialValue:r,name:o,asProps:i,renderError:u,as:s,valueToProps:a,form:c,shouldUnregister:l,rules:f,validateDebounce:m,disabled:y,delayError:h,mode:v,...p},g)=>{const b=e.useRef(null),[k,w]=e.useState(0),S=e.useCallback(e=>{b.current=e,function(e,t){"function"==typeof e?e(t):e&&(e.current=t)}(g,e)},[g]),{value:E,onChange:V,onBlur:O,error:_,form:A,name:x,disabled:T}=bt({name:o,form:c,initialValue:r,shouldUnregister:l,rules:f,validateDebounce:m,delayError:h,disabled:y,mode:v,validate:(...e)=>{const n=b.current;if(!n||"function"!=typeof n.checkValidity||(n.setCustomValidity(""),!1!==n.checkValidity()))return t?t(...e):void 0;w(e=>e+1)}}),C=s||"input";e.useEffect(()=>{const e=b.current;e&&"function"==typeof e.setCustomValidity&&("string"==typeof _?(e.setCustomValidity(_),e.reportValidity()):e.setCustomValidity(""))},[_]),e.useEffect(()=>{k>0&&b.current?.reportValidity()},[k]),e.useEffect(()=>d(A.emitter,"focusError",(e,t)=>{if(e!==x)return;const n=b.current;n&&"function"==typeof n.focus&&(n.focus(),t?.shouldSelect&&"function"==typeof n.select&&n.select())}),[A,x]);const L=n??(e=>e.target.value),j=Pt(x);return e.createElement(e.Fragment,null,e.createElement(C,{...p,name:x,onBlur:O,...i,...a?a(E):{value:E},...It(_,x,p),disabled:T,onChange:e=>V(L(e)),ref:S}),_&&u?e.createElement("span",{id:j,role:"alert"},u(_,j)):null)}),Ht=e.forwardRef(({name:t,form:n,initialValue:r,shouldUnregister:o,validate:i,rules:u,validateDebounce:s,disabled:a,delayError:c,mode:l,...f},d)=>{const{value:m,onChange:y,onBlur:h,error:v,name:p,disabled:g}=bt({name:t,form:n,initialValue:r,shouldUnregister:o,validate:i,rules:u,validateDebounce:s,delayError:c,disabled:a,mode:l});return e.createElement("input",{...f,name:p,onBlur:h,type:"checkbox",checked:!!m,...It(v,p,f),disabled:g,onChange:e=>y(e.target.checked),ref:d})});function Rt(e,t){return e?Array.isArray(t)?t:[]:t??""}const Wt=e.forwardRef(({name:t,multiple:n,children:r,form:o,initialValue:i,shouldUnregister:u,validate:s,rules:a,validateDebounce:c,disabled:l,delayError:f,mode:d,...m},y)=>{const{value:h,onChange:v,onBlur:p,error:g,name:b,disabled:k}=bt({name:t,form:o,initialValue:i,shouldUnregister:u,validate:s,rules:a,validateDebounce:c,delayError:f,disabled:l,mode:d});return e.createElement("select",{...m,name:b,onBlur:p,multiple:n,value:Rt(n,h),...It(g,b,m),disabled:k,onChange:e=>v(n?Array.from(e.target.selectedOptions,e=>e.value):e.target.value),ref:y},r)});export{Ht as Checkbox,Dt as CheckboxGroupContext,Mt as CheckboxGroupProvider,qt as Field,Bt as Form,Tt as FormContext,Ct as FormProvider,Wt as Select,E as VALIDATION_OUTCOME,C as changeValue,L as changeValueByPath,F as clearErrors,V as createForm,jt as createFormContext,Te as ensureValidate,$t as fieldErrorId,ie as getDirtyFields,j as getError,D as getErrorByPath,P as getErrors,N as getFieldErrors,B as getFieldErrorsByPath,$ as getFieldState,I as getFirstError,ue as getTouchedFields,_ as getValue,A as getValueByPath,O as getValues,Be as handleSubmit,ye as hasErrors,K as hasTouched,z as hasTouchedByPath,je as incrementSubmitCount,Y as isDirty,se as isTouched,ae as removeField,ce as removeFieldByPath,de as reset,me as resetField,xe as revalidateFormOnChange,Me as setDisabled,R as setError,W as setErrorByPath,Pe as setFocus,fe as setInitialValues,Le as setIsSubmitting,J as setServerErrors,De as setSubmitSuccessful,U as setTouched,G as setTouchedByPath,H as setValidatingByPath,x as setValue,T as setValueByPath,ze as subscribe,he as trigger,q as unsetValidatingByPath,dt as useCanSubmit,Nt as useCheckboxGroupContext,at as useDirtyFields,rt as useError,ot as useErrorByPath,bt as useField,_t as useFieldArray,xt as useFieldArrayItem,it as useFieldErrors,ut as useFieldErrorsByPath,Ye as useForm,Lt as useFormContext,lt as useHasErrors,st as useIsDirty,ft as useIsSubmitting,mt as useSubmitCount,tt as useTouched,nt as useTouchedByPath,ct as useTouchedFields,Ze as useValue,et as useValueByPath,Xe as useWatch,Ce as validate};
|
|
2
2
|
//# sourceMappingURL=index.mjs.map
|