mobx-formkit 1.1.4 → 1.3.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.
Files changed (49) hide show
  1. package/AGENTS.md +33 -17
  2. package/lib/Base.d.ts +38 -1
  3. package/lib/Base.d.ts.map +1 -1
  4. package/lib/Base.js +61 -1
  5. package/lib/Base.js.map +1 -1
  6. package/lib/Field.d.ts +6 -0
  7. package/lib/Field.d.ts.map +1 -1
  8. package/lib/Field.js +17 -0
  9. package/lib/Field.js.map +1 -1
  10. package/lib/Form.d.ts.map +1 -1
  11. package/lib/Form.js +2 -0
  12. package/lib/Form.js.map +1 -1
  13. package/lib/Options.d.ts.map +1 -1
  14. package/lib/Options.js +2 -0
  15. package/lib/Options.js.map +1 -1
  16. package/lib/esm/Base.js +62 -2
  17. package/lib/esm/Base.js.map +1 -1
  18. package/lib/esm/Field.js +18 -1
  19. package/lib/esm/Field.js.map +1 -1
  20. package/lib/esm/Form.js +2 -0
  21. package/lib/esm/Form.js.map +1 -1
  22. package/lib/esm/Options.js +2 -0
  23. package/lib/esm/Options.js.map +1 -1
  24. package/lib/esm/models/OptionsModel.js +2 -0
  25. package/lib/esm/models/OptionsModel.js.map +1 -1
  26. package/lib/esm/utils.js +24 -2
  27. package/lib/esm/utils.js.map +1 -1
  28. package/lib/models/BaseInterface.d.ts +3 -0
  29. package/lib/models/BaseInterface.d.ts.map +1 -1
  30. package/lib/models/OptionsModel.d.ts +4 -0
  31. package/lib/models/OptionsModel.d.ts.map +1 -1
  32. package/lib/models/OptionsModel.js +2 -0
  33. package/lib/models/OptionsModel.js.map +1 -1
  34. package/lib/utils.d.ts +9 -1
  35. package/lib/utils.d.ts.map +1 -1
  36. package/lib/utils.js +23 -0
  37. package/lib/utils.js.map +1 -1
  38. package/package.json +1 -1
  39. package/src/Base.ts +72 -2
  40. package/src/Field.ts +19 -0
  41. package/src/Form.ts +3 -0
  42. package/src/Options.ts +2 -0
  43. package/src/models/BaseInterface.ts +3 -0
  44. package/src/models/OptionsModel.ts +4 -0
  45. package/src/utils.ts +21 -1
  46. package/umd/MobxFormkit.umd.js +106 -1
  47. package/umd/MobxFormkit.umd.js.map +1 -1
  48. package/umd/MobxFormkit.umd.min.js +1 -1
  49. package/umd/MobxFormkit.umd.min.js.map +1 -1
