Repository URL to install this package:
|
Version:
0.1.49 ▾
|
"use strict";
var __decorate = (this && this.__decorate) || function (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;
};
var __metadata = (this && this.__metadata) || function (k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
Object.defineProperty(exports, "__esModule", { value: true });
var mobx_1 = require("mobx");
var flags_1 = require("../../constants/flags");
var services_1 = require("../../constants/services");
var stores_1 = require("../../constants/stores");
var interfaces_1 = require("../../interfaces");
var container_1 = require("../../ioc/model/container");
var container_2 = require("../../ioc/model/container");
var metadata_1 = require("../metadata");
var ModelInstance = /** @class */ (function () {
function ModelInstance(page, id, metadata) {
var _this = this;
var modelData = page.getModelData(id);
this._id = modelData.id;
this._page = page;
this._metadata = metadata;
var modelInstance = this;
this._data = Object.keys(metadata.variables).reduce(function (variables, code) {
variables[code] = new _this._variableInstanceClass(_this, metadata.variables[code], code);
return variables;
}, {});
mobx_1.extendObservable(this, Object.keys(metadata.variables).reduce(function (variables, code) {
variables[code] = mobx_1.computed(function () {
return _this._data[code].value;
}, {
name: code,
context: _this,
setter: function (value) {
_this._data[code].setValue(value);
}
});
return variables;
}, {}));
this._metadata = metadata;
}
Object.defineProperty(ModelInstance.prototype, "isSelected", {
get: function () {
return this.getId() === this.getPage().selectedModel;
},
enumerable: true,
configurable: true
});
Object.defineProperty(ModelInstance.prototype, "isFocused", {
get: function () {
return this.getId() === this.getPage().focusedModel;
},
enumerable: true,
configurable: true
});
Object.defineProperty(ModelInstance.prototype, "isDeleted", {
get: function () {
return !this._page.hasModelData(this._id);
},
enumerable: true,
configurable: true
});
Object.defineProperty(ModelInstance.prototype, "isRepeatableChild", {
get: function () {
return this._page.isModelRepeatableChild(this._id);
},
enumerable: true,
configurable: true
});
Object.defineProperty(ModelInstance.prototype, "showGUIControls", {
get: function () {
return !this.isDeleted && this.isRepeatableChild && !this.isCarryingFlag(flags_1.default.CONTROLLED);
},
enumerable: true,
configurable: true
});
Object.defineProperty(ModelInstance.prototype, "nonRepeatableChildren", {
get: function () {
var _this = this;
return Object.keys(this._metadata.variables).filter(function (code) {
var variableMetadata = _this._metadata.variables[code];
var typeCode = _this.getVariableInstance(code).typeCode;
return typeCode === 'child' && !variableMetadata.options.repeatable;
}).map(function (code) {
return _this.getVariableInstance(code).value;
});
},
enumerable: true,
configurable: true
});
Object.defineProperty(ModelInstance.prototype, "modelToolConnections", {
get: function () {
var _this = this;
return this._metadata.tools.filter(function (connection) {
return typeof connection.validate !== 'function' || connection.validate(_this);
}).map(function (connection) { return ({
model: _this,
connection: connection
}); });
},
enumerable: true,
configurable: true
});
Object.defineProperty(ModelInstance.prototype, "defaultToolConnections", {
get: function () {
var _this = this;
return this._toolRegistry.getDefaultToolConnections().map(function (connection) { return ({
model: _this,
connection: connection
}); });
},
enumerable: true,
configurable: true
});
Object.defineProperty(ModelInstance.prototype, "recursiveToolConnections", {
get: function () {
var connections = this.modelToolConnections.concat(this.nonRepeatableChildren.reduce(function (data, child) { return (data.concat(child.recursiveToolConnections)); }, []));
return connections.filter(function (modelToolConnection, index) {
return connections.findIndex(function (mtc) {
return mtc.connection.id === modelToolConnection.connection.id;
}) === index;
});
},
enumerable: true,
configurable: true
});
Object.defineProperty(ModelInstance.prototype, "toolConnections", {
get: function () {
return this.defaultToolConnections.concat(this.recursiveToolConnections);
},
enumerable: true,
configurable: true
});
Object.defineProperty(ModelInstance.prototype, "actionToolSlots", {
get: function () {
var _this = this;
return this.toolConnections.filter(function (mtc) {
return _this._toolRegistry.getToolFromConnection(mtc.connection).type === interfaces_1.interfaces.ToolType.ACTION;
}).map(function (mtc) {
return _this._toolRegistry.getToolSlot(mtc.model, mtc.connection);
});
},
enumerable: true,
configurable: true
});
Object.defineProperty(ModelInstance.prototype, "modalToolSlots", {
get: function () {
var _this = this;
return this.toolConnections.filter(function (mtc) {
return _this._toolRegistry.getToolFromConnection(mtc.connection).type === interfaces_1.interfaces.ToolType.MODAL;
}).map(function (mtc) {
return _this._toolRegistry.getToolSlot(_this, mtc.connection);
});
},
enumerable: true,
configurable: true
});
Object.defineProperty(ModelInstance.prototype, "selectedTool", {
get: function () {
return this._page.getSelectedToolId(this._id);
},
enumerable: true,
configurable: true
});
ModelInstance.prototype.getId = function () {
return this._id;
};
ModelInstance.prototype.getType = function () {
return this._page.getModelData(this._id).type;
};
ModelInstance.prototype.getVersion = function () {
return this._page.getModelData(this._id).version;
};
ModelInstance.prototype.getPage = function () {
return this._page;
};
ModelInstance.prototype.getMetadata = function () {
return this._metadata;
};
ModelInstance.prototype.getModelViewComponent = function () {
return this._viewRegistry.getViewComponentByModelType(this.getType());
};
ModelInstance.prototype.getVariableInstance = function (code) {
return this._data[code];
};
ModelInstance.prototype.isCarryingFlag = function (flag, path) {
return this._page.isModelCarryingFlag(this._id, flag, path);
};
__decorate([
mobx_1.observable,
__metadata("design:type", Object)
], ModelInstance.prototype, "_data", void 0);
__decorate([
container_2.ibd.lazyInject(services_1.default.VIEW_REGISTRY),
__metadata("design:type", Object)
], ModelInstance.prototype, "_viewRegistry", void 0);
__decorate([
container_2.ibd.lazyInject(stores_1.default.VARIABLE_INSTANCE),
__metadata("design:type", Object)
], ModelInstance.prototype, "_variableInstanceClass", void 0);
__decorate([
container_2.ibd.lazyInject(services_1.default.TOOL_REGISTRY),
__metadata("design:type", Object)
], ModelInstance.prototype, "_toolRegistry", void 0);
__decorate([
mobx_1.computed,
__metadata("design:type", Object),
__metadata("design:paramtypes", [])
], ModelInstance.prototype, "isSelected", null);
__decorate([
mobx_1.computed,
__metadata("design:type", Object),
__metadata("design:paramtypes", [])
], ModelInstance.prototype, "isFocused", null);
__decorate([
mobx_1.computed,
__metadata("design:type", Object),
__metadata("design:paramtypes", [])
], ModelInstance.prototype, "isDeleted", null);
__decorate([
mobx_1.computed,
__metadata("design:type", Boolean),
__metadata("design:paramtypes", [])
], ModelInstance.prototype, "isRepeatableChild", null);
__decorate([
mobx_1.computed,
__metadata("design:type", Boolean),
__metadata("design:paramtypes", [])
], ModelInstance.prototype, "showGUIControls", null);
__decorate([
mobx_1.computed,
__metadata("design:type", Array),
__metadata("design:paramtypes", [])
], ModelInstance.prototype, "nonRepeatableChildren", null);
__decorate([
mobx_1.computed,
__metadata("design:type", Array),
__metadata("design:paramtypes", [])
], ModelInstance.prototype, "modelToolConnections", null);
__decorate([
mobx_1.computed,
__metadata("design:type", Array),
__metadata("design:paramtypes", [])
], ModelInstance.prototype, "defaultToolConnections", null);
__decorate([
mobx_1.computed,
__metadata("design:type", Array),
__metadata("design:paramtypes", [])
], ModelInstance.prototype, "recursiveToolConnections", null);
__decorate([
mobx_1.computed,
__metadata("design:type", Array),
__metadata("design:paramtypes", [])
], ModelInstance.prototype, "toolConnections", null);
__decorate([
mobx_1.computed,
__metadata("design:type", Array),
__metadata("design:paramtypes", [])
], ModelInstance.prototype, "actionToolSlots", null);
__decorate([
mobx_1.computed,
__metadata("design:type", Array),
__metadata("design:paramtypes", [])
], ModelInstance.prototype, "modalToolSlots", null);
__decorate([
mobx_1.computed,
__metadata("design:type", Object),
__metadata("design:paramtypes", [])
], ModelInstance.prototype, "selectedTool", null);
ModelInstance = __decorate([
container_1.provideStore(stores_1.default.MODEL_INSTANCE),
__metadata("design:paramtypes", [Object, String, metadata_1.ModelMetadata])
], ModelInstance);
return ModelInstance;
}());
exports.default = ModelInstance;
//# sourceMappingURL=modelInstance.js.map