New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

mstform

Package Overview
Dependencies
Maintainers
1
Versions
108
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mstform - npm Package Compare versions

Comparing version 0.3.4 to 0.4.0

dist/accessor.d.ts

120

dist/form.d.ts
import { IObservableArray } from "mobx";
import { IModelType, IType } from "mobx-state-tree";
import { IModelType } from "mobx-state-tree";
import { IConverter } from "./converter";
import { FieldOptions, FormStateOptions, RawGetter, SaveFunc, ValidationOption, Validator } from "./types";
import { FormState, FormStateOptions } from "./state";
import { FieldOptions, RawGetter, Validator } from "./types";
export declare type ArrayEntryType<T> = T extends IObservableArray<infer A> ? A : never;
export declare type RawType<F> = F extends Field<infer R, any> ? R : never;
export declare type FormDefinitionType<T> = T extends RepeatingForm<any, infer D> ? D : never;
export declare type Accessor = FieldAccessor<any, any> | RepeatingFormAccessor<any, any> | RepeatingFormIndexedAccessor<any, any>;
export declare type FormDefinition<M> = {

@@ -28,11 +28,2 @@ [K in keyof M]?: Field<any, M[K]> | RepeatingForm<ArrayEntryType<M[K]>, any>;

export declare type ProcessResponse<V> = ProcessValue<V> | ValidationMessage;
export declare type FieldAccess<M, D extends FormDefinition<M>, K extends keyof M> = FieldAccessor<RawType<D[K]>, M[K]>;
export declare type RepeatingFormAccess<M, D extends FormDefinition<M>, K extends keyof M> = RepeatingFormAccessor<ArrayEntryType<M[K]>, FormDefinitionType<D[K]>>;
export interface IFormAccessor<M, D extends FormDefinition<M>> {
validate(): Promise<boolean>;
field<K extends keyof M>(name: K): FieldAccess<M, D, K>;
repeatingForm<K extends keyof M>(name: K): RepeatingFormAccess<M, D, K>;
accessors: Accessor[];
flatAccessors: Accessor[];
}
export declare class Field<R, V> {

@@ -61,106 +52,1 @@ converter: IConverter<R, V>;

}
export declare class FormState<M, D extends FormDefinition<M>> implements IFormAccessor<M, D> {
form: Form<M, D>;
node: M;
raw: Map<string, any>;
errors: Map<string, string>;
validating: Map<string, boolean>;
addModePaths: Map<string, boolean>;
formAccessor: FormAccessor<M, D>;
saveFunc?: SaveFunc<M>;
validationBeforeSave: ValidationOption;
validationAfterSave: ValidationOption;
validationPauseDuration: number;
saveStatus: "before" | "rightAfter" | "after";
constructor(form: Form<M, D>, node: M, options?: FormStateOptions<M>);
setError(path: string, value: string): void;
deleteError(path: string): void;
setValidating(path: string, value: boolean): void;
setRaw(path: string, value: any): void;
removePath(path: string): void;
addPath(path: string): void;
validate(): Promise<boolean>;
save(): Promise<boolean>;
setErrors(errors: any): void;
clearErrors(): void;
isKnownAddModePath(path: string): boolean;
addMode(path: string): boolean;
getValue(path: string): any;
getError(path: string): string | undefined;
getMstType(path: string): IType<any, any>;
readonly isValidating: boolean;
readonly accessors: Accessor[];
readonly flatAccessors: Accessor[];
field<K extends keyof M>(name: K): FieldAccess<M, D, K>;
repeatingForm<K extends keyof M>(name: K): RepeatingFormAccess<M, D, K>;
repeatingField(name: string): any;
}
export declare class FormAccessor<M, D extends FormDefinition<M>> implements IFormAccessor<M, D> {
state: FormState<M, D>;
definition: any;
path: string;
constructor(state: FormState<M, D>, definition: any, path: string);
validate(): Promise<boolean>;
readonly accessors: Accessor[];
readonly flatAccessors: Accessor[];
field<K extends keyof M>(name: K): FieldAccess<M, D, K>;
repeatingForm<K extends keyof M>(name: K): RepeatingFormAccess<M, D, K>;
repeatingField(name: string): any;
}
export declare class FieldAccessor<R, V> {
state: FormState<any, any>;
field: Field<R, V>;
path: string;
name: string;
constructor(state: FormState<any, any>, field: Field<R, V>, path: string, name: string);
readonly addMode: boolean;
readonly raw: R;
readonly value: V;
readonly errorValue: string | undefined;
readonly canShowValidationMessages: boolean;
readonly error: string | undefined;
readonly isValidating: boolean;
validate(): Promise<boolean>;
setRaw(raw: R): Promise<void>;
handleChange: (...args: any[]) => Promise<void>;
readonly inputProps: {
value: R;
onChange: (...args: any[]) => Promise<void>;
};
readonly validationProps: {
validateStatus: string;
help?: undefined;
} | {
validateStatus: string;
help: string;
};
}
export declare class RepeatingFormAccessor<M, D extends FormDefinition<M>> {
state: FormState<any, any>;
repeatingForm: RepeatingForm<M, D>;
name: string;
path: string;
constructor(state: FormState<any, any>, repeatingForm: RepeatingForm<M, D>, path: string, name: string);
validate(): Promise<boolean>;
index(index: number): RepeatingFormIndexedAccessor<M, D>;
readonly accessors: RepeatingFormIndexedAccessor<M, D>[];
readonly flatAccessors: Accessor[];
readonly error: string | undefined;
insert(index: number, node: any): void;
push(node: any): void;
remove(node: any): void;
readonly length: number;
}
export declare class RepeatingFormIndexedAccessor<M, D extends FormDefinition<M>> implements IFormAccessor<M, D> {
state: FormState<any, any>;
definition: any;
index: number;
path: string;
formAccessor: FormAccessor<M, D>;
constructor(state: FormState<any, any>, definition: any, path: string, index: number);
validate(): Promise<boolean>;
field<K extends keyof M>(name: K): FieldAccess<M, D, K>;
repeatingForm<K extends keyof M>(name: K): RepeatingFormAccess<M, D, K>;
readonly accessors: Accessor[];
readonly flatAccessors: Accessor[];
}

@@ -242,381 +242,2 @@ 'use strict';

var Form = /** @class */ (function () {
function Form(model, definition) {
this.model = model;
this.definition = definition;
}
Object.defineProperty(Form.prototype, "FormStateType", {
get: function () {
throw new Error("For introspection");
},
enumerable: true,
configurable: true
});
Form.prototype.state = function (node, options) {
return new FormState(this, node, options);
};
return Form;
}());
var ValidationMessage = /** @class */ (function () {
function ValidationMessage(message) {
this.message = message;
}
return ValidationMessage;
}());
var ProcessValue = /** @class */ (function () {
function ProcessValue(value) {
this.value = value;
}
return ProcessValue;
}());
function identity(value) {
return value;
}
var Field = /** @class */ (function () {
function Field(converter, options) {
this.converter = converter;
this.options = options;
if (!options) {
this.rawValidators = [];
this.validators = [];
this.conversionError = "Could not convert";
this.requiredError = "Required";
this.required = false;
this.getRaw = identity;
}
else {
this.rawValidators = options.rawValidators ? options.rawValidators : [];
this.validators = options.validators ? options.validators : [];
this.conversionError = options.conversionError || "Could not convert";
this.requiredError = options.requiredError || "Required";
this.required = options.required || false;
if (options.fromEvent) {
if (options.getRaw) {
throw new Error("Cannot have fromEvent and getRaw defined at same time");
}
this.getRaw = function (ev) { return ev.target.value; };
}
else {
this.getRaw = options.getRaw || identity;
}
}
}
Object.defineProperty(Field.prototype, "RawType", {
get: function () {
throw new Error("This is a function to enable type introspection");
},
enumerable: true,
configurable: true
});
Object.defineProperty(Field.prototype, "ValueType", {
get: function () {
throw new Error("This is a function to enable type introspection");
},
enumerable: true,
configurable: true
});
Field.prototype.process = function (raw) {
return __awaiter(this, void 0, void 0, function () {
var _i, _a, validator, validationResponse, result, _b, _c, validator, validationResponse;
return __generator(this, function (_d) {
switch (_d.label) {
case 0:
if (raw === this.converter.emptyRaw && this.required) {
return [2 /*return*/, new ValidationMessage(this.requiredError)];
}
_i = 0, _a = this.rawValidators;
_d.label = 1;
case 1:
if (!(_i < _a.length)) return [3 /*break*/, 4];
validator = _a[_i];
return [4 /*yield*/, validator(raw)];
case 2:
validationResponse = _d.sent();
if (typeof validationResponse === "string" && validationResponse) {
return [2 /*return*/, new ValidationMessage(validationResponse)];
}
_d.label = 3;
case 3:
_i++;
return [3 /*break*/, 1];
case 4: return [4 /*yield*/, this.converter.convert(raw)];
case 5:
result = _d.sent();
if (result === CONVERSION_ERROR) {
// if we get a conversion error for the empty raw, the field
// is implied to be required
if (raw === this.converter.emptyRaw) {
return [2 /*return*/, new ValidationMessage(this.requiredError)];
}
return [2 /*return*/, new ValidationMessage(this.conversionError)];
}
_b = 0, _c = this.validators;
_d.label = 6;
case 6:
if (!(_b < _c.length)) return [3 /*break*/, 9];
validator = _c[_b];
return [4 /*yield*/, validator(result.value)];
case 7:
validationResponse = _d.sent();
if (typeof validationResponse === "string" && validationResponse) {
return [2 /*return*/, new ValidationMessage(validationResponse)];
}
_d.label = 8;
case 8:
_b++;
return [3 /*break*/, 6];
case 9: return [2 /*return*/, new ProcessValue(result.value)];
}
});
});
};
Field.prototype.render = function (value) {
return this.converter.render(value);
};
return Field;
}());
var RepeatingForm = /** @class */ (function () {
function RepeatingForm(definition) {
this.definition = definition;
}
return RepeatingForm;
}());
var RepeatingField = /** @class */ (function () {
function RepeatingField(options) {
this.options = options;
}
return RepeatingField;
}());
var FormState = /** @class */ (function () {
function FormState(form, node, options) {
var _this = this;
this.form = form;
this.node = node;
this.saveStatus = "before";
this.raw = mobx.observable.map();
this.errors = mobx.observable.map();
this.validating = mobx.observable.map();
this.addModePaths = mobx.observable.map();
mobxStateTree.onPatch(node, function (patch) {
if (patch.op === "remove") {
_this.removePath(patch.path);
}
if (patch.op === "add") {
_this.addPath(patch.path);
}
});
this.formAccessor = new FormAccessor(this, this.form.definition, "");
if (options == null) {
this.saveFunc = undefined;
this.validationBeforeSave = "immediate";
this.validationAfterSave = "immediate";
this.validationPauseDuration = 0;
this.addModePaths.set("/", false);
}
else {
this.saveFunc = options.save;
this.addModePaths.set("/", options.addMode || false);
var validation = options.validation || {};
this.validationBeforeSave = validation.beforeSave || "immediate";
this.validationAfterSave = validation.afterSave || "immediate";
this.validationPauseDuration = validation.pauseDuration || 0;
}
}
FormState.prototype.setError = function (path, value) {
this.errors.set(path, value);
};
FormState.prototype.deleteError = function (path) {
this.errors.delete(path);
};
FormState.prototype.setValidating = function (path, value) {
this.validating.set(path, value);
};
FormState.prototype.setRaw = function (path, value) {
if (this.saveStatus === "rightAfter") {
this.saveStatus = "after";
}
this.raw.set(path, value);
};
FormState.prototype.removePath = function (path) {
this.raw = removePath(this.raw, path);
this.errors = removePath(this.errors, path);
this.validating = removePath(this.validating, path);
this.addModePaths = removePath(this.addModePaths, path);
};
FormState.prototype.addPath = function (path) {
this.raw = addPath(this.raw, path);
this.errors = addPath(this.errors, path);
this.validating = addPath(this.validating, path);
this.addModePaths = addPath(this.addModePaths, path);
};
FormState.prototype.validate = function () {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, this.formAccessor.validate()];
case 1: return [2 /*return*/, _a.sent()];
}
});
});
};
FormState.prototype.save = function () {
return __awaiter(this, void 0, void 0, function () {
var isValid, errors;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, this.validate()];
case 1:
isValid = _a.sent();
this.saveStatus = "rightAfter";
if (!isValid) {
return [2 /*return*/, false];
}
if (!(this.saveFunc != null)) return [3 /*break*/, 3];
return [4 /*yield*/, this.saveFunc(this.node)];
case 2:
errors = _a.sent();
return [3 /*break*/, 4];
case 3:
console.warn("No mstform save function configured");
errors = null;
_a.label = 4;
case 4:
if (errors != null) {
this.setErrors(errors);
return [2 /*return*/, false];
}
this.clearErrors();
return [2 /*return*/, true];
}
});
});
};
FormState.prototype.setErrors = function (errors) {
var _this = this;
this.flatAccessors.map(function (accessor) {
var error = getByPath(errors, accessor.path);
if (error != null) {
_this.errors.set(accessor.path, error);
}
});
};
FormState.prototype.clearErrors = function () {
this.errors.clear();
};
FormState.prototype.isKnownAddModePath = function (path) {
var found;
this.addModePaths.forEach(function (value, key) {
if (path.startsWith(key)) {
found = value;
return;
}
});
if (found === undefined) {
return false;
}
return found;
};
FormState.prototype.addMode = function (path) {
return this.isKnownAddModePath(path) && this.raw.get(path) === undefined;
};
FormState.prototype.getValue = function (path) {
return mobxStateTree.resolvePath(this.node, path);
};
FormState.prototype.getError = function (path) {
return this.errors.get(path);
};
FormState.prototype.getMstType = function (path) {
var steps = pathToSteps(path);
var subType = this.form.model;
for (var _i = 0, steps_1 = steps; _i < steps_1.length; _i++) {
var step = steps_1[_i];
if (isInt(step)) {
subType = subType.getChildType(step);
continue;
}
subType = subType.getChildType(step);
}
return subType;
};
Object.defineProperty(FormState.prototype, "isValidating", {
get: function () {
return (Array.from(this.validating.values()).filter(function (value) { return value; }).length > 0);
},
enumerable: true,
configurable: true
});
Object.defineProperty(FormState.prototype, "accessors", {
get: function () {
return this.formAccessor.accessors;
},
enumerable: true,
configurable: true
});
Object.defineProperty(FormState.prototype, "flatAccessors", {
get: function () {
return this.formAccessor.flatAccessors;
},
enumerable: true,
configurable: true
});
FormState.prototype.field = function (name) {
return this.formAccessor.field(name);
};
FormState.prototype.repeatingForm = function (name) {
return this.formAccessor.repeatingForm(name);
};
FormState.prototype.repeatingField = function (name) { };
__decorate([
mobx.observable
], FormState.prototype, "raw", void 0);
__decorate([
mobx.observable
], FormState.prototype, "errors", void 0);
__decorate([
mobx.observable
], FormState.prototype, "validating", void 0);
__decorate([
mobx.observable
], FormState.prototype, "addModePaths", void 0);
__decorate([
mobx.observable
], FormState.prototype, "saveStatus", void 0);
__decorate([
mobx.action
], FormState.prototype, "setError", null);
__decorate([
mobx.action
], FormState.prototype, "deleteError", null);
__decorate([
mobx.action
], FormState.prototype, "setValidating", null);
__decorate([
mobx.action
], FormState.prototype, "setRaw", null);
__decorate([
mobx.action
], FormState.prototype, "removePath", null);
__decorate([
mobx.action
], FormState.prototype, "addPath", null);
__decorate([
mobx.action
], FormState.prototype, "save", null);
__decorate([
mobx.action
], FormState.prototype, "setErrors", null);
__decorate([
mobx.action
], FormState.prototype, "clearErrors", null);
__decorate([
mobx.computed
], FormState.prototype, "isValidating", null);
__decorate([
mobx.computed
], FormState.prototype, "accessors", null);
__decorate([
mobx.computed
], FormState.prototype, "flatAccessors", null);
return FormState;
}());
var FormAccessor = /** @class */ (function () {

@@ -726,2 +347,3 @@ function FormAccessor(state, definition, path) {

this.name = name;
process;
this.path = path + "/" + name;

@@ -810,2 +432,16 @@ }

});
Object.defineProperty(FieldAccessor.prototype, "disabled", {
get: function () {
return this.state.isDisabledFunc(this);
},
enumerable: true,
configurable: true
});
Object.defineProperty(FieldAccessor.prototype, "hidden", {
get: function () {
return this.state.isHiddenFunc(this);
},
enumerable: true,
configurable: true
});
FieldAccessor.prototype.validate = function () {

@@ -825,3 +461,3 @@ return __awaiter(this, void 0, void 0, function () {

return __awaiter(this, void 0, void 0, function () {
var processResult, e_1, currentRaw;
var processResult, e_1, currentRaw, extraResult;
return __generator(this, function (_a) {

@@ -837,2 +473,4 @@ switch (_a.label) {

case 2:
// XXX is await correct here? we should await the result
// later
processResult = _a.sent();

@@ -862,2 +500,7 @@ return [3 /*break*/, 4];

}
extraResult = this.state.extraValidationFunc(this, processResult.value);
// XXX possible flicker?
if (typeof extraResult === "string" && extraResult) {
this.state.setError(this.path, extraResult);
}
mobxStateTree.applyPatch(this.state.node, [

@@ -874,2 +517,3 @@ { op: "replace", path: this.path, value: processResult.value }

return {
disabled: this.disabled,
value: this.raw,

@@ -919,2 +563,8 @@ onChange: this.handleChange

__decorate([
mobx.computed
], FieldAccessor.prototype, "disabled", null);
__decorate([
mobx.computed
], FieldAccessor.prototype, "hidden", null);
__decorate([
mobx.action

@@ -959,2 +609,9 @@ ], FieldAccessor.prototype, "setRaw", null);

};
Object.defineProperty(RepeatingFormAccessor.prototype, "disabled", {
get: function () {
return this.state.isRepeatingFormDisabledFunc(this);
},
enumerable: true,
configurable: true
});
Object.defineProperty(RepeatingFormAccessor.prototype, "accessors", {

@@ -1022,2 +679,5 @@ get: function () {

mobx.computed
], RepeatingFormAccessor.prototype, "disabled", null);
__decorate([
mobx.computed
], RepeatingFormAccessor.prototype, "accessors", null);

@@ -1076,2 +736,398 @@ __decorate([

var FormState = /** @class */ (function () {
function FormState(form, node, options) {
var _this = this;
this.form = form;
this.node = node;
this.saveStatus = "before";
this.raw = mobx.observable.map();
this.errors = mobx.observable.map();
this.validating = mobx.observable.map();
this.addModePaths = mobx.observable.map();
mobxStateTree.onPatch(node, function (patch) {
if (patch.op === "remove") {
_this.removePath(patch.path);
}
else if (patch.op === "add") {
_this.addPath(patch.path);
}
});
this.formAccessor = new FormAccessor(this, this.form.definition, "");
if (options == null) {
this.saveFunc = defaultSaveFunc;
this.isDisabledFunc = function () { return false; };
this.isHiddenFunc = function () { return false; };
this.isRepeatingFormDisabledFunc = function () { return false; };
this.extraValidationFunc = function () { return false; };
this.validationBeforeSave = "immediate";
this.validationAfterSave = "immediate";
this.validationPauseDuration = 0;
this.addModePaths.set("/", false);
}
else {
this.saveFunc = options.save ? options.save : defaultSaveFunc;
this.isDisabledFunc = options.isDisabled
? options.isDisabled
: function () { return false; };
this.isHiddenFunc = options.isHidden ? options.isHidden : function () { return false; };
this.isRepeatingFormDisabledFunc = options.isRepeatingFormDisabled
? options.isRepeatingFormDisabled
: function () { return false; };
this.extraValidationFunc = options.extraValidation
? options.extraValidation
: function () { return false; };
this.addModePaths.set("/", options.addMode || false);
var validation = options.validation || {};
this.validationBeforeSave = validation.beforeSave || "immediate";
this.validationAfterSave = validation.afterSave || "immediate";
this.validationPauseDuration = validation.pauseDuration || 0;
}
}
FormState.prototype.setError = function (path, value) {
this.errors.set(path, value);
};
FormState.prototype.deleteError = function (path) {
this.errors.delete(path);
};
FormState.prototype.setValidating = function (path, value) {
this.validating.set(path, value);
};
FormState.prototype.setRaw = function (path, value) {
if (this.saveStatus === "rightAfter") {
this.saveStatus = "after";
}
this.raw.set(path, value);
};
FormState.prototype.removePath = function (path) {
this.raw = removePath(this.raw, path);
this.errors = removePath(this.errors, path);
this.validating = removePath(this.validating, path);
this.addModePaths = removePath(this.addModePaths, path);
};
FormState.prototype.addPath = function (path) {
this.raw = addPath(this.raw, path);
this.errors = addPath(this.errors, path);
this.validating = addPath(this.validating, path);
this.addModePaths = addPath(this.addModePaths, path);
};
FormState.prototype.validate = function () {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, this.formAccessor.validate()];
case 1: return [2 /*return*/, _a.sent()];
}
});
});
};
FormState.prototype.save = function () {
return __awaiter(this, void 0, void 0, function () {
var isValid, errors;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, this.validate()];
case 1:
isValid = _a.sent();
this.saveStatus = "rightAfter";
if (!isValid) {
return [2 /*return*/, false];
}
return [4 /*yield*/, this.saveFunc(this.node)];
case 2:
errors = _a.sent();
if (errors != null) {
this.setErrors(errors);
return [2 /*return*/, false];
}
this.clearErrors();
return [2 /*return*/, true];
}
});
});
};
FormState.prototype.setErrors = function (errors) {
var _this = this;
this.flatAccessors.map(function (accessor) {
var error = getByPath(errors, accessor.path);
if (error != null) {
_this.errors.set(accessor.path, error);
}
});
};
FormState.prototype.clearErrors = function () {
this.errors.clear();
};
FormState.prototype.isKnownAddModePath = function (path) {
var found;
this.addModePaths.forEach(function (value, key) {
if (path.startsWith(key)) {
found = value;
return;
}
});
if (found === undefined) {
return false;
}
return found;
};
FormState.prototype.addMode = function (path) {
return this.isKnownAddModePath(path) && this.raw.get(path) === undefined;
};
FormState.prototype.getValue = function (path) {
return mobxStateTree.resolvePath(this.node, path);
};
FormState.prototype.getError = function (path) {
return this.errors.get(path);
};
FormState.prototype.getMstType = function (path) {
var steps = pathToSteps(path);
var subType = this.form.model;
for (var _i = 0, steps_1 = steps; _i < steps_1.length; _i++) {
var step = steps_1[_i];
if (isInt(step)) {
subType = subType.getChildType(step);
continue;
}
subType = subType.getChildType(step);
}
return subType;
};
Object.defineProperty(FormState.prototype, "isValidating", {
get: function () {
return (Array.from(this.validating.values()).filter(function (value) { return value; }).length > 0);
},
enumerable: true,
configurable: true
});
Object.defineProperty(FormState.prototype, "accessors", {
get: function () {
return this.formAccessor.accessors;
},
enumerable: true,
configurable: true
});
Object.defineProperty(FormState.prototype, "flatAccessors", {
get: function () {
return this.formAccessor.flatAccessors;
},
enumerable: true,
configurable: true
});
FormState.prototype.field = function (name) {
return this.formAccessor.field(name);
};
FormState.prototype.repeatingForm = function (name) {
return this.formAccessor.repeatingForm(name);
};
FormState.prototype.repeatingField = function (name) { };
__decorate([
mobx.observable
], FormState.prototype, "raw", void 0);
__decorate([
mobx.observable
], FormState.prototype, "errors", void 0);
__decorate([
mobx.observable
], FormState.prototype, "validating", void 0);
__decorate([
mobx.observable
], FormState.prototype, "addModePaths", void 0);
__decorate([
mobx.observable
], FormState.prototype, "saveStatus", void 0);
__decorate([
mobx.action
], FormState.prototype, "setError", null);
__decorate([
mobx.action
], FormState.prototype, "deleteError", null);
__decorate([
mobx.action
], FormState.prototype, "setValidating", null);
__decorate([
mobx.action
], FormState.prototype, "setRaw", null);
__decorate([
mobx.action
], FormState.prototype, "removePath", null);
__decorate([
mobx.action
], FormState.prototype, "addPath", null);
__decorate([
mobx.action
], FormState.prototype, "save", null);
__decorate([
mobx.action
], FormState.prototype, "setErrors", null);
__decorate([
mobx.action
], FormState.prototype, "clearErrors", null);
__decorate([
mobx.computed
], FormState.prototype, "isValidating", null);
__decorate([
mobx.computed
], FormState.prototype, "accessors", null);
__decorate([
mobx.computed
], FormState.prototype, "flatAccessors", null);
return FormState;
}());
function defaultSaveFunc() {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
console.warn("No mstform save function configured");
return [2 /*return*/, null];
});
});
}
var Form = /** @class */ (function () {
function Form(model, definition) {
this.model = model;
this.definition = definition;
}
Object.defineProperty(Form.prototype, "FormStateType", {
get: function () {
throw new Error("For introspection");
},
enumerable: true,
configurable: true
});
Form.prototype.state = function (node, options) {
return new FormState(this, node, options);
};
return Form;
}());
var ValidationMessage = /** @class */ (function () {
function ValidationMessage(message) {
this.message = message;
}
return ValidationMessage;
}());
var ProcessValue = /** @class */ (function () {
function ProcessValue(value) {
this.value = value;
}
return ProcessValue;
}());
function identity(value) {
return value;
}
var Field = /** @class */ (function () {
function Field(converter, options) {
this.converter = converter;
this.options = options;
if (!options) {
this.rawValidators = [];
this.validators = [];
this.conversionError = "Could not convert";
this.requiredError = "Required";
this.required = false;
this.getRaw = identity;
}
else {
this.rawValidators = options.rawValidators ? options.rawValidators : [];
this.validators = options.validators ? options.validators : [];
this.conversionError = options.conversionError || "Could not convert";
this.requiredError = options.requiredError || "Required";
this.required = options.required || false;
if (options.fromEvent) {
if (options.getRaw) {
throw new Error("Cannot have fromEvent and getRaw defined at same time");
}
this.getRaw = function (ev) { return ev.target.value; };
}
else {
this.getRaw = options.getRaw || identity;
}
}
}
Object.defineProperty(Field.prototype, "RawType", {
get: function () {
throw new Error("This is a function to enable type introspection");
},
enumerable: true,
configurable: true
});
Object.defineProperty(Field.prototype, "ValueType", {
get: function () {
throw new Error("This is a function to enable type introspection");
},
enumerable: true,
configurable: true
});
Field.prototype.process = function (raw) {
return __awaiter(this, void 0, void 0, function () {
var _i, _a, validator, validationResponse, result, _b, _c, validator, validationResponse;
return __generator(this, function (_d) {
switch (_d.label) {
case 0:
if (raw === this.converter.emptyRaw && this.required) {
return [2 /*return*/, new ValidationMessage(this.requiredError)];
}
_i = 0, _a = this.rawValidators;
_d.label = 1;
case 1:
if (!(_i < _a.length)) return [3 /*break*/, 4];
validator = _a[_i];
return [4 /*yield*/, validator(raw)];
case 2:
validationResponse = _d.sent();
if (typeof validationResponse === "string" && validationResponse) {
return [2 /*return*/, new ValidationMessage(validationResponse)];
}
_d.label = 3;
case 3:
_i++;
return [3 /*break*/, 1];
case 4: return [4 /*yield*/, this.converter.convert(raw)];
case 5:
result = _d.sent();
if (result === CONVERSION_ERROR) {
// if we get a conversion error for the empty raw, the field
// is implied to be required
if (raw === this.converter.emptyRaw) {
return [2 /*return*/, new ValidationMessage(this.requiredError)];
}
return [2 /*return*/, new ValidationMessage(this.conversionError)];
}
_b = 0, _c = this.validators;
_d.label = 6;
case 6:
if (!(_b < _c.length)) return [3 /*break*/, 9];
validator = _c[_b];
return [4 /*yield*/, validator(result.value)];
case 7:
validationResponse = _d.sent();
if (typeof validationResponse === "string" && validationResponse) {
return [2 /*return*/, new ValidationMessage(validationResponse)];
}
_d.label = 8;
case 8:
_b++;
return [3 /*break*/, 6];
case 9: return [2 /*return*/, new ProcessValue(result.value)];
}
});
});
};
Field.prototype.render = function (value) {
return this.converter.render(value);
};
return Field;
}());
var RepeatingForm = /** @class */ (function () {
function RepeatingForm(definition) {
this.definition = definition;
}
return RepeatingForm;
}());
var RepeatingField = /** @class */ (function () {
function RepeatingField(options) {
this.options = options;
}
return RepeatingField;
}());
var NUMBER_REGEX = new RegExp("^-?(0|[1-9]\\d*)(\\.\\d*)?$");

