1import{j as C}from"./jsx-runtime-DlwXME2q.js";import{r as E}from"./chunk-JMJ3UQ3L-C2QzpDYB.js";import{F as Rt}from"./index-CLAXKjud.js";(function(){try{var e=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{};e.SENTRY_RELEASE={id:"9a1d8ca"};var s=new e.Error().stack;s&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[s]="7abdfefb-a12f-4d94-a6fb-47b530c058e1",e._sentryDebugIdIdentifier="sentry-dbid-7abdfefb-a12f-4d94-a6fb-47b530c058e1")}catch{}})();const x=new WeakMap,Q=new WeakMap,et={current:[]};let ut=!1,G=0;const z=new Set,K=new Map;function At(e){const s=Array.from(e).sort((r,t)=>r instanceof T&&r.options.deps.includes(t)?1:t instanceof T&&t.options.deps.includes(r)?-1:0);for(const r of s){if(et.current.includes(r))continue;et.current.push(r),r.recompute();const t=Q.get(r);if(t)for(const i of t){const n=x.get(i);n&&At(n)}}}function Bt(e){const s={prevVal:e.prevState,currentVal:e.state};for(const r of e.listeners)r(s)}function xt(e){const s={prevVal:e.prevState,currentVal:e.state};for(const r of e.listeners)r(s)}function It(e){if(G>0&&!K.has(e)&&K.set(e,e.prevState),z.add(e),!(G>0)&&!ut)try{for(ut=!0;z.size>0;){const s=Array.from(z);z.clear();for(const r of s){const t=K.get(r)??r.prevState;r.prevState=t,Bt(r)}for(const r of s){const t=x.get(r);t&&(et.current.push(r),At(t))}for(const r of s){const t=x.get(r);if(t)for(const i of t)xt(i)}}}finally{ut=!1,et.current=[],K.clear()}}function I(e){G++;try{e()}finally{if(G--,G===0){const s=z.values().next().value;s&&It(s)}}}function Ut(e){return typeof e=="function"}class st{constructor(s,r){this.listeners=new Set,this.subscribe=t=>{var i,n;this.listeners.add(t);const a=(n=(i=this.options)==null?void 0:i.onSubscribe)==null?void 0:n.call(i,t,this);return()=>{this.listeners.delete(t),a?.()}},this.prevState=s,this.state=s,this.options=r}setState(s){var r,t,i;this.prevState=this.state,(r=this.options)!=null&&r.updateFn?this.state=this.options.updateFn(this.prevState)(s):Ut(s)?this.state=s(this.prevState):this.state=s,(i=(t=this.options)==null?void 0:t.onUpdate)==null||i.call(t),It(this)}}class T{constructor(s){this.listeners=new Set,this._subscriptions=[],this.lastSeenDepValues=[],this.getDepVals=()=>{const r=this.options.deps.length,t=new Array(r),i=new Array(r);for(let n=0;n<r;n++){const a=this.options.deps[n];t[n]=a.prevState,i[n]=a.state}return this.lastSeenDepValues=i,{prevDepVals:t,currDepVals:i,prevVal:this.prevState??void 0}},this.recompute=()=>{var r,t;this.prevState=this.state;const i=this.getDepVals();this.state=this.options.fn(i),(t=(r=this.options).onUpdate)==null||t.call(r)},this.checkIfRecalculationNeededDeeply=()=>{for(const n of this.options.deps)n instanceof T&&n.checkIfRecalculationNeededDeeply();let r=!1;const t=this.lastSeenDepValues,{currDepVals:i}=this.getDepVals();for(let n=0;n<i.length;n++)if(i[n]!==t[n]){r=!0;break}r&&this.recompute()},this.mount=()=>(this.registerOnGraph(),this.checkIfRecalculationNeededDeeply(),()=>{this.unregisterFromGraph();for(const r of this._subscriptions)r()}),this.subscribe=r=>{var t,i;this.listeners.add(r);const n=(i=(t=this.options).onSubscribe)==null?void 0:i.call(t,r,this);return()=>{this.listeners.delete(r),n?.()}},this.options=s,this.state=s.fn({prevDepVals:void 0,prevVal:void 0,currDepVals:this.getDepVals().currDepVals})}registerOnGraph(s=this.options.deps){for(const r of s)if(r instanceof T)r.registerOnGraph(),this.registerOnGraph(r.options.deps);else if(r instanceof st){let t=x.get(r);t||(t=new Set,x.set(r,t)),t.add(this);let i=Q.get(this);i||(i=new Set,Q.set(this,i)),i.add(r)}}unregisterFromGraph(s=this.options.deps){for(const r of s)if(r instanceof T)this.unregisterFromGraph(r.options.deps);else if(r instanceof st){const t=x.get(r);t&&t.delete(this);const i=Q.get(this);i&&i.delete(r)}}}function Wt(e){return typeof e=="function"}function pt(e,...s){return Wt(e)?e(...s):e}function Nt(e){return e||(typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():"")}class Lt{#s=!0;#t;#e;#n;#i;#r;#a;#l;#c=0;#h=5;#o=!1;#d=()=>{this.debugLog("Connected to event bus"),this.#r=!0,this.#o=!1,this.debugLog("Emitting queued events",this.#i),this.#i.forEac
1h(s=>this.emitEventToBus(s)),this.#i=[],this.stopConnectLoop(),this.#e().removeEventListener("tanstack-connect-success",this.#d)};#u=()=>{if(this.#c<this.#h){this.#c++,this.dispatchCustomEvent("tanstack-connect",{});return}this.#e().removeEventListener("tanstack-connect",this.#u),this.debugLog("Max retries reached, giving up on connection"),this.stopConnectLoop()};#f=()=>{this.#o||(this.#o=!0,this.#e().addEventListener("tanstack-connect-success",this.#d),this.#u())};constructor({pluginId:s,debug:r=!1,enabled:t=!0,reconnectEveryMs:i=300}){this.#t=s,this.#s=t,this.#e=this.getGlobalTarget,this.#n=r,this.debugLog(" Initializing event subscription for plugin",this.#t),this.#i=[],this.#r=!1,this.#a=null,this.#l=i}startConnectLoop(){this.#a!==null||this.#r||(this.debugLog(`Starting connect loop (every ${this.#l}ms)`),this.#a=setInterval(this.#u,this.#l))}stopConnectLoop(){this.#o=!1,this.#a!==null&&(clearInterval(this.#a),this.#a=null,this.debugLog("Stopped connect loop"))}debugLog(...s){this.#n}getGlobalTarget(){if(typeof globalThis<"u"&&globalThis.__TANSTACK_EVENT_TARGET__)return this.debugLog("Using global event target"),globalThis.__TANSTACK_EVENT_TARGET__;if(typeof window<"u"&&typeof window.addEventListener<"u")return this.debugLog("Using window as event target"),window;const s=typeof EventTarget<"u"?new EventTarget:void 0;return typeof s>"u"||typeof s.addEventListener>"u"?(this.debugLog("No event mechanism available, running in non-web environment"),{addEventListener:()=>{},removeEventListener:()=>{},dispatchEvent:()=>!1}):(this.debugLog("Using new EventTarget as fallback"),s)}getPluginId(){return this.#t}dispatchCustomEventShim(s,r){try{const t=new Event(s,{detail:r});this.#e().dispatchEvent(t)}catch{this.debugLog("Failed to dispatch shim event")}}dispatchCustomEvent(s,r){try{this.#e().dispatchEvent(new CustomEvent(s,{detail:r}))}catch{this.dispatchCustomEventShim(s,r)}}emitEventToBus(s){this.debugLog("Emitting event to client bus",s),this.dispatchCustomEvent("tanstack-dispatch-event",s)}emit(s,r){if(!this.#s){this.debugLog("Event bus client is disabled, not emitting event",s,r);return}if(!this.#r){this.debugLog("Bus not available, will be pushed as soon as connected"),this.#i.push({type:`${this.#t}:${s}`,payload:r,pluginId:this.#t}),typeof CustomEvent<"u"&&!this.#o&&(this.#f(),this.startConnectLoop());return}return this.emitEventToBus({type:`${this.#t}:${s}`,payload:r,pluginId:this.#t})}on(s,r){const t=`${this.#t}:${s}`;if(!this.#s)return this.debugLog("Event bus client is disabled, not registering event",t),()=>{};const i=n=>{this.debugLog("Received event from bus",n.detail),r(n.detail)};return this.#e().addEventListener(t,i),this.debugLog("Registered event to bus",t),()=>{this.#e().removeEventListener(t,i)}}onAll(s){if(!this.#s)return this.debugLog("Event bus client is disabled, not registering event"),()=>{};const r=t=>{const i=t.detail;s(i)};return this.#e().addEventListener("tanstack-devtools-global",r),()=>this.#e().removeEventListener("tanstack-devtools-global",r)}onAllPluginEvents(s){if(!this.#s)return this.debugLog("Event bus client is disabled, not registering event"),()=>{};const r=t=>{const i=t.detail;this.#t&&i.pluginId!==this.#t||s(i)};return this.#e().addEventListener("tanstack-devtools-global",r),()=>this.#e().removeEventListener("tanstack-devtools-global",r)}}class zt extends Lt{constructor(s){super({pluginId:"pacer",debug:s?.debug})}}const Gt=(e,s)=>{Tt.emit(e,s)},Tt=new zt;function Mt(){return{executionCount:0,isPending:!1,lastArgs:void 0,lastExecutionTime:0,nextExecutionTime:0,status:"idle",maybeExecuteCount:0}}const Kt={enabled:!0,leading:!0,trailing:!0,wait:0};class jt{constructor(s,r){this.fn=s,this.store=new st(Mt()),this.setOptions=t=>{this.options={...this.options,...t},this.#e()||this.cancel()},this.#t=t=>{this.store.setState(i=>{const n={...i,...t},{isPending:a}=n;return{...n,status:this.#e()?a?"pending":"idle":"disabled"}}),Gt("Throttler",this)},this.#e=()=>!!pt(this.options.enabled,this),this.#n=()=>pt(this.options.wait,this),this.maybeExecute=(...t)=>{this.#t({maybeExecuteCount:this.store.state.maybeExecuteCount+1});const i=Date.now(),n=i-this.store.state.lastExecutionTime,a=this.#n();if(this.options.leading&&n>=a)this.#i(...t);else if(this.#t({lastArgs:t}),!this.#s&&this.options.trailing){const c=this.store.state.lastExecutionTime?i-this.store.state.lastExecutionTime:0,u=a-c;this.#t({isPending:!0}),this.#s=setTimeout(()=>{const{lastArgs:o}=this.store.state;o!==void 0&&this.#i(...o)},u)}},this.#i=(...t)=>{if(!this.#e())return;this.fn(...t);const i=Date.now(),n=i+this.#n();this.#r(),this.#t({executionCount:this.store.state.executionCount+1,lastExecutionTime:i,nextExecutionTime:n,isPending:!1,lastArgs:void 0}),this.options.onExecute?.(t,this),setTimeout(()=>{this.store.state.isPending||this.#t({nextExecutionTime:void 0})},this.#n())},this.flush=()=>{this.store.state.isPending&&this.store.state.lastArgs&&this.#i(...this.store.state.lastArgs)},this.#r=()=>{this.#s&&(clearTimeout(this.#s),this.#s=void 0)},this.cancel=()=>{this.#r(),this.#t({lastArgs:void 0,isPending:!1})},this.reset=()=>{this.#t(Mt())},this.key=Nt(r.key),this.options={...Kt,...r},this.#t(this.options.initialState??{}),Tt.on("d-Throttler",t=>{t.payload.key===this.key&&(this.#t(t.payload.store.state),this.setOptions(t.payload.options))})}#s;#t;#e;#n;#i;#r}function qt(e,s){return new jt(e,s).maybeExecute}function nt(e,s){return typeof e=="function"?e(s):e}
1function j(e,s){return gt(s).reduce((t,i)=>{if(t===null)return null;if(typeof t<"u")return t[i]},e)}function q(e,s,r){const t=gt(s);function i(n){if(!t.length)return nt(r,n);const a=t.shift();if(typeof a=="string"||typeof a=="number"&&!Array.isArray(n))return typeof n=="object"?(n===null&&(n={}),{...n,[a]:i(n[a])}):{[a]:i()};if(Array.isArray(n)&&typeof a=="number"){const c=n.slice(0,a);return[...c.length?c:new Array(a),i(n[a]),...n.slice(a+1)]}return[...new Array(a),i()]}return i(e)}function Ht(e,s){const r=gt(s);function t(i){if(!i)return;if(r.length===1){const a=r[0];if(Array.isArray(i)&&typeof a=="number")return i.filter((o,l)=>l!==a);const{[a]:c,...u}=i;return u}const n=r.shift();if((typeof n=="string"||typeof n=="number"&&!Array.isArray(i))&&typeof i=="object")return{...i,[n]:t(i[n])};if(typeof n=="number"&&Array.isArray(i)){if(n>=i.length)return i;const a=i.slice(0,n);return[...a.length?a:new Array(n),t(i[n]),...i.slice(n+1)]}throw new Error("It seems we have created an infinite loop in deleteBy. ")}return t(e)}const Xt=/^(\d+)$/gm,Yt=/\.(\d+)(?=\.)/gm,Jt=/^(\d+)\./gm,Qt=/\.(\d+$)/gm,Zt=/\.{2,}/gm,ht="__int__",H=`${ht}$1`;function gt(e){if(Array.isArray(e))return[...e];if(typeof e!="string")throw new Error("Path must be a string.");return e.replace(/(^\[)|]/gm,"").replace(/\[/g,".").replace(Xt,H).replace(Yt,`.${H}.`).replace(Jt,`${H}.`).replace(Qt,`.${H}`).replace(Zt,".").split(".").map(s=>{if(s.startsWith(ht)){const r=s.substring(ht.length),t=parseInt(r,10);return String(t)===r?t:r}return s})}function te(e){return!(Array.isArray(e)&&e.length===0)}function ft(e,s){const r=t=>t.validators.filter(Boolean).map(i=>({cause:i.cause,validate:i.fn}));return s.validationLogic({form:s.form,validators:s.validators,event:{type:e,async:!1},runValidation:r})}function mt(e,s){const{asyncDebounceMs:r}=s,{onBlurAsyncDebounceMs:t,onChangeAsyncDebounceMs:i,onDynamicAsyncDebounceMs:n}=s.validators||{},a=r??0,c=u=>u.validators.filter(Boolean).map(o=>{const l=o?.cause||e;let h=a;switch(l){case"change":h=i??a;break;case"blur":h=t??a;break;case"dynamic":h=n??a;break;case"submit":h=0;break}return e==="submit"&&(h=0),{cause:l,validate:o.fn,debounceMs:h}});return s.validationLogic({form:s.form,validators:s.validators,event:{type:e,async:!0},runValidation:c})}const vt=e=>!!e&&typeof e=="object"&&"fields"in e;function O(e,s){if(Object.is(e,s))return!0;if(typeof e!="object"||e===null||typeof s!="object"||s===null)return!1;if(e instanceof Date&&s instanceof Date)return e.getTime()===s.getTime();if(e instanceof Map&&s instanceof Map){if(e.size!==s.size)return!1;for(const[i,n]of e)if(!s.has(i)||!Object.is(n,s.get(i)))return!1;return!0}if(e instanceof Set&&s instanceof Set){if(e.size!==s.size)return!1;for(const i of e)if(!s.has(i))return!1;return!0}const r=Object.keys(e),t=Object.keys(s);if(r.length!==t.length)return!1;for(const i of r)if(!t.includes(i)||!O(e[i],s[i]))return!1;return!0}const bt=({newFormValidatorError:e,isPreviousErrorFromFormValidator:s,previousErrorValue:r})=>e?{newErrorValue:e,newSource:"form"}:s?{newErrorValue:void 0,newSource:void 0}:r?{newErrorValue:r,newSource:"field"}:{newErrorValue:void 0,newSource:void 0},yt=({formLevelError:e,fieldLevelError:s})=>s?{newErrorValue:s,newSource:"field"}:e?{newErrorValue:e,newSource:"form"}:{newErrorValue:void 0,newSource:void 0};function F(e,s){return e==null?s:{...e,...s}}let P=256;const Z=[];let X;for(;P--;)Z[P]=(P+256).toString(16).substring(1);function Dt(){let e=0,s,r="";if(!X||P+16>256){for(X=new Array(256),e=256;e--;)X[e]=256*Math.random()|0;e=0,P=0}for(;e<16;e++)s=X[P+e],e===6?r+=Z[s&15|64]:e===8?r+=Z[s&63|128]:r+=Z[s],e&1&&e>1&&e<11&&(r+="-");return P++,r}const B=e=>{if(!e.validators)return e.runValidation({validators:[],form:e.form});const s=e.event.async,r=s?void 0:{fn:e.validators.onMount,cause:"mount"},t={fn:s?e.validators.onChangeAsync:e.validators.onChange,cause:"change"},i={fn:s?e.validators.onBlurAsync:e.validators.onBlur,cause:"blur"},n={fn:s?e.validators.onSubmitAsync:e.validators.onSubmit,cause:"submit"},a=s?void 0:{fn:()=>{},cause:"server"};switch(e.event.type){case"mount":return e.runValidation({validators:[r],form:e.form});case"submit":return e.runValidation({validators:[t,i,n,a],form:e.form});
1case"server":return e.runValidation({validators:[],form:e.form});case"blur":return e.runValidation({validators:[i,a],form:e.form});case"change":return e.runValidation({validators:[t,a],form:e.form});default:throw new Error(`Unknown validation event type: ${e.event.type}`)}};function ee(e,s){const r=new Map;for(const t of e){const i=t.path??[];let n=s,a="";for(let c=0;c<i.length;c++){const u=i[c];if(u===void 0)continue;const o=typeof u=="object"?u.key:u,l=Number(o);Array.isArray(n)&&!Number.isNaN(l)?a+=`[${l}]`:a+=(c>0?".":"")+String(o),typeof n=="object"&&n!==null?n=n[o]:n=void 0}r.set(a,(r.get(a)??[]).concat(t))}return Object.fromEntries(r)}const St=(e,s)=>{const r=ee(e,s);return{form:r,fields:r}},U={validate({value:e,validationSource:s},r){const t=r["~standard"].validate(e);if(t instanceof Promise)throw new Error("async function passed to sync validator");if(t.issues)return s==="field"?t.issues:St(t.issues,e)},async validateAsync({value:e,validationSource:s},r){const t=await r["~standard"].validate(e);if(t.issues)return s==="field"?t.issues:St(t.issues,e)}},_t=e=>!!e&&"~standard"in e,it={isValidating:!1,isTouched:!1,isBlurred:!1,isDirty:!1,isPristine:!0,isValid:!0,isDefaultValue:!0,errors:[],errorMap:{},errorSourceMap:{}};function Y(e){function s(l,h,f){const d=a(l,h,"move",f),m=Math.min(h,f),g=Math.max(h,f);for(let v=m;v<=g;v++)d.push(n(l,v));const M=Object.keys(e.fieldInfo).reduce((v,p)=>(p.startsWith(n(l,h))&&v.set(p,e.getFieldMeta(p)),v),new Map);u(d,h<f?"up":"down"),Object.keys(e.fieldInfo).filter(v=>v.startsWith(n(l,f))).forEach(v=>{const p=v.replace(n(l,f),n(l,h)),y=M.get(p);y&&e.setFieldMeta(v,y)})}function r(l,h){const f=a(l,h,"remove");u(f,"up")}function t(l,h,f){a(l,h,"swap",f).forEach(m=>{if(!m.toString().startsWith(n(l,h)))return;const g=m.toString().replace(n(l,h),n(l,f)),[M,v]=[e.getFieldMeta(m),e.getFieldMeta(g)];M&&e.setFieldMeta(g,M),v&&e.setFieldMeta(m,v)})}function i(l,h){const f=a(l,h,"insert");u(f,"down"),f.forEach(d=>{d.toString().startsWith(n(l,h))&&e.setFieldMeta(d,o())})}function n(l,h){return`${l}[${h}]`}function a(l,h,f,d){const m=[n(l,h)];switch(f){case"swap":m.push(n(l,d));break;case"move":{const[g,M]=[Math.min(h,d),Math.max(h,d)];for(let v=g;v<=M;v++)m.push(n(l,v));break}default:{const g=e.getFieldValue(l),M=Array.isArray(g)?g.length:0;for(let v=h+1;v<M;v++)m.push(n(l,v));break}}return Object.keys(e.fieldInfo).filter(g=>m.some(M=>g.startsWith(M)))}function c(l,h){return l.replace(/\[(\d+)\]/,(f,d)=>{const m=parseInt(d,10);return`[${h==="up"?m+1:Math.max(0,m-1)}]`})}function u(l,h){(h==="up"?l:[...l].reverse()).forEach(d=>{const m=c(d.toString(),h),g=e.getFieldMeta(m);g?e.setFieldMeta(d,g):e.setFieldMeta(d,o())})}const o=()=>it;return{handleArrayMove:s,handleArrayRemove:r,handleArraySwap:t,handleArrayInsert:i}}class se extends Lt{constructor(){super({pluginId:"form-devtools",reconnectEveryMs:1e3})}}const A=new se;function ct(e){return{values:e.values??{},errorMap:e.errorMap??{},fieldMetaBase:e.fieldMetaBase??{},isSubmitted:e.isSubmitted??!1,isSubmitting:e.isSubmitting??!1,isValidating:e.isValidating??!1,submissionAttempts:e.submissionAttempts??0,isSubmitSuccessful:e.isSubmitSuccessful??!1,validationMetaMap:e.validationMetaMap??{onChange:void 0,onBlur:void 0,onSubmit:void 0,onMount:void 0,onServer:void 0,onDynamic:void 0}}}class Vt{constructor(s){this.options={},this.fieldInfo={},this.prevTransformArray=[],this.mount=()=>{const t=this.fieldMetaDerived.mount(),i=this.store.mount(),n=()=>{t(),i(),A.emit("form-unmounted",{id:this._formId})};this.options.listeners?.onMount?.({formApi:this});const{onMount:a}=this.options.validators||{};return A.emit("form-api",{id:this._formId,state:this.store.state,options:this.options}),a&&this.validateSync("mount"),n},this.update=t=>{if(!t)return;const i=this.options;this.options=t;const n=!!t.transform?.deps?.some((u,o)=>u!==this.prevTransformArray[o]),a=t.defaultValues&&!O(t.defaultValues,i.defaultValues)&&!this.state.isTouched,c=!O(t.defaultState,i.defaultState)&&!this.state.isTouched;!a&&!c&&!n||(I(()=>{this.baseStore.setState(()=>ct(Object.assign({},this.state,c?t.defaultState:{},a?{values:t.defaultValues}:{},n?{_force_re_eval:!this.state._force_re_eval}:{})))}),A.emit("form-api",{id:this._formId,state:this.store.state,options:this.options}))},this.reset=(t,i)=>{const{fieldMeta:n}=this.state,a=this.resetFieldMeta(n);t&&!i?.keepDefaultValues&&(this.options={...this.options,defaultValues:t}),this.baseStore.setState(()=>ct({...this.options.defaultState,values:t??this.options.defaultValues??this.options.defaultState?.values,fieldMetaBase:a}))},this.validateAllFields=async t=>{const i=[];return I(()=>
1{Object.values(this.fieldInfo).forEach(a=>{if(!a.instance)return;const c=a.instance;i.push(Promise.resolve().then(()=>c.validate(t,{skipFormValidation:!0}))),a.instance.state.meta.isTouched||a.instance.setMeta(u=>({...u,isTouched:!0}))})}),(await Promise.all(i)).flat()},this.validateArrayFieldsStartingFrom=async(t,i,n)=>{const a=this.getFieldValue(t),c=Array.isArray(a)?Math.max(a.length-1,0):null,u=[`${t}[${i}]`];for(let f=i+1;f<=(c??0);f++)u.push(`${t}[${f}]`);const o=Object.keys(this.fieldInfo).filter(f=>u.some(d=>f.startsWith(d))),l=[];return I(()=>{o.forEach(f=>{l.push(Promise.resolve().then(()=>this.validateField(f,n)))})}),(await Promise.all(l)).flat()},this.validateField=(t,i)=>{const n=this.fieldInfo[t]?.instance;return n?(n.state.meta.isTouched||n.setMeta(a=>({...a,isTouched:!0})),n.validate(i)):[]},this.validateSync=t=>{const i=ft(t,{...this.options,form:this,validationLogic:this.options.validationLogic||B});let n=!1;const a={};return I(()=>{for(const o of i){if(!o.validate)continue;const l=this.runValidator({validate:o.validate,value:{value:this.state.values,formApi:this,validationSource:"form"},type:"validate"}),{formError:h,fieldErrors:f}=tt(l),d=N(o.cause);for(const m of Object.keys(this.state.fieldMeta)){if(this.baseStore.state.fieldMetaBase[m]===void 0)continue;const g=this.getFieldMeta(m);if(!g)continue;const{errorMap:M,errorSourceMap:v}=g,p=f?.[m],{newErrorValue:y,newSource:V}=bt({newFormValidatorError:p,isPreviousErrorFromFormValidator:v?.[d]==="form",previousErrorValue:M?.[d]});V==="form"&&(a[m]={...a[m],[d]:p}),M?.[d]!==y&&this.setFieldMeta(m,S=>({...S,errorMap:{...S.errorMap,[d]:y},errorSourceMap:{...S.errorSourceMap,[d]:V}}))}this.state.errorMap?.[d]!==h&&this.baseStore.setState(m=>({...m,errorMap:{...m.errorMap,[d]:h}})),(h||f)&&(n=!0)}const c=N("submit");this.state.errorMap?.[c]&&t!=="submit"&&!n&&this.baseStore.setState(o=>({...o,errorMap:{...o.errorMap,[c]:void 0}}));const u=N("server");this.state.errorMap?.[u]&&t!=="server"&&!n&&this.baseStore.setState(o=>({...o,errorMap:{...o.errorMap,[u]:void 0}}))}),{hasErrored:n,fieldsErrorMap:a}},this.validateAsync=async t=>{const i=mt(t,{...this.options,form:this,validationLogic:this.options.validationLogic||B});this.state.isFormValidating||this.baseStore.setState(o=>({...o,isFormValidating:!0}));const n=[];let a;for(const o of i){if(!o.validate)continue;const l=N(o.cause);this.state.validationMetaMap[l]?.lastAbortController.abort();const f=new AbortController;this.state.validationMetaMap[l]={lastAbortController:f},n.push(new Promise(async d=>{let m;try{m=await new Promise((p,y)=>{setTimeout(async()=>{if(f.signal.aborted)return p(void 0);try{p(await this.runValidator({validate:o.validate,value:{value:this.state.values,formApi:this,validationSource:"form",signal:f.signal},type:"validateAsync"}))}catch(V){y(V)}},o.debounceMs)})}catch(p){m=p}const{formError:g,fieldErrors:M}=tt(m);M&&(a=a?{...a,...M}:M);const v=N(o.cause);for(const p of Object.keys(this.state.fieldMeta)){if(this.baseStore.state.fieldMetaBase[p]===void 0)continue;const y=this.getFieldMeta(p);if(!y)continue;const{errorMap:V,errorSourceMap:S}=y,D=a?.[p],{newErrorValue:_,newSource:w}=bt({newFormValidatorError:D,isPreviousErrorFromFormValidator:S?.[v]==="form",previousErrorValue:V?.[v]});V?.[v]!==_&&this.setFieldMeta(p,k=>({...k,errorMap:{...k.errorMap,[v]:_},errorSourceMap:{...k.errorSourceMap,[v]:w}}))}this.baseStore.setState(p=>({...p,errorMap:{...p.errorMap,[v]:g}})),d(a?{fieldErrors:a,errorMapKey:v}:void 0)}))}let c=[];const u={};if(n.length){c=await Promise.all(n);for(const o of c)if(o?.fieldErrors){const{errorMapKey:l}=o;for(const[h,f]of Object.entries(o.fieldErrors)){const m={...u[h]||{},[l]:f};u[h]=m}}}return this.baseStore.setState(o=>({...o,isFormValidating:!1})),u},this.validate=t=>{const{hasErrored:i,fieldsErrorMap:n}=this.validateSync(t);return i&&!this.options.asyncAlways?n:this.validateAsync(t)},this._handleSubmit=async t=>{this.baseStore.setState(a=>({...a,isSubmitted:!1,submissionAttempts:a.submissionAttempts+1,isSubmitSuccessful:!1})),I(()=>
1{Object.values(this.fieldInfo).forEach(a=>{a.instance&&(a.instance.state.meta.isTouched||a.instance.setMeta(c=>({...c,isTouched:!0})))})});const i=t??this.options.onSubmitMeta;if(!this.state.canSubmit&&!this._devtoolsSubmissionOverride){this.options.onSubmitInvalid?.({value:this.state.values,formApi:this,meta:i});return}this.baseStore.setState(a=>({...a,isSubmitting:!0}));const n=()=>{this.baseStore.setState(a=>({...a,isSubmitting:!1}))};if(await this.validateAllFields("submit"),!this.state.isFieldsValid){n(),this.options.onSubmitInvalid?.({value:this.state.values,formApi:this,meta:i}),A.emit("form-submission",{id:this._formId,submissionAttempt:this.state.submissionAttempts,successful:!1,stage:"validateAllFields",errors:Object.values(this.state.fieldMeta).map(a=>a.errors).flat()});return}if(await this.validate("submit"),!this.state.isValid){n(),this.options.onSubmitInvalid?.({value:this.state.values,formApi:this,meta:i}),A.emit("form-submission",{id:this._formId,submissionAttempt:this.state.submissionAttempts,successful:!1,stage:"validate",errors:this.state.errors});return}I(()=>{Object.values(this.fieldInfo).forEach(a=>{a.instance?.options.listeners?.onSubmit?.({value:a.instance.state.value,fieldApi:a.instance})})}),this.options.listeners?.onSubmit?.({formApi:this,meta:i});try{await this.options.onSubmit?.({value:this.state.values,formApi:this,meta:i}),I(()=>{this.baseStore.setState(a=>({...a,isSubmitted:!0,isSubmitSuccessful:!0})),A.emit("form-submission",{id:this._formId,submissionAttempt:this.state.submissionAttempts,successful:!0}),n()})}catch(a){throw this.baseStore.setState(c=>({...c,isSubmitSuccessful:!1})),A.emit("form-submission",{id:this._formId,submissionAttempt:this.state.submissionAttempts,successful:!1,stage:"inflight",onError:a}),n(),a}},this.getFieldValue=t=>j(this.state.values,t),this.getFieldMeta=t=>this.state.fieldMeta[t],this.getFieldInfo=t=>this.fieldInfo[t]||={instance:null,validationMetaMap:{onChange:void 0,onBlur:void 0,onSubmit:void 0,onMount:void 0,onServer:void 0,onDynamic:void 0}},this.setFieldMeta=(t,i)=>{this.baseStore.setState(n=>({...n,fieldMetaBase:{...n.fieldMetaBase,[t]:nt(i,n.fieldMetaBase[t])}}))},this.resetFieldMeta=t=>Object.keys(t).reduce((i,n)=>{const a=n;return i[a]=it,i},{}),this.setFieldValue=(t,i,n)=>{const a=n?.dontUpdateMeta??!1,c=n?.dontRunListeners??!1,u=n?.dontValidate??!1;I(()=>{a||this.setFieldMeta(t,o=>({...o,isTouched:!0,isDirty:!0,errorMap:{...o?.errorMap,onMount:void 0}})),this.baseStore.setState(o=>({...o,values:q(o.values,t,i)}))}),c||this.getFieldInfo(t).instance?.triggerOnChangeListener(),u||this.validateField(t,"change")},this.deleteField=t=>{const n=[...Object.keys(this.fieldInfo).filter(a=>{const c=t.toString();return a!==c&&a.startsWith(c)}),t];this.baseStore.setState(a=>{const c={...a};return n.forEach(u=>{c.values=Ht(c.values,u),delete this.fieldInfo[u],delete c.fieldMetaBase[u]}),c})},this.pushFieldValue=(t,i,n)=>{this.setFieldValue(t,a=>[...Array.isArray(a)?a:[],i],n)},this.insertFieldValue=async(t,i,n,a)=>{this.setFieldValue(t,u=>[...u.slice(0,i),n,...u.slice(i)],F(a,{dontValidate:!0}));const c=a?.dontValidate??!1;c||await this.validateField(t,"change"),Y(this).handleArrayInsert(t,i),c||await this.validateArrayFieldsStartingFrom(t,i,"change")},this.replaceFieldValue=async(t,i,n,a)=>{this.setFieldValue(t,u=>u.map((o,l)=>l===i?n:o),F(a,{dontValidate:!0})),(a?.dontValidate??!1)||(await this.validateField(t,"change"),await this.validateArrayFieldsStartingFrom(t,i,"change"))},this.removeFieldValue=async(t,i,n)=>{const a=this.getFieldValue(t),c=Array.isArray(a)?Math.max(a.length-1,0):null;if(this.setFieldValue(t,o=>o.filter((l,h)=>h!==i),F(n,{dontValidate:!0})),Y(this).handleArrayRemove(t,i),c!==null){const o=`${t}[${c}]`;this.deleteField(o)}(n?.dontValidate??!1)||(await this.validateField(t,"change"),await this.validateArrayFieldsStartingFrom(t,i,"change"))},this.swapFieldValues=(t,i,n,a)=>{this.setFieldValue(t,u=>{const o=u[i],l=u[n];return q(q(u,`${i}`,l),`${n}`,o)},F(a,{dontValidate:!0})),Y(this).handleArraySwap(t,i,n),(a?.dontValidate??!1)||(this.validateField(t,"change"),this.validateField(`${t}[${i}]`,"change"),this.validateField(`${t}[${n}]`,"change"))},this.moveFieldValues=(t,i,n,a)=>{this.setFieldValue(t,u=>{const o=[...u];return o.splice(n,0,o.splice(i,1)[0]),o},F(a,{dontValidate:!0})),Y(this).handleArrayMove(t,i,n),(a?.dontValidate??!1)||(this.validateField(t,"change"),this.validateField(`${t}[${i}]`,"change"),this.validateField(`${t}[${n}]`,"change"))},this.clearFieldValues=(t,i)=>{const n=this.getFieldValue(t),a=Array.isArray(n)?Math.max(n.length-1,0):null;if(this.setFieldValue(t,[],F(i,{dontValidate:!0})),a!==null)for(let u=0;u<=a;u++){const o=`${t}[${u}]`;this.deleteField(o)}(i?.dontValidate??!1)||this.validateField(t,"change")},this.resetField=t=>{this.baseStore.setState(i=>({...i,fieldMetaBase:{...i.fieldMetaBase,[t]:it},values:this.options.defaultValues?q(i.values,t,j(this.options.defaultValues,t)):i.values}))},this.setErrorMap=t=>{I(()=>{Object.entries(t).forEach(([i,n])=>{const a=i;if(vt(n)){const{formError:c,fieldErrors:u}=tt(n);for(const o of Object.keys(this.fieldInfo))this.getFieldMeta(o)&&this.setFieldMeta(o,h=>({...h,errorMap:{...h.errorMap,[a]:u?.[o]},errorSourceMap:{...h.errorSourceMap,[a]:"form"}}));this.baseStore.setState(o=>({...o,errorMap:{...o.errorMap,[a]:c}}))}else this.baseStore.setState(c=>({...c,errorMap:{...c.errorMap,[a]:n}}))})})},this.getAllErrors=()=>({form:{errors:this.state.errors,errorMap:this.state.errorMap},fields:Object.entries(this.state.fieldMeta).reduce((t,[i,n])=>(Object.keys(n).length&&n.errors.length&&(t[i]={errors:n.errors,errorMap:n.errorMap}),t),{})}),this.parseValuesWithSchema=t=>U.validate({value:this.state.values,validationSource:"form"},t),this.parseValuesWithSchemaAsync=t=>U.validateAsync({value:this.state.values,validationSource:"form"},t),this.timeoutIds={validations:{},listeners:{},formListeners:{}},this._formId=s?.formId??Dt(),this._devtoolsSubmissionOverride=!1,this.baseStore=new st(ct({...s?.defaultState,values:s?.defaultValues??s?.defaultState?.values})),this.fieldMetaDerived=new T({deps:[this.baseStore],fn:({prevDepVals:t,currDepVals:i,prevVal:n})=>{const a=n,c=t?.[0],u=i[0];let o=0;const l={};for(const h of Object.keys(u.fieldMetaBase)){const f=u.fieldMetaBase[h],d=c?.fieldMetaBase[h],m=a?.[h],g=j(u.values,h);let M=m?.errors;if(!d||f.errorMap!==d.errorMap){M=Object.values(f.errorMap??{}).filter(S=>S!==void 0);const V=this.getFieldInfo(h)?.instance;V&&!V.options.disableErrorFlat&&(M=M.flat(1))}const v=!te(M),p=!f.isDirty,y=O(g,j(this.options.defaultValues,h))||O(g,this.getFieldInfo(h)?.instance?.options.defaultValue);if(m&&m.isPristine===p&&m.isValid===v&&m.isDefaultValue===y&&m.errors===M&&f===d){l[h]=m,o++;continue}l[h]={...f,errors:M??[],isPristine:p,isValid:v,isDefaultValue:y}}return Object.keys(u.fieldMetaBase).length&&a&&o===Object.keys(u.fieldMetaBase).length?a:l}}),this.store=new T({deps:[this.baseStore,this.fieldMetaDerived],fn:({prevDepVals:t,currDepVals:i,prevVal:n})=>
1{const a=n,c=t?.[0],u=i[0],o=i[1],l=Object.values(o).filter(Boolean),h=l.some(b=>b.isValidating),f=l.every(b=>b.isValid),d=l.some(b=>b.isTouched),m=l.some(b=>b.isBlurred),g=l.every(b=>b.isDefaultValue),M=d&&u.errorMap?.onMount,v=l.some(b=>b.isDirty),p=!v,y=!!(u.errorMap?.onMount||l.some(b=>b?.errorMap?.onMount)),V=!!h;let S=a?.errors??[];(!c||u.errorMap!==c.errorMap)&&(S=Object.values(u.errorMap).reduce((b,$)=>$===void 0?b:$&&vt($)?(b.push($.form),b):(b.push($),b),[]));const D=S.length===0,_=f&&D,w=this.options.canSubmitWhenInvalid??!1,k=u.submissionAttempts===0&&!d&&!y||!V&&!u.isSubmitting&&_||w;let R=u.errorMap;if(M&&(S=S.filter(b=>b!==u.errorMap.onMount),R=Object.assign(R,{onMount:void 0})),a&&c&&a.errorMap===R&&a.fieldMeta===this.fieldMetaDerived.state&&a.errors===S&&a.isFieldsValidating===h&&a.isFieldsValid===f&&a.isFormValid===D&&a.isValid===_&&a.canSubmit===k&&a.isTouched===d&&a.isBlurred===m&&a.isPristine===p&&a.isDefaultValue===g&&a.isDirty===v&&O(c,u))return a;let ot={...u,errorMap:R,fieldMeta:this.fieldMetaDerived.state,errors:S,isFieldsValidating:h,isFieldsValid:f,isFormValid:D,isValid:_,canSubmit:k,isTouched:d,isBlurred:m,isPristine:p,isDefaultValue:g,isDirty:v};const lt=this.options.transform?.deps??[];if(lt.length!==this.prevTransformArray.length||lt.some((b,$)=>b!==this.prevTransformArray[$])){const b=Object.assign({},this,{state:ot});this.options.transform?.fn(b),ot=b.state,this.prevTransformArray=lt}return ot}}),this.handleSubmit=this.handleSubmit.bind(this),this.update(s||{});const r=qt(t=>A.emit("form-state",{id:this._formId,state:t}),{wait:300});this.store.subscribe(()=>{r(this.store.state)}),A.on("request-form-state",t=>{t.payload.id===this._formId&&A.emit("form-api",{id:this._formId,state:this.store.state,options:this.options})}),A.on("request-form-reset",t=>{t.payload.id===this._formId&&this.reset()}),A.on("request-form-force-submit",t=>{t.payload.id===this._formId&&(this._devtoolsSubmissionOverride=!0,this.handleSubmit(),this._devtoolsSubmissionOverride=!1)})}get state(){return this.store.state}get formId(){return this._formId}runValidator(s){return _t(s.validate)?U[s.type](s.value,s.validate):s.validate(s.value)}handleSubmit(s){return this._handleSubmit(s)}}function tt(e){if(e){if(vt(e)){const s=tt(e.form).formError,r=e.fields;return{formError:s,fieldErrors:r}}return{formError:e}}return{formError:void 0}}function N(e){switch(e){case"submit":return"onSubmit";case"blur":return"onBlur";case"mount":return"onMount";case"server":return"onServer";case"dynamic":return"onDynamic";case"change":default:return"onChange"}}class Ft{constructor(s){this.options={},this.mount=()=>{const r=this.store.mount();this.options.defaultValue!==void 0&&!this.getMeta().isTouched&&this.form.setFieldValue(this.name,this.options.defaultValue,{dontUpdateMeta:!0});const t=this.getInfo();t.instance=this,this.update(this.options);const{onMount:i}=this.options.validators||{};if(i){const n=this.runValidator({validate:i,value:{value:this.state.value,fieldApi:this,validationSource:"field"},type:"validate"});n&&this.setMeta(a=>({...a,errorMap:{...a?.errorMap,onMount:n},errorSourceMap:{...a?.errorSourceMap,onMount:"field"}}))}return this.options.listeners?.onMount?.({value:this.state.value,fieldApi:this}),r},this.update=r=>{if(this.options=r,this.name=r.name,!this.state.meta.isTouched&&this.options.defaultValue!==void 0){const t=this.form.getFieldValue(this.name);O(t,r.defaultValue)||this.form.setFieldValue(this.name,r.defaultValue,{dontUpdateMeta:!0,dontValidate:!0,dontRunListeners:!0})}this.form.getFieldMeta(this.name)||this.form.setFieldMeta(this.name,this.state.meta)},this.getValue=()=>this.form.getFieldValue(this.name),this.setValue=(r,t)=>{this.form.setFieldValue(this.name,r,F(t,{dontRunListeners:!0,dontValidate:!0})),t?.dontRunListeners||this.triggerOnChangeListener(),t?.dontValidate||this.validate("change")},this.getMeta=()=>this.store.state.meta,this.setMeta=r=>this.form.setFieldMeta(this.name,r),this.getInfo=()=>this.form.getFieldInfo(this.name),this.pushValue=(r,t)=>{this.form.pushFieldValue(this.name,r,F(t,{dontRunListeners:!0}
1)),t?.dontRunListeners||this.triggerOnChangeListener()},this.insertValue=(r,t,i)=>{this.form.insertFieldValue(this.name,r,t,F(i,{dontRunListeners:!0})),i?.dontRunListeners||this.triggerOnChangeListener()},this.replaceValue=(r,t,i)=>{this.form.replaceFieldValue(this.name,r,t,F(i,{dontRunListeners:!0})),i?.dontRunListeners||this.triggerOnChangeListener()},this.removeValue=(r,t)=>{this.form.removeFieldValue(this.name,r,F(t,{dontRunListeners:!0})),t?.dontRunListeners||this.triggerOnChangeListener()},this.swapValues=(r,t,i)=>{this.form.swapFieldValues(this.name,r,t,F(i,{dontRunListeners:!0})),i?.dontRunListeners||this.triggerOnChangeListener()},this.moveValue=(r,t,i)=>{this.form.moveFieldValues(this.name,r,t,F(i,{dontRunListeners:!0})),i?.dontRunListeners||this.triggerOnChangeListener()},this.clearValues=r=>{this.form.clearFieldValues(this.name,F(r,{dontRunListeners:!0})),r?.dontRunListeners||this.triggerOnChangeListener()},this.getLinkedFields=r=>{const t=Object.values(this.form.fieldInfo),i=[];for(const n of t){if(!n.instance)continue;const{onChangeListenTo:a,onBlurListenTo:c}=n.instance.options.validators||{};r==="change"&&a?.includes(this.name)&&i.push(n.instance),r==="blur"&&c?.includes(this.name)&&i.push(n.instance)}return i},this.validateSync=(r,t)=>{const i=ft(r,{...this.options,form:this.form,validationLogic:this.form.options.validationLogic||B}),a=this.getLinkedFields(r).reduce((o,l)=>{const h=ft(r,{...l.options,form:l.form,validationLogic:l.form.options.validationLogic||B});return h.forEach(f=>{f.field=l}),o.concat(h)},[]);let c=!1;I(()=>{const o=(l,h)=>{const f=J(h.cause),d=h.validate?Et(l.runValidator({validate:h.validate,value:{value:l.store.state.value,validationSource:"field",fieldApi:l},type:"validate"})):void 0,m=t[f],{newErrorValue:g,newSource:M}=yt({formLevelError:m,fieldLevelError:d});l.state.meta.errorMap?.[f]!==g&&l.setMeta(v=>({...v,errorMap:{...v.errorMap,[f]:g},errorSourceMap:{...v.errorSourceMap,[f]:M}})),g&&(c=!0)};for(const l of i)o(this,l);for(const l of a)l.validate&&o(l.field,l)});const u=J("submit");return this.state.meta.errorMap?.[u]&&r!=="submit"&&!c&&this.setMeta(o=>({...o,errorMap:{...o.errorMap,[u]:void 0},errorSourceMap:{...o.errorSourceMap,[u]:void 0}})),{hasErrored:c}},this.validateAsync=async(r,t)=>{const i=mt(r,{...this.options,form:this.form,validationLogic:this.form.options.validationLogic||B}),n=await t,a=this.getLinkedFields(r),c=a.reduce((f,d)=>{const m=mt(r,{...d.options,form:d.form,validationLogic:d.form.options.validationLogic||B});return m.forEach(g=>{g.field=d}),f.concat(m)},[]);this.state.meta.isValidating||this.setMeta(f=>({...f,isValidating:!0}));for(const f of a)f.setMeta(d=>({...d,isValidating:!0}));const u=[],o=[],l=(f,d,m)=>{const g=J(d.cause);f.getInfo().validationMetaMap[g]?.lastAbortController.abort();const v=new AbortController;this.getInfo().validationMetaMap[g]={lastAbortController:v},m.push(new Promise(async p=>{let y;try{y=await new Promise((w,k)=>{this.timeoutIds.validations[d.cause]&&clearTimeout(this.timeoutIds.validations[d.cause]),this.timeoutIds.validations[d.cause]=setTimeout(async()=>{if(v.signal.aborted)return w(void 0);try{w(await this.runValidator({validate:d.validate,value:{value:f.store.state.value,fieldApi:f,signal:v.signal,validationSource:"field"},type:"validateAsync"}))}catch(R){k(R)}},d.debounceMs)})}catch(w){y=w}if(v.signal.aborted)return p(void 0);const V=Et(y),S=n[this.name]?.[g],{newErrorValue:D,newSource:_}=yt({formLevelError:S,fieldLevelError:V});f.setMeta(w=>({...w,errorMap:{...w?.errorMap,[g]:D},errorSourceMap:{...w.errorSourceMap,[g]:_}})),p(D)}))};for(const f of i)f.validate&&l(this,f,u);for(const f of c)f.validate&&l(f.field,f,o);let h=[];(u.length||o.length)&&(h=await Promise.all(u),await Promise.all(o)),this.setMeta(f=>({...f,isValidating:!1}));for(const f of a)f.setMeta(d=>({...d,isValidating:!1}));return h.filter(Boolean)},this.validate=(r,t)=>{if(!this.state.meta.isTouched)return[];const{fieldsErrorMap:i}=t?.skipFormValidation?{fieldsErrorMap:{}}:this.form.validateSync(r),{hasErrored:n}=this.validateSync(r,i[this.name]??{});if(n&&!this.options.asyncAlways)return this.getInfo().validationMetaMap[J(r)]?.lastAbortController.abort(),this.state.meta.errors;const a=t?.skipFormValidation?Promise.resolve({}):this.form.validateAsync(r);return this.validateAsync(r,a)},this.handleChange=r=>{this.setValue(r)},this.handleBlur=()=>{this.state.meta.isTouched||this.setMeta(t=>({...t,isTouched:!0})),this.state.meta.isBlurred||this.setMeta(t=>({...t,isBlurred:!0}
1)),this.validate("blur"),this.triggerOnBlurListener()},this.setErrorMap=r=>{this.setMeta(t=>({...t,errorMap:{...t.errorMap,...r}}))},this.parseValueWithSchema=r=>U.validate({value:this.state.value,validationSource:"field"},r),this.parseValueWithSchemaAsync=r=>U.validateAsync({value:this.state.value,validationSource:"field"},r),this.triggerOnChangeListener=()=>{const r=this.form.options.listeners?.onChangeDebounceMs;r&&r>0?(this.timeoutIds.formListeners.change&&clearTimeout(this.timeoutIds.formListeners.change),this.timeoutIds.formListeners.change=setTimeout(()=>{this.form.options.listeners?.onChange?.({formApi:this.form,fieldApi:this})},r)):this.form.options.listeners?.onChange?.({formApi:this.form,fieldApi:this});const t=this.options.listeners?.onChangeDebounceMs;t&&t>0?(this.timeoutIds.listeners.change&&clearTimeout(this.timeoutIds.listeners.change),this.timeoutIds.listeners.change=setTimeout(()=>{this.options.listeners?.onChange?.({value:this.state.value,fieldApi:this})},t)):this.options.listeners?.onChange?.({value:this.state.value,fieldApi:this})},this.form=s.form,this.name=s.name,this.options=s,this.timeoutIds={validations:{},listeners:{},formListeners:{}},this.store=new T({deps:[this.form.store],fn:()=>{const r=this.form.getFieldMeta(this.name)??{...it,...s.defaultMeta};let t=this.form.getFieldValue(this.name);return!r.isTouched&&t===void 0&&this.options.defaultValue!==void 0&&!O(t,this.options.defaultValue)&&(t=this.options.defaultValue),{value:t,meta:r}}})}get state(){return this.store.state}runValidator(s){return _t(s.validate)?U[s.type](s.value,s.validate):s.validate(s.value)}triggerOnBlurListener(){const s=this.form.options.listeners?.onBlurDebounceMs;s&&s>0?(this.timeoutIds.formListeners.blur&&clearTimeout(this.timeoutIds.formListeners.blur),this.timeoutIds.formListeners.blur=setTimeout(()=>{this.form.options.listeners?.onBlur?.({formApi:this.form,fieldApi:this})},s)):this.form.options.listeners?.onBlur?.({formApi:this.form,fieldApi:this});const r=this.options.listeners?.onBlurDebounceMs;r&&r>0?(this.timeoutIds.listeners.blur&&clearTimeout(this.timeoutIds.listeners.blur),this.timeoutIds.listeners.blur=setTimeout(()=>{this.options.listeners?.onBlur?.({value:this.state.value,fieldApi:this})},r)):this.options.listeners?.onBlur?.({value:this.state.value,fieldApi:this})}}function Et(e){if(e)return e}function J(e){switch(e){case"submit":return"onSubmit";case"blur":return"onBlur";case"mount":return"onMount";case"server":return"onServer";case"dynamic":return"onDynamic";case"change":default:return"onChange"}}var kt={exports:{}},Ot={},Ct={exports:{}},$t={};/** 2 * @license React 3 * use-sync-external-store-shim.production.js 4 * 5 * Copyright (c) Meta Platforms, Inc. and affiliates. 6 * 7 * This source code is licensed under the MIT license found in the 8 * LICENSE file in the root directory of this source tree. 9 */var W=E;function ie(e,s){return e===s&&(e!==0||1/e===1/s)||e!==e&&s!==s}var re=typeof Object.is=="function"?Object.is:ie,ne=W.useState,ae=W.useEffect,oe=W.useLayoutEffect,le=W.useDebugValue;function ue(e,s){var r=s(),t=ne({inst:{value:r,getSnapshot:s}}),i=t[0].inst,n=t[1];return oe(function(){i.value=r,i.getSnapshot=s,dt(i)&&n({inst:i})},[e,r,s]),ae(function(){return dt(i)&&n({inst:i}),e(function(){dt(i)&&n({inst:i})})},[e]),le(r),r}function dt(e){var s=e.getSnapshot;e=e.value;try{var r=s();return!re(e,r)}catch{return!0}}function ce(e,s){return s()}var de=typeof window>"u"||typeof window.document>"u"||typeof window.document.createElement>"u"?ce:ue;$t.useSyncExternalStore=W.useSyncExternalStore!==void 0?W.useSyncExternalStore:de;Ct.exports=$t;var he=Ct.exports;/** 10 * @license React 11 * use-sync-external-store-shim/with-selector.production.js 12 * 13 * Copyright (c) Meta Platforms, Inc. and affiliates. 14 * 15 * This source code is licensed under the MIT license found in the 16 * LICENSE file in the root directory of this source tree. 17 */var at=E,fe=he;function me(e,s){return e===s&&(e!==0||1/e===1/s)||e!==e&&s!==s}var ve=typeof Object.is=="function"?Object.is:me,ge=fe.useSyncExternalStore,pe=at.useRef,Me=at.useEffect,be=at.useMemo,ye=at.useDebugValue;Ot.useSyncExternalStoreWithSelector=function(e,s,r,t,i){var n=pe(null);if(n.current===null){var a={hasValue:!1,value:null};n.current=a}else a=n.current;n=be(function(){function u(d){if(!o){if(o=!0,l=d,d=t(d),i!==void 0&&a.hasValue){var m=a.value;if(i(m,d))return h=m}return h=d}if(m=h,ve(l,d))return m;var g=t(d);return i!==void 0&&i(m,g)?(l=d,m):(l=d,h=g)}var o=!1,l,h,f=r===void 0?null:r;return[function(){return u(s())},f===null?void 0:function(){return u(f())}]},[s,r,t,i]);var c=ge(e,n[0],n[1]);return Me(function(){a.hasValue=!0,a.value=c},[c]),ye(c),c};kt.exports=Ot;var Se=kt.exports;function L(e,s=t=>t,r={}){const t=r.equal??Ve;return Se.useSyncExternalStoreWithSelector(e.subscribe,()=>e.state,()=>e.state,s,t)}function Ve(e,s){if(Object.is(e,s))return!0;
17if(typeof e!="object"||e===null||typeof s!="object"||s===null)return!1;if(e instanceof Map&&s instanceof Map){if(e.size!==s.size)return!1;for(const[t,i]of e)if(!s.has(t)||!Object.is(i,s.get(t)))return!1;return!0}if(e instanceof Set&&s instanceof Set){if(e.size!==s.size)return!1;for(const t of e)if(!s.has(t))return!1;return!0}if(e instanceof Date&&s instanceof Date)return e.getTime()===s.getTime();const r=wt(e);if(r.length!==wt(s).length)return!1;for(let t=0;t<r.length;t++)if(!Object.prototype.hasOwnProperty.call(s,r[t])||!Object.is(e[r[t]],s[r[t]]))return!1;return!0}function wt(e){return Object.keys(e).concat(Object.getOwnPropertySymbols(e))}const rt=typeof window<"u"?E.useLayoutEffect:E.useEffect;function Fe(e){const[s,r]=E.useState(()=>({form:e.form,name:e.name})),[t,i]=E.useState(()=>new Ft({...e}));(s.form!==e.form||s.name!==e.name)&&(i(new Ft({...e})),r({form:e.form,name:e.name}));const n=L(t.store,d=>d.value),a=L(t.store,d=>d.meta.isTouched),c=L(t.store,d=>d.meta.isBlurred),u=L(t.store,d=>d.meta.isDirty),o=L(t.store,d=>d.meta.errorMap),l=L(t.store,d=>d.meta.errorSourceMap),h=L(t.store,d=>d.meta.isValidating),f=E.useMemo(()=>{const m={...t,get state(){return{value:n,get meta(){return{...t.state.meta,isTouched:a,isBlurred:c,isDirty:u,errorMap:o,errorSourceMap:l,isValidating:h}}}}};return m.Field=Pt,m},[t,n,a,c,u,o,l,h]);return rt(t.mount,[t]),rt(()=>{t.update(e)}),L(t.store,e.mode==="array"?d=>[d.meta,Object.keys(d.value??[]).length]:void 0),f}const Pt=({children:e,...s})=>{const r=Fe(s),t=E.useMemo(()=>nt(e,r),[e,r]);return C.jsx(C.Fragment,{children:t})};function Ee({form:e,selector:s,children:r}){const t=L(e.store,s);return C.jsx(C.Fragment,{children:nt(r,t)})}function _e(e){const s=E.useState(()=>Dt())[0],[r,t]=E.useState(e?.formId),[i,n]=E.useState(()=>new Vt({...e,formId:e?.formId??s}));if(r!==e?.formId){const c=e?.formId??s;n(new Vt({...e,formId:c})),t(c)}const a=E.useMemo(()=>{const c={...i,handleSubmit:(...u)=>{i._handleSubmit(...u)},get formId(){return i._formId},get state(){return i.store.state}};return c.Field=function(o){return C.jsx(Pt,{...o,form:i})},c.Subscribe=function(o){return C.jsx(Ee,{form:i,selector:o.selector,children:o.children})},c},[i]);return rt(i.mount,[]),rt(()=>{i.update(e)}),a}function we(e){const s=e.state.meta.errors[0];if(s)return typeof s=="string"?s:s.message??"Invalid input"}const Ae=E.forwardRef(({className:e="",field:s,label:r,theme:t="light",hideValidation:i=!1,id:n,...a},c)=>{const u=we(s),o=!!u&&!i,l=n??s.name;return C.jsx(Rt,{label:r,htmlFor:l,error:o?u:void 0,theme:t,className:e,children:C.jsx("input",{ref:c,id:l,name:s.name,value:s.state.value,onBlur:s.handleBlur,onChange:h=>s.handleChange(h.target.value),"aria-invalid":o?!0:void 0,className:`c-input ${o?"c-input--error":""}`,...a})})});Ae.displayName="Textbox";export{Ae as T,L as a,we as f,_e as u};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.