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.11.0 to 0.12.0

CHANGES.md

1578

dist/mstform.js

@@ -1,1576 +0,2 @@

'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
var mobx = require('mobx');
var mobxStateTree = require('mobx-state-tree');
/*! *****************************************************************************
Copyright (c) Microsoft Corporation. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
this file except in compliance with the License. You may obtain a copy of the
License at http://www.apache.org/licenses/LICENSE-2.0
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
MERCHANTABLITY OR NON-INFRINGEMENT.
See the Apache Version 2.0 License for specific language governing permissions
and limitations under the License.
***************************************************************************** */
/* global Reflect, Promise */
var extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
function __extends(d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
}
function __decorate(decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
}
function __awaiter(thisArg, _arguments, P, generator) {
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
}
function __generator(thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (_) try {
if (f = 1, y && (t = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [0, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
}
var value = function (accessor) {
return {
value: accessor.raw,
onChange: function (ev) { return accessor.setRaw(ev.target.value); }
};
};
var checked = function (accessor) {
return {
checked: accessor.raw,
onChange: function (ev) { return accessor.setRaw(ev.target.checked); }
};
};
var object = function (accessor) {
return {
value: accessor.raw,
onChange: function (value) { return accessor.setRaw(value); }
};
};
var controlled = {
value: value,
checked: checked,
object: object
};
var ConversionValue = /** @class */ (function () {
function ConversionValue(value) {
this.value = value;
}
return ConversionValue;
}());
var CONVERSION_ERROR = "ConversionError";
var Converter = /** @class */ (function () {
function Converter(definition) {
this.definition = definition;
this.emptyRaw = definition.emptyRaw;
this.defaultControlled = definition.defaultControlled
? definition.defaultControlled
: controlled.object;
}
Converter.prototype.convert = function (raw) {
return __awaiter(this, void 0, void 0, function () {
var rawValidationSuccess, value, rawValidationSuccess;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
if (!this.definition.rawValidate) return [3 /*break*/, 2];
return [4 /*yield*/, this.definition.rawValidate(raw)];
case 1:
rawValidationSuccess = _a.sent();
if (!rawValidationSuccess) {
return [2 /*return*/, CONVERSION_ERROR];
}
_a.label = 2;
case 2:
value = this.definition.convert(raw);
if (!this.definition.validate) return [3 /*break*/, 4];
return [4 /*yield*/, this.definition.validate(value)];
case 3:
rawValidationSuccess = _a.sent();
if (!rawValidationSuccess) {
return [2 /*return*/, CONVERSION_ERROR];
}
_a.label = 4;
case 4: return [2 /*return*/, new ConversionValue(value)];
}
});
});
};
Converter.prototype.render = function (value) {
return this.definition.render(value);
};
return Converter;
}());
// have to use this here but loses type information
var equal = require("fast-deep-equal");
function identity(value) {
return value;
}
function pathToSteps(path) {
if (path.startsWith("/")) {
path = path.slice(1);
}
return path.split("/");
}
function stepsToPath(parts) {
var result = parts.join("/");
if (!result.startsWith("/")) {
return "/" + result;
}
return result;
}
function isInt(s) {
return Number.isInteger(parseInt(s, 10));
}
function unwrap(o) {
if (mobx.isObservable(o)) {
return mobx.toJS(o);
}
return o;
}
function getByPath(obj, path) {
return getBySteps(obj, pathToSteps(path));
}
function getBySteps(obj, steps) {
var first = steps[0], rest = steps.slice(1);
if (rest.length === 0) {
return obj[first];
}
var sub = obj[first];
if (sub === undefined) {
return undefined;
}
return getBySteps(sub, rest);
}
function deleteByPath(obj, path) {
return deleteBySteps(obj, pathToSteps(path));
}
function deleteBySteps(obj, steps) {
var first = steps[0], rest = steps.slice(1);
if (rest.length === 0) {
delete obj[first];
}
var sub = obj[first];
if (sub === undefined) {
return;
}
deleteBySteps(sub, rest);
}
function removePath(map, path, disposeFunc) {
var parts = pathToSteps(path);
var last = parts[parts.length - 1];
var removedIndex = parseInt(last, 10);
var basePath = stepsToPath(parts.slice(0, parts.length - 1));
var result = new Map();
map.forEach(function (value, key) {
if (!key.startsWith(basePath)) {
result.set(key, value);
return;
}
var withoutBase = key.slice(basePath.length + 1);
var pathParts = pathToSteps(withoutBase);
var number = parseInt(pathParts[0], 10);
if (isNaN(number)) {
result.set(key, value);
return;
}
if (number < removedIndex) {
result.set(key, value);
return;
}
else if (number === removedIndex) {
if (disposeFunc != null) {
disposeFunc(value);
}
return;
}
var restParts = pathParts.slice(1);
var newPath = basePath + stepsToPath([(number - 1).toString()].concat(restParts));
result.delete(key);
result.set(newPath, value);
});
return result;
}
function addPath(map, path) {
var parts = pathToSteps(path);
var last = parts[parts.length - 1];
var addedIndex = parseInt(last, 10);
if (isNaN(addedIndex)) {
return map;
}
var basePath = stepsToPath(parts.slice(0, parts.length - 1));
var result = new Map();
map.forEach(function (value, key) {
if (!key.startsWith(basePath)) {
result.set(key, value);
return;
}
var withoutBase = key.slice(basePath.length + 1);
var pathParts = pathToSteps(withoutBase);
var number = parseInt(pathParts[0], 10);
if (isNaN(number)) {
result.set(key, value);
return;
}
// if number is before the currently added index, we want it as is
if (number < addedIndex) {
result.set(key, value);
return;
}
// if it's greater or equal, we want to shift them
var restParts = pathParts.slice(1);
var newPath = basePath + stepsToPath([(number + 1).toString()].concat(restParts));
result.set(newPath, value);
});
// we return the result with a gap for the newly added item
return result;
}
function deepCopy(o) {
// it's a crazy technique but it works for plain JSON, and
// we use it for errors which is plain JSON
return JSON.parse(JSON.stringify(o));
}
var FormAccessor = /** @class */ (function () {
function FormAccessor(state, definition, node, path) {
this.state = state;
this.definition = definition;
this.node = node;
this.path = path;
}
FormAccessor.prototype.validate = function () {
return __awaiter(this, void 0, void 0, function () {
var promises, values;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
promises = this.accessors.map(function (accessor) { return accessor.validate(); });
return [4 /*yield*/, Promise.all(promises)];
case 1:
values = _a.sent();
return [2 /*return*/, values.filter(function (value) { return !value; }).length === 0];
}
});
});
};
Object.defineProperty(FormAccessor.prototype, "accessors", {
get: function () {
var _this = this;
var result = [];
Object.keys(this.definition).forEach(function (key) {
var entry = _this.definition[key];
if (entry instanceof Field) {
result.push(_this.field(key));
}
else if (entry instanceof RepeatingForm) {
result.push(_this.repeatingForm(key));
}
});
return result;
},
enumerable: true,
configurable: true
});
Object.defineProperty(FormAccessor.prototype, "flatAccessors", {
get: function () {
var result = [];
this.accessors.forEach(function (accessor) {
if (accessor instanceof FieldAccessor) {
result.push(accessor);
}
else if (accessor instanceof RepeatingFormAccessor) {
result.push.apply(result, accessor.flatAccessors);
result.push(accessor);
}
});
return result;
},
enumerable: true,
configurable: true
});
FormAccessor.prototype.access = function (name) {
// XXX catching errors isn't ideal
try {
return this.field(name);
}
catch (_a) {
try {
return this.repeatingForm(name);
}
catch (_b) {
return undefined;
}
}
};
FormAccessor.prototype.accessBySteps = function (steps) {
var first = steps[0], rest = steps.slice(1);
var accessor = this.access(first);
if (rest.length === 0) {
return accessor;
}
if (accessor === undefined) {
return accessor;
}
return accessor.accessBySteps(rest);
};
FormAccessor.prototype.field = function (name) {
var field = this.definition[name];
if (!(field instanceof Field)) {
throw new Error("Not accessing a Field instance");
}
return new FieldAccessor(this.state, field, this.node, this.path, name);
};
FormAccessor.prototype.repeatingForm = function (name) {
var repeatingForm = this.definition[name];
if (!(repeatingForm instanceof RepeatingForm)) {
throw new Error("Not accessing a RepeatingForm instance");
}
// we know that the node is an array of M[] at this point
var nodes = this.node[name];
return new RepeatingFormAccessor(this.state, repeatingForm, nodes, this.path, name);
};
FormAccessor.prototype.repeatingField = function (name) { };
__decorate([
mobx.computed
], FormAccessor.prototype, "accessors", null);
__decorate([
mobx.computed
], FormAccessor.prototype, "flatAccessors", null);
return FormAccessor;
}());
var FieldAccessor = /** @class */ (function () {
function FieldAccessor(state, field, node, path, name) {
var _this = this;
this.state = state;
this.field = field;
this.node = node;
// backward compatibility -- use setRaw instead
this.handleChange = function () {
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
return __awaiter(_this, void 0, void 0, function () {
var raw, _a;
return __generator(this, function (_b) {
switch (_b.label) {
case 0:
raw = (_a = this.field).getRaw.apply(_a, args);
return [4 /*yield*/, this.setRaw(raw)];
case 1:
_b.sent();
return [2 /*return*/];
}
});
});
};
this.handleFocus = function (event) {
if (_this.state.focusFunc == null) {
return;
}
_this.state.focusFunc(event, _this);
};
this.name = name;
process;
this.path = path + "/" + name;
this.createDerivedReaction();
}
FieldAccessor.prototype.createDerivedReaction = function () {
var _this = this;
var derivedFunc = this.field.derivedFunc;
if (derivedFunc == null) {
return;
}
if (this.state.derivedDisposers.get(this.path)) {
return;
}
var disposer = mobx.reaction(function () { return derivedFunc(_this.node); }, function (derivedValue) {
_this.setRaw(_this.field.render(derivedValue));
});
this.state.setDerivedDisposer(this.path, disposer);
};
Object.defineProperty(FieldAccessor.prototype, "addMode", {
get: function () {
return this.state.addMode(this.path);
},
enumerable: true,
configurable: true
});
Object.defineProperty(FieldAccessor.prototype, "raw", {
get: function () {
var result = this.state.raw.get(this.path);
if (result !== undefined) {
// this is an object reference. don't convert to JS
if (mobx.isObservable(result) && !(result instanceof Array)) {
return result;
}
// anything else, including arrays, convert to JS
// XXX what if we have an array of object references? cross that
// bridge when we support it
return mobx.toJS(result);
}
if (this.addMode) {
return this.field.converter.emptyRaw;
}
return this.field.render(this.value);
},
enumerable: true,
configurable: true
});
Object.defineProperty(FieldAccessor.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: true,
configurable: true
});
Object.defineProperty(FieldAccessor.prototype, "errorValue", {
get: function () {
return this.state.getError(this.path);
},
enumerable: true,
configurable: true
});
Object.defineProperty(FieldAccessor.prototype, "canShowValidationMessages", {
get: function () {
// immediately after a save we always want messages
if (this.state.saveStatus === "rightAfter") {
return true;
}
var policy = this.state.saveStatus === "before"
? this.state.validationBeforeSave
: this.state.validationAfterSave;
if (policy === "immediate") {
return true;
}
if (policy === "no") {
return false;
}
// not implemented yet
if (policy === "blur" || policy === "pause") {
return false;
}
return true;
},
enumerable: true,
configurable: true
});
Object.defineProperty(FieldAccessor.prototype, "error", {
get: function () {
if (this.canShowValidationMessages) {
return this.errorValue;
}
else {
return undefined;
}
},
enumerable: true,
configurable: true
});
Object.defineProperty(FieldAccessor.prototype, "isValidating", {
get: function () {
return this.state.validating.get(this.path) || false;
},
enumerable: true,
configurable: true
});
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 () {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, this.setRaw(this.raw)];
case 1:
_a.sent();
return [2 /*return*/, this.errorValue === undefined];
}
});
});
};
FieldAccessor.prototype.setRaw = function (raw) {
return __awaiter(this, void 0, void 0, function () {
var processResult, e_1, currentRaw, extraResult, changeFunc;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
this.state.setRaw(this.path, raw);
this.state.setValidating(this.path, true);
_a.label = 1;
case 1:
_a.trys.push([1, 3, , 4]);
return [4 /*yield*/, this.field.process(raw)];
case 2:
// XXX is await correct here? we should await the result
// later
processResult = _a.sent();
return [3 /*break*/, 4];
case 3:
e_1 = _a.sent();
this.state.setError(this.path, "Something went wrong");
this.state.setValidating(this.path, false);
return [2 /*return*/];
case 4:
currentRaw = this.state.raw.get(this.path);
// if the raw changed in the mean time, bail out
if (!equal(unwrap(currentRaw), unwrap(raw))) {
return [2 /*return*/];
}
// validation only is complete if the currentRaw has been validated
this.state.setValidating(this.path, false);
if (processResult instanceof ValidationMessage) {
this.state.setError(this.path, processResult.message);
return [2 /*return*/];
}
else {
this.state.deleteError(this.path);
}
if (!(processResult instanceof ProcessValue)) {
throw new Error("Unknown process result");
}
extraResult = this.state.extraValidationFunc(this, processResult.value);
// XXX possible flicker?
if (typeof extraResult === "string" && extraResult) {
this.state.setError(this.path, extraResult);
}
// if there are no changes, don't do anything
if (equal(unwrap(this.value), unwrap(processResult.value))) {
return [2 /*return*/];
}
this.state.setValueWithoutRawUpdate(this.path, processResult.value);
changeFunc = this.field.changeFunc;
if (changeFunc != null) {
changeFunc(this.node, processResult.value);
}
return [2 /*return*/];
}
});
});
};
Object.defineProperty(FieldAccessor.prototype, "inputProps", {
get: function () {
var result = this.field.controlled(this);
result.disabled = this.disabled;
if (this.state.focusFunc != null) {
result.onFocus = this.handleFocus;
}
return result;
},
enumerable: true,
configurable: true
});
Object.defineProperty(FieldAccessor.prototype, "validationProps", {
get: function () {
var error = this.error;
var isValidating = this.isValidating;
if (!error) {
return { validateStatus: isValidating ? "validating" : "" };
}
return {
validateStatus: isValidating ? "validating" : "error",
help: error
};
},
enumerable: true,
configurable: true
});
FieldAccessor.prototype.accessBySteps = function (steps) {
throw new Error("Cannot step through field accessor");
};
__decorate([
mobx.computed
], FieldAccessor.prototype, "addMode", null);
__decorate([
mobx.computed
], FieldAccessor.prototype, "raw", null);
__decorate([
mobx.computed
], FieldAccessor.prototype, "value", null);
__decorate([
mobx.computed
], FieldAccessor.prototype, "errorValue", null);
__decorate([
mobx.computed
], FieldAccessor.prototype, "canShowValidationMessages", null);
__decorate([
mobx.computed
], FieldAccessor.prototype, "error", null);
__decorate([
mobx.computed
], FieldAccessor.prototype, "isValidating", null);
__decorate([
mobx.computed
], FieldAccessor.prototype, "disabled", null);
__decorate([
mobx.computed
], FieldAccessor.prototype, "hidden", null);
__decorate([
mobx.action
], FieldAccessor.prototype, "setRaw", null);
__decorate([
mobx.computed
], FieldAccessor.prototype, "inputProps", null);
__decorate([
mobx.computed
], FieldAccessor.prototype, "validationProps", null);
return FieldAccessor;
}());
var RepeatingFormAccessor = /** @class */ (function () {
function RepeatingFormAccessor(state, repeatingForm, nodes, path, name) {
this.state = state;
this.repeatingForm = repeatingForm;
this.nodes = nodes;
this.name = name;
this.path = path + "/" + name;
}
RepeatingFormAccessor.prototype.validate = function () {
return __awaiter(this, void 0, void 0, function () {
var promises, _i, _a, accessor, values;
return __generator(this, function (_b) {
switch (_b.label) {
case 0:
promises = [];
for (_i = 0, _a = this.accessors; _i < _a.length; _i++) {
accessor = _a[_i];
promises.push(accessor.validate());
}
return [4 /*yield*/, Promise.all(promises)];
case 1:
values = _b.sent();
return [2 /*return*/, values.filter(function (value) { return !value; }).length === 0];
}
});
});
};
RepeatingFormAccessor.prototype.index = function (index) {
return new RepeatingFormIndexedAccessor(this.state, this.repeatingForm.definition, this.nodes[index], this.path, index);
};
Object.defineProperty(RepeatingFormAccessor.prototype, "disabled", {
get: function () {
return this.state.isRepeatingFormDisabledFunc(this);
},
enumerable: true,
configurable: true
});
Object.defineProperty(RepeatingFormAccessor.prototype, "accessors", {
get: function () {
var result = [];
for (var index = 0; index < this.length; index++) {
result.push(this.index(index));
}
return result;
},
enumerable: true,
configurable: true
});
Object.defineProperty(RepeatingFormAccessor.prototype, "flatAccessors", {
get: function () {
var result = [];
this.accessors.forEach(function (accessor) {
result.push.apply(result, accessor.flatAccessors);
});
return result;
},
enumerable: true,
configurable: true
});
RepeatingFormAccessor.prototype.accessBySteps = function (steps) {
var first = steps[0], rest = steps.slice(1);
var number = parseInt(first, 10);
if (isNaN(number)) {
throw new Error("Expected index of repeating form");
}
var accessor = this.index(number);
return accessor.accessBySteps(rest);
};
Object.defineProperty(RepeatingFormAccessor.prototype, "error", {
get: function () {
return this.state.errors.get(this.path);
},
enumerable: true,
configurable: true
});
RepeatingFormAccessor.prototype.insert = function (index, node) {
var path = this.path + "/" + index;
mobxStateTree.applyPatch(this.state.node, [{ op: "add", path: path, value: node }]);
};
RepeatingFormAccessor.prototype.push = function (node) {
var a = mobxStateTree.resolvePath(this.state.node, this.path);
var path = this.path + "/" + a.length;
mobxStateTree.applyPatch(this.state.node, [{ op: "add", path: path, value: node }]);
};
RepeatingFormAccessor.prototype.remove = function (node) {
var a = mobxStateTree.resolvePath(this.state.node, this.path);
var index = a.indexOf(node);
if (index === -1) {
throw new Error("Cannot find node to remove.");
}
mobxStateTree.applyPatch(this.state.node, [
{ op: "remove", path: this.path + "/" + index }
]);
};
Object.defineProperty(RepeatingFormAccessor.prototype, "length", {
get: function () {
var a = mobxStateTree.resolvePath(this.state.node, this.path);
return a.length;
},
enumerable: true,
configurable: true
});
__decorate([
mobx.computed
], RepeatingFormAccessor.prototype, "disabled", null);
__decorate([
mobx.computed
], RepeatingFormAccessor.prototype, "accessors", null);
__decorate([
mobx.computed
], RepeatingFormAccessor.prototype, "flatAccessors", null);
__decorate([
mobx.computed
], RepeatingFormAccessor.prototype, "error", null);
return RepeatingFormAccessor;
}());
var RepeatingFormIndexedAccessor = /** @class */ (function () {
function RepeatingFormIndexedAccessor(state, definition, node, path, index) {
this.state = state;
this.definition = definition;
this.node = node;
this.index = index;
this.path = path + "/" + index;
this.formAccessor = new FormAccessor(state, definition, node, path + "/" + index);
}
RepeatingFormIndexedAccessor.prototype.validate = function () {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
return [2 /*return*/, this.formAccessor.validate()];
});
});
};
RepeatingFormIndexedAccessor.prototype.access = function (name) {
return this.formAccessor.access(name);
};
RepeatingFormIndexedAccessor.prototype.accessBySteps = function (steps) {
var first = steps[0], rest = steps.slice(1);
var accessor = this.access(first);
if (rest.length === 0) {
return accessor;
}
if (accessor === undefined) {
return undefined;
}
return accessor.accessBySteps(steps);
};
RepeatingFormIndexedAccessor.prototype.field = function (name) {
return this.formAccessor.field(name);
};
RepeatingFormIndexedAccessor.prototype.repeatingForm = function (name) {
return this.formAccessor.repeatingForm(name);
};
Object.defineProperty(RepeatingFormIndexedAccessor.prototype, "accessors", {
get: function () {
return this.formAccessor.accessors;
},
enumerable: true,
configurable: true
});
Object.defineProperty(RepeatingFormIndexedAccessor.prototype, "flatAccessors", {
get: function () {
return this.formAccessor.flatAccessors;
},
enumerable: true,
configurable: true
});
__decorate([
mobx.computed
], RepeatingFormIndexedAccessor.prototype, "accessors", null);
__decorate([
mobx.computed
], RepeatingFormIndexedAccessor.prototype, "flatAccessors", null);
return RepeatingFormIndexedAccessor;
}());
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();
this.derivedDisposers = mobx.observable.map();
this.additionalErrorTree = {};
this.noRawUpdate = false;
mobxStateTree.onPatch(node, function (patch) {
if (patch.op === "remove") {
_this.removePath(patch.path);
}
else if (patch.op === "add") {
_this.addPath(patch.path);
}
else if (patch.op === "replace") {
_this.setRawFromValue(patch.path);
}
});
this.formAccessor = new FormAccessor(this, this.form.definition, node, "");
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);
this.focusFunc = null;
}
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;
this.focusFunc = options.focus ? options.focus : null;
}
}
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.setSaveStatus = function (status) {
this.saveStatus = status;
};
FormState.prototype.setRaw = function (path, value) {
if (this.saveStatus === "rightAfter") {
this.setSaveStatus("after");
}
this.raw.set(path, value);
};
FormState.prototype.setRawFromValue = function (path) {
if (this.noRawUpdate) {
return;
}
var fieldAccessor = this.accessByPath(path);
if (fieldAccessor === undefined ||
!(fieldAccessor instanceof FieldAccessor)) {
// if this is any other accessor or undefined, we cannot re-render
// as there is no raw
return;
}
// get underlying value; we can't get it from
// fieldAccessor as it might be in addMode
var value = this.getValue(path);
// we don't use setRaw on the field but directly re-rerender
// this causes any addMode for this field to be disabled
this.setRaw(path, fieldAccessor.field.render(value));
// trigger validation
fieldAccessor.validate();
};
FormState.prototype.setValueWithoutRawUpdate = function (path, value) {
this.noRawUpdate = true;
mobxStateTree.applyPatch(this.node, [{ op: "replace", path: path, value: value }]);
this.noRawUpdate = false;
};
FormState.prototype.setDerivedDisposer = function (path, disposer) {
this.derivedDisposers.set(path, disposer);
};
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);
this.derivedDisposers = removePath(this.derivedDisposers, path, function (value) {
value();
});
this.addModePaths.set(path, true);
};
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);
this.derivedDisposers = addPath(this.derivedDisposers, path);
this.addModePaths.set(path, true);
};
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.setSaveStatus("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;
var additionalErrors = deepCopy(errors);
this.flatAccessors.map(function (accessor) {
var error = getByPath(errors, accessor.path);
if (error != null) {
_this.errors.set(accessor.path, error);
// delete from remaining structure
deleteByPath(additionalErrors, accessor.path);
}
});
this.additionalErrorTree = additionalErrors;
};
FormState.prototype.clearErrors = function () {
this.additionalErrorTree = {};
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.accessByPath = function (path) {
var steps = pathToSteps(path);
return this.accessBySteps(steps);
};
FormState.prototype.accessBySteps = function (steps) {
return this.formAccessor.accessBySteps(steps);
};
FormState.prototype.access = function (name) {
return this.formAccessor.access(name);
};
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) { };
FormState.prototype.additionalError = function (name) {
var result = this.additionalErrorTree[name];
if (typeof result !== "string") {
return undefined;
}
return result;
};
Object.defineProperty(FormState.prototype, "additionalErrors", {
get: function () {
var _this = this;
var result = [];
Object.keys(this.additionalErrorTree).forEach(function (key) {
var value = _this.additionalErrorTree[key];
if (typeof value !== "string") {
return;
}
result.push(value);
});
result.sort();
return result;
},
enumerable: true,
configurable: true
});
__decorate([
mobx.observable
], FormState.prototype, "raw", void 0);
__decorate([
mobx.observable
], FormState.prototype, "errors", void 0);
__decorate([
mobx.observable
], FormState.prototype, "additionalErrorTree", void 0);
__decorate([
mobx.observable
], FormState.prototype, "validating", void 0);
__decorate([
mobx.observable
], FormState.prototype, "addModePaths", void 0);
__decorate([
mobx.observable
], FormState.prototype, "derivedDisposers", 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, "setSaveStatus", null);
__decorate([
mobx.action
], FormState.prototype, "setRaw", null);
__decorate([
mobx.action
], FormState.prototype, "setRawFromValue", null);
__decorate([
mobx.action
], FormState.prototype, "setValueWithoutRawUpdate", null);
__decorate([
mobx.action
], FormState.prototype, "setDerivedDisposer", 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);
__decorate([
mobx.computed
], FormState.prototype, "additionalErrors", 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;
}());
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;
this.controlled = this.createDefaultControlled();
}
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;
}
this.derivedFunc = options.derived;
this.changeFunc = options.change;
this.controlled = options.controlled || this.createDefaultControlled();
}
}
Field.prototype.createDefaultControlled = function () {
var _this = this;
if (this.getRaw !== identity) {
return function (accessor) {
return {
value: accessor.raw,
onChange: function () {
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
return accessor.setRaw(_this.getRaw.apply(_this, args));
}
};
};
}
return this.converter.defaultControlled;
};
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 NUMBER_REGEX = new RegExp("^-?(0|[1-9]\\d*)(\\.\\d*)?$");
var INTEGER_REGEX = new RegExp("^-?(0|[1-9]\\d*)$");
var StringConverter = /** @class */ (function (_super) {
__extends(StringConverter, _super);
function StringConverter() {
var _this = _super !== null && _super.apply(this, arguments) || this;
_this.defaultControlled = controlled.value;
return _this;
}
return StringConverter;
}(Converter));
var string = new StringConverter({
emptyRaw: "",
convert: function (raw) {
return raw;
},
render: function (value) {
return value;
}
});
var number = new StringConverter({
emptyRaw: "",
rawValidate: function (raw) {
// deal with case when string starts with .
if (raw.startsWith(".")) {
raw = "0" + raw;
}
return NUMBER_REGEX.test(raw);
},
convert: function (raw) {
return +raw;
},
render: function (value) {
return value.toString();
}
});
var integer = new StringConverter({
emptyRaw: "",
rawValidate: function (raw) {
return INTEGER_REGEX.test(raw);
},
convert: function (raw) {
return +raw;
},
render: function (value) {
return value.toString();
}
});
var boolean = new Converter({
emptyRaw: false,
convert: function (raw) {
return raw;
},
render: function (value) {
return value;
},
defaultControlled: controlled.checked
});
var Decimal = /** @class */ (function () {
function Decimal(maxWholeDigits, decimalPlaces) {
this.maxWholeDigits = maxWholeDigits;
this.decimalPlaces = decimalPlaces;
this.defaultControlled = controlled.value;
this.emptyRaw = "";
var regex = new RegExp("^-?(0|[1-9]\\d{0," + (maxWholeDigits - 1) + "})(\\.\\d{0," + decimalPlaces + "})?$");
this.converter = new StringConverter({
emptyRaw: "",
rawValidate: function (raw) {
// deal with case when string starts with .
if (raw.startsWith(".")) {
raw = "0" + raw;
}
return regex.test(raw);
},
convert: function (raw) {
return raw;
},
render: function (value) {
return value;
}
});
}
Decimal.prototype.convert = function (raw) {
return this.converter.convert(raw);
};
Decimal.prototype.render = function (value) {
return this.converter.render(value);
};
Decimal.prototype.getRaw = function (value) {
return value;
};
return Decimal;
}());
function decimal(maxDigits, decimalPlaces) {
return new Decimal(maxDigits, decimalPlaces);
}
// XXX create a way to create arrays with mobx state tree types
var stringArray = new Converter({
emptyRaw: [],
convert: function (raw) {
return mobx.observable.array(raw);
},
render: function (value) {
return value.slice();
}
});
function maybe(converter) {
if (converter instanceof StringConverter) {
return new StringMaybe(converter);
}
return maybeModel(converter);
}
var StringMaybe = /** @class */ (function () {
function StringMaybe(converter) {
this.converter = converter;
this.defaultControlled = controlled.value;
this.emptyRaw = "";
}
StringMaybe.prototype.convert = function (raw) {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
if (raw.trim() === "") {
return [2 /*return*/, new ConversionValue(null)];
}
return [2 /*return*/, this.converter.convert(raw)];
});
});
};
StringMaybe.prototype.render = function (value) {
if (value === null) {
return "";
}
return this.converter.render(value);
};
return StringMaybe;
}());
var Model = /** @class */ (function () {
function Model(model) {
this.emptyRaw = null;
this.defaultControlled = controlled.object;
}
Model.prototype.convert = function (raw) {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
if (raw === null) {
return [2 /*return*/, CONVERSION_ERROR];
}
return [2 /*return*/, new ConversionValue(raw)];
});
});
};
Model.prototype.render = function (value) {
return value;
};
return Model;
}());
function model(model) {
return new Model(model);
}
function maybeModel(converter) {
return new Converter({
emptyRaw: null,
convert: identity,
render: identity,
defaultControlled: controlled.object
});
}
var object$1 = new Converter({
emptyRaw: null,
convert: identity,
render: identity
});
var converters = {
string: string,
number: number,
integer: integer,
decimal: decimal,
boolean: boolean,
stringArray: stringArray,
maybe: maybe,
model: model,
object: object$1
};
exports.Form = Form;
exports.ValidationMessage = ValidationMessage;
exports.ProcessValue = ProcessValue;
exports.Field = Field;
exports.RepeatingForm = RepeatingForm;
exports.ConversionValue = ConversionValue;
exports.CONVERSION_ERROR = CONVERSION_ERROR;
exports.Converter = Converter;
exports.StringConverter = StringConverter;
exports.converters = converters;
exports.FormAccessor = FormAccessor;
exports.FieldAccessor = FieldAccessor;
exports.RepeatingFormAccessor = RepeatingFormAccessor;
exports.RepeatingFormIndexedAccessor = RepeatingFormIndexedAccessor;
exports.controlled = controlled;
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e(require("mobx"),require("mobx-state-tree")):"function"==typeof define&&define.amd?define(["mobx","mobx-state-tree"],e):"object"==typeof exports?exports.mstform=e(require("mobx"),require("mobx-state-tree")):t.mstform=e(t.mobx,t["mobx-state-tree"])}(window,function(t,e){return function(t){var e={};function r(n){if(e[n])return e[n].exports;var o=e[n]={i:n,l:!1,exports:{}};return t[n].call(o.exports,o,o.exports,r),o.l=!0,o.exports}return r.m=t,r.c=e,r.d=function(t,e,n){r.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:n})},r.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},r.t=function(t,e){if(1&e&&(t=r(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var o in t)r.d(n,o,function(e){return t[e]}.bind(null,o));return n},r.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return r.d(e,"a",e),e},r.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},r.p="",r(r.s=2)}([function(e,r){e.exports=t},function(t,r){t.exports=e},function(t,e,r){"use strict";r.r(e);var n={value:function(t){return{value:t.raw,onChange:function(e){return t.setRaw(e.target.value)}}},checked:function(t){return{checked:t.raw,onChange:function(e){return t.setRaw(e.target.checked)}}},object:function(t){return{value:t.raw,onChange:function(e){return t.setRaw(e)}}}},o=function(t,e,r,n){return new(r||(r=Promise))(function(o,i){function s(t){try{u(n.next(t))}catch(t){i(t)}}function a(t){try{u(n.throw(t))}catch(t){i(t)}}function u(t){t.done?o(t.value):new r(function(e){e(t.value)}).then(s,a)}u((n=n.apply(t,e||[])).next())})},i=function(t,e){var r,n,o,i,s={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function a(i){return function(a){return function(i){if(r)throw new TypeError("Generator is already executing.");for(;s;)try{if(r=1,n&&(o=2&i[0]?n.return:i[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,i[1])).done)return o;switch(n=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return s.label++,{value:i[1],done:!1};case 5:s.label++,n=i[1],i=[0];continue;case 7:i=s.ops.pop(),s.trys.pop();continue;default:if(!(o=(o=s.trys).length>0&&o[o.length-1])&&(6===i[0]||2===i[0])){s=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){s.label=i[1];break}if(6===i[0]&&s.label<o[1]){s.label=o[1],o=i;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(i);break}o[2]&&s.ops.pop(),s.trys.pop();continue}i=e.call(t,s)}catch(t){i=[6,t],n=0}finally{r=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,a])}}},s=function(){return function(t){this.value=t}}(),a=function(){function t(t){this.definition=t,this.emptyRaw=t.emptyRaw,this.defaultControlled=t.defaultControlled?t.defaultControlled:n.object}return t.prototype.convert=function(t){return o(this,void 0,void 0,function(){var e;return i(this,function(r){switch(r.label){case 0:return this.definition.rawValidate?[4,this.definition.rawValidate(t)]:[3,2];case 1:if(!r.sent())return[2,"ConversionError"];r.label=2;case 2:return e=this.definition.convert(t),this.definition.validate?[4,this.definition.validate(e)]:[3,4];case 3:if(!r.sent())return[2,"ConversionError"];r.label=4;case 4:return[2,new s(e)]}})})},t.prototype.render=function(t){return this.definition.render(t)},t}(),u=r(0),c=r(1),p=function(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;a>=0;a--)(o=t[a])&&(s=(i<3?o(s):i>3?o(e,r,s):o(e,r))||s);return i>3&&s&&Object.defineProperty(e,r,s),s},l=function(t,e){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(t,e)},d=function(t,e,r,n){return new(r||(r=Promise))(function(o,i){function s(t){try{u(n.next(t))}catch(t){i(t)}}function a(t){try{u(n.throw(t))}catch(t){i(t)}}function u(t){t.done?o(t.value):new r(function(e){e(t.value)}).then(s,a)}u((n=n.apply(t,e||[])).next())})},f=function(t,e){var r,n,o,i,s={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function a(i){return function(a){return function(i){if(r)throw new TypeError("Generator is already executing.");for(;s;)try{if(r=1,n&&(o=2&i[0]?n.return:i[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,i[1])).done)return o;switch(n=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return s.label++,{value:i[1],done:!1};case 5:s.label++,n=i[1],i=[0];continue;case 7:i=s.ops.pop(),s.trys.pop();continue;default:if(!(o=(o=s.trys).length>0&&o[o.length-1])&&(6===i[0]||2===i[0])){s=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){s.label=i[1];break}if(6===i[0]&&s.label<o[1]){s.label=o[1],o=i;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(i);break}o[2]&&s.ops.pop(),s.trys.pop();continue}i=e.call(t,s)}catch(t){i=[6,t],n=0}finally{r=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,a])}}},h=function(){return{}};function y(t){h=t}var v=function(){function t(t,e,r,n,o){this.state=t,this.definition=e,this.node=r,this.path=n,this.allowedKeys=o,this.keys=null!=o?o:Object.keys(this.definition)}return t.prototype.validate=function(){return d(this,void 0,void 0,function(){var t;return f(this,function(e){switch(e.label){case 0:return t=this.accessors.map(function(t){return t.validate()}),[4,Promise.all(t)];case 1:return[2,e.sent().every(function(t){return t})]}})})},Object.defineProperty(t.prototype,"isValid",{get:function(){return this.accessors.every(function(t){return t.isValid})},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"accessors",{get:function(){var t=this,e=[];return this.keys.forEach(function(r){var n=t.definition[r];n instanceof I?e.push(t.field(r)):n instanceof U&&e.push(t.repeatingForm(r))}),e},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"flatAccessors",{get:function(){var t=[];return this.accessors.forEach(function(e){e instanceof g?t.push(e):e instanceof b&&(t.push.apply(t,e.flatAccessors),t.push(e))}),t},enumerable:!0,configurable:!0}),t.prototype.access=function(t){if(this.keys.includes(t))try{return this.field(t)}catch(e){try{return this.repeatingForm(t)}catch(t){return}}},t.prototype.accessBySteps=function(t){var e=t[0],r=t.slice(1),n=this.access(e);return 0===r.length?n:void 0===n?n:n.accessBySteps(r)},t.prototype.getDefinitionEntry=function(t){if(this.keys.includes(t))return this.definition[t]},t.prototype.restricted=function(e){var r=this;return e.forEach(function(t){if(!r.keys.includes(t))throw new Error("Cannot restrict FormAccessor to non-existent key: "+t)}),new t(this.state,this.definition,this.node,this.path,e)},t.prototype.field=function(t){var e=this.getDefinitionEntry(t);if(null==e)throw new Error("Field "+t+" is not in group");if(!(e instanceof I))throw new Error("Not accessing a Field instance");return new g(this.state,e,this.node,this.path,t)},t.prototype.repeatingForm=function(t){var e=this.getDefinitionEntry(t);if(null==e)throw new Error("RepeatingForm "+t+" is not in group");if(!(e instanceof U))throw new Error("Not accessing a RepeatingForm instance");var r=this.node[t];return new b(this.state,e,r,this.path,t)},t.prototype.repeatingField=function(t){},p([u.computed,l("design:type",Boolean),l("design:paramtypes",[])],t.prototype,"isValid",null),p([u.computed,l("design:type",Array),l("design:paramtypes",[])],t.prototype,"accessors",null),p([u.computed,l("design:type",Array),l("design:paramtypes",[])],t.prototype,"flatAccessors",null),t}(),g=function(){function t(t,e,r,n,o){var i=this;this.state=t,this.field=e,this.node=r,this.handleChange=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];return d(i,void 0,void 0,function(){var e,r;return f(this,function(n){switch(n.label){case 0:return r=(e=this.field).getRaw.apply(e,t),[4,this.setRaw(r)];case 1:return n.sent(),[2]}})})},this.handleFocus=function(t){null!=i.state.focusFunc&&i.state.focusFunc(t,i)},this.name=o,this.path=n+"/"+o,this.createDerivedReaction()}var e,r,n;return t.prototype.createDerivedReaction=function(){var t=this,e=this.field.derivedFunc;if(null!=e&&!this.state.derivedDisposers.get(this.path)){var r=Object(u.reaction)(function(){return e(t.node)},function(e){t.setRaw(t.field.render(e))});this.state.setDerivedDisposer(this.path,r)}},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?!Object(u.isObservable)(t)||t instanceof Array?Object(u.toJS)(t):t:this.addMode?this.field.converter.emptyRaw:this.field.render(this.value)},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 d(this,void 0,void 0,function(){return f(this,function(t){switch(t.label){case 0:return[4,this.setRaw(this.raw)];case 1:return t.sent(),[2,this.isValid]}})})},Object.defineProperty(t.prototype,"isValid",{get:function(){return void 0===this.errorValue},enumerable:!0,configurable:!0}),t.prototype.setRaw=function(t){return d(this,void 0,void 0,function(){var e,r,n,o;return f(this,function(i){switch(i.label){case 0:this.state.setRaw(this.path,t),this.state.setValidating(this.path,!0),i.label=1;case 1:return i.trys.push([1,3,,4]),[4,this.field.process(t)];case 2:return e=i.sent(),[3,4];case 3:return i.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),!u.comparer.structural(r,t))return[2];if(this.state.setValidating(this.path,!1),e instanceof _)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"string"==typeof(n=this.state.extraValidationFunc(this,e.value))&&n&&this.state.setError(this.path,n),u.comparer.structural(this.value,e.value)?[2]:(this.state.setValueWithoutRawUpdate(this.path,e.value),null!=(o=this.field.changeFunc)&&o(this.node,e.value),[2])}})})},Object.defineProperty(t.prototype,"inputProps",{get:function(){var t=this.field.controlled(this);return t.disabled=this.disabled,null!=this.state.focusFunc&&(t.onFocus=this.handleFocus),t},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"validationProps",{get:function(){return h(this)},enumerable:!0,configurable:!0}),t.prototype.accessBySteps=function(t){throw new Error("Cannot step through field accessor")},p([u.computed,l("design:type",Boolean),l("design:paramtypes",[])],t.prototype,"addMode",null),p([u.computed,l("design:type","function"==typeof(e="undefined"!=typeof R&&R)&&e||Object),l("design:paramtypes",[])],t.prototype,"raw",null),p([u.computed,l("design:type","function"==typeof(r="undefined"!=typeof V&&V)&&r||Object),l("design:paramtypes",[])],t.prototype,"value",null),p([u.computed,l("design:type",Object),l("design:paramtypes",[])],t.prototype,"errorValue",null),p([u.computed,l("design:type",Boolean),l("design:paramtypes",[])],t.prototype,"canShowValidationMessages",null),p([u.computed,l("design:type",Object),l("design:paramtypes",[])],t.prototype,"error",null),p([u.computed,l("design:type",Boolean),l("design:paramtypes",[])],t.prototype,"isValidating",null),p([u.computed,l("design:type",Boolean),l("design:paramtypes",[])],t.prototype,"disabled",null),p([u.computed,l("design:type",Boolean),l("design:paramtypes",[])],t.prototype,"hidden",null),p([u.computed,l("design:type",Boolean),l("design:paramtypes",[])],t.prototype,"isValid",null),p([u.action,l("design:type",Function),l("design:paramtypes",["function"==typeof(n="undefined"!=typeof R&&R)&&n||Object]),l("design:returntype",Promise)],t.prototype,"setRaw",null),p([u.computed,l("design:type",Object),l("design:paramtypes",[])],t.prototype,"inputProps",null),p([u.computed,l("design:type",Object),l("design:paramtypes",[])],t.prototype,"validationProps",null),t}(),b=function(){function t(t,e,r,n,o){this.state=t,this.repeatingForm=e,this.nodes=r,this.name=o,this.path=n+"/"+o}return t.prototype.validate=function(){return d(this,void 0,void 0,function(){var t,e,r,n;return f(this,function(o){switch(o.label){case 0:for(t=[],e=0,r=this.accessors;e<r.length;e++)n=r[e],t.push(n.validate());return[4,Promise.all(t)];case 1:return[2,o.sent().every(function(t){return t})]}})})},Object.defineProperty(t.prototype,"isValid",{get:function(){return this.accessors.every(function(t){return t.isValid})},enumerable:!0,configurable:!0}),t.prototype.index=function(t){return new m(this.state,this.repeatingForm.definition,this.nodes[t],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 t=[];return this.accessors.forEach(function(e){t.push.apply(t,e.flatAccessors)}),t},enumerable:!0,configurable:!0}),t.prototype.accessBySteps=function(t){var e=t[0],r=t.slice(1),n=parseInt(e,10);if(isNaN(n))throw new Error("Expected index of repeating form");return this.index(n).accessBySteps(r)},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;Object(c.applyPatch)(this.state.node,[{op:"add",path:r,value:e}])},t.prototype.push=function(t){var e=Object(c.resolvePath)(this.state.node,this.path),r=this.path+"/"+e.length;Object(c.applyPatch)(this.state.node,[{op:"add",path:r,value:t}])},t.prototype.remove=function(t){var e=Object(c.resolvePath)(this.state.node,this.path).indexOf(t);if(-1===e)throw new Error("Cannot find node to remove.");Object(c.applyPatch)(this.state.node,[{op:"remove",path:this.path+"/"+e}])},Object.defineProperty(t.prototype,"length",{get:function(){return Object(c.resolvePath)(this.state.node,this.path).length},enumerable:!0,configurable:!0}),p([u.computed,l("design:type",Boolean),l("design:paramtypes",[])],t.prototype,"isValid",null),p([u.computed,l("design:type",Boolean),l("design:paramtypes",[])],t.prototype,"disabled",null),p([u.computed,l("design:type",Array),l("design:paramtypes",[])],t.prototype,"accessors",null),p([u.computed,l("design:type",Array),l("design:paramtypes",[])],t.prototype,"flatAccessors",null),p([u.computed,l("design:type",Object),l("design:paramtypes",[])],t.prototype,"error",null),t}(),m=function(){function t(t,e,r,n,o){this.state=t,this.definition=e,this.node=r,this.index=o,this.path=n+"/"+o,this.formAccessor=new v(t,e,r,n+"/"+o)}return t.prototype.validate=function(){return d(this,void 0,void 0,function(){return f(this,function(t){return[2,this.formAccessor.validate()]})})},Object.defineProperty(t.prototype,"isValid",{get:function(){return this.formAccessor.isValid},enumerable:!0,configurable:!0}),t.prototype.access=function(t){return this.formAccessor.access(t)},t.prototype.accessBySteps=function(t){var e=t[0],r=t.slice(1),n=this.access(e);return 0===r.length?n:void 0!==n?n.accessBySteps(t):void 0},t.prototype.restricted=function(t){return this.formAccessor.restricted(t)},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}),p([u.computed,l("design:type",Boolean),l("design:paramtypes",[])],t.prototype,"isValid",null),p([u.computed,l("design:type",Array),l("design:paramtypes",[])],t.prototype,"accessors",null),p([u.computed,l("design:type",Array),l("design:paramtypes",[])],t.prototype,"flatAccessors",null),t}();function w(t){return t}function P(t){return t.startsWith("/")&&(t=t.slice(1)),t.split("/")}function j(t){var e=t.join("/");return e.startsWith("/")?e:"/"+e}function O(t){return Number.isInteger(parseInt(t,10))}function E(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,P(e))}function F(t,e){return function t(e,r){var n=r[0],o=r.slice(1);0===o.length&&delete e[n];var i=e[n];if(void 0===i)return;t(i,o)}(t,P(e))}function S(t,e,r){var n=P(e),o=n[n.length-1],i=parseInt(o,10),s=j(n.slice(0,n.length-1)),a=new Map;return t.forEach(function(t,e){if(e.startsWith(s)){var n=P(e.slice(s.length+1)),o=parseInt(n[0],10);if(isNaN(o))a.set(e,t);else if(o<i)a.set(e,t);else if(o!==i){var u=n.slice(1),c=s+j([(o-1).toString()].concat(u));a.delete(e),a.set(c,t)}else null!=r&&r(t)}else a.set(e,t)}),a}function x(t,e){var r=P(e),n=r[r.length-1],o=parseInt(n,10);if(isNaN(o))return t;var i=j(r.slice(0,r.length-1)),s=new Map;return t.forEach(function(t,e){if(e.startsWith(i)){var r=P(e.slice(i.length+1)),n=parseInt(r[0],10);if(isNaN(n))s.set(e,t);else if(n<o)s.set(e,t);else{var a=r.slice(1),u=i+j([(n+1).toString()].concat(a));s.set(u,t)}}else s.set(e,t)}),s}var A=function(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;a>=0;a--)(o=t[a])&&(s=(i<3?o(s):i>3?o(e,r,s):o(e,r))||s);return i>3&&s&&Object.defineProperty(e,r,s),s},D=function(t,e){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(t,e)},C=function(t,e,r,n){return new(r||(r=Promise))(function(o,i){function s(t){try{u(n.next(t))}catch(t){i(t)}}function a(t){try{u(n.throw(t))}catch(t){i(t)}}function u(t){t.done?o(t.value):new r(function(e){e(t.value)}).then(s,a)}u((n=n.apply(t,e||[])).next())})},M=function(t,e){var r,n,o,i,s={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function a(i){return function(a){return function(i){if(r)throw new TypeError("Generator is already executing.");for(;s;)try{if(r=1,n&&(o=2&i[0]?n.return:i[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,i[1])).done)return o;switch(n=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return s.label++,{value:i[1],done:!1};case 5:s.label++,n=i[1],i=[0];continue;case 7:i=s.ops.pop(),s.trys.pop();continue;default:if(!(o=(o=s.trys).length>0&&o[o.length-1])&&(6===i[0]||2===i[0])){s=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){s.label=i[1];break}if(6===i[0]&&s.label<o[1]){s.label=o[1],o=i;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(i);break}o[2]&&s.ops.pop(),s.trys.pop();continue}i=e.call(t,s)}catch(t){i=[6,t],n=0}finally{r=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,a])}}},k=function(){function t(t,e,r){var n=this;if(this.form=t,this.node=e,this.saveStatus="before",this.raw=u.observable.map(),this.errors=u.observable.map(),this.validating=u.observable.map(),this.addModePaths=u.observable.map(),this.derivedDisposers=u.observable.map(),this.additionalErrorTree={},this.noRawUpdate=!1,Object(c.onPatch)(e,function(t){"remove"===t.op?n.removePath(t.path):"add"===t.op?n.addPath(t.path):"replace"===t.op&&n.setRawFromValue(t.path)}),this.formAccessor=new v(this,this.form.definition,e,""),null==r)this.saveFunc=B,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),this.focusFunc=null;else{this.saveFunc=r.save?r.save:B,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 o=r.validation||{};this.validationBeforeSave=o.beforeSave||"immediate",this.validationAfterSave=o.afterSave||"immediate",this.validationPauseDuration=o.pauseDuration||0,this.focusFunc=r.focus?r.focus:null}}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.setSaveStatus=function(t){this.saveStatus=t},t.prototype.setRaw=function(t,e){"rightAfter"===this.saveStatus&&this.setSaveStatus("after"),this.raw.set(t,e)},t.prototype.setRawFromValue=function(t){if(!this.noRawUpdate){var e=this.accessByPath(t);if(void 0!==e&&e instanceof g){var r=this.getValue(t);this.setRaw(t,e.field.render(r)),e.validate()}}},t.prototype.setValueWithoutRawUpdate=function(t,e){this.noRawUpdate=!0,Object(c.applyPatch)(this.node,[{op:"replace",path:t,value:e}]),this.noRawUpdate=!1},t.prototype.setDerivedDisposer=function(t,e){this.derivedDisposers.set(t,e)},t.prototype.removePath=function(t){this.raw=S(this.raw,t),this.errors=S(this.errors,t),this.validating=S(this.validating,t),this.addModePaths=S(this.addModePaths,t),this.derivedDisposers=S(this.derivedDisposers,t,function(t){t()}),this.addModePaths.set(t,!0)},t.prototype.addPath=function(t){this.raw=x(this.raw,t),this.errors=x(this.errors,t),this.validating=x(this.validating,t),this.addModePaths=x(this.addModePaths,t),this.derivedDisposers=x(this.derivedDisposers,t),this.addModePaths.set(t,!0)},t.prototype.validate=function(){return C(this,void 0,void 0,function(){return M(this,function(t){return[2,this.formAccessor.validate()]})})},Object.defineProperty(t.prototype,"isValid",{get:function(){return this.formAccessor.isValid},enumerable:!0,configurable:!0}),t.prototype.save=function(){return C(this,void 0,void 0,function(){var t,e;return M(this,function(r){switch(r.label){case 0:return[4,this.validate()];case 1:return t=r.sent(),this.setSaveStatus("rightAfter"),t?[4,this.saveFunc(this.node)]:[2,!1];case 2:return null!=(e=r.sent())?(this.setErrors(e),[2,!1]):(this.clearErrors(),[2,!0])}})})},t.prototype.setErrors=function(t){var e=this,r=function(t){return JSON.parse(JSON.stringify(t))}(t);this.flatAccessors.map(function(n){var o=E(t,n.path);null!=o&&(e.errors.set(n.path,o),F(r,n.path))}),this.additionalErrorTree=r},t.prototype.clearErrors=function(){this.additionalErrorTree={},this.errors.clear()},t.prototype.isKnownAddModePath=function(t){var e;return this.addModePaths.forEach(function(r,n){t.startsWith(n)&&(e=r)}),void 0!==e&&e},t.prototype.addMode=function(t){return this.isKnownAddModePath(t)&&void 0===this.raw.get(t)},t.prototype.getValue=function(t){return Object(c.resolvePath)(this.node,t)},t.prototype.getError=function(t){return this.errors.get(t)},t.prototype.getMstType=function(t){for(var e=P(t),r=this.form.model,n=0,o=e;n<o.length;n++){var i=o[n];O(i)?r=r.getChildType(i):r=r.getChildType(i)}return r},Object.defineProperty(t.prototype,"isValidating",{get:function(){return Array.from(this.validating.values()).filter(function(t){return t}).length>0},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.accessByPath=function(t){var e=P(t);return this.accessBySteps(e)},t.prototype.accessBySteps=function(t){return this.formAccessor.accessBySteps(t)},t.prototype.access=function(t){return this.formAccessor.access(t)},t.prototype.restricted=function(t){return this.formAccessor.restricted(t)},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){},t.prototype.additionalError=function(t){var e=this.additionalErrorTree[t];if("string"==typeof e)return e},Object.defineProperty(t.prototype,"additionalErrors",{get:function(){var t=this,e=[];return Object.keys(this.additionalErrorTree).forEach(function(r){var n=t.additionalErrorTree[r];"string"==typeof n&&e.push(n)}),e.sort(),e},enumerable:!0,configurable:!0}),A([u.observable,D("design:type",Map)],t.prototype,"raw",void 0),A([u.observable,D("design:type",Map)],t.prototype,"errors",void 0),A([u.observable,D("design:type",Object)],t.prototype,"additionalErrorTree",void 0),A([u.observable,D("design:type",Map)],t.prototype,"validating",void 0),A([u.observable,D("design:type",Map)],t.prototype,"addModePaths",void 0),A([u.observable,D("design:type",Map)],t.prototype,"derivedDisposers",void 0),A([u.observable,D("design:type",String)],t.prototype,"saveStatus",void 0),A([u.action,D("design:type",Function),D("design:paramtypes",[String,String]),D("design:returntype",void 0)],t.prototype,"setError",null),A([u.action,D("design:type",Function),D("design:paramtypes",[String]),D("design:returntype",void 0)],t.prototype,"deleteError",null),A([u.action,D("design:type",Function),D("design:paramtypes",[String,Boolean]),D("design:returntype",void 0)],t.prototype,"setValidating",null),A([u.action,D("design:type",Function),D("design:paramtypes",[String]),D("design:returntype",void 0)],t.prototype,"setSaveStatus",null),A([u.action,D("design:type",Function),D("design:paramtypes",[String,Object]),D("design:returntype",void 0)],t.prototype,"setRaw",null),A([u.action,D("design:type",Function),D("design:paramtypes",[String]),D("design:returntype",void 0)],t.prototype,"setRawFromValue",null),A([u.action,D("design:type",Function),D("design:paramtypes",[String,Object]),D("design:returntype",void 0)],t.prototype,"setValueWithoutRawUpdate",null),A([u.action,D("design:type",Function),D("design:paramtypes",[String,Function]),D("design:returntype",void 0)],t.prototype,"setDerivedDisposer",null),A([u.action,D("design:type",Function),D("design:paramtypes",[String]),D("design:returntype",void 0)],t.prototype,"removePath",null),A([u.action,D("design:type",Function),D("design:paramtypes",[String]),D("design:returntype",void 0)],t.prototype,"addPath",null),A([u.computed,D("design:type",Boolean),D("design:paramtypes",[])],t.prototype,"isValid",null),A([u.action,D("design:type",Function),D("design:paramtypes",[]),D("design:returntype",Promise)],t.prototype,"save",null),A([u.action,D("design:type",Function),D("design:paramtypes",[Object]),D("design:returntype",void 0)],t.prototype,"setErrors",null),A([u.action,D("design:type",Function),D("design:paramtypes",[]),D("design:returntype",void 0)],t.prototype,"clearErrors",null),A([u.computed,D("design:type",Boolean),D("design:paramtypes",[])],t.prototype,"isValidating",null),A([u.computed,D("design:type",Array),D("design:paramtypes",[])],t.prototype,"accessors",null),A([u.computed,D("design:type",Array),D("design:paramtypes",[])],t.prototype,"flatAccessors",null),A([u.computed,D("design:type",Array),D("design:paramtypes",[])],t.prototype,"additionalErrors",null),t}();function B(){return C(this,void 0,void 0,function(){return M(this,function(t){return console.warn("No mstform save function configured"),[2,null]})})}var T=function(t,e,r,n){return new(r||(r=Promise))(function(o,i){function s(t){try{u(n.next(t))}catch(t){i(t)}}function a(t){try{u(n.throw(t))}catch(t){i(t)}}function u(t){t.done?o(t.value):new r(function(e){e(t.value)}).then(s,a)}u((n=n.apply(t,e||[])).next())})},N=function(t,e){var r,n,o,i,s={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function a(i){return function(a){return function(i){if(r)throw new TypeError("Generator is already executing.");for(;s;)try{if(r=1,n&&(o=2&i[0]?n.return:i[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,i[1])).done)return o;switch(n=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return s.label++,{value:i[1],done:!1};case 5:s.label++,n=i[1],i=[0];continue;case 7:i=s.ops.pop(),s.trys.pop();continue;default:if(!(o=(o=s.trys).length>0&&o[o.length-1])&&(6===i[0]||2===i[0])){s=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){s.label=i[1];break}if(6===i[0]&&s.label<o[1]){s.label=o[1],o=i;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(i);break}o[2]&&s.ops.pop(),s.trys.pop();continue}i=e.call(t,s)}catch(t){i=[6,t],n=0}finally{r=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,a])}}},q=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 k(this,t,e)},t}(),_=function(){return function(t){this.message=t}}(),W=function(){return function(t){this.value=t}}(),I=function(){function t(t,e){if(this.converter=t,this.options=e,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||w;this.derivedFunc=e.derived,this.changeFunc=e.change,this.controlled=e.controlled||this.createDefaultControlled()}else this.rawValidators=[],this.validators=[],this.conversionError="Could not convert",this.requiredError="Required",this.required=!1,this.getRaw=w,this.controlled=this.createDefaultControlled()}return t.prototype.createDefaultControlled=function(){var t=this;return this.getRaw!==w?function(e){return{value:e.raw,onChange:function(){for(var r=[],n=0;n<arguments.length;n++)r[n]=arguments[n];return e.setRaw(t.getRaw.apply(t,r))}}}:this.converter.defaultControlled},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(t){return T(this,void 0,void 0,function(){var e,r,n,o,i,s;return N(this,function(a){switch(a.label){case 0:if(t===this.converter.emptyRaw&&this.required)return[2,new _(this.requiredError)];e=0,r=this.rawValidators,a.label=1;case 1:return e<r.length?[4,(0,r[e])(t)]:[3,4];case 2:if("string"==typeof(s=a.sent())&&s)return[2,new _(s)];a.label=3;case 3:return e++,[3,1];case 4:return[4,this.converter.convert(t)];case 5:if("ConversionError"===(n=a.sent()))return t===this.converter.emptyRaw?[2,new _(this.requiredError)]:[2,new _(this.conversionError)];o=0,i=this.validators,a.label=6;case 6:return o<i.length?[4,(0,i[o])(n.value)]:[3,9];case 7:if("string"==typeof(s=a.sent())&&s)return[2,new _(s)];a.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}(),U=function(){return function(t){this.definition=t}}(),G=function(){var t=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])};return function(e,r){function n(){this.constructor=e}t(e,r),e.prototype=null===r?Object.create(r):(n.prototype=r.prototype,new n)}}(),H=function(t,e,r,n){return new(r||(r=Promise))(function(o,i){function s(t){try{u(n.next(t))}catch(t){i(t)}}function a(t){try{u(n.throw(t))}catch(t){i(t)}}function u(t){t.done?o(t.value):new r(function(e){e(t.value)}).then(s,a)}u((n=n.apply(t,e||[])).next())})},K=function(t,e){var r,n,o,i,s={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function a(i){return function(a){return function(i){if(r)throw new TypeError("Generator is already executing.");for(;s;)try{if(r=1,n&&(o=2&i[0]?n.return:i[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,i[1])).done)return o;switch(n=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return s.label++,{value:i[1],done:!1};case 5:s.label++,n=i[1],i=[0];continue;case 7:i=s.ops.pop(),s.trys.pop();continue;default:if(!(o=(o=s.trys).length>0&&o[o.length-1])&&(6===i[0]||2===i[0])){s=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){s.label=i[1];break}if(6===i[0]&&s.label<o[1]){s.label=o[1],o=i;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(i);break}o[2]&&s.ops.pop(),s.trys.pop();continue}i=e.call(t,s)}catch(t){i=[6,t],n=0}finally{r=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,a])}}},J=new RegExp("^-?(0|[1-9]\\d*)(\\.\\d*)?$"),$=new RegExp("^-?(0|[1-9]\\d*)$"),z=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.defaultControlled=n.value,e}return G(e,t),e}(a),L=new z({emptyRaw:"",convert:function(t){return t},render:function(t){return t}}),Q=new z({emptyRaw:"",rawValidate:function(t){return t.startsWith(".")&&(t="0"+t),J.test(t)},convert:function(t){return+t},render:function(t){return t.toString()}}),X=new z({emptyRaw:"",rawValidate:function(t){return $.test(t)},convert:function(t){return+t},render:function(t){return t.toString()}}),Y=new a({emptyRaw:!1,convert:function(t){return t},render:function(t){return t},defaultControlled:n.checked}),Z=function(){function t(t,e){this.maxWholeDigits=t,this.decimalPlaces=e,this.defaultControlled=n.value,this.emptyRaw="";var r=new RegExp("^-?(0|[1-9]\\d{0,"+(t-1)+"})(\\.\\d{0,"+e+"})?$");this.converter=new z({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 tt=new a({emptyRaw:[],convert:function(t){return u.observable.array(t)},render:function(t){return t.slice()}});var et=function(){function t(t){this.converter=t,this.defaultControlled=n.value,this.emptyRaw=""}return t.prototype.convert=function(t){return H(this,void 0,void 0,function(){return K(this,function(e){return""===t.trim()?[2,new s(null)]:[2,this.converter.convert(t)]})})},t.prototype.render=function(t){return null===t?"":this.converter.render(t)},t}(),rt=function(){function t(t){this.emptyRaw=null,this.defaultControlled=n.object}return t.prototype.convert=function(t){return H(this,void 0,void 0,function(){return K(this,function(e){return null===t?[2,"ConversionError"]:[2,new s(t)]})})},t.prototype.render=function(t){return t},t}();var nt={string:L,number:Q,integer:X,decimal:function(t,e){return new Z(t,e)},boolean:Y,stringArray:tt,maybe:function(t){return t instanceof z?new et(t):new a({emptyRaw:null,convert:w,render:w,defaultControlled:n.object})},model:function(t){return new rt(t)},object:new a({emptyRaw:null,convert:w,render:w})},ot=function(){function t(t,e){this.model=t,this.allowedKeys=e}return t.prototype.access=function(t){return t.restricted(this.allowedKeys)},t}();r.d(e,"Form",function(){return q}),r.d(e,"ValidationMessage",function(){return _}),r.d(e,"ProcessValue",function(){return W}),r.d(e,"Field",function(){return I}),r.d(e,"RepeatingForm",function(){return U}),r.d(e,"ConversionValue",function(){return s}),r.d(e,"CONVERSION_ERROR",function(){return"ConversionError"}),r.d(e,"Converter",function(){return a}),r.d(e,"StringConverter",function(){return z}),r.d(e,"converters",function(){return nt}),r.d(e,"setupValidationProps",function(){return y}),r.d(e,"FormAccessor",function(){return v}),r.d(e,"FieldAccessor",function(){return g}),r.d(e,"RepeatingFormAccessor",function(){return b}),r.d(e,"RepeatingFormIndexedAccessor",function(){return m}),r.d(e,"controlled",function(){return n}),r.d(e,"Group",function(){return ot})}])});
//# sourceMappingURL=mstform.js.map
{
"name": "mstform",
"private": false,
"version": "0.11.0",
"version": "0.12.0",
"description": "mobx-state-tree powered forms",
"main": "dist/mstform.js",
"umd:main": "dist/mstform.umd.js",
"module": "dist/mstform.module.js",
"typings": "dist/index.d.ts",
"typings": "dist/src/index.d.ts",
"sideEffects": false,
"files": [
"dist"
],
"author": "ISProjects",
"license": "MIT",
"repository": {
"type": "git",
"url": "git@github.com:isprojects/mstform.git"
},
"scripts": {
"build": "tsc && cpr lib/src dist --delete-first --filter=\\\\.js && yarn rollup",
"rollup": "rollup -c",
"test": "cross-env NODE_ENV=development jest --ci && cross-env NODE_ENV=production jest --ci && yarn run test-cyclic",
"speedtest": "node --expose-gc test/perf/report.js",
"test-cyclic": "yarn run build && node -e \"require('.')\"",
"watch": "jest --watch",
"_prepublish": "yarn run build && npm run build-docs",
"coverage": "jest --coverage",
"build-docs": "tsc && documentation build lib/index.js --sort-order alpha -f md -o ../../API.md.tmp && concat -o ../../API.md ../../docs/API_header.md ../../API.md.tmp && rm ../../API.md.tmp",
"lint": "tslint -c tslint.json 'src/**/*.ts'"
"start": "webpack-dev-server --open --config webpack.dev.js",
"lint": "tslint -t codeFrame 'src/**/*.ts' 'test/**/*.ts'",
"build": "webpack --config webpack.prod.js",
"prepublishOnly": "yarn run lint && yarn run test && yarn run build",
"test": "jest",
"test:watch": "jest --watch",
"test:debug": "node --nolazy --inspect-brk=9229 ./node_modules/.bin/jest --runInBand",
"test:prod": "yarn run lint && yarn run test -- --coverage --no-cache",
"report-coverage": "cat ./coverage/lcov.info | coveralls",
"semantic-release": "semantic-release",
"semantic-release-prepare": "ts-node tools/semantic-release-prepare",
"precommit": "lint-staged"
},
"author": "ISProjects",
"license": "MIT",
"files": [
"dist/"
],
"lint-staged": {
"{src,test,demo}/**/*.ts": [
"prettier --write",
"git add"
]
},
"jest": {
"testEnvironment": "node",
"transform": {
".(ts|tsx)": "<rootDir>/node_modules/ts-jest/preprocessor.js"
},
"testRegex": "(/__tests__/.*|\\.(test|spec))\\.(ts|tsx|js)$",
"roots": [
"<rootDir>/src/",
"<rootDir>/test/"
],
"moduleFileExtensions": [
"ts",
"tsx",
"js"
],
"coveragePathIgnorePatterns": [
"/node_modules/",
"/test/"
],
"coverageThreshold": {
"global": {
"branches": 90,
"functions": 95,
"lines": 95,
"statements": 95
}
},
"collectCoverage": false
},
"devDependencies": {
"@types/jest": "^22.2.0",
"@types/node": "^8.0.19",
"concat": "^1.0.3",
"concurrently": "^3.1.0",
"coveralls": "^2.11.4",
"cpr": "^2.1.0",
"@types/node": "^10.0.3",
"@types/react": "^16.2.0",
"@types/react-dom": "^16.0.6",
"clean-webpack-plugin": "^0.1.19",
"coveralls": "^3.0.0",
"cross-env": "^5.1.1",
"documentation": "^5.2.2",
"fast-deep-equal": "^1.1.0",
"html-webpack-plugin": "^3.2.0",
"husky": "^0.14.0",
"jest": "^22.4.2",
"lint-staged": "^7.1.3",
"mobx": "^4.2.0",
"mobx-react": "^5.0.0",
"mobx-state-tree": "^2.0.5",
"rollup": "^0.43.0",
"rollup-plugin-commonjs": "^8.0.2",
"rollup-plugin-filesize": "^1.3.2",
"rollup-plugin-node-resolve": "^3.0.0",
"rollup-plugin-replace": "^1.1.1",
"rollup-plugin-uglify": "^2.0.1",
"sinon": "^3.2.1",
"prettier": "^1.13.4",
"prompt": "^1.0.0",
"react": "^16.2.0",
"react-dom": "^16.2.0",
"replace-in-file": "^3.0.0-beta.2",
"semantic-release": "^15.0.0",
"ts-jest": "^22.4.1",
"tslib": "^1.7.1",
"tslint": "^3.15.1",
"tslint-config-prettier": "^1.12.0",
"typescript": "^2.8.3"
"ts-loader": "^4.4.2",
"ts-node": "^6.0.0",
"tslint": "^5.8.0",
"tslint-config-prettier": "^1.1.0",
"tslint-config-standard": "^7.0.0",
"typescript": "^2.9",
"validate-commit-msg": "^2.12.2",
"webpack": "^4.16.2",
"webpack-cli": "^3.1.0",
"webpack-dev-server": "^3.1.5",
"webpack-merge": "^4.1.3"
},
"peerDependencies": {
"fast-deep-equal": "^1.1.0",
"mobx": "^4.2.0",

@@ -65,29 +111,3 @@ "mobx-state-tree": "^2.0.5"

"state management"
],
"jest": {
"transform": {
"^.+\\.tsx?$": "ts-jest",
"^.+\\.jsx?$": "babel-jest"
},
"testRegex": "test/.*\\.(t|j)sx?$",
"moduleFileExtensions": [
"ts",
"tsx",
"js",
"jsx",
"json"
],
"testPathIgnorePatterns": [
"/node_modules/",
"/src/",
"/dist/",
"/test/fixtures",
"/test/perf",
"/\\./",
"/lib"
],
"watchPathIgnorePatterns": [
"<rootDir>/node_modules/"
]
}
]
}
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