@@ -1250,7 +1306,2 @@ var INTEGER_REGEX = new RegExp("^-?(0|[1-9]\\d*)$");

exports.RepeatingField = RepeatingField;
exports.FormState = FormState;
exports.FormAccessor = FormAccessor;
exports.FieldAccessor = FieldAccessor;
exports.RepeatingFormAccessor = RepeatingFormAccessor;
exports.RepeatingFormIndexedAccessor = RepeatingFormIndexedAccessor;
exports.ConversionValue = ConversionValue;

@@ -1257,0 +1308,0 @@ exports.CONVERSION_ERROR = CONVERSION_ERROR;

@@ -238,381 +238,2 @@ import { action, computed, isObservable, observable, toJS } from 'mobx';

var Form = /** @class */ (function () {
function Form(model, definition) {
this.model = model;
this.definition = definition;
}
Object.defineProperty(Form.prototype, "FormStateType", {
get: function () {
throw new Error("For introspection");
},
enumerable: true,
configurable: true
});
Form.prototype.state = function (node, options) {
return new FormState(this, node, options);
};
return Form;
}());
var ValidationMessage = /** @class */ (function () {
function ValidationMessage(message) {
this.message = message;
}
return ValidationMessage;
}());
var ProcessValue = /** @class */ (function () {
function ProcessValue(value) {
this.value = value;
}
return ProcessValue;
}());
function identity(value) {
return value;
}
var Field = /** @class */ (function () {
function Field(converter, options) {
this.converter = converter;
this.options = options;
if (!options) {
this.rawValidators = [];
this.validators = [];
this.conversionError = "Could not convert";
this.requiredError = "Required";
this.required = false;
this.getRaw = identity;
}
else {
this.rawValidators = options.rawValidators ? options.rawValidators : [];
this.validators = options.validators ? options.validators : [];
this.conversionError = options.conversionError || "Could not convert";
this.requiredError = options.requiredError || "Required";
this.required = options.required || false;
if (options.fromEvent) {
if (options.getRaw) {
throw new Error("Cannot have fromEvent and getRaw defined at same time");
}
this.getRaw = function (ev) { return ev.target.value; };
}
else {
this.getRaw = options.getRaw || identity;
}
}
}
Object.defineProperty(Field.prototype, "RawType", {
get: function () {
throw new Error("This is a function to enable type introspection");
},
enumerable: true,
configurable: true
});
Object.defineProperty(Field.prototype, "ValueType", {
get: function () {
throw new Error("This is a function to enable type introspection");
},
enumerable: true,
configurable: true
});
Field.prototype.process = function (raw) {
return __awaiter(this, void 0, void 0, function () {
var _i, _a, validator, validationResponse, result, _b, _c, validator, validationResponse;
return __generator(this, function (_d) {
switch (_d.label) {
case 0:
if (raw === this.converter.emptyRaw && this.required) {
return [2 /*return*/, new ValidationMessage(this.requiredError)];
}
_i = 0, _a = this.rawValidators;
_d.label = 1;
case 1:
if (!(_i < _a.length)) return [3 /*break*/, 4];
validator = _a[_i];
return [4 /*yield*/, validator(raw)];
case 2:
validationResponse = _d.sent();
if (typeof validationResponse === "string" && validationResponse) {
return [2 /*return*/, new ValidationMessage(validationResponse)];
}
_d.label = 3;
case 3:
_i++;
return [3 /*break*/, 1];
case 4: return [4 /*yield*/, this.converter.convert(raw)];
case 5:
result = _d.sent();
if (result === CONVERSION_ERROR) {
// if we get a conversion error for the empty raw, the field
// is implied to be required
if (raw === this.converter.emptyRaw) {
return [2 /*return*/, new ValidationMessage(this.requiredError)];
}
return [2 /*return*/, new ValidationMessage(this.conversionError)];
}
_b = 0, _c = this.validators;
_d.label = 6;
case 6:
if (!(_b < _c.length)) return [3 /*break*/, 9];
validator = _c[_b];
return [4 /*yield*/, validator(result.value)];
case 7:
validationResponse = _d.sent();
if (typeof validationResponse === "string" && validationResponse) {
return [2 /*return*/, new ValidationMessage(validationResponse)];
}
_d.label = 8;
case 8:
_b++;
return [3 /*break*/, 6];
case 9: return [2 /*return*/, new ProcessValue(result.value)];
}
});
});
};
Field.prototype.render = function (value) {
return this.converter.render(value);
};
return Field;
}());
var RepeatingForm = /** @class */ (function () {
function RepeatingForm(definition) {
this.definition = definition;
}
return RepeatingForm;
}());
var RepeatingField = /** @class */ (function () {
function RepeatingField(options) {
this.options = options;
}
return RepeatingField;
}());
var FormState = /** @class */ (function () {
function FormState(form, node, options) {
var _this = this;
this.form = form;
this.node = node;
this.saveStatus = "before";
this.raw = observable.map();
this.errors = observable.map();
this.validating = observable.map();
this.addModePaths = observable.map();
onPatch(node, function (patch) {
if (patch.op === "remove") {
_this.removePath(patch.path);
}
if (patch.op === "add") {
_this.addPath(patch.path);
}
});
this.formAccessor = new FormAccessor(this, this.form.definition, "");
if (options == null) {
this.saveFunc = undefined;
this.validationBeforeSave = "immediate";
this.validationAfterSave = "immediate";
this.validationPauseDuration = 0;
this.addModePaths.set("/", false);
}
else {
this.saveFunc = options.save;
this.addModePaths.set("/", options.addMode || false);
var validation = options.validation || {};
this.validationBeforeSave = validation.beforeSave || "immediate";
this.validationAfterSave = validation.afterSave || "immediate";
this.validationPauseDuration = validation.pauseDuration || 0;
}
}
FormState.prototype.setError = function (path, value) {
this.errors.set(path, value);
};
FormState.prototype.deleteError = function (path) {
this.errors.delete(path);
};
FormState.prototype.setValidating = function (path, value) {
this.validating.set(path, value);
};
FormState.prototype.setRaw = function (path, value) {
if (this.saveStatus === "rightAfter") {
this.saveStatus = "after";
}
this.raw.set(path, value);
};
FormState.prototype.removePath = function (path) {
this.raw = removePath(this.raw, path);
this.errors = removePath(this.errors, path);
this.validating = removePath(this.validating, path);
this.addModePaths = removePath(this.addModePaths, path);
};
FormState.prototype.addPath = function (path) {
this.raw = addPath(this.raw, path);
this.errors = addPath(this.errors, path);
this.validating = addPath(this.validating, path);
this.addModePaths = addPath(this.addModePaths, path);
};
FormState.prototype.validate = function () {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, this.formAccessor.validate()];
case 1: return [2 /*return*/, _a.sent()];
}
});
});
};
FormState.prototype.save = function () {
return __awaiter(this, void 0, void 0, function () {
var isValid, errors;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, this.validate()];
case 1:
isValid = _a.sent();
this.saveStatus = "rightAfter";
if (!isValid) {
return [2 /*return*/, false];
}
if (!(this.saveFunc != null)) return [3 /*break*/, 3];
return [4 /*yield*/, this.saveFunc(this.node)];
case 2:
errors = _a.sent();
return [3 /*break*/, 4];
case 3:
console.warn("No mstform save function configured");
errors = null;
_a.label = 4;
case 4:
if (errors != null) {
this.setErrors(errors);
return [2 /*return*/, false];
}
this.clearErrors();
return [2 /*return*/, true];
}
});
});
};
FormState.prototype.setErrors = function (errors) {
var _this = this;
this.flatAccessors.map(function (accessor) {
var error = getByPath(errors, accessor.path);
if (error != null) {
_this.errors.set(accessor.path, error);
}
});
};
FormState.prototype.clearErrors = function () {
this.errors.clear();
};
FormState.prototype.isKnownAddModePath = function (path) {
var found;
this.addModePaths.forEach(function (value, key) {
if (path.startsWith(key)) {
found = value;
return;
}
});
if (found === undefined) {
return false;
}
return found;
};
FormState.prototype.addMode = function (path) {
return this.isKnownAddModePath(path) && this.raw.get(path) === undefined;
};
FormState.prototype.getValue = function (path) {
return resolvePath(this.node, path);
};
FormState.prototype.getError = function (path) {
return this.errors.get(path);
};
FormState.prototype.getMstType = function (path) {
var steps = pathToSteps(path);
var subType = this.form.model;
for (var _i = 0, steps_1 = steps; _i < steps_1.length; _i++) {
var step = steps_1[_i];
if (isInt(step)) {
subType = subType.getChildType(step);
continue;
}
subType = subType.getChildType(step);
}
return subType;
};
Object.defineProperty(FormState.prototype, "isValidating", {
get: function () {
return (Array.from(this.validating.values()).filter(function (value) { return value; }).length > 0);
},
enumerable: true,
configurable: true
});
Object.defineProperty(FormState.prototype, "accessors", {
get: function () {
return this.formAccessor.accessors;
},
enumerable: true,
configurable: true
});
Object.defineProperty(FormState.prototype, "flatAccessors", {
get: function () {
return this.formAccessor.flatAccessors;
},
enumerable: true,
configurable: true
});
FormState.prototype.field = function (name) {
return this.formAccessor.field(name);
};
FormState.prototype.repeatingForm = function (name) {
return this.formAccessor.repeatingForm(name);
};
FormState.prototype.repeatingField = function (name) { };
__decorate([
observable
], FormState.prototype, "raw", void 0);
__decorate([
observable
], FormState.prototype, "errors", void 0);
__decorate([
observable
], FormState.prototype, "validating", void 0);
__decorate([
observable
], FormState.prototype, "addModePaths", void 0);
__decorate([
observable
], FormState.prototype, "saveStatus", void 0);
__decorate([
action
], FormState.prototype, "setError", null);
__decorate([
action
], FormState.prototype, "deleteError", null);
__decorate([
action
], FormState.prototype, "setValidating", null);
__decorate([
action
], FormState.prototype, "setRaw", null);
__decorate([
action
], FormState.prototype, "removePath", null);
__decorate([
action
], FormState.prototype, "addPath", null);
__decorate([
action
], FormState.prototype, "save", null);
__decorate([
action
], FormState.prototype, "setErrors", null);
__decorate([
action
], FormState.prototype, "clearErrors", null);
__decorate([
computed
], FormState.prototype, "isValidating", null);
__decorate([
computed
], FormState.prototype, "accessors", null);
__decorate([
computed
], FormState.prototype, "flatAccessors", null);
return FormState;
}());
var FormAccessor = /** @class */ (function () {

@@ -722,2 +343,3 @@ function FormAccessor(state, definition, path) {

this.name = name;
process;
this.path = path + "/" + name;

@@ -806,2 +428,16 @@ }

});
Object.defineProperty(FieldAccessor.prototype, "disabled", {
get: function () {
return this.state.isDisabledFunc(this);
},
enumerable: true,
configurable: true
});
Object.defineProperty(FieldAccessor.prototype, "hidden", {
get: function () {
return this.state.isHiddenFunc(this);
},
enumerable: true,
configurable: true
});
FieldAccessor.prototype.validate = function () {

@@ -821,3 +457,3 @@ return __awaiter(this, void 0, void 0, function () {

return __awaiter(this, void 0, void 0, function () {
var processResult, e_1, currentRaw;
var processResult, e_1, currentRaw, extraResult;
return __generator(this, function (_a) {

@@ -833,2 +469,4 @@ switch (_a.label) {

case 2:
// XXX is await correct here? we should await the result
// later
processResult = _a.sent();

@@ -858,2 +496,7 @@ return [3 /*break*/, 4];

}
extraResult = this.state.extraValidationFunc(this, processResult.value);
// XXX possible flicker?
if (typeof extraResult === "string" && extraResult) {
this.state.setError(this.path, extraResult);
}
applyPatch(this.state.node, [

@@ -870,2 +513,3 @@ { op: "replace", path: this.path, value: processResult.value }

return {
disabled: this.disabled,
value: this.raw,

@@ -915,2 +559,8 @@ onChange: this.handleChange

__decorate([
computed
], FieldAccessor.prototype, "disabled", null);
__decorate([
computed
], FieldAccessor.prototype, "hidden", null);
__decorate([
action

@@ -955,2 +605,9 @@ ], FieldAccessor.prototype, "setRaw", null);

};
Object.defineProperty(RepeatingFormAccessor.prototype, "disabled", {
get: function () {
return this.state.isRepeatingFormDisabledFunc(this);
},
enumerable: true,
configurable: true
});
Object.defineProperty(RepeatingFormAccessor.prototype, "accessors", {

@@ -1018,2 +675,5 @@ get: function () {

computed
], RepeatingFormAccessor.prototype, "disabled", null);
__decorate([
computed
], RepeatingFormAccessor.prototype, "accessors", null);

@@ -1072,2 +732,398 @@ __decorate([

var FormState = /** @class */ (function () {
function FormState(form, node, options) {
var _this = this;
this.form = form;
this.node = node;
this.saveStatus = "before";
this.raw = observable.map();
this.errors = observable.map();
this.validating = observable.map();
this.addModePaths = observable.map();
onPatch(node, function (patch) {
if (patch.op === "remove") {
_this.removePath(patch.path);
}
else if (patch.op === "add") {
_this.addPath(patch.path);
}
});
this.formAccessor = new FormAccessor(this, this.form.definition, "");
if (options == null) {
this.saveFunc = defaultSaveFunc;
this.isDisabledFunc = function () { return false; };
this.isHiddenFunc = function () { return false; };
this.isRepeatingFormDisabledFunc = function () { return false; };
this.extraValidationFunc = function () { return false; };
this.validationBeforeSave = "immediate";
this.validationAfterSave = "immediate";
this.validationPauseDuration = 0;
this.addModePaths.set("/", false);
}
else {
this.saveFunc = options.save ? options.save : defaultSaveFunc;
this.isDisabledFunc = options.isDisabled
? options.isDisabled
: function () { return false; };
this.isHiddenFunc = options.isHidden ? options.isHidden : function () { return false; };
this.isRepeatingFormDisabledFunc = options.isRepeatingFormDisabled
? options.isRepeatingFormDisabled
: function () { return false; };
this.extraValidationFunc = options.extraValidation
? options.extraValidation
: function () { return false; };
this.addModePaths.set("/", options.addMode || false);
var validation = options.validation || {};
this.validationBeforeSave = validation.beforeSave || "immediate";
this.validationAfterSave = validation.afterSave || "immediate";
this.validationPauseDuration = validation.pauseDuration || 0;
}
}
FormState.prototype.setError = function (path, value) {
this.errors.set(path, value);
};
FormState.prototype.deleteError = function (path) {
this.errors.delete(path);
};
FormState.prototype.setValidating = function (path, value) {
this.validating.set(path, value);
};
FormState.prototype.setRaw = function (path, value) {
if (this.saveStatus === "rightAfter") {
this.saveStatus = "after";
}
this.raw.set(path, value);
};
FormState.prototype.removePath = function (path) {
this.raw = removePath(this.raw, path);
this.errors = removePath(this.errors, path);
this.validating = removePath(this.validating, path);
this.addModePaths = removePath(this.addModePaths, path);
};
FormState.prototype.addPath = function (path) {
this.raw = addPath(this.raw, path);
this.errors = addPath(this.errors, path);
this.validating = addPath(this.validating, path);
this.addModePaths = addPath(this.addModePaths, path);
};
FormState.prototype.validate = function () {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, this.formAccessor.validate()];
case 1: return [2 /*return*/, _a.sent()];
}
});
});
};
FormState.prototype.save = function () {
return __awaiter(this, void 0, void 0, function () {
var isValid, errors;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, this.validate()];
case 1:
isValid = _a.sent();
this.saveStatus = "rightAfter";
if (!isValid) {
return [2 /*return*/, false];
}
return [4 /*yield*/, this.saveFunc(this.node)];
case 2:
errors = _a.sent();
if (errors != null) {
this.setErrors(errors);
return [2 /*return*/, false];
}
this.clearErrors();
return [2 /*return*/, true];
}
});
});
};
FormState.prototype.setErrors = function (errors) {
var _this = this;
this.flatAccessors.map(function (accessor) {
var error = getByPath(errors, accessor.path);
if (error != null) {
_this.errors.set(accessor.path, error);
}
});
};
FormState.prototype.clearErrors = function () {
this.errors.clear();
};
FormState.prototype.isKnownAddModePath = function (path) {
var found;
this.addModePaths.forEach(function (value, key) {
if (path.startsWith(key)) {
found = value;
return;
}
});
if (found === undefined) {
return false;
}
return found;
};
FormState.prototype.addMode = function (path) {
return this.isKnownAddModePath(path) && this.raw.get(path) === undefined;
};
FormState.prototype.getValue = function (path) {
return resolvePath(this.node, path);
};
FormState.prototype.getError = function (path) {
return this.errors.get(path);
};
FormState.prototype.getMstType = function (path) {
var steps = pathToSteps(path);
var subType = this.form.model;
for (var _i = 0, steps_1 = steps; _i < steps_1.length; _i++) {
var step = steps_1[_i];
if (isInt(step)) {
subType = subType.getChildType(step);
continue;
}
subType = subType.getChildType(step);
}
return subType;
};
Object.defineProperty(FormState.prototype, "isValidating", {
get: function () {
return (Array.from(this.validating.values()).filter(function (value) { return value; }).length > 0);
},
enumerable: true,
configurable: true
});
Object.defineProperty(FormState.prototype, "accessors", {
get: function () {
return this.formAccessor.accessors;
},
enumerable: true,
configurable: true
});
Object.defineProperty(FormState.prototype, "flatAccessors", {
get: function () {
return this.formAccessor.flatAccessors;
},
enumerable: true,
configurable: true
});
FormState.prototype.field = function (name) {
return this.formAccessor.field(name);
};
FormState.prototype.repeatingForm = function (name) {
return this.formAccessor.repeatingForm(name);
};
FormState.prototype.repeatingField = function (name) { };
__decorate([
observable
], FormState.prototype, "raw", void 0);
__decorate([
observable
], FormState.prototype, "errors", void 0);
__decorate([
observable
], FormState.prototype, "validating", void 0);
__decorate([
observable
], FormState.prototype, "addModePaths", void 0);
__decorate([
observable
], FormState.prototype, "saveStatus", void 0);
__decorate([
action
], FormState.prototype, "setError", null);
__decorate([
action
], FormState.prototype, "deleteError", null);
__decorate([
action
], FormState.prototype, "setValidating", null);
__decorate([
action
], FormState.prototype, "setRaw", null);
__decorate([
action
], FormState.prototype, "removePath", null);
__decorate([
action
], FormState.prototype, "addPath", null);
__decorate([
action
], FormState.prototype, "save", null);
__decorate([
action
], FormState.prototype, "setErrors", null);
__decorate([
action
], FormState.prototype, "clearErrors", null);
__decorate([
computed
], FormState.prototype, "isValidating", null);
__decorate([
computed
], FormState.prototype, "accessors", null);
__decorate([
computed
], FormState.prototype, "flatAccessors", null);
return FormState;
}());
function defaultSaveFunc() {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
console.warn("No mstform save function configured");
return [2 /*return*/, null];
});
});
}
var Form = /** @class */ (function () {
function Form(model, definition) {
this.model = model;
this.definition = definition;
}
Object.defineProperty(Form.prototype, "FormStateType", {
get: function () {
throw new Error("For introspection");
},
enumerable: true,
configurable: true
});
Form.prototype.state = function (node, options) {
return new FormState(this, node, options);
};
return Form;
}());
var ValidationMessage = /** @class */ (function () {
function ValidationMessage(message) {
this.message = message;
}
return ValidationMessage;
}());
var ProcessValue = /** @class */ (function () {
function ProcessValue(value) {
this.value = value;
}
return ProcessValue;
}());
function identity(value) {
return value;
}
var Field = /** @class */ (function () {
function Field(converter, options) {
this.converter = converter;
this.options = options;
if (!options) {
this.rawValidators = [];
this.validators = [];
this.conversionError = "Could not convert";
this.requiredError = "Required";
this.required = false;
this.getRaw = identity;
}
else {
this.rawValidators = options.rawValidators ? options.rawValidators : [];
this.validators = options.validators ? options.validators : [];
this.conversionError = options.conversionError || "Could not convert";
this.requiredError = options.requiredError || "Required";
this.required = options.required || false;
if (options.fromEvent) {
if (options.getRaw) {
throw new Error("Cannot have fromEvent and getRaw defined at same time");
}
this.getRaw = function (ev) { return ev.target.value; };
}
else {
this.getRaw = options.getRaw || identity;
}
}
}
Object.defineProperty(Field.prototype, "RawType", {
get: function () {
throw new Error("This is a function to enable type introspection");
},
enumerable: true,
configurable: true
});
Object.defineProperty(Field.prototype, "ValueType", {
get: function () {
throw new Error("This is a function to enable type introspection");
},
enumerable: true,
configurable: true
});
Field.prototype.process = function (raw) {
return __awaiter(this, void 0, void 0, function () {
var _i, _a, validator, validationResponse, result, _b, _c, validator, validationResponse;
return __generator(this, function (_d) {
switch (_d.label) {
case 0:
if (raw === this.converter.emptyRaw && this.required) {
return [2 /*return*/, new ValidationMessage(this.requiredError)];
}
_i = 0, _a = this.rawValidators;
_d.label = 1;
case 1:
if (!(_i < _a.length)) return [3 /*break*/, 4];
validator = _a[_i];
return [4 /*yield*/, validator(raw)];
case 2:
validationResponse = _d.sent();
if (typeof validationResponse === "string" && validationResponse) {
return [2 /*return*/, new ValidationMessage(validationResponse)];
}
_d.label = 3;
case 3:
_i++;
return [3 /*break*/, 1];
case 4: return [4 /*yield*/, this.converter.convert(raw)];
case 5:
result = _d.sent();
if (result === CONVERSION_ERROR) {
// if we get a conversion error for the empty raw, the field
// is implied to be required
if (raw === this.converter.emptyRaw) {
return [2 /*return*/, new ValidationMessage(this.requiredError)];
}
return [2 /*return*/, new ValidationMessage(this.conversionError)];
}
_b = 0, _c = this.validators;
_d.label = 6;
case 6:
if (!(_b < _c.length)) return [3 /*break*/, 9];
validator = _c[_b];
return [4 /*yield*/, validator(result.value)];
case 7:
validationResponse = _d.sent();
if (typeof validationResponse === "string" && validationResponse) {
return [2 /*return*/, new ValidationMessage(validationResponse)];
}
_d.label = 8;
case 8:
_b++;
return [3 /*break*/, 6];
case 9: return [2 /*return*/, new ProcessValue(result.value)];
}
});
});
};
Field.prototype.render = function (value) {
return this.converter.render(value);
};
return Field;
}());
var RepeatingForm = /** @class */ (function () {
function RepeatingForm(definition) {
this.definition = definition;
}
return RepeatingForm;
}());
var RepeatingField = /** @class */ (function () {
function RepeatingField(options) {
this.options = options;
}
return RepeatingField;
}());
var NUMBER_REGEX = new RegExp("^-?(0|[1-9]\\d*)(\\.\\d*)?$");

