sveltejs-forms
Version:
Declarative forms for Svelte
3 lines (2 loc) • 23.1 kB
JavaScript
function t(){}function e(t,e){for(const n in e)t[n]=e[n];return t}function n(t){return t()}function r(){return Object.create(null)}function o(t){t.forEach(n)}function i(t){return"function"==typeof t}function u(t,e){return t!=t?e==e:t!==e||t&&"object"==typeof t||"function"==typeof t}function l(e,...n){if(null==e)return t;const r=e.subscribe(...n);return r.unsubscribe?()=>r.unsubscribe():r}function c(t,e,n){t.$$.on_destroy.push(l(e,n))}function a(t,n,r,o){return t[1]&&o?e(r.ctx.slice(),t[1](o(n))):r.ctx}function s(t){const e={};for(const n in t)"$"!==n[0]&&(e[n]=t[n]);return e}function f(t,e){const n={};e=new Set(e);for(const r in t)e.has(r)||"$"===r[0]||(n[r]=t[r]);return n}function d(t,e,n=e){return t.set(n),e}function p(t,e){t.appendChild(e)}function h(t,e,n){t.insertBefore(e,n||null)}function v(t){t.parentNode.removeChild(t)}function m(t,e){for(let n=0;n<t.length;n+=1)t[n]&&t[n].d(e)}function _(t){return document.createElement(t)}function g(t){return document.createTextNode(t)}function y(){return g(" ")}function b(t,e,n,r){return t.addEventListener(e,n,r),()=>t.removeEventListener(e,n,r)}function $(t,e,n){null==n?t.removeAttribute(e):t.getAttribute(e)!==n&&t.setAttribute(e,n)}function O(t,e){const n=Object.getOwnPropertyDescriptors(t.__proto__);for(const r in e)null==e[r]?t.removeAttribute(r):"style"===r?t.style.cssText=e[r]:"__value"===r||n[r]&&n[r].set?t[r]=e[r]:$(t,r,e[r])}function x(t,e){e=""+e,t.data!==e&&(t.data=e)}function j(t,e,n){t.classList[n?"add":"remove"](e)}let w;function E(t){w=t}function S(){if(!w)throw new Error("Function called outside component initialization");return w}function A(){const t=S();return(e,n)=>{const r=t.$$.callbacks[e];if(r){const o=function(t,e){const n=document.createEvent("CustomEvent");return n.initCustomEvent(t,!1,!1,e),n}(e,n);r.slice().forEach(e=>{e.call(t,o)})}}}function k(t){return S().$$.context.get(t)}const C=[],z=[],F=[],P=[],V=Promise.resolve();let T=!1;function N(t){F.push(t)}let B=!1;const L=new Set;function M(){if(!B){B=!0;do{for(let t=0;t<C.length;t+=1){const e=C[t];E(e),q(e.$$)}for(C.length=0;z.length;)z.pop()();for(let t=0;t<F.length;t+=1){const e=F[t];L.has(e)||(L.add(e),e())}F.length=0}while(C.length);for(;P.length;)P.pop()();T=!1,B=!1,L.clear()}}function q(t){if(null!==t.fragment){t.update(),o(t.before_update);const e=t.dirty;t.dirty=[-1],t.fragment&&t.fragment.p(t.ctx,e),t.after_update.forEach(N)}}const D=new Set;function J(t,e){t&&t.i&&(D.delete(t),t.i(e))}function R(t,e){const n={},r={},o={$$scope:1};let i=t.length;for(;i--;){const u=t[i],l=e[i];if(l){for(const t in u)t in l||(r[t]=1);for(const t in l)o[t]||(n[t]=l[t],o[t]=1);t[i]=l}else for(const t in u)o[t]=1}for(const t in r)t in n||(n[t]=void 0);return n}function U(t,e){-1===t.$$.dirty[0]&&(C.push(t),T||(T=!0,V.then(M)),t.$$.dirty.fill(0)),t.$$.dirty[e/31|0]|=1<<e%31}function G(e,u,l,c,a,s,f=[-1]){const d=w;E(e);const p=u.props||{},h=e.$$={fragment:null,ctx:null,props:s,update:t,not_equal:a,bound:r(),on_mount:[],on_destroy:[],before_update:[],after_update:[],context:new Map(d?d.$$.context:[]),callbacks:r(),dirty:f};let m=!1;if(h.ctx=l?l(e,p,(t,n,...r)=>{const o=r.length?r[0]:n;return h.ctx&&a(h.ctx[t],h.ctx[t]=o)&&(h.bound[t]&&h.bound[t](o),m&&U(e,t)),n}):[],h.update(),m=!0,o(h.before_update),h.fragment=!!c&&c(h.ctx),u.target){if(u.hydrate){const t=function(t){return Array.from(t.childNodes)}(u.target);h.fragment&&h.fragment.l(t),t.forEach(v)}else h.fragment&&h.fragment.c();u.intro&&J(e.$$.fragment),function(t,e,r){const{fragment:u,on_mount:l,on_destroy:c,after_update:a}=t.$$;u&&u.m(e,r),N(()=>{const e=l.map(n).filter(i);c?c.push(...e):o(e),t.$$.on_mount=[]}),a.forEach(N)}(e,u.target,u.anchor),M()}E(d)}class I{$destroy(){!function(t,e){const n=t.$$;null!==n.fragment&&(o(n.on_destroy),n.fragment&&n.fragment.d(e),n.on_destroy=n.fragment=null,n.ctx=[])}(this,1),this.$destroy=t}$on(t,e){const n=this.$$.callbacks[t]||(this.$$.callbacks[t]=[]);return n.push(e),()=>{const t=n.indexOf(e);-1!==t&&n.splice(t,1)}}$set(){}}const H=[];function K(e,n=t){let r;const o=[];function i(t){if(u(e,t)&&(e=t,r)){const t=!H.length;for(let t=0;t<o.length;t+=1){const n=o[t];n[1](),H.push(n,e)}if(t){for(let t=0;t<H.length;t+=2)H[t][0](H[t+1]);H.length=0}}}return{set:i,update:function(t){i(t(e))},subscribe:function(u,l=t){const c=[u,l];return o.push(c),1===o.length&&(r=n(i)||t),u(e),()=>{const t=o.indexOf(c);-1!==t&&o.splice(t,1),0===o.length&&(r(),r=null)}}}}function Q(e,n,r){const u=!Array.isArray(e),c=u?[e]:e,a=n.length<2;return{subscribe:K(r,e=>{let r=!1;const s=[];let f=0,d=t;const p=()=>{if(f)return;d();const r=n(u?s[0]:s,e);a?e(r):d=i(r)?r:t},h=c.map((t,e)=>l(t,t=>{s[e]=t,f&=~(1<<e),r&&p()},()=>{f|=1<<e}));return r=!0,p(),function(){o(h),d()}}).subscribe}}var W="object"==typeof global&&global&&global.Object===Object&&global,X="object"==typeof self&&self&&self.Object===Object&&self,Y=W||X||Function("return this")(),Z=Y.Symbol,tt=Object.prototype,et=tt.hasOwnProperty,nt=tt.toString,rt=Z?Z.toStringTag:void 0;var ot=Object.prototype.toString;var it=Z?Z.toStringTag:void 0;function ut(t){return null==t?void 0===t?"[object Undefined]":"[object Null]":it&&it in Object(t)?function(t){var e=et.call(t,rt),n=t[rt];try{t[rt]=void 0;var r=!0}catch(t){}var o=nt.call(t);return r&&(e?t[rt]=n:delete t[rt]),o}(t):function(t){return ot.call(t)}(t)}function lt(t){var e=typeof t;return null!=t&&("object"==e||"function"==e)}var ct,at=Y["__core-js_shared__"],st=(ct=/[^.]+$/.exec(at&&at.keys&&at.keys.IE_PROTO||""))?"Symbol(src)_1."+ct:"";var ft=Function.prototype.toString;var dt=/^\[object .+?Constructor\]$/,pt=Function.prototype,ht=Object.prototype,vt=pt.toString,mt=ht.hasOwnProperty,_t=RegExp("^"+vt.call(mt).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");function gt(t){return!(!lt(t)||(e=t,st&&st in e))&&(function(t){if(!lt(t))return!1;var e=ut(t);return"[object Function]"==e||"[object GeneratorFunction]"==e||"[object AsyncFunction]"==e||"[object Proxy]"==e}(t)?_t:dt).test(function(t){if(null!=t){try{return ft.call(t)}catch(t){}try{return t+""}catch(t){}}return""}(t));var e}function yt(t,e){var n=function(t,e){return null==t?void 0:t[e]}(t,e);return gt(n)?n:void 0}var bt=function(){try{var t=yt(Object,"defineProperty");return t({},"",{}),t}catch(t){}}();function $t(t,e){return t===e||t!=t&&e!=e}var Ot=Object.prototype.hasOwnProperty;function xt(t,e,n){var r=t[e];Ot.call(t,e)&&$t(r,n)&&(void 0!==n||e in t)||function(t,e,n){"__proto__"==e&&bt?bt(t,e,{configurable:!0,enumerable:!0,value:n,writable:!0}):t[e]=n}(t,e,n)}var jt=Array.isArray;function wt(t){return"symbol"==typeof t||function(t){return null!=t&&"object"==typeof t}(t)&&"[object Symbol]"==ut(t)}var Et=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,St=/^\w*$/;var At=yt(Object,"create");var kt=Object.prototype.hasOwnProperty;var Ct=Object.prototype.hasOwnProperty;function zt(t){var e=-1,n=null==t?0:t.length;for(this.clear();++e<n;){var r=t[e];this.set(r[0],r[1])}}function Ft(t,e){for(var n=t.length;n--;)if($t(t[n][0],e))return n;return-1}zt.prototype.clear=function(){this.__data__=At?At(null):{},this.size=0},zt.prototype.delete=function(t){var e=this.has(t)&&delete this.__data__[t];return this.size-=e?1:0,e},zt.prototype.get=function(t){var e=this.__data__;if(At){var n=e[t];return"__lodash_hash_undefined__"===n?void 0:n}return kt.call(e,t)?e[t]:void 0},zt.prototype.has=function(t){var e=this.__data__;return At?void 0!==e[t]:Ct.call(e,t)},zt.prototype.set=function(t,e){var n=this.__data__;return this.size+=this.has(t)?0:1,n[t]=At&&void 0===e?"__lodash_hash_undefined__":e,this};var Pt=Array.prototype.splice;function Vt(t){var e=-1,n=null==t?0:t.length;for(this.clear();++e<n;){var r=t[e];this.set(r[0],r[1])}}Vt.prototype.clear=function(){this.__data__=[],this.size=0},Vt.prototype.delete=function(t){var e=this.__data__,n=Ft(e,t);return!(n<0)&&(n==e.length-1?e.pop():Pt.call(e,n,1),--this.size,!0)},Vt.prototype.get=function(t){var e=this.__data__,n=Ft(e,t);return n<0?void 0:e[n][1]},Vt.prototype.has=function(t){return Ft(this.__data__,t)>-1},Vt.prototype.set=function(t,e){var n=this.__data__,r=Ft(n,t);return r<0?(++this.size,n.push([t,e])):n[r][1]=e,this};var Tt=yt(Y,"Map");function Nt(t,e){var n,r,o=t.__data__;return("string"==(r=typeof(n=e))||"number"==r||"symbol"==r||"boolean"==r?"__proto__"!==n:null===n)?o["string"==typeof e?"string":"hash"]:o.map}function Bt(t){var e=-1,n=null==t?0:t.length;for(this.clear();++e<n;){var r=t[e];this.set(r[0],r[1])}}Bt.prototype.clear=function(){this.size=0,this.__data__={hash:new zt,map:new(Tt||Vt),string:new zt}},Bt.prototype.delete=function(t){var e=Nt(this,t).delete(t);return this.size-=e?1:0,e},Bt.prototype.get=function(t){return Nt(this,t).get(t)},Bt.prototype.has=function(t){return Nt(this,t).has(t)},Bt.prototype.set=function(t,e){var n=Nt(this,t),r=n.size;return n.set(t,e),this.size+=n.size==r?0:1,this};function Lt(t,e){if("function"!=typeof t||null!=e&&"function"!=typeof e)throw new TypeError("Expected a function");var n=function(){var r=arguments,o=e?e.apply(this,r):r[0],i=n.cache;if(i.has(o))return i.get(o);var u=t.apply(this,r);return n.cache=i.set(o,u)||i,u};return n.cache=new(Lt.Cache||Bt),n}Lt.Cache=Bt;var Mt=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,qt=/\\(\\)?/g,Dt=function(t){var e=Lt(t,(function(t){return 500===n.size&&n.clear(),t})),n=e.cache;return e}((function(t){var e=[];return 46===t.charCodeAt(0)&&e.push(""),t.replace(Mt,(function(t,n,r,o){e.push(r?o.replace(qt,"$1"):n||t)})),e}));var Jt=Z?Z.prototype:void 0,Rt=Jt?Jt.toString:void 0;function Ut(t){if("string"==typeof t)return t;if(jt(t))return function(t,e){for(var n=-1,r=null==t?0:t.length,o=Array(r);++n<r;)o[n]=e(t[n],n,t);return o}(t,Ut)+"";if(wt(t))return Rt?Rt.call(t):"";var e=t+"";return"0"==e&&1/t==-1/0?"-0":e}function Gt(t,e){return jt(t)?t:function(t,e){if(jt(t))return!1;var n=typeof t;return!("number"!=n&&"symbol"!=n&&"boolean"!=n&&null!=t&&!wt(t))||(St.test(t)||!Et.test(t)||null!=e&&t in Object(e))}(t,e)?[t]:Dt(function(t){return null==t?"":Ut(t)}(t))}var It=/^(?:0|[1-9]\d*)$/;function Ht(t,e){var n=typeof t;return!!(e=null==e?9007199254740991:e)&&("number"==n||"symbol"!=n&&It.test(t))&&t>-1&&t%1==0&&t<e}function Kt(t){if("string"==typeof t||wt(t))return t;var e=t+"";return"0"==e&&1/t==-1/0?"-0":e}function Qt(t,e,n){return null==t?t:function(t,e,n,r){if(!lt(t))return t;for(var o=-1,i=(e=Gt(e,t)).length,u=i-1,l=t;null!=l&&++o<i;){var c=Kt(e[o]),a=n;if(o!=u){var s=l[c];void 0===(a=r?r(s,c,l):void 0)&&(a=lt(s)?s:Ht(e[o+1])?[]:{})}xt(l,c,a),l=l[c]}return t}(t,e,n)}function Wt(t,e,n){var r=null==t?void 0:function(t,e){for(var n=0,r=(e=Gt(e,t)).length;null!=t&&n<r;)t=t[Kt(e[n++])];return n&&n==r?t:void 0}(t,e);return void 0===r?n:r}const Xt=t=>({isSubmitting:32&t,isValid:1&t,values:4&t,errors:16&t,touched:8&t}),Yt=t=>({isSubmitting:t[5],isValid:t[0],setValue:t[13],touchField:t[12],validate:t[11],values:t[2],errors:t[4],touched:t[3]});function Zt(t){let e,n,r;const i=t[25].default,u=function(t,e,n,r){if(t){const o=a(t,e,n,r);return t[0](o)}}(i,t,t[24],Yt);return{c(){e=_("form"),u&&u.c(),$(e,"class","sveltejs-forms")},m(i,l,c){var a;h(i,e,l),u&&u.m(e,null),t[26](e),n=!0,c&&o(r),r=[b(e,"submit",(a=t[15],function(t){return t.preventDefault(),a.call(this,t)})),b(e,"reset",t[14])]},p(t,[e]){u&&u.p&&16777277&e&&u.p(a(i,t,t[24],Yt),function(t,e,n,r){if(t[2]&&r){const o=t[2](r(n));if(void 0===e.dirty)return o;if("object"==typeof o){const t=[],n=Math.max(e.dirty.length,o.length);for(let r=0;r<n;r+=1)t[r]=e.dirty[r]|o[r];return t}return e.dirty|o}return e.dirty}(i,t[24],e,Xt))},i(t){n||(J(u,t),n=!0)},o(t){!function(t,e,n,r){if(t&&t.o){if(D.has(t))return;D.add(t),(void 0).c.push(()=>{D.delete(t),r&&(n&&t.d(1),r())}),t.o(e)}}(u,t),n=!1},d(n){n&&v(e),u&&u.d(n),t[26](null),o(r)}}}const te={};function ee(t,e,n){let r,o,i,u,l,{initialValues:a={}}=e,{schema:s=null}=e,{validateOnChange:f=!0}=e,{validateOnBlur:p=!0}=e;const h=A(),v=K(function(t=""){return new Proxy({},{get:function(e,n){return Object.prototype.hasOwnProperty.call(e,n)?e[n]:t}})}());c(t,v,t=>n(2,r=t));const m=K({});c(t,m,t=>n(21,u=t));const _=K({});c(t,_,t=>n(4,i=t));const g=K({});c(t,g,t=>n(3,o=t));const y=K(!1);let b,$,O;var x,j,w;function E(t){O.forEach(({path:e,multiple:n})=>{d(v,r=Qt(r,e,Wt(t||a,e,n?[]:""))),d(g,o=Qt(o,e,!1))}),d(_,i={}),d(m,u={}),n(0,b=void 0)}async function k(){var t;if(s)try{d(m,u=await s.validate((t=r,JSON.parse(JSON.stringify(t))),{abortEarly:!1,stripUnknown:!0})),d(_,i={}),n(0,b=!0)}catch(t){d(_,i={}),t.inner.forEach(t=>{d(_,i=Qt(i,t.path,t.message))}),n(0,b=!1)}else n(0,b=!0)}function C(t,e=!1){(p||e)&&(d(g,o=Qt(o,t,!0)),k())}function F(t,e,n=!0){d(v,r=Qt(r,t,e)),d(g,o=Qt(o,t,!0)),n&&f&&k()}c(t,y,t=>n(5,l=t)),x=()=>{O=Array.from($.querySelectorAll("input,textarea,select")).filter(t=>!!t.name).map(t=>({path:t.name})).reduce((t,e)=>{const n=t=>t.path===e.path,r=!!t.find(n);return[...t.filter(t=>!n(t)),{...e,multiple:r}]},[]),E()},S().$$.on_mount.push(x),j=te,w={touchField:C,setValue:F,validate:k,values:v,errors:_,touched:g,isSubmitting:y,validateOnBlur:p,validateOnChange:f},S().$$.context.set(j,w);let{$$slots:P={},$$scope:V}=e;return t.$set=t=>{"initialValues"in t&&n(16,a=t.initialValues),"schema"in t&&n(17,s=t.schema),"validateOnChange"in t&&n(18,f=t.validateOnChange),"validateOnBlur"in t&&n(19,p=t.validateOnBlur),"$$scope"in t&&n(24,V=t.$$scope)},[b,$,r,o,i,l,v,m,_,g,y,k,C,F,function(){E(),h("reset")},async function(){O.forEach(({path:t})=>d(g,o=Qt(o,t,!0))),await k(),s&&!b||(d(y,l=!0),h("submit",{values:s?{...u}:{...r},setSubmitting:t=>d(y,l=t),resetForm:E}))},a,s,f,p,O,u,h,E,V,P,function(t){z[t?"unshift":"push"](()=>{n(1,$=t)})}]}class ne extends I{constructor(t){super(),G(this,t,ee,Zt,u,{initialValues:16,schema:17,validateOnChange:18,validateOnBlur:19})}}function re(t){let e,n;return{c(){e=_("label"),n=g(t[1]),$(e,"for",t[0])},m(t,r){h(t,e,r),p(e,n)},p(t,r){2&r&&x(n,t[1]),1&r&&$(e,"for",t[0])},d(t){t&&v(e)}}}function oe(t){let n,r,u=[{name:t[0]},{type:t[2]},{id:t[0]},{value:Wt(t[6],t[0])},t[12]],l={};for(let t=0;t<u.length;t+=1)l=e(l,u[t]);return{c(){n=_("input"),O(n,l)},m(e,u,l){h(e,n,u),l&&o(r),r=[b(n,"blur",t[11]),b(n,"change",t[10]),b(n,"input",(function(){i(Wt(t[4],t[0])&&t[10])&&(Wt(t[4],t[0])&&t[10]).apply(this,arguments)}))]},p(e,r){t=e,O(n,R(u,[1&r&&{name:t[0]},4&r&&{type:t[2]},1&r&&{id:t[0]},65&r&&{value:Wt(t[6],t[0])},4096&r&&t[12]]))},d(t){t&&v(n),o(r)}}}function ie(t){let n,r,u=[{name:t[0]},{id:t[0]},{value:Wt(t[6],t[0])},t[12]],l={};for(let t=0;t<u.length;t+=1)l=e(l,u[t]);return{c(){n=_("textarea"),O(n,l)},m(e,u,l){h(e,n,u),l&&o(r),r=[b(n,"blur",t[11]),b(n,"change",t[10]),b(n,"input",(function(){i(Wt(t[4],t[0])&&t[10])&&(Wt(t[4],t[0])&&t[10]).apply(this,arguments)}))]},p(e,r){t=e,O(n,R(u,[1&r&&{name:t[0]},1&r&&{id:t[0]},65&r&&{value:Wt(t[6],t[0])},4096&r&&t[12]]))},d(t){t&&v(n),o(r)}}}function ue(t){let e,n,r=Wt(t[5],t[0])+"";return{c(){e=_("div"),n=g(r),$(e,"class","message")},m(t,r){h(t,e,r),p(e,n)},p(t,e){33&e&&r!==(r=Wt(t[5],t[0])+"")&&x(n,r)},d(t){t&&v(e)}}}function le(e){let n,r,o,i=Wt(e[4],e[0])&&Wt(e[5],e[0]),u=e[1]&&re(e);function l(t,e){return t[3]?ie:oe}let c=l(e),a=c(e),s=i&&ue(e);return{c(){n=_("div"),u&&u.c(),r=y(),a.c(),o=y(),s&&s.c(),$(n,"class","field"),j(n,"error",Wt(e[4],e[0])&&Wt(e[5],e[0]))},m(t,e){h(t,n,e),u&&u.m(n,null),p(n,r),a.m(n,null),p(n,o),s&&s.m(n,null)},p(t,[e]){t[1]?u?u.p(t,e):(u=re(t),u.c(),u.m(n,r)):u&&(u.d(1),u=null),c===(c=l(t))&&a?a.p(t,e):(a.d(1),a=c(t),a&&(a.c(),a.m(n,o))),49&e&&(i=Wt(t[4],t[0])&&Wt(t[5],t[0])),i?s?s.p(t,e):(s=ue(t),s.c(),s.m(n,null)):s&&(s.d(1),s=null),49&e&&j(n,"error",Wt(t[4],t[0])&&Wt(t[5],t[0]))},i:t,o:t,d(t){t&&v(n),u&&u.d(),a.d(),s&&s.d()}}}function ce(t,n,r){const o=["name","label","type","multiline"];let i,u,l,a=f(n,o),{name:d}=n,{label:p=""}=n,{type:h="text"}=n,{multiline:v=!1}=n;const{touchField:m,setValue:_,values:g,errors:y,touched:b}=k(te);return c(t,g,t=>r(6,l=t)),c(t,y,t=>r(5,u=t)),c(t,b,t=>r(4,i=t)),Object.keys(a).includes("value")&&setTimeout(()=>_(d,a.value,!1),0),t.$set=t=>{n=e(e({},n),s(t)),r(12,a=f(n,o)),"name"in t&&r(0,d=t.name),"label"in t&&r(1,p=t.label),"type"in t&&r(2,h=t.type),"multiline"in t&&r(3,v=t.multiline)},[d,p,h,v,i,u,l,g,y,b,function(t){_(d,t.target.value)},function(){m(d)},a]}class ae extends I{constructor(t){super(),G(this,t,ce,le,u,{name:0,label:1,type:2,multiline:3})}}function se(t,e,n){const r=t.slice();return r[14]=e[n],r}function fe(t){let e,n;return{c(){e=_("label"),n=g(t[1]),$(e,"for",t[0])},m(t,r){h(t,e,r),p(e,n)},p(t,r){2&r&&x(n,t[1]),1&r&&$(e,"for",t[0])},d(t){t&&v(e)}}}function de(t){let e,n,r,o,i,u=t[14].title+"";return{c(){e=_("option"),n=g(u),r=y(),e.__value=o=t[14].id,e.value=e.__value,e.selected=i=Wt(t[5],t[0])===t[14].id},m(t,o){h(t,e,o),p(e,n),p(e,r)},p(t,r){4&r&&u!==(u=t[14].title+"")&&x(n,u),4&r&&o!==(o=t[14].id)&&(e.__value=o),e.value=e.__value,37&r&&i!==(i=Wt(t[5],t[0])===t[14].id)&&(e.selected=i)},d(t){t&&v(e)}}}function pe(t){let e,n,r=Wt(t[4],t[0])+"";return{c(){e=_("div"),n=g(r),$(e,"class","message")},m(t,r){h(t,e,r),p(e,n)},p(t,e){17&e&&r!==(r=Wt(t[4],t[0])+"")&&x(n,r)},d(t){t&&v(e)}}}function he(n){let r,i,u,l,c,a,s=Wt(n[3],n[0])&&Wt(n[4],n[0]),f=n[1]&&fe(n),d=n[2],g=[];for(let t=0;t<d.length;t+=1)g[t]=de(se(n,d,t));let x=[{name:n[0]},{id:n[0]},{value:Wt(n[5],n[0])},n[11]],w={};for(let t=0;t<x.length;t+=1)w=e(w,x[t]);let E=s&&pe(n);return{c(){r=_("div"),f&&f.c(),i=y(),u=_("select"),l=_("option");for(let t=0;t<g.length;t+=1)g[t].c();c=y(),E&&E.c(),l.__value="",l.value=l.__value,O(u,w),$(r,"class","field"),j(r,"error",Wt(n[3],n[0])&&Wt(n[4],n[0]))},m(t,e,s){h(t,r,e),f&&f.m(r,null),p(r,i),p(r,u),p(u,l);for(let t=0;t<g.length;t+=1)g[t].m(u,null);p(r,c),E&&E.m(r,null),s&&o(a),a=[b(u,"change",n[9]),b(u,"blur",n[10])]},p(t,[e]){if(t[1]?f?f.p(t,e):(f=fe(t),f.c(),f.m(r,i)):f&&(f.d(1),f=null),37&e){let n;for(d=t[2],n=0;n<d.length;n+=1){const r=se(t,d,n);g[n]?g[n].p(r,e):(g[n]=de(r),g[n].c(),g[n].m(u,null))}for(;n<g.length;n+=1)g[n].d(1);g.length=d.length}O(u,R(x,[1&e&&{name:t[0]},1&e&&{id:t[0]},33&e&&{value:Wt(t[5],t[0])},2048&e&&t[11]])),25&e&&(s=Wt(t[3],t[0])&&Wt(t[4],t[0])),s?E?E.p(t,e):(E=pe(t),E.c(),E.m(r,null)):E&&(E.d(1),E=null),25&e&&j(r,"error",Wt(t[3],t[0])&&Wt(t[4],t[0]))},i:t,o:t,d(t){t&&v(r),f&&f.d(),m(g,t),E&&E.d(),o(a)}}}function ve(t,n,r){const o=["name","label","options"];let i,u,l,a=f(n,o),{name:d}=n,{label:p=""}=n,{options:h}=n;const{touchField:v,setValue:m,values:_,errors:g,touched:y}=k(te);return c(t,_,t=>r(5,l=t)),c(t,g,t=>r(4,u=t)),c(t,y,t=>r(3,i=t)),Object.keys(a).includes("value")&&setTimeout(()=>m(d,a.value,!1),0),t.$set=t=>{n=e(e({},n),s(t)),r(11,a=f(n,o)),"name"in t&&r(0,d=t.name),"label"in t&&r(1,p=t.label),"options"in t&&r(2,h=t.options)},[d,p,h,i,u,l,_,g,y,function(t){m(d,t.target.value)},function(){v(d)},a]}class me extends I{constructor(t){super(),G(this,t,ve,he,u,{name:0,label:1,options:2})}}function _e(t,e,n,r){var o,i,u=!0,l="withOld"in n,c=Q(t,(t,n)=>{if(o=n,l&&(i=t),u){let r=e(t,n);if(!(e.length<2))return r;n(r)}},r),a=!Array.isArray(t),s=e=>{u=!1,a?t.set(e):e.forEach((e,n)=>{t[n].set(e)}),u=!0};l&&(n=n.withOld);var f=n.length>=(l?3:2),d=null;var p=0;function h(t){var e,r,u=!1,a=p+1,h=c.subscribe(t=>{u?e=!0:r=t}),v=t(r);u=!0,o(v),h(),e&&a>p&&(p=a,function(t){if(d&&(d(),d=null),l)var e=n(t,i,s);else e=n(t,s);f?"function"==typeof e&&(d=e):s(e)}(v))}return{subscribe:c.subscribe,set(t){h(()=>t)},update:h}}function ge(t,e,n){const r=t.slice();return r[20]=e[n],r}function ye(t){let n,r,i=[{id:t[0]+"-"+t[20].id},{type:"radio"},{name:t[0]},{__value:t[20].id},t[12]],u={};for(let t=0;t<i.length;t+=1)u=e(u,i[t]);return{c(){n=_("input"),O(n,u),t[18][0].push(n)},m(e,i,u){h(e,n,i),n.checked=n.__value===t[5],u&&o(r),r=[b(n,"change",t[19]),b(n,"change",t[10]),b(n,"blur",t[11])]},p(t,e){O(n,R(i,[3&e&&{id:t[0]+"-"+t[20].id},{type:"radio"},1&e&&{name:t[0]},2&e&&{__value:t[20].id},4096&e&&t[12]])),32&e&&(n.checked=n.__value===t[5])},d(e){e&&v(n),t[18][0].splice(t[18][0].indexOf(n),1),o(r)}}}function be(t){let n,r,i=[{id:t[0]+"-"+t[20].id},{type:"checkbox"},{name:t[0]},{__value:t[20].id},t[12]],u={};for(let t=0;t<i.length;t+=1)u=e(u,i[t]);return{c(){n=_("input"),O(n,u),t[18][0].push(n)},m(e,i,u){h(e,n,i),n.checked=~t[5].indexOf(n.__value),u&&o(r),r=[b(n,"change",t[17]),b(n,"change",t[10]),b(n,"blur",t[11])]},p(t,e){O(n,R(i,[3&e&&{id:t[0]+"-"+t[20].id},{type:"checkbox"},1&e&&{name:t[0]},2&e&&{__value:t[20].id},4096&e&&t[12]])),32&e&&(n.checked=~t[5].indexOf(n.__value))},d(e){e&&v(n),t[18][0].splice(t[18][0].indexOf(n),1),o(r)}}}function $e(t){let e,n,r,o=t[20].title+"";return{c(){e=_("label"),n=g(o),$(e,"for",r=t[20].id)},m(t,r){h(t,e,r),p(e,n)},p(t,i){2&i&&o!==(o=t[20].title+"")&&x(n,o),2&i&&r!==(r=t[20].id)&&$(e,"for",r)},d(t){t&&v(e)}}}function Oe(t){let e,n;function r(t,e){return t[2]?be:ye}let o=r(t),i=o(t),u=t[20].title&&$e(t);return{c(){i.c(),e=y(),u&&u.c(),n=g("")},m(t,r){i.m(t,r),h(t,e,r),u&&u.m(t,r),h(t,n,r)},p(t,l){o===(o=r(t))&&i?i.p(t,l):(i.d(1),i=o(t),i&&(i.c(),i.m(e.parentNode,e))),t[20].title?u?u.p(t,l):(u=$e(t),u.c(),u.m(n.parentNode,n)):u&&(u.d(1),u=null)},d(t){i.d(t),t&&v(e),u&&u.d(t),t&&v(n)}}}function xe(t){let e,n,r=Wt(t[4],t[0])+"";return{c(){e=_("div"),n=g(r),$(e,"class","message")},m(t,r){h(t,e,r),p(e,n)},p(t,e){17&e&&r!==(r=Wt(t[4],t[0])+"")&&x(n,r)},d(t){t&&v(e)}}}function je(e){let n,r,o=Wt(e[3],e[0])&&Wt(e[4],e[0]),i=e[1],u=[];for(let t=0;t<i.length;t+=1)u[t]=Oe(ge(e,i,t));let l=o&&xe(e);return{c(){n=_("div");for(let t=0;t<u.length;t+=1)u[t].c();r=y(),l&&l.c(),$(n,"class","field"),j(n,"error",Wt(e[3],e[0])&&Wt(e[4],e[0]))},m(t,e){h(t,n,e);for(let t=0;t<u.length;t+=1)u[t].m(n,null);p(n,r),l&&l.m(n,null)},p(t,[e]){if(7207&e){let o;for(i=t[1],o=0;o<i.length;o+=1){const l=ge(t,i,o);u[o]?u[o].p(l,e):(u[o]=Oe(l),u[o].c(),u[o].m(n,r))}for(;o<u.length;o+=1)u[o].d(1);u.length=i.length}25&e&&(o=Wt(t[3],t[0])&&Wt(t[4],t[0])),o?l?l.p(t,e):(l=xe(t),l.c(),l.m(n,null)):l&&(l.d(1),l=null),25&e&&j(n,"error",Wt(t[3],t[0])&&Wt(t[4],t[0]))},i:t,o:t,d(t){t&&v(n),m(u,t),l&&l.d()}}}function we(t,n,r){const o=["name","options","multiple","value"];let i,u,l,a,d=f(n,o),{name:p}=n,{options:h}=n,{multiple:v=!1}=n,{value:m=""}=n;const{touchField:_,values:g,errors:y,touched:b,validateOnChange:$}=k(te);c(t,g,t=>r(14,i=t)),c(t,y,t=>r(4,l=t)),c(t,b,t=>r(3,u=t));const O=_e(g,t=>Wt(t,p,v?[]:""),t=>Qt(i,p,t));c(t,O,t=>r(5,a=t)),m&&setTimeout(()=>{O.set(m)},0);const x=[[]];return t.$set=t=>{n=e(e({},n),s(t)),r(12,d=f(n,o)),"name"in t&&r(0,p=t.name),"options"in t&&r(1,h=t.options),"multiple"in t&&r(2,v=t.multiple),"value"in t&&r(13,m=t.value)},[p,h,v,u,l,a,g,y,b,O,function(){_(p,$)},function(){_(p)},d,m,i,_,$,function(){a=function(t){const e=[];for(let n=0;n<t.length;n+=1)t[n].checked&&e.push(t[n].__value);return e}(x[0]),O.set(a)},x,function(){a=this.__value,O.set(a)}]}class Ee extends I{constructor(t){super(),G(this,t,we,je,u,{name:0,options:1,multiple:2,value:13})}}export{Ee as Choice,ne as Form,ae as Input,me as Select};
//# sourceMappingURL=index.min.mjs.map