Comparing version 0.4.0 to 0.5.0
@@ -11,2 +11,3 @@ import { IObservableArray } from "mobx"; | ||
decimal: (maxDigits: number, decimalPlaces: number) => IConverter<string, string>; | ||
boolean: Converter<boolean, boolean>; | ||
stringArray: Converter<string[], IObservableArray<string>>; | ||
@@ -13,0 +14,0 @@ maybe: { |
@@ -360,3 +360,5 @@ 'use strict'; | ||
if (result !== undefined) { | ||
return result; | ||
// convert the value to JavaScript otherwise things like | ||
// arrays coming out of an observable map are observable | ||
return mobx.toJS(result); | ||
} | ||
@@ -1169,2 +1171,11 @@ if (this.addMode) { | ||
}); | ||
var boolean = new Converter({ | ||
emptyRaw: false, | ||
convert: function (raw) { | ||
return raw; | ||
}, | ||
render: function (value) { | ||
return value; | ||
} | ||
}); | ||
var Decimal = /** @class */ (function () { | ||
@@ -1214,3 +1225,3 @@ function Decimal(maxWholeDigits, decimalPlaces) { | ||
render: function (value) { | ||
return value; | ||
return value.slice(); | ||
} | ||
@@ -1286,2 +1297,3 @@ }); | ||
decimal: decimal, | ||
boolean: boolean, | ||
stringArray: stringArray, | ||
@@ -1288,0 +1300,0 @@ maybe: maybe, |
@@ -356,3 +356,5 @@ import { action, computed, isObservable, observable, toJS } from 'mobx'; | ||
if (result !== undefined) { | ||
return result; | ||
// convert the value to JavaScript otherwise things like | ||
// arrays coming out of an observable map are observable | ||
return toJS(result); | ||
} | ||
@@ -1165,2 +1167,11 @@ if (this.addMode) { | ||
}); | ||
var boolean = new Converter({ | ||
emptyRaw: false, | ||
convert: function (raw) { | ||
return raw; | ||
}, | ||
render: function (value) { | ||
return value; | ||
} | ||
}); | ||
var Decimal = /** @class */ (function () { | ||
@@ -1210,3 +1221,3 @@ function Decimal(maxWholeDigits, decimalPlaces) { | ||
render: function (value) { | ||
return value; | ||
return value.slice(); | ||
} | ||
@@ -1282,2 +1293,3 @@ }); | ||
decimal: decimal, | ||
boolean: boolean, | ||
stringArray: stringArray, | ||
@@ -1284,0 +1296,0 @@ maybe: maybe, |
@@ -1,1 +0,1 @@ | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("mobx"),require("mobx-state-tree")):"function"==typeof define&&define.amd?define(["exports","mobx","mobx-state-tree"],e):e(t.mstForm=t.mstForm||{},t.mobx,t["mobx-state-tree"])}(this,function(t,o,s){"use strict";var n=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r])};function e(t,e,r,n){var i,o=arguments.length,s=o<3?e:null===n?n=Object.getOwnPropertyDescriptor(e,r):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)s=Reflect.decorate(t,e,r,n);else for(var a=t.length-1;0<=a;a--)(i=t[a])&&(s=(o<3?i(s):3<o?i(e,r,s):i(e,r))||s);return 3<o&&s&&Object.defineProperty(e,r,s),s}function u(o,s,a,u){return new(a||(a=Promise))(function(t,e){function r(t){try{i(u.next(t))}catch(t){e(t)}}function n(t){try{i(u.throw(t))}catch(t){e(t)}}function i(e){e.done?t(e.value):new a(function(t){t(e.value)}).then(r,n)}i((u=u.apply(o,s||[])).next())})}function c(r,n){var i,o,s,t,a={label:0,sent:function(){if(1&s[0])throw s[1];return s[1]},trys:[],ops:[]};return t={next:e(0),throw:e(1),return:e(2)},"function"==typeof Symbol&&(t[Symbol.iterator]=function(){return this}),t;function e(e){return function(t){return function(e){if(i)throw new TypeError("Generator is already executing.");for(;a;)try{if(i=1,o&&(s=o[2&e[0]?"return":e[0]?"throw":"next"])&&!(s=s.call(o,e[1])).done)return s;switch(o=0,s&&(e=[0,s.value]),e[0]){case 0:case 1:s=e;break;case 4:return a.label++,{value:e[1],done:!1};case 5:a.label++,o=e[1],e=[0];continue;case 7:e=a.ops.pop(),a.trys.pop();continue;default:if(!(s=0<(s=a.trys).length&&s[s.length-1])&&(6===e[0]||2===e[0])){a=0;continue}if(3===e[0]&&(!s||e[1]>s[0]&&e[1]<s[3])){a.label=e[1];break}if(6===e[0]&&a.label<s[1]){a.label=s[1],s=e;break}if(s&&a.label<s[2]){a.label=s[2],a.ops.push(e);break}s[2]&&a.ops.pop(),a.trys.pop();continue}e=n.call(r,a)}catch(t){e=[6,t],o=0}finally{i=s=0}if(5&e[0])throw e[1];return{value:e[0]?e[1]:void 0,done:!0}}([e,t])}}}var i=function(t){this.value=t},l="ConversionError",r=function(){function t(t){this.definition=t,this.emptyRaw=this.definition.emptyRaw}return t.prototype.convert=function(r){return u(this,void 0,void 0,function(){var e;return c(this,function(t){switch(t.label){case 0:return this.definition.rawValidate?[4,this.definition.rawValidate(r)]:[3,2];case 1:if(!t.sent())return[2,l];t.label=2;case 2:return e=this.definition.convert(r),this.definition.validate?[4,this.definition.validate(e)]:[3,4];case 3:if(!t.sent())return[2,l];t.label=4;case 4:return[2,new i(e)]}})})},t.prototype.render=function(t){return this.definition.render(t)},t}(),a=require("fast-deep-equal");function p(t){return t}function h(t){return t.startsWith("/")&&(t=t.slice(1)),t.split("/")}function f(t){var e=t.join("/");return e.startsWith("/")?e:"/"+e}function d(t){return o.isObservable(t)?o.toJS(t):t}function v(t,e){return function t(e,r){var n=r[0],i=r.slice(1);if(0===i.length)return e[n];var o=e[n];if(void 0===o)return;return t(o,i)}(t,h(e))}function y(t,e){var r=h(e),n=r[r.length-1],s=parseInt(n,10),a=f(r.slice(0,r.length-1)),u=new Map;return t.forEach(function(t,e){if(e.startsWith(a)){var r=h(e.slice(a.length+1)),n=parseInt(r[0],10);if(isNaN(n))u.set(e,t);else if(n<s)u.set(e,t);else if(n!==s){var i=r.slice(1),o=a+f([(n-1).toString()].concat(i));u.delete(e),u.set(o,t)}}else u.set(e,t)}),u}function g(t,e){var r=h(e),n=r[r.length-1],s=parseInt(n,10);if(isNaN(s))return t;var a=f(r.slice(0,r.length-1)),u=new Map;return t.forEach(function(t,e){if(e.startsWith(a)){var r=h(e.slice(a.length+1)),n=parseInt(r[0],10);if(isNaN(n))u.set(e,t);else if(n<s)u.set(e,t);else{var i=r.slice(1),o=a+f([(n+1).toString()].concat(i));u.set(o,t)}}else u.set(e,t)}),u}var b=function(){function t(t,e,r){this.state=t,this.definition=e,this.path=r}return t.prototype.validate=function(){return u(this,void 0,void 0,function(){var e;return c(this,function(t){switch(t.label){case 0:return e=this.accessors.map(function(t){return t.validate()}),[4,Promise.all(e)];case 1:return[2,0===t.sent().filter(function(t){return!t}).length]}})})},Object.defineProperty(t.prototype,"accessors",{get:function(){var r=this,n=[];return Object.keys(this.definition).forEach(function(t){var e=r.definition[t];e instanceof A?n.push(r.field(t)):e instanceof S&&n.push(r.repeatingForm(t))}),n},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"flatAccessors",{get:function(){var e=[];return this.accessors.forEach(function(t){t instanceof m?e.push(t):t instanceof w&&(e.push.apply(e,t.flatAccessors),e.push(t))}),e},enumerable:!0,configurable:!0}),t.prototype.field=function(t){var e=this.definition[t];if(!(e instanceof A))throw new Error("Not accessing a Field instance");return new m(this.state,e,this.path,t)},t.prototype.repeatingForm=function(t){var e=this.definition[t];if(!(e instanceof S))throw new Error("Not accessing a RepeatingForm instance");return new w(this.state,e,this.path,t)},t.prototype.repeatingField=function(t){},e([o.computed],t.prototype,"accessors",null),e([o.computed],t.prototype,"flatAccessors",null),t}(),m=function(){function t(t,e,r,n){var i=this;this.state=t,this.field=e,this.handleChange=function(){for(var n=[],t=0;t<arguments.length;t++)n[t]=arguments[t];return u(i,void 0,void 0,function(){var e,r;return c(this,function(t){switch(t.label){case 0:return e=(r=this.field).getRaw.apply(r,n),[4,this.setRaw(e)];case 1:return t.sent(),[2]}})})},this.name=n,process,this.path=r+"/"+n}return Object.defineProperty(t.prototype,"addMode",{get:function(){return this.state.addMode(this.path)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"raw",{get:function(){var t=this.state.raw.get(this.path);return void 0!==t?t:this.addMode?this.field.converter.emptyRaw:this.field.render(this.state.getValue(this.path))},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"value",{get:function(){if(this.addMode)throw new Error("Cannot access field in add mode until it has been set once");return this.state.getValue(this.path)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"errorValue",{get:function(){return this.state.getError(this.path)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"canShowValidationMessages",{get:function(){if("rightAfter"===this.state.saveStatus)return!0;var t="before"===this.state.saveStatus?this.state.validationBeforeSave:this.state.validationAfterSave;return"immediate"===t||"no"!==t&&("blur"!==t&&"pause"!==t)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"error",{get:function(){return this.canShowValidationMessages?this.errorValue:void 0},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"isValidating",{get:function(){return this.state.validating.get(this.path)||!1},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"disabled",{get:function(){return this.state.isDisabledFunc(this)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"hidden",{get:function(){return this.state.isHiddenFunc(this)},enumerable:!0,configurable:!0}),t.prototype.validate=function(){return u(this,void 0,void 0,function(){return c(this,function(t){switch(t.label){case 0:return[4,this.setRaw(this.raw)];case 1:return t.sent(),[2,void 0===this.errorValue]}})})},t.prototype.setRaw=function(i){return u(this,void 0,void 0,function(){var e,r,n;return c(this,function(t){switch(t.label){case 0:this.state.setRaw(this.path,i),this.state.setValidating(this.path,!0),t.label=1;case 1:return t.trys.push([1,3,,4]),[4,this.field.process(i)];case 2:return e=t.sent(),[3,4];case 3:return t.sent(),this.state.setError(this.path,"Something went wrong"),this.state.setValidating(this.path,!1),[2];case 4:if(r=this.state.raw.get(this.path),!a(d(r),d(i)))return[2];if(this.state.setValidating(this.path,!1),e instanceof F)return this.state.setError(this.path,e.message),[2];if(this.state.deleteError(this.path),!(e instanceof O))throw new Error("Unknown process result");return"string"==typeof(n=this.state.extraValidationFunc(this,e.value))&&n&&this.state.setError(this.path,n),s.applyPatch(this.state.node,[{op:"replace",path:this.path,value:e.value}]),[2]}})})},Object.defineProperty(t.prototype,"inputProps",{get:function(){return{disabled:this.disabled,value:this.raw,onChange:this.handleChange}},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"validationProps",{get:function(){var t=this.errorValue,e=this.isValidating;return t?{validateStatus:e?"validating":"error",help:t}:{validateStatus:e?"validating":""}},enumerable:!0,configurable:!0}),e([o.computed],t.prototype,"addMode",null),e([o.computed],t.prototype,"raw",null),e([o.computed],t.prototype,"value",null),e([o.computed],t.prototype,"errorValue",null),e([o.computed],t.prototype,"canShowValidationMessages",null),e([o.computed],t.prototype,"error",null),e([o.computed],t.prototype,"isValidating",null),e([o.computed],t.prototype,"disabled",null),e([o.computed],t.prototype,"hidden",null),e([o.action],t.prototype,"setRaw",null),e([o.computed],t.prototype,"inputProps",null),e([o.computed],t.prototype,"validationProps",null),t}(),w=function(){function t(t,e,r,n){this.state=t,this.repeatingForm=e,this.name=n,this.path=r+"/"+n}return t.prototype.validate=function(){return u(this,void 0,void 0,function(){var e,r,n,i;return c(this,function(t){switch(t.label){case 0:for(e=[],r=0,n=this.accessors;r<n.length;r++)i=n[r],e.push(i.validate());return[4,Promise.all(e)];case 1:return[2,0===t.sent().filter(function(t){return!t}).length]}})})},t.prototype.index=function(t){return new P(this.state,this.repeatingForm.definition,this.path,t)},Object.defineProperty(t.prototype,"disabled",{get:function(){return this.state.isRepeatingFormDisabledFunc(this)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"accessors",{get:function(){for(var t=[],e=0;e<this.length;e++)t.push(this.index(e));return t},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"flatAccessors",{get:function(){var e=[];return this.accessors.forEach(function(t){e.push.apply(e,t.flatAccessors)}),e},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"error",{get:function(){return this.state.errors.get(this.path)},enumerable:!0,configurable:!0}),t.prototype.insert=function(t,e){var r=this.path+"/"+t;s.applyPatch(this.state.node,[{op:"add",path:r,value:e}]),this.state.addModePaths.set(r,!0)},t.prototype.push=function(t){var e=s.resolvePath(this.state.node,this.path),r=this.path+"/"+e.length;s.applyPatch(this.state.node,[{op:"add",path:r,value:t}]),this.state.addModePaths.set(r,!0)},t.prototype.remove=function(t){var e=s.resolvePath(this.state.node,this.path).indexOf(t);if(-1===e)throw new Error("Cannot find node to remove.");s.applyPatch(this.state.node,[{op:"remove",path:this.path+"/"+e}])},Object.defineProperty(t.prototype,"length",{get:function(){return s.resolvePath(this.state.node,this.path).length},enumerable:!0,configurable:!0}),e([o.computed],t.prototype,"disabled",null),e([o.computed],t.prototype,"accessors",null),e([o.computed],t.prototype,"flatAccessors",null),e([o.computed],t.prototype,"error",null),t}(),P=function(){function t(t,e,r,n){this.state=t,this.definition=e,this.index=n,this.path=r+"/"+n,this.formAccessor=new b(t,e,r+"/"+n)}return t.prototype.validate=function(){return u(this,void 0,void 0,function(){return c(this,function(t){return[2,this.formAccessor.validate()]})})},t.prototype.field=function(t){return this.formAccessor.field(t)},t.prototype.repeatingForm=function(t){return this.formAccessor.repeatingForm(t)},Object.defineProperty(t.prototype,"accessors",{get:function(){return this.formAccessor.accessors},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"flatAccessors",{get:function(){return this.formAccessor.flatAccessors},enumerable:!0,configurable:!0}),e([o.computed],t.prototype,"accessors",null),e([o.computed],t.prototype,"flatAccessors",null),t}(),R=function(){function t(t,e,r){var n=this;if(this.form=t,this.node=e,this.saveStatus="before",this.raw=o.observable.map(),this.errors=o.observable.map(),this.validating=o.observable.map(),this.addModePaths=o.observable.map(),s.onPatch(e,function(t){"remove"===t.op?n.removePath(t.path):"add"===t.op&&n.addPath(t.path)}),this.formAccessor=new b(this,this.form.definition,""),null==r)this.saveFunc=E,this.isDisabledFunc=function(){return!1},this.isHiddenFunc=function(){return!1},this.isRepeatingFormDisabledFunc=function(){return!1},this.extraValidationFunc=function(){return!1},this.validationBeforeSave="immediate",this.validationAfterSave="immediate",this.validationPauseDuration=0,this.addModePaths.set("/",!1);else{this.saveFunc=r.save?r.save:E,this.isDisabledFunc=r.isDisabled?r.isDisabled:function(){return!1},this.isHiddenFunc=r.isHidden?r.isHidden:function(){return!1},this.isRepeatingFormDisabledFunc=r.isRepeatingFormDisabled?r.isRepeatingFormDisabled:function(){return!1},this.extraValidationFunc=r.extraValidation?r.extraValidation:function(){return!1},this.addModePaths.set("/",r.addMode||!1);var i=r.validation||{};this.validationBeforeSave=i.beforeSave||"immediate",this.validationAfterSave=i.afterSave||"immediate",this.validationPauseDuration=i.pauseDuration||0}}return t.prototype.setError=function(t,e){this.errors.set(t,e)},t.prototype.deleteError=function(t){this.errors.delete(t)},t.prototype.setValidating=function(t,e){this.validating.set(t,e)},t.prototype.setRaw=function(t,e){"rightAfter"===this.saveStatus&&(this.saveStatus="after"),this.raw.set(t,e)},t.prototype.removePath=function(t){this.raw=y(this.raw,t),this.errors=y(this.errors,t),this.validating=y(this.validating,t),this.addModePaths=y(this.addModePaths,t)},t.prototype.addPath=function(t){this.raw=g(this.raw,t),this.errors=g(this.errors,t),this.validating=g(this.validating,t),this.addModePaths=g(this.addModePaths,t)},t.prototype.validate=function(){return u(this,void 0,void 0,function(){return c(this,function(t){switch(t.label){case 0:return[4,this.formAccessor.validate()];case 1:return[2,t.sent()]}})})},t.prototype.save=function(){return u(this,void 0,void 0,function(){var e,r;return c(this,function(t){switch(t.label){case 0:return[4,this.validate()];case 1:return e=t.sent(),this.saveStatus="rightAfter",e?[4,this.saveFunc(this.node)]:[2,!1];case 2:return null!=(r=t.sent())?(this.setErrors(r),[2,!1]):(this.clearErrors(),[2,!0])}})})},t.prototype.setErrors=function(r){var n=this;this.flatAccessors.map(function(t){var e=v(r,t.path);null!=e&&n.errors.set(t.path,e)})},t.prototype.clearErrors=function(){this.errors.clear()},t.prototype.isKnownAddModePath=function(r){var n;return this.addModePaths.forEach(function(t,e){r.startsWith(e)&&(n=t)}),void 0!==n&&n},t.prototype.addMode=function(t){return this.isKnownAddModePath(t)&&void 0===this.raw.get(t)},t.prototype.getValue=function(t){return s.resolvePath(this.node,t)},t.prototype.getError=function(t){return this.errors.get(t)},t.prototype.getMstType=function(t){for(var e,r=h(t),n=this.form.model,i=0,o=r;i<o.length;i++){var s=o[i];(e=s,Number.isInteger(parseInt(e,10)))?n=n.getChildType(s):n=n.getChildType(s)}return n},Object.defineProperty(t.prototype,"isValidating",{get:function(){return 0<Array.from(this.validating.values()).filter(function(t){return t}).length},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"accessors",{get:function(){return this.formAccessor.accessors},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"flatAccessors",{get:function(){return this.formAccessor.flatAccessors},enumerable:!0,configurable:!0}),t.prototype.field=function(t){return this.formAccessor.field(t)},t.prototype.repeatingForm=function(t){return this.formAccessor.repeatingForm(t)},t.prototype.repeatingField=function(t){},e([o.observable],t.prototype,"raw",void 0),e([o.observable],t.prototype,"errors",void 0),e([o.observable],t.prototype,"validating",void 0),e([o.observable],t.prototype,"addModePaths",void 0),e([o.observable],t.prototype,"saveStatus",void 0),e([o.action],t.prototype,"setError",null),e([o.action],t.prototype,"deleteError",null),e([o.action],t.prototype,"setValidating",null),e([o.action],t.prototype,"setRaw",null),e([o.action],t.prototype,"removePath",null),e([o.action],t.prototype,"addPath",null),e([o.action],t.prototype,"save",null),e([o.action],t.prototype,"setErrors",null),e([o.action],t.prototype,"clearErrors",null),e([o.computed],t.prototype,"isValidating",null),e([o.computed],t.prototype,"accessors",null),e([o.computed],t.prototype,"flatAccessors",null),t}();function E(){return u(this,void 0,void 0,function(){return c(this,function(t){return console.warn("No mstform save function configured"),[2,null]})})}var V=function(){function t(t,e){this.model=t,this.definition=e}return Object.defineProperty(t.prototype,"FormStateType",{get:function(){throw new Error("For introspection")},enumerable:!0,configurable:!0}),t.prototype.state=function(t,e){return new R(this,t,e)},t}(),F=function(t){this.message=t},O=function(t){this.value=t};function j(t){return t}var A=function(){function t(t,e){if(this.converter=t,this.options=e)if(this.rawValidators=e.rawValidators?e.rawValidators:[],this.validators=e.validators?e.validators:[],this.conversionError=e.conversionError||"Could not convert",this.requiredError=e.requiredError||"Required",this.required=e.required||!1,e.fromEvent){if(e.getRaw)throw new Error("Cannot have fromEvent and getRaw defined at same time");this.getRaw=function(t){return t.target.value}}else this.getRaw=e.getRaw||j;else this.rawValidators=[],this.validators=[],this.conversionError="Could not convert",this.requiredError="Required",this.required=!1,this.getRaw=j}return Object.defineProperty(t.prototype,"RawType",{get:function(){throw new Error("This is a function to enable type introspection")},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"ValueType",{get:function(){throw new Error("This is a function to enable type introspection")},enumerable:!0,configurable:!0}),t.prototype.process=function(a){return u(this,void 0,void 0,function(){var e,r,n,i,o,s;return c(this,function(t){switch(t.label){case 0:if(a===this.converter.emptyRaw&&this.required)return[2,new F(this.requiredError)];e=0,r=this.rawValidators,t.label=1;case 1:return e<r.length?[4,(0,r[e])(a)]:[3,4];case 2:if("string"==typeof(s=t.sent())&&s)return[2,new F(s)];t.label=3;case 3:return e++,[3,1];case 4:return[4,this.converter.convert(a)];case 5:if((n=t.sent())===l)return a===this.converter.emptyRaw?[2,new F(this.requiredError)]:[2,new F(this.conversionError)];i=0,o=this.validators,t.label=6;case 6:return i<o.length?[4,(0,o[i])(n.value)]:[3,9];case 7:if("string"==typeof(s=t.sent())&&s)return[2,new F(s)];t.label=8;case 8:return i++,[3,6];case 9:return[2,new O(n.value)]}})})},t.prototype.render=function(t){return this.converter.render(t)},t}(),S=function(t){this.definition=t},M=function(t){this.options=t},x=new RegExp("^-?(0|[1-9]\\d*)(\\.\\d*)?$"),q=new RegExp("^-?(0|[1-9]\\d*)$"),C=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return function(t,e){function r(){this.constructor=t}n(t,e),t.prototype=null===e?Object.create(e):(r.prototype=e.prototype,new r)}(e,t),e}(r),D=new C({emptyRaw:"",convert:function(t){return t},render:function(t){return t}}),N=new C({emptyRaw:"",rawValidate:function(t){return t.startsWith(".")&&(t="0"+t),x.test(t)},convert:function(t){return+t},render:function(t){return t.toString()}}),_=new C({emptyRaw:"",rawValidate:function(t){return q.test(t)},convert:function(t){return+t},render:function(t){return t.toString()}}),T=function(){function t(t,e){this.maxWholeDigits=t,this.decimalPlaces=e,this.emptyRaw="";var r=new RegExp("^-?(0|[1-9]\\d{0,"+(t-1)+"})(\\.\\d{0,"+e+"})?$");this.converter=new C({emptyRaw:"",rawValidate:function(t){return t.startsWith(".")&&(t="0"+t),r.test(t)},convert:function(t){return t},render:function(t){return t}})}return t.prototype.convert=function(t){return this.converter.convert(t)},t.prototype.render=function(t){return this.converter.render(t)},t.prototype.getRaw=function(t){return t},t}();var W=new r({emptyRaw:[],convert:function(t){return o.observable.array(t)},render:function(t){return t}});var I=function(){function t(t){this.converter=t,this.emptyRaw=""}return t.prototype.convert=function(e){return u(this,void 0,void 0,function(){return c(this,function(t){return""===e.trim()?[2,new i(null)]:[2,this.converter.convert(e)]})})},t.prototype.render=function(t){return null===t?"":this.converter.render(t)},t}(),k=function(){function t(t){this.emptyRaw=null}return t.prototype.convert=function(e){return u(this,void 0,void 0,function(){return c(this,function(t){return null===e?[2,l]:[2,new i(e)]})})},t.prototype.render=function(t){return t},t}();var H={string:D,number:N,integer:_,decimal:function(t,e){return new T(t,e)},stringArray:W,maybe:function(t){return t instanceof C?new I(t):new r({emptyRaw:null,convert:p,render:p})},model:function(t){return new k(t)},object:new r({emptyRaw:null,convert:p,render:p})};t.Form=V,t.ValidationMessage=F,t.ProcessValue=O,t.Field=A,t.RepeatingForm=S,t.RepeatingField=M,t.ConversionValue=i,t.CONVERSION_ERROR=l,t.Converter=r,t.StringConverter=C,t.converters=H,Object.defineProperty(t,"__esModule",{value:!0})}); | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("mobx"),require("mobx-state-tree")):"function"==typeof define&&define.amd?define(["exports","mobx","mobx-state-tree"],e):e(t.mstForm=t.mstForm||{},t.mobx,t["mobx-state-tree"])}(this,function(t,o,s){"use strict";var n=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r])};function e(t,e,r,n){var i,o=arguments.length,s=o<3?e:null===n?n=Object.getOwnPropertyDescriptor(e,r):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)s=Reflect.decorate(t,e,r,n);else for(var a=t.length-1;0<=a;a--)(i=t[a])&&(s=(o<3?i(s):3<o?i(e,r,s):i(e,r))||s);return 3<o&&s&&Object.defineProperty(e,r,s),s}function u(o,s,a,u){return new(a||(a=Promise))(function(t,e){function r(t){try{i(u.next(t))}catch(t){e(t)}}function n(t){try{i(u.throw(t))}catch(t){e(t)}}function i(e){e.done?t(e.value):new a(function(t){t(e.value)}).then(r,n)}i((u=u.apply(o,s||[])).next())})}function c(r,n){var i,o,s,t,a={label:0,sent:function(){if(1&s[0])throw s[1];return s[1]},trys:[],ops:[]};return t={next:e(0),throw:e(1),return:e(2)},"function"==typeof Symbol&&(t[Symbol.iterator]=function(){return this}),t;function e(e){return function(t){return function(e){if(i)throw new TypeError("Generator is already executing.");for(;a;)try{if(i=1,o&&(s=o[2&e[0]?"return":e[0]?"throw":"next"])&&!(s=s.call(o,e[1])).done)return s;switch(o=0,s&&(e=[0,s.value]),e[0]){case 0:case 1:s=e;break;case 4:return a.label++,{value:e[1],done:!1};case 5:a.label++,o=e[1],e=[0];continue;case 7:e=a.ops.pop(),a.trys.pop();continue;default:if(!(s=0<(s=a.trys).length&&s[s.length-1])&&(6===e[0]||2===e[0])){a=0;continue}if(3===e[0]&&(!s||e[1]>s[0]&&e[1]<s[3])){a.label=e[1];break}if(6===e[0]&&a.label<s[1]){a.label=s[1],s=e;break}if(s&&a.label<s[2]){a.label=s[2],a.ops.push(e);break}s[2]&&a.ops.pop(),a.trys.pop();continue}e=n.call(r,a)}catch(t){e=[6,t],o=0}finally{i=s=0}if(5&e[0])throw e[1];return{value:e[0]?e[1]:void 0,done:!0}}([e,t])}}}var i=function(t){this.value=t},l="ConversionError",r=function(){function t(t){this.definition=t,this.emptyRaw=this.definition.emptyRaw}return t.prototype.convert=function(r){return u(this,void 0,void 0,function(){var e;return c(this,function(t){switch(t.label){case 0:return this.definition.rawValidate?[4,this.definition.rawValidate(r)]:[3,2];case 1:if(!t.sent())return[2,l];t.label=2;case 2:return e=this.definition.convert(r),this.definition.validate?[4,this.definition.validate(e)]:[3,4];case 3:if(!t.sent())return[2,l];t.label=4;case 4:return[2,new i(e)]}})})},t.prototype.render=function(t){return this.definition.render(t)},t}(),a=require("fast-deep-equal");function p(t){return t}function h(t){return t.startsWith("/")&&(t=t.slice(1)),t.split("/")}function f(t){var e=t.join("/");return e.startsWith("/")?e:"/"+e}function d(t){return o.isObservable(t)?o.toJS(t):t}function v(t,e){return function t(e,r){var n=r[0],i=r.slice(1);if(0===i.length)return e[n];var o=e[n];if(void 0===o)return;return t(o,i)}(t,h(e))}function y(t,e){var r=h(e),n=r[r.length-1],s=parseInt(n,10),a=f(r.slice(0,r.length-1)),u=new Map;return t.forEach(function(t,e){if(e.startsWith(a)){var r=h(e.slice(a.length+1)),n=parseInt(r[0],10);if(isNaN(n))u.set(e,t);else if(n<s)u.set(e,t);else if(n!==s){var i=r.slice(1),o=a+f([(n-1).toString()].concat(i));u.delete(e),u.set(o,t)}}else u.set(e,t)}),u}function b(t,e){var r=h(e),n=r[r.length-1],s=parseInt(n,10);if(isNaN(s))return t;var a=f(r.slice(0,r.length-1)),u=new Map;return t.forEach(function(t,e){if(e.startsWith(a)){var r=h(e.slice(a.length+1)),n=parseInt(r[0],10);if(isNaN(n))u.set(e,t);else if(n<s)u.set(e,t);else{var i=r.slice(1),o=a+f([(n+1).toString()].concat(i));u.set(o,t)}}else u.set(e,t)}),u}var g=function(){function t(t,e,r){this.state=t,this.definition=e,this.path=r}return t.prototype.validate=function(){return u(this,void 0,void 0,function(){var e;return c(this,function(t){switch(t.label){case 0:return e=this.accessors.map(function(t){return t.validate()}),[4,Promise.all(e)];case 1:return[2,0===t.sent().filter(function(t){return!t}).length]}})})},Object.defineProperty(t.prototype,"accessors",{get:function(){var r=this,n=[];return Object.keys(this.definition).forEach(function(t){var e=r.definition[t];e instanceof A?n.push(r.field(t)):e instanceof S&&n.push(r.repeatingForm(t))}),n},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"flatAccessors",{get:function(){var e=[];return this.accessors.forEach(function(t){t instanceof m?e.push(t):t instanceof w&&(e.push.apply(e,t.flatAccessors),e.push(t))}),e},enumerable:!0,configurable:!0}),t.prototype.field=function(t){var e=this.definition[t];if(!(e instanceof A))throw new Error("Not accessing a Field instance");return new m(this.state,e,this.path,t)},t.prototype.repeatingForm=function(t){var e=this.definition[t];if(!(e instanceof S))throw new Error("Not accessing a RepeatingForm instance");return new w(this.state,e,this.path,t)},t.prototype.repeatingField=function(t){},e([o.computed],t.prototype,"accessors",null),e([o.computed],t.prototype,"flatAccessors",null),t}(),m=function(){function t(t,e,r,n){var i=this;this.state=t,this.field=e,this.handleChange=function(){for(var n=[],t=0;t<arguments.length;t++)n[t]=arguments[t];return u(i,void 0,void 0,function(){var e,r;return c(this,function(t){switch(t.label){case 0:return e=(r=this.field).getRaw.apply(r,n),[4,this.setRaw(e)];case 1:return t.sent(),[2]}})})},this.name=n,process,this.path=r+"/"+n}return Object.defineProperty(t.prototype,"addMode",{get:function(){return this.state.addMode(this.path)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"raw",{get:function(){var t=this.state.raw.get(this.path);return void 0!==t?o.toJS(t):this.addMode?this.field.converter.emptyRaw:this.field.render(this.state.getValue(this.path))},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"value",{get:function(){if(this.addMode)throw new Error("Cannot access field in add mode until it has been set once");return this.state.getValue(this.path)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"errorValue",{get:function(){return this.state.getError(this.path)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"canShowValidationMessages",{get:function(){if("rightAfter"===this.state.saveStatus)return!0;var t="before"===this.state.saveStatus?this.state.validationBeforeSave:this.state.validationAfterSave;return"immediate"===t||"no"!==t&&("blur"!==t&&"pause"!==t)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"error",{get:function(){return this.canShowValidationMessages?this.errorValue:void 0},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"isValidating",{get:function(){return this.state.validating.get(this.path)||!1},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"disabled",{get:function(){return this.state.isDisabledFunc(this)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"hidden",{get:function(){return this.state.isHiddenFunc(this)},enumerable:!0,configurable:!0}),t.prototype.validate=function(){return u(this,void 0,void 0,function(){return c(this,function(t){switch(t.label){case 0:return[4,this.setRaw(this.raw)];case 1:return t.sent(),[2,void 0===this.errorValue]}})})},t.prototype.setRaw=function(i){return u(this,void 0,void 0,function(){var e,r,n;return c(this,function(t){switch(t.label){case 0:this.state.setRaw(this.path,i),this.state.setValidating(this.path,!0),t.label=1;case 1:return t.trys.push([1,3,,4]),[4,this.field.process(i)];case 2:return e=t.sent(),[3,4];case 3:return t.sent(),this.state.setError(this.path,"Something went wrong"),this.state.setValidating(this.path,!1),[2];case 4:if(r=this.state.raw.get(this.path),!a(d(r),d(i)))return[2];if(this.state.setValidating(this.path,!1),e instanceof F)return this.state.setError(this.path,e.message),[2];if(this.state.deleteError(this.path),!(e instanceof O))throw new Error("Unknown process result");return"string"==typeof(n=this.state.extraValidationFunc(this,e.value))&&n&&this.state.setError(this.path,n),s.applyPatch(this.state.node,[{op:"replace",path:this.path,value:e.value}]),[2]}})})},Object.defineProperty(t.prototype,"inputProps",{get:function(){return{disabled:this.disabled,value:this.raw,onChange:this.handleChange}},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"validationProps",{get:function(){var t=this.errorValue,e=this.isValidating;return t?{validateStatus:e?"validating":"error",help:t}:{validateStatus:e?"validating":""}},enumerable:!0,configurable:!0}),e([o.computed],t.prototype,"addMode",null),e([o.computed],t.prototype,"raw",null),e([o.computed],t.prototype,"value",null),e([o.computed],t.prototype,"errorValue",null),e([o.computed],t.prototype,"canShowValidationMessages",null),e([o.computed],t.prototype,"error",null),e([o.computed],t.prototype,"isValidating",null),e([o.computed],t.prototype,"disabled",null),e([o.computed],t.prototype,"hidden",null),e([o.action],t.prototype,"setRaw",null),e([o.computed],t.prototype,"inputProps",null),e([o.computed],t.prototype,"validationProps",null),t}(),w=function(){function t(t,e,r,n){this.state=t,this.repeatingForm=e,this.name=n,this.path=r+"/"+n}return t.prototype.validate=function(){return u(this,void 0,void 0,function(){var e,r,n,i;return c(this,function(t){switch(t.label){case 0:for(e=[],r=0,n=this.accessors;r<n.length;r++)i=n[r],e.push(i.validate());return[4,Promise.all(e)];case 1:return[2,0===t.sent().filter(function(t){return!t}).length]}})})},t.prototype.index=function(t){return new P(this.state,this.repeatingForm.definition,this.path,t)},Object.defineProperty(t.prototype,"disabled",{get:function(){return this.state.isRepeatingFormDisabledFunc(this)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"accessors",{get:function(){for(var t=[],e=0;e<this.length;e++)t.push(this.index(e));return t},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"flatAccessors",{get:function(){var e=[];return this.accessors.forEach(function(t){e.push.apply(e,t.flatAccessors)}),e},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"error",{get:function(){return this.state.errors.get(this.path)},enumerable:!0,configurable:!0}),t.prototype.insert=function(t,e){var r=this.path+"/"+t;s.applyPatch(this.state.node,[{op:"add",path:r,value:e}]),this.state.addModePaths.set(r,!0)},t.prototype.push=function(t){var e=s.resolvePath(this.state.node,this.path),r=this.path+"/"+e.length;s.applyPatch(this.state.node,[{op:"add",path:r,value:t}]),this.state.addModePaths.set(r,!0)},t.prototype.remove=function(t){var e=s.resolvePath(this.state.node,this.path).indexOf(t);if(-1===e)throw new Error("Cannot find node to remove.");s.applyPatch(this.state.node,[{op:"remove",path:this.path+"/"+e}])},Object.defineProperty(t.prototype,"length",{get:function(){return s.resolvePath(this.state.node,this.path).length},enumerable:!0,configurable:!0}),e([o.computed],t.prototype,"disabled",null),e([o.computed],t.prototype,"accessors",null),e([o.computed],t.prototype,"flatAccessors",null),e([o.computed],t.prototype,"error",null),t}(),P=function(){function t(t,e,r,n){this.state=t,this.definition=e,this.index=n,this.path=r+"/"+n,this.formAccessor=new g(t,e,r+"/"+n)}return t.prototype.validate=function(){return u(this,void 0,void 0,function(){return c(this,function(t){return[2,this.formAccessor.validate()]})})},t.prototype.field=function(t){return this.formAccessor.field(t)},t.prototype.repeatingForm=function(t){return this.formAccessor.repeatingForm(t)},Object.defineProperty(t.prototype,"accessors",{get:function(){return this.formAccessor.accessors},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"flatAccessors",{get:function(){return this.formAccessor.flatAccessors},enumerable:!0,configurable:!0}),e([o.computed],t.prototype,"accessors",null),e([o.computed],t.prototype,"flatAccessors",null),t}(),R=function(){function t(t,e,r){var n=this;if(this.form=t,this.node=e,this.saveStatus="before",this.raw=o.observable.map(),this.errors=o.observable.map(),this.validating=o.observable.map(),this.addModePaths=o.observable.map(),s.onPatch(e,function(t){"remove"===t.op?n.removePath(t.path):"add"===t.op&&n.addPath(t.path)}),this.formAccessor=new g(this,this.form.definition,""),null==r)this.saveFunc=E,this.isDisabledFunc=function(){return!1},this.isHiddenFunc=function(){return!1},this.isRepeatingFormDisabledFunc=function(){return!1},this.extraValidationFunc=function(){return!1},this.validationBeforeSave="immediate",this.validationAfterSave="immediate",this.validationPauseDuration=0,this.addModePaths.set("/",!1);else{this.saveFunc=r.save?r.save:E,this.isDisabledFunc=r.isDisabled?r.isDisabled:function(){return!1},this.isHiddenFunc=r.isHidden?r.isHidden:function(){return!1},this.isRepeatingFormDisabledFunc=r.isRepeatingFormDisabled?r.isRepeatingFormDisabled:function(){return!1},this.extraValidationFunc=r.extraValidation?r.extraValidation:function(){return!1},this.addModePaths.set("/",r.addMode||!1);var i=r.validation||{};this.validationBeforeSave=i.beforeSave||"immediate",this.validationAfterSave=i.afterSave||"immediate",this.validationPauseDuration=i.pauseDuration||0}}return t.prototype.setError=function(t,e){this.errors.set(t,e)},t.prototype.deleteError=function(t){this.errors.delete(t)},t.prototype.setValidating=function(t,e){this.validating.set(t,e)},t.prototype.setRaw=function(t,e){"rightAfter"===this.saveStatus&&(this.saveStatus="after"),this.raw.set(t,e)},t.prototype.removePath=function(t){this.raw=y(this.raw,t),this.errors=y(this.errors,t),this.validating=y(this.validating,t),this.addModePaths=y(this.addModePaths,t)},t.prototype.addPath=function(t){this.raw=b(this.raw,t),this.errors=b(this.errors,t),this.validating=b(this.validating,t),this.addModePaths=b(this.addModePaths,t)},t.prototype.validate=function(){return u(this,void 0,void 0,function(){return c(this,function(t){switch(t.label){case 0:return[4,this.formAccessor.validate()];case 1:return[2,t.sent()]}})})},t.prototype.save=function(){return u(this,void 0,void 0,function(){var e,r;return c(this,function(t){switch(t.label){case 0:return[4,this.validate()];case 1:return e=t.sent(),this.saveStatus="rightAfter",e?[4,this.saveFunc(this.node)]:[2,!1];case 2:return null!=(r=t.sent())?(this.setErrors(r),[2,!1]):(this.clearErrors(),[2,!0])}})})},t.prototype.setErrors=function(r){var n=this;this.flatAccessors.map(function(t){var e=v(r,t.path);null!=e&&n.errors.set(t.path,e)})},t.prototype.clearErrors=function(){this.errors.clear()},t.prototype.isKnownAddModePath=function(r){var n;return this.addModePaths.forEach(function(t,e){r.startsWith(e)&&(n=t)}),void 0!==n&&n},t.prototype.addMode=function(t){return this.isKnownAddModePath(t)&&void 0===this.raw.get(t)},t.prototype.getValue=function(t){return s.resolvePath(this.node,t)},t.prototype.getError=function(t){return this.errors.get(t)},t.prototype.getMstType=function(t){for(var e,r=h(t),n=this.form.model,i=0,o=r;i<o.length;i++){var s=o[i];(e=s,Number.isInteger(parseInt(e,10)))?n=n.getChildType(s):n=n.getChildType(s)}return n},Object.defineProperty(t.prototype,"isValidating",{get:function(){return 0<Array.from(this.validating.values()).filter(function(t){return t}).length},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"accessors",{get:function(){return this.formAccessor.accessors},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"flatAccessors",{get:function(){return this.formAccessor.flatAccessors},enumerable:!0,configurable:!0}),t.prototype.field=function(t){return this.formAccessor.field(t)},t.prototype.repeatingForm=function(t){return this.formAccessor.repeatingForm(t)},t.prototype.repeatingField=function(t){},e([o.observable],t.prototype,"raw",void 0),e([o.observable],t.prototype,"errors",void 0),e([o.observable],t.prototype,"validating",void 0),e([o.observable],t.prototype,"addModePaths",void 0),e([o.observable],t.prototype,"saveStatus",void 0),e([o.action],t.prototype,"setError",null),e([o.action],t.prototype,"deleteError",null),e([o.action],t.prototype,"setValidating",null),e([o.action],t.prototype,"setRaw",null),e([o.action],t.prototype,"removePath",null),e([o.action],t.prototype,"addPath",null),e([o.action],t.prototype,"save",null),e([o.action],t.prototype,"setErrors",null),e([o.action],t.prototype,"clearErrors",null),e([o.computed],t.prototype,"isValidating",null),e([o.computed],t.prototype,"accessors",null),e([o.computed],t.prototype,"flatAccessors",null),t}();function E(){return u(this,void 0,void 0,function(){return c(this,function(t){return console.warn("No mstform save function configured"),[2,null]})})}var V=function(){function t(t,e){this.model=t,this.definition=e}return Object.defineProperty(t.prototype,"FormStateType",{get:function(){throw new Error("For introspection")},enumerable:!0,configurable:!0}),t.prototype.state=function(t,e){return new R(this,t,e)},t}(),F=function(t){this.message=t},O=function(t){this.value=t};function j(t){return t}var A=function(){function t(t,e){if(this.converter=t,this.options=e)if(this.rawValidators=e.rawValidators?e.rawValidators:[],this.validators=e.validators?e.validators:[],this.conversionError=e.conversionError||"Could not convert",this.requiredError=e.requiredError||"Required",this.required=e.required||!1,e.fromEvent){if(e.getRaw)throw new Error("Cannot have fromEvent and getRaw defined at same time");this.getRaw=function(t){return t.target.value}}else this.getRaw=e.getRaw||j;else this.rawValidators=[],this.validators=[],this.conversionError="Could not convert",this.requiredError="Required",this.required=!1,this.getRaw=j}return Object.defineProperty(t.prototype,"RawType",{get:function(){throw new Error("This is a function to enable type introspection")},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"ValueType",{get:function(){throw new Error("This is a function to enable type introspection")},enumerable:!0,configurable:!0}),t.prototype.process=function(a){return u(this,void 0,void 0,function(){var e,r,n,i,o,s;return c(this,function(t){switch(t.label){case 0:if(a===this.converter.emptyRaw&&this.required)return[2,new F(this.requiredError)];e=0,r=this.rawValidators,t.label=1;case 1:return e<r.length?[4,(0,r[e])(a)]:[3,4];case 2:if("string"==typeof(s=t.sent())&&s)return[2,new F(s)];t.label=3;case 3:return e++,[3,1];case 4:return[4,this.converter.convert(a)];case 5:if((n=t.sent())===l)return a===this.converter.emptyRaw?[2,new F(this.requiredError)]:[2,new F(this.conversionError)];i=0,o=this.validators,t.label=6;case 6:return i<o.length?[4,(0,o[i])(n.value)]:[3,9];case 7:if("string"==typeof(s=t.sent())&&s)return[2,new F(s)];t.label=8;case 8:return i++,[3,6];case 9:return[2,new O(n.value)]}})})},t.prototype.render=function(t){return this.converter.render(t)},t}(),S=function(t){this.definition=t},M=function(t){this.options=t},x=new RegExp("^-?(0|[1-9]\\d*)(\\.\\d*)?$"),q=new RegExp("^-?(0|[1-9]\\d*)$"),C=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return function(t,e){function r(){this.constructor=t}n(t,e),t.prototype=null===e?Object.create(e):(r.prototype=e.prototype,new r)}(e,t),e}(r),D=new C({emptyRaw:"",convert:function(t){return t},render:function(t){return t}}),N=new C({emptyRaw:"",rawValidate:function(t){return t.startsWith(".")&&(t="0"+t),x.test(t)},convert:function(t){return+t},render:function(t){return t.toString()}}),_=new C({emptyRaw:"",rawValidate:function(t){return q.test(t)},convert:function(t){return+t},render:function(t){return t.toString()}}),T=new r({emptyRaw:!1,convert:function(t){return t},render:function(t){return t}}),W=function(){function t(t,e){this.maxWholeDigits=t,this.decimalPlaces=e,this.emptyRaw="";var r=new RegExp("^-?(0|[1-9]\\d{0,"+(t-1)+"})(\\.\\d{0,"+e+"})?$");this.converter=new C({emptyRaw:"",rawValidate:function(t){return t.startsWith(".")&&(t="0"+t),r.test(t)},convert:function(t){return t},render:function(t){return t}})}return t.prototype.convert=function(t){return this.converter.convert(t)},t.prototype.render=function(t){return this.converter.render(t)},t.prototype.getRaw=function(t){return t},t}();var I=new r({emptyRaw:[],convert:function(t){return o.observable.array(t)},render:function(t){return t.slice()}});var k=function(){function t(t){this.converter=t,this.emptyRaw=""}return t.prototype.convert=function(e){return u(this,void 0,void 0,function(){return c(this,function(t){return""===e.trim()?[2,new i(null)]:[2,this.converter.convert(e)]})})},t.prototype.render=function(t){return null===t?"":this.converter.render(t)},t}(),H=function(){function t(t){this.emptyRaw=null}return t.prototype.convert=function(e){return u(this,void 0,void 0,function(){return c(this,function(t){return null===e?[2,l]:[2,new i(e)]})})},t.prototype.render=function(t){return t},t}();var B={string:D,number:N,integer:_,decimal:function(t,e){return new W(t,e)},boolean:T,stringArray:I,maybe:function(t){return t instanceof C?new k(t):new r({emptyRaw:null,convert:p,render:p})},model:function(t){return new H(t)},object:new r({emptyRaw:null,convert:p,render:p})};t.Form=V,t.ValidationMessage=F,t.ProcessValue=O,t.Field=A,t.RepeatingForm=S,t.RepeatingField=M,t.ConversionValue=i,t.CONVERSION_ERROR=l,t.Converter=r,t.StringConverter=C,t.converters=B,Object.defineProperty(t,"__esModule",{value:!0})}); |
{ | ||
"name": "mstform", | ||
"private": false, | ||
"version": "0.4.0", | ||
"version": "0.5.0", | ||
"description": "mobx-state-tree powered forms", | ||
@@ -6,0 +6,0 @@ "main": "dist/mstform.js", |
132361
2941