@ibsheet/loader
Version:
Dynamically load support module for IBSheet
117 lines • 4.37 kB
JavaScript
;
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.RegistryItemURL = void 0;
var uuid_1 = require("uuid");
var custom_1 = require("../../custom");
var lodash_1 = require("../../shared/lodash");
var utils_1 = require("../utils");
var RegistryItemURL = (function (_super) {
__extends(RegistryItemURL, _super);
function RegistryItemURL(data) {
var _this = _super.call(this) || this;
_this._dependencies = [];
_this.type = 'js';
_this.target = 'body';
_this.validate = null;
_this.loaded = false;
var url = (0, lodash_1.get)(data, 'url');
if ((0, lodash_1.isNil)(url)) {
throw new Error("[RegistryItemURL] invalid url, ".concat(url));
}
_this.value = url;
_this.type = (0, lodash_1.get)(data, 'type', _this.type);
_this.target = (0, lodash_1.get)(data, 'target', _this.target);
var dependencies = (0, lodash_1.get)(data, 'dependencies');
if (!(0, lodash_1.isNil)(dependencies) && Array.isArray(dependencies)) {
_this.dependencies = dependencies;
}
_this._id = (0, uuid_1.v1)();
return _this;
}
Object.defineProperty(RegistryItemURL.prototype, "id", {
get: function () {
return this._id;
},
enumerable: false,
configurable: true
});
Object.defineProperty(RegistryItemURL.prototype, "value", {
get: function () {
return this._value;
},
set: function (val) {
if ((0, lodash_1.isNil)(val) || !val.length) {
throw new Error('undefiend registry url');
}
var sType;
var filename = (0, utils_1.getFilenameFromURL)(val);
if (!(0, lodash_1.isNil)(filename)) {
var file = filename.split('.');
if (file.length > 1) {
sType = file.pop();
this._basename = file.join('.');
}
else {
this._basename = filename;
}
}
if (!(0, lodash_1.isNil)(sType)) {
this.type = sType;
this.target = sType === 'css' ? 'head' : 'body';
}
this._value = val;
},
enumerable: false,
configurable: true
});
Object.defineProperty(RegistryItemURL.prototype, "basename", {
get: function () {
return this._basename;
},
enumerable: false,
configurable: true
});
Object.defineProperty(RegistryItemURL.prototype, "alias", {
get: function () {
return "".concat(this.basename, ".").concat(this.type);
},
enumerable: false,
configurable: true
});
Object.defineProperty(RegistryItemURL.prototype, "dependencies", {
get: function () {
return this._dependencies;
},
set: function (arr) {
var _this = this;
this._dependencies = arr.filter(function (str) { return str !== _this.basename; });
},
enumerable: false,
configurable: true
});
RegistryItemURL.prototype.test = function () {
var fnValidate = this.validate;
if ((0, lodash_1.isNil)(fnValidate) || !(0, lodash_1.isFunction)(fnValidate))
return true;
return fnValidate();
};
return RegistryItemURL;
}(custom_1.CustomEventEmitter));
exports.RegistryItemURL = RegistryItemURL;
exports.default = RegistryItemURL;
//# sourceMappingURL=url.js.map