@owanturist/signal-form 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";function t(t,i){return null!=t?t:i()}function i(t){let i,s=t[0],o=1;for(;o<t.length;){const e=t[o],n=t[o+1];if(o+=2,("optionalAccess"===e||"optionalCall"===e)&&null==s)return;"access"===e||"optionalAccess"===e?(i=s,s=n(s)):"call"!==e&&"optionalCall"!==e||(s=n((...t)=>s.call(i,...t)),i=void 0)}return s}Object.defineProperty(exports,"__esModule",{value:!0});var s="onTouch",o="onChange",e="onSubmit",n="onInit",r=require("@owanturist/signal");function h(t){return null!=t}function c(t){return null===t}function a(t){return!0===t}function l(t){return Boolean(t)}function d(t,i,s,o,e){const n=i.read(t);return o?o(n,s.read(t)):null!=e?e(n):n}var u=class{static t({i:t}){return t}clone(){return this.i.h().o()}getOutput(t,i){const{l:s,u:o}=this.i;return d(t,s,o,i)}getInitial(t){return this.i.v.read(t)}setInitial(t){r.batch.call(void 0,i=>{this.i.p(i,t)})}getInput(t){return this.i.V.read(t)}setInput(t){r.batch.call(void 0,i=>{this.i.O(i,t)})}getError(t,i){const{m:s,A:o}=this.i;return d(t,s,o,i)}setError(t){r.batch.call(void 0,i=>{this.i.I(i,t)})}getValidateOn(t,i){const{C:s,T:o}=this.i;return d(t,s,o,i)}setValidateOn(t){r.batch.call(void 0,i=>{this.i.k(i,t)})}isValid(t,i){const{q:s,j:o}=this.i;return d(t,s,o,i,a)}isInvalid(t,i){const{S:s,F:o}=this.i;return d(t,s,o,i,l)}isValidated(t,i){const{B:s,W:o}=this.i;return d(t,s,o,i,a)}isDirty(t,i){const{M:s,P:o}=this.i;return d(t,s,o,i,l)}isTouched(t,i){const{D:s,R:o}=this.i;return d(t,s,o,i,l)}setTouched(t){r.batch.call(void 0,i=>{this.i.G(i,t)})}reset(t){r.batch.call(void 0,i=>{this.i.H(i,t)})}onFocusWhenInvalid(t){return this.i.K.J(t)}focusFirstInvalid(){r.batch.call(void 0,t=>{i([this,"access",t=>t.i,"access",t=>t.L,"call",i=>i(t),"optionalCall",t=>t()])})}getSubmitCount(t){return this.i.U.N.read(t)}isSubmitting(t){return this.i.U.X.read(t)>0}onSubmit(t){return this.i.Y.J(t)}async submit(){r.batch.call(void 0,t=>{this.i.U.N.write(t=>t+1),this.i.U.Z(t)});const t=r.untracked.call(void 0,t=>{const i=this.i.U.l.read(t);if(!c(i))return this.i.U.tt(t,i).filter(h)});t?t.length>0&&(this.i.U.X.write(t=>t+1),await Promise.all(t),this.i.U.X.write(t=>Math.max(0,t-1))):r.batch.call(void 0,t=>{i([this,"access",t=>t.i,"access",t=>t.U,"access",t=>t.L,"call",i=>i(t),"optionalCall",t=>t()])})}};function v(t){return t instanceof u}function _(t,i){return"object"==typeof t&&null!=t&&i in t}function f(t,i){return Object.is(t,i)}function p(t,i){return!!f(t,i)||t.length===i.length&&t.every((t,s)=>f(t,i[s]))}function b(t){return void 0===t}function V(t,i){return i===f||i===Object.is?f:(s,o)=>t(s)||t(o)?s===o:i(s,o)}function O(t){return t}function m(t){return"function"==typeof t}function y(i){let s=null;return()=>(t(s,()=>s={it:i()}),s.it)}function x(t,...i){return m(t)?t(...i):t}var{isArray:A}=Array;function g(t,i){return(A(t)?t:Array.from(t)).map((t,s)=>i(t,s))}var I=class{constructor(){this.st=[]}J(t){return this.st.push(t),()=>{this.st.splice(this.st.indexOf(t),1)}}ot(t){return g(new Set(this.st),i=>i(t))}et(){return 0===this.st.length}},w=class{constructor(s){this.K=new I,this.Y=new I,this.N=r.Signal.call(void 0,0),this.X=r.Signal.call(void 0,0),this.U=t(i([s,"optionalAccess",t=>t.U]),()=>this)}h(){return this.nt(null)}rt(t){return this.U===t.U?t:t.nt(this)}ht(t){return this.U===t.U}L(t){for(const{i:i}of this.ct(t)){const s=i.L(t);if(s)return s}const i=this.K.et()?null:this.m.read(t);return c(i)?null:()=>{this.K.ot(i)}}tt(t,i){const s=this.ct(t).flatMap(({i:s,lt:o})=>s.tt(t,o(i)));return[...this.Y.ot(i),...s]}},C=class extends u{constructor(t){super(),this.i=t}setTransform(t){this.i.dt(t)}};function E(t){return"object"==typeof t&&h(t)}function T(t){return"string"==typeof t}function k(i){if(!E(i))return[];const s=t(i.errors,()=>i.issues);return A(s)?g(s.filter(E),({message:t})=>t).filter(T):i instanceof Error?[i.message]:[]}function q(t,i){if("safeParse"in t)return(s=t.safeParse(i)).success?[null,s.data]:[g(_(s.error,"errors")?s.error.errors:s.error.issues,({message:t})=>t),null];var s;try{return[null,t.parse(i)]}catch(t){return[k(t),null]}}var j={ut:!0,vt:t=>[null,t]};function S(t){return{ut:!0,vt:i=>[null,t(i)]}}var F=class t extends w{constructor(t,i,h,a,l,d,u,v,_,f,p){super(t),this._t=i,this.V=h,this.ft=a,this.C=l,this.D=d,this.bt=u,this.Vt=v,this.Ot=_,this.yt=f,this.xt=p,this.o=y(()=>new C(this)),this.At=r.Signal.call(void 0,!0),this.gt=this.At;const b=r.Signal.call(void 0,t=>{const i=a.read(t);if(!c(i))return[i,null];const s=h.read(t),o=u.read(t),[e,n]=o.vt(s);return c(n)?[V.read(t)?e:null,null]:[null,n]});this.v=r.Signal.call(void 0,t=>i.read(t).it.read(t),{equals:_}),this.m=this.A=r.Signal.call(void 0,t=>{const[i]=b.read(t);return i},{equals:p}),this.l=this.u=r.Signal.call(void 0,t=>{const[,i]=b.read(t);return i},{equals:f}),this.R=d,this.M=this.P=r.Signal.call(void 0,t=>v(this.v.read(t),h.read(t))),this.T=l,this.q=this.j=r.Signal.call(void 0,t=>!c(this.l.read(t))),this.S=this.F=r.Signal.call(void 0,t=>!c(this.m.read(t)));const V=r.Signal.call(void 0,!1);this.B=this.W=r.Signal.call(void 0,t=>V.read(t)||this.S.read(t),(t,i)=>{V.write(()=>{if(t||u.read(i).ut)return!0;switch(l.read(i)){case n:return!0;case s:return d.read(i);case o:return this.M.read(i);case e:return!1}})}),this.B.write(!1)}nt(i){return new t(i,this._t.clone(({it:t,It:i})=>({it:t.clone(),It:i.clone()})),this.V.clone(),this.ft.clone(),this.C.clone(),this.D.clone(),this.bt.clone(),this.Vt,this.Ot,this.yt,this.xt)}wt(t,i,s){const{It:o,it:e}=this._t.read(t);if(i){const n=i._t.read(t);o.read(t)&&s&&(n.It.write(!0),n.it.write(e.read(t))),this._t.write(n)}else this._t.write({it:e.clone(),It:o.clone()})}p(t,i){const{it:s,It:o}=this._t.read(t);s.write(s=>m(i)?i(s,this.V.read(t)):i),o.write(!0),this.B.write(O)}O(t,i){this.V.write(s=>m(i)?i(s,this.v.read(t)):i),this.B.write(O)}I(t,i){this.ft.write(t=>x(i,t))}k(t,i){const s=this.C.read(t);this.C.write(x(i,s));s!==this.C.read(t)&&this.B.write(!1)}G(t,i){this.D.write(t=>x(i,t)),this.B.write(O)}Z(){this.B.write(!0)}H(t,i){const s=b(i)?this.v.read(t):m(i)?i(this.v.read(t),this.V.read(t)):i;this._t.read(t).it.write(s),this.V.write(s),this.D.write(!1),this.ft.write(null),this.B.write(!1)}ct(){return[]}dt(t){r.batch.call(void 0,()=>{this.bt.write(S(t)),this.B.write(O)})}};function B(t){return Array.isArray(t)?t.entries():Object.entries(t)}function W(t,i){const s={};for(const[o,e]of B(t))s[o]=i(e,o);return s}var M=class extends u{constructor(t){super(),this.i=t,this.fields={...W(t.Ct,({o:t})=>t()),...W(t.Et,t=>i=>t.read(i))}}};function P(t){return"boolean"==typeof t}M.t=u.t;var{values:D}=Object;function R(i,s,o,e){const n=t(i.find(s),()=>o);for(const s of i)if(s!==n)return t(e,()=>i);return n}var z=class t extends w{constructor(t,i,o){super(t),this.o=y(()=>new M(this)),this.v=r.Signal.call(void 0,t=>({...W(this.Ct,({v:i})=>i.read(t)),...W(this.Et,i=>i.read(t))})),this.V=r.Signal.call(void 0,t=>({...W(this.Ct,({V:i})=>i.read(t)),...W(this.Et,i=>i.read(t))})),this.m=r.Signal.call(void 0,t=>{const i=W(this.Ct,({m:i})=>i.read(t));return D(i).every(c)?null:i}),this.A=r.Signal.call(void 0,t=>W(this.Ct,({A:i})=>i.read(t))),this.C=r.Signal.call(void 0,t=>{const i=W(this.Ct,({C:i})=>i.read(t));return R(D(i),T,s,i)}),this.T=r.Signal.call(void 0,t=>W(this.Ct,({T:i})=>i.read(t))),this.D=r.Signal.call(void 0,t=>{const i=W(this.Ct,({D:i})=>i.read(t));return R(D(i),P,!1,i)}),this.R=r.Signal.call(void 0,t=>W(this.Ct,({R:i})=>i.read(t))),this.l=r.Signal.call(void 0,t=>{const i=W(this.Ct,({l:i})=>i.read(t));if(D(i).some(c))return null;const s=W(this.Et,i=>i.read(t));return{...i,...s}}),this.u=r.Signal.call(void 0,t=>({...W(this.Ct,({u:i})=>i.read(t)),...W(this.Et,i=>i.read(t))})),this.q=r.Signal.call(void 0,t=>{const i=W(this.Ct,({q:i})=>i.read(t));return R(D(i),P,!1,i)}),this.j=r.Signal.call(void 0,t=>W(this.Ct,({j:i})=>i.read(t))),this.S=r.Signal.call(void 0,t=>{const i=W(this.Ct,({S:i})=>i.read(t));return R(D(i),P,!1,i)}),this.F=r.Signal.call(void 0,t=>W(this.Ct,({F:i})=>i.read(t))),this.B=r.Signal.call(void 0,t=>{const i=W(this.Ct,({B:i})=>i.read(t));return R(D(i),P,!1,i)}),this.W=r.Signal.call(void 0,t=>W(this.Ct,({W:i})=>i.read(t))),this.M=r.Signal.call(void 0,t=>{const i=W(this.Ct,({M:i})=>i.read(t));return R(D(i),P,!1,i)}),this.P=r.Signal.call(void 0,t=>W(this.Ct,({P:i})=>i.read(t))),this.At=r.Signal.call(void 0,t=>{const i=W(this.Ct,({At:i})=>i.read(t));return R(D(i),P,!1,i)}),this.gt=r.Signal.call(void 0,t=>W(this.Ct,({gt:i})=>i.read(t))),this.Ct=W(i,t=>this.rt(t)),this.Et=W(o,t=>t.clone())}nt(i){return new t(i,this.Ct,this.Et)}wt(t,s,o){for(const[e,n]of B(this.Ct))n.wt(t,i([s,"optionalAccess",t=>t.Ct,"access",t=>t[e]]),o)}p(t,i){const s=m(i)?i(this.v.read(t),this.V.read(t)):i;for(const[i,o]of B(this.Ct))_(s,i)&&!b(s[i])&&o.p(t,s[i]);for(const[t,i]of B(this.Et))_(s,t)&&!b(s[t])&&i.write(s[t])}O(t,i){const s=m(i)?i(this.V.read(t),this.v.read(t)):i;for(const[i,o]of B(this.Ct))_(s,i)&&!b(s[i])&&o.O(t,s[i])}I(t,i){const s=m(i)?i(this.A.read(t)):i;for(const[i,o]of B(this.Ct))c(s)?o.I(t,s):_(s,i)&&!b(s[i])&&o.I(t,s[i])}k(t,i){const s=m(i)?i(this.T.read(t)):i;for(const[i,o]of B(this.Ct))T(s)?o.k(t,s):_(s,i)&&!b(s[i])&&o.k(t,s[i])}G(t,i){const s=m(i)?i(this.R.read(t)):i;for(const[i,o]of B(this.Ct))P(s)?o.G(t,s):_(s,i)&&!b(s[i])&&o.G(t,s[i])}Z(t){for(const i of D(this.Ct))i.Z(t)}H(t,i){b(i)||this.p(t,i);for(const i of D(this.Ct))i.H(t,void 0)}ct(){return g(B(this.Ct),([t,i])=>({i:i,lt:i=>i[t]}))}};function G(...t){return t}G.Tt=t=>t,G.kt=(t,i)=>i,G.qt=(t,i,s)=>s;var H=class extends u{constructor(t){super(),this.i=t,this.jt=r.Signal.call(void 0,t=>this.i.St(t),{equals:p})}getElements(t,i=G.Tt){return i(this.jt.read(t))}setElements(t){r.batch.call(void 0,s=>{const o=this.i.Ft(s),e=g(m(t)?t(this.jt.read(s),s):t,u.t),n=g(e,t=>this.i.rt(t));for(const t of n)t.wt(s,void 0,!1);for(const[t,r]of B(n))r.wt(s,o.at(t),!i([e,"access",t=>t.at,"call",i=>i(t),"optionalAccess",t=>t.ht,"call",t=>t(r)]));this.i.jt.write(n)})}};function J(t,i){return 0===t.length?i:0===i.length?t:[...t,...i]}function K(t,i){return i<=0?t:i>=t.length?[]:t.slice(i)}H.t=u.t;var L=class t extends w{constructor(t,i){super(t),this.o=y(()=>new H(this)),this.v=r.Signal.call(void 0,t=>g(this.Ft(t),({v:i})=>i.read(t))),this.V=r.Signal.call(void 0,t=>g(this.jt.read(t),({V:i})=>i.read(t))),this.m=r.Signal.call(void 0,t=>{const i=g(this.jt.read(t),({m:i})=>i.read(t));return i.every(c)?null:i}),this.A=r.Signal.call(void 0,t=>g(this.jt.read(t),({A:i})=>i.read(t))),this.C=r.Signal.call(void 0,t=>R(g(this.jt.read(t),({C:i})=>i.read(t)),T,s)),this.T=r.Signal.call(void 0,t=>g(this.jt.read(t),({T:i})=>i.read(t))),this.D=r.Signal.call(void 0,t=>R(g(this.jt.read(t),({D:i})=>i.read(t)),P,!1)),this.R=r.Signal.call(void 0,t=>g(this.jt.read(t),({R:i})=>i.read(t))),this.l=r.Signal.call(void 0,t=>{const i=g(this.jt.read(t),({l:i})=>i.read(t));return i.some(c)?null:i}),this.u=r.Signal.call(void 0,t=>g(this.jt.read(t),({u:i})=>i.read(t))),this.q=r.Signal.call(void 0,t=>R(g(this.jt.read(t),({q:i})=>i.read(t)),P,!1)),this.j=r.Signal.call(void 0,t=>g(this.jt.read(t),({j:i})=>i.read(t))),this.S=r.Signal.call(void 0,t=>R(g(this.jt.read(t),({S:i})=>i.read(t)),P,!1)),this.F=r.Signal.call(void 0,t=>g(this.jt.read(t),({F:i})=>i.read(t))),this.B=r.Signal.call(void 0,t=>R(g(this.jt.read(t),({B:i})=>i.read(t)),P,!1)),this.W=r.Signal.call(void 0,t=>g(this.jt.read(t),({W:i})=>i.read(t))),this.M=r.Signal.call(void 0,t=>{const i=this.jt.read(t),s=this.Ft(t);return R(J(g(i,({M:i,At:o},e)=>e>=s.length?o.read(t):i.read(t)),g(K(s,i.length),({At:i})=>i.read(t))),P,!1)}),this.P=r.Signal.call(void 0,t=>{const i=this.jt.read(t),s=this.Ft(t);return J(g(i,({P:i,gt:o},e)=>e>=s.length?o.read(t):i.read(t)),g(K(s,i.length),({gt:i})=>i.read(t)))}),this.At=r.Signal.call(void 0,t=>R(g(this.Ft(t),({At:i})=>i.read(t)),P,!1)),this.gt=r.Signal.call(void 0,t=>g(this.Ft(t),({gt:i})=>i.read(t)));const o=g(i,t=>t.h());this.Bt=r.Signal.call(void 0,{Wt:r.Signal.call(void 0,o)}),this.jt=r.Signal.call(void 0,r.untracked.call(void 0,t=>g(i,(i,s)=>{const e=this.rt(i);return e.wt(t,o.at(s),!0),e})))}nt(i){return new t(i,r.untracked.call(void 0,this.jt))}St(t){return g(this.jt.read(t),({o:t})=>t())}Ft(t){return this.Bt.read(t).Wt.read(t)}wt(t,s,o){if(s){const e=this.jt.read(t),n=s.Bt.read(t);this.Bt.write(n);for(const[s,r]of B(n.Wt.read(t)))i([e,"access",t=>t.at,"call",t=>t(s),"optionalAccess",t=>t.wt,"call",i=>i(t,r,o)])}}p(t,s){const o=m(s)?s(this.v.read(t),this.V.read(t)):s,e=this.jt.read(t),n=this.Bt.read(t),r=n.Wt.read(t),h=g((c=J(r,K(e,r.length)),(a=o.length)<=0?[]:a>=c.length?c:c.slice(0,a)),t=>t.h());var c,a;n.Wt.write(h);for(const[s,e]of B(o))b(e)||i([h,"access",t=>t.at,"call",t=>t(s),"optionalAccess",t=>t.p,"call",i=>i(t,e)]);for(const[s,o]of B(h))i([e,"access",t=>t.at,"call",t=>t(s),"optionalAccess",t=>t.wt,"call",i=>i(t,o,!1)])}O(t,i){const s=m(i)?i(this.V.read(t),this.v.read(t)):i;for(const[i,o]of B(this.jt.read(t))){const e=s.at(i);b(e)||o.O(t,e)}}I(t,i){const s=m(i)?i(this.A.read(t)):i;for(const[i,o]of B(this.jt.read(t))){const e=c(s)?s:s.at(i);b(e)||o.I(t,e)}}k(t,i){const s=m(i)?i(this.T.read(t)):i;for(const[i,o]of B(this.Ft(t))){const e=T(s)?s:s.at(i);b(e)||o.k(t,e)}for(const[i,o]of B(this.jt.read(t))){const e=T(s)?s:s.at(i);b(e)||o.k(t,e)}}G(t,i){const s=m(i)?i(this.R.read(t)):i;for(const[i,o]of B(this.jt.read(t))){const e=P(s)?s:s.at(i);b(e)||o.G(t,e)}}Z(t){for(const i of this.jt.read(t))i.Z(t)}H(t,i){b(i)||this.p(t,i);const s=this.Ft(t);for(const i of s)i.H(t,void 0);this.jt.write(g(s,t=>this.rt(t)))}ct(t){return g(this.jt.read(t),(t,i)=>({i:t,lt:t=>t.at(i)}))}};var N=class extends u{constructor(t){super(),this.i=t,this.enabled=t.Mt.o(),this.element=t.Pt.o()}getEnabledElement(t){return i([this,"access",t=>t.i,"access",t=>t.Dt,"call",i=>i(t),"optionalAccess",t=>t.o,"call",t=>t()])}};N.t=u.t;var Q=class t extends w{constructor(t,i,s){super(t),this.o=y(()=>new N(this)),this.v=r.Signal.call(void 0,t=>this.Rt(t,({v:t})=>t)),this.V=r.Signal.call(void 0,t=>this.Rt(t,({V:t})=>t)),this.m=r.Signal.call(void 0,t=>this.zt(t,({m:t})=>t,c,null)),this.A=r.Signal.call(void 0,t=>this.Rt(t,({A:t})=>t)),this.C=r.Signal.call(void 0,t=>this.zt(t,({C:t})=>t,T)),this.T=r.Signal.call(void 0,t=>this.Rt(t,({T:t})=>t)),this.D=r.Signal.call(void 0,t=>this.zt(t,({D:t})=>t,P)),this.R=r.Signal.call(void 0,t=>this.Rt(t,({R:t})=>t)),this.l=r.Signal.call(void 0,t=>{const i=this.Mt.l.read(t);if(!1===i)return;if(c(i))return null;const s=this.Pt.l.read(t);return c(s)?null:s}),this.u=r.Signal.call(void 0,t=>this.Rt(t,({u:t})=>t)),this.q=r.Signal.call(void 0,t=>this.zt(t,({q:t})=>t,P)),this.j=r.Signal.call(void 0,t=>this.Rt(t,({j:t})=>t)),this.S=r.Signal.call(void 0,t=>this.zt(t,({S:t})=>t,P)),this.F=r.Signal.call(void 0,t=>this.Rt(t,({F:t})=>t)),this.B=r.Signal.call(void 0,t=>this.zt(t,({B:t})=>t,P)),this.W=r.Signal.call(void 0,t=>this.Rt(t,({W:t})=>t)),this.M=r.Signal.call(void 0,t=>this.zt(t,({M:t})=>t,P)),this.P=r.Signal.call(void 0,t=>this.Rt(t,({P:t})=>t)),this.At=r.Signal.call(void 0,t=>this.zt(t,({At:t})=>t,P)),this.gt=r.Signal.call(void 0,t=>this.Rt(t,({gt:t})=>t)),this.Mt=this.rt(i),this.Pt=this.rt(s)}Gt(t){return a(this.Mt.l.read(t))}Dt(t){return this.Gt(t)?this.Pt:void 0}nt(i){return new t(i,this.Mt,this.Pt)}zt(t,i,s,o){const e=i(this.Mt).read(t),n=this.Dt(t);if(!n)return s(e)||b(o)?e:{enabled:e,element:o};const r=i(n).read(t);return R([e,r],s,e,{enabled:e,element:r})}Rt(t,i){return{enabled:i(this.Mt).read(t),element:i(this.Pt).read(t)}}p(t,i){const{enabled:s,element:o}=m(i)?i(this.v.read(t),this.V.read(t)):i;b(s)||this.Mt.p(t,s),b(o)||this.Pt.p(t,o)}wt(t,s,o){this.Mt.wt(t,i([s,"optionalAccess",t=>t.Mt]),o),this.Pt.wt(t,i([s,"optionalAccess",t=>t.Pt]),o)}O(t,i){const{enabled:s,element:o}=m(i)?i(this.V.read(t),this.v.read(t)):i;b(s)||this.Mt.O(t,s),b(o)||this.Pt.O(t,o)}I(t,i){const s=m(i)?i(this.A.read(t)):i,o=c(s)?s:s.enabled;b(o)||this.Mt.I(t,o);const e=c(s)?this.Gt(t)?s:void 0:s.element;b(e)||this.Pt.I(t,e)}k(t,i){const s=m(i)?i(this.T.read(t)):i,[o,e]=T(s)?[s,this.Gt(t)?s:void 0]:[s.enabled,s.element];b(o)||this.Mt.k(t,o),b(e)||this.Pt.k(t,e)}G(t,i){const s=m(i)?i(this.R.read(t)):i,[o,e]=P(s)?[s,this.Gt(t)?s:void 0]:[s.enabled,s.element];b(o)||this.Mt.G(t,o),b(e)||this.Pt.G(t,e)}Z(t){this.Mt.Z(t),this.Pt.Z(t)}H(t,i){b(i)||this.p(t,i),this.Mt.H(t,void 0),this.Pt.H(t,void 0)}ct(t){const i=this.Mt.l.read(t),s={i:this.Mt,lt:()=>i};return!0!==i?[s]:[s,{i:this.Pt,lt:t=>t}]}};var U=class extends u{constructor(t){super(),this.i=t,this.active=t.Ht.o(),this.branches=W(t.Jt,({o:t})=>t())}getActiveBranch(t){const i=this.i.Kt(t);if(i)return{kind:i.kind,value:i.value.o()}}};U.t=u.t;var X=class t extends w{constructor(t,i,s){super(t),this.o=y(()=>new U(this)),this.v=r.Signal.call(void 0,t=>this.Rt(t,({v:t})=>t)),this.V=r.Signal.call(void 0,t=>this.Rt(t,({V:t})=>t)),this.m=r.Signal.call(void 0,t=>this.zt(t,({m:t})=>t,c,null)),this.A=r.Signal.call(void 0,t=>this.Rt(t,({A:t})=>t)),this.C=r.Signal.call(void 0,t=>this.zt(t,({C:t})=>t,T)),this.T=r.Signal.call(void 0,t=>this.Rt(t,({T:t})=>t)),this.D=r.Signal.call(void 0,t=>this.zt(t,({D:t})=>t,P)),this.R=r.Signal.call(void 0,t=>this.Rt(t,({R:t})=>t)),this.l=r.Signal.call(void 0,t=>{const i=this.Kt(t);if(!i)return null;const s=i.value.l.read(t);return c(s)?null:{kind:i.kind,value:s}}),this.u=r.Signal.call(void 0,t=>this.Rt(t,({l:t})=>t)),this.q=r.Signal.call(void 0,t=>this.zt(t,({q:t})=>t,P)),this.j=r.Signal.call(void 0,t=>this.Rt(t,({j:t})=>t)),this.S=r.Signal.call(void 0,t=>this.zt(t,({S:t})=>t,P)),this.F=r.Signal.call(void 0,t=>this.Rt(t,({F:t})=>t)),this.B=r.Signal.call(void 0,t=>this.zt(t,({B:t})=>t,P)),this.W=r.Signal.call(void 0,t=>this.Rt(t,({W:t})=>t)),this.M=r.Signal.call(void 0,t=>this.zt(t,({M:t})=>t,P)),this.P=r.Signal.call(void 0,t=>this.Rt(t,({P:t})=>t)),this.At=r.Signal.call(void 0,t=>this.zt(t,({At:t})=>t,P)),this.gt=r.Signal.call(void 0,t=>this.Rt(t,({gt:t})=>t)),this.Ht=this.rt(i),this.Jt=W(s,t=>this.rt(t))}Kt(t){const i=this.Ht.l.read(t),s=c(i)?null:this.Jt[i];return s?{kind:i,value:s}:void 0}zt(t,i,s,o){const e=this.Kt(t),n=i(this.Ht).read(t);if(!e)return s(n)||b(o)?n:{active:n,branch:o};const r=i(e.value).read(t);return s(r)&&s(n)&&r===n?n:{active:n,branch:s(r)?r:{kind:e.kind,value:r}}}Rt(t,i){return{active:i(this.Ht).read(t),branches:W(this.Jt,s=>i(s).read(t))}}nt(i){return new t(i,this.Ht,this.Jt)}p(t,i){const s=y(()=>this.v.read(t)),o=y(()=>this.V.read(t)),{active:e,branches:n}=m(i)?i(s(),o()):i;b(e)||this.Ht.p(t,e);const r=m(n)?n(s().branches,o().branches):n;for(const[i,s]of B(this.Jt))_(r,i)&&!b(r[i])&&s.p(t,r[i])}wt(t,s,o){this.Ht.wt(t,i([s,"optionalAccess",t=>t.Ht]),o);for(const[e,n]of B(this.Jt))n.wt(t,i([s,"optionalAccess",t=>t.Jt,"access",t=>t[e]]),o)}O(t,i){const s=y(()=>this.v.read(t)),o=y(()=>this.V.read(t)),{active:e,branches:n}=m(i)?i(o(),s()):i;b(e)||this.Ht.O(t,e);const r=m(n)?n(o().branches,s().branches):n;for(const[i,s]of B(this.Jt))_(r,i)&&!b(r[i])&&s.O(t,r[i])}I(t,s){const o=y(()=>this.A.read(t)),e=m(s)?s(o()):s,[n,r,h]=c(e)?[e,e,void 0]:[e.active,_(e,"branch")?e.branch:void 0,_(e,"branches")?m(e.branches)?e.branches(o().branches):e.branches:void 0];b(n)||this.Ht.I(t,n);for(const[i,s]of B(this.Jt)){const o=c(h)?h:_(h,i)?h[i]:void 0;b(o)||s.I(t,o)}if(!b(r)){const s=this.Kt(t),o=m(r)?s?r({kind:s.kind,value:s.value.A.read(t)}):void 0:r;if(c(o))i([s,"optionalAccess",t=>t.value,"access",t=>t.I,"call",i=>i(t,o)]);else if(!b(o)){const{kind:i,value:s}=o,e=_(this.Jt,i)?this.Jt[i]:void 0;e&&e.I(t,s)}}}k(t,s){const o=y(()=>this.T.read(t)),e=m(s)?s(o()):s,[n,r,h]=T(e)?[e,e,void 0]:[e.active,_(e,"branch")?e.branch:void 0,_(e,"branches")?m(e.branches)?e.branches(o().branches):e.branches:void 0];b(n)||this.Ht.k(t,n);for(const[i,s]of B(this.Jt)){const o=T(h)?h:_(h,i)?h[i]:void 0;b(o)||s.k(t,o)}if(!b(r)){const s=this.Kt(t),o=m(r)?s?r({kind:s.kind,value:s.value.T.read(t)}):void 0:r;if(T(o))i([s,"optionalAccess",t=>t.value,"access",t=>t.k,"call",i=>i(t,o)]);else if(!b(o)){const{kind:i,value:s}=o,e=_(this.Jt,i)?this.Jt[i]:void 0;e&&e.k(t,s)}}}G(t,s){const o=y(()=>this.R.read(t)),e=m(s)?s(o()):s,[n,r,h]=P(e)?[e,e,void 0]:[e.active,_(e,"branch")?e.branch:void 0,_(e,"branches")?m(e.branches)?e.branches(o().branches):e.branches:void 0];b(n)||this.Ht.G(t,n);for(const[i,s]of B(this.Jt)){const o=P(h)?h:_(h,i)?h[i]:void 0;b(o)||s.G(t,o)}if(!b(r)){const s=this.Kt(t),o=m(r)?s?r({kind:s.kind,value:s.value.R.read(t)}):void 0:r;if(P(o))i([s,"optionalAccess",t=>t.value,"access",t=>t.G,"call",i=>i(t,o)]);else if(!b(o)){const{kind:i,value:s}=o,e=_(this.Jt,i)?this.Jt[i]:void 0;e&&e.G(t,s)}}}Z(t){this.Ht.Z(t),i([this,"access",t=>t.Kt,"call",i=>i(t),"optionalAccess",t=>t.value,"access",t=>t.Z,"call",i=>i(t)])}H(t,i){b(i)||this.p(t,i),this.Ht.H(t,void 0);for(const i of D(this.Jt))i.H(t,void 0)}ct(t){const i={i:this.Ht,lt:t=>t.kind},s=this.Kt(t);return s?[i,{i:s.value,lt:t=>t.value}]:[i]}};exports.FormList=function(t,{input:i,initial:s,touched:o,validateOn:e,error:n}={}){const h=new L(null,g(t,H.t));return r.batch.call(void 0,t=>{b(i)||h.O(t,i),b(s)||h.p(t,s),b(o)||h.G(t,o),b(e)||h.k(t,e),b(n)||h.I(t,n)}),h.o()},exports.FormOptional=function(t,i,{input:s,initial:o,touched:e,validateOn:n,error:h}={}){const c=new Q(null,N.t(t),N.t(i));return r.batch.call(void 0,t=>{b(e)||c.G(t,e),b(o)||c.p(t,o),b(s)||c.O(t,s),b(n)||c.k(t,n),b(h)||c.I(t,h)}),c.o()},exports.FormShape=function(t,{input:i,initial:s,touched:o,validateOn:e,error:n}={}){const[h,c]=function(t,i){const s={},o={};for(const[e,n]of B(t))i(n,e)?s[e]=n:o[e]=n;return[s,o]}(t,v),a=new z(null,W(h,M.t),W(c,t=>r.Signal.call(void 0,t)));return r.batch.call(void 0,t=>{b(i)||a.O(t,i),b(s)||a.p(t,s),b(o)||a.G(t,o),b(e)||a.k(t,e),b(n)||a.I(t,n)}),a.o()},exports.FormSwitch=function(t,i,{input:s,initial:o,touched:e,validateOn:n,error:h}={}){const c=new X(null,U.t(t),W(i,t=>U.t(t)));return r.batch.call(void 0,t=>{b(e)||c.G(t,e),b(o)||c.p(t,o),b(s)||c.O(t,s),b(n)||c.k(t,n),b(h)||c.I(t,h)}),c.o()},exports.FormUnit=function(o,e){const h=t(i([e,"optionalAccess",t=>t.isInputEqual]),()=>f),a=t(i([e,"optionalAccess",t=>t.isInputDirty]),()=>(t,i)=>!h(t,i)),l=t(i([e,"optionalAccess",t=>t.initial]),()=>o),d=r.Signal.call(void 0,o,{equals:h}),u=r.Signal.call(void 0,{It:r.Signal.call(void 0,!b(i([e,"optionalAccess",t=>t.initial]))),it:r.Signal.call(void 0,h(l,o)?o:l,{equals:h})}),v=r.Signal.call(void 0,t(i([e,"optionalAccess",t=>t.touched]),()=>!1));if(_(e,"schema")){const i=(O=e.schema,{ut:!1,vt:t=>q(O,t)}),o=V(c,p),n=V(c,t(e.isOutputEqual,()=>f));return new F(null,u,d,r.Signal.call(void 0,t(e.error,()=>null),{equals:o}),r.Signal.call(void 0,t(e.validateOn,()=>s)),v,r.Signal.call(void 0,i),a,h,n,o).o()}var O;const m=V(c,t(i([e,"optionalAccess",t=>t.isErrorEqual]),()=>f)),y=r.Signal.call(void 0,t(i([e,"optionalAccess",t=>t.error]),()=>null),{equals:m});if(_(e,"validate")){const i={ut:!1,vt:e.validate},o=V(c,t(e.isOutputEqual,()=>f));return new F(null,u,d,y,r.Signal.call(void 0,t(e.validateOn,()=>s)),v,r.Signal.call(void 0,i),a,h,o,m).o()}if(_(e,"transform")){const i=S(e.transform),s=V(c,t(e.isOutputEqual,()=>f));return new F(null,u,d,y,r.Signal.call(void 0,n),v,r.Signal.call(void 0,i),a,h,s,m).o()}return new F(null,u,d,y,r.Signal.call(void 0,n),v,r.Signal.call(void 0,j),a,h,V(c,h),m).o()},exports.VALIDATE_ON_CHANGE=o,exports.VALIDATE_ON_INIT=n,exports.VALIDATE_ON_SUBMIT=e,exports.VALIDATE_ON_TOUCH=s,exports.isFormList=function(t){return t instanceof H},exports.isFormOptional=function(t){return t instanceof N},exports.isFormShape=function(t){return t instanceof M},exports.isFormSwitch=function(t){return t instanceof U},exports.isFormUnit=function(t){return t instanceof C},exports.isSignalForm=v;//# sourceMappingURL=index.cjs.map
1
+ "use strict";function t(t,i){return null!=t?t:i()}function i(t){let i,s=t[0],o=1;for(;o<t.length;){const n=t[o],e=t[o+1];if(o+=2,("optionalAccess"===n||"optionalCall"===n)&&null==s)return;"access"===n||"optionalAccess"===n?(i=s,s=e(s)):"call"!==n&&"optionalCall"!==n||(s=e((...t)=>s.call(i,...t)),i=void 0)}return s}Object.defineProperty(exports,"__esModule",{value:!0});var s="onTouch",o="onChange",n="onSubmit",e="onInit",r=require("@owanturist/signal");function h(t){return null!=t}function c(t){return null===t}function u(t){return!0===t}function d(t){return Boolean(t)}function a(t,i,s,o,n){const e=i.read(t);return o?o(e,s.read(t)):null!=n?n(e):e}var l=class{static t({i:t}){return t}clone(){return this.i.h().o()}getOutput(t,i){const{l:s,u:o}=this.i;return a(t,s,o,i)}getInitial(t){return this.i.m.read(t)}setInitial(t){r.batch.call(void 0,i=>{this.i.S(i,t)})}getInput(t){return this.i.p.read(t)}setInput(t){r.batch.call(void 0,i=>{this.i.v(i,t)})}getError(t,i){const{F:s,V:o}=this.i;return a(t,s,o,i)}setError(t){r.batch.call(void 0,i=>{this.i.U(i,t)})}getValidateOn(t,i){const{O:s,I:o}=this.i;return a(t,s,o,i)}setValidateOn(t){r.batch.call(void 0,i=>{this.i.T(i,t)})}isValid(t,i){const{N:s,C:o}=this.i;return a(t,s,o,i,u)}isInvalid(t,i){const{L:s,B:o}=this.i;return a(t,s,o,i,d)}isValidated(t,i){const{A:s,q:o}=this.i;return a(t,s,o,i,u)}isDirty(t,i){const{P:s,k:o}=this.i;return a(t,s,o,i,d)}isTouched(t,i){const{D:s,G:o}=this.i;return a(t,s,o,i,d)}setTouched(t){r.batch.call(void 0,i=>{this.i.j(i,t)})}reset(t){r.batch.call(void 0,i=>{this.i.H(i,t)})}onFocusWhenInvalid(t){return this.i.W.M(t)}focusFirstInvalid(){r.batch.call(void 0,t=>{i([this,"access",t=>t.i,"access",t=>t.R,"call",i=>i(t),"optionalCall",t=>t()])})}getSubmitCount(t){return this.i.K.J.read(t)}isSubmitting(t){return this.i.K.X.read(t)>0}onSubmit(t){return this.i.Y.M(t)}async submit(){r.batch.call(void 0,t=>{this.i.K.J.write(t=>t+1),this.i.K.Z(t)});const t=r.untracked.call(void 0,t=>{const i=this.i.K.l.read(t);if(!c(i))return this.i.K.tt(t,i).filter(h)});t?t.length>0&&(this.i.K.X.write(t=>t+1),await Promise.all(t),this.i.K.X.write(t=>Math.max(0,t-1))):r.batch.call(void 0,t=>{i([this,"access",t=>t.i,"access",t=>t.K,"access",t=>t.R,"call",i=>i(t),"optionalCall",t=>t()])})}};function v(t,i){return"object"==typeof t&&null!=t&&i in t}function _(t,i){return Object.is(t,i)}function f(t,i){return!!_(t,i)||t.length===i.length&&t.every((t,s)=>_(t,i[s]))}function p(t){return void 0===t}function b(t,i){return i===_||i===Object.is?_:(s,o)=>t(s)||t(o)?s===o:i(s,o)}function V(t){return t}function O(t){return"function"==typeof t}function m(i){let s=null;return()=>(t(s,()=>s={it:i()}),s.it)}function y(t,...i){return O(t)?t(...i):t}var{isArray:x}=Array;function g(t,i){return(x(t)?t:Array.from(t)).map((t,s)=>i(t,s))}var w=class{constructor(){this.st=[]}M(t){return this.st.push(t),()=>{this.st.splice(this.st.indexOf(t),1)}}nt(t){return g(new Set(this.st),i=>i(t))}et(){return 0===this.st.length}},I=class{constructor(s){this.W=new w,this.Y=new w,this.J=r.Signal.call(void 0,0),this.X=r.Signal.call(void 0,0),this.K=t(i([s,"optionalAccess",t=>t.K]),()=>this)}h(){return this.rt(null)}ot(t){return this.K===t.K?t:t.rt(this)}ht(t){return this.K===t.K}R(t){for(const{i:i}of this.lt(t)){const s=i.R(t);if(s)return s}const i=this.W.et()?null:this.F.read(t);return c(i)?null:()=>{this.W.nt(i)}}tt(t,i){const s=this.lt(t).flatMap(({i:s,ut:o})=>s.tt(t,o(i)));return[...this.Y.nt(i),...s]}},A=class extends l{constructor(t){super(),this.i=t}setTransform(t){this.i.ct(t)}};function C(t){return"object"==typeof t&&h(t)}function E(t){return"string"==typeof t}function T(i){if(!C(i))return[];const s=t(i.errors,()=>i.issues);return x(s)?g(s.filter(C),({message:t})=>t).filter(E):i instanceof Error?[i.message]:[]}function k(t,i){if("safeParse"in t)return(s=t.safeParse(i)).success?[null,s.data]:[g(v(s.error,"errors")?s.error.errors:s.error.issues,({message:t})=>t),null];var s;try{return[null,t.parse(i)]}catch(t){return[T(t),null]}}var q={dt:!0,ft:t=>[null,t]};function j(t){return{dt:!0,ft:i=>[null,t(i)]}}var S=class t extends I{constructor(t,i,h,u,d,a,l,v,_,f,p){super(t),this.m=i,this.p=h,this.St=u,this.O=d,this.D=a,this._t=l,this.gt=v,this.vt=_,this.Ft=f,this.bt=p,this.o=m(()=>new A(this)),this.Vt=r.Signal.call(void 0,!0);const b=r.Signal.call(void 0,t=>{const i=u.read(t);if(!c(i))return[i,null];const s=h.read(t),o=l.read(t),[n,e]=o.ft(s);return c(e)?[V.read(t)?n:null,null]:[null,e]});this.F=this.V=r.Signal.call(void 0,t=>{const[i]=b.read(t);return i},{equals:f}),this.l=this.u=r.Signal.call(void 0,t=>{const[,i]=b.read(t);return i},{equals:_}),this.G=a,this.P=this.k=r.Signal.call(void 0,t=>v(this.m.read(t),h.read(t))),this.I=d,this.N=this.C=r.Signal.call(void 0,t=>!c(this.l.read(t))),this.L=this.B=r.Signal.call(void 0,t=>!c(this.F.read(t)));const V=r.Signal.call(void 0,!1);this.A=this.q=r.Signal.call(void 0,t=>V.read(t)||this.L.read(t),(t,i)=>{V.write(()=>{if(t||l.read(i).dt)return!0;switch(d.read(i)){case e:return!0;case s:return a.read(i);case o:return this.P.read(i);case n:return!1}})}),this.A.write(!1)}rt(i){return new t(i,this.m.clone(),this.p.clone(),this.St.clone(),this.O.clone(),this.D.clone(),this._t.clone(),this.gt,this.vt,this.Ft,this.bt)}S(t,i){this.m.write(s=>O(i)?i(s,this.p.read(t)):i),this.bt=!0,this.A.write(V)}Ut(t,i){this.bt||(this.m.write(i),this.A.write(V))}v(t,i){this.p.write(s=>O(i)?i(s,this.m.read(t)):i),this.A.write(V)}U(t,i){this.St.write(t=>y(i,t))}T(t,i){const s=this.O.read(t);this.O.write(y(i,s));s!==this.O.read(t)&&this.A.write(!1)}j(t,i){this.D.write(t=>y(i,t)),this.A.write(V)}Z(){this.A.write(!0)}H(t,i){const s=p(i)?this.m.read(t):O(i)?i(this.m.read(t),this.p.read(t)):i;p(i)||(this.bt=!0),this.m.write(s),this.p.write(s),this.D.write(!1),this.St.write(null),this.A.write(!1)}lt(){return[]}ct(t){r.batch.call(void 0,()=>{this._t.write(j(t)),this.A.write(V)})}};function F(t){return Array.isArray(t)?t.entries():Object.entries(t)}function B(t,i){const s={};for(const[o,n]of F(t))s[o]=i(n,o);return s}var W=class extends l{constructor(t){super(),this.i=t,this.fields=B(t.yt,({o:t})=>t())}};function M(t){return"boolean"==typeof t}W.t=l.t;var{values:P}=Object;function D(i,s,o,n){const e=t(i.find(s),()=>o);for(const s of i)if(s!==e)return t(n,()=>i);return e}var R=class t extends I{constructor(t,i){super(t),this.o=m(()=>new W(this)),this.m=r.Signal.call(void 0,t=>B(this.yt,({m:i})=>i.read(t))),this.p=r.Signal.call(void 0,t=>B(this.yt,({p:i})=>i.read(t))),this.F=r.Signal.call(void 0,t=>{const i=B(this.yt,({F:i})=>i.read(t));return P(i).every(c)?null:i}),this.V=r.Signal.call(void 0,t=>B(this.yt,({V:i})=>i.read(t))),this.O=r.Signal.call(void 0,t=>{const i=B(this.yt,({O:i})=>i.read(t));return D(P(i),E,s,i)}),this.I=r.Signal.call(void 0,t=>B(this.yt,({I:i})=>i.read(t))),this.D=r.Signal.call(void 0,t=>{const i=B(this.yt,({D:i})=>i.read(t));return D(P(i),M,!1,i)}),this.G=r.Signal.call(void 0,t=>B(this.yt,({G:i})=>i.read(t))),this.l=r.Signal.call(void 0,t=>{const i=B(this.yt,({l:i})=>i.read(t));return P(i).some(c)?null:i}),this.u=r.Signal.call(void 0,t=>B(this.yt,({u:i})=>i.read(t))),this.N=r.Signal.call(void 0,t=>{const i=B(this.yt,({N:i})=>i.read(t));return D(P(i),M,!1,i)}),this.C=r.Signal.call(void 0,t=>B(this.yt,({C:i})=>i.read(t))),this.L=r.Signal.call(void 0,t=>{const i=B(this.yt,({L:i})=>i.read(t));return D(P(i),M,!1,i)}),this.B=r.Signal.call(void 0,t=>B(this.yt,({B:i})=>i.read(t))),this.A=r.Signal.call(void 0,t=>{const i=B(this.yt,({A:i})=>i.read(t));return D(P(i),M,!1,i)}),this.q=r.Signal.call(void 0,t=>B(this.yt,({q:i})=>i.read(t))),this.P=r.Signal.call(void 0,t=>{const i=B(this.yt,({P:i})=>i.read(t));return D(P(i),M,!1,i)}),this.k=r.Signal.call(void 0,t=>B(this.yt,({k:i})=>i.read(t))),this.Vt=r.Signal.call(void 0,t=>B(this.yt,({Vt:i})=>i.read(t))),this.yt=B(i,t=>this.ot(t))}rt(i){return new t(i,this.yt)}S(t,i){const s=O(i)?i(this.m.read(t),this.p.read(t)):i;for(const[i,o]of F(this.yt))v(s,i)&&!p(s[i])&&o.S(t,s[i])}Ut(t,i){for(const[s,o]of F(this.yt))o.Ut(t,i[s])}v(t,i){const s=O(i)?i(this.p.read(t),this.m.read(t)):i;for(const[i,o]of F(this.yt))v(s,i)&&!p(s[i])&&o.v(t,s[i])}U(t,i){const s=O(i)?i(this.V.read(t)):i;for(const[i,o]of F(this.yt))c(s)?o.U(t,s):v(s,i)&&!p(s[i])&&o.U(t,s[i])}T(t,i){const s=O(i)?i(this.I.read(t)):i;for(const[i,o]of F(this.yt))E(s)?o.T(t,s):v(s,i)&&!p(s[i])&&o.T(t,s[i])}j(t,i){const s=O(i)?i(this.G.read(t)):i;for(const[i,o]of F(this.yt))M(s)?o.j(t,s):v(s,i)&&!p(s[i])&&o.j(t,s[i])}Z(t){for(const i of P(this.yt))i.Z(t)}H(t,i){p(i)||this.S(t,i);for(const i of P(this.yt))i.H(t,void 0)}lt(){return g(F(this.yt),([t,i])=>({i:i,ut:i=>i[t]}))}};function z(...t){return t}z.Ot=t=>t,z.wt=(t,i)=>i,z.Et=(t,i,s)=>s;var G=class extends l{constructor(t){super(),this.i=t,this.It=r.Signal.call(void 0,t=>this.i.Tt(t),{equals:f})}getElements(t,i=z.Ot){return i(this.It.read(t))}setElements(t){r.batch.call(void 0,i=>{const s=this.getInitial(i),o=g(O(t)?t(this.i.Tt(i),i):t,l.t);for(const[t,n]of F(o))t<s.length&&(n.ht(this.i)?n.S(i,s[t]):n.Ut(i,s[t]));this.i.It.write(g(o,t=>this.i.ot(t)))})}};function H(t,i){return 0===t.length?i:0===i.length?t:[...t,...i]}function J(t,i){return i<=0?t:i>=t.length?[]:t.slice(i)}function K(t,i){return i<=0?[]:i>=t.length?t:t.slice(0,i)}G.t=l.t;var L=class t extends I{constructor(t,i,o,n=[]){super(t),this.Nt=i,this.Ct=o,this.o=m(()=>new G(this)),this.m=r.Signal.call(void 0,t=>{const i=this.It.read(t);return g(this.Ct.read(t),(s,o)=>{const n=i.at(o);return n?n.m.read(t):s})}),this.p=r.Signal.call(void 0,t=>g(this.It.read(t),({p:i})=>i.read(t))),this.F=r.Signal.call(void 0,t=>{const i=g(this.It.read(t),({F:i})=>i.read(t));return i.every(c)?null:i}),this.V=r.Signal.call(void 0,t=>g(this.It.read(t),({V:i})=>i.read(t))),this.O=r.Signal.call(void 0,t=>D(g(this.It.read(t),({O:i})=>i.read(t)),E,s)),this.I=r.Signal.call(void 0,t=>g(this.It.read(t),({I:i})=>i.read(t))),this.D=r.Signal.call(void 0,t=>D(g(this.It.read(t),({D:i})=>i.read(t)),M,!1)),this.G=r.Signal.call(void 0,t=>g(this.It.read(t),({G:i})=>i.read(t))),this.l=r.Signal.call(void 0,t=>{const i=g(this.It.read(t),({l:i})=>i.read(t));return i.some(c)?null:i}),this.u=r.Signal.call(void 0,t=>g(this.It.read(t),({u:i})=>i.read(t))),this.N=r.Signal.call(void 0,t=>D(g(this.It.read(t),({N:i})=>i.read(t)),M,!1)),this.C=r.Signal.call(void 0,t=>g(this.It.read(t),({C:i})=>i.read(t))),this.L=r.Signal.call(void 0,t=>D(g(this.It.read(t),({L:i})=>i.read(t)),M,!1)),this.B=r.Signal.call(void 0,t=>g(this.It.read(t),({B:i})=>i.read(t))),this.A=r.Signal.call(void 0,t=>D(g(this.It.read(t),({A:i})=>i.read(t)),M,!1)),this.q=r.Signal.call(void 0,t=>g(this.It.read(t),({q:i})=>i.read(t))),this.P=r.Signal.call(void 0,t=>{const i=this.It.read(t),s=this.Ct.read(t);return D(H(g(i,({P:i},o)=>o>=s.length||i.read(t)),g(J(s,i.length),()=>!0)),M,!1)}),this.k=r.Signal.call(void 0,t=>{const i=this.It.read(t),s=this.Ct.read(t);return H(g(i,({k:i,Vt:o},n)=>n>=s.length?o.read(t):i.read(t)),g(J(s,i.length),(s,o)=>this.Nt(s,i.length+o).Vt.read(t)))}),this.Vt=r.Signal.call(void 0,t=>{const i=this.It.read(t),s=this.Ct.read(t);return H(g(i,({Vt:i})=>i.read(t)),g(J(s,i.length),(s,o)=>this.Nt(s,i.length+o).Vt.read(t)))}),this.It=r.Signal.call(void 0,g(n,t=>this.ot(t)))}rt(i){return new t(i,this.Nt,this.Ct.clone(),r.untracked.call(void 0,this.It))}Tt(t){return g(this.It.read(t),({o:t})=>t())}S(t,i){const s=O(i)?i(this.m.read(t),this.p.read(t)):i,o=K(this.It.read(t),s.length);for(const[i,n]of F(o))n.S(t,s[i]);this.Ct.write(s)}Ut(t,i){const s=K(this.It.read(t),i.length);for(const[o,n]of F(s))n.Ut(t,i[o]);this.Ct.write(s.map(i=>i.m.read(t)))}v(t,i){const s=this.m.read(t),o=O(i)?i(this.p.read(t),s):i,n=K(this.It.read(t),o.length);for(const[i,s]of F(n))s.v(t,o[i]);const e=J(o,n.length).map((i,o)=>{const e=n.length+o,r=this.Nt(i,e);return e<s.length&&r.Ut(t,s[e]),this.ot(r)});this.It.write(H(n,e))}U(t,i){const s=O(i)?i(this.V.read(t)):i;for(const[i,o]of F(this.It.read(t))){const n=c(s)?s:s.at(i);p(n)||o.U(t,n)}}T(t,i){const s=O(i)?i(this.I.read(t)):i;for(const[i,o]of F(this.It.read(t))){const n=E(s)?s:s.at(i);p(n)||o.T(t,n)}}j(t,i){const s=O(i)?i(this.G.read(t)):i;for(const[i,o]of F(this.It.read(t))){const n=M(s)?s:s.at(i);p(n)||o.j(t,n)}}Z(t){for(const i of this.It.read(t))i.Z(t)}H(t,i){p(i)||this.S(t,i),this.v(t,this.m.read(t));for(const i of this.It.read(t))i.H(t,void 0)}lt(t){return g(this.It.read(t),(t,i)=>({i:t,ut:t=>t.at(i)}))}};var N=class extends l{constructor(t){super(),this.i=t,this.enabled=t.Lt.o(),this.element=t.Bt.o()}getEnabledElement(t){return i([this,"access",t=>t.i,"access",t=>t.At,"call",i=>i(t),"optionalAccess",t=>t.o,"call",t=>t()])}};N.t=l.t;var Q=class t extends I{constructor(t,i,s){super(t),this.o=m(()=>new N(this)),this.m=r.Signal.call(void 0,t=>this.qt(t,({m:t})=>t)),this.p=r.Signal.call(void 0,t=>this.qt(t,({p:t})=>t)),this.F=r.Signal.call(void 0,t=>this.Pt(t,({F:t})=>t,c,null)),this.V=r.Signal.call(void 0,t=>this.qt(t,({V:t})=>t)),this.O=r.Signal.call(void 0,t=>this.Pt(t,({O:t})=>t,E)),this.I=r.Signal.call(void 0,t=>this.qt(t,({I:t})=>t)),this.D=r.Signal.call(void 0,t=>this.Pt(t,({D:t})=>t,M)),this.G=r.Signal.call(void 0,t=>this.qt(t,({G:t})=>t)),this.l=r.Signal.call(void 0,t=>{const i=this.Lt.l.read(t);if(!1===i)return;if(c(i))return null;const s=this.Bt.l.read(t);return c(s)?null:s}),this.u=r.Signal.call(void 0,t=>this.qt(t,({u:t})=>t)),this.N=r.Signal.call(void 0,t=>this.Pt(t,({N:t})=>t,M)),this.C=r.Signal.call(void 0,t=>this.qt(t,({C:t})=>t)),this.L=r.Signal.call(void 0,t=>this.Pt(t,({L:t})=>t,M)),this.B=r.Signal.call(void 0,t=>this.qt(t,({B:t})=>t)),this.A=r.Signal.call(void 0,t=>this.Pt(t,({A:t})=>t,M)),this.q=r.Signal.call(void 0,t=>this.qt(t,({q:t})=>t)),this.P=r.Signal.call(void 0,t=>this.Pt(t,({P:t})=>t,M)),this.k=r.Signal.call(void 0,t=>this.qt(t,({k:t})=>t)),this.Vt=r.Signal.call(void 0,t=>this.qt(t,({Vt:t})=>t)),this.Lt=this.ot(i),this.Bt=this.ot(s)}kt(t){return u(this.Lt.l.read(t))}At(t){return this.kt(t)?this.Bt:void 0}rt(i){return new t(i,this.Lt,this.Bt)}Pt(t,i,s,o){const n=i(this.Lt).read(t),e=this.At(t);if(!e)return s(n)||p(o)?n:{enabled:n,element:o};const r=i(e).read(t);return D([n,r],s,n,{enabled:n,element:r})}qt(t,i){return{enabled:i(this.Lt).read(t),element:i(this.Bt).read(t)}}S(t,i){const{enabled:s,element:o}=O(i)?i(this.m.read(t),this.p.read(t)):i;p(s)||this.Lt.S(t,s),p(o)||this.Bt.S(t,o)}Ut(t,i){this.Lt.Ut(t,i.enabled),this.Bt.Ut(t,i.element)}v(t,i){const{enabled:s,element:o}=O(i)?i(this.p.read(t),this.m.read(t)):i;p(s)||this.Lt.v(t,s),p(o)||this.Bt.v(t,o)}U(t,i){const s=O(i)?i(this.V.read(t)):i,o=c(s)?s:s.enabled;p(o)||this.Lt.U(t,o);const n=c(s)?this.kt(t)?s:void 0:s.element;p(n)||this.Bt.U(t,n)}T(t,i){const s=O(i)?i(this.I.read(t)):i,[o,n]=E(s)?[s,this.kt(t)?s:void 0]:[s.enabled,s.element];p(o)||this.Lt.T(t,o),p(n)||this.Bt.T(t,n)}j(t,i){const s=O(i)?i(this.G.read(t)):i,[o,n]=M(s)?[s,this.kt(t)?s:void 0]:[s.enabled,s.element];p(o)||this.Lt.j(t,o),p(n)||this.Bt.j(t,n)}Z(t){this.Lt.Z(t),this.Bt.Z(t)}H(t,i){p(i)||this.S(t,i),this.Lt.H(t,void 0),this.Bt.H(t,void 0)}lt(t){const i=this.Lt.l.read(t),s={i:this.Lt,ut:()=>i};return!0!==i?[s]:[s,{i:this.Bt,ut:t=>t}]}};var U=class extends l{constructor(t){super(),this.i=t,this.active=t.zt.o(),this.branches=B(t.Dt,({o:t})=>t())}getActiveBranch(t){const i=this.i.xt(t);if(i)return{kind:i.kind,value:i.value.o()}}};U.t=l.t;var X=class t extends I{constructor(t,i,s){super(t),this.o=m(()=>new U(this)),this.m=r.Signal.call(void 0,t=>this.qt(t,({m:t})=>t)),this.p=r.Signal.call(void 0,t=>this.qt(t,({p:t})=>t)),this.F=r.Signal.call(void 0,t=>this.Pt(t,({F:t})=>t,c,null)),this.V=r.Signal.call(void 0,t=>this.qt(t,({V:t})=>t)),this.O=r.Signal.call(void 0,t=>this.Pt(t,({O:t})=>t,E)),this.I=r.Signal.call(void 0,t=>this.qt(t,({I:t})=>t)),this.D=r.Signal.call(void 0,t=>this.Pt(t,({D:t})=>t,M)),this.G=r.Signal.call(void 0,t=>this.qt(t,({G:t})=>t)),this.l=r.Signal.call(void 0,t=>{const i=this.xt(t);if(!i)return null;const s=i.value.l.read(t);return c(s)?null:{kind:i.kind,value:s}}),this.u=r.Signal.call(void 0,t=>this.qt(t,({u:t})=>t)),this.N=r.Signal.call(void 0,t=>this.Pt(t,({N:t})=>t,M)),this.C=r.Signal.call(void 0,t=>this.qt(t,({C:t})=>t)),this.L=r.Signal.call(void 0,t=>this.Pt(t,({L:t})=>t,M)),this.B=r.Signal.call(void 0,t=>this.qt(t,({B:t})=>t)),this.A=r.Signal.call(void 0,t=>this.Pt(t,({A:t})=>t,M)),this.q=r.Signal.call(void 0,t=>this.qt(t,({q:t})=>t)),this.P=r.Signal.call(void 0,t=>this.Pt(t,({P:t})=>t,M)),this.k=r.Signal.call(void 0,t=>this.qt(t,({k:t})=>t)),this.Vt=r.Signal.call(void 0,t=>this.qt(t,({Vt:t})=>t)),this.zt=this.ot(i),this.Dt=B(s,t=>this.ot(t))}xt(t){const i=this.zt.l.read(t),s=c(i)?null:this.Dt[i];return s?{kind:i,value:s}:void 0}Pt(t,i,s,o){const n=this.xt(t),e=i(this.zt).read(t);if(!n)return s(e)||p(o)?e:{active:e,branch:o};const r=i(n.value).read(t);return s(r)&&s(e)&&r===e?e:{active:e,branch:s(r)?r:{kind:n.kind,value:r}}}qt(t,i){return{active:i(this.zt).read(t),branches:B(this.Dt,s=>i(s).read(t))}}rt(i){return new t(i,this.zt,this.Dt)}S(t,i){const s=m(()=>this.m.read(t)),o=m(()=>this.p.read(t)),{active:n,branches:e}=O(i)?i(s(),o()):i;p(n)||this.zt.S(t,n);const r=O(e)?e(s().branches,o().branches):e;for(const[i,s]of F(this.Dt))v(r,i)&&!p(r[i])&&s.S(t,r[i])}Ut(t,i){this.zt.Ut(t,i.active);for(const[s,o]of F(this.Dt))o.Ut(t,i.branches[s])}v(t,i){const s=m(()=>this.m.read(t)),o=m(()=>this.p.read(t)),{active:n,branches:e}=O(i)?i(o(),s()):i;p(n)||this.zt.v(t,n);const r=O(e)?e(o().branches,s().branches):e;for(const[i,s]of F(this.Dt))v(r,i)&&!p(r[i])&&s.v(t,r[i])}U(t,s){const o=m(()=>this.V.read(t)),n=O(s)?s(o()):s,[e,r,h]=c(n)?[n,n,void 0]:[n.active,v(n,"branch")?n.branch:void 0,v(n,"branches")?O(n.branches)?n.branches(o().branches):n.branches:void 0];p(e)||this.zt.U(t,e);for(const[i,s]of F(this.Dt)){const o=c(h)?h:v(h,i)?h[i]:void 0;p(o)||s.U(t,o)}if(!p(r)){const s=this.xt(t),o=O(r)?s?r({kind:s.kind,value:s.value.V.read(t)}):void 0:r;if(c(o))i([s,"optionalAccess",t=>t.value,"access",t=>t.U,"call",i=>i(t,o)]);else if(!p(o)){const{kind:i,value:s}=o,n=v(this.Dt,i)?this.Dt[i]:void 0;n&&n.U(t,s)}}}T(t,s){const o=m(()=>this.I.read(t)),n=O(s)?s(o()):s,[e,r,h]=E(n)?[n,n,void 0]:[n.active,v(n,"branch")?n.branch:void 0,v(n,"branches")?O(n.branches)?n.branches(o().branches):n.branches:void 0];p(e)||this.zt.T(t,e);for(const[i,s]of F(this.Dt)){const o=E(h)?h:v(h,i)?h[i]:void 0;p(o)||s.T(t,o)}if(!p(r)){const s=this.xt(t),o=O(r)?s?r({kind:s.kind,value:s.value.I.read(t)}):void 0:r;if(E(o))i([s,"optionalAccess",t=>t.value,"access",t=>t.T,"call",i=>i(t,o)]);else if(!p(o)){const{kind:i,value:s}=o,n=v(this.Dt,i)?this.Dt[i]:void 0;n&&n.T(t,s)}}}j(t,s){const o=m(()=>this.G.read(t)),n=O(s)?s(o()):s,[e,r,h]=M(n)?[n,n,void 0]:[n.active,v(n,"branch")?n.branch:void 0,v(n,"branches")?O(n.branches)?n.branches(o().branches):n.branches:void 0];p(e)||this.zt.j(t,e);for(const[i,s]of F(this.Dt)){const o=M(h)?h:v(h,i)?h[i]:void 0;p(o)||s.j(t,o)}if(!p(r)){const s=this.xt(t),o=O(r)?s?r({kind:s.kind,value:s.value.G.read(t)}):void 0:r;if(M(o))i([s,"optionalAccess",t=>t.value,"access",t=>t.j,"call",i=>i(t,o)]);else if(!p(o)){const{kind:i,value:s}=o,n=v(this.Dt,i)?this.Dt[i]:void 0;n&&n.j(t,s)}}}Z(t){this.zt.Z(t),i([this,"access",t=>t.xt,"call",i=>i(t),"optionalAccess",t=>t.value,"access",t=>t.Z,"call",i=>i(t)])}H(t,i){p(i)||this.S(t,i),this.zt.H(t,void 0);for(const i of P(this.Dt))i.H(t,void 0)}lt(t){const i={i:this.zt,ut:t=>t.kind},s=this.xt(t);return s?[i,{i:s.value,ut:t=>t.value}]:[i]}};exports.FormList=function(i,{input:s,initial:o,touched:n,validateOn:e,error:h}={}){const c=new L(null,(t,s)=>G.t(i(t,s)),r.Signal.call(void 0,[],{equals:f}));return r.batch.call(void 0,i=>{const r=t(s,()=>o);p(r)||c.v(i,r),p(o)||c.S(i,o),p(n)||c.j(i,n),p(e)||c.T(i,e),p(h)||c.U(i,h)}),c.o()},exports.FormOptional=function(t,i,{input:s,initial:o,touched:n,validateOn:e,error:h}={}){const c=new Q(null,N.t(t),N.t(i));return r.batch.call(void 0,t=>{p(n)||c.j(t,n),p(o)||c.S(t,o),p(s)||c.v(t,s),p(e)||c.T(t,e),p(h)||c.U(t,h)}),c.o()},exports.FormShape=function(t,{input:i,initial:s,touched:o,validateOn:n,error:e}={}){const h=new R(null,B(t,W.t));return r.batch.call(void 0,t=>{p(i)||h.v(t,i),p(s)||h.S(t,s),p(o)||h.j(t,o),p(n)||h.T(t,n),p(e)||h.U(t,e)}),h.o()},exports.FormSwitch=function(t,i,{input:s,initial:o,touched:n,validateOn:e,error:h}={}){const c=new X(null,U.t(t),B(i,t=>U.t(t)));return r.batch.call(void 0,t=>{p(n)||c.j(t,n),p(o)||c.S(t,o),p(s)||c.v(t,s),p(e)||c.T(t,e),p(h)||c.U(t,h)}),c.o()},exports.FormUnit=function(o,n){const h=t(i([n,"optionalAccess",t=>t.isInputEqual]),()=>_),u=t(i([n,"optionalAccess",t=>t.isInputDirty]),()=>(t,i)=>!h(t,i)),d=!p(i([n,"optionalAccess",t=>t.initial])),a=t(i([n,"optionalAccess",t=>t.initial]),()=>o),l=r.Signal.call(void 0,o,{equals:h}),V=r.Signal.call(void 0,h(a,o)?o:a,{equals:h}),O=r.Signal.call(void 0,t(i([n,"optionalAccess",t=>t.touched]),()=>!1));if(v(n,"schema")){const i=(m=n.schema,{dt:!1,ft:t=>k(m,t)}),o=b(c,f),e=b(c,t(n.isOutputEqual,()=>_));return new S(null,V,l,r.Signal.call(void 0,t(n.error,()=>null),{equals:o}),r.Signal.call(void 0,t(n.validateOn,()=>s)),O,r.Signal.call(void 0,i),u,e,o,d).o()}var m;const y=b(c,t(i([n,"optionalAccess",t=>t.isErrorEqual]),()=>_)),x=r.Signal.call(void 0,t(i([n,"optionalAccess",t=>t.error]),()=>null),{equals:y});if(v(n,"validate")){const i={dt:!1,ft:n.validate},o=b(c,t(n.isOutputEqual,()=>_));return new S(null,V,l,x,r.Signal.call(void 0,t(n.validateOn,()=>s)),O,r.Signal.call(void 0,i),u,o,y,d).o()}if(v(n,"transform")){const i=j(n.transform),s=b(c,t(n.isOutputEqual,()=>_));return new S(null,V,l,x,r.Signal.call(void 0,e),O,r.Signal.call(void 0,i),u,s,y,d).o()}return new S(null,V,l,x,r.Signal.call(void 0,e),O,r.Signal.call(void 0,q),u,b(c,h),y,d).o()},exports.VALIDATE_ON_CHANGE=o,exports.VALIDATE_ON_INIT=e,exports.VALIDATE_ON_SUBMIT=n,exports.VALIDATE_ON_TOUCH=s,exports.isFormList=function(t){return t instanceof G},exports.isFormOptional=function(t){return t instanceof N},exports.isFormShape=function(t){return t instanceof W},exports.isFormSwitch=function(t){return t instanceof U},exports.isFormUnit=function(t){return t instanceof A},exports.isSignalForm=function(t){return t instanceof l};//# sourceMappingURL=index.cjs.map