@owanturist/signal-form 0.5.0 → 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/index.cjs CHANGED
@@ -1 +1,2 @@
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
1
+ "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});let e=require("@owanturist/signal");const t=`onTouch`,n=`onChange`,r=`onSubmit`,i=`onInit`;function a(e){return e!=null}function o(e){return e===null}function s(e){return!0===e}function c(e){return!!e}function l(e,t,n,r,i){let a=t.read(e);return r?r(a,n.read(e)):i==null?a:i(a)}var u=class{static t(e){return e.i}clone(){return this.i.o().h()}getOutput(e,t){let{u:n,l:r}=this.i;return l(e,n,r,t)}getInitial(e){return this.i.v.read(e)}setInitial(t){(0,e.batch)(e=>{this.i.p(e,t)})}getInput(e){return this.i.V.read(e)}setInput(t){(0,e.batch)(e=>{this.i.m(e,t)})}getError(e,t){let{O:n,I:r}=this.i;return l(e,n,r,t)}setError(t){(0,e.batch)(e=>{this.i.T(e,t)})}getValidateOn(e,t){let{C:n,j:r}=this.i;return l(e,n,r,t)}setValidateOn(t){(0,e.batch)(e=>{this.i.k(e,t)})}isValid(e,t){let{q:n,S:r}=this.i;return l(e,n,r,t,s)}isInvalid(e,t){let{A:n,F:r}=this.i;return l(e,n,r,t,c)}isValidated(e,t){let{B:n,M:r}=this.i;return l(e,n,r,t,s)}isDirty(e,t){let{W:n,P:r}=this.i;return l(e,n,r,t,c)}isTouched(e,t){let{D:n,R:r}=this.i;return l(e,n,r,t,c)}setTouched(t){(0,e.batch)(e=>{this.i.G(e,t)})}reset(t){(0,e.batch)(e=>{this.i.H(e,t)})}onFocusWhenInvalid(e){return this.i.K.J(e)}focusFirstInvalid(){(0,e.batch)(e=>{this.i.L(e)?.()})}getSubmitCount(e){return this.i.U.N.read(e)}isSubmitting(e){return this.i.U.X.read(e)>0}onSubmit(e){return this.i.Y.J(e)}async submit(){(0,e.batch)(e=>{this.i.U.N.write(e=>e+1),this.i.U.Z(e)});let t=(0,e.untracked)(e=>{let t=this.i.U.u.read(e);if(!o(t))return this.i.U.tt(e,t).filter(a)});t?t.length>0&&(this.i.U.X.write(e=>e+1),await Promise.all(t),this.i.U.X.write(e=>Math.max(0,e-1))):(0,e.batch)(e=>{this.i.U.L(e)?.()})}};function d(e,t){return typeof e==`object`&&!!e&&t in e}function f(e,t){return Object.is(e,t)}function p(e,t){return!!f(e,t)||e.length===t.length&&e.every((e,n)=>f(e,t[n]))}function m(e){return e===void 0}function h(e,t){return t===f||t===Object.is?f:(n,r)=>e(n)||e(r)?n===r:t(n,r)}function g(e){return e}function _(e){return typeof e==`function`}function v(e){let t=null;return()=>(t??(t={st:e()}),t.st)}function y(e,...t){return _(e)?e(...t):e}const b=Array.isArray;function x(e,t){return(b(e)?e:Array.from(e)).map((e,n)=>t(e,n))}var S=class{constructor(){this.it=[]}J(e){return this.it.push(e),()=>{this.it.splice(this.it.indexOf(e),1)}}et(e){return x(new Set(this.it),t=>t(e))}nt(){return this.it.length===0}},C=class{constructor(t){this.K=new S,this.Y=new S,this.N=(0,e.Signal)(0),this.X=(0,e.Signal)(0),this.U=t?.U??this}o(){return this.ht(null)}rt(e){return this.U===e.U?e:e.ht(this)}ot(e){return this.U===e.U}L(e){for(let{i:t}of this.ut(e)){let n=t.L(e);if(n)return n}let t=this.K.nt()?null:this.O.read(e);return o(t)?null:()=>{this.K.et(t)}}tt(e,t){let n=this.ut(e).flatMap(({i:n,ct:r})=>n.tt(e,r(t)));return[...this.Y.et(t),...n]}},w=class extends u{constructor(e){super(),this.i=e}setTransform(e){this.i.lt(e)}};function T(e){return typeof e==`object`&&a(e)}function E(e){return typeof e==`string`}function D(e){if(!T(e))return[];let t=e.errors??e.issues;return b(t)?x(t.filter(T),({message:e})=>e).filter(E):e instanceof Error?[e.message]:[]}function O(e,t){if(`safeParse`in e)return(n=e.safeParse(t)).success?[null,n.data]:[x(d(n.error,`errors`)?n.error.errors:n.error.issues,({message:e})=>e),null];var n;try{return[null,e.parse(t)]}catch(e){return[D(e),null]}}function k(e){return{dt:!0,_t:t=>[null,e(t)]}}var A=class a extends C{constructor(a,s,c,l,u,d,f,p,m,h,g){super(a),this.v=s,this.V=c,this.ft=l,this.C=u,this.D=d,this.vt=f,this.bt=p,this.Vt=m,this.Ot=h,this.yt=g,this.h=v(()=>new w(this)),this.xt=(0,e.Signal)(!0);let _=(0,e.Signal)(e=>{let t=l.read(e);if(!o(t))return[t,null];let n=c.read(e),[r,i]=f.read(e)._t(n);return o(i)?[y.read(e)?r:null,null]:[null,i]});this.O=this.I=(0,e.Signal)(e=>{let[t]=_.read(e);return t},{equals:h}),this.u=this.l=(0,e.Signal)(e=>{let[,t]=_.read(e);return t},{equals:m}),this.R=d,this.W=this.P=(0,e.Signal)(e=>p(this.v.read(e),c.read(e))),this.j=u,this.q=this.S=(0,e.Signal)(e=>!o(this.u.read(e))),this.A=this.F=(0,e.Signal)(e=>!o(this.O.read(e)));let y=(0,e.Signal)(!1);this.B=this.M=(0,e.Signal)(e=>y.read(e)||this.A.read(e),(e,a)=>{y.write(()=>{if(e||f.read(a).dt)return!0;switch(u.read(a)){case i:return!0;case t:return d.read(a);case n:return this.W.read(a);case r:return!1}})}),this.B.write(!1)}ht(e){return new a(e,this.v.clone(),this.V.clone(),this.ft.clone(),this.C.clone(),this.D.clone(),this.vt.clone(),this.bt,this.Vt,this.Ot,this.yt)}p(e,t){this.v.write(n=>_(t)?t(n,this.V.read(e)):t),this.yt=!0,this.B.write(g)}gt(e,t){this.yt||(this.v.write(t),this.B.write(g))}m(e,t){this.V.write(n=>_(t)?t(n,this.v.read(e)):t),this.B.write(g)}T(e,t){this.ft.write(e=>y(t,e))}k(e,t){let n=this.C.read(e);this.C.write(y(t,n)),n!==this.C.read(e)&&this.B.write(!1)}G(e,t){this.D.write(e=>y(t,e)),this.B.write(g)}Z(){this.B.write(!0)}H(e,t){let n=m(t)?this.v.read(e):_(t)?t(this.v.read(e),this.V.read(e)):t;m(t)||(this.yt=!0),this.v.write(n),this.V.write(n),this.D.write(!1),this.ft.write(null),this.B.write(!1)}ut(){return[]}lt(t){(0,e.batch)(()=>{this.vt.write(k(t)),this.B.write(g)})}};function j(e){return Array.isArray(e)?e.entries():Object.entries(e)}function M(e,t){let n={};for(let[r,i]of j(e))n[r]=t(i,r);return n}function N(e,t){return M(e,t)}function P(e,t){return M(e,t)}function F(e){return M(e,({h:e})=>e())}var I=class extends u{constructor(e){super(),this.i=e,this.fields=F(e.wt)}};function L(e){return typeof e==`boolean`}I.t=u.t;const R=Object.values;function z(e,t,n,r){let i=e.find(t)??n;for(let t of e)if(t!==i)return r??e;return i}var B=class n extends C{constructor(n,r){super(n),this.h=v(()=>new I(this)),this.v=(0,e.Signal)(e=>M(this.wt,({v:t})=>t.read(e))),this.V=(0,e.Signal)(e=>M(this.wt,({V:t})=>t.read(e))),this.O=(0,e.Signal)(e=>{let t=M(this.wt,({O:t})=>t.read(e));return R(t).every(o)?null:t}),this.I=(0,e.Signal)(e=>M(this.wt,({I:t})=>t.read(e))),this.C=(0,e.Signal)(e=>{let n=M(this.wt,({C:t})=>t.read(e));return z(R(n),E,t,n)}),this.j=(0,e.Signal)(e=>M(this.wt,({j:t})=>t.read(e))),this.D=(0,e.Signal)(e=>{let t=M(this.wt,({D:t})=>t.read(e));return z(R(t),L,!1,t)}),this.R=(0,e.Signal)(e=>M(this.wt,({R:t})=>t.read(e))),this.u=(0,e.Signal)(e=>{let t=M(this.wt,({u:t})=>t.read(e));return R(t).some(o)?null:t}),this.l=(0,e.Signal)(e=>M(this.wt,({l:t})=>t.read(e))),this.q=(0,e.Signal)(e=>{let t=M(this.wt,({q:t})=>t.read(e));return z(R(t),L,!1,t)}),this.S=(0,e.Signal)(e=>M(this.wt,({S:t})=>t.read(e))),this.A=(0,e.Signal)(e=>{let t=M(this.wt,({A:t})=>t.read(e));return z(R(t),L,!1,t)}),this.F=(0,e.Signal)(e=>M(this.wt,({F:t})=>t.read(e))),this.B=(0,e.Signal)(e=>{let t=M(this.wt,({B:t})=>t.read(e));return z(R(t),L,!1,t)}),this.M=(0,e.Signal)(e=>M(this.wt,({M:t})=>t.read(e))),this.W=(0,e.Signal)(e=>{let t=M(this.wt,({W:t})=>t.read(e));return z(R(t),L,!1,t)}),this.P=(0,e.Signal)(e=>M(this.wt,({P:t})=>t.read(e))),this.xt=(0,e.Signal)(e=>M(this.wt,({xt:t})=>t.read(e))),this.wt=P(r,e=>this.rt(e))}ht(e){return new n(e,this.wt)}p(e,t){let n=_(t)?t(this.v.read(e),this.V.read(e)):t;for(let[t,r]of j(this.wt))d(n,t)&&!m(n[t])&&r.p(e,n[t])}gt(e,t){for(let[n,r]of j(this.wt))r.gt(e,t[n])}m(e,t){let n=_(t)?t(this.V.read(e),this.v.read(e)):t;for(let[t,r]of j(this.wt))d(n,t)&&!m(n[t])&&r.m(e,n[t])}T(e,t){let n=_(t)?t(this.I.read(e)):t;for(let[t,r]of j(this.wt))o(n)?r.T(e,n):d(n,t)&&!m(n[t])&&r.T(e,n[t])}k(e,t){let n=_(t)?t(this.j.read(e)):t;for(let[t,r]of j(this.wt))E(n)?r.k(e,n):d(n,t)&&!m(n[t])&&r.k(e,n[t])}G(e,t){let n=_(t)?t(this.R.read(e)):t;for(let[t,r]of j(this.wt))L(n)?r.G(e,n):d(n,t)&&!m(n[t])&&r.G(e,n[t])}Z(e){for(let t of R(this.wt))t.Z(e)}H(e,t){m(t)||this.p(e,t);for(let t of R(this.wt))t.H(e,void 0)}ut(){return x(j(this.wt),([e,t])=>({i:t,ct:t=>t[e]}))}},V=class extends u{constructor(t){super(),this.i=t,this.It=(0,e.Signal)(e=>this.i.Tt(e),{equals:p})}getElements(e,t){let n=this.It.read(e);return t?t(n):n}setElements(t){(0,e.batch)(e=>{let n=this.getInitial(e),r=x(_(t)?t(this.i.Tt(e),e):t,u.t);for(let[t,i]of j(r))t<n.length&&(i.ot(this.i)?i.p(e,n[t]):i.gt(e,n[t]));this.i.It.write(x(r,e=>this.i.rt(e)))})}};function H(e,t){return e.length===0?t:t.length===0?e:[...e,...t]}function U(e,t){return t<=0?e:t>=e.length?[]:e.slice(t)}function W(e,t){return t<=0?[]:t>=e.length?e:e.slice(0,t)}V.t=u.t;var G=class n extends C{constructor(n,r,i,a=[]){super(n),this.Et=r,this.Ct=i,this.h=v(()=>new V(this)),this.v=(0,e.Signal)(e=>{let t=this.It.read(e);return x(this.Ct.read(e),(n,r)=>{let i=t.at(r);return i?i.v.read(e):n})}),this.V=(0,e.Signal)(e=>x(this.It.read(e),({V:t})=>t.read(e))),this.O=(0,e.Signal)(e=>{let t=x(this.It.read(e),({O:t})=>t.read(e));return t.every(o)?null:t}),this.I=(0,e.Signal)(e=>x(this.It.read(e),({I:t})=>t.read(e))),this.C=(0,e.Signal)(e=>z(x(this.It.read(e),({C:t})=>t.read(e)),E,t)),this.j=(0,e.Signal)(e=>x(this.It.read(e),({j:t})=>t.read(e))),this.D=(0,e.Signal)(e=>z(x(this.It.read(e),({D:t})=>t.read(e)),L,!1)),this.R=(0,e.Signal)(e=>x(this.It.read(e),({R:t})=>t.read(e))),this.u=(0,e.Signal)(e=>{let t=x(this.It.read(e),({u:t})=>t.read(e));return t.some(o)?null:t}),this.l=(0,e.Signal)(e=>x(this.It.read(e),({l:t})=>t.read(e))),this.q=(0,e.Signal)(e=>z(x(this.It.read(e),({q:t})=>t.read(e)),L,!1)),this.S=(0,e.Signal)(e=>x(this.It.read(e),({S:t})=>t.read(e))),this.A=(0,e.Signal)(e=>z(x(this.It.read(e),({A:t})=>t.read(e)),L,!1)),this.F=(0,e.Signal)(e=>x(this.It.read(e),({F:t})=>t.read(e))),this.B=(0,e.Signal)(e=>z(x(this.It.read(e),({B:t})=>t.read(e)),L,!1)),this.M=(0,e.Signal)(e=>x(this.It.read(e),({M:t})=>t.read(e))),this.W=(0,e.Signal)(e=>{let t=this.It.read(e),n=this.Ct.read(e);return z(H(x(t,({W:t},r)=>r>=n.length||t.read(e)),x(U(n,t.length),()=>!0)),L,!1)}),this.P=(0,e.Signal)(e=>{let t=this.It.read(e),n=this.Ct.read(e);return H(x(t,({P:t,xt:r},i)=>i>=n.length?r.read(e):t.read(e)),x(U(n,t.length),(n,r)=>this.Et(n,t.length+r).xt.read(e)))}),this.xt=(0,e.Signal)(e=>{let t=this.It.read(e),n=this.Ct.read(e);return H(x(t,({xt:t})=>t.read(e)),x(U(n,t.length),(n,r)=>this.Et(n,t.length+r).xt.read(e)))}),this.It=(0,e.Signal)(x(a,e=>this.rt(e)))}ht(t){return new n(t,this.Et,this.Ct.clone(),(0,e.untracked)(this.It))}Tt(e){return x(this.It.read(e),({h:e})=>e())}p(e,t){let n=_(t)?t(this.v.read(e),this.V.read(e)):t,r=W(this.It.read(e),n.length);for(let[t,i]of j(r))i.p(e,n[t]);this.Ct.write(n)}gt(e,t){let n=W(this.It.read(e),t.length);for(let[r,i]of j(n))i.gt(e,t[r]);this.Ct.write(n.map(t=>t.v.read(e)))}m(e,t){let n=this.v.read(e),r=_(t)?t(this.V.read(e),n):t,i=W(this.It.read(e),r.length);for(let[t,n]of j(i))n.m(e,r[t]);let a=U(r,i.length).map((t,r)=>{let a=i.length+r,o=this.Et(t,a);return a<n.length&&o.gt(e,n[a]),this.rt(o)});this.It.write(H(i,a))}T(e,t){let n=_(t)?t(this.I.read(e)):t;for(let[t,r]of j(this.It.read(e))){let i=o(n)?n:n.at(t);m(i)||r.T(e,i)}}k(e,t){let n=_(t)?t(this.j.read(e)):t;for(let[t,r]of j(this.It.read(e))){let i=E(n)?n:n.at(t);m(i)||r.k(e,i)}}G(e,t){let n=_(t)?t(this.R.read(e)):t;for(let[t,r]of j(this.It.read(e))){let i=L(n)?n:n.at(t);m(i)||r.G(e,i)}}Z(e){for(let t of this.It.read(e))t.Z(e)}H(e,t){m(t)||this.p(e,t),this.m(e,this.v.read(e));for(let t of this.It.read(e))t.H(e,void 0)}ut(e){return x(this.It.read(e),(e,t)=>({i:e,ct:e=>e.at(t)}))}},K=class extends u{constructor(e){super(),this.i=e,this.enabled=e.jt.h(),this.element=e.kt.h()}getEnabledElement(e){return this.i.qt(e)?.h()}};K.t=u.t;var q=class t extends C{constructor(t,n,r){super(t),this.h=v(()=>new K(this)),this.v=(0,e.Signal)(e=>({enabled:this.jt.v.read(e),element:this.kt.v.read(e)})),this.V=(0,e.Signal)(e=>({enabled:this.jt.V.read(e),element:this.kt.V.read(e)})),this.O=(0,e.Signal)(e=>this.St(e,({O:e})=>e,o,null)),this.I=(0,e.Signal)(e=>({enabled:this.jt.I.read(e),element:this.kt.I.read(e)})),this.C=(0,e.Signal)(e=>this.St(e,({C:e})=>e,E)),this.j=(0,e.Signal)(e=>({enabled:this.jt.j.read(e),element:this.kt.j.read(e)})),this.D=(0,e.Signal)(e=>this.St(e,({D:e})=>e,L)),this.R=(0,e.Signal)(e=>({enabled:this.jt.R.read(e),element:this.kt.R.read(e)})),this.u=(0,e.Signal)(e=>{let t=this.jt.u.read(e);if(!1===t)return;if(o(t))return null;let n=this.kt.u.read(e);return o(n)?null:n}),this.l=(0,e.Signal)(e=>({enabled:this.jt.l.read(e),element:this.kt.l.read(e)})),this.q=(0,e.Signal)(e=>this.St(e,({q:e})=>e,L)),this.S=(0,e.Signal)(e=>({enabled:this.jt.S.read(e),element:this.kt.S.read(e)})),this.A=(0,e.Signal)(e=>this.St(e,({A:e})=>e,L)),this.F=(0,e.Signal)(e=>({enabled:this.jt.F.read(e),element:this.kt.F.read(e)})),this.B=(0,e.Signal)(e=>this.St(e,({B:e})=>e,L)),this.M=(0,e.Signal)(e=>({enabled:this.jt.M.read(e),element:this.kt.M.read(e)})),this.W=(0,e.Signal)(e=>this.St(e,({W:e})=>e,L)),this.P=(0,e.Signal)(e=>({enabled:this.jt.P.read(e),element:this.kt.P.read(e)})),this.xt=(0,e.Signal)(e=>({enabled:this.jt.xt.read(e),element:this.kt.xt.read(e)})),this.jt=this.rt(n),this.kt=this.rt(r)}At(e){return s(this.jt.u.read(e))}qt(e){return this.At(e)?this.kt:void 0}ht(e){return new t(e,this.jt,this.kt)}St(e,t,n,r){let i=t(this.jt).read(e),a=this.qt(e),o=a&&t(a).read(e);return a?z([i,o],n,i,{enabled:i,element:o}):n(i)||m(r)?i:{enabled:i,element:r}}p(e,t){let{enabled:n,element:r}=_(t)?t(this.v.read(e),this.V.read(e)):t;m(n)||this.jt.p(e,n),m(r)||this.kt.p(e,r)}gt(e,t){this.jt.gt(e,t.enabled),this.kt.gt(e,t.element)}m(e,t){let{enabled:n,element:r}=_(t)?t(this.V.read(e),this.v.read(e)):t;m(n)||this.jt.m(e,n),m(r)||this.kt.m(e,r)}T(e,t){let n=_(t)?t(this.I.read(e)):t,r=o(n)?n:n.enabled;m(r)||this.jt.T(e,r);let i=o(n)?this.At(e)?n:void 0:n.element;m(i)||this.kt.T(e,i)}k(e,t){let n=_(t)?t(this.j.read(e)):t,[r,i]=E(n)?[n,this.At(e)?n:void 0]:[n.enabled,n.element];m(r)||this.jt.k(e,r),m(i)||this.kt.k(e,i)}G(e,t){let n=_(t)?t(this.R.read(e)):t,[r,i]=L(n)?[n,this.At(e)?n:void 0]:[n.enabled,n.element];m(r)||this.jt.G(e,r),m(i)||this.kt.G(e,i)}Z(e){this.jt.Z(e),this.kt.Z(e)}H(e,t){m(t)||this.p(e,t),this.jt.H(e,void 0),this.kt.H(e,void 0)}ut(e){let t=this.jt.u.read(e),n={i:this.jt,ct:()=>t};return!0===t?[n,{i:this.kt,ct:e=>e}]:[n]}},J=class extends u{constructor(e){super(),this.i=e,this.active=e.Ft.h(),this.branches=F(e.Bt)}getActiveBranch(e){let t=this.i.Mt(e);if(t)return{kind:t.kind,value:t.value.h()}}};J.t=u.t;var Y=class t extends C{constructor(t,n,r){super(t),this.h=v(()=>new J(this)),this.v=(0,e.Signal)(e=>this.Wt(e,({v:e})=>e)),this.V=(0,e.Signal)(e=>this.Wt(e,({V:e})=>e)),this.O=(0,e.Signal)(e=>this.St(e,({O:e})=>e,o,null)),this.I=(0,e.Signal)(e=>this.Wt(e,({I:e})=>e)),this.C=(0,e.Signal)(e=>this.St(e,({C:e})=>e,E)),this.j=(0,e.Signal)(e=>this.Wt(e,({j:e})=>e)),this.D=(0,e.Signal)(e=>this.St(e,({D:e})=>e,L)),this.R=(0,e.Signal)(e=>this.Wt(e,({R:e})=>e)),this.u=(0,e.Signal)(e=>{let t=this.Mt(e);if(!t)return null;let n=t.value.u.read(e);return o(n)?null:{kind:t.kind,value:n}}),this.l=(0,e.Signal)(e=>this.Wt(e,({l:e})=>e)),this.q=(0,e.Signal)(e=>this.St(e,({q:e})=>e,L)),this.S=(0,e.Signal)(e=>this.Wt(e,({S:e})=>e)),this.A=(0,e.Signal)(e=>this.St(e,({A:e})=>e,L)),this.F=(0,e.Signal)(e=>this.Wt(e,({F:e})=>e)),this.B=(0,e.Signal)(e=>this.St(e,({B:e})=>e,L)),this.M=(0,e.Signal)(e=>this.Wt(e,({M:e})=>e)),this.W=(0,e.Signal)(e=>this.St(e,({W:e})=>e,L)),this.P=(0,e.Signal)(e=>this.Wt(e,({P:e})=>e)),this.xt=(0,e.Signal)(e=>this.Wt(e,({xt:e})=>e)),this.Ft=this.rt(n),this.Bt=P(r,e=>this.rt(e))}Mt(e){let t=this.Ft.u.read(e),n=o(t)?null:this.Bt[t];return n?{kind:t,value:n}:void 0}St(e,t,n,r){let i=this.Mt(e),a=t(this.Ft).read(e);if(!i)return n(a)||m(r)?a:{active:a,branch:r};let o=t(i.value).read(e);return n(o)&&n(a)&&o===a?a:{active:a,branch:n(o)?o:{kind:i.kind,value:o}}}Wt(e,t){return{active:t(this.Ft).read(e),branches:M(this.Bt,n=>t(n).read(e))}}ht(e){return new t(e,this.Ft,this.Bt)}p(e,t){let n=v(()=>this.v.read(e)),r=v(()=>this.V.read(e)),{active:i,branches:a}=_(t)?t(n(),r()):t;m(i)||this.Ft.p(e,i);let o=_(a)?a(n().branches,r().branches):a;for(let[t,n]of j(this.Bt))d(o,t)&&!m(o[t])&&n.p(e,o[t])}gt(e,t){this.Ft.gt(e,t.active);for(let[n,r]of j(this.Bt))r.gt(e,t.branches[n])}m(e,t){let n=v(()=>this.v.read(e)),r=v(()=>this.V.read(e)),{active:i,branches:a}=_(t)?t(r(),n()):t;m(i)||this.Ft.m(e,i);let o=_(a)?a(r().branches,n().branches):a;for(let[t,n]of j(this.Bt))d(o,t)&&!m(o[t])&&n.m(e,o[t])}T(e,t){let n=v(()=>this.I.read(e)),r=_(t)?t(n()):t,[i,a,s]=o(r)?[r,r,void 0]:[r.active,typeof r==`object`&&`branch`in r?r.branch:void 0,d(r,`branches`)?_(r.branches)?r.branches(n().branches):r.branches:void 0];m(i)||this.Ft.T(e,i);for(let[t,n]of j(this.Bt)){let r=o(s)?s:d(s,t)?s[t]:void 0;m(r)||n.T(e,r)}if(!m(a)){let t=this.Mt(e),n=_(a)?t?a({kind:t.kind,value:t.value.I.read(e)}):void 0:a;if(o(n))t?.value.T(e,n);else if(!m(n)){let{kind:t,value:r}=n,i=d(this.Bt,t)?this.Bt[t]:void 0;i&&i.T(e,r)}}}k(e,t){let n=v(()=>this.j.read(e)),r=_(t)?t(n()):t,[i,a,o]=E(r)?[r,r,void 0]:[r.active,typeof r==`object`&&`branch`in r?r.branch:void 0,d(r,`branches`)?_(r.branches)?r.branches(n().branches):r.branches:void 0];m(i)||this.Ft.k(e,i);for(let[t,n]of j(this.Bt)){let r=E(o)?o:d(o,t)?o[t]:void 0;m(r)||n.k(e,r)}if(!m(a)){let t=this.Mt(e),n=_(a)?t?a({kind:t.kind,value:t.value.j.read(e)}):void 0:a;if(E(n))t?.value.k(e,n);else if(!m(n)){let{kind:t,value:r}=n,i=d(this.Bt,t)?this.Bt[t]:void 0;i&&i.k(e,r)}}}G(e,t){let n=v(()=>this.R.read(e)),r=_(t)?t(n()):t,[i,a,o]=L(r)?[r,r,void 0]:[r.active,typeof r==`object`&&`branch`in r?r.branch:void 0,d(r,`branches`)?_(r.branches)?r.branches(n().branches):r.branches:void 0];m(i)||this.Ft.G(e,i);for(let[t,n]of j(this.Bt)){let r=L(o)?o:d(o,t)?o[t]:void 0;m(r)||n.G(e,r)}if(!m(a)){let t=this.Mt(e),n=_(a)?t?a({kind:t.kind,value:t.value.R.read(e)}):void 0:a;if(L(n))t?.value.G(e,n);else if(!m(n)){let{kind:t,value:r}=n,i=d(this.Bt,t)?this.Bt[t]:void 0;i&&i.G(e,r)}}}Z(e){this.Ft.Z(e),this.Mt(e)?.value.Z(e)}H(e,t){m(t)||this.p(e,t),this.Ft.H(e,void 0);for(let t of R(this.Bt))t.H(e,void 0)}ut(e){let t={i:this.Ft,ct:e=>e.kind},n=this.Mt(e);return n?[t,{i:n.value,ct:e=>e.value}]:[t]}};exports.FormList=function(t,{input:n,initial:r,touched:i,validateOn:a,error:o}={}){let s=new G(null,(e,n)=>V.t(t(e,n)),(0,e.Signal)([],{equals:p}));return(0,e.batch)(e=>{let t=n??r;m(t)||s.m(e,t),m(r)||s.p(e,r),m(i)||s.G(e,i),m(a)||s.k(e,a),m(o)||s.T(e,o)}),s.h()},exports.FormOptional=function(t,n,{input:r,initial:i,touched:a,validateOn:o,error:s}={}){let c=new q(null,K.t(t),K.t(n));return(0,e.batch)(e=>{m(a)||c.G(e,a),m(i)||c.p(e,i),m(r)||c.m(e,r),m(o)||c.k(e,o),m(s)||c.T(e,s)}),c.h()},exports.FormShape=function(t,{input:n,initial:r,touched:i,validateOn:a,error:o}={}){let s=new B(null,N(t,I.t));return(0,e.batch)(e=>{m(n)||s.m(e,n),m(r)||s.p(e,r),m(i)||s.G(e,i),m(a)||s.k(e,a),m(o)||s.T(e,o)}),s.h()},exports.FormSwitch=function(t,n,{input:r,initial:i,touched:a,validateOn:o,error:s}={}){let c=new Y(null,J.t(t),N(n,J.t));return(0,e.batch)(e=>{m(a)||c.G(e,a),m(i)||c.p(e,i),m(r)||c.m(e,r),m(o)||c.k(e,o),m(s)||c.T(e,s)}),c.h()},exports.FormUnit=function(t,n){let r=n?.isInputEqual??f,a=n?.isInputDirty??((e,t)=>!r(e,t)),s=!m(n?.initial),c=n?.initial??t,l=(0,e.Signal)(t,{equals:r}),u=(0,e.Signal)(r(c,t)?t:c,{equals:r}),g=(0,e.Signal)(n?.touched??!1);if(d(n,`schema`)){let t=(_=n.schema,{dt:!1,_t:e=>O(_,e)}),r=h(o,p),i=h(o,n.isOutputEqual??f);return new A(null,u,l,(0,e.Signal)(n.error??null,{equals:r}),(0,e.Signal)(n.validateOn??`onTouch`),g,(0,e.Signal)(t),a,i,r,s).h()}var _;let v=h(o,n?.isErrorEqual??f),y=(0,e.Signal)(n?.error??null,{equals:v});if(d(n,`validate`)){let t={dt:!1,_t:n.validate},r=h(o,n.isOutputEqual??f);return new A(null,u,l,y,(0,e.Signal)(n.validateOn??`onTouch`),g,(0,e.Signal)(t),a,r,v,s).h()}if(d(n,`transform`)){let t=k(n.transform),r=h(o,n.isOutputEqual??f);return new A(null,u,l,y,(0,e.Signal)(i),g,(0,e.Signal)(t),a,r,v,s).h()}return new A(null,u,l,y,(0,e.Signal)(i),g,(0,e.Signal)({dt:!0,_t:e=>[null,e]}),a,h(o,r),v,s).h()},exports.VALIDATE_ON_CHANGE=n,exports.VALIDATE_ON_INIT=i,exports.VALIDATE_ON_SUBMIT=r,exports.VALIDATE_ON_TOUCH=t,exports.isFormList=function(e){return e instanceof V},exports.isFormOptional=function(e){return e instanceof K},exports.isFormShape=function(e){return e instanceof I},exports.isFormSwitch=function(e){return e instanceof J},exports.isFormUnit=function(e){return e instanceof w},exports.isSignalForm=function(e){return e instanceof u};
2
+ //# sourceMappingURL=index.cjs.map