@@ -1,2 +1,2 @@
1
- !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("mobx"),require("lodash")):"function"==typeof define&&define.amd?define(["exports","mobx","lodash"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).MobxFormkit={},e.mobx,e._)}(this,function(e,t,i){"use strict";function s(e){var t=Object.create(null);return e&&Object.keys(e).forEach(function(i){if("default"!==i){var s=Object.getOwnPropertyDescriptor(e,i);Object.defineProperty(t,i,s.get?s:{enumerable:!0,get:function(){return e[i]}})}}),t.default=e,Object.freeze(t)}const r=s(t),a=(e,t)=>"function"==typeof r.makeObservable?r.makeObservable(e,t):function(e,t){const i=Object.entries(t).filter(([t])=>t in e),s=e=>e===r.computed||"computed"===e,a=e=>e===r.action||"action"===e,l=t=>{let i,s=Object.getPrototypeOf(e);for(;s&&void 0===i;)i=Object.getOwnPropertyDescriptor(s,t),s=Object.getPrototypeOf(s);return i};i.forEach(([t,i])=>{if(s(i)){const i=Object.getOwnPropertyDescriptor(e,t);if(!i||"function"!=typeof i.get){const i=l(t),s=i&&"function"==typeof i.get?i.get:null,r=i&&"function"==typeof i.set?i.set:null;Object.defineProperty(e,t,{configurable:!0,enumerable:!!i&&i.enumerable,get:s?()=>s.call(e):()=>{},set:r?t=>r.call(e,t):void 0})}}else if(a(i)){const i=e[t];"function"!=typeof i||Object.prototype.hasOwnProperty.call(e,t)||Object.defineProperty(e,t,{configurable:!0,writable:!0,enumerable:!1,value:i})}});const n={};return i.forEach(([e,t])=>{s(t)?n[e]=r.computed:a(t)?n[e]=r.action:n[e]=r.observable}),r.decorate(e,n),e}(e,t);class l{_isArrayMap=!0;onMove;_entries=t.observable.array([]);constructor(e){e&&e.length>0&&this._entries.replace(e)}get size(){return this._entries.length}get(e){const t=this._entries.find(([t])=>t===e);return t?t[1]:void 0}set(e,t){const i=this._entries.find(([t])=>t===e);return i?i[1]=t:this._entries.push([e,t]),this}has(e){return this._entries.some(([t])=>t===e)}delete(e){const t=this._entries.findIndex(([t])=>t===e);return-1!==t&&(this._entries.splice(t,1),!0)}clear(){this._entries.clear()}keys(){return this._entries.map(([e])=>e)[Symbol.iterator]()}values(){return this._entries.map(([,e])=>e)[Symbol.iterator]()}entries(){return this._entries[Symbol.iterator]()}forEach(e,t){this._entries.forEach(([i,s])=>{e.call(t,s,i,this)})}toJSON(){const e={};return this._entries.forEach(([t,i])=>{e[String(t)]=i}),e}toString(){return"[object ArrayMap]"}merge(e){return e&&"object"==typeof e&&(e.forEach&&"function"==typeof e.forEach?e.forEach((e,t)=>{this.set(t,e)}):Array.isArray(e)?e.forEach(([e,t])=>{this.set(e,t)}):Object.keys(e).forEach(t=>{this.set(t,e[t])})),this}replace(e){return this.clear(),this.merge(e)}get intercept(){return this._entries.intercept}[Symbol.iterator](){return this._entries[Symbol.iterator]()}move(e,i){t.runInAction(()=>{if(e<0||e>=this._entries.length)return;if(i<0||i>=this._entries.length)return;if(e===i)return;const[t]=this._entries.splice(e,1);this._entries.splice(i,0,t),this.onMove?.()})}toArray(){return this._entries}}var n,o,d,h;!function(e){e.key="key",e.id="id",e.path="path",e.name="name",e.fields="fields",e.ref="ref",e.type="type",e.computed="computed",e.value="value",e.initial="initial",e.default="default",e.checked="checked",e.label="label",e.placeholder="placeholder",e.error="error",e.validatedWith="validatedWith",e.validators="validators",e.rules="rules",e.related="related",e.options="options",e.extra="extra",e.bindings="bindings",e.hooks="hooks",e.handlers="handlers",e.converter="converter",e.input="input",e.output="output",e.interceptors="interceptors",e.observers="observers",e.disabled="disabled",e.deleted="deleted",e.blurred="blurred",e.validating="validating",e.submitting="submitting",e.clearing="clearing",e.resetting="resetting",e.changed="changed",e.touched="touched",e.focused="focused",e.isEmpty="isEmpty",e.isDefault="isDefault",e.isPristine="isPristine",e.isDirty="isDirty",e.isValid="isValid",e.hasError="hasError",e.onInit="onInit",e.onSync="onSync",e.onChange="onChange",e.onBlur="onBlur",e.onFocus="onFocus",e.onToggle="onToggle",e.onDrop="onDrop",e.onSubmit="onSubmit",e.onReset="onReset",e.onClear="onClear",e.onAdd="onAdd",e.onDel="onDel",e.autoFocus="autoFocus",e.inputMode="inputMode",e.onKeyDown="onKeyDown",e.onKeyUp="onKeyUp",e.class="class",e.nullable="nullable",e.autoComplete="autoComplete"}(n||(n={})),function(e){e.computed="computed",e.observable="observable",e.editable="editable",e.all="all"}(o||(o={})),function(e){e.some="some",e.every="every"}(d||(d={})),function(e){e.computed="computed",e.values="values",e.labels="labels",e.placeholders="placeholders",e.defaults="defaults",e.initials="initials",e.disabled="disabled",e.deleted="deleted",e.types="types",e.related="related",e.rules="rules",e.options="options",e.bindings="bindings",e.extra="extra",e.hooks="hooks",e.handlers="handlers",e.validatedWith="validatedWith",e.validators="validators",e.observers="observers",e.interceptors="interceptors",e.converters="converters",e.input="input",e.output="output",e.autoFocus="autoFocus",e.inputMode="inputMode",e.refs="refs",e.classes="classes",e.nullable="nullable",e.autoComplete="autoComplete"}(h||(h={}));const u={editable:[n.type,n.value,n.initial,n.default,n.label,n.placeholder,n.related,n.options,n.extra,n.bindings,n.hooks,n.handlers,n.deleted,n.disabled,n.autoFocus,n.inputMode,n.ref,n.nullable,n.autoComplete],handlers:[n.onChange,n.onToggle,n.onFocus,n.onBlur,n.onDrop,n.onSubmit,n.onReset,n.onClear,n.onAdd,n.onDel],computed:[n.error,n.hasError,n.isValid,n.isDirty,n.isPristine,n.isDefault,n.isEmpty,n.focused,n.touched,n.changed,n.validating,n.submitting,n.resetting,n.clearing,n.blurred,n.deleted,n.disabled],separated:[h.computed,h.values,h.labels,h.placeholders,h.defaults,h.initials,h.disabled,h.deleted,h.types,h.related,h.rules,h.options,h.bindings,h.extra,h.hooks,h.handlers,h.validatedWith,h.validators,h.observers,h.interceptors,h.converters,h.input,h.output,h.autoFocus,h.inputMode,h.refs,h.classes,h.nullable,h.autoComplete],functions:[n.computed,n.observers,n.interceptors,n.converter,n.input,n.output],validation:[n.rules,n.validators,n.validatedWith],occurrences:{isDirty:d.some,isPristine:d.every,isDefault:d.every,isValid:d.every,isEmpty:d.every,hasError:d.some,focused:d.some,blurred:d.some,touched:d.some,deleted:d.every,disabled:d.every,clearing:d.every,resetting:d.every}},c=e=>{if(e&&e._isArrayMap){const t=[];return e.forEach(e=>t.push(e)),t}return t.values(e)},p=({type:e,data:t})=>{let i;switch(e){case d.some:i=e=>e.some(Boolean);break;case d.every:i=e=>e.every(Boolean);break;default:throw new Error("Occurrence not found for specified prop")}return i(t)},f=(e,t)=>{let i;switch(e){case o.computed:i=u.computed;break;case o.observable:i=[n.fields,...u.computed,...u.editable];break;case o.editable:i=[...u.editable,...u.validation,...u.functions,...u.handlers];break;case o.all:i=[n.id,n.key,n.name,n.path,...u.computed,...u.editable,...u.validation,...u.functions,...u.handlers];break;default:i=null}return t.filter(e=>i.includes(e)).length>0},v=(e,t)=>{if(f(e,t))return;throw new Error(`The selected property is not allowed (${JSON.stringify(t)})`)},b=(e,t,i=null)=>{if(null!=t)return;throw new Error(`${null==i?"The selected field is not defined":i} (${e})`)},g=e=>{let t;return t=e.replace(/\.\d+($|\.)/g,"[]."),t=t.replace("..","."),t=t.replace(/^\.+|\.+$/g,""),t},y=(e,t)=>t.some(t=>i.has(e,t)),m=e=>i.isEmpty(e)&&Array.isArray(e),$=e=>Array.isArray(e)&&e.every(e=>"string"==typeof e),O=e=>Array.isArray(e)&&e.every(e=>i.isPlainObject(e)),E=({fields:e})=>!$({fields:e})&&f(o.editable,(e=>e?[...new Set(Object.values(e).flatMap(e=>e?Object.keys(e):[]))]:[])(e)),k=e=>Array.from((e=>e&&e._isArrayMap?Array.from(e.keys()):t.keys(e))(e)).map(Number),V=e=>k(e).every(e=>Number.isInteger(e)),A=e=>{const t=k(e),i=t.length?Math.max(...t):void 0;return void 0===i?0:i+1};let F=0;const w=e=>`${[e.path.replace(/\./g,"-"),"--"].join("")}${++F}`,D=e=>null!=e&&"undefined"!=typeof Event&&(e instanceof Event||null!=e.target),S=(...e)=>{for(const t of e)if(void 0!==t)return t},C=({type:e,value:t,nullable:i,isEmptyArray:s=!1,fallbackValueOption:r=""})=>Array.isArray(t)||s?[]:i||t instanceof Date||"date"===e||"datetime-local"===e?null:"number"==typeof t||"number"===e?0:"boolean"!=typeof t&&"checkbox"!==e&&("string"==typeof t||"file"===e?"":r),x=e=>{let t=String(e??"");return t=t.replace(/\[/g,"."),t=t.replace(/\]/g,""),t},j=(e,{fallbackValueOption:t="",type:i,isEmptyArray:s,separated:r,unified:a,fallback:l})=>e(S(r,a,l,C({fallbackValueOption:t,type:i,isEmptyArray:s}))),_=(e,t,s,r)=>e.incremental&&null!==t&&"object"==typeof t&&i.isEmpty(t)?[]:e.hasIncrementalKeys?((e,t,i)=>{const s=Object.values(e),r=[n.value,n.initial,n.default].includes(t);return i&&r?s.filter(e=>null!=e&&""!==e):s})(t,s,r):t,I=(e,t,s=!1)=>{if(t===n.value||t.startsWith("value.")){const r=e.$output?e.$output(e[n.value]):e[n.value],a=t.startsWith("value.")?i.get(r,t.substring(6)):r;return"string"==typeof a&&i.isEmpty(a)&&s?null:a}return e[t]},P=(e,t=!1)=>{let s=e;return $(s)&&(s=i.transform(s,(e,s)=>{const r=s.split(".");return r.length?i.merge(e,((e,t=!1)=>e.reduceRight((i,s)=>{const r={};if(s.endsWith("[]")){const e=t?[i]:[];return r[s.replace(/\[\]$/,"")]=e,r}const a=e[e.indexOf(s)-1],l=!!a&&a.endsWith("[]")&&e[e.length-1]===s;return!t&&l||(r[s]=i),r},{}))(r,t)):Object.assign(e,{[s]:""})},{})),s},N=(e,t=!0)=>i.transform(e,(e,s,r)=>((e,t)=>null!==e&&"object"==typeof e&&!(e instanceof Date)&&!i.has(e,n.fields)&&!i.has(e,n.class)&&(!y(e,[...u.editable,...u.handlers,...u.validation,...u.functions])||t))(s,t)?Object.assign(e,{[r]:{fields:m(s)?[]:N(s)}}):Object.assign(e,{[r]:s}),{}),M=(e,t,s)=>{if(!i.has(t,h.values))return e;let{values:r}=t;return E({fields:t.fields})&&(r=(e=>i.transform(e,(e,t,s)=>{return Object.assign(e,{[s]:{value:t,fields:(r=t,i.isPlainObject(r)?Object.entries(r).map(([e,t])=>({value:t,name:e})):void 0)}});var r},{}))(r)),i.merge(e,i.transform(r,(t,i,r)=>{Array.isArray(e[r])&&(t[r]=i),r in e||isNaN(Number(r))&&!s||(t[r]=i)},{}))},B=(e,t=!0,s=!0)=>{let r=i.merge(P(e.fields,!1),P(e.struct,!1));return r=(e=>{let t=e;return O(t)&&(t=i.transform(t,(e,t)=>{if(!E({fields:{field:t}})||i.has(t,n.name))return Object.assign(e,{[t.name]:t})},{})),t})(r),r=M(r,e,s),r=N(r,t),r},W=(e,t,s=0,r=!1)=>{const a=(Array.isArray(e)?e:Object.values(e)).filter(e=>"string"==typeof e),l=g(t),o=a.filter(e=>e.startsWith(l)),d=P(o,r),h=l.replace(/\[\]/g,`[${s}]`),u=N(i.get(d,h));return a.length&&a.filter(e=>e.startsWith(t+"[]")).map(e=>e.substring((t+"[].").length)).filter(e=>e.endsWith("[]")).map(e=>e.substring(0,e.length-2)).forEach(e=>{const t=e.split(".");let i=u[0]?.fields;for(let e=0;e<t.length&&(i=i?.[t[e]]?.[n.fields],i);e++);i&&delete i[0]}),u};var H,R,T;!function(e){e.uniqueId="uniqueId",e.fallback="fallback",e.fallbackValue="fallbackValue",e.defaultGenericError="defaultGenericError",e.submitThrowsError="submitThrowsError",e.showErrorsOnInit="showErrorsOnInit",e.showErrorsOnSubmit="showErrorsOnSubmit",e.showErrorsOnBlur="showErrorsOnBlur",e.showErrorsOnChange="showErrorsOnChange",e.showErrorsOnClear="showErrorsOnClear",e.showErrorsOnReset="showErrorsOnReset",e.validateOnInit="validateOnInit",e.validateOnSubmit="validateOnSubmit",e.validateOnBlur="validateOnBlur",e.validateOnChange="validateOnChange",e.validateOnChangeAfterInitialBlur="validateOnChangeAfterInitialBlur",e.validateOnChangeAfterSubmit="validateOnChangeAfterSubmit",e.validateDisabledFields="validateDisabledFields",e.validateDeletedFields="validateDeletedFields",e.validatePristineFields="validatePristineFields",e.validateTrimmedValue="validateTrimmedValue",e.validateOnClear="validateOnClear",e.validateOnReset="validateOnReset",e.strictSet="strictSet",e.strictUpdate="strictUpdate",e.strictDelete="strictDelete",e.strictSelect="strictSelect",e.softDelete="softDelete",e.retrieveOnlyDirtyFieldsValues="retrieveOnlyDirtyFieldsValues",e.retrieveOnlyEnabledFieldsValues="retrieveOnlyEnabledFieldsValues",e.retrieveOnlyEnabledFieldsErrors="retrieveOnlyEnabledFieldsErrors",e.retrieveNullifiedEmptyStrings="retrieveNullifiedEmptyStrings",e.removeNullishValuesInArrays="removeNullishValuesInArrays",e.preserveDeletedFieldsValues="preserveDeletedFieldsValues",e.autoTrimValue="autoTrimValue",e.autoParseNumbers="autoParseNumbers",e.validationDebounceWait="validationDebounceWait",e.validationDebounceOptions="validationDebounceOptions",e.stopValidationOnError="stopValidationOnError",e.validationPluginsOrder="validationPluginsOrder",e.resetValidationBeforeValidate="resetValidationBeforeValidate",e.applyInputConverterOnInit="applyInputConverterOnInit",e.applyInputConverterOnSet="applyInputConverterOnSet",e.applyInputConverterOnUpdate="applyInputConverterOnUpdate",e.bubbleUpErrorMessages="bubbleUpErrorMessages"}(H||(H={})),function(e){e.onSuccess="onSuccess",e.onError="onError"}(R||(R={}));class U{noop=()=>{};state;fields=new l;path;$submitted=0;$submitting=!1;$validated=0;$validating=!1;$clearing=!1;$resetting=!1;$touched=!1;$changed=0;$hooks={};$handlers={};constructor(){a(this,{$submitted:t.observable,$submitting:t.observable,$validated:t.observable,$validating:t.observable,$clearing:t.observable,$resetting:t.observable,$touched:t.observable,$changed:t.observable,$hooks:t.observable,$handlers:t.observable,changed:t.computed,submitted:t.computed,submitting:t.computed,validated:t.computed,validating:t.computed,clearing:t.computed,resetting:t.computed,hasIncrementalKeys:t.computed,hasNestedFields:t.computed,size:t.computed,initField:t.action,submit:t.action,deepUpdate:t.action,set:t.action,add:t.action,del:t.action,move:t.action}),this.fields.onMove=()=>{this.$changed++,this.state.form.$changed++}}execHook=(e,t={},...i)=>S(t[e],this.$hooks[e],this.noop).apply(this,[this,...i]);execHandler=(e,t,i=void 0,s=null,r=!0)=>[S(this.$handlers[e]&&this.$handlers[e].apply(this,[this]),i,this.noop).apply(this,[...t]),r&&this.execHook(s||e,{},...t)];get resetting(){return this.hasNestedFields?this.check(n.resetting,!0):this.$resetting}get clearing(){return this.hasNestedFields?this.check(n.clearing,!0):this.$clearing}get submitted(){return t.toJS(this.$submitted)}get submitting(){return t.toJS(this.$submitting)}get validated(){return t.toJS(this.$validated)}get validating(){return t.toJS(this.$validating)}get hasIncrementalKeys(){return!!this.fields.size&&V(this.fields)}get hasNestedFields(){return 0!==this.fields.size}get size(){return this.fields.size}get changed(){return null!=this.path&&this.hasNestedFields?this.reduce((e,t)=>e+t.changed,0)+this.$changed:this.$changed}intercept=e=>this.MOBXEvent("function"==typeof e?{type:"interceptor",call:e}:{type:"interceptor",...e});observe=e=>this.MOBXEvent("function"==typeof e?{type:"observer",call:e}:{type:"observer",...e});onClear=(...e)=>this.execHandler(n.onClear,e,e=>{D(e)&&e.preventDefault(),this.clear(!0,!1)});onReset=(...e)=>this.execHandler(n.onReset,e,e=>{D(e)&&e.preventDefault(),this.reset(!0,!1)});onSubmit=(...e)=>this.execHandler(n.onSubmit,e,(e,t={})=>{D(e)&&e.preventDefault(),this.submit(t)},null,!1);onAdd=(...e)=>this.execHandler(n.onAdd,e,(e,t)=>{D(e)&&e.preventDefault(),this.add(D(t)?null:t,!1)});onDel=(...e)=>this.execHandler(n.onDel,e,(e,t)=>{D(e)&&e.preventDefault(),this.del(D(t)?this.path:t,!1)});initFields(e,t=!1){const s=this.state.options.get(H.fallback),r=e=>[this.path,e].join(".").replace(/^\.+/,"");let a;a=B(e,this.state.strict,s),a=((e,t)=>{if(t){const s=i.get(t.plugins,"ajv.config.schema");i.isEmpty(e)&&s&&s.properties&&i.each(s.properties,(t,s)=>{i.set(e,s,{value:t.default,label:t.title})})}return e})(a,this.validator),i.forIn(a,(e,i)=>{const a=r(i);if(null==this.select(a,null,!1))if(s)this.initField(i,a,e,t);else{const s=g(a);this.state.struct().filter(e=>e.startsWith(s)).find(e=>"."===e.charAt(s.length)||"[]"===e.substring(s.length,s.length+2)||e===s)&&this.initField(i,a,e,t)}})}initField(e,t,s,r=!1,a){const l=this.state.get("current","props"),o=g(t),d=e=>{const t=i.get(l[e],o);if(![n.input,n.output,n.converter].includes(e)||"function"==typeof t)return t},u={$value:void 0!==a?a:i.get(l[h.values],t),$computed:d(h.computed),$label:d(h.labels),$placeholder:d(h.placeholders),$default:d(h.defaults),$initial:d(h.initials),$disabled:d(h.disabled),$deleted:d(h.deleted),$type:d(h.types),$related:d(h.related),$rules:d(h.rules),$options:d(h.options),$bindings:d(h.bindings),$extra:d(h.extra),$hooks:d(h.hooks),$handlers:d(h.handlers),$validatedWith:d(h.validatedWith),$validators:d(h.validators),$observers:d(h.observers),$interceptors:d(h.interceptors),$converters:d(h.converters),$input:d(h.input),$output:d(h.output),$autoFocus:d(h.autoFocus),$ref:d(h.refs),$nullable:d(h.nullable),$autoComplete:d(h.autoComplete)},c=this.state.form.makeField({key:e,path:t,struct:o,data:s,props:u,update:r,state:this.state},s&&s[n.class]||d(h.classes));return this.fields.merge({[e]:c}),c}validate(e,t){const s=i.merge({},e,{path:this.path});return this.state.form.validator.validate(s,t)}submit(e={},{execOnSubmitHook:i=!0,execValidationHooks:s=!0,validate:r=!0}={}){const a=i?(()=>this.execHook(n.onSubmit,e))():void 0;if(this.$submitting=!0,this.$submitted+=1,!r||!this.state.options.get(H.validateOnSubmit,this))return Promise.resolve(a).then(t.action(()=>this.$submitting=!1)).catch(t.action(e=>{throw this.$submitting=!1,e})).then(()=>this);const l=t=>t?this.execHook(R.onSuccess,e):this.execHook(R.onError,e);return this.validate({showErrors:this.state.options.get(H.showErrorsOnSubmit,this)}).then(({isValid:e})=>{const t=s?l(e):void 0;if(e)return Promise.all([a,t]);const i=this.state.options.get(H.defaultGenericError,this);return this.state.options.get(H.submitThrowsError,this)&&i&&this.invalidate(),Promise.all([a,t])}).then(t.action(()=>this.$submitting=!1)).catch(t.action(e=>{throw this.$submitting=!1,e})).then(()=>this)}check(e,t=!1){return v(o.computed,[e]),t?p({type:u.occurrences[e],data:this.deepCheck(u.occurrences[e],e,this.fields)}):this[e]}deepCheck(e,t,s){const r=c(s);return i.transform(r,(i,s)=>(![n.isValid,n.hasError,n.isDirty,n.isPristine].includes(t)&&s.fields.size&&Array.isArray(s.initial)||i.push(s[t]),i.push(p({data:this.deepCheck(e,t,s.fields),type:e})),i),[])}firstError(){if(!this.state.options.get(H.bubbleUpErrorMessages,this))return null;for(const e of c(this.fields)){if(e.error)return e.error;if(e.fields.size){const t=e.firstError();if(t)return t}}return null}update(e){if(!i.isPlainObject(e))throw new Error("The update() method accepts only plain objects.");this.deepUpdate(B({fields:e},this.state.strict),void 0,void 0,e)}deepUpdate(e,t="",s=!0,r){i.each(e,(e,a)=>{const l=i.has(e,n.name)?e.name:a,o=`${t}.${l}`.replace(/^\.+/,""),d=this.state.options.get(H.strictUpdate,this),h=this.select(o,null,d),u=this.select(t,null,!1)||this.state.form.select(this.path??"",null,!1),p=this.state.options.get(H.applyInputConverterOnUpdate,this);if(null!=h&&void 0!==e){const t=i.get(r,o),s=[this.path??"",o].join(".").replace(/^\.+/,"");if(Array.isArray(t)&&!this.isArrayContainer(s))return void(h.value=j(p?h.$input:e=>e,{fallbackValueOption:this.state.options.get(H.fallbackValue,this),separated:t}));if(Array.isArray(h.values())){const t=Math.max(-1,...Object.keys(e.fields||{}).map(Number));c(h.fields).forEach(e=>{Number(e.name)>t&&(h.$changed++,h.state.form.$changed++,h.fields.delete(e.name))})}if(e?.fields){const e=this.state.options.get(H.fallback),t=this.state.struct().findIndex(e=>e.startsWith(h.path.replace(/\.\d+\./,"[].")+"[]"));if(!e&&0===h.fields.size&&t<0)return void(h.value=j(p?h.$input:e=>e,{fallbackValueOption:this.state.options.get(H.fallbackValue,this),separated:i.get(r,o)}))}if(null===e||null==e.fields)return void(h.value=j(p?h.$input:e=>e,{fallbackValueOption:this.state.options.get(H.fallbackValue,this),separated:e}))}if(null!=u&&null==h){const t=[this.path,o].join(".").replace(/^\.+/,"");u.$changed++,u.state.form.$changed++,u.initField(l,t,e,!0,i.get(r,o))}else if(s)if(i.has(e,n.fields)&&null!=e.fields)this.deepUpdate(e.fields,o,!0,r);else{const e=W(this.state.struct(),o);this.deepUpdate(e,o,!1,r)}})}get(e=null,t=!0){if(null==e)return this.deepGet([...u.computed,...u.editable,...u.validation],this.fields,t);if(v(o.all,Array.isArray(e)?e:[e]),"string"==typeof e){if([n.hooks,n.handlers].includes(e))return this[`$${e}`];if(t&&0===this.fields.size){const i=this.state.options.get(H.retrieveNullifiedEmptyStrings,this);return I(this,e,!!t&&i)}const i=this.deepGet(e,this.fields,t),s=this.state.options.get(H.removeNullishValuesInArrays,this);return _(this,i,e,!!t&&s)}return this.deepGet(e,this.fields,t)}deepGet(e,t,s=!0){const r=c(t),a=i.transform(r,(t,r)=>{if(Object.assign(t,{[r.key]:{fields:(t=>0!==t.size?this.deepGet(e,t,s):void 0)(r.fields)}}),"string"==typeof e){const i=this.state.options,a=i.get(H.retrieveOnlyDirtyFieldsValues,this)&&e===n.value&&r.isPristine||i.get(H.retrieveOnlyEnabledFieldsValues,this)&&e===n.value&&r.disabled||i.get(H.retrieveOnlyEnabledFieldsErrors,this)&&e===n.error&&r.disabled&&r.isValid&&(!r.error||!r.hasError)||i.get(H.softDelete,this)&&e===n.value&&r.deleted;if(0===r.fields.size){if(delete t[r.key],a)return t;const i=this.state.options.get(H.retrieveNullifiedEmptyStrings,this);return Object.assign(t,{[r.key]:I(r,e,!!s&&i)})}let l=this.deepGet(e,r.fields,s);if(e===n.value&&(l=r.$output(l)),delete t[r.key],a)return t;const o=this.state.options.get(H.removeNullishValuesInArrays,this);return Object.assign(t,{[r.key]:_(r,l,e,!!s&&o)})}return i.each(e,e=>Object.assign(t[r.key],{[e]:r[e]})),t},{});if("string"==typeof e&&r.length>0&&V(t)){const e=new Set(Object.keys(a));return r.filter(t=>e.has(String(t.key))).map(e=>a[String(e.key)])}return a}set(e,t){if("string"==typeof e&&void 0!==t){v(o.editable,[e]);const s=[n.hooks,n.handlers].includes(e);if((null!==t&&"object"==typeof t&&e===n.value||i.isPlainObject(t)&&!s)&&this.hasNestedFields)return this.deepSet(e,t,"",!0);if(e===n.value){const e=this.state.options.get(H.applyInputConverterOnSet,this);this.value=j(e?this.$input:e=>e,{fallbackValueOption:this.state.options.get(H.fallbackValue,this),separated:t})}else s?Object.assign(this[`$${e}`],t):i.set(this,`$${e}`,t);return}null==t&&(this.hasNestedFields?this.deepSet(n.value,e,"",!0):this.set(n.value,e))}deepSet(e,t,s="",r=!1){const a=this.state.options.get(H.strictSet,this);null!=t?i.each(t,(t,i)=>{const l=`${s}.${i}`.replace(/^\.+/,""),n=this.select(l,null,a);a&&b(l,n,"You are updating a not existent field:"),void 0!==n&&(void 0!==t&&n.set(e,t,r),n.fields.size&&null!==t&&"object"==typeof t&&this.deepSet(e,t,l,r))}):this.each(e=>e.$value=C({fallbackValueOption:this.state.options.get(H.fallbackValue,this),value:e.$value,nullable:e.$nullable,type:e.type}))}add(e,t=!0){if(O(e))return i.each(e,e=>this.update({[A(this.fields)]:e})),this.$changed++,this.state.form.$changed++,t&&this.execHook(n.onAdd),this;if(this.isPlainArrayField()&&!i.has(e,n.key)&&!i.has(e,n.name)){const s=Array.isArray(this.value)?[...this.value]:[];return s.push(i.has(e,n.value)?e[n.value]:C({fallbackValueOption:this.state.options.get(H.fallbackValue,this),nullable:this.$nullable,type:this.type})),this.set(n.value,s),this.$changed++,this.state.form.$changed++,t&&this.execHook(n.onAdd),this}const s=this.createField(e);return this.$changed++,this.state.form.$changed++,t&&this.execHook(n.onAdd),s}createField(e,t){const s=W(this.state.struct(),this.path??"",0,!0),r=s[0]?.fields??null,a=i.isPlainObject(e)?Object.keys(e).filter(e=>e!==n.key):[],l=!!r&&i.isPlainObject(e)&&!i.has(e,n.value)&&!i.has(e,n.fields)&&a.length>0&&(!i.has(e,n.name)||Object.prototype.hasOwnProperty.call(r,n.name)),o=t??e?.[n.key],d=void 0!==o?o:l||void 0===e?.[n.name]?A(this.fields):e[n.name],h=this.initField(d,(e=>[this.path,e].join(".").replace(/^\.+/,""))(d),l?s[0]:i.merge(s[0],e),!1,i.has(e,n.value)?e[n.value]:void 0),u=i.has(e,n.value)||i.has(e,n.fields);if(l)i.each(a,t=>{const i=h.select(t);i&&!i.hasNestedFields&&i.set(n.value,e[t])});else if(!u)if(s[0]?.fields&&i.isPlainObject(e)&&!y(e,[n.key,n.name]))i.each(e,(e,t)=>{const i=h.select(t);i&&!i.hasNestedFields&&i.set(n.value,e)});else if(!this.state.options.get(H.preserveDeletedFieldsValues,this)){const e=this.state.options.get(H.fallbackValue,this);h.$value=C({fallbackValueOption:e,value:h.$value,nullable:h.$nullable,type:h.type}),h.each(t=>t.$value=C({fallbackValueOption:e,value:t.$value,nullable:t.$nullable,type:t.type}))}return h}isArrayContainer(e){const t=this.state.struct();if(!Array.isArray(t))return!1;const i=(e??"").replace(/\.\d+\./g,"[].");return t.some(e=>"string"==typeof e&&e.startsWith(`${i}[]`))}isPlainArrayField(){return!this.hasNestedFields&&!this.isArrayContainer(this.path??"")&&Array.isArray(this.value)}applyValue(e,t){void 0!==t&&(i.isPlainObject(t)&&e.fields.size?i.each(t,(t,i)=>{const s=e.select(i);s&&(s.fields.size?this.applyValue(s,t):s.set(n.value,t))}):e.set(n.value,t))}applyArrayValue(e,t){c(e.fields).forEach(i=>{Number(i.name)>=t.length&&e.fields.delete(i.name)}),t.forEach((t,s)=>{const r=String(s),a=e.fields.get(r);a?this.applyValue(a,t):e.createField(i.isPlainObject(t)?t:{[n.value]:t},r)})}del(e=null,t=!0){const i=this.state.options.get(H.strictDelete,this),s=x(e??this.path??""),r=[this.path??"",s??""].join(".").replace(/^\.+|\.+$/g,""),a=this.container(e),l=s.split("."),o=l[l.length-1];if(i&&!a.fields.has(o)){b(r,null,`Key "${o}" not found when trying to delete field`)}return a.$changed++,a.state.form.$changed++,this.state.options.get(H.softDelete,this)?this.select(r).set(n.deleted,!0):(a.each(e=>e.debouncedValidation.cancel()),t&&this.execHook(n.onDel),a.fields.delete(o))}MOBXEvent({prop:e=n.value,key:s=null,path:r=null,call:a,type:l}){let d=s||e;v(o.observable,[d]);const h=this.select(r||this.path,null,!1)||this,u=e=>a.apply(null,[{change:e,form:this.state.form,path:h.path||null,field:h.path?h:null}]);let c,p;"observer"===l&&(c=t.observe,p=e=>t.observe(h.fields.toArray(),e)),"interceptor"===l&&(d=`$${e}`,c=t.intercept,p=h.fields.intercept);const f=h.path?`${d}@${h.path}`:d;i.merge(this.state.disposers[l],{[f]:d===n.fields?p.apply(e=>u(e)):c(h,d,e=>u(e))})}dispose(e=null){return this.path&&e?this.disposeSingle(e):this.disposeAll()}disposeAll(){const e=e=>e.apply();i.each(this.state.disposers.interceptor,e),i.each(this.state.disposers.observer,e),this.state.disposers={interceptor:{},observer:{}}}disposeSingle({type:e,key:t=n.value,path:i=null}){const s=x(i??this.path??"");"interceptor"===e&&(t=`$${t}`);const r=this.state.disposers[e];r[`${t}@${s}`].apply(),delete r[`${t}@${s}`]}select(e,t=null,s=!0){const r=x(String(e)).split("."),a=r[0];r.shift();let l=null==t?this.fields.get(a):t.get(a),n=!1;return i.each(r,e=>{n||(null==l?(l=void 0,n=!0):l=l.fields.get(e))}),s&&this.state.options.get(H.strictSelect,this)&&b(String(e),l),l}container(e){const t=x(e??this.path??"").replace(/[^./]+$/,"").replace(/^\.+|\.+$/g,"");return this.path&&null==e?""!==t?this.state.form.select(t,null,!1):this.state.form:""!==t?this.select(t,null,!1):this}has(e){return this.fields.has(e)}map(e){return c(this.fields).map(e)}each(e,t=null,i=0){const s=t||this.fields;c(s).forEach((t,s)=>{e(t,s,i),0!==t.fields.size&&this.each(e,t.fields,i+1)})}reduce(e,t){return c(this.fields).reduce(e,t)}move(e,t){this.fields.move(e,t)}$(e){return this.select(e)}values(){return this.get(n.value)}errors(){return this.get(n.error)}labels(){return this.get(n.label)}placeholders(){return this.get(n.placeholder)}defaults(){return this.get(n.default)}initials(){return this.get(n.initial)}types(){return this.get(n.type)}}class z{promises=[];form=null;drivers={};plugins={vjf:void 0,dvr:void 0,ajv:void 0,yup:void 0,zod:void 0,joi:void 0,valibot:void 0,vinejs:void 0};error=null;constructor(e){a(this,{error:t.observable,validate:t.action,validateField:t.action}),this.form=e.form,Object.assign(this.plugins,e.plugins),this.initDrivers()}initDrivers(){Object.entries(this.plugins).forEach(([e,t])=>{this.drivers[e]=t&&t.class&&new t.class({config:t.config,state:this.form.state,promises:this.promises})})}validate(e,i){const s=S(e?.path,e),r=S(e?.field,this.form.select(s,null,!1),this.form),a=S(e?.related,i?.related,!0),l=S(e?.showErrors,i?.showErrors,!1);return r.$validating=!0,r.$validated+=1,this.error=null,new Promise(e=>{(r.path||"string"==typeof s)&&this.validateField({field:r,showErrors:l,related:a,path:s}),r.each(e=>this.validateField({path:e.path,field:e,showErrors:l,related:a})),e(Promise.all(this.promises.splice(0)))}).then(t.action(()=>{r.$validating=!1,r.$clearing=!1,r.$resetting=!1})).catch(t.action(e=>{throw r.$validating=!1,r.$clearing=!1,r.$resetting=!1,e})).then(()=>r)}validateField({showErrors:e=!1,related:t=!1,field:s=null,path:r}){const a=s||this.form.select(r),{options:l}=this.form.state;if(!a.path)throw new Error("Validation Error: Invalid Field Instance");if(a.deleted&&!l.get(H.validateDeletedFields,a))return;if(a.disabled&&!l.get(H.validateDisabledFields,a))return;if(a.isPristine&&!l.get(H.validatePristineFields,a))return;l.get(H.resetValidationBeforeValidate,a)&&a.resetValidation(),l.get(H.validateTrimmedValue,a)&&a.trim();const n=l.get(H.stopValidationOnError,a),o=l.get(H.validationPluginsOrder,a),d=o?o.map(e=>this.drivers[e]):this.drivers;i.each(d,e=>{e&&e.validate(a),!n||a.hasError}),a.showErrors(e,!1),t&&this.validateRelatedFields(a,e)}validateRelatedFields(e,t){e.related&&e.related.length&&e.related.map(e=>this.validateField({related:!1,showErrors:t,path:e}))}}class K{options={uniqueId:w,fallback:!0,fallbackValue:"",defaultGenericError:null,submitThrowsError:!0,showErrorsOnInit:!1,showErrorsOnSubmit:!0,showErrorsOnBlur:!0,showErrorsOnChange:!0,showErrorsOnClear:!1,showErrorsOnReset:!0,validateOnInit:!0,validateOnSubmit:!0,validateOnBlur:!0,validateOnChange:!1,validateOnChangeAfterInitialBlur:!1,validateOnChangeAfterSubmit:!1,validateOnClear:!1,validateOnReset:!1,validateDisabledFields:!1,validateDeletedFields:!1,validatePristineFields:!0,strictSet:!1,strictUpdate:!1,strictDelete:!0,strictSelect:!0,softDelete:!1,retrieveOnlyDirtyFieldsValues:!1,retrieveOnlyEnabledFieldsValues:!1,retrieveOnlyEnabledFieldsErrors:!1,retrieveNullifiedEmptyStrings:!1,autoTrimValue:!1,autoParseNumbers:!1,removeNullishValuesInArrays:!1,preserveDeletedFieldsValues:!1,validationDebounceWait:250,validationDebounceOptions:{leading:!1,trailing:!0},stopValidationOnError:!1,validationPluginsOrder:void 0,resetValidationBeforeValidate:!0,validateTrimmedValue:!1,applyInputConverterOnInit:!0,applyInputConverterOnSet:!0,applyInputConverterOnUpdate:!0,bubbleUpErrorMessages:!1};constructor(){a(this,{options:t.observable,set:t.action})}get(e="",s=null){return i.has(s,"path")&&i.has(s.$options,e)?s.$options[e]:e?i.get(this.options,e):t.toJS(this.options)}set(e){t.set(this.options,e)}}class G{templates={};rewriters={default:{id:n.id,name:n.name,type:n.type,value:n.value,checked:n.checked,label:n.label,placeholder:n.placeholder,disabled:n.disabled,autoComplete:n.autoComplete,onChange:n.onChange,onBlur:n.onBlur,onFocus:n.onFocus,autoFocus:n.autoFocus,inputMode:n.inputMode,onKeyUp:n.onKeyUp,onKeyDown:n.onKeyDown}};register(e){return i.each(e,(e,t)=>{"function"==typeof e&&i.merge(this.templates,{[t]:e}),i.isPlainObject(e)&&i.merge(this.rewriters,{[t]:e})}),this}load(e,t=n.default,s){const r={keys:i.get(this.rewriters,n.default),form:e.state.form,field:e,props:s,$try:S};if(i.has(this.templates,t))return i.get(this.templates,t)(r);if(i.has(this.rewriters,t)){const r={};return i.each(i.get(this.rewriters,t),(t,a)=>i.merge(r,{[t]:S(s[a],e[a])})),r}if(i.has(this.templates,t))return i.get(this.templates,t)(r);if(t===n.default){const t={};return i.each(i.get(this.rewriters,n.default),(r,a)=>i.merge(t,{[r]:S(s[a],e[a])})),t}throw new Error(`Bindings: template or rewriter "${t}" does not exist — register it or use the "default" binding`)}}!function(e){e.mixed="mixed",e.unified="unified",e.separated="separated"}(T||(T={}));class q{mode=T.mixed;strict=!1;form;options;bindings;$extra;$struct=[];disposers={interceptor:{},observer:{}};initial={props:{},fields:{}};current={props:{},fields:{}};constructor({form:e,initial:t,options:i,bindings:s}){this.set("form",e),this.initProps(t),this.options=new K,this.options.set(i),this.bindings=new G,this.bindings.register(s),this.observeOptions()}initProps(e={}){const t=[...u.editable,...u.separated,...u.validation,...u.functions,...u.handlers],i=Object.fromEntries(Object.entries(e).filter(([e])=>t.includes(e)));this.set("initial","props",i);const s=E(e),r=(e=>y(e,u.separated)||y(e,u.validation))(e);if((r||$(e.fields))&&!s){const t=S(e.struct,e.fields);return this.struct(t),this.strict=!0,void(this.mode=T.separated)}this.struct(e.struct),this.mode=T.unified}struct(e=null){return e&&(this.$struct=e),this.$struct}get(e,t){return this[e][t]}set(e,t,i=null){"form"===e&&(this.form=t),"initial"===e&&(Object.assign(this.initial[t],i),Object.assign(this.current[t],i)),"current"===e&&Object.assign(this.current[t],i)}extra(e=null){return"string"==typeof e?i.get(this.$extra,e):null===e?this.$extra:(this.$extra=e,null)}observeOptions(){var e;t.observe(this.options.options,(e=[{type:"update",key:H.validateOnChange,to:!0,exec:()=>this.form.each(e=>e.observeValidationOnChange())},{type:"update",key:H.validateOnChange,to:!1,exec:()=>this.form.each(e=>{"function"==typeof e.disposeValidationOnChange&&e.disposeValidationOnChange()})},{type:"update",key:H.validateOnBlur,to:!0,exec:()=>this.form.each(e=>e.observeValidationOnBlur())},{type:"update",key:H.validateOnBlur,to:!1,exec:()=>this.form.each(e=>{"function"==typeof e.disposeValidationOnBlur&&e.disposeValidationOnBlur()})}],t=>e.map((e=>({key:t,to:i,type:s,exec:r})=>e.type===s&&e.name===t&&e.newValue===i&&r.apply(e,[e]))(t))))}}const J=(e,t)=>"function"!=typeof t?t:t({field:e,form:e.state.form}),X=e=>"function"==typeof e?e:void 0,L=(e,t)=>"function"==typeof e[`_${t}`]?e[`_${t}`].apply(e,[{form:e.state.form,field:e}]):e[`$${t}`],Y=(e,t,i)=>Object.assign(e,{_label:X(t.$label??i?.label),_placeholder:X(t.$placeholder??i?.placeholder),_disabled:X(t.$disabled??i?.disabled),_rules:X(t.$rules??i?.rules),_related:X(t.$related??i?.related),_deleted:X(t.$deleted??i?.deleted),_validators:X(t.$validators??i?.validators),_validatedWith:X(t.$validatedWith??i?.validatedWith),_bindings:X(t.$bindings??i?.bindings),_extra:X(t.$extra??i?.extra),_options:X(t.$options??i?.options),_autoFocus:X(t.$autoFocus??i?.autoFocus),_inputMode:X(t.$inputMode??i?.inputMode),$label:J(e,t.$label??i?.label??""),$placeholder:J(e,t.$placeholder??i?.placeholder??""),$disabled:J(e,t.$disabled??i?.disabled??!1),$rules:J(e,t.$rules??i?.rules??null),$related:J(e,t.$related??i?.related??[]),$deleted:J(e,t.$deleted??i?.deleted??!1),$validatedWith:J(e,t.$validatedWith??i?.validatedWith??n.value),$bindings:J(e,t.$bindings??i?.bindings??n.default),$extra:J(e,t.$extra??i?.extra??null),$options:J(e,t.$options??i?.options??{}),$autoFocus:J(e,t.$autoFocus??i?.autoFocus??!1),$inputMode:J(e,t.$inputMode??i?.inputMode??void 0),$validators:J(e,t.$validators??i?.validators??null),$hooks:t.$hooks??i?.hooks??{},$handlers:t.$handlers??i?.handlers??{},$observers:t.$observers??i?.observers??null,$interceptors:t.$interceptors??i?.interceptors??null,$ref:t.$ref??i?.ref??void 0,$nullable:t.$nullable??i?.nullable??!1,$autoComplete:t.$autoComplete??i?.autoComplete??void 0}),Q=(e,t,i,s,{isEmptyArray:r,fallbackValueOption:a})=>j(e=>e,{isEmptyArray:r,type:e.type,unified:s?C({fallbackValueOption:a,type:e.type,value:e.value}):t?.default,separated:i.$default,fallback:e.$initial});class Z extends U{hasInitialNestedFields=!1;incremental=!1;id;key;name;$observers;$interceptors;$converter=e=>e;$input=e=>e;$output=e=>e;_value;_label;_placeholder;_disabled;_rules;_related;_deleted;_validatedWith;_validators;_bindings;_extra;_options;_autoFocus;_inputMode;$options=void 0;$value=void 0;$type=void 0;$label=void 0;$placeholder=void 0;$default=void 0;$initial=void 0;$bindings=void 0;$extra=void 0;$related=void 0;$validatedWith=void 0;$validators=void 0;$rules=void 0;$disabled=!1;$focused=!1;$blurred=!1;$deleted=!1;$autoFocus=!1;$inputMode=void 0;$ref=void 0;$nullable=!1;$autoComplete=void 0;showError=!1;errorSync=null;errorAsync=null;validationErrorStack=[];validationFunctionsData=[];validationAsyncData={valid:!0,message:null};debouncedValidation;disposeValidationOnBlur;disposeValidationOnChange;files=void 0;constructor({key:e,path:s,struct:r,data:l={},props:o={},update:d=!1,state:h}){super(),a(this,{$options:t.observable,$value:t.observable,$type:t.observable,$label:t.observable,$placeholder:t.observable,$default:t.observable,$initial:t.observable,$bindings:t.observable,$extra:t.observable,$related:t.observable,$validatedWith:t.observable,$validators:t.observable,$rules:t.observable,$disabled:t.observable,$focused:t.observable,$blurred:t.observable,$deleted:t.observable,showError:t.observable,errorSync:t.observable,errorAsync:t.observable,validationErrorStack:t.observable,validationFunctionsData:t.observable,validationAsyncData:t.observable,files:t.observable,autoFocus:t.computed,inputMode:t.computed,ref:t.computed,checkValidationErrors:t.computed,checked:t.computed,value:t.computed,initial:t.computed,default:t.computed,actionRunning:t.computed,type:t.computed,label:t.computed,placeholder:t.computed,extra:t.computed,options:t.computed,bindings:t.computed,related:t.computed,disabled:t.computed,rules:t.computed,validators:t.computed,validatedValue:t.computed,error:t.computed,hasError:t.computed,isValid:t.computed,isDefault:t.computed,isDirty:t.computed,isPristine:t.computed,isEmpty:t.computed,blurred:t.computed,touched:t.computed,deleted:t.computed,setupField:t.action,initNestedFields:t.action,invalidate:t.action,setValidationAsyncData:t.action,resetValidation:t.action,clear:t.action,reset:t.action,focus:t.action,blur:t.action,showErrors:t.action,update:t.action}),this.state=h,this.setupField(e,s,r,l,o,d),this.initNestedFields(l,d),this.incremental=this.hasIncrementalKeys,this.debouncedValidation=i.debounce(this.validate,this.state.options.get(H.validationDebounceWait,this),this.state.options.get(H.validationDebounceOptions,this)),this.observeValidationOnBlur(),this.observeValidationOnChange(),this.initMOBXEvent(n.observers),this.initMOBXEvent(n.interceptors),t.runInAction(()=>Object.assign(this.$hooks,this.hooks?.apply(this,[this]))),t.runInAction(()=>Object.assign(this.$handlers,this.handlers?.apply(this,[this]))),this.execHook(n.onInit),t.autorun(()=>this.changed&&this.execHook(n.onChange))}get checkValidationErrors(){return!this.validationAsyncData.valid||!i.isEmpty(this.validationErrorStack)||"string"==typeof this.errorAsync||"string"==typeof this.errorSync}set value(e){let t=e;"string"==typeof t&&this.state.options.get(H.autoTrimValue,this)&&(t=t.trim()),this.$value!==t&&(this.handleSetNumberValue(t)||(this.$value=this.$converter(t),this.$changed++,this.actionRunning||this.state.form.$changed++))}handleSetNumberValue(e){return!!this.state.options.get(H.autoParseNumbers,this)&&("number"!=typeof this.$initial&&"number"!=this.type||!new RegExp("^-?\\d+(,\\d+)*(\\.\\d+([eE]\\d+)?)?$","g").exec(e)?void 0:(this.$value=this.$converter(Number(e)),this.$changed++,this.actionRunning||this.state.form.$changed++,!0))}get actionRunning(){return this.submitting||this.clearing||this.resetting}get checked(){return"checkbox"===this.type?this.value:void 0}get value(){return"function"!=typeof this._value||this.hasNestedFields?this.getComputedProp(n.value):L(this,n.value)}get initial(){return this.$initial?t.toJS(this.$initial):this.getComputedProp(n.initial)}get default(){return this.$default?t.toJS(this.$default):this.getComputedProp(n.default)}set initial(e){this.$initial=e}set default(e){this.$default=e}get nullable(){return L(this,n.nullable)}get autoComplete(){return L(this,n.autoComplete)}get ref(){return L(this,n.ref)}get extra(){return L(this,n.extra)}get autoFocus(){return L(this,n.autoFocus)}get inputMode(){return L(this,n.inputMode)}get type(){return L(this,n.type)}get label(){return L(this,n.label)}get placeholder(){return L(this,n.placeholder)}get options(){return L(this,n.options)}get bindings(){return L(this,n.bindings)}get related(){return L(this,n.related)}get disabled(){return L(this,n.disabled)}get rules(){return L(this,n.rules)}get validators(){return L(this,n.validators)}get validatedWith(){return L(this,n.validatedWith)}get validatedValue(){return I(this,this.validatedWith)}get error(){return!1===this.showError?null:this.errorAsync||this.errorSync||this.firstError()||null}get hasError(){return this.checkValidationErrors||this.check(n.hasError,!0)}get isValid(){return!this.checkValidationErrors&&this.check(n.isValid,!0)}get isDefault(){return!i.isNil(this.default)&&i.isEqual(this.default,this.value)}get isDirty(){const e=this.changed?this.value:this.initial;return!i.isEqual(this.initial,e)||this.deleted}get isPristine(){const e=this.changed?this.value:this.initial;return i.isEqual(this.initial,e)&&!this.deleted}get isEmpty(){return this.hasNestedFields?this.check(n.isEmpty,!0):"boolean"==typeof this.value?!!this.$value:"number"!=typeof this.value&&(!(this.value instanceof Date)&&(null!==this.value&&i.isEmpty(this.value)))}get focused(){return this.hasNestedFields?this.check(n.focused,!0):this.$focused}get blurred(){return this.hasNestedFields?this.check(n.blurred,!0):this.$blurred}get touched(){return this.hasNestedFields?this.check(n.touched,!0):this.$touched}get deleted(){return!!this.$deleted||!!this.hasNestedFields&&this.check(n.deleted,!0)}sync=t.action((e,t=null)=>{const s=e=>((e,t)=>"boolean"==typeof t&&"boolean"==typeof e.target.checked)(e,this.value)?e.target.checked:e.target.value;let r;i.isNil(e)||i.isNil(e.target)?(i.isNil(t)||i.isNil(t.target)||(t=s(t)),r=S(e,t)):r=s(e),this.hasNestedFields&&Array.isArray(r)?this.state.form.applyArrayValue(this,r):this.value=r});onSync=(...e)=>"file"===this.type?this.onDrop(...e):this.execHandler(n.onChange,e,this.sync,n.onSync);onChange=this.onSync;onToggle=(...e)=>this.execHandler(n.onToggle,e,this.sync);onBlur=(...e)=>this.execHandler(n.onBlur,e,t.action(()=>{this.$focused=!1,this.$blurred=!0}));onFocus=(...e)=>this.execHandler(n.onFocus,e,t.action(()=>{this.$focused=!0,this.$touched=!0}));onDrop=(...e)=>this.execHandler(n.onDrop,e,t.action(()=>{const t=e[0];let i=null;var s;D(t)&&(s=t,s?.target?.files&&0!==s.target.files.length)&&(i=Array.from(t.target.files));const r=i||e,a=this.files||[],l=new Set(a.map(e=>[e?.name,e?.size,e?.lastModified].join("|")));this.files=[...a,...r.filter(e=>{if(!e||"number"!=typeof e.size)return!0;const t=[e.name,e.size,e.lastModified].join("|");return!l.has(t)&&(l.add(t),!0)})]}));onKeyDown=(...e)=>this.execHandler(n.onKeyDown,e);onKeyUp=(...e)=>this.execHandler(n.onKeyUp,e);setupField(e,t,s,r,a,l){this.key=e,this.path=t,this.id=this.state.options.get(H.uniqueId)?.apply(this,[this]);const n=this.state.options.get(H.fallbackValue,this),o=this.state.options.get(H.applyInputConverterOnInit,this),d=((e,t)=>!!$(e)&&(!!e.filter(e=>e.startsWith(t)).find(e=>"[]"===e.substring(t.length))||(e?.find(e=>e===t)?.endsWith("[]")??!1)))(this.state.struct(),g(this.path??"")),{$type:h,$input:u,$output:c,$converter:p,$converters:f,$computed:v}=a;if(i.isPlainObject(r)){const{type:t,input:i,output:s,converter:b,converters:g,computed:y}=r;this.name=r.name??String(e),this.$type=h||t||"text",this.$converter=S(p,f,b,g,this.$converter),this.$input=S(u,i,this.$input),this.$output=S(c,s,this.$output);const m=j(o?this.$input:e=>e,{fallbackValueOption:n,isEmptyArray:d,type:this.type,unified:y||r.value,separated:v||a.$value,fallback:a.$initial});return this._value=X(m),this.$value="function"==typeof this._value?J(this,m):m,this.$initial=j(e=>e,{fallbackValueOption:n,isEmptyArray:d,type:this.type,unified:r.initial,separated:a.$initial,fallback:this.$value}),this.$default=Q(this,r,a,l,{fallbackValueOption:n,isEmptyArray:d}),void Y(this,a,r)}this.name=String(e),this.$type=h||"text",this.$converter=S(p,f,this.$converter),this.$input=S(u,this.$input),this.$output=S(c,this.$output);const b=j(o?this.$input:e=>e,{fallbackValueOption:n,isEmptyArray:d,type:this.type,unified:v||r,separated:v||a.$value});this._value=X(b),this.$value="function"==typeof this._value?J(this,b):b,this.$initial=j(e=>e,{fallbackValueOption:n,isEmptyArray:d,type:this.type,unified:r,separated:a.$initial,fallback:this.$value}),this.$default=Q(this,r,a,l,{fallbackValueOption:n,isEmptyArray:d}),Y(this,a,r)}getComputedProp(e){if(this.incremental||this.hasNestedFields)return e===n.value?this.get(e,!1):t.untracked(()=>this.get(e,!1));const i=this[`$${e}`];return Array.isArray(i)||t.isObservableArray(i)?[].slice.call(i):t.toJS(i)}initNestedFields(e,t){const s=i.isNil(e)?null:e.fields;Array.isArray(s)&&!i.isEmpty(s)&&(this.hasInitialNestedFields=!0),this.initFields({fields:s},t),!t&&Array.isArray(s)&&i.isEmpty(s)&&Array.isArray(this.value)&&!i.isEmpty(this.value)&&(this.hasInitialNestedFields=!0,this.initFields({fields:s,values:this.value},t))}invalidate(e,t=!0,i=!1){return!0===i?(this.errorAsync=e,void this.showErrors(!0,t)):Array.isArray(e)?(this.validationErrorStack=e,void this.showErrors(!0,t)):(this.validationErrorStack.unshift(e),void this.showErrors(!0,t))}setValidationAsyncData(e=!1,t=null){this.validationAsyncData={valid:e,message:t}}resetValidation(e=!1){this.showError=!1,this.errorSync=null,this.errorAsync=null,this.validationAsyncData={valid:!0,message:null},this.validationFunctionsData=[],this.validationErrorStack=[],Promise.resolve().then(t.action(()=>{this.$resetting=!1,this.$clearing=!1})),e&&this.each(t=>t.resetValidation(e))}clear(e=!0,t=!0){t&&this.execHook(n.onClear),this.$clearing=!0,this.$touched=!1,this.$blurred=!1,this.$changed=0,this.files=void 0,this.$value=C({fallbackValueOption:this.state.options.get(H.fallbackValue),value:this.$value,nullable:this.$nullable,type:this.type}),this.isArrayContainer(this.path??"")&&Array.isArray(this.value)?c(this.fields).forEach(e=>this.fields.delete(e.name)):e&&this.each(t=>t.clear(e)),this.state.options.get(H.validateOnClear,this)?this.validate({showErrors:this.state.options.get(H.showErrorsOnClear,this)}):this.resetValidation(e)}reset(e=!0,t=!0){t&&this.execHook(n.onReset),this.$resetting=!0,this.$touched=!1,this.$blurred=!1,this.$changed=0,this.files=void 0;const s=this.$default!==this.$initial,r=s?this.$default:this.$initial;if(this.isArrayContainer(this.path??"")&&!s&&Array.isArray(r)){const t=r,s=c(this.fields);s.length===t.length&&s.every((e,s)=>i.isEqual(e.value,t[s]))?e&&this.each(t=>t.reset(e)):(s.forEach(e=>this.fields.delete(e.name)),t.forEach((e,t)=>this.createField(i.isPlainObject(e)?e:{[n.value]:e},String(t))))}else s&&(this.value=this.$default),s||(this.value=this.$initial),e&&this.each(t=>t.reset(e));this.state.options.get(H.validateOnReset,this)?this.validate({showErrors:this.state.options.get(H.showErrorsOnReset,this)}):this.resetValidation(e)}focus(){this.ref&&!this.focused&&this.ref.focus(),this.$focused=!0,this.$touched=!0}blur(){this.ref&&this.focused&&this.ref.blur(),this.$focused=!1,this.$blurred=!0}trim(){"string"==typeof this.value&&(this.$value=this.value.trim())}showErrors(e=!0,t=!0){this.showError=e,this.errorSync=this.validationErrorStack.length?this.validationErrorStack[0]:null,this.errorAsync=this.validationAsyncData.valid?null:this.validationAsyncData.message,t&&this.each(i=>i.showErrors(e,t))}observeValidationOnBlur(){const e=this.state.options;e.get(H.validateOnBlur,this)&&(this.disposeValidationOnBlur=t.observe(this,"$focused",t=>!1===t.newValue&&this.debouncedValidation({showErrors:e.get(H.showErrorsOnBlur,this)})))}observeValidationOnChange(){const e=this.state.options;e.get(H.validateOnChange,this)?this.disposeValidationOnChange=t.observe(this,"$value",()=>!this.actionRunning&&this.debouncedValidation({showErrors:e.get(H.showErrorsOnChange,this)})):(e.get(H.validateOnChangeAfterInitialBlur,this)||e.get(H.validateOnChangeAfterSubmit,this))&&(this.disposeValidationOnChange=t.observe(this,"$value",()=>!this.actionRunning&&(e.get(H.validateOnChangeAfterInitialBlur,this)&&this.blurred||e.get(H.validateOnChangeAfterSubmit,this)&&this.state.form.submitted)&&this.debouncedValidation({showErrors:e.get(H.showErrorsOnChange,this)})))}initMOBXEvent(e){const t=this[`$${e}`];if(!Array.isArray(t))return;let s;e===n.observers&&(s=this.observe),e===n.interceptors&&(s=this.intercept),t.map(e=>s(i.omit(e,n.path)))}bind(e={}){return{...this.state.bindings.load(this,this.bindings,e),ref:e=>this.$ref=e}}update(e){if(!i.isPlainObject(e))throw new Error("The update() method accepts only plain objects.");const t=this.state.options.get(H.fallback,this),s=this.state.options.get(H.applyInputConverterOnUpdate,this),r=this.state.struct().findIndex(e=>e.startsWith((this.path??"").replace(/\.\d+\./,"[].")+"[]"));!t&&0===this.fields.size&&r<0?this.value=j(s?this.$input:e=>e,{fallbackValueOption:this.state.options.get(H.fallbackValue,this),separated:e}):super.update(e)}}class ee extends U{name;path=null;extra={};validator;debouncedValidation=null;constructor(e={},{name:s="",options:r={},plugins:l={},bindings:o={},hooks:d={},handlers:h={},extra:u={}}={}){super(),a(this,{extra:t.observable,fields:t.observable,flatMapValues:t.computed,error:t.computed,hasError:t.computed,isValid:t.computed,isPristine:t.computed,isDirty:t.computed,isDefault:t.computed,isEmpty:t.computed,focused:t.computed,touched:t.computed,disabled:t.computed,invalidate:t.action,clear:t.action,reset:t.action,resetValidation:t.action}),this.name=s,this.extra=u,t.runInAction(()=>this.$hooks=d),t.runInAction(()=>this.$handlers=h),globalThis.__MOBX_FORMKIT_DEVTOOLS_HOOK__?.emit?.({type:"form:new",key:this.name,form:this});const c=i.each({setup:e,options:r,plugins:l,bindings:o},(e,t)=>"function"==typeof this[t]?i.merge(e,this[t].apply(this,[this])):e);t.runInAction(()=>Object.assign(this.$hooks,this.hooks?.apply(this,[this]))),t.runInAction(()=>Object.assign(this.$handlers,this.handlers?.apply(this,[this]))),this.state=new q({form:this,initial:c.setup,options:c.options,bindings:c.bindings}),this.validator=new z({form:this,plugins:c.plugins}),this.initFields(c.setup),this.debouncedValidation=i.debounce(this.validate,this.state.options.get(H.validationDebounceWait),this.state.options.get(H.validationDebounceOptions)),this.state.options.get(H.validateOnInit)&&this.validator.validate({showErrors:this.state.options.get(H.showErrorsOnInit)}),this.execHook(n.onInit),t.autorun(()=>this.$changed&&this.execHook(n.onChange))}get flatMapValues(){const e={};return this.each(t=>e[t.path]=t.validatedValue),e}get error(){return this.validator.error||this.firstError()||null}get hasError(){return!!this.validator.error||this.check(n.hasError,!0)}get isValid(){return!this.validator.error&&this.check(n.isValid,!0)}get isPristine(){return this.check(n.isPristine,!0)}get isDirty(){return this.check(n.isDirty,!0)}get isDefault(){return this.check(n.isDefault,!0)}get isEmpty(){return this.check(n.isEmpty,!0)}get focused(){return this.check(n.focused,!0)}get touched(){return this.check(n.touched,!0)}get disabled(){return this.check(n.disabled,!0)}makeField(e,t=Z){return new t(e)}$(e){return super.$(e)}select(e,t=null,i=!0){return super.select(e,t,i)}values(){return super.values()}invalidate(e=null,t=!0){this.debouncedValidation.cancel(),this.validator.error=e||this.state.options.get(H.defaultGenericError)||null,t&&this.each(e=>e.debouncedValidation.cancel())}showErrors(e=!0){this.each(t=>t.showErrors(e))}resetValidation(e=!0){this.validator.error=null,e&&this.each(t=>t.resetValidation(e))}clear(e=!0,t=!0){t&&this.execHook(n.onClear),this.$touched=!1,this.$changed=0,e&&this.each(t=>t.clear(e))}reset(e=!0,t=!0){t&&this.execHook(n.onReset),this.$touched=!1,this.$changed=0,e&&this.each(t=>t.reset(e))}}e.ArrayMap=l,e.Field=Z,e.Form=ee,e.default=ee,Object.defineProperty(e,"__esModule",{value:!0})});
1
+ !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("mobx"),require("lodash")):"function"==typeof define&&define.amd?define(["exports","mobx","lodash"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).MobxFormkit={},e.mobx,e._)}(this,function(e,t,i){"use strict";function s(e){var t=Object.create(null);return e&&Object.keys(e).forEach(function(i){if("default"!==i){var s=Object.getOwnPropertyDescriptor(e,i);Object.defineProperty(t,i,s.get?s:{enumerable:!0,get:function(){return e[i]}})}}),t.default=e,Object.freeze(t)}const r=s(t),a=(e,t)=>"function"==typeof r.makeObservable?r.makeObservable(e,t):function(e,t){const i=Object.entries(t).filter(([t])=>t in e),s=e=>e===r.computed||"computed"===e,a=e=>e===r.action||"action"===e,l=t=>{let i,s=Object.getPrototypeOf(e);for(;s&&void 0===i;)i=Object.getOwnPropertyDescriptor(s,t),s=Object.getPrototypeOf(s);return i};i.forEach(([t,i])=>{if(s(i)){const i=Object.getOwnPropertyDescriptor(e,t);if(!i||"function"!=typeof i.get){const i=l(t),s=i&&"function"==typeof i.get?i.get:null,r=i&&"function"==typeof i.set?i.set:null;Object.defineProperty(e,t,{configurable:!0,enumerable:!!i&&i.enumerable,get:s?()=>s.call(e):()=>{},set:r?t=>r.call(e,t):void 0})}}else if(a(i)){const i=e[t];"function"!=typeof i||Object.prototype.hasOwnProperty.call(e,t)||Object.defineProperty(e,t,{configurable:!0,writable:!0,enumerable:!1,value:i})}});const n={};return i.forEach(([e,t])=>{s(t)?n[e]=r.computed:a(t)?n[e]=r.action:n[e]=r.observable}),r.decorate(e,n),e}(e,t);class l{_isArrayMap=!0;onMove;_entries=t.observable.array([]);constructor(e){e&&e.length>0&&this._entries.replace(e)}get size(){return this._entries.length}get(e){const t=this._entries.find(([t])=>t===e);return t?t[1]:void 0}set(e,t){const i=this._entries.find(([t])=>t===e);return i?i[1]=t:this._entries.push([e,t]),this}has(e){return this._entries.some(([t])=>t===e)}delete(e){const t=this._entries.findIndex(([t])=>t===e);return-1!==t&&(this._entries.splice(t,1),!0)}clear(){this._entries.clear()}keys(){return this._entries.map(([e])=>e)[Symbol.iterator]()}values(){return this._entries.map(([,e])=>e)[Symbol.iterator]()}entries(){return this._entries[Symbol.iterator]()}forEach(e,t){this._entries.forEach(([i,s])=>{e.call(t,s,i,this)})}toJSON(){const e={};return this._entries.forEach(([t,i])=>{e[String(t)]=i}),e}toString(){return"[object ArrayMap]"}merge(e){return e&&"object"==typeof e&&(e.forEach&&"function"==typeof e.forEach?e.forEach((e,t)=>{this.set(t,e)}):Array.isArray(e)?e.forEach(([e,t])=>{this.set(e,t)}):Object.keys(e).forEach(t=>{this.set(t,e[t])})),this}replace(e){return this.clear(),this.merge(e)}get intercept(){return this._entries.intercept}[Symbol.iterator](){return this._entries[Symbol.iterator]()}move(e,i){t.runInAction(()=>{if(e<0||e>=this._entries.length)return;if(i<0||i>=this._entries.length)return;if(e===i)return;const[t]=this._entries.splice(e,1);this._entries.splice(i,0,t),this.onMove?.()})}toArray(){return this._entries}}var n,o,d,h;!function(e){e.key="key",e.id="id",e.path="path",e.name="name",e.fields="fields",e.ref="ref",e.type="type",e.computed="computed",e.value="value",e.initial="initial",e.default="default",e.checked="checked",e.label="label",e.placeholder="placeholder",e.error="error",e.validatedWith="validatedWith",e.validators="validators",e.rules="rules",e.related="related",e.options="options",e.extra="extra",e.bindings="bindings",e.hooks="hooks",e.handlers="handlers",e.converter="converter",e.input="input",e.output="output",e.interceptors="interceptors",e.observers="observers",e.disabled="disabled",e.deleted="deleted",e.blurred="blurred",e.validating="validating",e.submitting="submitting",e.clearing="clearing",e.resetting="resetting",e.changed="changed",e.touched="touched",e.focused="focused",e.isEmpty="isEmpty",e.isDefault="isDefault",e.isPristine="isPristine",e.isDirty="isDirty",e.isValid="isValid",e.hasError="hasError",e.onInit="onInit",e.onSync="onSync",e.onChange="onChange",e.onBlur="onBlur",e.onFocus="onFocus",e.onToggle="onToggle",e.onDrop="onDrop",e.onSubmit="onSubmit",e.onReset="onReset",e.onClear="onClear",e.onAdd="onAdd",e.onDel="onDel",e.autoFocus="autoFocus",e.inputMode="inputMode",e.onKeyDown="onKeyDown",e.onKeyUp="onKeyUp",e.class="class",e.nullable="nullable",e.autoComplete="autoComplete"}(n||(n={})),function(e){e.computed="computed",e.observable="observable",e.editable="editable",e.all="all"}(o||(o={})),function(e){e.some="some",e.every="every"}(d||(d={})),function(e){e.computed="computed",e.values="values",e.labels="labels",e.placeholders="placeholders",e.defaults="defaults",e.initials="initials",e.disabled="disabled",e.deleted="deleted",e.types="types",e.related="related",e.rules="rules",e.options="options",e.bindings="bindings",e.extra="extra",e.hooks="hooks",e.handlers="handlers",e.validatedWith="validatedWith",e.validators="validators",e.observers="observers",e.interceptors="interceptors",e.converters="converters",e.input="input",e.output="output",e.autoFocus="autoFocus",e.inputMode="inputMode",e.refs="refs",e.classes="classes",e.nullable="nullable",e.autoComplete="autoComplete"}(h||(h={}));const u={editable:[n.type,n.value,n.initial,n.default,n.label,n.placeholder,n.related,n.options,n.extra,n.bindings,n.hooks,n.handlers,n.deleted,n.disabled,n.autoFocus,n.inputMode,n.ref,n.nullable,n.autoComplete],handlers:[n.onChange,n.onToggle,n.onFocus,n.onBlur,n.onDrop,n.onSubmit,n.onReset,n.onClear,n.onAdd,n.onDel],computed:[n.error,n.hasError,n.isValid,n.isDirty,n.isPristine,n.isDefault,n.isEmpty,n.focused,n.touched,n.changed,n.validating,n.submitting,n.resetting,n.clearing,n.blurred,n.deleted,n.disabled],separated:[h.computed,h.values,h.labels,h.placeholders,h.defaults,h.initials,h.disabled,h.deleted,h.types,h.related,h.rules,h.options,h.bindings,h.extra,h.hooks,h.handlers,h.validatedWith,h.validators,h.observers,h.interceptors,h.converters,h.input,h.output,h.autoFocus,h.inputMode,h.refs,h.classes,h.nullable,h.autoComplete],functions:[n.computed,n.observers,n.interceptors,n.converter,n.input,n.output],validation:[n.rules,n.validators,n.validatedWith],occurrences:{isDirty:d.some,isPristine:d.every,isDefault:d.every,isValid:d.every,isEmpty:d.every,hasError:d.some,focused:d.some,blurred:d.some,touched:d.some,deleted:d.every,disabled:d.every,clearing:d.every,resetting:d.every}},c=e=>{if(e&&e._isArrayMap){const t=[];return e.forEach(e=>t.push(e)),t}return t.values(e)},p=({type:e,data:t})=>{let i;switch(e){case d.some:i=e=>e.some(Boolean);break;case d.every:i=e=>e.every(Boolean);break;default:throw new Error("Occurrence not found for specified prop")}return i(t)},f=(e,t)=>{let i;switch(e){case o.computed:i=u.computed;break;case o.observable:i=[n.fields,...u.computed,...u.editable];break;case o.editable:i=[...u.editable,...u.validation,...u.functions,...u.handlers];break;case o.all:i=[n.id,n.key,n.name,n.path,...u.computed,...u.editable,...u.validation,...u.functions,...u.handlers];break;default:i=null}return t.filter(e=>i.includes(e)).length>0},v=(e,t)=>{if(f(e,t))return;throw new Error(`The selected property is not allowed (${JSON.stringify(t)})`)},b=(e,t,i=null)=>{if(null!=t)return;throw new Error(`${null==i?"The selected field is not defined":i} (${e})`)},g=e=>{let t;return t=e.replace(/\.\d+($|\.)/g,"[]."),t=t.replace("..","."),t=t.replace(/^\.+|\.+$/g,""),t},m=(e,t)=>t.some(t=>i.has(e,t)),y=e=>i.isEmpty(e)&&Array.isArray(e),$=e=>Array.isArray(e)&&e.every(e=>"string"==typeof e),O=e=>Array.isArray(e)&&e.every(e=>i.isPlainObject(e)),E=({fields:e})=>!$({fields:e})&&f(o.editable,(e=>e?[...new Set(Object.values(e).flatMap(e=>e?Object.keys(e):[]))]:[])(e)),k=e=>Array.from((e=>e&&e._isArrayMap?Array.from(e.keys()):t.keys(e))(e)).map(Number),V=e=>k(e).every(e=>Number.isInteger(e)),A=e=>{const t=k(e),i=t.length?Math.max(...t):void 0;return void 0===i?0:i+1},w=e=>{if(null===e||"object"!=typeof e)return e;if(Array.isArray(e))return e.map(e=>w(e));if(e instanceof Date)return new Date(e.getTime());if(!i.isPlainObject(e))return e;const t={};return i.each(Object.keys(e),i=>{t[i]=w(e[i])}),t};let F=0;const D=e=>`${[e.path.replace(/\./g,"-"),"--"].join("")}${++F}`,S=e=>null!=e&&"undefined"!=typeof Event&&(e instanceof Event||null!=e.target),C=(...e)=>{for(const t of e)if(void 0!==t)return t},x=({type:e,value:t,nullable:i,isEmptyArray:s=!1,fallbackValueOption:r=""})=>Array.isArray(t)||s?[]:i||t instanceof Date||"date"===e||"datetime-local"===e?null:"number"==typeof t||"number"===e?0:"boolean"!=typeof t&&"checkbox"!==e&&("string"==typeof t||"file"===e?"":r),j=e=>{let t=String(e??"");return t=t.replace(/\[/g,"."),t=t.replace(/\]/g,""),t},_=(e,{fallbackValueOption:t="",type:i,isEmptyArray:s,separated:r,unified:a,fallback:l})=>e(C(r,a,l,x({fallbackValueOption:t,type:i,isEmptyArray:s}))),I=(e,t,s,r)=>e.incremental&&null!==t&&"object"==typeof t&&i.isEmpty(t)?[]:e.hasIncrementalKeys?((e,t,i)=>{const s=Object.values(e),r=[n.value,n.initial,n.default].includes(t);return i&&r?s.filter(e=>null!=e&&""!==e):s})(t,s,r):t,P=(e,t,s=!1)=>{if(t===n.value||t.startsWith("value.")){const r=e.$output?e.$output(e[n.value]):e[n.value],a=t.startsWith("value.")?i.get(r,t.substring(6)):r;return"string"==typeof a&&i.isEmpty(a)&&s?null:a}return e[t]},N=(e,t=!1)=>{let s=e;return $(s)&&(s=i.transform(s,(e,s)=>{const r=s.split(".");return r.length?i.merge(e,((e,t=!1)=>e.reduceRight((i,s)=>{const r={};if(s.endsWith("[]")){const e=t?[i]:[];return r[s.replace(/\[\]$/,"")]=e,r}const a=e[e.indexOf(s)-1],l=!!a&&a.endsWith("[]")&&e[e.length-1]===s;return!t&&l||(r[s]=i),r},{}))(r,t)):Object.assign(e,{[s]:""})},{})),s},M=(e,t=!0)=>i.transform(e,(e,s,r)=>((e,t)=>null!==e&&"object"==typeof e&&!(e instanceof Date)&&!i.has(e,n.fields)&&!i.has(e,n.class)&&(!m(e,[...u.editable,...u.handlers,...u.validation,...u.functions])||t))(s,t)?Object.assign(e,{[r]:{fields:y(s)?[]:M(s)}}):Object.assign(e,{[r]:s}),{}),B=(e,t,s)=>{if(!i.has(t,h.values))return e;let{values:r}=t;return E({fields:t.fields})&&(r=(e=>i.transform(e,(e,t,s)=>{return Object.assign(e,{[s]:{value:t,fields:(r=t,i.isPlainObject(r)?Object.entries(r).map(([e,t])=>({value:t,name:e})):void 0)}});var r},{}))(r)),i.merge(e,i.transform(r,(t,i,r)=>{Array.isArray(e[r])&&(t[r]=i),r in e||isNaN(Number(r))&&!s||(t[r]=i)},{}))},W=(e,t=!0,s=!0)=>{let r=i.merge(N(e.fields,!1),N(e.struct,!1));return r=(e=>{let t=e;return O(t)&&(t=i.transform(t,(e,t)=>{if(!E({fields:{field:t}})||i.has(t,n.name))return Object.assign(e,{[t.name]:t})},{})),t})(r),r=B(r,e,s),r=M(r,t),r},R=(e,t,s=0,r=!1)=>{const a=(Array.isArray(e)?e:Object.values(e)).filter(e=>"string"==typeof e),l=g(t),o=a.filter(e=>e.startsWith(l)),d=N(o,r),h=l.replace(/\[\]/g,`[${s}]`),u=M(i.get(d,h));return a.length&&a.filter(e=>e.startsWith(t+"[]")).map(e=>e.substring((t+"[].").length)).filter(e=>e.endsWith("[]")).map(e=>e.substring(0,e.length-2)).forEach(e=>{const t=e.split(".");let i=u[0]?.fields;for(let e=0;e<t.length&&(i=i?.[t[e]]?.[n.fields],i);e++);i&&delete i[0]}),u};var H,T,U;!function(e){e.uniqueId="uniqueId",e.fallback="fallback",e.fallbackValue="fallbackValue",e.defaultGenericError="defaultGenericError",e.submitThrowsError="submitThrowsError",e.showErrorsOnInit="showErrorsOnInit",e.showErrorsOnSubmit="showErrorsOnSubmit",e.showErrorsOnBlur="showErrorsOnBlur",e.showErrorsOnChange="showErrorsOnChange",e.showErrorsOnClear="showErrorsOnClear",e.showErrorsOnReset="showErrorsOnReset",e.showErrorsOnRestore="showErrorsOnRestore",e.validateOnInit="validateOnInit",e.validateOnSubmit="validateOnSubmit",e.validateOnBlur="validateOnBlur",e.validateOnChange="validateOnChange",e.validateOnChangeAfterInitialBlur="validateOnChangeAfterInitialBlur",e.validateOnChangeAfterSubmit="validateOnChangeAfterSubmit",e.validateDisabledFields="validateDisabledFields",e.validateDeletedFields="validateDeletedFields",e.validatePristineFields="validatePristineFields",e.validateTrimmedValue="validateTrimmedValue",e.validateOnClear="validateOnClear",e.validateOnReset="validateOnReset",e.validateOnRestore="validateOnRestore",e.strictSet="strictSet",e.strictUpdate="strictUpdate",e.strictDelete="strictDelete",e.strictSelect="strictSelect",e.softDelete="softDelete",e.retrieveOnlyDirtyFieldsValues="retrieveOnlyDirtyFieldsValues",e.retrieveOnlyEnabledFieldsValues="retrieveOnlyEnabledFieldsValues",e.retrieveOnlyEnabledFieldsErrors="retrieveOnlyEnabledFieldsErrors",e.retrieveNullifiedEmptyStrings="retrieveNullifiedEmptyStrings",e.removeNullishValuesInArrays="removeNullishValuesInArrays",e.preserveDeletedFieldsValues="preserveDeletedFieldsValues",e.autoTrimValue="autoTrimValue",e.autoParseNumbers="autoParseNumbers",e.validationDebounceWait="validationDebounceWait",e.validationDebounceOptions="validationDebounceOptions",e.stopValidationOnError="stopValidationOnError",e.validationPluginsOrder="validationPluginsOrder",e.resetValidationBeforeValidate="resetValidationBeforeValidate",e.applyInputConverterOnInit="applyInputConverterOnInit",e.applyInputConverterOnSet="applyInputConverterOnSet",e.applyInputConverterOnUpdate="applyInputConverterOnUpdate",e.bubbleUpErrorMessages="bubbleUpErrorMessages"}(H||(H={})),function(e){e.onSuccess="onSuccess",e.onError="onError"}(T||(T={}));class z{noop=()=>{};state;fields=new l;path;$submitted=0;$submitting=!1;$validated=0;$validating=!1;$clearing=!1;$resetting=!1;$touched=!1;$changed=0;$hooks={};$handlers={};$committed=void 0;constructor(){a(this,{$submitted:t.observable,$submitting:t.observable,$validated:t.observable,$validating:t.observable,$clearing:t.observable,$resetting:t.observable,$touched:t.observable,$changed:t.observable,$hooks:t.observable,$handlers:t.observable,changed:t.computed,submitted:t.computed,submitting:t.computed,validated:t.computed,validating:t.computed,clearing:t.computed,resetting:t.computed,hasIncrementalKeys:t.computed,hasNestedFields:t.computed,size:t.computed,initField:t.action,submit:t.action,deepUpdate:t.action,set:t.action,add:t.action,del:t.action,move:t.action,commit:t.action,restore:t.action}),this.fields.onMove=()=>{this.$changed++,this.state.form.$changed++}}execHook=(e,t={},...i)=>C(t[e],this.$hooks[e],this.noop).apply(this,[this,...i]);execHandler=(e,t,i=void 0,s=null,r=!0)=>[C(this.$handlers[e]&&this.$handlers[e].apply(this,[this]),i,this.noop).apply(this,[...t]),r&&this.execHook(s||e,{},...t)];get resetting(){return this.hasNestedFields?this.check(n.resetting,!0):this.$resetting}get clearing(){return this.hasNestedFields?this.check(n.clearing,!0):this.$clearing}get submitted(){return t.toJS(this.$submitted)}get submitting(){return t.toJS(this.$submitting)}get validated(){return t.toJS(this.$validated)}get validating(){return t.toJS(this.$validating)}get hasIncrementalKeys(){return!!this.fields.size&&V(this.fields)}get hasNestedFields(){return 0!==this.fields.size}get size(){return this.fields.size}get changed(){return null!=this.path&&this.hasNestedFields?this.reduce((e,t)=>e+t.changed,0)+this.$changed:this.$changed}intercept=e=>this.MOBXEvent("function"==typeof e?{type:"interceptor",call:e}:{type:"interceptor",...e});observe=e=>this.MOBXEvent("function"==typeof e?{type:"observer",call:e}:{type:"observer",...e});onClear=(...e)=>this.execHandler(n.onClear,e,e=>{S(e)&&e.preventDefault(),this.clear(!0,!1)});onReset=(...e)=>this.execHandler(n.onReset,e,e=>{S(e)&&e.preventDefault(),this.reset(!0,!1)});onSubmit=(...e)=>this.execHandler(n.onSubmit,e,(e,t={})=>{S(e)&&e.preventDefault(),this.submit(t)},null,!1);onAdd=(...e)=>this.execHandler(n.onAdd,e,(e,t)=>{S(e)&&e.preventDefault(),this.add(S(t)?null:t,!1)});onDel=(...e)=>this.execHandler(n.onDel,e,(e,t)=>{S(e)&&e.preventDefault(),this.del(S(t)?this.path:t,!1)});initFields(e,t=!1){const s=this.state.options.get(H.fallback),r=e=>[this.path,e].join(".").replace(/^\.+/,"");let a;a=W(e,this.state.strict,s),a=((e,t)=>{if(t){const s=i.get(t.plugins,"ajv.config.schema");i.isEmpty(e)&&s&&s.properties&&i.each(s.properties,(t,s)=>{i.set(e,s,{value:t.default,label:t.title})})}return e})(a,this.validator),i.forIn(a,(e,i)=>{const a=r(i);if(null==this.select(a,null,!1))if(s)this.initField(i,a,e,t);else{const s=g(a);this.state.struct().filter(e=>e.startsWith(s)).find(e=>"."===e.charAt(s.length)||"[]"===e.substring(s.length,s.length+2)||e===s)&&this.initField(i,a,e,t)}})}initField(e,t,s,r=!1,a){const l=this.state.get("current","props"),o=g(t),d=e=>{const t=i.get(l[e],o);if(![n.input,n.output,n.converter].includes(e)||"function"==typeof t)return t},u={$value:void 0!==a?a:i.get(l[h.values],t),$computed:d(h.computed),$label:d(h.labels),$placeholder:d(h.placeholders),$default:d(h.defaults),$initial:d(h.initials),$disabled:d(h.disabled),$deleted:d(h.deleted),$type:d(h.types),$related:d(h.related),$rules:d(h.rules),$options:d(h.options),$bindings:d(h.bindings),$extra:d(h.extra),$hooks:d(h.hooks),$handlers:d(h.handlers),$validatedWith:d(h.validatedWith),$validators:d(h.validators),$observers:d(h.observers),$interceptors:d(h.interceptors),$converters:d(h.converters),$input:d(h.input),$output:d(h.output),$autoFocus:d(h.autoFocus),$ref:d(h.refs),$nullable:d(h.nullable),$autoComplete:d(h.autoComplete)},c=this.state.form.makeField({key:e,path:t,struct:o,data:s,props:u,update:r,state:this.state},s&&s[n.class]||d(h.classes));return this.fields.merge({[e]:c}),c}validate(e,t){const s=i.merge({},e,{path:this.path});return this.state.form.validator.validate(s,t)}submit(e={},{execOnSubmitHook:i=!0,execValidationHooks:s=!0,validate:r=!0}={}){const a=i?(()=>this.execHook(n.onSubmit,e))():void 0;if(this.$submitting=!0,this.$submitted+=1,!r||!this.state.options.get(H.validateOnSubmit,this))return Promise.resolve(a).then(t.action(()=>this.$submitting=!1)).catch(t.action(e=>{throw this.$submitting=!1,e})).then(()=>this);const l=t=>t?this.execHook(T.onSuccess,e):this.execHook(T.onError,e);return this.validate({showErrors:this.state.options.get(H.showErrorsOnSubmit,this)}).then(({isValid:e})=>{const t=s?l(e):void 0;if(e)return Promise.all([a,t]);const i=this.state.options.get(H.defaultGenericError,this);return this.state.options.get(H.submitThrowsError,this)&&i&&this.invalidate(),Promise.all([a,t])}).then(t.action(()=>this.$submitting=!1)).catch(t.action(e=>{throw this.$submitting=!1,e})).then(()=>this)}check(e,t=!1){return v(o.computed,[e]),t?p({type:u.occurrences[e],data:this.deepCheck(u.occurrences[e],e,this.fields)}):this[e]}deepCheck(e,t,s){const r=c(s);return i.transform(r,(i,s)=>(![n.isValid,n.hasError,n.isDirty,n.isPristine].includes(t)&&s.fields.size&&Array.isArray(s.initial)||i.push(s[t]),i.push(p({data:this.deepCheck(e,t,s.fields),type:e})),i),[])}firstError(){if(!this.state.options.get(H.bubbleUpErrorMessages,this))return null;for(const e of c(this.fields)){if(e.error)return e.error;if(e.fields.size){const t=e.firstError();if(t)return t}}return null}update(e){if(!i.isPlainObject(e))throw new Error("The update() method accepts only plain objects.");this.deepUpdate(W({fields:e},this.state.strict),void 0,void 0,e)}deepUpdate(e,t="",s=!0,r){i.each(e,(e,a)=>{const l=i.has(e,n.name)?e.name:a,o=`${t}.${l}`.replace(/^\.+/,""),d=this.state.options.get(H.strictUpdate,this),h=this.select(o,null,d),u=this.select(t,null,!1)||this.state.form.select(this.path??"",null,!1),p=this.state.options.get(H.applyInputConverterOnUpdate,this);if(null!=h&&void 0!==e){const t=i.get(r,o),s=[this.path??"",o].join(".").replace(/^\.+/,"");if(Array.isArray(t)&&!this.isArrayContainer(s))return void(h.value=_(p?h.$input:e=>e,{fallbackValueOption:this.state.options.get(H.fallbackValue,this),separated:t}));if(Array.isArray(h.values())){const t=Math.max(-1,...Object.keys(e.fields||{}).map(Number));c(h.fields).forEach(e=>{Number(e.name)>t&&(h.$changed++,h.state.form.$changed++,h.fields.delete(e.name))})}if(e?.fields){const e=this.state.options.get(H.fallback),t=this.state.struct().findIndex(e=>e.startsWith(h.path.replace(/\.\d+\./,"[].")+"[]"));if(!e&&0===h.fields.size&&t<0)return void(h.value=_(p?h.$input:e=>e,{fallbackValueOption:this.state.options.get(H.fallbackValue,this),separated:i.get(r,o)}))}if(null===e||null==e.fields)return void(h.value=_(p?h.$input:e=>e,{fallbackValueOption:this.state.options.get(H.fallbackValue,this),separated:e}))}if(null!=u&&null==h){const t=[this.path,o].join(".").replace(/^\.+/,"");u.$changed++,u.state.form.$changed++,u.initField(l,t,e,!0,i.get(r,o))}else if(s)if(i.has(e,n.fields)&&null!=e.fields)this.deepUpdate(e.fields,o,!0,r);else{const e=R(this.state.struct(),o);this.deepUpdate(e,o,!1,r)}})}get(e=null,t=!0){if(null==e)return this.deepGet([...u.computed,...u.editable,...u.validation],this.fields,t);if(v(o.all,Array.isArray(e)?e:[e]),"string"==typeof e){if([n.hooks,n.handlers].includes(e))return this[`$${e}`];if(t&&0===this.fields.size){const i=this.state.options.get(H.retrieveNullifiedEmptyStrings,this);return P(this,e,!!t&&i)}const i=this.deepGet(e,this.fields,t),s=this.state.options.get(H.removeNullishValuesInArrays,this);return I(this,i,e,!!t&&s)}return this.deepGet(e,this.fields,t)}deepGet(e,t,s=!0){const r=c(t),a=i.transform(r,(t,r)=>{if(Object.assign(t,{[r.key]:{fields:(t=>0!==t.size?this.deepGet(e,t,s):void 0)(r.fields)}}),"string"==typeof e){const i=this.state.options,a=i.get(H.retrieveOnlyDirtyFieldsValues,this)&&e===n.value&&r.isPristine||i.get(H.retrieveOnlyEnabledFieldsValues,this)&&e===n.value&&r.disabled||i.get(H.retrieveOnlyEnabledFieldsErrors,this)&&e===n.error&&r.disabled&&r.isValid&&(!r.error||!r.hasError)||i.get(H.softDelete,this)&&e===n.value&&r.deleted;if(0===r.fields.size){if(delete t[r.key],a)return t;const i=this.state.options.get(H.retrieveNullifiedEmptyStrings,this);return Object.assign(t,{[r.key]:P(r,e,!!s&&i)})}let l=this.deepGet(e,r.fields,s);if(e===n.value&&(l=r.$output(l)),delete t[r.key],a)return t;const o=this.state.options.get(H.removeNullishValuesInArrays,this);return Object.assign(t,{[r.key]:I(r,l,e,!!s&&o)})}return i.each(e,e=>Object.assign(t[r.key],{[e]:r[e]})),t},{});if("string"==typeof e&&r.length>0&&V(t)){const e=new Set(Object.keys(a));return r.filter(t=>e.has(String(t.key))).map(e=>a[String(e.key)])}return a}set(e,t){if("string"==typeof e&&void 0!==t){v(o.editable,[e]);const s=[n.hooks,n.handlers].includes(e);if((null!==t&&"object"==typeof t&&e===n.value||i.isPlainObject(t)&&!s)&&this.hasNestedFields)return this.deepSet(e,t,"",!0);if(e===n.value){const e=this.state.options.get(H.applyInputConverterOnSet,this);this.value=_(e?this.$input:e=>e,{fallbackValueOption:this.state.options.get(H.fallbackValue,this),separated:t})}else s?Object.assign(this[`$${e}`],t):i.set(this,`$${e}`,t);return}null==t&&(this.hasNestedFields?this.deepSet(n.value,e,"",!0):this.set(n.value,e))}deepSet(e,t,s="",r=!1){const a=this.state.options.get(H.strictSet,this);null!=t?i.each(t,(t,i)=>{const l=`${s}.${i}`.replace(/^\.+/,""),n=this.select(l,null,a);a&&b(l,n,"You are updating a not existent field:"),void 0!==n&&(void 0!==t&&n.set(e,t,r),n.fields.size&&null!==t&&"object"==typeof t&&this.deepSet(e,t,l,r))}):this.each(e=>e.$value=x({fallbackValueOption:this.state.options.get(H.fallbackValue,this),value:e.$value,nullable:e.$nullable,type:e.type}))}add(e,t=!0){if(O(e))return i.each(e,e=>this.update({[A(this.fields)]:e})),this.$changed++,this.state.form.$changed++,t&&this.execHook(n.onAdd),this;if(this.isPlainArrayField()&&!i.has(e,n.key)&&!i.has(e,n.name)){const s=Array.isArray(this.value)?[...this.value]:[];return s.push(i.has(e,n.value)?e[n.value]:x({fallbackValueOption:this.state.options.get(H.fallbackValue,this),nullable:this.$nullable,type:this.type})),this.set(n.value,s),this.$changed++,this.state.form.$changed++,t&&this.execHook(n.onAdd),this}const s=this.createField(e);return this.$changed++,this.state.form.$changed++,t&&this.execHook(n.onAdd),s}createField(e,t){const s=R(this.state.struct(),this.path??"",0,!0),r=s[0]?.fields??null,a=i.isPlainObject(e)?Object.keys(e).filter(e=>e!==n.key):[],l=!!r&&i.isPlainObject(e)&&!i.has(e,n.value)&&!i.has(e,n.fields)&&a.length>0&&(!i.has(e,n.name)||Object.prototype.hasOwnProperty.call(r,n.name)),o=t??e?.[n.key],d=void 0!==o?o:l||void 0===e?.[n.name]?A(this.fields):e[n.name],h=this.initField(d,(e=>[this.path,e].join(".").replace(/^\.+/,""))(d),l?s[0]:i.merge(s[0],e),!1,i.has(e,n.value)?e[n.value]:void 0),u=i.has(e,n.value)||i.has(e,n.fields);if(l)i.each(a,t=>{const i=h.select(t);i&&!i.hasNestedFields&&i.set(n.value,e[t])});else if(!u)if(s[0]?.fields&&i.isPlainObject(e)&&!m(e,[n.key,n.name]))i.each(e,(e,t)=>{const i=h.select(t);i&&!i.hasNestedFields&&i.set(n.value,e)});else if(!this.state.options.get(H.preserveDeletedFieldsValues,this)){const e=this.state.options.get(H.fallbackValue,this);h.$value=x({fallbackValueOption:e,value:h.$value,nullable:h.$nullable,type:h.type}),h.each(t=>t.$value=x({fallbackValueOption:e,value:t.$value,nullable:t.$nullable,type:t.type}))}return h}isArrayContainer(e){const t=this.state.struct();if(!Array.isArray(t))return!1;const i=(e??this.path??"").replace(/\.\d+\./g,"[].");return t.some(e=>"string"==typeof e&&e.startsWith(`${i}[]`))}isPlainArrayField(){return!this.hasNestedFields&&!this.isArrayContainer(this.path??"")&&Array.isArray(this.value)}applyValue(e,t){void 0!==t&&(i.isPlainObject(t)&&e.fields.size?i.each(t,(t,i)=>{const s=e.select(i);s&&(s.fields.size?this.applyValue(s,t):s.set(n.value,t))}):e.set(n.value,t))}applyArrayValue(e,t){c(e.fields).forEach(i=>{Number(i.name)>=t.length&&e.fields.delete(i.name)}),t.forEach((t,s)=>{const r=String(s),a=e.fields.get(r);a?this.applyValue(a,t):e.createField(i.isPlainObject(t)?t:{[n.value]:t},r)})}commit(){this.$committed=w(this.values())}restore(){if(void 0!==this.$committed)return this.update(w(this.$committed)),this.state.options.get(H.validateOnRestore,this)?this.validate({showErrors:this.state.options.get(H.showErrorsOnRestore,this)}):void 0}committed(){return void 0===this.$committed?void 0:w(this.$committed)}initCommittedSnapshot(){this.$committed=w(this.resetTargetValues())}resetTargetValues(){const e={};return c(this.fields).forEach(t=>{e[t.key]=t.resetTargetValue()}),e}del(e=null,t=!0){const i=this.state.options.get(H.strictDelete,this),s=j(e??this.path??""),r=[this.path??"",s??""].join(".").replace(/^\.+|\.+$/g,""),a=this.container(e),l=s.split("."),o=l[l.length-1];if(i&&!a.fields.has(o)){b(r,null,`Key "${o}" not found when trying to delete field`)}return a.$changed++,a.state.form.$changed++,this.state.options.get(H.softDelete,this)?this.select(r).set(n.deleted,!0):(a.each(e=>e.debouncedValidation.cancel()),t&&this.execHook(n.onDel),a.fields.delete(o))}MOBXEvent({prop:e=n.value,key:s=null,path:r=null,call:a,type:l}){let d=s||e;v(o.observable,[d]);const h=this.select(r||this.path,null,!1)||this,u=e=>a.apply(null,[{change:e,form:this.state.form,path:h.path||null,field:h.path?h:null}]);let c,p;"observer"===l&&(c=t.observe,p=e=>t.observe(h.fields.toArray(),e)),"interceptor"===l&&(d=`$${e}`,c=t.intercept,p=h.fields.intercept);const f=h.path?`${d}@${h.path}`:d;i.merge(this.state.disposers[l],{[f]:d===n.fields?p.apply(e=>u(e)):c(h,d,e=>u(e))})}dispose(e=null){return this.path&&e?this.disposeSingle(e):this.disposeAll()}disposeAll(){const e=e=>e.apply();i.each(this.state.disposers.interceptor,e),i.each(this.state.disposers.observer,e),this.state.disposers={interceptor:{},observer:{}}}disposeSingle({type:e,key:t=n.value,path:i=null}){const s=j(i??this.path??"");"interceptor"===e&&(t=`$${t}`);const r=this.state.disposers[e];r[`${t}@${s}`].apply(),delete r[`${t}@${s}`]}select(e,t=null,s=!0){const r=j(String(e)).split("."),a=r[0];r.shift();let l=null==t?this.fields.get(a):t.get(a),n=!1;return i.each(r,e=>{n||(null==l?(l=void 0,n=!0):l=l.fields.get(e))}),s&&this.state.options.get(H.strictSelect,this)&&b(String(e),l),l}container(e){const t=j(e??this.path??"").replace(/[^./]+$/,"").replace(/^\.+|\.+$/g,"");return this.path&&null==e?""!==t?this.state.form.select(t,null,!1):this.state.form:""!==t?this.select(t,null,!1):this}has(e){return this.fields.has(e)}map(e){return c(this.fields).map(e)}each(e,t=null,i=0){const s=t||this.fields;c(s).forEach((t,s)=>{e(t,s,i),0!==t.fields.size&&this.each(e,t.fields,i+1)})}reduce(e,t){return c(this.fields).reduce(e,t)}move(e,t){this.fields.move(e,t)}$(e){return this.select(e)}values(){return this.get(n.value)}errors(){return this.get(n.error)}labels(){return this.get(n.label)}placeholders(){return this.get(n.placeholder)}defaults(){return this.get(n.default)}initials(){return this.get(n.initial)}types(){return this.get(n.type)}}class K{promises=[];form=null;drivers={};plugins={vjf:void 0,dvr:void 0,ajv:void 0,yup:void 0,zod:void 0,joi:void 0,valibot:void 0,vinejs:void 0};error=null;constructor(e){a(this,{error:t.observable,validate:t.action,validateField:t.action}),this.form=e.form,Object.assign(this.plugins,e.plugins),this.initDrivers()}initDrivers(){Object.entries(this.plugins).forEach(([e,t])=>{this.drivers[e]=t&&t.class&&new t.class({config:t.config,state:this.form.state,promises:this.promises})})}validate(e,i){const s=C(e?.path,e),r=C(e?.field,this.form.select(s,null,!1),this.form),a=C(e?.related,i?.related,!0),l=C(e?.showErrors,i?.showErrors,!1);return r.$validating=!0,r.$validated+=1,this.error=null,new Promise(e=>{(r.path||"string"==typeof s)&&this.validateField({field:r,showErrors:l,related:a,path:s}),r.each(e=>this.validateField({path:e.path,field:e,showErrors:l,related:a})),e(Promise.all(this.promises.splice(0)))}).then(t.action(()=>{r.$validating=!1,r.$clearing=!1,r.$resetting=!1})).catch(t.action(e=>{throw r.$validating=!1,r.$clearing=!1,r.$resetting=!1,e})).then(()=>r)}validateField({showErrors:e=!1,related:t=!1,field:s=null,path:r}){const a=s||this.form.select(r),{options:l}=this.form.state;if(!a.path)throw new Error("Validation Error: Invalid Field Instance");if(a.deleted&&!l.get(H.validateDeletedFields,a))return;if(a.disabled&&!l.get(H.validateDisabledFields,a))return;if(a.isPristine&&!l.get(H.validatePristineFields,a))return;l.get(H.resetValidationBeforeValidate,a)&&a.resetValidation(),l.get(H.validateTrimmedValue,a)&&a.trim();const n=l.get(H.stopValidationOnError,a),o=l.get(H.validationPluginsOrder,a),d=o?o.map(e=>this.drivers[e]):this.drivers;i.each(d,e=>{e&&e.validate(a),!n||a.hasError}),a.showErrors(e,!1),t&&this.validateRelatedFields(a,e)}validateRelatedFields(e,t){e.related&&e.related.length&&e.related.map(e=>this.validateField({related:!1,showErrors:t,path:e}))}}class G{options={uniqueId:D,fallback:!0,fallbackValue:"",defaultGenericError:null,submitThrowsError:!0,showErrorsOnInit:!1,showErrorsOnSubmit:!0,showErrorsOnBlur:!0,showErrorsOnChange:!0,showErrorsOnClear:!1,showErrorsOnReset:!0,showErrorsOnRestore:!1,validateOnInit:!0,validateOnSubmit:!0,validateOnBlur:!0,validateOnChange:!1,validateOnChangeAfterInitialBlur:!1,validateOnChangeAfterSubmit:!1,validateOnClear:!1,validateOnReset:!1,validateOnRestore:!1,validateDisabledFields:!1,validateDeletedFields:!1,validatePristineFields:!0,strictSet:!1,strictUpdate:!1,strictDelete:!0,strictSelect:!0,softDelete:!1,retrieveOnlyDirtyFieldsValues:!1,retrieveOnlyEnabledFieldsValues:!1,retrieveOnlyEnabledFieldsErrors:!1,retrieveNullifiedEmptyStrings:!1,autoTrimValue:!1,autoParseNumbers:!1,removeNullishValuesInArrays:!1,preserveDeletedFieldsValues:!1,validationDebounceWait:250,validationDebounceOptions:{leading:!1,trailing:!0},stopValidationOnError:!1,validationPluginsOrder:void 0,resetValidationBeforeValidate:!0,validateTrimmedValue:!1,applyInputConverterOnInit:!0,applyInputConverterOnSet:!0,applyInputConverterOnUpdate:!0,bubbleUpErrorMessages:!1};constructor(){a(this,{options:t.observable,set:t.action})}get(e="",s=null){return i.has(s,"path")&&i.has(s.$options,e)?s.$options[e]:e?i.get(this.options,e):t.toJS(this.options)}set(e){t.set(this.options,e)}}class q{templates={};rewriters={default:{id:n.id,name:n.name,type:n.type,value:n.value,checked:n.checked,label:n.label,placeholder:n.placeholder,disabled:n.disabled,autoComplete:n.autoComplete,onChange:n.onChange,onBlur:n.onBlur,onFocus:n.onFocus,autoFocus:n.autoFocus,inputMode:n.inputMode,onKeyUp:n.onKeyUp,onKeyDown:n.onKeyDown}};register(e){return i.each(e,(e,t)=>{"function"==typeof e&&i.merge(this.templates,{[t]:e}),i.isPlainObject(e)&&i.merge(this.rewriters,{[t]:e})}),this}load(e,t=n.default,s){const r={keys:i.get(this.rewriters,n.default),form:e.state.form,field:e,props:s,$try:C};if(i.has(this.templates,t))return i.get(this.templates,t)(r);if(i.has(this.rewriters,t)){const r={};return i.each(i.get(this.rewriters,t),(t,a)=>i.merge(r,{[t]:C(s[a],e[a])})),r}if(i.has(this.templates,t))return i.get(this.templates,t)(r);if(t===n.default){const t={};return i.each(i.get(this.rewriters,n.default),(r,a)=>i.merge(t,{[r]:C(s[a],e[a])})),t}throw new Error(`Bindings: template or rewriter "${t}" does not exist — register it or use the "default" binding`)}}!function(e){e.mixed="mixed",e.unified="unified",e.separated="separated"}(U||(U={}));class J{mode=U.mixed;strict=!1;form;options;bindings;$extra;$struct=[];disposers={interceptor:{},observer:{}};initial={props:{},fields:{}};current={props:{},fields:{}};constructor({form:e,initial:t,options:i,bindings:s}){this.set("form",e),this.initProps(t),this.options=new G,this.options.set(i),this.bindings=new q,this.bindings.register(s),this.observeOptions()}initProps(e={}){const t=[...u.editable,...u.separated,...u.validation,...u.functions,...u.handlers],i=Object.fromEntries(Object.entries(e).filter(([e])=>t.includes(e)));this.set("initial","props",i);const s=E(e),r=(e=>m(e,u.separated)||m(e,u.validation))(e);if((r||$(e.fields))&&!s){const t=C(e.struct,e.fields);return this.struct(t),this.strict=!0,void(this.mode=U.separated)}this.struct(e.struct),this.mode=U.unified}struct(e=null){return e&&(this.$struct=e),this.$struct}get(e,t){return this[e][t]}set(e,t,i=null){"form"===e&&(this.form=t),"initial"===e&&(Object.assign(this.initial[t],i),Object.assign(this.current[t],i)),"current"===e&&Object.assign(this.current[t],i)}extra(e=null){return"string"==typeof e?i.get(this.$extra,e):null===e?this.$extra:(this.$extra=e,null)}observeOptions(){var e;t.observe(this.options.options,(e=[{type:"update",key:H.validateOnChange,to:!0,exec:()=>this.form.each(e=>e.observeValidationOnChange())},{type:"update",key:H.validateOnChange,to:!1,exec:()=>this.form.each(e=>{"function"==typeof e.disposeValidationOnChange&&e.disposeValidationOnChange()})},{type:"update",key:H.validateOnBlur,to:!0,exec:()=>this.form.each(e=>e.observeValidationOnBlur())},{type:"update",key:H.validateOnBlur,to:!1,exec:()=>this.form.each(e=>{"function"==typeof e.disposeValidationOnBlur&&e.disposeValidationOnBlur()})}],t=>e.map((e=>({key:t,to:i,type:s,exec:r})=>e.type===s&&e.name===t&&e.newValue===i&&r.apply(e,[e]))(t))))}}const X=(e,t)=>"function"!=typeof t?t:t({field:e,form:e.state.form}),L=e=>"function"==typeof e?e:void 0,Y=(e,t)=>"function"==typeof e[`_${t}`]?e[`_${t}`].apply(e,[{form:e.state.form,field:e}]):e[`$${t}`],Q=(e,t,i)=>Object.assign(e,{_label:L(t.$label??i?.label),_placeholder:L(t.$placeholder??i?.placeholder),_disabled:L(t.$disabled??i?.disabled),_rules:L(t.$rules??i?.rules),_related:L(t.$related??i?.related),_deleted:L(t.$deleted??i?.deleted),_validators:L(t.$validators??i?.validators),_validatedWith:L(t.$validatedWith??i?.validatedWith),_bindings:L(t.$bindings??i?.bindings),_extra:L(t.$extra??i?.extra),_options:L(t.$options??i?.options),_autoFocus:L(t.$autoFocus??i?.autoFocus),_inputMode:L(t.$inputMode??i?.inputMode),$label:X(e,t.$label??i?.label??""),$placeholder:X(e,t.$placeholder??i?.placeholder??""),$disabled:X(e,t.$disabled??i?.disabled??!1),$rules:X(e,t.$rules??i?.rules??null),$related:X(e,t.$related??i?.related??[]),$deleted:X(e,t.$deleted??i?.deleted??!1),$validatedWith:X(e,t.$validatedWith??i?.validatedWith??n.value),$bindings:X(e,t.$bindings??i?.bindings??n.default),$extra:X(e,t.$extra??i?.extra??null),$options:X(e,t.$options??i?.options??{}),$autoFocus:X(e,t.$autoFocus??i?.autoFocus??!1),$inputMode:X(e,t.$inputMode??i?.inputMode??void 0),$validators:X(e,t.$validators??i?.validators??null),$hooks:t.$hooks??i?.hooks??{},$handlers:t.$handlers??i?.handlers??{},$observers:t.$observers??i?.observers??null,$interceptors:t.$interceptors??i?.interceptors??null,$ref:t.$ref??i?.ref??void 0,$nullable:t.$nullable??i?.nullable??!1,$autoComplete:t.$autoComplete??i?.autoComplete??void 0}),Z=(e,t,i,s,{isEmptyArray:r,fallbackValueOption:a})=>_(e=>e,{isEmptyArray:r,type:e.type,unified:s?x({fallbackValueOption:a,type:e.type,value:e.value}):t?.default,separated:i.$default,fallback:e.$initial});class ee extends z{hasInitialNestedFields=!1;incremental=!1;id;key;name;$observers;$interceptors;$converter=e=>e;$input=e=>e;$output=e=>e;_value;_label;_placeholder;_disabled;_rules;_related;_deleted;_validatedWith;_validators;_bindings;_extra;_options;_autoFocus;_inputMode;$options=void 0;$value=void 0;$type=void 0;$label=void 0;$placeholder=void 0;$default=void 0;$initial=void 0;$bindings=void 0;$extra=void 0;$related=void 0;$validatedWith=void 0;$validators=void 0;$rules=void 0;$disabled=!1;$focused=!1;$blurred=!1;$deleted=!1;$autoFocus=!1;$inputMode=void 0;$ref=void 0;$nullable=!1;$autoComplete=void 0;showError=!1;errorSync=null;errorAsync=null;validationErrorStack=[];validationFunctionsData=[];validationAsyncData={valid:!0,message:null};debouncedValidation;disposeValidationOnBlur;disposeValidationOnChange;files=void 0;constructor({key:e,path:s,struct:r,data:l={},props:o={},update:d=!1,state:h}){super(),a(this,{$options:t.observable,$value:t.observable,$type:t.observable,$label:t.observable,$placeholder:t.observable,$default:t.observable,$initial:t.observable,$bindings:t.observable,$extra:t.observable,$related:t.observable,$validatedWith:t.observable,$validators:t.observable,$rules:t.observable,$disabled:t.observable,$focused:t.observable,$blurred:t.observable,$deleted:t.observable,showError:t.observable,errorSync:t.observable,errorAsync:t.observable,validationErrorStack:t.observable,validationFunctionsData:t.observable,validationAsyncData:t.observable,files:t.observable,autoFocus:t.computed,inputMode:t.computed,ref:t.computed,checkValidationErrors:t.computed,checked:t.computed,value:t.computed,initial:t.computed,default:t.computed,actionRunning:t.computed,type:t.computed,label:t.computed,placeholder:t.computed,extra:t.computed,options:t.computed,bindings:t.computed,related:t.computed,disabled:t.computed,rules:t.computed,validators:t.computed,validatedValue:t.computed,error:t.computed,hasError:t.computed,isValid:t.computed,isDefault:t.computed,isDirty:t.computed,isPristine:t.computed,isEmpty:t.computed,blurred:t.computed,touched:t.computed,deleted:t.computed,setupField:t.action,initNestedFields:t.action,invalidate:t.action,setValidationAsyncData:t.action,resetValidation:t.action,clear:t.action,reset:t.action,focus:t.action,blur:t.action,showErrors:t.action,update:t.action}),this.state=h,this.setupField(e,s,r,l,o,d),this.initNestedFields(l,d),this.initCommittedSnapshot(),this.incremental=this.hasIncrementalKeys,this.debouncedValidation=i.debounce(this.validate,this.state.options.get(H.validationDebounceWait,this),this.state.options.get(H.validationDebounceOptions,this)),this.observeValidationOnBlur(),this.observeValidationOnChange(),this.initMOBXEvent(n.observers),this.initMOBXEvent(n.interceptors),t.runInAction(()=>Object.assign(this.$hooks,this.hooks?.apply(this,[this]))),t.runInAction(()=>Object.assign(this.$handlers,this.handlers?.apply(this,[this]))),this.execHook(n.onInit),t.autorun(()=>this.changed&&this.execHook(n.onChange))}get checkValidationErrors(){return!this.validationAsyncData.valid||!i.isEmpty(this.validationErrorStack)||"string"==typeof this.errorAsync||"string"==typeof this.errorSync}set value(e){let t=e;"string"==typeof t&&this.state.options.get(H.autoTrimValue,this)&&(t=t.trim()),this.$value!==t&&(this.handleSetNumberValue(t)||(this.$value=this.$converter(t),this.$changed++,this.actionRunning||this.state.form.$changed++))}handleSetNumberValue(e){return!!this.state.options.get(H.autoParseNumbers,this)&&("number"!=typeof this.$initial&&"number"!=this.type||!new RegExp("^-?\\d+(,\\d+)*(\\.\\d+([eE]\\d+)?)?$","g").exec(e)?void 0:(this.$value=this.$converter(Number(e)),this.$changed++,this.actionRunning||this.state.form.$changed++,!0))}get actionRunning(){return this.submitting||this.clearing||this.resetting}get checked(){return"checkbox"===this.type?this.value:void 0}get value(){return"function"!=typeof this._value||this.hasNestedFields?this.getComputedProp(n.value):Y(this,n.value)}get initial(){return this.$initial?t.toJS(this.$initial):this.getComputedProp(n.initial)}get default(){return this.$default?t.toJS(this.$default):this.getComputedProp(n.default)}set initial(e){this.$initial=e}set default(e){this.$default=e}get nullable(){return Y(this,n.nullable)}get autoComplete(){return Y(this,n.autoComplete)}get ref(){return Y(this,n.ref)}get extra(){return Y(this,n.extra)}get autoFocus(){return Y(this,n.autoFocus)}get inputMode(){return Y(this,n.inputMode)}get type(){return Y(this,n.type)}get label(){return Y(this,n.label)}get placeholder(){return Y(this,n.placeholder)}get options(){return Y(this,n.options)}get bindings(){return Y(this,n.bindings)}get related(){return Y(this,n.related)}get disabled(){return Y(this,n.disabled)}get rules(){return Y(this,n.rules)}get validators(){return Y(this,n.validators)}get validatedWith(){return Y(this,n.validatedWith)}get validatedValue(){return P(this,this.validatedWith)}get error(){return!1===this.showError?null:this.errorAsync||this.errorSync||this.firstError()||null}get hasError(){return this.checkValidationErrors||this.check(n.hasError,!0)}get isValid(){return!this.checkValidationErrors&&this.check(n.isValid,!0)}get isDefault(){return!i.isNil(this.default)&&i.isEqual(this.default,this.value)}get isDirty(){const e=this.changed?this.value:this.initial;return!i.isEqual(this.initial,e)||this.deleted}resetTargetValue(){if(this.hasNestedFields){const e={};return c(this.fields).forEach(t=>{e[t.key]=t.resetTargetValue()}),this.hasIncrementalKeys?Object.values(e):e}return this.$default!==this.$initial?this.$default:this.$initial}get isPristine(){const e=this.changed?this.value:this.initial;return i.isEqual(this.initial,e)&&!this.deleted}get isEmpty(){return this.hasNestedFields?this.check(n.isEmpty,!0):"boolean"==typeof this.value?!!this.$value:"number"!=typeof this.value&&(!(this.value instanceof Date)&&(null!==this.value&&i.isEmpty(this.value)))}get focused(){return this.hasNestedFields?this.check(n.focused,!0):this.$focused}get blurred(){return this.hasNestedFields?this.check(n.blurred,!0):this.$blurred}get touched(){return this.hasNestedFields?this.check(n.touched,!0):this.$touched}get deleted(){return!!this.$deleted||!!this.hasNestedFields&&this.check(n.deleted,!0)}sync=t.action((e,t=null)=>{const s=e=>((e,t)=>"boolean"==typeof t&&"boolean"==typeof e.target.checked)(e,this.value)?e.target.checked:e.target.value;let r;i.isNil(e)||i.isNil(e.target)?(i.isNil(t)||i.isNil(t.target)||(t=s(t)),r=C(e,t)):r=s(e),this.hasNestedFields&&Array.isArray(r)?this.state.form.applyArrayValue(this,r):this.value=r});onSync=(...e)=>"file"===this.type?this.onDrop(...e):this.execHandler(n.onChange,e,this.sync,n.onSync);onChange=this.onSync;onToggle=(...e)=>this.execHandler(n.onToggle,e,this.sync);onBlur=(...e)=>this.execHandler(n.onBlur,e,t.action(()=>{this.$focused=!1,this.$blurred=!0}));onFocus=(...e)=>this.execHandler(n.onFocus,e,t.action(()=>{this.$focused=!0,this.$touched=!0}));onDrop=(...e)=>this.execHandler(n.onDrop,e,t.action(()=>{const t=e[0];let i=null;var s;S(t)&&(s=t,s?.target?.files&&0!==s.target.files.length)&&(i=Array.from(t.target.files));const r=i||e,a=this.files||[],l=new Set(a.map(e=>[e?.name,e?.size,e?.lastModified].join("|")));this.files=[...a,...r.filter(e=>{if(!e||"number"!=typeof e.size)return!0;const t=[e.name,e.size,e.lastModified].join("|");return!l.has(t)&&(l.add(t),!0)})]}));onKeyDown=(...e)=>this.execHandler(n.onKeyDown,e);onKeyUp=(...e)=>this.execHandler(n.onKeyUp,e);setupField(e,t,s,r,a,l){this.key=e,this.path=t,this.id=this.state.options.get(H.uniqueId)?.apply(this,[this]);const n=this.state.options.get(H.fallbackValue,this),o=this.state.options.get(H.applyInputConverterOnInit,this),d=((e,t)=>!!$(e)&&(!!e.filter(e=>e.startsWith(t)).find(e=>"[]"===e.substring(t.length))||(e?.find(e=>e===t)?.endsWith("[]")??!1)))(this.state.struct(),g(this.path??"")),{$type:h,$input:u,$output:c,$converter:p,$converters:f,$computed:v}=a;if(i.isPlainObject(r)){const{type:t,input:i,output:s,converter:b,converters:g,computed:m}=r;this.name=r.name??String(e),this.$type=h||t||"text",this.$converter=C(p,f,b,g,this.$converter),this.$input=C(u,i,this.$input),this.$output=C(c,s,this.$output);const y=_(o?this.$input:e=>e,{fallbackValueOption:n,isEmptyArray:d,type:this.type,unified:m||r.value,separated:v||a.$value,fallback:a.$initial});return this._value=L(y),this.$value="function"==typeof this._value?X(this,y):y,this.$initial=_(e=>e,{fallbackValueOption:n,isEmptyArray:d,type:this.type,unified:r.initial,separated:a.$initial,fallback:this.$value}),this.$default=Z(this,r,a,l,{fallbackValueOption:n,isEmptyArray:d}),void Q(this,a,r)}this.name=String(e),this.$type=h||"text",this.$converter=C(p,f,this.$converter),this.$input=C(u,this.$input),this.$output=C(c,this.$output);const b=_(o?this.$input:e=>e,{fallbackValueOption:n,isEmptyArray:d,type:this.type,unified:v||r,separated:v||a.$value});this._value=L(b),this.$value="function"==typeof this._value?X(this,b):b,this.$initial=_(e=>e,{fallbackValueOption:n,isEmptyArray:d,type:this.type,unified:r,separated:a.$initial,fallback:this.$value}),this.$default=Z(this,r,a,l,{fallbackValueOption:n,isEmptyArray:d}),Q(this,a,r)}getComputedProp(e){if(this.incremental||this.hasNestedFields)return e===n.value?this.get(e,!1):t.untracked(()=>this.get(e,!1));const i=this[`$${e}`];return Array.isArray(i)||t.isObservableArray(i)?[].slice.call(i):t.toJS(i)}initNestedFields(e,t){const s=i.isNil(e)?null:e.fields;Array.isArray(s)&&!i.isEmpty(s)&&(this.hasInitialNestedFields=!0),this.initFields({fields:s},t),!t&&Array.isArray(s)&&i.isEmpty(s)&&Array.isArray(this.value)&&!i.isEmpty(this.value)&&(this.hasInitialNestedFields=!0,this.initFields({fields:s,values:this.value},t))}invalidate(e,t=!0,i=!1){return!0===i?(this.errorAsync=e,void this.showErrors(!0,t)):Array.isArray(e)?(this.validationErrorStack=e,void this.showErrors(!0,t)):(this.validationErrorStack.unshift(e),void this.showErrors(!0,t))}setValidationAsyncData(e=!1,t=null){this.validationAsyncData={valid:e,message:t}}resetValidation(e=!1){this.showError=!1,this.errorSync=null,this.errorAsync=null,this.validationAsyncData={valid:!0,message:null},this.validationFunctionsData=[],this.validationErrorStack=[],Promise.resolve().then(t.action(()=>{this.$resetting=!1,this.$clearing=!1})),e&&this.each(t=>t.resetValidation(e))}clear(e=!0,t=!0){t&&this.execHook(n.onClear),this.$clearing=!0,this.$touched=!1,this.$blurred=!1,this.$changed=0,this.files=void 0,this.$value=x({fallbackValueOption:this.state.options.get(H.fallbackValue),value:this.$value,nullable:this.$nullable,type:this.type}),this.isArrayContainer(this.path??"")&&Array.isArray(this.value)?c(this.fields).forEach(e=>this.fields.delete(e.name)):e&&this.each(t=>t.clear(e)),this.state.options.get(H.validateOnClear,this)?this.validate({showErrors:this.state.options.get(H.showErrorsOnClear,this)}):this.resetValidation(e)}reset(e=!0,t=!0){t&&this.execHook(n.onReset),this.$resetting=!0,this.$touched=!1,this.$blurred=!1,this.$changed=0,this.files=void 0;const s=this.$default!==this.$initial,r=s?this.$default:this.$initial;if(this.isArrayContainer(this.path??"")&&!s&&Array.isArray(r)){const t=r,s=c(this.fields);s.length===t.length&&s.every((e,s)=>i.isEqual(e.value,t[s]))?e&&this.each(t=>t.reset(e)):(s.forEach(e=>this.fields.delete(e.name)),t.forEach((e,t)=>this.createField(i.isPlainObject(e)?e:{[n.value]:e},String(t))))}else s&&(this.value=this.$default),s||(this.value=this.$initial),e&&this.each(t=>t.reset(e));this.state.options.get(H.validateOnReset,this)?this.validate({showErrors:this.state.options.get(H.showErrorsOnReset,this)}):this.resetValidation(e)}focus(){this.ref&&!this.focused&&this.ref.focus(),this.$focused=!0,this.$touched=!0}blur(){this.ref&&this.focused&&this.ref.blur(),this.$focused=!1,this.$blurred=!0}trim(){"string"==typeof this.value&&(this.$value=this.value.trim())}showErrors(e=!0,t=!0){this.showError=e,this.errorSync=this.validationErrorStack.length?this.validationErrorStack[0]:null,this.errorAsync=this.validationAsyncData.valid?null:this.validationAsyncData.message,t&&this.each(i=>i.showErrors(e,t))}observeValidationOnBlur(){const e=this.state.options;e.get(H.validateOnBlur,this)&&(this.disposeValidationOnBlur=t.observe(this,"$focused",t=>!1===t.newValue&&this.debouncedValidation({showErrors:e.get(H.showErrorsOnBlur,this)})))}observeValidationOnChange(){const e=this.state.options;e.get(H.validateOnChange,this)?this.disposeValidationOnChange=t.observe(this,"$value",()=>!this.actionRunning&&this.debouncedValidation({showErrors:e.get(H.showErrorsOnChange,this)})):(e.get(H.validateOnChangeAfterInitialBlur,this)||e.get(H.validateOnChangeAfterSubmit,this))&&(this.disposeValidationOnChange=t.observe(this,"$value",()=>!this.actionRunning&&(e.get(H.validateOnChangeAfterInitialBlur,this)&&this.blurred||e.get(H.validateOnChangeAfterSubmit,this)&&this.state.form.submitted)&&this.debouncedValidation({showErrors:e.get(H.showErrorsOnChange,this)})))}initMOBXEvent(e){const t=this[`$${e}`];if(!Array.isArray(t))return;let s;e===n.observers&&(s=this.observe),e===n.interceptors&&(s=this.intercept),t.map(e=>s(i.omit(e,n.path)))}bind(e={}){return{...this.state.bindings.load(this,this.bindings,e),ref:e=>this.$ref=e}}update(e){if(!i.isPlainObject(e))throw new Error("The update() method accepts only plain objects.");const t=this.state.options.get(H.fallback,this),s=this.state.options.get(H.applyInputConverterOnUpdate,this),r=this.state.struct().findIndex(e=>e.startsWith((this.path??"").replace(/\.\d+\./,"[].")+"[]"));!t&&0===this.fields.size&&r<0?this.value=_(s?this.$input:e=>e,{fallbackValueOption:this.state.options.get(H.fallbackValue,this),separated:e}):super.update(e)}}class te extends z{name;path=null;extra={};validator;debouncedValidation=null;constructor(e={},{name:s="",options:r={},plugins:l={},bindings:o={},hooks:d={},handlers:h={},extra:u={}}={}){super(),a(this,{extra:t.observable,fields:t.observable,flatMapValues:t.computed,error:t.computed,hasError:t.computed,isValid:t.computed,isPristine:t.computed,isDirty:t.computed,isDefault:t.computed,isEmpty:t.computed,focused:t.computed,touched:t.computed,disabled:t.computed,invalidate:t.action,clear:t.action,reset:t.action,resetValidation:t.action}),this.name=s,this.extra=u,t.runInAction(()=>this.$hooks=d),t.runInAction(()=>this.$handlers=h),globalThis.__MOBX_FORMKIT_DEVTOOLS_HOOK__?.emit?.({type:"form:new",key:this.name,form:this});const c=i.each({setup:e,options:r,plugins:l,bindings:o},(e,t)=>"function"==typeof this[t]?i.merge(e,this[t].apply(this,[this])):e);t.runInAction(()=>Object.assign(this.$hooks,this.hooks?.apply(this,[this]))),t.runInAction(()=>Object.assign(this.$handlers,this.handlers?.apply(this,[this]))),this.state=new J({form:this,initial:c.setup,options:c.options,bindings:c.bindings}),this.validator=new K({form:this,plugins:c.plugins}),this.initFields(c.setup),this.initCommittedSnapshot(),this.debouncedValidation=i.debounce(this.validate,this.state.options.get(H.validationDebounceWait),this.state.options.get(H.validationDebounceOptions)),this.state.options.get(H.validateOnInit)&&this.validator.validate({showErrors:this.state.options.get(H.showErrorsOnInit)}),this.execHook(n.onInit),t.autorun(()=>this.$changed&&this.execHook(n.onChange))}get flatMapValues(){const e={};return this.each(t=>e[t.path]=t.validatedValue),e}get error(){return this.validator.error||this.firstError()||null}get hasError(){return!!this.validator.error||this.check(n.hasError,!0)}get isValid(){return!this.validator.error&&this.check(n.isValid,!0)}get isPristine(){return this.check(n.isPristine,!0)}get isDirty(){return this.check(n.isDirty,!0)}get isDefault(){return this.check(n.isDefault,!0)}get isEmpty(){return this.check(n.isEmpty,!0)}get focused(){return this.check(n.focused,!0)}get touched(){return this.check(n.touched,!0)}get disabled(){return this.check(n.disabled,!0)}makeField(e,t=ee){return new t(e)}$(e){return super.$(e)}select(e,t=null,i=!0){return super.select(e,t,i)}values(){return super.values()}invalidate(e=null,t=!0){this.debouncedValidation.cancel(),this.validator.error=e||this.state.options.get(H.defaultGenericError)||null,t&&this.each(e=>e.debouncedValidation.cancel())}showErrors(e=!0){this.each(t=>t.showErrors(e))}resetValidation(e=!0){this.validator.error=null,e&&this.each(t=>t.resetValidation(e))}clear(e=!0,t=!0){t&&this.execHook(n.onClear),this.$touched=!1,this.$changed=0,e&&this.each(t=>t.clear(e))}reset(e=!0,t=!0){t&&this.execHook(n.onReset),this.$touched=!1,this.$changed=0,e&&this.each(t=>t.reset(e))}}e.ArrayMap=l,e.Field=ee,e.Form=te,e.default=te,Object.defineProperty(e,"__esModule",{value:!0})});
2
2
  //# sourceMappingURL=MobxFormkit.umd.min.js.map