@membank/dashboard 0.4.1 → 0.5.1
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/dist/client/assets/{MagnifyingGlass.es-B8P_LfEH.js → MagnifyingGlass.es-CGxS0MwI.js} +1 -1
- package/dist/client/assets/{index-O2KJf81b.js → index-DZxM00o8.js} +3 -3
- package/dist/client/assets/index-GVEqDPxR.css +1 -0
- package/dist/client/assets/memories-ja38P73o.js +1 -0
- package/dist/client/assets/memories._id-DeaZiiQb.js +1 -0
- package/dist/client/assets/{memories.index-ByQeKvpK.js → memories.index-DUtHo-Be.js} +1 -1
- package/dist/client/assets/{native-select-DqP_P0PQ.js → native-select-BpuM7pgJ.js} +1 -1
- package/dist/client/index.html +2 -2
- package/dist/index.cjs +40 -16
- package/dist/index.mjs +40 -16
- package/package.json +3 -3
- package/dist/client/assets/index-CMSfmat6.css +0 -1
- package/dist/client/assets/memories-3VR4rZ5U.js +0 -1
- package/dist/client/assets/memories._id-D3XqSd0M.js +0 -1
|
@@ -1 +0,0 @@
|
|
|
1
|
-
var We=e=>{throw TypeError(e)};var ze=(e,t,i)=>t.has(e)||We("Cannot "+i);var S=(e,t,i)=>(ze(e,t,"read from private field"),i?i.call(e):t.get(e)),R=(e,t,i)=>t.has(e)?We("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,i),P=(e,t,i,r)=>(ze(e,t,"write to private field"),r?r.call(e,i):t.set(e,i),i);var Ke=(e,t,i,r)=>({set _(u){P(e,t,u,i)},get _(){return S(e,t,r)}});import{V as rt,W as ot,a as bt,r as V,X as W,j as g,b as Q,Y as pt,l as Ne,e as Z,x as yt,n as _e,J as Mt,o as St,Z as Ft,H as ue,_ as wt,M as xt,O as He,P as Pe,$ as Vt,Q as Et,a0 as At,a1 as qe,a2 as Ge,a3 as It,D as ve,C as se,a4 as Qe,S as lt,G as jt,F as Lt,a5 as Ct,a6 as Ye,a7 as kt,a8 as Tt}from"./index-O2KJf81b.js";import{v as Ot,k as Pt,q as Bt,w as Rt,d as ut,j as Dt,T as Je,m as dt,e as Nt,A as $,b as _t,x as $t,l as Ut,N as Xe,s as ke,I as Wt}from"./native-select-DqP_P0PQ.js";class zt{constructor(t){this.atom=rt(t)}setState(t){this.atom.set(t)}get state(){return this.atom.get()}get(){return this.state}subscribe(t){return this.atom.subscribe(ot(t))}}class Kt{constructor(t){this.atom=rt(t)}get state(){return this.atom.get()}get(){return this.state}subscribe(t){return this.atom.subscribe(ot(t))}}function we(e){return typeof e=="function"?new Kt(e):new zt(e)}function Ht(e,t){if(e===void 0)return{shouldBlockFn:()=>!0,withResolver:!1};if("shouldBlockFn"in e)return e;if(typeof e=="function")return{shouldBlockFn:async()=>await e(),enableBeforeUnload:!0,withResolver:!1};const i=!!(e.condition??!0),r=e.blockerFn;return{shouldBlockFn:async()=>i&&r!==void 0?await r():i,enableBeforeUnload:i,withResolver:r===void 0}}function qt(e,t){const{shouldBlockFn:i,enableBeforeUnload:r=!0,disabled:u=!1,withResolver:f=!1}=Ht(e),s=bt(),{history:n}=s,[c,d]=V.useState({status:"idle",current:void 0,next:void 0,action:void 0,proceed:void 0,reset:void 0});return V.useEffect(()=>{const l=async o=>{function h(b){const F=s.parseLocation(b),p=s.getMatchedRoutes(F.pathname);return p.foundRoute===void 0?{routeId:"__notFound__",fullPath:F.pathname,pathname:F.pathname,params:p.routeParams,search:s.options.parseSearch(b.search)}:{routeId:p.foundRoute.id,fullPath:p.foundRoute.fullPath,pathname:F.pathname,params:p.routeParams,search:s.options.parseSearch(b.search)}}const a=h(o.currentLocation),m=h(o.nextLocation);if(a.routeId==="__notFound__"&&m.routeId!=="__notFound__")return!1;const v=await i({action:o.action,current:a,next:m});if(!f)return v;if(!v)return!1;const M=await new Promise(b=>{d({status:"blocked",current:a,next:m,action:o.action,proceed:()=>b(!1),reset:()=>b(!0)})});return d({status:"idle",current:void 0,next:void 0,action:void 0,proceed:void 0,reset:void 0}),M};return u?void 0:n.block({blockerFn:l,enableBeforeUnload:r})},[i,r,u,f,n,s]),c}var Gt=class{constructor(e,t){this.fn=e,this.options=t,this.lastExecutionTime=0,this.isPending=!1,this.maybeExecute=(...i)=>{const r=Date.now()-this.lastExecutionTime;if(this.options.leading&&r>=this.options.wait)this.execute(...i);else if(this.lastArgs=i,!this.timeoutId&&this.options.trailing){const u=this.options.wait-r;this.isPending=!0,this.timeoutId=setTimeout(()=>{this.lastArgs!==void 0&&this.execute(...this.lastArgs)},u)}},this.execute=(...i)=>{var r,u;this.fn(...i),(u=(r=this.options).onExecute)==null||u.call(r,i,this),this.lastExecutionTime=Date.now(),this.clearTimeout(),this.lastArgs=void 0,this.isPending=!1},this.flush=()=>{this.isPending&&this.lastArgs&&this.execute(...this.lastArgs)},this.cancel=()=>{this.clearTimeout(),this.lastArgs=void 0,this.isPending=!1},this.clearTimeout=()=>{this.timeoutId&&(clearTimeout(this.timeoutId),this.timeoutId=void 0)},this.options.leading===void 0&&this.options.trailing===void 0&&(this.options.leading=!0,this.options.trailing=!0)}};function Qt(e,t){return new Gt(e,t).maybeExecute}var J,_,D,fe,H,te,q,re,me,Ae,X,oe,G,ge,le,Ie;class Yt{constructor({pluginId:t,debug:i=!1,enabled:r=!0,reconnectEveryMs:u=300}){R(this,J,!0);R(this,_);R(this,D);R(this,fe);R(this,H);R(this,te);R(this,q);R(this,re);R(this,me,0);R(this,Ae,5);R(this,X,!1);R(this,oe,!1);R(this,G,null);R(this,ge,()=>{this.debugLog("Connected to event bus"),P(this,te,!0),P(this,X,!1),this.debugLog("Emitting queued events",S(this,H)),S(this,H).forEach(t=>this.emitEventToBus(t)),P(this,H,[]),this.stopConnectLoop(),S(this,D).call(this).removeEventListener("tanstack-connect-success",S(this,ge))});R(this,le,()=>{if(S(this,me)<S(this,Ae)){Ke(this,me)._++,this.dispatchCustomEvent("tanstack-connect",{});return}S(this,D).call(this).removeEventListener("tanstack-connect",S(this,le)),P(this,oe,!0),this.debugLog("Max retries reached, giving up on connection"),this.stopConnectLoop()});R(this,Ie,()=>{S(this,X)||(P(this,X,!0),S(this,D).call(this).addEventListener("tanstack-connect-success",S(this,ge)),S(this,le).call(this))});P(this,_,t),P(this,J,r),P(this,D,this.getGlobalTarget),P(this,fe,i),this.debugLog(" Initializing event subscription for plugin",S(this,_)),P(this,H,[]),P(this,te,!1),P(this,oe,!1),P(this,q,null),P(this,re,u)}startConnectLoop(){S(this,q)!==null||S(this,te)||(this.debugLog(`Starting connect loop (every ${S(this,re)}ms)`),P(this,q,setInterval(S(this,le),S(this,re))))}stopConnectLoop(){P(this,X,!1),S(this,q)!==null&&(clearInterval(S(this,q)),P(this,q,null),P(this,H,[]),this.debugLog("Stopped connect loop"))}debugLog(...t){S(this,fe)&&console.log(`🌴 [tanstack-devtools:${S(this,_)}-plugin]`,...t)}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 t=typeof EventTarget<"u"?new EventTarget:void 0;return typeof t>"u"||typeof t.addEventListener>"u"?(this.debugLog("No event mechanism available, running in non-web environment"),{addEventListener:()=>{},removeEventListener:()=>{},dispatchEvent:()=>!1}):(this.debugLog("Using new EventTarget as fallback"),t)}getPluginId(){return S(this,_)}dispatchCustomEventShim(t,i){try{const r=new Event(t,{detail:i});S(this,D).call(this).dispatchEvent(r)}catch{this.debugLog("Failed to dispatch shim event")}}dispatchCustomEvent(t,i){try{S(this,D).call(this).dispatchEvent(new CustomEvent(t,{detail:i}))}catch{this.dispatchCustomEventShim(t,i)}}emitEventToBus(t){this.debugLog("Emitting event to client bus",t),this.dispatchCustomEvent("tanstack-dispatch-event",t)}createEventPayload(t,i){return{type:`${S(this,_)}:${t}`,payload:i,pluginId:S(this,_)}}emit(t,i){if(!S(this,J)){this.debugLog("Event bus client is disabled, not emitting event",t,i);return}if(S(this,G)&&(this.debugLog("Emitting event to internal event target",t,i),S(this,G).dispatchEvent(new CustomEvent(`${S(this,_)}:${t}`,{detail:this.createEventPayload(t,i)}))),S(this,oe)){this.debugLog("Previously failed to connect, not emitting to bus");return}if(!S(this,te)){this.debugLog("Bus not available, will be pushed as soon as connected"),S(this,H).push(this.createEventPayload(t,i)),typeof CustomEvent<"u"&&!S(this,X)&&(S(this,Ie).call(this),this.startConnectLoop());return}return this.emitEventToBus(this.createEventPayload(t,i))}on(t,i,r){const u=(r==null?void 0:r.withEventTarget)??!1,f=`${S(this,_)}:${t}`;if(u&&(S(this,G)||P(this,G,new EventTarget),S(this,G).addEventListener(f,n=>{i(n.detail)})),!S(this,J))return this.debugLog("Event bus client is disabled, not registering event",f),()=>{};const s=n=>{this.debugLog("Received event from bus",n.detail),i(n.detail)};return S(this,D).call(this).addEventListener(f,s),this.debugLog("Registered event to bus",f),()=>{var n;u&&((n=S(this,G))==null||n.removeEventListener(f,s)),S(this,D).call(this).removeEventListener(f,s)}}onAll(t){if(!S(this,J))return this.debugLog("Event bus client is disabled, not registering event"),()=>{};const i=r=>{const u=r.detail;t(u)};return S(this,D).call(this).addEventListener("tanstack-devtools-global",i),()=>S(this,D).call(this).removeEventListener("tanstack-devtools-global",i)}onAllPluginEvents(t){if(!S(this,J))return this.debugLog("Event bus client is disabled, not registering event"),()=>{};const i=r=>{const u=r.detail;S(this,_)&&u.pluginId!==S(this,_)||t(u)};return S(this,D).call(this).addEventListener("tanstack-devtools-global",i),()=>S(this,D).call(this).removeEventListener("tanstack-devtools-global",i)}}J=new WeakMap,_=new WeakMap,D=new WeakMap,fe=new WeakMap,H=new WeakMap,te=new WeakMap,q=new WeakMap,re=new WeakMap,me=new WeakMap,Ae=new WeakMap,X=new WeakMap,oe=new WeakMap,G=new WeakMap,ge=new WeakMap,le=new WeakMap,Ie=new WeakMap;class Jt extends Yt{constructor(){super({pluginId:"form-devtools",reconnectEveryMs:1e3})}}const U=new Jt;function je(e,t){return typeof e=="function"?e(t):e}function be(e,t){return $e(t).reduce((r,u)=>{if(r===null)return null;if(typeof r<"u")return r[u]},e)}function pe(e,t,i){const r=$e(t);function u(f){if(!r.length)return je(i,f);const s=r.shift();if(typeof s=="string"||typeof s=="number"&&!Array.isArray(f))return typeof f=="object"?(f===null&&(f={}),{...f,[s]:u(f[s])}):{[s]:u()};if(Array.isArray(f)&&typeof s=="number"){const n=f.slice(0,s);return[...n.length?n:new Array(s),u(f[s]),...f.slice(s+1)]}return[...new Array(s),u()]}return u(e)}function Xt(e,t){const i=$e(t);function r(u){if(!u)return;if(i.length===1){const s=i[0];if(Array.isArray(u)&&typeof s=="number")return u.filter((d,l)=>l!==s);const{[s]:n,...c}=u;return c}const f=i.shift();if((typeof f=="string"||typeof f=="number"&&!Array.isArray(u))&&typeof u=="object")return{...u,[f]:r(u[f])};if(typeof f=="number"&&Array.isArray(u)){if(f>=u.length)return u;const s=u.slice(0,f);return[...s.length?s:new Array(f),r(u[f]),...u.slice(f+1)]}throw new Error("It seems we have created an infinite loop in deleteBy. ")}return r(e)}const Zt=/^(\d+)$/gm,es=/\.(\d+)(?=\.)/gm,ts=/^(\d+)\./gm,ss=/\.(\d+$)/gm,is=/\.{2,}/gm,Be="__int__",ye=`${Be}$1`;function $e(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(Zt,ye).replace(es,`.${ye}.`).replace(ts,`${ye}.`).replace(ss,`.${ye}`).replace(is,".").split(".").map(t=>{if(t.startsWith(Be)){const i=t.substring(Be.length),r=parseInt(i,10);return String(r)===i?r:i}return t})}function ns(e){return!(Array.isArray(e)&&e.length===0)}function Re(e,t){const i=r=>r.validators.filter(Boolean).map(u=>({cause:u.cause,validate:u.fn}));return t.validationLogic({form:t.form,validators:t.validators,event:{type:e,fieldName:t.fieldName,async:!1},runValidation:i})}function De(e,t){const{asyncDebounceMs:i}=t,{onBlurAsyncDebounceMs:r,onChangeAsyncDebounceMs:u,onDynamicAsyncDebounceMs:f}=t.validators||{},s=i??0,n=c=>c.validators.filter(Boolean).map(d=>{const l=(d==null?void 0:d.cause)||e;let o=s;switch(l){case"change":o=u??s;break;case"blur":o=r??s;break;case"dynamic":o=f??s;break;case"submit":o=0;break}return e==="submit"&&(o=0),{cause:l,validate:d.fn,debounceMs:o}});return t.validationLogic({form:t.form,validators:t.validators,event:{type:e,fieldName:t.fieldName,async:!0},runValidation:n})}const xe=e=>!!e&&typeof e=="object"&&"fields"in e;function Y(e,t){if(Object.is(e,t))return!0;if(typeof e!="object"||e===null||typeof t!="object"||t===null)return!1;if(e instanceof Date&&t instanceof Date)return e.getTime()===t.getTime();if(e instanceof Map&&t instanceof Map){if(e.size!==t.size)return!1;for(const[u,f]of e)if(!t.has(u)||!Object.is(f,t.get(u)))return!1;return!0}if(e instanceof Set&&t instanceof Set){if(e.size!==t.size)return!1;for(const u of e)if(!t.has(u))return!1;return!0}const i=Object.keys(e),r=Object.keys(t);if(i.length!==r.length)return!1;for(const u of i)if(!r.includes(u)||!Y(e[u],t[u]))return!1;return!0}const Ze=({newFormValidatorError:e,isPreviousErrorFromFormValidator:t,previousErrorValue:i})=>e?{newErrorValue:e,newSource:"form"}:t?{newErrorValue:void 0,newSource:void 0}:i?{newErrorValue:i,newSource:"field"}:{newErrorValue:void 0,newSource:void 0},et=({formLevelError:e,fieldLevelError:t})=>t?{newErrorValue:t,newSource:"field"}:e?{newErrorValue:e,newSource:"form"}:{newErrorValue:void 0,newSource:void 0};function N(e,t){return e==null?t:{...e,...t}}let ee=256;const Ve=[];let Me;for(;ee--;)Ve[ee]=(ee+256).toString(16).substring(1);function ct(){let e=0,t,i="";if(!Me||ee+16>256){for(Me=new Array(256),e=256;e--;)Me[e]=256*Math.random()|0;e=0,ee=0}for(;e<16;e++)t=Me[ee+e],e===6?i+=Ve[t&15|64]:e===8?i+=Ve[t&63|128]:i+=Ve[t],e&1&&e>1&&e<11&&(i+="-");return ee++,i}const as=Qt(e=>U.emit("form-state",{id:e.formId,state:e.store.state}),{wait:300});function ce(e){if(e===null||typeof e!="object")return e;if(e instanceof Date)return new Date(e.getTime());if(Array.isArray(e)){const i=[];for(let r=0;r<e.length;r++)i[r]=ce(e[r]);return i}if(e instanceof Map){const i=new Map;return e.forEach((r,u)=>{i.set(u,ce(r))}),i}if(e instanceof Set){const i=new Set;return e.forEach(r=>{i.add(ce(r))}),i}const t={};for(const i in e)Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=ce(e[i]));return t}const ie=e=>{if(!e.validators)return e.runValidation({validators:[],form:e.form});const t=e.event.async,i=t?void 0:{fn:e.validators.onMount,cause:"mount"},r={fn:t?e.validators.onChangeAsync:e.validators.onChange,cause:"change"},u={fn:t?e.validators.onBlurAsync:e.validators.onBlur,cause:"blur"},f={fn:t?e.validators.onSubmitAsync:e.validators.onSubmit,cause:"submit"},s=t?void 0:{fn:()=>{},cause:"server"};switch(e.event.type){case"mount":return e.runValidation({validators:[i],form:e.form});case"submit":return e.runValidation({validators:[r,u,f,s],form:e.form});case"server":return e.runValidation({validators:[],form:e.form});case"blur":return e.runValidation({validators:[u,s],form:e.form});case"change":return e.runValidation({validators:[r,s],form:e.form});default:throw new Error(`Unknown validation event type: ${e.event.type}`)}};function rs(e,t){const i=new Map;for(const r of e){const u=r.path??[];let f=t,s="";for(let n=0;n<u.length;n++){const c=u[n];if(c===void 0)continue;const d=typeof c=="object"?c.key:c,l=Number(d);Array.isArray(f)&&!Number.isNaN(l)?s+=`[${l}]`:s+=(n>0?".":"")+String(d),typeof f=="object"&&f!==null?f=f[d]:f=void 0}i.set(s,(i.get(s)??[]).concat(r))}return Object.fromEntries(i)}const tt=(e,t)=>{const i=rs(e,t);return{form:i,fields:i}},ae={validate({value:e,validationSource:t},i){const r=i["~standard"].validate(e);if(r instanceof Promise)throw new Error("async function passed to sync validator");if(r.issues)return t==="field"?r.issues:tt(r.issues,e)},async validateAsync({value:e,validationSource:t},i){const r=await i["~standard"].validate(e);if(r.issues)return t==="field"?r.issues:tt(r.issues,e)}},ht=e=>!!e&&"~standard"in e,z={isValidating:!1,isTouched:!1,isBlurred:!1,isDirty:!1,isPristine:!0,isValid:!0,isDefaultValue:!0,errors:[],errorMap:{},errorSourceMap:{}};function Se(e){function t(l,o,h){const a=s(l,o,"move",h),m=Math.min(o,h),v=Math.max(o,h);for(let b=m;b<=v;b++)a.push(f(l,b));const M=Object.keys(e.fieldInfo).reduce((b,F)=>(F.startsWith(f(l,o))&&b.set(F,e.getFieldMeta(F)),b),new Map);c(a,o<h?"up":"down"),Object.keys(e.fieldInfo).filter(b=>b.startsWith(f(l,h))).forEach(b=>{const F=b.replace(f(l,h),f(l,o)),p=M.get(F);p&&e.setFieldMeta(b,p)})}function i(l,o){const h=s(l,o,"remove");c(h,"up")}function r(l,o,h){s(l,o,"swap",h).forEach(m=>{if(!m.toString().startsWith(f(l,o)))return;const v=m.toString().replace(f(l,o),f(l,h)),[M,b]=[e.getFieldMeta(m),e.getFieldMeta(v)];M&&e.setFieldMeta(v,M),b&&e.setFieldMeta(m,b)})}function u(l,o){const h=s(l,o,"insert");c(h,"down"),h.forEach(a=>{a.toString().startsWith(f(l,o))&&e.setFieldMeta(a,d())})}function f(l,o){return`${l}[${o}]`}function s(l,o,h,a){const m=[f(l,o)];switch(h){case"swap":m.push(f(l,a));break;case"move":{const[v,M]=[Math.min(o,a),Math.max(o,a)];for(let b=v;b<=M;b++)m.push(f(l,b));break}default:{const v=e.getFieldValue(l),M=Array.isArray(v)?v.length:0;for(let b=o+1;b<M;b++)m.push(f(l,b));break}}return Object.keys(e.fieldInfo).filter(v=>m.some(M=>v.startsWith(M)))}function n(l,o){return l.replace(/\[(\d+)\]/,(h,a)=>{const m=parseInt(a,10);return`[${o==="up"?m+1:Math.max(0,m-1)}]`})}function c(l,o){(o==="up"?l:[...l].reverse()).forEach(a=>{const m=n(a.toString(),o),v=e.getFieldMeta(m);v?e.setFieldMeta(a,v):e.setFieldMeta(a,d())})}const d=()=>z;return{handleArrayMove:t,handleArrayRemove:i,handleArraySwap:r,handleArrayInsert:u}}function Te(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 st{constructor(t){var f;this.options={},this.fieldInfo={},this.mount=()=>{var h,a;const s=this.store.subscribe(()=>{as(this)}),n=U.on("request-form-state",m=>{m.payload.id===this._formId&&U.emit("form-api",{id:this._formId,state:this.store.state,options:this.options})}),c=U.on("request-form-reset",m=>{m.payload.id===this._formId&&this.reset()}),d=U.on("request-form-force-submit",m=>{m.payload.id===this._formId&&(this._devtoolsSubmissionOverride=!0,this.handleSubmit(),this._devtoolsSubmissionOverride=!1)}),l=()=>{d(),c(),n(),s.unsubscribe(),U.emit("form-unmounted",{id:this._formId})};(a=(h=this.options.listeners)==null?void 0:h.onMount)==null||a.call(h,{formApi:this});const{onMount:o}=this.options.validators||{};return U.emit("form-api",{id:this._formId,state:this.store.state,options:this.options}),o&&this.validateSync("mount"),l},this.update=s=>{if(!s)return;const n=this.options;this.options=s;const c=s.defaultValues&&!Y(s.defaultValues,n.defaultValues)&&!this.state.isTouched,d=!Y(s.defaultState,n.defaultState)&&!this.state.isTouched;!c&&!d||(W(()=>{this.baseStore.setState(()=>Te(Object.assign({},this.state,d?s.defaultState:{},c?{values:s.defaultValues}:{})))}),U.emit("form-api",{id:this._formId,state:this.store.state,options:this.options}))},this.reset=(s,n)=>{const{fieldMeta:c}=this.state,d=this.resetFieldMeta(c);s&&!(n!=null&&n.keepDefaultValues)&&(this.options={...this.options,defaultValues:s}),this.baseStore.setState(()=>{var l;return Te({...this.options.defaultState,values:s??this.options.defaultValues??((l=this.options.defaultState)==null?void 0:l.values),fieldMetaBase:d})})},this.validateAllFields=async s=>{const n=[];return W(()=>{Object.values(this.fieldInfo).forEach(d=>{if(!d.instance)return;const l=d.instance;n.push(Promise.resolve().then(()=>l.validate(s,{skipFormValidation:!0}))),d.instance.state.meta.isTouched||d.instance.setMeta(o=>({...o,isTouched:!0}))})}),(await Promise.all(n)).flat()},this.validateArrayFieldsStartingFrom=async(s,n,c)=>{const d=this.getFieldValue(s),l=Array.isArray(d)?Math.max(d.length-1,0):null,o=[`${s}[${n}]`];for(let v=n+1;v<=(l??0);v++)o.push(`${s}[${v}]`);const h=Object.keys(this.fieldInfo).filter(v=>o.some(M=>v.startsWith(M))),a=[];return W(()=>{h.forEach(v=>{a.push(Promise.resolve().then(()=>this.validateField(v,c)))})}),(await Promise.all(a)).flat()},this.validateField=(s,n)=>{var d,l;const c=(d=this.fieldInfo[s])==null?void 0:d.instance;if(!c){const{hasErrored:o}=this.validateSync(n);return o&&!this.options.asyncAlways?((l=this.getFieldMeta(s))==null?void 0:l.errors)??[]:this.validateAsync(n).then(()=>{var h;return((h=this.getFieldMeta(s))==null?void 0:h.errors)??[]})}return c.state.meta.isTouched||c.setMeta(o=>({...o,isTouched:!0})),c.validate(n)},this.validateSync=s=>{const n=Re(s,{...this.options,form:this,validationLogic:this.options.validationLogic||ie});let c=!1;const d={};return W(()=>{var h,a,m;for(const v of n){if(!v.validate)continue;const M=this.runValidator({validate:v.validate,value:{value:this.state.values,formApi:this,validationSource:"form"},type:"validate"}),{formError:b,fieldErrors:F}=Ee(M),p=de(v.cause),E=new Set([...Object.keys(this.state.fieldMeta),...Object.keys(F||{})]);for(const w of E){if(this.baseStore.state.fieldMetaBase[w]===void 0&&!(F!=null&&F[w]))continue;const k=this.getFieldMeta(w)??z,{errorMap:A,errorSourceMap:O}=k,C=F==null?void 0:F[w],{newErrorValue:B,newSource:L}=Ze({newFormValidatorError:C,isPreviousErrorFromFormValidator:(O==null?void 0:O[p])==="form",previousErrorValue:A==null?void 0:A[p]});L==="form"&&(d[w]={...d[w],[p]:C}),(A==null?void 0:A[p])!==B&&this.setFieldMeta(w,(y=z)=>({...y,errorMap:{...y.errorMap,[p]:B},errorSourceMap:{...y.errorSourceMap,[p]:L}}))}((h=this.state.errorMap)==null?void 0:h[p])!==b&&this.baseStore.setState(w=>({...w,errorMap:{...w.errorMap,[p]:b}})),(b||F)&&(c=!0)}const l=de("submit");(a=this.state.errorMap)!=null&&a[l]&&s!=="submit"&&!c&&this.baseStore.setState(v=>({...v,errorMap:{...v.errorMap,[l]:void 0}}));const o=de("server");(m=this.state.errorMap)!=null&&m[o]&&s!=="server"&&!c&&this.baseStore.setState(v=>({...v,errorMap:{...v.errorMap,[o]:void 0}}))}),{hasErrored:c,fieldsErrorMap:d}},this.validateAsync=async s=>{const n=De(s,{...this.options,form:this,validationLogic:this.options.validationLogic||ie});this.state.isFormValidating||this.baseStore.setState(h=>({...h,isFormValidating:!0}));const c=[];let d;for(const h of n){if(!h.validate)continue;const a=de(h.cause),m=this.state.validationMetaMap[a];m==null||m.lastAbortController.abort();const v=new AbortController;this.state.validationMetaMap[a]={lastAbortController:v},c.push(new Promise(async M=>{let b;try{b=await new Promise((w,k)=>{setTimeout(async()=>{if(v.signal.aborted)return w(void 0);try{w(await this.runValidator({validate:h.validate,value:{value:this.state.values,formApi:this,validationSource:"form",signal:v.signal},type:"validateAsync"}))}catch(A){k(A)}},h.debounceMs)})}catch(w){b=w}const{formError:F,fieldErrors:p}=Ee(b);p&&(d=d?{...d,...p}:p);const E=de(h.cause);for(const w of Object.keys(this.state.fieldMeta)){if(this.baseStore.state.fieldMetaBase[w]===void 0)continue;const k=this.getFieldMeta(w);if(!k)continue;const{errorMap:A,errorSourceMap:O}=k,C=d==null?void 0:d[w],{newErrorValue:B,newSource:L}=Ze({newFormValidatorError:C,isPreviousErrorFromFormValidator:(O==null?void 0:O[E])==="form",previousErrorValue:A==null?void 0:A[E]});(A==null?void 0:A[E])!==B&&this.setFieldMeta(w,y=>({...y,errorMap:{...y.errorMap,[E]:B},errorSourceMap:{...y.errorSourceMap,[E]:L}}))}this.baseStore.setState(w=>({...w,errorMap:{...w.errorMap,[E]:F}})),M(d?{fieldErrors:d,errorMapKey:E}:void 0)}))}let l=[];const o={};if(c.length){l=await Promise.all(c);for(const h of l)if(h!=null&&h.fieldErrors){const{errorMapKey:a}=h;for(const[m,v]of Object.entries(h.fieldErrors)){const b={...o[m]||{},[a]:v};o[m]=b}}}return this.baseStore.setState(h=>({...h,isFormValidating:!1})),o},this.validate=s=>{const{hasErrored:n,fieldsErrorMap:c}=this.validateSync(s);return n&&!this.options.asyncAlways?c:this.validateAsync(s)},this._handleSubmit=async s=>{var d,l,o,h,a,m,v,M,b,F;this.baseStore.setState(p=>({...p,isSubmitted:!1,submissionAttempts:p.submissionAttempts+1,isSubmitSuccessful:!1})),W(()=>{Object.values(this.fieldInfo).forEach(p=>{p.instance&&(p.instance.state.meta.isTouched||p.instance.setMeta(E=>({...E,isTouched:!0})))})});const n=s??this.options.onSubmitMeta;if(!this.state.canSubmit&&!this._devtoolsSubmissionOverride){(l=(d=this.options).onSubmitInvalid)==null||l.call(d,{value:this.state.values,formApi:this,meta:n});return}this.baseStore.setState(p=>({...p,isSubmitting:!0}));const c=()=>{this.baseStore.setState(p=>({...p,isSubmitting:!1}))};if(await this.validateAllFields("submit"),!this.state.isFieldsValid){c(),(h=(o=this.options).onSubmitInvalid)==null||h.call(o,{value:this.state.values,formApi:this,meta:n}),U.emit("form-submission",{id:this._formId,submissionAttempt:this.state.submissionAttempts,successful:!1,stage:"validateAllFields",errors:Object.values(this.state.fieldMeta).map(p=>p.errors).flat()});return}if(await this.validate("submit"),!this.state.isValid){c(),(m=(a=this.options).onSubmitInvalid)==null||m.call(a,{value:this.state.values,formApi:this,meta:n}),U.emit("form-submission",{id:this._formId,submissionAttempt:this.state.submissionAttempts,successful:!1,stage:"validate",errors:this.state.errors});return}W(()=>{Object.values(this.fieldInfo).forEach(p=>{var E,w,k;(k=(w=(E=p.instance)==null?void 0:E.options.listeners)==null?void 0:w.onSubmit)==null||k.call(w,{value:p.instance.state.value,fieldApi:p.instance})})}),(M=(v=this.options.listeners)==null?void 0:v.onSubmit)==null||M.call(v,{formApi:this,meta:n});try{await((F=(b=this.options).onSubmit)==null?void 0:F.call(b,{value:this.state.values,formApi:this,meta:n})),W(()=>{this.baseStore.setState(p=>({...p,isSubmitted:!0,isSubmitSuccessful:!0})),U.emit("form-submission",{id:this._formId,submissionAttempt:this.state.submissionAttempts,successful:!0}),c()})}catch(p){throw this.baseStore.setState(E=>({...E,isSubmitSuccessful:!1})),U.emit("form-submission",{id:this._formId,submissionAttempt:this.state.submissionAttempts,successful:!1,stage:"inflight",onError:p}),c(),p}},this.getFieldValue=s=>be(this.state.values,s),this.getFieldMeta=s=>this.state.fieldMeta[s],this.getFieldInfo=s=>{var n;return(n=this.fieldInfo)[s]||(n[s]={instance:null,validationMetaMap:{onChange:void 0,onBlur:void 0,onSubmit:void 0,onMount:void 0,onServer:void 0,onDynamic:void 0}})},this.setFieldMeta=(s,n)=>{this.baseStore.setState(c=>({...c,fieldMetaBase:{...c.fieldMetaBase,[s]:je(n,c.fieldMetaBase[s])}}))},this.resetFieldMeta=s=>Object.keys(s).reduce((n,c)=>{const d=c;return n[d]=z,n},{}),this.setFieldValue=(s,n,c)=>{var h;const d=(c==null?void 0:c.dontUpdateMeta)??!1,l=(c==null?void 0:c.dontRunListeners)??!1,o=(c==null?void 0:c.dontValidate)??!1;W(()=>{d||this.setFieldMeta(s,a=>({...a,isTouched:!0,isDirty:!0,errorMap:{...a==null?void 0:a.errorMap,onMount:void 0}})),this.baseStore.setState(a=>({...a,values:pe(a.values,s,n)}))}),l||(h=this.getFieldInfo(s).instance)==null||h.triggerOnChangeListener(),o||this.validateField(s,"change")},this.deleteField=s=>{const c=[...Object.keys(this.fieldInfo).filter(d=>{const l=s.toString();return d!==l&&d.startsWith(l)}),s];this.baseStore.setState(d=>{const l={...d};return c.forEach(o=>{l.values=Xt(l.values,o),delete this.fieldInfo[o],delete l.fieldMetaBase[o]}),l})},this.pushFieldValue=(s,n,c)=>{this.setFieldValue(s,d=>[...Array.isArray(d)?d:[],n],c)},this.insertFieldValue=async(s,n,c,d)=>{this.setFieldValue(s,o=>[...o.slice(0,n),c,...o.slice(n)],N(d,{dontValidate:!0}));const l=(d==null?void 0:d.dontValidate)??!1;l||await this.validateField(s,"change"),Se(this).handleArrayInsert(s,n),l||await this.validateArrayFieldsStartingFrom(s,n,"change")},this.replaceFieldValue=async(s,n,c,d)=>{this.setFieldValue(s,o=>o.map((h,a)=>a===n?c:h),N(d,{dontValidate:!0})),((d==null?void 0:d.dontValidate)??!1)||(await this.validateField(s,"change"),await this.validateArrayFieldsStartingFrom(s,n,"change"))},this.removeFieldValue=async(s,n,c)=>{const d=this.getFieldValue(s),l=Array.isArray(d)?Math.max(d.length-1,0):null;if(this.setFieldValue(s,h=>h.filter((a,m)=>m!==n),N(c,{dontValidate:!0})),Se(this).handleArrayRemove(s,n),l!==null){const h=`${s}[${l}]`;this.deleteField(h)}((c==null?void 0:c.dontValidate)??!1)||(await this.validateField(s,"change"),await this.validateArrayFieldsStartingFrom(s,n,"change"))},this.swapFieldValues=(s,n,c,d)=>{this.setFieldValue(s,o=>{const h=o[n],a=o[c];return pe(pe(o,`${n}`,a),`${c}`,h)},N(d,{dontValidate:!0})),Se(this).handleArraySwap(s,n,c),((d==null?void 0:d.dontValidate)??!1)||(this.validateField(s,"change"),this.validateField(`${s}[${n}]`,"change"),this.validateField(`${s}[${c}]`,"change"))},this.moveFieldValues=(s,n,c,d)=>{this.setFieldValue(s,o=>{const h=[...o];return h.splice(c,0,h.splice(n,1)[0]),h},N(d,{dontValidate:!0})),Se(this).handleArrayMove(s,n,c),((d==null?void 0:d.dontValidate)??!1)||(this.validateField(s,"change"),this.validateField(`${s}[${n}]`,"change"),this.validateField(`${s}[${c}]`,"change"))},this.clearFieldValues=(s,n)=>{const c=this.getFieldValue(s),d=Array.isArray(c)?Math.max(c.length-1,0):null;if(this.setFieldValue(s,[],N(n,{dontValidate:!0})),d!==null)for(let o=0;o<=d;o++){const h=`${s}[${o}]`;this.deleteField(h)}((n==null?void 0:n.dontValidate)??!1)||this.validateField(s,"change")},this.resetField=s=>{this.baseStore.setState(n=>({...n,fieldMetaBase:{...n.fieldMetaBase,[s]:z},values:this.options.defaultValues?pe(n.values,s,be(this.options.defaultValues,s)):n.values}))},this.setErrorMap=s=>{W(()=>{Object.entries(s).forEach(([n,c])=>{const d=n;if(xe(c)){const{formError:l,fieldErrors:o}=Ee(c);for(const h of Object.keys(this.fieldInfo))this.getFieldMeta(h)&&this.setFieldMeta(h,m=>({...m,errorMap:{...m.errorMap,[d]:o==null?void 0:o[h]},errorSourceMap:{...m.errorSourceMap,[d]:"form"}}));this.baseStore.setState(h=>({...h,errorMap:{...h.errorMap,[d]:l}}))}else this.baseStore.setState(l=>({...l,errorMap:{...l.errorMap,[d]:c}}))})})},this.getAllErrors=()=>({form:{errors:this.state.errors,errorMap:this.state.errorMap},fields:Object.entries(this.state.fieldMeta).reduce((s,[n,c])=>(Object.keys(c).length&&c.errors.length&&(s[n]={errors:c.errors,errorMap:c.errorMap}),s),{})}),this.parseValuesWithSchema=s=>ae.validate({value:this.state.values,validationSource:"form"},s),this.parseValuesWithSchemaAsync=s=>ae.validateAsync({value:this.state.values,validationSource:"form"},s),this.timeoutIds={validations:{},listeners:{},formListeners:{}},this._formId=(t==null?void 0:t.formId)??ct(),this._devtoolsSubmissionOverride=!1;let i=Te({...t==null?void 0:t.defaultState,values:(t==null?void 0:t.defaultValues)??((f=t==null?void 0:t.defaultState)==null?void 0:f.values)});if(t!=null&&t.transform){i=t.transform({state:i}).state;for(const s of Object.keys(i.errorMap)){const n=i.errorMap[s];if(!(n===void 0||!xe(n)))for(const c of Object.keys(n.fields)){const d=n.fields[c];if(d===void 0)continue;const l=i.fieldMetaBase[c];i.fieldMetaBase[c]={isTouched:!1,isValidating:!1,isBlurred:!1,isDirty:!1,...l??{},errorSourceMap:{...(l==null?void 0:l.errorSourceMap)??{},onChange:"form"},errorMap:{...(l==null?void 0:l.errorMap)??{},[s]:d}}}}}this.baseStore=we(i);let r;this.fieldMetaDerived=we(s=>{var l,o,h;const n=this.baseStore.get();let c=0;const d={};for(const a of Object.keys(n.fieldMetaBase)){const m=n.fieldMetaBase[a],v=r==null?void 0:r.fieldMetaBase[a],M=s==null?void 0:s[a],b=be(n.values,a);let F=M==null?void 0:M.errors;if(!v||m.errorMap!==v.errorMap){F=Object.values(m.errorMap??{}).filter(A=>A!==void 0);const k=(l=this.getFieldInfo(a))==null?void 0:l.instance;(!k||!k.options.disableErrorFlat)&&(F=F.flat(1))}const p=!ns(F),E=!m.isDirty,w=Y(b,be(this.options.defaultValues,a))||Y(b,(h=(o=this.getFieldInfo(a))==null?void 0:o.instance)==null?void 0:h.options.defaultValue);if(M&&M.isPristine===E&&M.isValid===p&&M.isDefaultValue===w&&M.errors===F&&m===v){d[a]=M,c++;continue}d[a]={...m,errors:F??[],isPristine:E,isValid:p,isDefaultValue:w}}return Object.keys(n.fieldMetaBase).length?s&&c===Object.keys(n.fieldMetaBase).length?s:(r=this.baseStore.get(),d):d});let u;this.store=we(s=>{var L,y;const n=this.baseStore.get(),c=this.fieldMetaDerived.get(),d=Object.values(c).filter(Boolean),l=d.some(x=>x.isValidating),o=d.every(x=>x.isValid),h=d.some(x=>x.isTouched),a=d.some(x=>x.isBlurred),m=d.every(x=>x.isDefaultValue),v=h&&((L=n.errorMap)==null?void 0:L.onMount),M=d.some(x=>x.isDirty),b=!M,F=!!((y=n.errorMap)!=null&&y.onMount||d.some(x=>{var I;return(I=x==null?void 0:x.errorMap)==null?void 0:I.onMount})),p=!!l;let E=(s==null?void 0:s.errors)??[];(!u||n.errorMap!==u.errorMap)&&(E=Object.values(n.errorMap).reduce((x,I)=>I===void 0?x:I&&xe(I)?(x.push(I.form),x):(x.push(I),x),[]));const w=E.length===0,k=o&&w,A=this.options.canSubmitWhenInvalid??!1,O=n.submissionAttempts===0&&!h&&!F||!p&&!n.isSubmitting&&k||A;let C=n.errorMap;if(v&&(E=E.filter(x=>x!==n.errorMap.onMount),C=Object.assign(C,{onMount:void 0})),s&&u&&s.errorMap===C&&s.fieldMeta===this.fieldMetaDerived.state&&s.errors===E&&s.isFieldsValidating===l&&s.isFieldsValid===o&&s.isFormValid===w&&s.isValid===k&&s.canSubmit===O&&s.isTouched===h&&s.isBlurred===a&&s.isPristine===b&&s.isDefaultValue===m&&s.isDirty===M&&Y(u,n))return s;const B={...n,errorMap:C,fieldMeta:this.fieldMetaDerived.state,errors:E,isFieldsValidating:l,isFieldsValid:o,isFormValid:w,isValid:k,canSubmit:O,isTouched:h,isBlurred:a,isPristine:b,isDefaultValue:m,isDirty:M};return u=this.baseStore.get(),B}),this.handleSubmit=this.handleSubmit.bind(this),this.update(t||{})}get state(){return this.store.state}get formId(){return this._formId}runValidator(t){return ht(t.validate)?ae[t.type](t.value,t.validate):t.validate(t.value)}handleSubmit(t){return this._handleSubmit(t)}}function Ee(e){if(e){if(xe(e)){const t=Ee(e.form).formError,i=e.fields;return{formError:t,fieldErrors:i}}return{formError:e}}return{formError:void 0}}function de(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 it{constructor(t){this.options={},this.mount=()=>{var u,f;this.options.defaultValue!==void 0&&!this.getMeta().isTouched&&this.form.setFieldValue(this.name,this.options.defaultValue,{dontUpdateMeta:!0});const i=this.getInfo();i.instance=this,this.update(this.options);const{onMount:r}=this.options.validators||{};if(r){const s=this.runValidator({validate:r,value:{value:this.state.value,fieldApi:this,validationSource:"field"},type:"validate"});s&&this.setMeta(n=>({...n,errorMap:{...n==null?void 0:n.errorMap,onMount:s},errorSourceMap:{...n==null?void 0:n.errorSourceMap,onMount:"field"}}))}return(f=(u=this.options.listeners)==null?void 0:u.onMount)==null||f.call(u,{value:this.state.value,fieldApi:this}),()=>{var n,c,d,l;for(const[o,h]of Object.entries(this.timeoutIds.validations))h&&(clearTimeout(h),this.timeoutIds.validations[o]=null);for(const[o,h]of Object.entries(this.timeoutIds.listeners))h&&(clearTimeout(h),this.timeoutIds.listeners[o]=null);for(const[o,h]of Object.entries(this.timeoutIds.formListeners))h&&(clearTimeout(h),this.timeoutIds.formListeners[o]=null);const s=this.form.fieldInfo[this.name];if(s&&s.instance===this){for(const[o,h]of Object.entries(s.validationMetaMap))h==null||h.lastAbortController.abort(),s.validationMetaMap[o]=void 0;this.form.baseStore.setState(o=>{var h,a,m;return{...o,fieldMetaBase:{...o.fieldMetaBase,[this.name]:{...z,isTouched:((h=o.fieldMetaBase[this.name])==null?void 0:h.isTouched)??z.isTouched,isBlurred:((a=o.fieldMetaBase[this.name])==null?void 0:a.isBlurred)??z.isBlurred,isDirty:((m=o.fieldMetaBase[this.name])==null?void 0:m.isDirty)??z.isDirty}}}}),s.instance=null,(c=(n=this.options.listeners)==null?void 0:n.onUnmount)==null||c.call(n,{value:this.state.value,fieldApi:this}),(l=(d=this.form.options.listeners)==null?void 0:d.onFieldUnmount)==null||l.call(d,{formApi:this.form,fieldApi:this})}}},this.update=i=>{if(this.options=i,this.name=i.name,!this.state.meta.isTouched&&this.options.defaultValue!==void 0){const r=this.form.getFieldValue(this.name);Y(r,i.defaultValue)||this.form.setFieldValue(this.name,i.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=(i,r)=>{this.form.setFieldValue(this.name,i,N(r,{dontRunListeners:!0,dontValidate:!0})),r!=null&&r.dontRunListeners||this.triggerOnChangeListener(),r!=null&&r.dontValidate||this.validate("change")},this.getMeta=()=>this.store.state.meta,this.setMeta=i=>this.form.setFieldMeta(this.name,i),this.getInfo=()=>this.form.getFieldInfo(this.name),this.pushValue=(i,r)=>{this.form.pushFieldValue(this.name,i,N(r,{dontRunListeners:!0})),r!=null&&r.dontRunListeners||this.triggerOnChangeListener()},this.insertValue=(i,r,u)=>{this.form.insertFieldValue(this.name,i,r,N(u,{dontRunListeners:!0})),u!=null&&u.dontRunListeners||this.triggerOnChangeListener()},this.replaceValue=(i,r,u)=>{this.form.replaceFieldValue(this.name,i,r,N(u,{dontRunListeners:!0})),u!=null&&u.dontRunListeners||this.triggerOnChangeListener()},this.removeValue=(i,r)=>{this.form.removeFieldValue(this.name,i,N(r,{dontRunListeners:!0})),r!=null&&r.dontRunListeners||this.triggerOnChangeListener()},this.swapValues=(i,r,u)=>{this.form.swapFieldValues(this.name,i,r,N(u,{dontRunListeners:!0})),u!=null&&u.dontRunListeners||this.triggerOnChangeListener()},this.moveValue=(i,r,u)=>{this.form.moveFieldValues(this.name,i,r,N(u,{dontRunListeners:!0})),u!=null&&u.dontRunListeners||this.triggerOnChangeListener()},this.clearValues=i=>{this.form.clearFieldValues(this.name,N(i,{dontRunListeners:!0})),i!=null&&i.dontRunListeners||this.triggerOnChangeListener()},this.getLinkedFields=i=>{const r=Object.values(this.form.fieldInfo),u=[];for(const f of r){if(!f.instance)continue;const{onChangeListenTo:s,onBlurListenTo:n}=f.instance.options.validators||{};i==="change"&&(s!=null&&s.includes(this.name))&&u.push(f.instance),i==="blur"&&(n!=null&&n.includes(this.name))&&u.push(f.instance)}return u},this.validateSync=(i,r)=>{var d;const u=Re(i,{...this.options,form:this.form,fieldName:this.name,validationLogic:this.form.options.validationLogic||ie}),s=this.getLinkedFields(i).reduce((l,o)=>{const h=Re(i,{...o.options,form:o.form,fieldName:o.name,validationLogic:o.form.options.validationLogic||ie});return h.forEach(a=>{a.field=o}),l.concat(h)},[]);let n=!1;W(()=>{const l=(o,h)=>{var F;const a=Fe(h.cause),m=h.validate?nt(o.runValidator({validate:h.validate,value:{value:o.store.state.value,validationSource:"field",fieldApi:o},type:"validate"})):void 0,v=r[a],{newErrorValue:M,newSource:b}=et({formLevelError:v,fieldLevelError:m});((F=o.state.meta.errorMap)==null?void 0:F[a])!==M&&o.setMeta(p=>({...p,errorMap:{...p.errorMap,[a]:M},errorSourceMap:{...p.errorSourceMap,[a]:b}})),M&&(n=!0)};for(const o of u)l(this,o);for(const o of s)o.validate&&l(o.field,o)});const c=Fe("submit");return(d=this.state.meta.errorMap)!=null&&d[c]&&i!=="submit"&&!n&&this.setMeta(l=>({...l,errorMap:{...l.errorMap,[c]:void 0},errorSourceMap:{...l.errorSourceMap,[c]:void 0}})),{hasErrored:n}},this.validateAsync=async(i,r)=>{const u=De(i,{...this.options,form:this.form,fieldName:this.name,validationLogic:this.form.options.validationLogic||ie}),f=await r,s=this.getLinkedFields(i),n=s.reduce((a,m)=>{const v=De(i,{...m.options,form:m.form,fieldName:m.name,validationLogic:m.form.options.validationLogic||ie});return v.forEach(M=>{M.field=m}),a.concat(v)},[]),c=[],d=[],l=u.some(a=>a.validate)||n.some(a=>a.validate);if(l){this.state.meta.isValidating||this.setMeta(a=>({...a,isValidating:!0}));for(const a of s)a.setMeta(m=>({...m,isValidating:!0}))}const o=(a,m,v)=>{const M=Fe(m.cause),b=a.getInfo(),F=b.validationMetaMap[M];F==null||F.lastAbortController.abort();const p=new AbortController;b.validationMetaMap[M]={lastAbortController:p},v.push(new Promise(async E=>{var B;let w;try{w=await new Promise((L,y)=>{a.timeoutIds.validations[m.cause]&&clearTimeout(a.timeoutIds.validations[m.cause]),a.timeoutIds.validations[m.cause]=setTimeout(async()=>{if(p.signal.aborted)return L(void 0);try{L(await this.runValidator({validate:m.validate,value:{value:a.store.state.value,fieldApi:a,signal:p.signal,validationSource:"field"},type:"validateAsync"}))}catch(x){y(x)}},m.debounceMs)})}catch(L){w=L}if(p.signal.aborted)return E(void 0);const k=nt(w),A=(B=f[a.name])==null?void 0:B[M],{newErrorValue:O,newSource:C}=et({formLevelError:A,fieldLevelError:k});if(a.getInfo().instance!==a)return E(void 0);a.setMeta(L=>({...L,errorMap:{...L==null?void 0:L.errorMap,[M]:O},errorSourceMap:{...L.errorSourceMap,[M]:C}})),E(O)}))};for(const a of u)a.validate&&o(this,a,c);for(const a of n)a.validate&&o(a.field,a,d);let h=[];if((c.length||d.length)&&(h=await Promise.all(c),await Promise.all(d)),l){this.setMeta(a=>({...a,isValidating:!1}));for(const a of s)a.setMeta(m=>({...m,isValidating:!1}))}return h.filter(Boolean)},this.validate=(i,r)=>{var n;if(!this.state.meta.isTouched)return[];const{fieldsErrorMap:u}=r!=null&&r.skipFormValidation?{fieldsErrorMap:{}}:this.form.validateSync(i),{hasErrored:f}=this.validateSync(i,u[this.name]??{});if(f&&!this.options.asyncAlways)return(n=this.getInfo().validationMetaMap[Fe(i)])==null||n.lastAbortController.abort(),this.state.meta.errors;const s=r!=null&&r.skipFormValidation?Promise.resolve({}):this.form.validateAsync(i);return this.validateAsync(i,s)},this.handleChange=i=>{this.setValue(i)},this.handleBlur=()=>{this.state.meta.isTouched||this.setMeta(r=>({...r,isTouched:!0})),this.state.meta.isBlurred||this.setMeta(r=>({...r,isBlurred:!0})),this.validate("blur"),this.triggerOnBlurListener()},this.setErrorMap=i=>{this.setMeta(r=>({...r,errorMap:{...r.errorMap,...i}}))},this.parseValueWithSchema=i=>ae.validate({value:this.state.value,validationSource:"field"},i),this.parseValueWithSchemaAsync=i=>ae.validateAsync({value:this.state.value,validationSource:"field"},i),this.triggerOnChangeListener=()=>{var u,f,s,n,c,d;const i=(u=this.form.options.listeners)==null?void 0:u.onChangeDebounceMs;i&&i>0?(this.timeoutIds.formListeners.change&&clearTimeout(this.timeoutIds.formListeners.change),this.timeoutIds.formListeners.change=setTimeout(()=>{var l,o;(o=(l=this.form.options.listeners)==null?void 0:l.onChange)==null||o.call(l,{formApi:this.form,fieldApi:this})},i)):(s=(f=this.form.options.listeners)==null?void 0:f.onChange)==null||s.call(f,{formApi:this.form,fieldApi:this});const r=(n=this.options.listeners)==null?void 0:n.onChangeDebounceMs;r&&r>0?(this.timeoutIds.listeners.change&&clearTimeout(this.timeoutIds.listeners.change),this.timeoutIds.listeners.change=setTimeout(()=>{var l,o;(o=(l=this.options.listeners)==null?void 0:l.onChange)==null||o.call(l,{value:this.state.value,fieldApi:this})},r)):(d=(c=this.options.listeners)==null?void 0:c.onChange)==null||d.call(c,{value:this.state.value,fieldApi:this})},this.form=t.form,this.name=t.name,this.options=t,this.timeoutIds={validations:{},listeners:{},formListeners:{}},this.store=we(i=>{this.form.store.get();const r=this.form.getFieldMeta(this.name)??{...z,...t.defaultMeta};let u=this.form.getFieldValue(this.name);return!r.isTouched&&u===void 0&&this.options.defaultValue!==void 0&&!Y(u,this.options.defaultValue)&&(u=this.options.defaultValue),i&&i.value===u&&i.meta===r?i:{value:u,meta:r}})}get state(){return this.store.state}runValidator(t){return ht(t.validate)?ae[t.type](t.value,t.validate):t.validate(t.value)}triggerOnBlurListener(){var r,u,f,s,n,c;const t=(r=this.form.options.listeners)==null?void 0:r.onBlurDebounceMs;t&&t>0?(this.timeoutIds.formListeners.blur&&clearTimeout(this.timeoutIds.formListeners.blur),this.timeoutIds.formListeners.blur=setTimeout(()=>{var d,l;(l=(d=this.form.options.listeners)==null?void 0:d.onBlur)==null||l.call(d,{formApi:this.form,fieldApi:this})},t)):(f=(u=this.form.options.listeners)==null?void 0:u.onBlur)==null||f.call(u,{formApi:this.form,fieldApi:this});const i=(s=this.options.listeners)==null?void 0:s.onBlurDebounceMs;i&&i>0?(this.timeoutIds.listeners.blur&&clearTimeout(this.timeoutIds.listeners.blur),this.timeoutIds.listeners.blur=setTimeout(()=>{var d,l;(l=(d=this.options.listeners)==null?void 0:d.onBlur)==null||l.call(d,{value:this.state.value,fieldApi:this})},i)):(c=(n=this.options.listeners)==null?void 0:n.onBlur)==null||c.call(n,{value:this.state.value,fieldApi:this})}}function nt(e){if(e)return e}function Fe(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"}}function os(e,t){if(!t)return;const i=Object.assign({},e,{state:ce(e.state)});t(i),i.fieldInfo!==e.fieldInfo&&(e.fieldInfo=i.fieldInfo),i.options!==e.options&&(e.options=i.options);const u=Object.keys({values:null,validationMetaMap:null,fieldMetaBase:null,isSubmitting:null,isSubmitted:null,isValidating:null,submissionAttempts:null,isSubmitSuccessful:null,_force_re_eval:null}).reduce((f,s)=>(e.state[s]!==i.state[s]&&(f[s]=i.state[s]),f),{});return W(()=>{Object.keys(u).length&&e.baseStore.setState(f=>({...f,...u})),i.state.errorMap!==e.state.errorMap&&e.setErrorMap(i.state.errorMap)}),i}const ne=typeof window<"u"?V.useLayoutEffect:V.useEffect;function ls(e){const[t,i]=V.useState(()=>({form:e.form,name:e.name})),[r,u]=V.useState(()=>new it({...e}));(t.form!==e.form||t.name!==e.name)&&(u(new it({...e})),i({form:e.form,name:e.name}));const f=Q(r.store,e.mode==="array"?a=>Object.keys(a.value??[]).length:a=>a.value),s=Q(r.store,a=>a.meta.isTouched),n=Q(r.store,a=>a.meta.isBlurred),c=Q(r.store,a=>a.meta.isDirty),d=Q(r.store,a=>a.meta.errorMap),l=Q(r.store,a=>a.meta.errorSourceMap),o=Q(r.store,a=>a.meta.isValidating),h=V.useMemo(()=>{const m={...r,get state(){return{value:e.mode==="array"?r.state.value:f,get meta(){return{...r.state.meta,isTouched:s,isBlurred:n,isDirty:c,errorMap:d,errorSourceMap:l,isValidating:o}}}}};return m.Field=ft,m},[r,e.mode,f,s,n,c,d,l,o]);return ne(r.mount,[r]),ne(()=>{r.update(e)}),h}const ft=(({children:e,...t})=>{const i=ls(t),r=V.useMemo(()=>je(e,i),[e,i]);return g.jsx(g.Fragment,{children:r})});function us(){return V.useState(()=>ct())[0]}const ds=pt,cs=V.version.split(".")[0]==="17"?us:ds.useId;function hs({form:e,selector:t=r=>r,children:i}){const r=Q(e.store,t);return g.jsx(g.Fragment,{children:je(i,r)})}function fs(e){const t=cs(),[i,r]=V.useState(e==null?void 0:e.formId),[u,f]=V.useState(()=>new st({...e,formId:(e==null?void 0:e.formId)??t}));if(i!==(e==null?void 0:e.formId)){const c=(e==null?void 0:e.formId)??t;f(new st({...e,formId:c})),r(c)}const s=V.useMemo(()=>{const c={...u,handleSubmit:((...d)=>u._handleSubmit(...d)),get formId(){return u._formId},get state(){return u.store.state}};return c.Field=function(l){return g.jsx(ft,{...l,form:u})},c.Subscribe=function(l){return g.jsx(hs,{form:u,selector:l.selector,children:l.children})},c},[u]);ne(u.mount,[]),ne(()=>{u.update(e)});const n=V.useRef(!1);return ne(()=>{n.current&&e!=null&&e.transform&&os(u,e.transform)},[u,e==null?void 0:e.transform]),ne(()=>{n.current=!0}),s}function ms(e){const{open:t,defaultOpen:i,onOpenChange:r,disabled:u}=e,f=t!==void 0,[s,n]=Ot({controlled:t,default:i,name:"Collapsible",state:"open"}),{mounted:c,setMounted:d,transitionStatus:l}=Pt(s,!0,!0),[o,h]=V.useState(s),[{height:a,width:m},v]=V.useState({height:void 0,width:void 0}),M=Bt(),[b,F]=V.useState(),p=b??M,[E,w]=V.useState(!1),[k,A]=V.useState(!1),O=V.useRef(null),C=V.useRef(null),B=V.useRef(null),L=V.useRef(null),y=Rt(L,!1),x=Ne(I=>{const j=!s,T=ut(Dt,I.nativeEvent);if(r(j,T),T.isCanceled)return;const K=L.current;C.current==="css-animation"&&K!=null&&K.style.removeProperty("animation-name"),!E&&!k&&(C.current!=null&&C.current!=="css-animation"&&!c&&j&&d(!0),C.current==="css-animation"&&(!o&&j&&h(!0),!c&&j&&d(!0))),n(j),C.current==="none"&&c&&!j&&d(!1)});return Z(()=>{f&&C.current==="none"&&!s&&d(!1)},[f,s,t,d]),V.useMemo(()=>({abortControllerRef:O,animationTypeRef:C,disabled:u,handleTrigger:x,height:a,mounted:c,open:s,panelId:p,panelRef:L,runOnceAnimationsFinish:y,setDimensions:v,setHiddenUntilFound:w,setKeepMounted:A,setMounted:d,setOpen:n,setPanelIdState:F,setVisible:h,transitionDimensionRef:B,transitionStatus:l,visible:o,width:m}),[O,C,u,x,a,c,s,p,L,y,v,w,A,d,n,h,B,l,o,m])}const mt=V.createContext(void 0);function gt(){const e=V.useContext(mt);if(e===void 0)throw new Error(yt(15));return e}let he=(function(e){return e.open="data-open",e.closed="data-closed",e[e.startingStyle=Je.startingStyle]="startingStyle",e[e.endingStyle=Je.endingStyle]="endingStyle",e})({}),gs=(function(e){return e.panelOpen="data-panel-open",e})({});const vs={[he.open]:""},bs={[he.closed]:""},ps={open(e){return e?{[gs.panelOpen]:""}:null}},ys={open(e){return e?vs:bs}},vt={...ys,...dt},Ms=V.forwardRef(function(t,i){const{render:r,className:u,defaultOpen:f=!1,disabled:s=!1,onOpenChange:n,open:c,style:d,...l}=t,o=Ne(n),h=ms({open:c,defaultOpen:f,onOpenChange:o,disabled:s}),a=V.useMemo(()=>({open:h.open,disabled:h.disabled,transitionStatus:h.transitionStatus}),[h.open,h.disabled,h.transitionStatus]),m=V.useMemo(()=>({...h,onOpenChange:o,state:a}),[h,o,a]),v=_e("div",t,{state:a,ref:i,props:l,stateAttributesMapping:vt});return g.jsx(mt.Provider,{value:m,children:v})}),Ss={...ps,...dt},Fs=V.forwardRef(function(t,i){const{panelId:r,open:u,handleTrigger:f,state:s,disabled:n}=gt(),{className:c,disabled:d=n,id:l,render:o,nativeButton:h=!0,style:a,...m}=t,{getButtonProps:v,buttonRef:M}=Mt({disabled:d,focusableWhenDisabled:!0,native:h}),b=V.useMemo(()=>({"aria-controls":u?r:void 0,"aria-expanded":u,onClick:f}),[r,u,f]);return _e("button",t,{state:s,ref:[i,M],props:[b,m,v],stateAttributesMapping:Ss})});let ws=(function(e){return e.disabled="data-disabled",e.orientation="data-orientation",e})({});function xs(e){const{abortControllerRef:t,animationTypeRef:i,externalRef:r,height:u,hiddenUntilFound:f,keepMounted:s,id:n,mounted:c,onOpenChange:d,open:l,panelRef:o,runOnceAnimationsFinish:h,setDimensions:a,setMounted:m,setOpen:v,setVisible:M,transitionDimensionRef:b,visible:F,width:p}=e,E=V.useRef(!1),w=V.useRef(null),k=V.useRef(l),A=V.useRef(l),O=Nt(),C=V.useMemo(()=>i.current==="css-animation"?!F:!l&&!c,[l,c,F,i]),B=Ne(y=>{if(!y)return;if(i.current==null||b.current==null){const j=getComputedStyle(y),T=j.animationName!=="none"&&j.animationName!=="",K=j.transitionDuration!=="0s"&&j.transitionDuration!=="";T&&K||(j.animationName==="none"&&j.transitionDuration!=="0s"?i.current="css-transition":j.animationName!=="none"&&j.transitionDuration==="0s"?i.current="css-animation":i.current="none"),y.getAttribute(ws.orientation)==="horizontal"||j.transitionProperty.indexOf("width")>-1?b.current="width":b.current="height"}if(i.current!=="css-transition")return;(u===void 0||p===void 0)&&(a({height:y.scrollHeight,width:y.scrollWidth}),A.current&&y.style.setProperty("transition-duration","0s"));let x=-1,I=-1;return x=$.request(()=>{A.current=!1,I=$.request(()=>{setTimeout(()=>{y.style.removeProperty("transition-duration")})})}),()=>{$.cancel(x),$.cancel(I)}}),L=St(r,o,B);return Z(()=>{if(i.current!=="css-transition")return;const y=o.current;if(!y)return;let x=-1;if(t.current!=null&&(t.current.abort(),t.current=null),l){const I={"justify-content":y.style.justifyContent,"align-items":y.style.alignItems,"align-content":y.style.alignContent,"justify-items":y.style.justifyItems};Object.keys(I).forEach(j=>{y.style.setProperty(j,"initial","important")}),!A.current&&!s&&y.setAttribute(he.startingStyle,""),a({height:y.scrollHeight,width:y.scrollWidth}),x=$.request(()=>{Object.entries(I).forEach(([j,T])=>{T===""?y.style.removeProperty(j):y.style.setProperty(j,T)})})}else{if(y.scrollHeight===0&&y.scrollWidth===0)return;a({height:y.scrollHeight,width:y.scrollWidth});const I=new AbortController;t.current=I;const j=I.signal;let T=null;const K=he.endingStyle;return T=new MutationObserver(Le=>{Le.some(Ce=>Ce.type==="attributes"&&Ce.attributeName===K)&&(T==null||T.disconnect(),T=null,h(()=>{a({height:0,width:0}),y.style.removeProperty("content-visibility"),m(!1),t.current===I&&(t.current=null)},j))}),T.observe(y,{attributes:!0,attributeFilter:[K]}),()=>{T==null||T.disconnect(),O.cancel(),t.current===I&&(I.abort(),t.current=null)}}return()=>{$.cancel(x)}},[t,i,O,f,s,c,l,o,h,a,m]),Z(()=>{if(i.current!=="css-animation")return;const y=o.current;y&&(w.current=y.style.animationName||w.current,y.style.setProperty("animation-name","none"),a({height:y.scrollHeight,width:y.scrollWidth}),!k.current&&!E.current&&y.style.removeProperty("animation-name"),l?(t.current!=null&&(t.current.abort(),t.current=null),m(!0),M(!0)):(t.current=new AbortController,h(()=>{m(!1),M(!1),t.current=null},t.current.signal)))},[t,i,l,o,h,a,m,M,F]),Ft(()=>{const y=$.request(()=>{k.current=!1});return()=>$.cancel(y)}),Z(()=>{if(!f)return;const y=o.current;if(!y)return;let x=-1,I=-1;return l&&E.current&&(y.style.transitionDuration="0s",a({height:y.scrollHeight,width:y.scrollWidth}),x=$.request(()=>{E.current=!1,I=$.request(()=>{setTimeout(()=>{y.style.removeProperty("transition-duration")})})})),()=>{$.cancel(x),$.cancel(I)}},[f,l,o,a]),Z(()=>{const y=o.current;y&&f&&C&&(y.setAttribute("hidden","until-found"),i.current==="css-transition"&&y.setAttribute(he.startingStyle,""))},[f,C,i,o]),V.useEffect(function(){const x=o.current;if(!x)return;function I(j){E.current=!0,v(!0),d(!0,ut($t,j))}return _t(x,"beforematch",I)},[d,o,v]),V.useMemo(()=>({props:{hidden:C,id:n,ref:L}}),[C,n,L])}let at=(function(e){return e.collapsiblePanelHeight="--collapsible-panel-height",e.collapsiblePanelWidth="--collapsible-panel-width",e})({});const Vs=V.forwardRef(function(t,i){const{className:r,hiddenUntilFound:u,keepMounted:f,render:s,id:n,style:c,...d}=t,{abortControllerRef:l,animationTypeRef:o,height:h,mounted:a,onOpenChange:m,open:v,panelId:M,panelRef:b,runOnceAnimationsFinish:F,setDimensions:p,setHiddenUntilFound:E,setKeepMounted:w,setMounted:k,setPanelIdState:A,setOpen:O,setVisible:C,state:B,transitionDimensionRef:L,visible:y,width:x,transitionStatus:I}=gt(),j=u??!1,T=f??!1;Z(()=>{if(n)return A(n),()=>{A(void 0)}},[n,A]),Z(()=>{E(j)},[E,j]),Z(()=>{w(T)},[w,T]);const{props:K}=xs({abortControllerRef:l,animationTypeRef:o,externalRef:i,height:h,hiddenUntilFound:j,id:M,keepMounted:T,mounted:a,onOpenChange:m,open:v,panelRef:b,runOnceAnimationsFinish:F,setDimensions:p,setMounted:k,setOpen:O,setVisible:C,transitionDimensionRef:L,visible:y,width:x});Ut({open:v&&I==="idle",ref:b,onComplete(){v&&p({height:void 0,width:void 0})}});const Le=V.useMemo(()=>({...B,transitionStatus:I}),[B,I]),Ue=_e("div",t,{state:Le,ref:[i,b],props:[K,{style:{[at.collapsiblePanelHeight]:h===void 0?"auto":`${h}px`,[at.collapsiblePanelWidth]:x===void 0?"auto":`${x}px`}},d],stateAttributesMapping:vt});return T||j||a?Ue:null});function Es({...e}){return g.jsx(Ms,{"data-slot":"collapsible",...e})}function As({...e}){return g.jsx(Fs,{"data-slot":"collapsible-trigger",...e})}function Is({...e}){return g.jsx(Vs,{"data-slot":"collapsible-content",...e})}function js({className:e,...t}){return g.jsx("label",{"data-slot":"label",className:ue("flex items-center gap-2 text-xs/relaxed leading-none font-medium select-none group-data-[disabled=true]:pointer-events-none group-data-[disabled=true]:opacity-50 peer-disabled:cursor-not-allowed peer-disabled:opacity-50",e),...t})}function Ls({className:e,...t}){return g.jsx("div",{"data-slot":"field-group",className:ue("group/field-group @container/field-group flex w-full flex-col gap-4 data-[slot=checkbox-group]:gap-3 *:data-[slot=field-group]:gap-4",e),...t})}const Cs=wt("group/field flex w-full gap-2 data-[invalid=true]:text-destructive",{variants:{orientation:{vertical:"flex-col *:w-full [&>.sr-only]:w-auto",horizontal:"flex-row items-center has-[>[data-slot=field-content]]:items-start *:data-[slot=field-label]:flex-auto has-[>[data-slot=field-content]]:[&>[role=checkbox],[role=radio]]:mt-px",responsive:"flex-col *:w-full @md/field-group:flex-row @md/field-group:items-center @md/field-group:*:w-auto @md/field-group:has-[>[data-slot=field-content]]:items-start @md/field-group:*:data-[slot=field-label]:flex-auto [&>.sr-only]:w-auto @md/field-group:has-[>[data-slot=field-content]]:[&>[role=checkbox],[role=radio]]:mt-px"}},defaultVariants:{orientation:"vertical"}});function ks({className:e,orientation:t="vertical",...i}){return g.jsx("fieldset",{"data-slot":"field","data-orientation":t,className:ue(Cs({orientation:t}),e),...i})}function Ts({className:e,...t}){return g.jsx(js,{"data-slot":"field-label",className:ue("group/field-label peer/field-label flex w-fit gap-2 leading-snug group-data-[disabled=true]/field:opacity-50 has-data-checked:bg-primary/5 has-[>[data-slot=field]]:rounded-md has-[>[data-slot=field]]:border *:data-[slot=field]:p-2 dark:has-data-checked:bg-primary/10","has-[>[data-slot=field]]:w-full has-[>[data-slot=field]]:flex-col",e),...t})}function Os({className:e,children:t,errors:i,...r}){const u=V.useMemo(()=>{var s;if(t)return t;if(!(i!=null&&i.length))return null;const f=[...new Map(i.map(n=>[n==null?void 0:n.message,n])).values()];return(f==null?void 0:f.length)===1?(s=f[0])==null?void 0:s.message:g.jsx("ul",{className:"ml-4 flex list-disc flex-col gap-1",children:f.map(n=>(n==null?void 0:n.message)&&g.jsx("li",{children:n.message},n.message))})},[t,i]);return u?g.jsx("div",{role:"alert","data-slot":"field-error",className:ue("text-xs/relaxed font-normal text-destructive",e),...r,children:u}):null}function Ps({className:e,...t}){return g.jsx("textarea",{"data-slot":"textarea",className:ue("flex field-sizing-content min-h-16 w-full resize-none rounded-md border border-input bg-input/20 px-2 py-2 text-sm transition-colors outline-none placeholder:text-muted-foreground focus-visible:border-ring focus-visible:ring-2 focus-visible:ring-ring/30 disabled:cursor-not-allowed disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-2 aria-invalid:ring-destructive/20 md:text-xs/relaxed dark:bg-input/30 dark:aria-invalid:border-destructive/50 dark:aria-invalid:ring-destructive/40",e),...t})}function Bs(e){const t=xt(),{data:i=[],isLoading:r}=He(o=>o.from({m:Pe}).where(({m:h})=>Vt(h.id,e)),[e]),u=i[0]??null,{data:f=[]}=He(o=>o.from({p:Et}),[]),s=()=>{Pe.update(e,o=>{o.needsReview=!1})},n=async o=>{try{return await It(e,o),await qe.invalidateQueries({queryKey:["memories"]}),!0}catch{return Ge.error("Failed to add project — try again"),!1}},c=async o=>{try{await At(e,o),await qe.invalidateQueries({queryKey:["memories"]})}catch{Ge.error("Failed to remove project — try again")}},d=()=>void t({to:"/memories"}),l=f.filter(o=>!(u!=null&&u.projects.some(h=>h.id===o.id)));return{memory:u,isLoading:r,availableProjects:l,handleApprove:s,handleAddProject:n,handleRemoveProject:c,handleClose:d}}const Rs=Ct({content:Ye().min(1,"Content is required."),type:kt(lt),tagsInput:Ye()});function Oe({field:e,label:t,description:i,children:r}){const u=e.state.meta.isTouched&&!e.state.meta.isValid;return g.jsxs(ks,{"data-invalid":u,children:[g.jsx(Ts,{htmlFor:e.name,className:"text-[11px] uppercase tracking-wide text-muted-foreground",children:t}),r,i,u&&g.jsx(Os,{errors:e.state.meta.errors})]})}function Ds({memory:e,availableProjects:t,handleApprove:i,handleAddProject:r,handleRemoveProject:u,handleClose:f}){const[s,n]=V.useState(!1),[c,d]=V.useState("");V.useEffect(()=>{if(!s)return;const a=setTimeout(()=>n(!1),1500);return()=>clearTimeout(a)},[s]);const l=fs({defaultValues:{content:e.content,type:e.type,tagsInput:e.tags.join(", ")},validators:{onSubmit:Rs},onSubmit:({value:a})=>{const m=a.tagsInput.split(",").map(v=>v.trim()).filter(Boolean);Pe.update(e.id,v=>{a.content!==e.content&&(v.content=a.content),a.type!==e.type&&(v.type=a.type),JSON.stringify(m)!==JSON.stringify(e.tags)&&(v.tags=m)}),n(!0)}}),o=qt({shouldBlockFn:()=>l.state.isDirty,withResolver:!0}),h=async()=>{if(!c)return;await r(c)&&d("")};return g.jsxs("div",{className:"flex flex-col h-full",children:[g.jsxs("div",{className:"flex items-center justify-between px-4 py-2.5 border-b border-border shrink-0",children:[g.jsxs("div",{className:"flex items-center gap-2",children:[g.jsx(ve,{variant:e.type,children:e.type}),e.needsReview&&g.jsx(ve,{variant:"destructive",title:"Flagged for review — possible duplicate or conflict with another memory",children:"needs review"}),e.pinned&&g.jsx(ve,{variant:"default",children:"pinned"})]}),g.jsx(se,{variant:"ghost",size:"icon-sm",onClick:f,"aria-label":"Close",children:g.jsx(Qe,{weight:"regular"})})]}),g.jsxs("div",{className:"flex-1 overflow-y-auto px-4 py-4 space-y-4",children:[g.jsxs(Ls,{children:[g.jsx(l.Field,{name:"content",children:a=>g.jsx(Oe,{field:a,label:"Content",children:g.jsx(Ps,{id:a.name,name:a.name,value:a.state.value,onBlur:a.handleBlur,onChange:m=>a.handleChange(m.target.value),rows:8,className:"min-h-32 font-[var(--font-heading)] text-sm","aria-invalid":a.state.meta.isTouched&&!a.state.meta.isValid})})}),g.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[g.jsx(l.Field,{name:"type",children:a=>g.jsx(Oe,{field:a,label:"Type",description:g.jsx("p",{className:"text-[10px] text-muted-foreground leading-snug",children:Lt[a.state.value]}),children:g.jsx(Xe,{id:a.name,name:a.name,value:a.state.value,onBlur:a.handleBlur,onChange:m=>a.handleChange(m.target.value),className:"w-full",children:lt.map(m=>g.jsx(ke,{value:m,children:jt(m)},m))})})}),g.jsx(l.Field,{name:"tagsInput",children:a=>g.jsx(Oe,{field:a,label:"Tags",children:g.jsx(Wt,{id:a.name,name:a.name,value:a.state.value,onBlur:a.handleBlur,onChange:m=>a.handleChange(m.target.value),placeholder:"tag1, tag2","aria-invalid":a.state.meta.isTouched&&!a.state.meta.isValid})})})]})]}),g.jsxs("div",{className:"space-y-1.5",children:[g.jsx("p",{className:"text-[11px] uppercase tracking-wide text-muted-foreground",children:"Projects"}),g.jsxs("div",{className:"flex flex-wrap gap-1",children:[e.projects.length===0&&g.jsx("span",{className:"text-[11px] text-muted-foreground",children:"Global (no project)"}),e.projects.map(a=>g.jsxs(ve,{variant:"secondary",className:"gap-1 rounded-full text-[11px]",children:[a.name,g.jsx("button",{type:"button",onClick:()=>void u(a.id),className:"hover:text-destructive transition-colors leading-none","aria-label":`Remove from ${a.name}`,children:g.jsx(Qe,{weight:"regular",className:"size-2.5"})})]},a.id))]}),t.length>0&&g.jsxs("div",{className:"flex gap-1",children:[g.jsxs(Xe,{value:c,onChange:a=>d(a.target.value),size:"sm",className:"flex-1",children:[g.jsx(ke,{value:"",children:"Add to project…"}),t.map(a=>g.jsx(ke,{value:a.id,children:a.name},a.id))]}),g.jsx(se,{variant:"outline",size:"sm",disabled:!c,onClick:()=>void h(),children:"+"})]})]}),g.jsxs(Es,{className:"group pt-2 border-t border-border",children:[g.jsxs(As,{className:"flex items-center gap-1 cursor-pointer text-[11px] uppercase tracking-wide text-muted-foreground hover:text-foreground transition-colors select-none w-full",children:[g.jsx("span",{className:"transition-transform group-data-[open]:rotate-90",children:"›"}),"Details"]}),g.jsxs(Is,{className:"space-y-1 mt-2",children:[e.sourceHarness&&g.jsxs("div",{className:"flex justify-between text-[11px] text-muted-foreground",children:[g.jsx("span",{children:"Source"}),g.jsx("span",{children:e.sourceHarness})]}),g.jsxs("div",{className:"flex justify-between text-[11px] text-muted-foreground",children:[g.jsx("span",{children:"Accessed"}),g.jsxs("span",{children:[e.accessCount,"×"]})]}),g.jsxs("div",{className:"flex justify-between text-[11px] text-muted-foreground",children:[g.jsx("span",{children:"Updated"}),g.jsx("span",{children:new Date(e.updatedAt).toLocaleString()})]}),g.jsxs("div",{className:"flex justify-between text-[11px] text-muted-foreground",children:[g.jsx("span",{children:"Created"}),g.jsx("span",{children:new Date(e.createdAt).toLocaleString()})]})]})]})]}),g.jsxs("div",{className:"flex items-center gap-2 px-4 py-3 border-t border-border shrink-0",children:[o.status==="blocked"&&g.jsxs(g.Fragment,{children:[g.jsx("span",{className:"text-xs text-destructive",children:"Unsaved changes"}),g.jsx(se,{variant:"ghost",size:"sm",onClick:()=>o.proceed(),children:"Discard"}),g.jsx(se,{variant:"outline",size:"sm",onClick:()=>o.reset(),children:"Keep editing"})]}),e.needsReview&&o.status!=="blocked"&&g.jsx(se,{variant:"outline",size:"sm",onClick:i,title:"Mark as reviewed — this memory was flagged as a possible duplicate or conflict",children:"Mark reviewed"}),g.jsx("div",{className:"flex-1"}),g.jsx(se,{variant:"default",size:"sm",disabled:!l.state.isDirty,onClick:()=>void l.handleSubmit(),children:s?"Saved":"Save"})]})]})}function Ns({id:e}){const{memory:t,isLoading:i,availableProjects:r,handleApprove:u,handleAddProject:f,handleRemoveProject:s,handleClose:n}=Bs(e);return i||!t?g.jsx("div",{className:"flex items-center justify-center h-full text-xs text-muted-foreground",children:i?"Loading…":"Memory not found"}):g.jsx(Ds,{memory:t,availableProjects:r,handleApprove:u,handleAddProject:f,handleRemoveProject:s,handleClose:n},t.id)}function Ws(){const{id:e}=Tt.useParams();return g.jsx(Ns,{id:e},e)}export{Ws as component};
|