@@ -1240,2 +1296,2 @@ var INTEGER_REGEX = new RegExp("^-?(0|[1-9]\\d*)$");

export { Form, ValidationMessage, ProcessValue, Field, RepeatingForm, RepeatingField, FormState, FormAccessor, FieldAccessor, RepeatingFormAccessor, RepeatingFormIndexedAccessor, ConversionValue, CONVERSION_ERROR, Converter, StringConverter, converters };
export { Form, ValidationMessage, ProcessValue, Field, RepeatingForm, RepeatingField, ConversionValue, CONVERSION_ERROR, Converter, StringConverter, converters };

@@ -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,i,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 o,i=arguments.length,s=i<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--)(o=t[a])&&(s=(i<3?o(s):3<i?o(e,r,s):o(e,r))||s);return 3<i&&s&&Object.defineProperty(e,r,s),s}function u(i,s,a,u){return new(a||(a=Promise))(function(t,e){function r(t){try{o(u.next(t))}catch(t){e(t)}}function n(t){try{o(u.throw(t))}catch(t){e(t)}}function o(e){e.done?t(e.value):new a(function(t){t(e.value)}).then(r,n)}o((u=u.apply(i,s||[])).next())})}function c(r,n){var o,i,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(o)throw new TypeError("Generator is already executing.");for(;a;)try{if(o=1,i&&(s=i[2&e[0]?"return":e[0]?"throw":"next"])&&!(s=s.call(i,e[1])).done)return s;switch(i=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++,i=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],i=0}finally{o=s=0}if(5&e[0])throw e[1];return{value:e[0]?e[1]:void 0,done:!0}}([e,t])}}}var o=function(t){this.value=t},p="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,p];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,p];t.label=4;case 4:return[2,new o(e)]}})})},t.prototype.render=function(t){return this.definition.render(t)},t}(),a=require("fast-deep-equal");function l(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 i.isObservable(t)?i.toJS(t):t}function v(t,e){return function t(e,r){var n=r[0],o=r.slice(1);if(0===o.length)return e[n];var i=e[n];if(void 0===i)return;return t(i,o)}(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 o=r.slice(1),i=a+f([(n-1).toString()].concat(o));u.delete(e),u.set(i,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 o=r.slice(1),i=a+f([(n+1).toString()].concat(o));u.set(i,t)}}else u.set(e,t)}),u}var m=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 O(this,t,e)},t}(),b=function(t){this.message=t},w=function(t){this.value=t};function P(t){return t}var E=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||P;else this.rawValidators=[],this.validators=[],this.conversionError="Could not convert",this.requiredError="Required",this.required=!1,this.getRaw=P}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,o,i,s;return c(this,function(t){switch(t.label){case 0:if(a===this.converter.emptyRaw&&this.required)return[2,new b(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 b(s)];t.label=3;case 3:return e++,[3,1];case 4:return[4,this.converter.convert(a)];case 5:if((n=t.sent())===p)return a===this.converter.emptyRaw?[2,new b(this.requiredError)]:[2,new b(this.conversionError)];o=0,i=this.validators,t.label=6;case 6:return o<i.length?[4,(0,i[o])(n.value)]:[3,9];case 7:if("string"==typeof(s=t.sent())&&s)return[2,new b(s)];t.label=8;case 8:return o++,[3,6];case 9:return[2,new w(n.value)]}})})},t.prototype.render=function(t){return this.converter.render(t)},t}(),R=function(t){this.definition=t},A=function(t){this.options=t},O=function(){function t(t,e,r){var n=this;if(this.form=t,this.node=e,this.saveStatus="before",this.raw=i.observable.map(),this.errors=i.observable.map(),this.validating=i.observable.map(),this.addModePaths=i.observable.map(),s.onPatch(e,function(t){"remove"===t.op&&n.removePath(t.path),"add"===t.op&&n.addPath(t.path)}),this.formAccessor=new V(this,this.form.definition,""),null==r)this.saveFunc=void 0,this.validationBeforeSave="immediate",this.validationAfterSave="immediate",this.validationPauseDuration=0,this.addModePaths.set("/",!1);else{this.saveFunc=r.save,this.addModePaths.set("/",r.addMode||!1);var o=r.validation||{};this.validationBeforeSave=o.beforeSave||"immediate",this.validationAfterSave=o.afterSave||"immediate",this.validationPauseDuration=o.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?null==this.saveFunc?[3,3]:[4,this.saveFunc(this.node)]:[2,!1];case 2:return r=t.sent(),[3,4];case 3:console.warn("No mstform save function configured"),r=null,t.label=4;case 4:return null!=r?(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,o=0,i=r;o<i.length;o++){var s=i[o];(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([i.observable],t.prototype,"raw",void 0),e([i.observable],t.prototype,"errors",void 0),e([i.observable],t.prototype,"validating",void 0),e([i.observable],t.prototype,"addModePaths",void 0),e([i.observable],t.prototype,"saveStatus",void 0),e([i.action],t.prototype,"setError",null),e([i.action],t.prototype,"deleteError",null),e([i.action],t.prototype,"setValidating",null),e([i.action],t.prototype,"setRaw",null),e([i.action],t.prototype,"removePath",null),e([i.action],t.prototype,"addPath",null),e([i.action],t.prototype,"save",null),e([i.action],t.prototype,"setErrors",null),e([i.action],t.prototype,"clearErrors",null),e([i.computed],t.prototype,"isValidating",null),e([i.computed],t.prototype,"accessors",null),e([i.computed],t.prototype,"flatAccessors",null),t}(),V=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 E?n.push(r.field(t)):e instanceof R&&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 j?e.push(t):t instanceof S&&(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 E))throw new Error("Not accessing a Field instance");return new j(this.state,e,this.path,t)},t.prototype.repeatingForm=function(t){var e=this.definition[t];if(!(e instanceof R))throw new Error("Not accessing a RepeatingForm instance");return new S(this.state,e,this.path,t)},t.prototype.repeatingField=function(t){},e([i.computed],t.prototype,"accessors",null),e([i.computed],t.prototype,"flatAccessors",null),t}(),j=function(){function t(t,e,r,n){var o=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(o,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,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}),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(n){return u(this,void 0,void 0,function(){var e,r;return c(this,function(t){switch(t.label){case 0:this.state.setRaw(this.path,n),this.state.setValidating(this.path,!0),t.label=1;case 1:return t.trys.push([1,3,,4]),[4,this.field.process(n)];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(n)))return[2];if(this.state.setValidating(this.path,!1),e instanceof b)return this.state.setError(this.path,e.message),[2];if(this.state.deleteError(this.path),!(e instanceof w))throw new Error("Unknown process result");return s.applyPatch(this.state.node,[{op:"replace",path:this.path,value:e.value}]),[2]}})})},Object.defineProperty(t.prototype,"inputProps",{get:function(){return{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([i.computed],t.prototype,"addMode",null),e([i.computed],t.prototype,"raw",null),e([i.computed],t.prototype,"value",null),e([i.computed],t.prototype,"errorValue",null),e([i.computed],t.prototype,"canShowValidationMessages",null),e([i.computed],t.prototype,"error",null),e([i.computed],t.prototype,"isValidating",null),e([i.action],t.prototype,"setRaw",null),e([i.computed],t.prototype,"inputProps",null),e([i.computed],t.prototype,"validationProps",null),t}(),S=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,o;return c(this,function(t){switch(t.label){case 0:for(e=[],r=0,n=this.accessors;r<n.length;r++)o=n[r],e.push(o.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 F(this.state,this.repeatingForm.definition,this.path,t)},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([i.computed],t.prototype,"accessors",null),e([i.computed],t.prototype,"flatAccessors",null),e([i.computed],t.prototype,"error",null),t}(),F=function(){function t(t,e,r,n){this.state=t,this.definition=e,this.index=n,this.path=r+"/"+n,this.formAccessor=new V(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([i.computed],t.prototype,"accessors",null),e([i.computed],t.prototype,"flatAccessors",null),t}(),M=new RegExp("^-?(0|[1-9]\\d*)(\\.\\d*)?$"),x=new RegExp("^-?(0|[1-9]\\d*)$"),q=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),C=new q({emptyRaw:"",convert:function(t){return t},render:function(t){return t}}),N=new q({emptyRaw:"",rawValidate:function(t){return t.startsWith(".")&&(t="0"+t),M.test(t)},convert:function(t){return+t},render:function(t){return t.toString()}}),_=new q({emptyRaw:"",rawValidate:function(t){return x.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 q({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 i.observable.array(t)},render:function(t){return t}});var W=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 o(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,p]:[2,new o(e)]})})},t.prototype.render=function(t){return t},t}();var D={string:C,number:N,integer:_,decimal:function(t,e){return new T(t,e)},stringArray:I,maybe:function(t){return t instanceof q?new W(t):new r({emptyRaw:null,convert:l,render:l})},model:function(t){return new k(t)},object:new r({emptyRaw:null,convert:l,render:l})};t.Form=m,t.ValidationMessage=b,t.ProcessValue=w,t.Field=E,t.RepeatingForm=R,t.RepeatingField=A,t.FormState=O,t.FormAccessor=V,t.FieldAccessor=j,t.RepeatingFormAccessor=S,t.RepeatingFormIndexedAccessor=F,t.ConversionValue=o,t.CONVERSION_ERROR=p,t.Converter=r,t.StringConverter=q,t.converters=D,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 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})});

@@ -21,10 +21,1 @@ export declare type ValidationResponse = string | null | undefined | false;

export declare type ValidationOption = "immediate" | "no";
export interface FormStateOptions<M> {
save?: SaveFunc<M>;
addMode?: boolean;
validation?: {
beforeSave?: ValidationOption;
afterSave?: ValidationOption;
pauseDuration?: number;
};
}
{
"name": "mstform",
"private": false,
"version": "0.3.4",
"version": "0.4.0",
"description": "mobx-state-tree powered forms",

@@ -6,0 +6,0 @@ "main": "dist/mstform.js",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc